Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Process pending signals while waiting for a job:



details:   https://anonhg.NetBSD.org/src/rev/2fa522dcc397
branches:  trunk
changeset: 810231:2fa522dcc397
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Aug 22 09:55:23 2015 +0000

description:
Process pending signals while waiting for a job:
    $ cat << EOF > hup.sh
    #!/bin/sh
    trap 'echo SIGHUP; exit 1' 1
    sleep 10000 &
    wait
    EOF
    $ chmod +x ./hup.sh
    $ ./hup.sh &
    $ kill -HUP %1

diffstat:

 bin/sh/jobs.c |  7 +++----
 bin/sh/trap.c |  8 ++++----
 bin/sh/trap.h |  4 ++--
 3 files changed, 9 insertions(+), 10 deletions(-)

diffs (80 lines):

diff -r a11784801af2 -r 2fa522dcc397 bin/sh/jobs.c
--- a/bin/sh/jobs.c     Sat Aug 22 07:48:14 2015 +0000
+++ b/bin/sh/jobs.c     Sat Aug 22 09:55:23 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jobs.c,v 1.73 2014/04/11 01:49:45 christos Exp $       */
+/*     $NetBSD: jobs.c,v 1.74 2015/08/22 09:55:23 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)jobs.c     8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: jobs.c,v 1.73 2014/04/11 01:49:45 christos Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.74 2015/08/22 09:55:23 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -1058,13 +1058,12 @@
        struct job *thisjob;
        int done;
        int stopped;
-       extern volatile char gotsig[];
 
        TRACE(("dowait(%x) called\n", flags));
        do {
                pid = waitproc(flags & WBLOCK, job, &status);
                TRACE(("wait returns pid %d, status %d\n", pid, status));
-       } while (pid == -1 && errno == EINTR && gotsig[SIGINT - 1] == 0);
+       } while (pid == -1 && errno == EINTR && pendingsigs == 0);
        if (pid <= 0)
                return pid;
        INTOFF;
diff -r a11784801af2 -r 2fa522dcc397 bin/sh/trap.c
--- a/bin/sh/trap.c     Sat Aug 22 07:48:14 2015 +0000
+++ b/bin/sh/trap.c     Sat Aug 22 09:55:23 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.35 2011/06/18 21:18:46 christos Exp $       */
+/*     $NetBSD: trap.c,v 1.36 2015/08/22 09:55:23 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)trap.c     8.5 (Berkeley) 6/5/95";
 #else
-__RCSID("$NetBSD: trap.c,v 1.35 2011/06/18 21:18:46 christos Exp $");
+__RCSID("$NetBSD: trap.c,v 1.36 2015/08/22 09:55:23 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -77,8 +77,8 @@
 
 char *trap[NSIG+1];            /* trap handler commands */
 MKINIT char sigmode[NSIG];     /* current value of signal */
-volatile char gotsig[NSIG];    /* indicates specified signal received */
-int pendingsigs;               /* indicates some signal received */
+static volatile char gotsig[NSIG];/* indicates specified signal received */
+volatile int pendingsigs;      /* indicates some signal received */
 
 static int getsigaction(int, sig_t *);
 
diff -r a11784801af2 -r 2fa522dcc397 bin/sh/trap.h
--- a/bin/sh/trap.h     Sat Aug 22 07:48:14 2015 +0000
+++ b/bin/sh/trap.h     Sat Aug 22 09:55:23 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.h,v 1.20 2012/03/15 02:02:20 joerg Exp $  */
+/*     $NetBSD: trap.h,v 1.21 2015/08/22 09:55:23 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -34,7 +34,7 @@
  *     @(#)trap.h      8.3 (Berkeley) 6/5/95
  */
 
-extern int pendingsigs;
+extern volatile int pendingsigs;
 
 void clear_traps(int);
 sig_t setsignal(int, int);



Home | Main Index | Thread Index | Old Index