From: Zoran V. <vas...@us...> - 2005-06-27 17:47:14
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10075/nsd Modified Files: tclcmds.c nswin32.c Log Message: Removed NsTclFailServiceObjCmd() and tied the processing to the NS_SIGINT signal as sent by the -restart option of the "ns_shutdown" command, hence avoiding different ways to force server restarts on different platforms. Removed experimental ReportException() call since it does not really seem to prevent the default handling in Windows where a Window pops up and the user has to confirm (such behaviour prevents the service control manager to restart the service). Index: nswin32.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/nswin32.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** nswin32.c 24 Jun 2005 08:40:27 -0000 1.7 --- nswin32.c 27 Jun 2005 17:46:58 -0000 1.8 *************** *** 51,55 **** static void ExitService(void); static char *GetServiceName(Ns_DString *dsPtr, char *server); - static int ReportException(int ec, char *msg); static SERVICE_STATUS_HANDLE hStatus = 0; static SERVICE_STATUS curStatus; --- 51,54 ---- *************** *** 340,344 **** * * Loop endlessly, processing HUP signals until a TERM ! * signal arrives. * * Results: --- 339,343 ---- * * Loop endlessly, processing HUP signals until a TERM ! * signal arrives * * Results: *************** *** 354,358 **** NsHandleSignals(void) { ! int pending; /* --- 353,357 ---- NsHandleSignals(void) { ! int sig; /* *************** *** 374,384 **** Ns_CondWait(&cond, &lock); } ! pending = sigpending; sigpending = 0; Ns_MutexUnlock(&lock); ! if (pending & NS_SIGHUP) { NsRunSignalProcs(); } ! } while (!(pending & NS_SIGTERM)); /* --- 373,392 ---- Ns_CondWait(&cond, &lock); } ! sig = sigpending; sigpending = 0; + if ((sig & NS_SIGINT)) { + + /* + * Signalize the Service Control Manager + * to restart the service. + */ + + servicefailed = 1; + } Ns_MutexUnlock(&lock); ! if ((sig & NS_SIGHUP)) { NsRunSignalProcs(); } ! } while (sig == NS_SIGHUP); /* *************** *** 391,395 **** } ! return pending; } --- 399,403 ---- } ! return sig; } *************** *** 937,963 **** ServiceMain(DWORD argc, LPTSTR *argv) { ! __try { ! hStatus = RegisterServiceCtrlHandler(argv[0], ServiceHandler); ! if (hStatus == 0) { ! Ns_Fatal("nswin32: RegisterServiceCtrlHandler() failed: '%s'", ! SysErrMsg()); ! } ! curStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ! curStatus.dwServiceSpecificExitCode = 0; ! StartTicker(SERVICE_START_PENDING); ! Ns_Main(argc, argv, NULL); ! StopTicker(); ! ReportStatus(SERVICE_STOP_PENDING, NO_ERROR, 100); ! if (!servicefailed) { ! ReportStatus(SERVICE_STOPPED, 0, 0); ! } ! Ns_Log(Notice, "nswin32: service exiting"); ! ! if(servicefailed) { ! exit(-1); ! } } ! __except (ReportException(GetExceptionCode(), "ServiceMain")) { ! // No code; this block is never executed. } } --- 945,965 ---- ServiceMain(DWORD argc, LPTSTR *argv) { ! hStatus = RegisterServiceCtrlHandler(argv[0], ServiceHandler); ! if (hStatus == 0) { ! Ns_Fatal("nswin32: RegisterServiceCtrlHandler() failed: '%s'", ! SysErrMsg()); } ! curStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ! curStatus.dwServiceSpecificExitCode = 0; ! StartTicker(SERVICE_START_PENDING); ! Ns_Main(argc, argv, NULL); ! StopTicker(); ! ReportStatus(SERVICE_STOP_PENDING, NO_ERROR, 100); ! if (!servicefailed) { ! ReportStatus(SERVICE_STOPPED, 0, 0); ! } ! Ns_Log(Notice, "nswin32: service exiting"); ! if(servicefailed) { ! exit(-1); } } *************** *** 1108,1163 **** return rc; } - - - /* - *---------------------------------------------------------------------- - * - * NsTclFailServiceObjCmd -- - * - * Tell the server not to unregister from the Service Control Manager - * (SCM) when exiting, effectively leaving SCM wondering about the - * service, thinking it failed and restarting it - * (provided restarting the serice is configured in SCM). - * - * Results: - * None. - * - *---------------------------------------------------------------------- - */ - - int - NsTclFailServiceObjCmd(ClientData dummy, Tcl_Interp *interp, int argc, char **argv) - { - servicefailed = 1; - - return TCL_OK; - } - - /* - *---------------------------------------------------------------------- - * - * reportException -- - * - * Handle expecptions - cause the server to terminate abruptly - * and leave a log trace. It is intended to prevents the default - * handling in Windows where a Window pops up and the user has to - * confirm - which then prevents the service control manager to - * restart the service. (The idea, however, does not seem to work - * as intended - Windows still brings up the popup for reporting - * the "bug" to Microsoft). - * - * Results: - * None. - * - * Side effects: - * Exits the server - * - *---------------------------------------------------------------------- - */ - - static int ReportException(int ec, char *msg) - { - fprintf(stderr, "EXCEPTION %x in %s\n", ec, msg); fflush(stderr); - exit(-1); - return EXCEPTION_EXECUTE_HANDLER; - } --- 1110,1111 ---- Index: tclcmds.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclcmds.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** tclcmds.c 27 Jun 2005 16:22:30 -0000 1.15 --- tclcmds.c 27 Jun 2005 17:46:56 -0000 1.16 *************** *** 81,85 **** NsTclDummyObjCmd, NsTclICtlObjCmd, - NsTclFailServiceObjCmd, NsTclFTruncateObjCmd, NsTclGetAddrObjCmd, --- 81,84 ---- *************** *** 587,596 **** /* - * nswin32.c - */ - #ifdef WIN32 - {"ns_failservice", NULL, NsTclFailServiceObjCmd}, - #endif - /* * Add more server Tcl commands here. */ --- 586,589 ---- |