Source-Changes-HG archive

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

[src/netbsd-6]: src/bin/sh Pull up following revision(s) (requested by christ...



details:   https://anonhg.NetBSD.org/src/rev/d122c353f68a
branches:  netbsd-6
changeset: 777005:d122c353f68a
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sun Nov 15 17:41:26 2015 +0000

description:
Pull up following revision(s) (requested by christos in ticket #1323):
        bin/sh/jobs.c: revision 1.74
        bin/sh/jobs.c: revision 1.75
        bin/sh/trap.c: revision 1.36
        bin/sh/trap.c: revision 1.37
        bin/sh/trap.h: revision 1.21
        bin/sh/trap.h: revision 1.22
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
report the signal that wait was interrupted by, which is not always SIGINT
anymore.

diffstat:

 bin/sh/jobs.c |  11 +++++------
 bin/sh/trap.c |  17 +++++++++++++----
 bin/sh/trap.h |   5 +++--
 3 files changed, 21 insertions(+), 12 deletions(-)

diffs (120 lines):

diff -r 6cf6a531e174 -r d122c353f68a bin/sh/jobs.c
--- a/bin/sh/jobs.c     Sun Nov 15 17:39:10 2015 +0000
+++ b/bin/sh/jobs.c     Sun Nov 15 17:41:26 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jobs.c,v 1.69.4.1 2014/12/07 15:58:27 martin Exp $     */
+/*     $NetBSD: jobs.c,v 1.69.4.2 2015/11/15 17:41:26 bouyer 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.69.4.1 2014/12/07 15:58:27 martin Exp $");
+__RCSID("$NetBSD: jobs.c,v 1.69.4.2 2015/11/15 17:41:26 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -619,7 +619,7 @@
                                continue;
                        }
                        if (dowait(WBLOCK, NULL) == -1)
-                              return 128 + SIGINT;
+                              return 128 + lastsig();
                        jp = jobtab;
                }
        }
@@ -634,7 +634,7 @@
                /* loop until process terminated or stopped */
                while (job->state == JOBRUNNING) {
                        if (dowait(WBLOCK|WNOFREE, job) == -1)
-                              return 128 + SIGINT;
+                              return 128 + lastsig();
                }
                status = job->ps[job->nprocs ? job->nprocs - 1 : 0].status;
                if (WIFEXITED(status))
@@ -1042,13 +1042,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 6cf6a531e174 -r d122c353f68a bin/sh/trap.c
--- a/bin/sh/trap.c     Sun Nov 15 17:39:10 2015 +0000
+++ b/bin/sh/trap.c     Sun Nov 15 17:41:26 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.35.4.1 2015/11/15 17:41:26 bouyer 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.35.4.1 2015/11/15 17:41:26 bouyer 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 *);
 
@@ -421,7 +421,16 @@
        pendingsigs = 0;
 }
 
+int
+lastsig(void)
+{
+       int i;
 
+       for (i = NSIG; i > 0; i--)
+               if (gotsig[i - 1])
+                       return i;
+       return SIGINT;  /* XXX */
+}
 
 /*
  * Controls whether the shell is interactive or not.
diff -r 6cf6a531e174 -r d122c353f68a bin/sh/trap.h
--- a/bin/sh/trap.h     Sun Nov 15 17:39:10 2015 +0000
+++ b/bin/sh/trap.h     Sun Nov 15 17:41:26 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.h,v 1.19 2011/06/18 21:18:46 christos Exp $       */
+/*     $NetBSD: trap.h,v 1.19.4.1 2015/11/15 17:41:26 bouyer 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);
@@ -43,3 +43,4 @@
 void dotrap(void);
 void setinteractive(int);
 void exitshell(int) __attribute__((__noreturn__));
+int lastsig(void);



Home | Main Index | Thread Index | Old Index