[Sysfence-commit] sysfence/sys processtitle.c,1.1,1.2 sighandlers.c,1.1,1.2 sighandlers.h,1.1,1.2
Status: Alpha
Brought to you by:
emes
|
From: mkoperto <mko...@us...> - 2004-05-28 20:36:59
|
Update of /cvsroot/sysfence/sysfence/sys In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9235/sys Modified Files: processtitle.c sighandlers.c sighandlers.h Log Message: + improved handling / blocking signals Index: processtitle.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sys/processtitle.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- processtitle.c 26 May 2004 17:30:42 -0000 1.1 +++ processtitle.c 28 May 2004 20:36:50 -0000 1.2 @@ -62,12 +62,22 @@ switch (process) { case MAIN_PROCESS: - length = strlen (MAIN_PROCESS_NAME); + length = strlen (MAIN_PROCESS_NAME) + strlen (STATE_STOPPED_NAME); /* do nothing if title too long */ if (length + 1 > SPT_BUFSIZE) return; - - sprintf (buf, "%s", MAIN_PROCESS_NAME); + + switch (state) { + case STATE_NORMAL: + sprintf (buf, "%s", RULE_PROCESS_NAME); + break; + case STATE_STOPPED: + sprintf (buf, "%s %s", RULE_PROCESS_NAME, + STATE_STOPPED_NAME); + break; + default: + return; + } break; case RULE_PROCESS: if (!rulename) return; Index: sighandlers.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sys/sighandlers.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sighandlers.c 26 May 2004 17:30:42 -0000 1.1 +++ sighandlers.c 28 May 2004 20:36:50 -0000 1.2 @@ -28,16 +28,24 @@ #include "processtitle.h" -struct sigaction schildact, stermact, susr1act; +struct sigaction schildact, stermact, susr1act, scontact; +sigset_t sigblockset; void schild_action (int snumber); void sterm_action (int snumber); -void susr1_action (int snumber); +void susr1_parent_action (int snumber); +void susr1_child_action (int snumber); +void scont_parent_action (int snumber); +void scont_child_action (int snumber); void signal_init (int process) { + sigemptyset(&sigblockset); + sigaddset(&sigblockset, SIGTERM); + sigaddset(&sigblockset, SIGUSR1); + switch (process) { case PARENT: memset (&schildact, 0, sizeof(schildact)); @@ -48,41 +56,36 @@ stermact.sa_handler = &sterm_action; sigaction (SIGTERM, &stermact, NULL); + memset (&susr1act, 0, sizeof(susr1act)); + susr1act.sa_handler = &susr1_parent_action; + sigaction (SIGUSR1, &susr1act, NULL); + + memset (&scontact, 0, sizeof(scontact)); + scontact.sa_handler = &scont_parent_action; + sigaction (SIGCONT, &scontact, NULL); return; case CHILD: memset (&susr1act, 0, sizeof(susr1act)); - susr1act.sa_handler = &susr1_action; - sigaction (SIGCHLD, &susr1act, NULL); - - memset (&stermact, 0, sizeof(stermact)); - stermact.sa_handler = SIG_DFL; - sigaction (SIGTERM, &stermact, NULL); - + susr1act.sa_handler = &susr1_child_action; + sigaction (SIGUSR1, &susr1act, NULL); + + memset (&scontact, 0, sizeof(scontact)); + scontact.sa_handler = &scont_child_action; + sigaction (SIGCONT, &scontact, NULL); return; default: return; } - } -void signals (int onoff) +void signals_handling (int onoff) { switch (onoff) { - case SIGON: - susr1act.sa_handler = &susr1_action; - sigaction (SIGUSR1, &susr1act, NULL); - - stermact.sa_handler = SIG_DFL; - sigaction (SIGTERM, &stermact, NULL); - + case SIGBLOCK: + sigprocmask (SIG_BLOCK, &sigblockset, NULL); return; - case SIGOFF: - susr1act.sa_handler = SIG_IGN; - sigaction (SIGUSR1, &susr1act, NULL); - - stermact.sa_handler = SIG_IGN; - sigaction (SIGTERM, &stermact, NULL); - + case SIGUNBLOCK: + sigprocmask (SIG_UNBLOCK, &sigblockset, NULL); return; default: return; @@ -131,8 +134,37 @@ bail_out (EXIT_OK, NULL); } -void susr1_action (int snumber) +void susr1_parent_action (int snumber) { - //setproctitle (RULE_PROCESS, STATE_STOPPED, rule->name); + int i; + + /* send SIGUSR1 to child processes */ + for (i=0; i<rulecount; i++) + if (*(ruleprocesses + i)) kill ((pid_t)*(ruleprocesses + i), SIGUSR1); + + setproctitle (MAIN_PROCESS, STATE_STOPPED, NULL); raise (SIGSTOP); } + +void susr1_child_action (int snumber) +{ + setproctitle (RULE_PROCESS, STATE_STOPPED, rule->name); + raise (SIGSTOP); +} + +void scont_parent_action (int snumber) +{ + int i; + + /* send SIGCONT to child processes */ + for (i=0; i<rulecount; i++) + if (*(ruleprocesses + i)) kill ((pid_t)*(ruleprocesses + i), SIGCONT); + + setproctitle (MAIN_PROCESS, STATE_NORMAL, NULL); +} + +void scont_child_action (int snumber) +{ + setproctitle (RULE_PROCESS, STATE_NORMAL, rule->name); +} + Index: sighandlers.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/sys/sighandlers.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sighandlers.h 26 May 2004 17:30:42 -0000 1.1 +++ sighandlers.h 28 May 2004 20:36:50 -0000 1.2 @@ -15,8 +15,8 @@ #define PARENT 0 #define CHILD 1 -#define SIGON 0 -#define SIGOFF 1 +#define SIGBLOCK 0 +#define SIGUNBLOCK 1 -void signal_init (); -void signals (int onoff); +void signal_init (int process); +void signals_handling (int onoff); |