update return interface

This commit is contained in:
rsc 2005-01-16 21:28:44 +00:00
parent 32053cdfb3
commit 10f14b04f3
2 changed files with 29 additions and 20 deletions

View file

@ -722,10 +722,10 @@ extern int unmount(char*, char*);
*/ */
extern int noted(int); extern int noted(int);
extern int notify(void(*)(void*, char*)); extern int notify(void(*)(void*, char*));
extern void noteenable(char*); extern int noteenable(char*);
extern void notedisable(char*); extern int notedisable(char*);
extern void notifyon(char*); extern int notifyon(char*);
extern void notifyoff(char*); extern int notifyoff(char*);
extern int p9open(char*, int); extern int p9open(char*, int);
extern int fd2path(int, char*, int); extern int fd2path(int, char*, int);
extern int p9pipe(int*); extern int p9pipe(int*);

View file

@ -36,6 +36,13 @@ struct Sig
int notified; /* do we call the notify function for this signal? */ 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 */ /* initial settings; for current status, ask the kernel */
static Sig sigs[] = { static Sig sigs[] = {
SIGHUP, 0, 1, 1, SIGHUP, 0, 1, 1,
@ -172,40 +179,41 @@ handler(int s)
return sa.sa_handler; return sa.sa_handler;
} }
static void static int
notesetenable(int sig, int enabled) notesetenable(int sig, int enabled)
{ {
sigset_t mask; sigset_t mask, omask;
if(sig == 0) if(sig == 0)
return; return -1;
sigemptyset(&mask); sigemptyset(&mask);
sigaddset(&mask, sig); 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) noteenable(char *msg)
{ {
notesetenable(_p9strsig(msg), 1); return notesetenable(_p9strsig(msg), 1);
} }
void int
notedisable(char *msg) notedisable(char *msg)
{ {
notesetenable(_p9strsig(msg), 0); return notesetenable(_p9strsig(msg), 0);
} }
static void static int
notifyseton(int s, int on) notifyseton(int s, int on)
{ {
Sig *sig; Sig *sig;
struct sigaction sa; struct sigaction sa, osa;
sig = findsig(s); sig = findsig(s);
if(sig == nil) if(sig == nil)
return; return -1;
memset(&sa, 0, sizeof sa); memset(&sa, 0, sizeof sa);
sa.sa_handler = on ? signotify : signonotify; sa.sa_handler = on ? signotify : signonotify;
if(sig->restart) if(sig->restart)
@ -220,19 +228,20 @@ notifyseton(int s, int on)
/* /*
* Install handler. * Install handler.
*/ */
sigaction(sig->sig, &sa, nil); sigaction(sig->sig, &sa, &osa);
return osa.sa_handler == signotify;
} }
void int
notifyon(char *msg) notifyon(char *msg)
{ {
notifyseton(_p9strsig(msg), 1); return notifyseton(_p9strsig(msg), 1);
} }
void int
notifyoff(char *msg) notifyoff(char *msg)
{ {
notifyseton(_p9strsig(msg), 0); return notifyseton(_p9strsig(msg), 0);
} }
/* /*