zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Deadlock when receiving kill-signal from child process
Date: Sun, 9 Aug 2015 17:29:42 -0700	[thread overview]
Message-ID: <150809172942.ZM4190@torch.brasslantern.com> (raw)
In-Reply-To: <150809164225.ZM10049@torch.brasslantern.com>

On Aug 9,  4:42pm, Bart Schaefer wrote:
}
} Nevertheless, it looks like glob.c needs to protect some places where
} it manipulates global state.

I couldn't really find anything definitive -- all the memory management
routines (halloc, zhalloc, zfree, etc.) already do signal queuing, so
we only get into trouble with e.g. stdio using the library malloc/free
directly.

The hunks in patcompile() below are paranoia because the static globals
patcode, patsize, et al. are being frobbed -- but even with this I get
worried that a signal trap that uses pattern matching called in the
midst of some other pattern matching operation could leave those in an
inconsistent state, because they're not saved/restored like globbing
state in zglob().

Similarly if you were in the middle of a pattern that wanted to set the
MATCH / MBEGIN / MEND / match / mbegin / mend parameters and then a
trap handler also did so, it sure looks to me as if the state of those
parameters becomes indeterminate.

Patch below follows on to 36022 but doesn't overlap with it in any way.


diff --git a/Src/glob.c b/Src/glob.c
index eff34a2..f82c3bd 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -216,22 +216,26 @@ static struct globdata curglobdata;
 
 #define save_globstate(N) \
   do { \
+    queue_signals(); \
     memcpy(&(N), &curglobdata, sizeof(struct globdata)); \
     (N).gd_pathpos = pathpos; \
     (N).gd_pathbuf = pathbuf; \
     (N).gd_glob_pre = glob_pre; \
     (N).gd_glob_suf = glob_suf; \
     pathbuf = NULL; \
+    unqueue_signals(); \
   } while (0)
 
 #define restore_globstate(N) \
   do { \
+    queue_signals(); \
     zfree(pathbuf, pathbufsz); \
     memcpy(&curglobdata, &(N), sizeof(struct globdata)); \
     pathpos = (N).gd_pathpos; \
     pathbuf = (N).gd_pathbuf; \
     glob_pre = (N).gd_glob_pre; \
     glob_suf = (N).gd_glob_suf; \
+    unqueue_signals(); \
   } while (0)
 
 /* pathname component in filename patterns */
diff --git a/Src/pattern.c b/Src/pattern.c
index 8fa1a72..7d38988 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -520,6 +520,8 @@ patcompile(char *exp, int inflags, char **endexp)
     char *lng, *strp = NULL;
     Patprog p;
 
+    queue_signals();
+
     startoff = sizeof(struct patprog);
     /* Ensure alignment of start of program string */
     startoff = (startoff + sizeof(union upat) - 1) & ~(sizeof(union upat) - 1);
@@ -582,8 +584,10 @@ patcompile(char *exp, int inflags, char **endexp)
 	if (!strp || (*strp && *strp != '/')) {
 	    /* No, do normal compilation. */
 	    strp = NULL;
-	    if (patcompswitch(0, &flags) == 0)
+	    if (patcompswitch(0, &flags) == 0) {
+		unqueue_signals();
 		return NULL;
+	    }
 	} else {
 	    /*
 	     * Yes, copy the string, and skip compilation altogether.
@@ -715,6 +719,8 @@ patcompile(char *exp, int inflags, char **endexp)
 
     if (endexp)
 	*endexp = patparse;
+
+    unqueue_signals();
     return p;
 }
 

-- 
Barton E. Schaefer


  parent reply	other threads:[~2015-08-10  0:29 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03 11:25 Mathias Fredriksson
2015-08-03 15:52 ` Bart Schaefer
2015-08-03 20:36   ` Mathias Fredriksson
2015-08-03 20:58     ` Bart Schaefer
2015-08-04 21:52       ` Mathias Fredriksson
2015-08-05  0:05         ` Mathias Fredriksson
2015-08-05  6:53         ` Bart Schaefer
2015-08-05 10:37           ` Mathias Fredriksson
2015-08-05 15:52             ` Bart Schaefer
2015-08-05 16:05               ` Mathias Fredriksson
2015-08-05 18:52                 ` Bart Schaefer
2015-08-05 19:11                   ` Mathias Fredriksson
2015-08-05 20:20                     ` Bart Schaefer
2015-08-05 21:49                       ` Mathias Fredriksson
2015-08-06  5:06                         ` Bart Schaefer
2015-08-06  8:24                           ` Mathias Fredriksson
2015-08-06 15:54                             ` Bart Schaefer
2015-08-07  0:45                               ` Mathias Fredriksson
2015-08-07  5:39                                 ` Bart Schaefer
2015-08-09 13:53                                   ` Mathias Fredriksson
2015-08-09 23:42                                     ` Bart Schaefer
2015-08-10  0:02                                       ` Mikael Magnusson
2015-08-10  0:16                                         ` Mathias Fredriksson
2015-08-10  1:47                                           ` Bart Schaefer
2015-08-10  2:02                                             ` Mikael Magnusson
2015-08-10 15:59                                               ` Bart Schaefer
2015-08-10 17:30                                                 ` Mathias Fredriksson
2015-08-10  0:36                                         ` Bart Schaefer
2015-08-10  0:29                                       ` Bart Schaefer [this message]
2015-08-10 19:34                                     ` Bart Schaefer
2015-08-10 21:17                                       ` Mathias Fredriksson
2015-08-10 22:53                                         ` Mathias Fredriksson
2015-08-11  0:53                                           ` Bart Schaefer
2015-08-11 12:17                                             ` Mathias Fredriksson
2015-08-11 14:38                                               ` Mathias Fredriksson
2015-08-11 15:07                                               ` Bart Schaefer
2015-08-11 15:22                                                 ` Mathias Fredriksson
2015-08-11  4:06                                           ` Running commands in a zpty worker Bart Schaefer
2015-08-11 13:14                                             ` Mathias Fredriksson
2015-08-11 14:35                                               ` Mathias Fredriksson
2015-08-11 14:37                                               ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150809172942.ZM4190@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).