diff options
-rw-r--r-- | include/libc.h | 8 | ||||
-rw-r--r-- | src/lib9/notify.c | 41 |
2 files changed, 29 insertions, 20 deletions
diff --git a/include/libc.h b/include/libc.h index 2528ee98..653606a1 100644 --- a/include/libc.h +++ b/include/libc.h @@ -722,10 +722,10 @@ extern int unmount(char*, char*); */ extern int noted(int); extern int notify(void(*)(void*, char*)); -extern void noteenable(char*); -extern void notedisable(char*); -extern void notifyon(char*); -extern void notifyoff(char*); +extern int noteenable(char*); +extern int notedisable(char*); +extern int notifyon(char*); +extern int notifyoff(char*); extern int p9open(char*, int); extern int fd2path(int, char*, int); extern int p9pipe(int*); diff --git a/src/lib9/notify.c b/src/lib9/notify.c index 364181ca..c4675be1 100644 --- a/src/lib9/notify.c +++ b/src/lib9/notify.c @@ -36,6 +36,13 @@ struct Sig int notified; /* do we call the notify function for this signal? */ }; +/* + * Bug. It is profoundly anti-social to play with the masks like this. + * For example, even though we don't want to see SIGTSTP, others do. + * Running bash inside a 9term that has disabled SIGTSTP makes ^Z not work. + * Instead we need to leave the signals enabled but notifyoff them. + */ + /* initial settings; for current status, ask the kernel */ static Sig sigs[] = { SIGHUP, 0, 1, 1, @@ -172,40 +179,41 @@ handler(int s) return sa.sa_handler; } -static void +static int notesetenable(int sig, int enabled) { - sigset_t mask; + sigset_t mask, omask; if(sig == 0) - return; + return -1; sigemptyset(&mask); sigaddset(&mask, sig); - sigprocmask(enabled ? SIG_UNBLOCK : SIG_BLOCK, &mask, nil); + sigprocmask(enabled ? SIG_UNBLOCK : SIG_BLOCK, &mask, &omask); + return !sigismember(&omask, sig); } -void +int noteenable(char *msg) { - notesetenable(_p9strsig(msg), 1); + return notesetenable(_p9strsig(msg), 1); } -void +int notedisable(char *msg) { - notesetenable(_p9strsig(msg), 0); + return notesetenable(_p9strsig(msg), 0); } -static void +static int notifyseton(int s, int on) { Sig *sig; - struct sigaction sa; + struct sigaction sa, osa; sig = findsig(s); if(sig == nil) - return; + return -1; memset(&sa, 0, sizeof sa); sa.sa_handler = on ? signotify : signonotify; if(sig->restart) @@ -220,19 +228,20 @@ notifyseton(int s, int on) /* * Install handler. */ - sigaction(sig->sig, &sa, nil); + sigaction(sig->sig, &sa, &osa); + return osa.sa_handler == signotify; } -void +int notifyon(char *msg) { - notifyseton(_p9strsig(msg), 1); + return notifyseton(_p9strsig(msg), 1); } -void +int notifyoff(char *msg) { - notifyseton(_p9strsig(msg), 0); + return notifyseton(_p9strsig(msg), 0); } /* |