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:-:";
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");
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;
/* 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 };
# 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 */
char *cp;
struct recvbuf *rbuflist;
struct recvbuf *rbuf;
- if(!debug)
+
+ if(!debug && NoWinService == FALSE)
{
/* register our service control handler */
sshStatusHandle = RegisterServiceCtrlHandler( TEXT("NetworkTimeProtocol"),
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)
}