From: Jorrit Herder Date: Wed, 12 Oct 2005 15:06:00 +0000 (+0000) Subject: Minor fixes for RS. Install signal handlers. X-Git-Tag: v3.1.2a~638 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=ee1f2bcb3941284556bec78e0c0beb9522831b98;p=minix.git Minor fixes for RS. Install signal handlers. --- diff --git a/drivers/at_wini/at_wini.c b/drivers/at_wini/at_wini.c index d7e888a9b..552eb3c6c 100644 --- a/drivers/at_wini/at_wini.c +++ b/drivers/at_wini/at_wini.c @@ -290,7 +290,15 @@ PRIVATE struct driver w_dtab = { *===========================================================================*/ PUBLIC int main() { -/* Set special disk parameters then call the generic main loop. */ +/* Install signal handlers. Ask PM to transform signal into message. */ + struct sigaction sa; + + sa.sa_handler = SIG_MESS; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGTERM,&sa,NULL)<0) panic("RS","sigaction failed", errno); + + /* Set special disk parameters then call the generic main loop. */ init_params(); signal(SIGTERM, SIG_IGN); driver_task(&w_dtab); diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile index 7e35f4696..b512cc0d2 100644 --- a/drivers/memory/Makefile +++ b/drivers/memory/Makefile @@ -31,8 +31,8 @@ $(LIBDRIVER): # install with other drivers -install: /usr/sbin/$(DRIVER) -/usr/sbin/$(DRIVER): $(DRIVER) +install: /sbin/$(DRIVER) +/sbin/$(DRIVER): $(DRIVER) install -o root -cs $? $@ # clean up local files diff --git a/drivers/printer/printer.c b/drivers/printer/printer.c index fb4f8588d..72ba3c6aa 100644 --- a/drivers/printer/printer.c +++ b/drivers/printer/printer.c @@ -109,22 +109,8 @@ FORWARD _PROTOTYPE( void prepare_output, (void) ); FORWARD _PROTOTYPE( void do_initialize, (void) ); FORWARD _PROTOTYPE( void reply, (int code,int replyee,int proc,int status)); FORWARD _PROTOTYPE( void do_printer_output, (void) ); -FORWARD _PROTOTYPE( void signal_handler, (int sig) ); +FORWARD _PROTOTYPE( void do_signal, (message *m_ptr) ); -/*===========================================================================* - * signal_handler * - *===========================================================================*/ -PRIVATE void signal_handler(sig) -int sig; /* signal number */ -{ -/* Expect a SIGTERM signal when this server must shutdown. */ - if (sig == SIGTERM) { - printf("Shutting down PRINTER driver\n"); - exit(0); - } else { - printf("PRINTER got unknown signal\n"); - } -} /*===========================================================================* * printer_task * @@ -133,6 +119,14 @@ PUBLIC void main(void) { /* Main routine of the printer task. */ message pr_mess; /* buffer for all incoming messages */ + struct sigaction sa; + int s; + + /* Install signal handlers. Ask PM to transform signal into message. */ + sa.sa_handler = SIG_MESS; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGTERM,&sa,NULL)<0) panic("PRN","sigaction failed", errno); while (TRUE) { receive(ANY, &pr_mess); @@ -147,14 +141,31 @@ PUBLIC void main(void) case DEV_STATUS: do_status(&pr_mess); break; case CANCEL: do_cancel(&pr_mess); break; case HARD_INT: do_printer_output(); break; - case SYS_SIG: /* do nothing */ break; - case DEV_PING: notify(pr_mess.m_source); break; + case SYS_SIG: do_signal(&pr_mess); break; + case DEV_PING: notify(pr_mess.m_source); break; default: reply(TASK_REPLY, pr_mess.m_source, pr_mess.PROC_NR, EINVAL); } } } + +/*===========================================================================* + * do_signal * + *===========================================================================*/ +PRIVATE void do_signal(m_ptr) +message *m_ptr; /* signal message */ +{ + int sig; + sigset_t sigset = m_ptr->NOTIFY_ARG; + + /* Expect a SIGTERM signal when this server must shutdown. */ + if (sigismember(&sigset, SIGTERM)) { + exit(0); + } + /* Ignore all other signals. */ +} + /*===========================================================================* * do_write * *===========================================================================*/ @@ -204,7 +215,7 @@ register message *m_ptr; /* pointer to the newly arrived message */ } /*===========================================================================* - * output_done * + * output_done * *===========================================================================*/ PRIVATE void output_done() { @@ -237,14 +248,9 @@ PRIVATE void output_done() else { /* done! report back to FS */ status = orig_count; } -#if DEAD_CODE - reply(REVIVE, caller, proc_nr, status); - writing = FALSE; -#else revive_pending = TRUE; revive_status = status; notify(caller); -#endif } /*===========================================================================* @@ -311,7 +317,6 @@ int status; /* number of chars printed or error code */ PRIVATE void do_initialize() { /* Set global variables and initialize the printer. */ - static int initialized = FALSE; if (initialized) return; initialized = TRUE; diff --git a/drivers/tty/tty.c b/drivers/tty/tty.c index 68323afdb..323af8326 100644 --- a/drivers/tty/tty.c +++ b/drivers/tty/tty.c @@ -163,7 +163,6 @@ PUBLIC void main(void) message tty_mess; /* buffer for all incoming messages */ unsigned line; int r, s; - char *types[] = {"task","driver","server", "user"}; register struct proc *rp; register tty_t *tp; @@ -1506,7 +1505,7 @@ PRIVATE void tty_init() register tty_t *tp; int s; - struct sigaction sigact; + struct sigaction sa; /* Initialize the terminal lines. */ for (tp = FIRST_TTY,s=0; tp < END_TTY; tp++,s++) { @@ -1534,12 +1533,13 @@ PRIVATE void tty_init() } #if DEAD_CODE - /* Install signal handler to ignore SIGTERM. */ - sigact.sa_handler = SIG_IGN; - sigact.sa_mask = ~0; /* block all other signals */ - sigact.sa_flags = 0; /* default behaviour */ - if (sigaction(SIGTERM, &sigact, NULL) != OK) - report("TTY","warning, sigaction() failed", errno); + /* Install signal handlers. Ask PM to transform signal into message. */ + sa.sa_handler = SIG_MESS; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + if (sigaction(SIGTERM,&sa,NULL)<0) panic("TTY","sigaction failed", errno); + if (sigaction(SIGKMESS,&sa,NULL)<0) panic("TTY","sigaction failed", errno); + if (sigaction(SIGKSTOP,&sa,NULL)<0) panic("TTY","sigaction failed", errno); #endif }