zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: Vincent Stemen <zsh@hightek.org>,
	zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: (2) Re: FreeBSD compatability feature request
Date: Wed, 21 Apr 2004 12:05:00 +0100	[thread overview]
Message-ID: <18144.1082545500@csr.com> (raw)
In-Reply-To: "Vincent Stemen"'s message of "Wed, 21 Apr 2004 03:21:51 CDT." <20040421082151.GA61057@quark.hightek.org>

OK, plan B.

I am now frightened about what happens when any signals are blocked
while we are waiting for a child.  So instead of doing that, I propose
queuing traps separately from signals.  This can't cause any races,
since no extra signal or process handling is involved.  The code is a
bit more verbose, but should be much safer.  This patches on top of the
other one.

Again, this should be exactly equivalent to 4.2.0 unless TRAPS_ASYNC is
unset (POSIX compatibility mode).

This ought to fix the hang.

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.26
diff -u -r1.26 jobs.c
--- Src/jobs.c	19 Apr 2004 16:02:22 -0000	1.26
+++ Src/jobs.c	21 Apr 2004 10:40:30 -0000
@@ -994,11 +994,8 @@
     int q = queue_signal_level();
     Job jn = jobtab + job;
 
-    queue_not_sigchld++;
-    if (isset(TRAPSASYNC))
-	dont_queue_signals();
-    else
-	queue_signals();
+    dont_queue_signals();
+    queue_traps();
     child_block();		 /* unblocked during child_suspend() */
     if (jn->procs || jn->auxprocs) { /* if any forks were done         */
 	jn->stat |= STAT_LOCKED;
@@ -1029,10 +1026,8 @@
 	numpipestats = 1;
     }
     child_unblock();
+    dont_queue_traps();
     restore_queue_signals(q);
-    if (!queueing_enabled)
-	run_queued_signals();
-    queue_not_sigchld--;
 }
 
 /* wait for running job to finish */
Index: Src/signals.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signals.c,v
retrieving revision 1.26
diff -u -r1.26 signals.c
--- Src/signals.c	19 Apr 2004 16:02:22 -0000	1.26
+++ Src/signals.c	21 Apr 2004 10:40:30 -0000
@@ -49,12 +49,19 @@
 /* Variables used by signal queueing */
 
 /**/
-mod_export int queueing_enabled, queue_front, queue_rear, queue_not_sigchld;
+mod_export int queueing_enabled, queue_front, queue_rear;
 /**/
 mod_export int signal_queue[MAX_QUEUE_SIZE];
 /**/
 mod_export sigset_t signal_mask_queue[MAX_QUEUE_SIZE];
 
+/* Variables used by trap queueing */
+
+/**/
+mod_export int trap_queueing_enabled, trap_queue_front, trap_queue_rear;
+/**/
+mod_export int trap_queue[MAX_QUEUE_SIZE];
+
 /* This is only used on machines that don't understand signal sets.  *
  * On SYSV machines this will represent the signals that are blocked *
  * (held) using sighold.  On machines which can't block signals at   *
@@ -426,7 +433,7 @@
 #endif
 
     /* Are we queueing signals now?      */
-    if (queueing_enabled && (sig != SIGCHLD || !queue_not_sigchld)) {
+    if (queueing_enabled) {
         int temp_rear = ++queue_rear % MAX_QUEUE_SIZE;
 
 	DPUTS(temp_rear == queue_front, "BUG: signal queue full");
@@ -1058,5 +1065,17 @@
     if ((sigtrapped[sig] & ZSIG_IGNORED) || !sigfuncs[sig] || errflag)
 	return;
 
+    /* Adapted from signal queueing in zhandler */
+    if (trap_queueing_enabled && !isset(TRAPSASYNC)) {
+	int temp_rear = ++trap_queue_rear % MAX_QUEUE_SIZE;
+
+	DPUTS(temp_rear == trap_queue_front, "BUG: trap queue full");
+	if (temp_rear != trap_queue_front) {
+	    trap_queue_rear = temp_rear;
+	    trap_queue[trap_queue_rear] = sig;
+	}
+	return;
+    }
+
     dotrapargs(sig, sigtrapped+sig, sigfuncs[sig]);
 }
Index: Src/signals.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signals.h,v
retrieving revision 1.4
diff -u -r1.4 signals.h
--- Src/signals.h	18 Jun 2001 07:24:23 -0000	1.4
+++ Src/signals.h	21 Apr 2004 10:40:30 -0000
@@ -101,6 +101,23 @@
 
 #define restore_queue_signals(q) (queueing_enabled = (q))
 
+/*
+ * Similar (but simpler) mechanism used for queueing traps.
+ * Only needed if NO_TRAPS_ASYNC is set.
+ */
+#define queue_traps()	(trap_queueing_enabled++)
+
+#define run_queued_traps() do { \
+    while (trap_queue_front != trap_queue_rear) { /* while traps in queue */ \
+	trap_queue_front = (trap_queue_front + 1) % MAX_QUEUE_SIZE; \
+	dotrap(trap_queue[trap_queue_front]);  /* handle queued trap   */ \
+    } \
+} while (0)
+
+#define dont_queue_traps() do { \
+    trap_queueing_enabled = 0; \
+    run_queued_traps(); \
+} while (0)
 
 /* Make some signal functions faster. */
 
-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


  parent reply	other threads:[~2004-04-21 11:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040417222222.GA27230@quark.hightek.org>
     [not found] ` <21533.1082374109@csr.com>
2004-04-21  8:21   ` Vincent Stemen
2004-04-21 10:00     ` Peter Stephenson
2004-04-21 11:05     ` Peter Stephenson [this message]
2004-04-22  8:59       ` PATCH: (2) " Vincent Stemen
2004-04-22  9:59         ` Peter Stephenson
2004-04-22 10:17           ` Peter Stephenson
2004-04-22 16:09             ` Jos Backus
2004-04-23  5:30               ` Vincent Stemen
2004-04-23  9:56                 ` Peter Stephenson
2004-04-27  3:56             ` Bart Schaefer
2004-04-27  9:58               ` Peter Stephenson
2004-04-29  2:16                 ` Vincent Stemen
2004-04-30 21:26         ` PATCH: (3) " Peter Stephenson
2004-05-01  1:45           ` Vincent Stemen
2004-05-01  2:23             ` Vincent Stemen
2004-05-04  7:17           ` PATCH: (3) - FreeBSD compatability issue resolved Vincent Stemen
2004-05-04  9:28             ` Peter Stephenson

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=18144.1082545500@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    --cc=zsh@hightek.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).