From: Adam Dickmeiss Date: Tue, 26 Nov 2002 13:15:42 +0000 (+0000) Subject: Fix SIGTERM handling in frontend server X-Git-Tag: YAZ.1.9.2~7 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=adbeacef10c4a91ba652516dff43c16fb3258f36;p=yaz-moved-to-github.git Fix SIGTERM handling in frontend server --- diff --git a/CHANGELOG b/CHANGELOG index d509bce..e0f624d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,10 @@ Possible compatibility problems with earlier versions marked with '*'. -Move retrieval (data1) module to Zebra since nobody seems -to be using it. +Fix bad race conditions on SIGTERM and terminate gracefully in +frontend server. + +Move retrieval (data1) module to Zebra since nobody seems to be +using it. Add GRS-1 render for ZOOM using same format as yaz-client. diff --git a/server/eventl.c b/server/eventl.c index 0ba7f4a..2ed53c6 100644 --- a/server/eventl.c +++ b/server/eventl.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: eventl.c,v 1.32 2002-09-25 12:37:07 adam Exp $ + * $Id: eventl.c,v 1.33 2002-11-26 13:15:42 adam Exp $ */ #include @@ -60,6 +60,13 @@ int event_loop(IOCHAN *iochans) static struct timeval nullto = {0, 0}, to; struct timeval *timeout; + if (statserv_must_terminate()) + { + fprintf (stderr, "must terminate 1\n"); + + for (p = *iochans; p; p = p->next) + p->force_event = EVENT_TIMEOUT; + } FD_ZERO(&in); FD_ZERO(&out); FD_ZERO(&except); @@ -84,7 +91,14 @@ int event_loop(IOCHAN *iochans) if (res < 0) { if (yaz_errno() == EINTR) - continue; + { + if (statserv_must_terminate()) + { + for (p = *iochans; p; p = p->next) + p->force_event = EVENT_TIMEOUT; + } + continue; + } else { /* Destroy the first member in the chain, and try again */ diff --git a/server/session.h b/server/session.h index 2e55035..45d5cb0 100644 --- a/server/session.h +++ b/server/session.h @@ -1,90 +1,9 @@ /* - * Copyright (C) 1995-1999, Index Data + * Copyright (C) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: session.h,v $ - * Revision 1.25 2001-07-19 19:51:42 adam - * Added typecasts to make C++ happy. - * - * Revision 1.24 2000/11/23 10:58:32 adam - * SSL comstack support. Separate POSIX thread support library. - * - * Revision 1.23 2000/04/05 07:39:55 adam - * Added shared library support (libtool). - * - * Revision 1.22 2000/03/20 19:06:25 adam - * Added Segment request for fronend server. Work on admin for client. - * - * Revision 1.21 1999/11/30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.20 1999/10/11 10:01:24 adam - * Implemented bend_sort_rr handler for frontend server. - * - * Revision 1.19 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.18 1998/08/03 10:23:57 adam - * Fixed bug regarding Options for Sort. - * - * Revision 1.17 1998/07/20 12:38:43 adam - * Implemented delete result set service to server API. - * - * Revision 1.16 1998/03/31 11:07:45 adam - * Furhter work on UNIverse resource report. - * Added Extended Services handling in frontend server. - * - * Revision 1.15 1998/02/11 11:53:36 adam - * Changed code so that it compiles as C++. - * - * Revision 1.14 1998/02/10 11:03:57 adam - * Added support for extended handlers in backend server interface. - * - * Revision 1.13 1998/01/29 13:30:23 adam - * Better event handle system for NT/Unix. - * - * Revision 1.12 1997/09/01 08:53:01 adam - * New windows NT/95 port using MSV5.0. The test server 'ztest' was - * moved a separate directory. MSV5.0 project server.dsp created. - * As an option, the server can now operate as an NT service. - * - * Revision 1.11 1995/11/08 17:41:40 quinn - * Smallish. - * - * Revision 1.10 1995/08/29 11:18:01 quinn - * Added code to receive close - * - * Revision 1.9 1995/06/16 10:31:38 quinn - * Added session timeout. - * - * Revision 1.8 1995/05/17 08:42:28 quinn - * Transfer auth info to backend. Allow backend to reject init gracefully. - * - * Revision 1.7 1995/05/16 08:51:08 quinn - * License, documentation, and memory fixes - * - * Revision 1.6 1995/05/15 11:56:41 quinn - * Asynchronous facilities. Restructuring of seshigh code. - * - * Revision 1.5 1995/04/20 15:13:01 quinn - * Cosmetic - * - * Revision 1.4 1995/04/10 10:23:39 quinn - * Some work to add scan and other things. - * - * Revision 1.3 1995/03/30 09:09:27 quinn - * Added state-handle and some support for asynchronous activities. - * - * Revision 1.2 1995/03/27 08:34:29 quinn - * Added dynamic server functionality. - * Released bindings to session.c (is now redundant) - * - * Revision 1.1 1995/03/14 10:28:02 quinn - * More work on demo server. - * - * + * $Id: session.h,v 1.26 2002-11-26 13:15:42 adam Exp $ */ #ifndef SESSION_H @@ -191,4 +110,6 @@ void request_delq(request_q *q); request *request_get(request_q *q); void request_release(request *r); +int statserv_must_terminate(void); + #endif diff --git a/server/statserv.c b/server/statserv.c index 3e236bc..edfcfa8 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -6,7 +6,7 @@ * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.85 2002-09-25 12:37:07 adam Exp $ + * $Id: statserv.c,v 1.86 2002-11-26 13:15:42 adam Exp $ */ #include @@ -332,7 +332,15 @@ static void listener(IOCHAN h, int event) #else /* ! WIN32 */ -/* To save having an #ifdef in event_loop we need to define this empty function */ +static int term_flag = 0; +/* To save having an #ifdef in event_loop we need to + define this empty function +*/ +int statserv_must_terminate(void) +{ + return term_flag; +} + void statserv_remove(IOCHAN pIOChannel) { } @@ -341,17 +349,18 @@ void statserv_closedown() { IOCHAN p; +/* CHANGE */ if (control_block.bend_stop) (*control_block.bend_stop)(&control_block); - for (p = pListener; p; p = p->next) + { iochan_destroy(p); + } } void sigterm(int sig) { - statserv_closedown(); - exit (0); + term_flag = 1; } static void *new_session (void *vp); @@ -499,11 +508,15 @@ static void listener(IOCHAN h, int event) new_session(new_line); #endif } + else if (event == EVENT_TIMEOUT) + { + yaz_log(LOG_LOG, "Shutting down listener."); + iochan_destroy(h); + } else { yaz_log(LOG_FATAL, "Bad event on listener."); iochan_destroy(h); - return; } } @@ -559,7 +572,8 @@ static void *new_session (void *vp) return 0; } -#endif /* WIN32 */ +/* UNIX */ +#endif static void inetd_connection(int what) { @@ -647,14 +661,14 @@ static int add_listener(char *where, int what) } #ifndef WIN32 -/* For windows we don't need to catch the signals */ +/* UNIX only (for windows we don't need to catch the signals) */ static void catchchld(int num) { while (waitpid(-1, 0, WNOHANG) > 0) ; signal(SIGCHLD, catchchld); } -#endif /* WIN32 */ +#endif statserv_options_block *statserv_getcontrol(void) { @@ -676,7 +690,8 @@ int statserv_start(int argc, char **argv) #ifdef WIN32 /* We need to initialize the thread list */ ThreadList_Initialize(); -#endif /* WIN32 */ +/* WIN32 */ +#endif #ifdef WIN32 if ((me = strrchr (argv[0], '\\'))) @@ -694,6 +709,7 @@ int statserv_start(int argc, char **argv) #ifdef WIN32 logf (LOG_LOG, "Starting server %s", me); #else +/* UNIX */ if (control_block.inetd) inetd_connection(control_block.default_proto); else @@ -727,8 +743,10 @@ int statserv_start(int argc, char **argv) exit(1); } } -#endif /* WIN32 */ - +/* UNIX */ +#endif + + if ((pListener == NULL) && *control_block.default_listen) add_listener(control_block.default_listen, control_block.default_proto); @@ -896,7 +914,9 @@ void StopAppService(void *pHandle) /* Stops the app */ statserv_closedown(); } +/* WIN32 */ #else +/* UNIX */ int statserv_main(int argc, char **argv, bend_initresult *(*bend_init)(bend_initrequest *r), void (*bend_close)(void *handle))