From: Zoran V. <vas...@us...> - 2005-10-11 21:19:40
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18977/nsd Modified Files: nsmain.c Log Message: StartWathedServer clears signal handlers before re-starting the server. Index: nsmain.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nsmain.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** nsmain.c 9 Oct 2005 22:27:24 -0000 1.22 --- nsmain.c 11 Oct 2005 21:19:31 -0000 1.23 *************** *** 60,64 **** #ifdef __APPLE__ ! # define WAKEUP_IN_SECONDS 600 /* Wakeup watchdog after somuch seconds */ #else # define WAKEUP_IN_SECONDS 0 /* Wakeup watchdog after somuch seconds */ --- 60,64 ---- #ifdef __APPLE__ ! # define WAKEUP_IN_SECONDS 600 /* Wakeup watchdog after somany seconds */ #else # define WAKEUP_IN_SECONDS 0 /* Wakeup watchdog after somuch seconds */ *************** *** 1177,1181 **** WatchdogSIGALRMHandler(int sig) { ! if (kill((pid_t) nsconf.pid, 0) && errno == ESRCH) { SysLog(LOG_WARNING, "watchdog: server %d terminated?", nsconf.pid); nsconf.pid = 0; --- 1177,1181 ---- WatchdogSIGALRMHandler(int sig) { ! if (nsconf.pid && kill((pid_t) nsconf.pid, 0) && errno == ESRCH) { SysLog(LOG_WARNING, "watchdog: server %d terminated?", nsconf.pid); nsconf.pid = 0; *************** *** 1205,1209 **** { int ret, status; ! pid_t pid; char *msg; --- 1205,1209 ---- { int ret, status; ! pid_t pid, srvpid = nsconf.pid; char *msg; *************** *** 1226,1230 **** } ! SysLog(LOG_NOTICE, "watchdog: server %d %s (%d).", nsconf.pid, msg, ret); return ret ? NS_ERROR : NS_OK; --- 1226,1231 ---- } ! nsconf.pid = 0; ! SysLog(LOG_NOTICE, "watchdog: server %d %s (%d).", srvpid, msg, ret); return ret ? NS_ERROR : NS_OK; *************** *** 1252,1256 **** StartWatchedServer(void) { ! unsigned int setSigHandlers=0, startTime, numRestarts=0, restartWait=0; struct itimerval timer; --- 1253,1257 ---- StartWatchedServer(void) { ! unsigned int startTime, numRestarts = 0, restartWait = 0; struct itimerval timer; *************** *** 1264,1267 **** --- 1265,1274 ---- sleep(restartWait); } + if (WAKEUP_IN_SECONDS) { + memset(&timer, 0, sizeof(struct itimerval)); + setitimer(ITIMER_REAL, &timer, NULL); + ns_signal(SIGALRM, SIG_DFL); + } + ns_signal(SIGTERM, SIG_DFL); nsconf.pid = ns_fork(); if (nsconf.pid == -1) { *************** *** 1285,1313 **** * the server is still present. This tries to solve issues with * signal delivery on some systems where waitpid() fails to report ! * process exitus (i.e. it is just stuck). */ ! ! if (setSigHandlers == 0) { ! setSigHandlers = 1; timer.it_interval.tv_sec = WAKEUP_IN_SECONDS; timer.it_value.tv_sec = timer.it_interval.tv_sec; ! timer.it_value.tv_usec = timer.it_interval.tv_usec = 0; ! if (timer.it_value.tv_sec || timer.it_value.tv_usec) { ! setitimer(ITIMER_REAL, &timer, NULL); ! ns_signal(SIGALRM, WatchdogSIGALRMHandler); ! } ! ns_signal(SIGTERM, WatchdogSIGTERMHandler); } ! startTime = time(NULL); - if (WaitForServer() == NS_OK) { break; } - if ((time(NULL) - startTime) > MIN_WORK_SECONDS) { restartWait = numRestarts = 0; } - if (++numRestarts > MAX_NUM_RESTARTS) { SysLog(LOG_WARNING, "watchdog: exceeded restart limit of %d", --- 1292,1312 ---- * the server is still present. This tries to solve issues with * signal delivery on some systems where waitpid() fails to report ! * process exitus (i.e. just stuck, although the process is gone). */ ! ! if (WAKEUP_IN_SECONDS) { timer.it_interval.tv_sec = WAKEUP_IN_SECONDS; timer.it_value.tv_sec = timer.it_interval.tv_sec; ! setitimer(ITIMER_REAL, &timer, NULL); ! ns_signal(SIGALRM, WatchdogSIGALRMHandler); } ! ns_signal(SIGTERM, WatchdogSIGTERMHandler); startTime = time(NULL); if (WaitForServer() == NS_OK) { break; } if ((time(NULL) - startTime) > MIN_WORK_SECONDS) { restartWait = numRestarts = 0; } if (++numRestarts > MAX_NUM_RESTARTS) { SysLog(LOG_WARNING, "watchdog: exceeded restart limit of %d", *************** *** 1315,1319 **** break; } - restartWait *= 2; if (restartWait > MAX_RESTART_SECONDS) { --- 1314,1317 ---- *************** *** 1322,1326 **** restartWait = 1; } - } while (!watchdogExit); --- 1320,1323 ---- |