From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8969 invoked from network); 19 Apr 2004 11:29:25 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 19 Apr 2004 11:29:25 -0000 Received: (qmail 5226 invoked by alias); 19 Apr 2004 11:29:01 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7365 Received: (qmail 5169 invoked from network); 19 Apr 2004 11:29:00 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 19 Apr 2004 11:29:00 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 19 Apr 2004 11:28:59 -0000 Received: (qmail 5595 invoked from network); 19 Apr 2004 11:28:59 -0000 Received: from lhuumrelay3.lnd.ops.eu.uu.net (62.189.58.19) by a.mx.sunsite.dk with SMTP; 19 Apr 2004 11:28:57 -0000 Received: from MAILSWEEPER01.csr.com (mailhost1.csr.com [62.189.183.235]) by lhuumrelay3.lnd.ops.eu.uu.net (8.11.0/8.11.0) with ESMTP id i3JBSUv22797 for ; Mon, 19 Apr 2004 11:28:31 GMT Received: from EXCHANGE02.csr.com (unverified [192.168.137.45]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id ; Mon, 19 Apr 2004 12:28:04 +0100 Received: from csr.com ([192.168.144.127]) by EXCHANGE02.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 19 Apr 2004 12:29:07 +0100 To: Vincent Stemen , zsh-users@sunsite.dk Subject: Re: FreeBSD compatability feature request In-reply-to: "Vincent Stemen"'s message of "Sat, 17 Apr 2004 17:22:22 CDT." <20040417222222.GA27230@quark.hightek.org> Date: Mon, 19 Apr 2004 12:28:29 +0100 Message-ID: <21533.1082374109@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 19 Apr 2004 11:29:07.0854 (UTC) FILETIME=[873692E0:01C42601] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.2 required=6.0 tests=EXCUSE_16 autolearn=no version=2.63 X-Spam-Hits: 0.2 Vincent Stemen wrote: > Here is the FreeBSD manual entry: > > -T trapsasync > When waiting for a child, execute traps immediately. If this > option is not set, traps are executed after the child exits, > as specified in IEEE Std 1003.2 (``POSIX.2'') This nonstandard > option is useful for putting guarding shells around children > that block signals. The surrounding shell may kill the child > or it may just return control to the tty and leave the child > alone, like this: > > sh -T -c "trap 'exit 1' 2 ; some-blocking-program" Good(ish) news... Just tried this out, and it looks like the `trapsasync' behaviour is the standard (and only) one in zsh. Hence it doesn't conform to POSIX (which isn't likely to be an earth-shattering revelation to zsh regulars). This means that almost everything we need for both behaviours is already there. It remains to add the option TRAPS_ASYNC, turned on by default in non-Bourne mode for compatibility, and make sure we can still handle SIGCHLD when the option is unset. Someone already had the foresight to handle sh options separately, so -T does the right thing in sh or ksh emulation and the example you gave should now work as expected. Further follow-ups should probably go to zsh-workers. Index: Doc/Zsh/options.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v retrieving revision 1.30 diff -u -r1.30 options.yo --- Doc/Zsh/options.yo 6 Mar 2004 00:23:03 -0000 1.30 +++ Doc/Zsh/options.yo 19 Apr 2004 11:13:25 -0000 @@ -1189,6 +1189,14 @@ Remove any right prompt from display when accepting a command line. This may be useful with terminals with other cut/paste methods. ) +pindex(TRAPS_ASYNC) +cindex(traps, asynchronous) +item(tt(TRAPS_ASYNC) )( +While waiting for a program to exit, run traps immediately. Otherwise +the trap is run after the program has exited. Note this does not affect +the point at which traps are run for any case other than when the shell is +waiting for a child process. +) pindex(TYPESET_SILENT) item(tt(TYPESET_SILENT))( If this is unset, executing any of the `tt(typeset)' family of @@ -1366,6 +1374,7 @@ subsect(sh/ksh emulation set) startsitem() sitem(tt(-C))(em(NO_)CLOBBER) +sitem(tt(-T))(TRAPS_ASYNC) sitem(tt(-X))(MARK_DIRS) sitem(tt(-a))(ALL_EXPORT) sitem(tt(-b))(NOTIFY) Index: Src/jobs.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v retrieving revision 1.25 diff -u -r1.25 jobs.c --- Src/jobs.c 17 Feb 2004 10:41:37 -0000 1.25 +++ Src/jobs.c 19 Apr 2004 11:13:25 -0000 @@ -994,7 +994,11 @@ int q = queue_signal_level(); Job jn = jobtab + job; - dont_queue_signals(); + queue_not_sigchld++; + if (isset(TRAPSASYNC)) + dont_queue_signals(); + else + queue_signals(); child_block(); /* unblocked during child_suspend() */ if (jn->procs || jn->auxprocs) { /* if any forks were done */ jn->stat |= STAT_LOCKED; @@ -1026,6 +1030,9 @@ } child_unblock(); restore_queue_signals(q); + if (!queueing_enabled) + run_queued_signals(); + queue_not_sigchld--; } /* wait for running job to finish */ Index: Src/options.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/options.c,v retrieving revision 1.17 diff -u -r1.17 options.c --- Src/options.c 6 Mar 2004 00:23:03 -0000 1.17 +++ Src/options.c 19 Apr 2004 11:13:25 -0000 @@ -203,6 +203,7 @@ {NULL, "singlelinezle", OPT_KSH, SINGLELINEZLE}, {NULL, "sunkeyboardhack", 0, SUNKEYBOARDHACK}, {NULL, "transientrprompt", 0, TRANSIENTRPROMPT}, +{NULL, "trapsasync", OPT_EMULATE|OPT_NONBOURNE, TRAPSASYNC}, {NULL, "typesetsilent", OPT_EMULATE|OPT_BOURNE, TYPESETSILENT}, {NULL, "unset", OPT_EMULATE|OPT_BSHELL, UNSET}, {NULL, "verbose", 0, VERBOSE}, @@ -346,7 +347,7 @@ /* Q */ 0, /* R */ 0, /* S */ 0, - /* T */ 0, + /* T */ TRAPSASYNC, /* U */ 0, /* V */ 0, /* W */ 0, Index: Src/signals.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/signals.c,v retrieving revision 1.25 diff -u -r1.25 signals.c --- Src/signals.c 25 Mar 2004 10:07:15 -0000 1.25 +++ Src/signals.c 19 Apr 2004 11:13:25 -0000 @@ -49,7 +49,7 @@ /* Variables used by signal queueing */ /**/ -mod_export int queueing_enabled, queue_front, queue_rear; +mod_export int queueing_enabled, queue_front, queue_rear, queue_not_sigchld; /**/ mod_export int signal_queue[MAX_QUEUE_SIZE]; /**/ @@ -425,7 +425,8 @@ } #endif - if (queueing_enabled) { /* Are we queueing signals now? */ + /* Are we queueing signals now? */ + if (queueing_enabled && (sig != SIGCHLD || !queue_not_sigchld)) { int temp_rear = ++queue_rear % MAX_QUEUE_SIZE; DPUTS(temp_rear == queue_front, "BUG: signal queue full"); Index: Src/zsh.h =================================================================== RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v retrieving revision 1.54 diff -u -r1.54 zsh.h --- Src/zsh.h 11 Mar 2004 14:25:12 -0000 1.54 +++ Src/zsh.h 19 Apr 2004 11:13:25 -0000 @@ -1523,6 +1523,7 @@ SINGLELINEZLE, SUNKEYBOARDHACK, TRANSIENTRPROMPT, + TRAPSASYNC, TYPESETSILENT, UNSET, VERBOSE, -- Peter Stephenson 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 **********************************************************************