]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Add support for running the nodebug version no as a service
authorDanny Mayer <mayer@ntp.org>
Mon, 5 May 2003 13:40:44 +0000 (09:40 -0400)
committerDanny Mayer <mayer@ntp.org>
Mon, 5 May 2003 13:40:44 +0000 (09:40 -0400)
bk: 3eb669dcpc6r9wBHACzvFiBOzv-iQA

ntpd/cmd_args.c
ntpd/ntpd.c
ports/winnt/libntp/libntp.dsp

index 52359b3de259f745d932f5752ba2c09ae5abd4b0..401489c431960a306b727a358e8f5f8b6fe4620b 100644 (file)
@@ -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;
 
index 7bd764f7a02931e5865812ccfa9b8383106a14f8..a6bebc45dc28bde12f81baa738ce3f5b9f8a82aa 100644 (file)
 /* 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)
        }
index f381549f667115d17397d0799d95255273ebd39f..8cd426de10e25ebc50123aa3086270a9d7ccad21 100644 (file)
@@ -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