X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=server%2Fstatserv.c;h=d831e50f5fe4abf204d1b2263e2d4e01aa102fb9;hb=9b92a8975685e36dd4c199a508cabf01de6ebef0;hp=d126b983eb3d9ff5de51b8ddbc5de3d29b844ea6;hpb=ec280185445fa342a6bf2f6a12ab3d29bbd1e54c;p=yaz-moved-to-github.git diff --git a/server/statserv.c b/server/statserv.c index d126b98..d831e50 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -1,12 +1,12 @@ /* - * Copyright (c) 1995-2002, Index Data + * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.81 2002-05-07 11:01:59 adam Exp $ + * $Id: statserv.c,v 1.89 2003-01-13 14:32:06 adam Exp $ */ #include @@ -243,7 +243,7 @@ void statserv_closedown() } } -void event_loop_thread (IOCHAN iochan) +void __cdecl event_loop_thread (IOCHAN iochan) { event_loop (&iochan); } @@ -330,9 +330,22 @@ static void listener(IOCHAN h, int event) } } +int statserv_must_terminate(void) +{ + return 0; +} + #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) { } @@ -343,15 +356,15 @@ void statserv_closedown() 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); @@ -402,6 +415,10 @@ static void listener(IOCHAN h, int event) } sprintf(nbuf, "%s(%d)", me, getpid()); yaz_log_init(control_block.loglevel, nbuf, 0); + /* ensure that bend_stop is not called when each child exits - + only for the main process .. + */ + control_block.bend_stop = 0; } else /* parent */ { @@ -412,7 +429,8 @@ static void listener(IOCHAN h, int event) char dummy[1]; int res; - if ((res = read(hand[0], dummy, 1)) < 0 && errno != EINTR) + if ((res = read(hand[0], dummy, 1)) < 0 && + yaz_errno() != EINTR) { yaz_log(LOG_FATAL|LOG_ERRNO, "handshake read"); return; @@ -498,11 +516,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; } } @@ -558,7 +580,8 @@ static void *new_session (void *vp) return 0; } -#endif /* WIN32 */ +/* UNIX */ +#endif static void inetd_connection(int what) { @@ -646,14 +669,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) { @@ -675,7 +698,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], '\\'))) @@ -693,11 +717,12 @@ 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 { - logf (LOG_LOG, "Starting server %s pid=%d", me, getpid()); + yaz_log (LOG_LOG, "Starting server %s pid=%d", me, getpid()); #if 0 sigset_t sigs_to_block; @@ -726,8 +751,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); @@ -831,7 +858,7 @@ int check_options(int argc, char **argv) fprintf(stderr, "Usage: %s [ -a -v " " -l -u -c -t " " -k -d " - " -ziST -w ... ]\n", me); + " -ziST1 -w ... ]\n", me); return 1; } } @@ -871,7 +898,7 @@ int statserv_main(int argc, char **argv, /* Now setup the service with the service controller */ SetupService(argc, argv, &ArgDetails, SZAPPNAME, cb->service_name, /* internal service name */ - cb->service_name, /* displayed name of the service */ + cb->service_display_name, /* displayed name */ SZDEPENDENCIES); return 0; } @@ -895,7 +922,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))