From e7377c90323e05943dcf318c172a5728605fd9b5 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 27 Sep 2013 15:42:06 +0200 Subject: [PATCH] GFS: log when closing down - at least SIGTERM YAZ-684 Also change formatting WRT PID logging a bit. --- src/statserv.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/statserv.c b/src/statserv.c index 324ca4e..f84c345 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -1026,7 +1026,7 @@ static void *new_session(void *vp) a = 0; #endif yaz_log_xml_errors(0, YLOG_WARN); - yaz_log(log_session, "Session - OK %d %s %ld", + yaz_log(log_session, "Session - OK %d %s PID=%ld", no_sessions, a ? a : "[Unknown]", (long) getpid()); if (max_sessions && no_sessions >= max_sessions) control_block.one_shot = 1; @@ -1102,8 +1102,8 @@ static int add_listener(char *where, int listen_id) else mode = "static"; - yaz_log(log_server, "Adding %s listener on %s id=%d", mode, where, - listen_id); + yaz_log(log_server, "Adding %s listener on %s id=%d PID=%ld", mode, where, + listen_id, (long) getpid()); l = cs_create_host(where, 2, &ap); if (!l) @@ -1205,6 +1205,14 @@ static void daemon_handler(void *data) iochan_event_loop(pListener); } +#ifndef WIN32 +static void normal_stop_handler(int num) +{ + yaz_log(log_server, "Received SIGTERM. PID=%ld", (long) getpid()); + exit(0); +} +#endif + static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) { char sep; @@ -1257,8 +1265,10 @@ static int statserv_sc_main(yaz_sc_t s, int argc, char **argv) return 1; if (s) yaz_sc_running(s); - yaz_log(YLOG_DEBUG, "Entering event loop."); +#ifndef WIN32 + signal(SIGTERM, normal_stop_handler); +#endif yaz_daemon(programname, (control_block.background ? YAZ_DAEMON_FORK : 0), daemon_handler, &pListener, -- 1.7.10.4