]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Martin Burnicki's cleanup of command line options and setting the registry for NTP
authorDanny Mayer <mayer@ntp.org>
Sun, 17 Apr 2005 03:26:04 +0000 (23:26 -0400)
committerDanny Mayer <mayer@ntp.org>
Sun, 17 Apr 2005 03:26:04 +0000 (23:26 -0400)
bk: 4261d74cmonOy5iA5I8WEWIunxVOUw

include/ntp_cmdargs.h
libntp/msyslog.c
ntpd/cmd_args.c
ntpd/ntpd.c
ports/winnt/instsrv/Instsrv.dsp
ports/winnt/libntp/libntp.dsp
ports/winnt/libntp/log.c [deleted file]
ports/winnt/libntp/log.h [deleted file]
ports/winnt/ntpd/nt_clockstuff.c
ports/winnt/ntpd/ntservice.c

index e9ab9b1c29ccc181b5f31e8231468978817e9b90..1d9993db11031e32caa0f8bf1fab8b55c7585bd4 100644 (file)
@@ -2,3 +2,4 @@
 
 extern void    getstartup      P((int, char **));
 extern void    getCmdOpts      P((int, char **));
+extern void    ntpd_usage      P((void));
index f0e8872bc8d02029fc7641cbea9e6129550775f8..fe4d979e12675ca35e29bbd32d6175d8075f8404 100644 (file)
@@ -25,7 +25,6 @@
 
 #ifdef SYS_WINNT
 # include <stdarg.h>
-# include "..\ports\winnt\libntp\log.h"
 # include "..\ports\winnt\libntp\messages.h"
 #endif
 
index 82f9e5820abeb34b773712e7e8098b6bc8e3ea86..eb85c4fe39d768034f56e861a80cef1f62a770b4 100644 (file)
@@ -20,12 +20,29 @@ extern char const *progname;
 int    listen_to_virtual_ips = 1;
 char   *specific_interface = NULL;        /* interface name or IP address to bind to */
 
-static const char *ntp_options = "aAbB:c:C:dD:f:gi:k:l:L:nNO:p:P:qr:s:S:t:T:W:u:v:V:xY:Z:-:";
+static const char *ntp_options = "aAbB:c:C:dD:f:gHi:k:l:L:nNO:p:P:qr:s:S:t:T:W:u:v:V:xY:Z:-:";
 
 #ifdef HAVE_NETINFO
 extern int     check_netinfo;
 #endif
 
+
+void ntpd_usage( void )
+{
+               (void) fprintf(stderr, "usage: %s [ -abdgnqx ] [ -c config_file ]\n", progname);
+               (void) fprintf(stderr, "\t\t[ -f drift_file ] [ -k key_file ] [ -l log_file ]\n");
+               (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broadcast_delay ] [ -s stats_dir ]\n");
+               (void) fprintf(stderr, "\t\t[ -t trusted_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
+               (void) fprintf(stderr, "\t\t[ -L [ interface ] ]\n");
+#if defined(HAVE_SCHED_SETSCHEDULER)
+               (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
+#endif
+#ifdef HAVE_DROPROOT
+               (void) fprintf(stderr, "\t\t[ -u user[:group] ] [ -i jaildir ]\n");
+#endif
+}  /* ntpd_usage */
+
+
 /*
  * getstartup - search through the options looking for a debugging flag
  */
@@ -125,41 +142,30 @@ getstartup(
                    ++errflg;
                    break;
 
-           case '-':
-             if ( ! strcmp(ntp_optarg, "version") ) {
-               printf("%.80s: %.80s\n", progname, Version);
-               exit(0);
-             } else if ( ! strcmp(ntp_optarg, "help") ) {
-               /* usage(); */
-               /* exit(0); */
-               ++errflg;
-             } else if ( ! strcmp(ntp_optarg, "copyright") ) {
-               printf("unknown\n");
-               exit(0);
-             } else {
-               fprintf(stderr, "%.80s: Error unknown argument '--%.80s'\n",
-                       progname,
-                       ntp_optarg);
-               exit(12);
-             }
-             break;
+               case '-':
+                       if ( ! strcmp(ntp_optarg, "version") ) {
+                               printf("%.80s: %.80s\n", progname, Version);
+                               exit(0);
+                       } else if ( ! strcmp(ntp_optarg, "help") ) {
+                               ntpd_usage();
+                               exit(0);
+                       } else if ( ! strcmp(ntp_optarg, "copyright") ) {
+                               printf("unknown\n");
+                               exit(0);
+                       } else {
+                               fprintf(stderr, "%.80s: Error unknown argument '--%.80s'\n",
+                                       progname,
+                                       ntp_optarg);
+                               exit(12);
+                       }
+                       break;
 
                default:
                        break;
-               }
+           }
 
        if (errflg || ntp_optind != argc) {
-               (void) fprintf(stderr, "usage: %s [ -abdgnqx ] [ -c config_file ] [ -e e_delay ]\n", progname);
-               (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
-               (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
-               (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
-               (void) fprintf(stderr, "\t\t[ -L interface ]\n");
-#if defined(HAVE_SCHED_SETSCHEDULER)
-               (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
-#endif
-#ifdef HAVE_DROPROOT
-               (void) fprintf(stderr, "\t\t[ -u user[:group] ] [ -i chrootdir ]\n");
-#endif
+               ntpd_usage();
                exit(2);
        }
        ntp_optind = 0; /* reset ntp_optind to restart ntp_getopt */
@@ -397,17 +403,7 @@ getCmdOpts(
        }
 
        if (errflg || ntp_optind != argc) {
-               (void) fprintf(stderr, "usage: %s [ -abdgnx ] [ -c config_file ] [ -e e_delay ]\n", progname);
-               (void) fprintf(stderr, "\t\t[ -f freq_file ] [ -k key_file ] [ -l log_file ]\n");
-               (void) fprintf(stderr, "\t\t[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]\n");
-               (void) fprintf(stderr, "\t\t[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]\n");
-               (void) fprintf(stderr, "\t\t[ -L interface ]\n");
-#if defined(HAVE_SCHED_SETSCHEDULER)
-               (void) fprintf(stderr, "\t\t[ -P fixed_process_priority ]\n");
-#endif
-#ifdef HAVE_DROPROOT
-               (void) fprintf(stderr, "\t\t[ -u user[:group] ] [ -i chrootdir ]\n");
-#endif
+               ntpd_usage();
                exit(2);
        }
        return;
index 43360cbb569da46bef6084b9bfd89f457351db34..5a0d097ad9255c355bdd15d53b4fe56c3f888890 100644 (file)
@@ -43,7 +43,6 @@
 # include <signal.h>
 # include <process.h>
 # include <io.h>
-# include "../libntp/log.h"
 # include <clockstuff.h>
 #include "ntp_iocompletionport.h"
 #endif /* SYS_WINNT */
index d3e674c1529a5085de5c3fa3add4e6e5b7b230f6..be582f9d42dc96c042b1fe85059bc75ebd48ba59 100644 (file)
@@ -42,7 +42,7 @@ RSC=rc.exe
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\..\..\include" /I "..\include" /I "." /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "SYS_WINNT" /D "HAVE_CONFIG_H" /D _WIN32_WINNT=0x400 /YX"windows.h" /FD /c
+# ADD CPP /nologo /MT /W4 /GX /O2 /I "..\..\..\include" /I "..\include" /I "." /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "SYS_WINNT" /D "HAVE_CONFIG_H" /D _WIN32_WINNT=0x400 /YX"windows.h" /FD /c
 # ADD BASE RSC /l 0x409 /d "NDEBUG"
 # ADD RSC /l 0x409 /d "NDEBUG"
 BSC32=bscmake.exe
index 07b1c33d2de87383ded6065f0471f9dfffc68bd6..9cd2cb97fda9a1527f9bd8abf64da69d9268a72d 100644 (file)
@@ -246,10 +246,6 @@ SOURCE=..\..\..\libntp\lib_strbuf.c
 # End Source File
 # Begin Source File
 
-SOURCE=.\log.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\..\libntp\machines.c
 # End Source File
 # Begin Source File
@@ -486,10 +482,6 @@ SOURCE=..\..\..\libntp\lib_strbuf.h
 # End Source File
 # Begin Source File
 
-SOURCE=.\log.h
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\..\include\md5.h
 # End Source File
 # Begin Source File
diff --git a/ports/winnt/libntp/log.c b/ports/winnt/libntp/log.c
deleted file mode 100644 (file)
index 991b498..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/* Microsoft Developer Support Copyright (c) 1993 Microsoft Corporation. */
-
-/* Skip asynch rpc inclusion */
-#ifndef __RPCASYNC_H__
-#define __RPCASYNC_H__
-#endif
-
-#include <windows.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "messages.h"
-#include "log.h"
-
-#define PERR(bSuccess, api) {if(!(bSuccess)) printf("%s: Error %d from %s \
-    on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
-
-
-/*********************************************************************
-* FUNCTION: addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL)   *
-*                                                                    *
-* PURPOSE: Add a source name key, message DLL name value, and        *
-*          message type supported value to the registry              *
-*                                                                    *
-* INPUT: source name, path of message DLL                            *
-*                                                                    *
-* RETURNS: none                                                      *
-*********************************************************************/
-
-void addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL)
-{
-  HKEY hk;                      /* registry key handle */
-  DWORD dwData;
-  BOOL bSuccess;
-  char   regarray[200];
-  char *lpregarray = regarray;
-
-  /* When an application uses the RegisterEventSource or OpenEventLog
-     function to get a handle of an event log, the event loggging service
-     searches for the specified source name in the registry. You can add a
-     new source name to the registry by opening a new registry subkey
-     under the Application key and adding registry values to the new
-     subkey. */
-
-  strcpy(lpregarray, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
-  strcat(lpregarray, pszAppname);
-
-  /* Create a new key for our application */
-  bSuccess = RegCreateKey(HKEY_LOCAL_MACHINE,lpregarray, &hk);
-  PERR(bSuccess == ERROR_SUCCESS, "RegCreateKey");
-
-  /* Add the Event-ID message-file name to the subkey. */
-  bSuccess = RegSetValueEx(hk,  /* subkey handle         */
-      "EventMessageFile",       /* value name            */
-      0,                        /* must be zero          */
-      REG_EXPAND_SZ,            /* value type            */
-      (LPBYTE) pszMsgDLL,       /* address of value data */
-      strlen(pszMsgDLL) + 1);   /* length of value data  */
-  PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
-
-  /* Set the supported types flags and addit to the subkey. */
-  dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
-      EVENTLOG_INFORMATION_TYPE;
-  bSuccess = RegSetValueEx(hk,  /* subkey handle                */
-      "TypesSupported",         /* value name                   */
-      0,                        /* must be zero                 */
-      REG_DWORD,                /* value type                   */
-      (LPBYTE) &dwData,         /* address of value data        */
-      sizeof(DWORD));           /* length of value data         */
-  PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
-  RegCloseKey(hk);
-  return;
-}
-
-/*********************************************************************
-* FUNCTION: reportAnEvent(DWORD dwIdEvent, WORD cStrings,            *
-*                         LPTSTR *ppszStrings);                      *
-*                                                                    *
-* PURPOSE: add the event to the event log                            *
-*                                                                    *
-* INPUT: the event ID to report in the log, the number of insert     *
-*        strings, and an array of null-terminated insert strings     *
-*                                                                    *
-* RETURNS: none                                                      *
-*********************************************************************/
-
-void reportAnIEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
-{
-  HANDLE hAppLog;
-  BOOL bSuccess;
-
-  /* Get a handle to the Application event log */
-  hAppLog = RegisterEventSource(NULL,   /* use local machine      */
-      "NTP");                   /* source name                 */
-  PERR(hAppLog, "RegisterEventSource");
-
-  /* Now report the event, which will add this event to the event log */
-  bSuccess = ReportEvent(hAppLog,       /* event-log handle            */
-      EVENTLOG_INFORMATION_TYPE,      /* event type                  */
-      0,                        /* category zero               */
-      dwIdEvent,                /* event ID                    */
-      NULL,                     /* no user SID                 */
-      cStrings,                 /* number of substitution strings     */
-      0,                        /* no binary data              */
-      pszStrings,               /* string array                */
-      NULL);                    /* address of data             */
-  PERR(bSuccess, "ReportEvent");
-  DeregisterEventSource(hAppLog);
-  return;
-}
-
-void reportAnWEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
-{
-  HANDLE hAppLog;
-  BOOL bSuccess;
-
-  /* Get a handle to the Application event log */
-  hAppLog = RegisterEventSource(NULL,   /* use local machine      */
-      "NTP");                   /* source name                 */
-  PERR(hAppLog, "RegisterEventSource");
-
-  /* Now report the event, which will add this event to the event log */
-  bSuccess = ReportEvent(hAppLog,       /* event-log handle            */
-      EVENTLOG_WARNING_TYPE,      /* event type                  */
-      0,                        /* category zero               */
-      dwIdEvent,                /* event ID                    */
-      NULL,                     /* no user SID                 */
-      cStrings,                 /* number of substitution strings     */
-      0,                        /* no binary data              */
-      pszStrings,               /* string array                */
-      NULL);                    /* address of data             */
-  PERR(bSuccess, "ReportEvent");
-  DeregisterEventSource(hAppLog);
-  return;
-}
-
-void reportAnEEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
-{
-  HANDLE hAppLog;
-  BOOL bSuccess;
-
-  /* Get a handle to the Application event log */
-  hAppLog = RegisterEventSource(NULL,   /* use local machine      */
-      "NTP");                   /* source name                 */
-  PERR(hAppLog, "RegisterEventSource");
-
-  /* Now report the event, which will add this event to the event log */
-  bSuccess = ReportEvent(hAppLog,       /* event-log handle            */
-      EVENTLOG_ERROR_TYPE,      /* event type                  */
-      0,                        /* category zero               */
-      dwIdEvent,                /* event ID                    */
-      NULL,                     /* no user SID                 */
-      cStrings,                 /* number of substitution strings     */
-      0,                        /* no binary data              */
-      pszStrings,               /* string array                */
-      NULL);                    /* address of data             */
-  PERR(bSuccess, "ReportEvent");
-  DeregisterEventSource(hAppLog);
-  return;
-}
diff --git a/ports/winnt/libntp/log.h b/ports/winnt/libntp/log.h
deleted file mode 100644 (file)
index 0908f22..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * log.h - Used only under Windows NT by msyslog.c
- *
- */
-#ifndef WINNT_LOG_H
-#define WINNT_LOG_H
-
-#include <windows.h>
-#include <process.h>
-
-/* function declarations */
-
-void addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL);
-void reportAnIEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings);
-void reportAnWEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings);
-void reportAnEEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings);
-
-#define MAX_MSG_LENGTH 1024
-#define MSG_ID_MASK            0x0000FFFF
-#define MAX_INSERT_STRS        8
-
-#endif /* WINNT_LOG_H */
index d0cfd6cca458ecd1709b3bd3baf3faf30b1d19d2..9678c3127ea1052c988bd71814364fadf6b0210a 100644 (file)
@@ -49,7 +49,6 @@
 #include "clockstuff.h"
 #include "ntservice.h"
 #include "ntp_timer.h"
-# include "../libntp/log.h"
 
 extern double sys_residual;    /* residual from previous adjustment */
 
@@ -165,7 +164,6 @@ void init_winnt_time(void) {
                msyslog(LOG_ERR, "GetModuleFileName(PGM_EXE_FILE) failed: %m\n");
                exit(1);
        }
-       addSourceToRegistry("NTP", szMsgPath);
 
        /* Initialize random file before OpenSSL checks */
        if(!init_randfile())
index f3a5aed1849bdc3a5ac2f2fbae6e5082ed2367f4..8a3664a95cde075d8ebc199ae4244f99b8dc80fc 100644 (file)
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <stdio.h>
 
+#include <ntp_cmdargs.h>
 #include "syslog.h"
 #include "ntservice.h"
 #include "clockstuff.h"
@@ -37,6 +38,7 @@ extern char *Version;
 HANDLE hServDoneEvent = NULL;
 extern HANDLE WaitHandles[3];
 extern volatile int debug;
+extern char *progname;
 
 void uninit_io_completion_port();
 int ntpdmain(int argc, char *argv[]);
@@ -63,9 +65,9 @@ int main( int argc, char *argv[] )
        int rc,
        i = 1;
 
-  /* Save the command line parameters */
-  glb_argc = argc;
-  glb_argv = argv;
+       /* Save the command line parameters */
+       glb_argc = argc;
+       glb_argv = argv;
 
        /* Command line users should put -f in the options */
        while (argv[i]) {
@@ -91,9 +93,13 @@ int main( int argc, char *argv[] )
 
                rc = StartServiceCtrlDispatcher(dispatchTable);
                if (!rc) {
+                       progname = argv[0];
                        rc = GetLastError();
-                       fprintf(stderr, "StartServiceCtrlDispatcher returned: %i\n", rc);
-                       fprintf(stderr, "Use -f to run from the command line.\n");
+#ifdef DEBUG
+                       fprintf(stderr, "%s: unable to start as service, rc: %i\n\n", progname, rc);
+#endif
+                       ntpd_usage();
+                       fprintf(stderr, "\nUse -d, -q, or -n to run from the command line.\n");
                        exit(rc);
                }
        }