From: Adam Dickmeiss Date: Fri, 14 Feb 2014 19:26:26 +0000 (+0100) Subject: Avoid yaz_log in sigterm handler YAZ-737 X-Git-Tag: v5.0.13~4 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=f31f3ef3afee001257b555e9a94c502a09de3fc4;p=yaz-moved-to-github.git Avoid yaz_log in sigterm handler YAZ-737 Logging is still performed, but outwide sig handler. --- diff --git a/src/eventl.c b/src/eventl.c index 3516f79..be79cf3 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -78,7 +78,7 @@ int iochan_is_alive(IOCHAN chan) return 1; } -int iochan_event_loop(IOCHAN *iochans) +int iochan_event_loop(IOCHAN *iochans, int *watch_sig) { do /* loop as long as there are active associations to process */ { @@ -127,6 +127,8 @@ int iochan_event_loop(IOCHAN *iochans) if (yaz_errno() == EINTR) { xfree(fds); + if (watch_sig && *watch_sig) + break; continue; } else diff --git a/src/eventl.h b/src/eventl.h index fb06d21..c80392c 100644 --- a/src/eventl.h +++ b/src/eventl.h @@ -79,7 +79,7 @@ int force_event; IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, int port); int iochan_is_alive(IOCHAN chan); -int iochan_event_loop(IOCHAN *iochans); +int iochan_event_loop(IOCHAN *iochans, int *watch_sig); void statserv_remove (IOCHAN pIOChannel); #endif /* diff --git a/src/statserv.c b/src/statserv.c index b43dcac..59bb868 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -832,7 +832,7 @@ static void statserv_closedown() void __cdecl event_loop_thread(IOCHAN iochan) { - iochan_event_loop(&iochan); + iochan_event_loop(&iochan, 0); } /* WIN32 listener */ @@ -1080,7 +1080,7 @@ static void *new_session(void *vp) control_block.one_shot = 1; if (control_block.threads) { - iochan_event_loop(&new_chan); + iochan_event_loop(&new_chan, 0); } else { @@ -1247,20 +1247,21 @@ static void statserv_reset(void) { } -static void daemon_handler(void *data) -{ - IOCHAN *pListener = data; - iochan_event_loop(pListener); -} +static int sig_received = 0; #ifndef WIN32 static void normal_stop_handler(int num) { - yaz_log(log_server, "Received SIGTERM. PID=%ld", (long) getpid()); - exit(0); + sig_received = num; } #endif +static void daemon_handler(void *data) +{ + IOCHAN *pListener = data; + iochan_event_loop(pListener, &sig_received); +} + static void show_version(void) { char vstr[20], sha1_str[41]; @@ -1335,6 +1336,10 @@ static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) daemon_handler, &pListener, *control_block.pid_fname ? control_block.pid_fname : 0, *control_block.setuid ? control_block.setuid : 0); +#ifndef WIN32 + if (sig_received) + yaz_log(YLOG_LOG, "Received SIGTERM PID=%ld", (long) getpid()); +#endif return 0; }