From: Danny Mayer Date: Mon, 5 May 2003 13:40:44 +0000 (-0400) Subject: Add support for running the nodebug version no as a service X-Git-Tag: NTP_4_1_80_RC1~29^2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13744fe3f6defb3d874af35f5ed71665ae0281cf;p=thirdparty%2Fntp.git Add support for running the nodebug version no as a service bk: 3eb669dcpc6r9wBHACzvFiBOzv-iQA --- diff --git a/ntpd/cmd_args.c b/ntpd/cmd_args.c index 52359b3de..401489c43 100644 --- a/ntpd/cmd_args.c +++ b/ntpd/cmd_args.c @@ -19,6 +19,9 @@ extern char const *progname; int listen_to_virtual_ips = 1; +#ifdef SYS_WINNT +extern BOOL NoWinService; +#endif #ifndef HAVE_CLOCKCTL static const char *ntp_options = "aAbB:c:C:dD:f:gk:l:LmnNO:p:P:qr:s:S:t:T:W:v:V:xY:Z:-:"; @@ -79,6 +82,14 @@ getstartup( break; #else case 'd': +/* + * We need to do this in order to have a way of running + * without running as a service + */ +#ifdef SYS_WINNT + NoWinService = TRUE; + break; +#endif case 'D': msyslog(LOG_ERR, "ntpd not compiled with -DDEBUG option - no DEBUG support"); fprintf(stderr, "ntpd not compiled with -DDEBUG option - no DEBUG support"); @@ -229,8 +240,16 @@ getCmdOpts( case 'd': #ifdef DEBUG debug++; +#else +/* + * We need to do this in order to have a way of running + * without running as a service + */ +#ifdef SYS_WINNT + NoWinService = TRUE; #else errflg++; +#endif #endif /* DEBUG */ break; diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 7bd764f7a..a6bebc45d 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -130,6 +130,7 @@ /* handles for various threads, process, and objects */ HANDLE ResolverThreadHandle = NULL; /* variables used to inform the Service Control Manager of our current state */ +BOOL NoWinService = FALSE; SERVICE_STATUS ssStatus; SERVICE_STATUS_HANDLE sshStatusHandle; HANDLE WaitHandles[3] = { NULL, NULL, NULL }; @@ -518,16 +519,22 @@ ntpdmain( # else /* SYS_WINNT */ { - SERVICE_TABLE_ENTRY dispatchTable[] = { + if (NoWinService == FALSE) { + SERVICE_TABLE_ENTRY dispatchTable[] = { { TEXT("NetworkTimeProtocol"), (LPSERVICE_MAIN_FUNCTION)service_main }, { NULL, NULL } - }; + }; - /* daemonize */ - if (!StartServiceCtrlDispatcher(dispatchTable)) - { - msyslog(LOG_ERR, "StartServiceCtrlDispatcher: %m"); - ExitProcess(2); + /* daemonize */ + if (!StartServiceCtrlDispatcher(dispatchTable)) + { + msyslog(LOG_ERR, "StartServiceCtrlDispatcher: %m"); + ExitProcess(2); + } + } + else { + service_main(argc, argv); + return 0; } } # endif /* SYS_WINNT */ @@ -554,7 +561,8 @@ service_main( char *cp; struct recvbuf *rbuflist; struct recvbuf *rbuf; - if(!debug) + + if(!debug && NoWinService == FALSE) { /* register our service control handler */ sshStatusHandle = RegisterServiceCtrlHandler( TEXT("NetworkTimeProtocol"), @@ -782,17 +790,19 @@ service_main( if(!debug) { # endif + if (NoWinService == FALSE) { /* report to the service control manager that the service is running */ - ssStatus.dwCurrentState = SERVICE_RUNNING; - ssStatus.dwWin32ExitCode = NO_ERROR; - if (!SetServiceStatus(sshStatusHandle, &ssStatus)) - { - msyslog(LOG_ERR, "SetServiceStatus: %m"); - if (ResolverThreadHandle != NULL) - CloseHandle(ResolverThreadHandle); - ssStatus.dwCurrentState = SERVICE_STOPPED; - SetServiceStatus(sshStatusHandle, &ssStatus); - return; + ssStatus.dwCurrentState = SERVICE_RUNNING; + ssStatus.dwWin32ExitCode = NO_ERROR; + if (!SetServiceStatus(sshStatusHandle, &ssStatus)) + { + msyslog(LOG_ERR, "SetServiceStatus: %m"); + if (ResolverThreadHandle != NULL) + CloseHandle(ResolverThreadHandle); + ssStatus.dwCurrentState = SERVICE_STOPPED; + SetServiceStatus(sshStatusHandle, &ssStatus); + return; + } } # if defined(DEBUG) } diff --git a/ports/winnt/libntp/libntp.dsp b/ports/winnt/libntp/libntp.dsp index f381549f6..8cd426de1 100644 --- a/ports/winnt/libntp/libntp.dsp +++ b/ports/winnt/libntp/libntp.dsp @@ -237,7 +237,7 @@ SOURCE=..\..\..\libntp\lib_strbuf.c # End Source File # Begin Source File -SOURCE=..\..\..\libntp\log.c +SOURCE=.\log.c # End Source File # Begin Source File @@ -457,15 +457,15 @@ SOURCE=..\..\..\libntp\lib_strbuf.h # End Source File # Begin Source File -SOURCE=..\..\..\libntp\log.h +SOURCE=.\log.h # End Source File # Begin Source File -SOURCE=.\log.h +SOURCE=..\..\..\include\md5.h # End Source File # Begin Source File -SOURCE=..\..\..\include\md5.h +SOURCE=..\..\..\include\isc\net.h # End Source File # Begin Source File