]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: Permit default behaviour of SIGTSTP, SIGTTIN, SIGTTOU.
authorDavid Symonds <dsymonds@golang.org>
Fri, 17 Feb 2012 03:36:40 +0000 (14:36 +1100)
committerDavid Symonds <dsymonds@golang.org>
Fri, 17 Feb 2012 03:36:40 +0000 (14:36 +1100)
Fixes #3037.

R=rsc, minux.ma, r, rsc
CC=golang-dev
https://golang.org/cl/5674072

src/pkg/runtime/runtime.h
src/pkg/runtime/signal_plan9_386.c
src/pkg/runtime/signal_unix.c
src/pkg/runtime/signal_windows_386.c
src/pkg/runtime/signal_windows_amd64.c
src/pkg/runtime/signals_darwin.h
src/pkg/runtime/signals_freebsd.h
src/pkg/runtime/signals_linux.h
src/pkg/runtime/signals_netbsd.h
src/pkg/runtime/signals_openbsd.h
src/pkg/runtime/sigqueue.goc

index 48f6b3e34b1088e791d9489235e75ac7aa8298d1..910f00c8a20b221f35c00c811f7d761276310407 100644 (file)
@@ -268,9 +268,10 @@ struct     SigTab
 enum
 {
        SigNotify = 1<<0,       // let signal.Notify have signal, even if from kernel
-       SigKill = 1<<1,  // if signal.Notify doesn't take it, exit quietly
-       SigThrow = 1<<2,  // if signal.Notify doesn't take it, exit loudly
-       SigPanic = 1<<3,  // if the signal is from the kernel, panic
+       SigKill = 1<<1,         // if signal.Notify doesn't take it, exit quietly
+       SigThrow = 1<<2,        // if signal.Notify doesn't take it, exit loudly
+       SigPanic = 1<<3,        // if the signal is from the kernel, panic
+       SigDefault = 1<<4,      // if the signal isn't explicitly requested, don't monitor it
 };
 
 // NOTE(rsc): keep in sync with extern.go:/type.Func.
@@ -501,6 +502,7 @@ Slice       runtime·gobytes(byte*, int32);
 String runtime·gostringnocopy(byte*);
 String runtime·gostringw(uint16*);
 void   runtime·initsig(void);
+void   runtime·sigenable(uint32 sig);
 int32  runtime·gotraceback(void);
 void   runtime·goroutineheader(G*);
 void   runtime·traceback(uint8 *pc, uint8 *sp, uint8 *lr, G* gp);
index c0b759c713604a8ae2fa7d560d6e8d17ca712146..996ce8b40e9ec080feeb6c3c7d9e9090a0af274e 100644 (file)
@@ -10,6 +10,11 @@ runtime·signame(int32)
        return runtime·emptystring;
 }
 
+void
+runtime·sigenable(uint32 sig)
+{
+}
+
 void
 runtime·resetcpuprofiler(int32 hz)
 {
index 14ce1418f818257e03bbba0b461b88aa6e1b74f1..13708415b98913f0aa12c3b4d93853741a3c6ef3 100644 (file)
@@ -27,9 +27,27 @@ runtime·initsig(void)
        // First call: basic setup.
        for(i = 0; i<NSIG; i++) {
                t = &runtime·sigtab[i];
-               if(t->flags == 0)
+               if((t->flags == 0) || (t->flags & SigDefault))
                        continue;
-               runtime·setsig(i, runtime·sighandler, 1);
+               runtime·setsig(i, runtime·sighandler, true);
+       }
+}
+
+void
+runtime·sigenable(uint32 sig)
+{
+       int32 i;
+       SigTab *t;
+
+       for(i = 0; i<NSIG; i++) {
+               // ~0 means all signals.
+               if(~sig == 0 || i == sig) {
+                       t = &runtime·sigtab[i];
+                       if(t->flags & SigDefault) {
+                               runtime·setsig(i, runtime·sighandler, true);
+                               t->flags &= ~SigDefault;  // make this idempotent
+                       }
+               }
        }
 }
 
index 0efa8c07317e003151ec3d1ee018191df14e786e..7b3492ff35ddb85fdec60e1c217cb10088e3b851 100644 (file)
@@ -80,6 +80,11 @@ runtime·sighandler(ExceptionRecord *info, Context *r, G *gp)
        return 0;
 }
 
+void
+runtime·sigenable(uint32 sig)
+{
+}
+
 void
 runtime·dosigprof(Context *r, G *gp)
 {
index 3db89e6d3e5f2f09b048dad3838c8834b16b48ab..e5e20fa0ba89cded420e3feed46801f3ae45b025 100644 (file)
@@ -87,6 +87,11 @@ runtime·sighandler(ExceptionRecord *info, Context *r, G *gp)
        return 0;
 }
 
+void
+runtime·sigenable(uint32 sig)
+{
+}
+
 void
 runtime·dosigprof(Context *r, G *gp)
 {
index 4ff08bcdc9f364786c405e6b87552c56dddc836b..229b585902565f4445d32a0d21980287545301ff 100644 (file)
@@ -6,6 +6,7 @@
 #define K SigKill
 #define T SigThrow
 #define P SigPanic
+#define D SigDefault
 
 SigTab runtime·sigtab[] = {
        /* 0 */ 0, "SIGNONE: no trap",
@@ -26,11 +27,11 @@ SigTab runtime·sigtab[] = {
        /* 15 */        N+K, "SIGTERM: termination",
        /* 16 */        N, "SIGURG: urgent condition on socket",
        /* 17 */        0, "SIGSTOP: stop",
-       /* 18 */        N, "SIGTSTP: keyboard stop",
+       /* 18 */        N+D, "SIGTSTP: keyboard stop",
        /* 19 */        0, "SIGCONT: continue after stop",
        /* 20 */        N, "SIGCHLD: child status has changed",
-       /* 21 */        N, "SIGTTIN: background read from tty",
-       /* 22 */        N, "SIGTTOU: background write to tty",
+       /* 21 */        N+D, "SIGTTIN: background read from tty",
+       /* 22 */        N+D, "SIGTTOU: background write to tty",
        /* 23 */        N, "SIGIO: i/o now possible",
        /* 24 */        N, "SIGXCPU: cpu limit exceeded",
        /* 25 */        N, "SIGXFSZ: file size limit exceeded",
@@ -46,3 +47,4 @@ SigTab runtime·sigtab[] = {
 #undef K
 #undef T
 #undef P
+#undef D
index 6a150173253a44fa9e28bf3b06a93810e8100d2e..4d27e050d089de91e83ba4b399d4254d60435716 100644 (file)
@@ -6,6 +6,7 @@
 #define K SigKill
 #define T SigThrow
 #define P SigPanic
+#define D SigDefault
 
 SigTab runtime·sigtab[] = {
        /* 0 */ 0, "SIGNONE: no trap",
@@ -26,11 +27,11 @@ SigTab runtime·sigtab[] = {
        /* 15 */        N+K, "SIGTERM: termination",
        /* 16 */        N, "SIGURG: urgent condition on socket",
        /* 17 */        0, "SIGSTOP: stop",
-       /* 18 */        N, "SIGTSTP: keyboard stop",
+       /* 18 */        N+D, "SIGTSTP: keyboard stop",
        /* 19 */        0, "SIGCONT: continue after stop",
        /* 20 */        N, "SIGCHLD: child status has changed",
-       /* 21 */        N, "SIGTTIN: background read from tty",
-       /* 22 */        N, "SIGTTOU: background write to tty",
+       /* 21 */        N+D, "SIGTTIN: background read from tty",
+       /* 22 */        N+D, "SIGTTOU: background write to tty",
        /* 23 */        N, "SIGIO: i/o now possible",
        /* 24 */        N, "SIGXCPU: cpu limit exceeded",
        /* 25 */        N, "SIGXFSZ: file size limit exceeded",
@@ -47,3 +48,4 @@ SigTab runtime·sigtab[] = {
 #undef K
 #undef T
 #undef P
+#undef D
index 1df063a187be28b6c86ac56f809d58d0c4c19d5a..345a6c5d11cc05d734b8316261a4fb0874146092 100644 (file)
@@ -6,6 +6,7 @@
 #define K SigKill
 #define T SigThrow
 #define P SigPanic
+#define D SigDefault
 
 SigTab runtime·sigtab[] = {
        /* 0 */ 0, "SIGNONE: no trap",
@@ -28,9 +29,9 @@ SigTab runtime·sigtab[] = {
        /* 17 */        N, "SIGCHLD: child status has changed",
        /* 18 */        0, "SIGCONT: continue",
        /* 19 */        0, "SIGSTOP: stop, unblockable",
-       /* 20 */        N, "SIGTSTP: keyboard stop",
-       /* 21 */        N, "SIGTTIN: background read from tty",
-       /* 22 */        N, "SIGTTOU: background write to tty",
+       /* 20 */        N+D, "SIGTSTP: keyboard stop",
+       /* 21 */        N+D, "SIGTTIN: background read from tty",
+       /* 22 */        N+D, "SIGTTOU: background write to tty",
        /* 23 */        N, "SIGURG: urgent condition on socket",
        /* 24 */        N, "SIGXCPU: cpu limit exceeded",
        /* 25 */        N, "SIGXFSZ: file size limit exceeded",
@@ -79,3 +80,4 @@ SigTab runtime·sigtab[] = {
 #undef K
 #undef T
 #undef P
+#undef D
index 6a150173253a44fa9e28bf3b06a93810e8100d2e..4d27e050d089de91e83ba4b399d4254d60435716 100644 (file)
@@ -6,6 +6,7 @@
 #define K SigKill
 #define T SigThrow
 #define P SigPanic
+#define D SigDefault
 
 SigTab runtime·sigtab[] = {
        /* 0 */ 0, "SIGNONE: no trap",
@@ -26,11 +27,11 @@ SigTab runtime·sigtab[] = {
        /* 15 */        N+K, "SIGTERM: termination",
        /* 16 */        N, "SIGURG: urgent condition on socket",
        /* 17 */        0, "SIGSTOP: stop",
-       /* 18 */        N, "SIGTSTP: keyboard stop",
+       /* 18 */        N+D, "SIGTSTP: keyboard stop",
        /* 19 */        0, "SIGCONT: continue after stop",
        /* 20 */        N, "SIGCHLD: child status has changed",
-       /* 21 */        N, "SIGTTIN: background read from tty",
-       /* 22 */        N, "SIGTTOU: background write to tty",
+       /* 21 */        N+D, "SIGTTIN: background read from tty",
+       /* 22 */        N+D, "SIGTTOU: background write to tty",
        /* 23 */        N, "SIGIO: i/o now possible",
        /* 24 */        N, "SIGXCPU: cpu limit exceeded",
        /* 25 */        N, "SIGXFSZ: file size limit exceeded",
@@ -47,3 +48,4 @@ SigTab runtime·sigtab[] = {
 #undef K
 #undef T
 #undef P
+#undef D
index 6a150173253a44fa9e28bf3b06a93810e8100d2e..4d27e050d089de91e83ba4b399d4254d60435716 100644 (file)
@@ -6,6 +6,7 @@
 #define K SigKill
 #define T SigThrow
 #define P SigPanic
+#define D SigDefault
 
 SigTab runtime·sigtab[] = {
        /* 0 */ 0, "SIGNONE: no trap",
@@ -26,11 +27,11 @@ SigTab runtime·sigtab[] = {
        /* 15 */        N+K, "SIGTERM: termination",
        /* 16 */        N, "SIGURG: urgent condition on socket",
        /* 17 */        0, "SIGSTOP: stop",
-       /* 18 */        N, "SIGTSTP: keyboard stop",
+       /* 18 */        N+D, "SIGTSTP: keyboard stop",
        /* 19 */        0, "SIGCONT: continue after stop",
        /* 20 */        N, "SIGCHLD: child status has changed",
-       /* 21 */        N, "SIGTTIN: background read from tty",
-       /* 22 */        N, "SIGTTOU: background write to tty",
+       /* 21 */        N+D, "SIGTTIN: background read from tty",
+       /* 22 */        N+D, "SIGTTOU: background write to tty",
        /* 23 */        N, "SIGIO: i/o now possible",
        /* 24 */        N, "SIGXCPU: cpu limit exceeded",
        /* 25 */        N, "SIGXFSZ: file size limit exceeded",
@@ -47,3 +48,4 @@ SigTab runtime·sigtab[] = {
 #undef K
 #undef T
 #undef P
+#undef D
index 02b575501228593f54ca5b5be3f7562b6b11332e..b49fdba86ea11bb53579130e19c4df1daab3ded3 100644 (file)
@@ -140,10 +140,12 @@ func signal_enable(s uint32) {
                // Special case: want everything.
                for(i=0; i<nelem(sig.wanted); i++)
                        sig.wanted[i] = ~(uint32)0;
+               runtime·sigenable(s);
                return;
        }
 
        if(s >= nelem(sig.wanted)*32)
                return;
        sig.wanted[s/32] |= 1U<<(s&31);
+       runtime·sigenable(s);
 }