[Sysfence-commit] sysfence sighandlers.c,NONE,1.1
Status: Alpha
Brought to you by:
emes
|
From: mkoperto <mko...@us...> - 2004-05-20 14:43:31
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24499 Added Files: sighandlers.c Log Message: works only for SIGTERM --- NEW FILE: sighandlers.c --- /* copyright (c) 2004, Mirek Kopertowski <m.k...@po...> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation (see file COPYING for details). You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <signal.h> #include <sys/types.h> #include <sys/wait.h> #include <string.h> #include "exit.h" #include "parseopt/lex.h" #include "getstats.h" #include "conditions.h" #include "mainloop.h" #include "communication.h" #include <stdlib.h> struct sigaction schildact, stermact; void schild_action (int snumber); void sterm_action (int snumber); void signal_init () { memset (&schildact, 0, sizeof(schildact)); schildact.sa_handler = &schild_action; sigaction (SIGCHLD, &schildact, NULL); memset (&stermact, 0, sizeof(stermact)); stermact.sa_handler = &sterm_action; sigaction (SIGTERM, &stermact, NULL); } /* local functions ------------------------------------------------------------*/ void schild_action (int snumber) { int exitstatus, pid, i=0; pid = (int)wait (&exitstatus); while (*(ruleprocesses + i)!=pid) i++; *(ruleprocesses + i) = 0; } void sterm_action (int snumber) { int i; /* deactive handling SIGCHLD */ memset (&schildact, 0, sizeof(schildact)); schildact.sa_handler = SIG_IGN; sigaction (SIGCHLD, &schildact, NULL); /* terminate child processes */ for (i=0; i<rulecount; i++) if (*(ruleprocesses + i)) kill ((pid_t)*(ruleprocesses + i), SIGTERM); /* detach, deallocate shared memory */ shared_mem_detach ((void *)stat); shared_mem_del (shmid); /* deallocate semaphore */ semaphore_del (semid); bail_out (EXIT_OK, NULL); } |