]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 536] Clean up the filegen initialization
authorHarlan Stenn <stenn@ntp.org>
Wed, 21 Dec 2005 02:46:45 +0000 (21:46 -0500)
committerHarlan Stenn <stenn@ntp.org>
Wed, 21 Dec 2005 02:46:45 +0000 (21:46 -0500)
bk: 43a8c215hEmIbxr3BNcd9iOLjnE-vg

ntpd/ntp_filegen.c
ntpd/ntp_util.c

index c7fcbc4b4d20463d09fdf559bae61b981c9661de..294b0fe2d32071b2802d04a48c6d2cc7e9ef2608 100644 (file)
@@ -169,7 +169,8 @@ filegen_open(
                                        free(savename);
                                } else {
                                        /*
-                                        * there is at least a second link tpo this file
+                                        * there is at least a second link to
+                                        * this file.
                                         * just remove the conflicting one
                                         */
                                        if (
index 45840037f51f6c6e8483d1d8eef4cff4b56e789c..2c50dc1bfc035c308486a15e316cce139d967d32 100644 (file)
 #endif
 
 #ifdef  DOSYNCTODR
-#if !defined(VMS)
-#include <sys/resource.h>
-#endif /* VMS */
+# if !defined(VMS)
+#  include <sys/resource.h>
+# endif /* VMS */
 #endif
 
 #if defined(VMS)
-#include <descrip.h>
+# include <descrip.h>
 #endif /* VMS */
 
 /*
@@ -58,15 +58,15 @@ static      char *stats_temp_file;
  * Statistics file stuff
  */
 #ifndef NTP_VAR
-#ifndef SYS_WINNT
-#define NTP_VAR "/var/NTP/"            /* NOTE the trailing '/' */
-#else
-#define NTP_VAR "c:\\var\\ntp\\"               /* NOTE the trailing '\\' */
-#endif /* SYS_WINNT */
+# ifndef SYS_WINNT
+#  define NTP_VAR "/var/NTP/"          /* NOTE the trailing '/' */
+# else
+#  define NTP_VAR "c:\\var\\ntp\\"             /* NOTE the trailing '\\' */
+# endif /* SYS_WINNT */
 #endif
 
 #ifndef MAXPATHLEN
-#define MAXPATHLEN 256
+# define MAXPATHLEN 256
 #endif
 
 static char statsdir[MAXPATHLEN] = NTP_VAR;
@@ -91,6 +91,24 @@ int stats_control;
  */
 double old_drift;
 
+static void setup_FILEGEN P((FILEGEN *fp));
+
+/*
+ * setup_FILEGEN
+ */
+
+static void
+setup_FILEGEN(FILEGEN *fp)
+{
+       fp->fp       = NULL;
+       fp->prefix   = &statsdir[0];
+       fp->basename = (char*)emalloc(1);
+       fp->basename[0] = 0;
+       fp->id       = 0;
+       fp->type     = FILEGEN_DAY;
+       fp->flag     = FGEN_FLAG_LINK; /* not yet enabled !!*/
+}
+
 /*
  * init_util - initialize the utilities
  */
@@ -101,79 +119,26 @@ init_util(void)
        stats_temp_file = 0;
        key_file_name = 0;
 
-#define PEERNAME "peerstats"
-#define LOOPNAME "loopstats"
-#define CLOCKNAME "clockstats"
-#define RAWNAME "rawstats"
-#define STANAME "systats"
-#ifdef OPENSSL
-#define CRYPTONAME "cryptostats"
-#endif /* OPENSSL */
-
-       peerstats.fp       = NULL;
-       peerstats.prefix   = &statsdir[0];
-       peerstats.basename = (char*)emalloc(strlen(PEERNAME)+1);
-       strcpy(peerstats.basename, PEERNAME);
-       peerstats.id       = 0;
-       peerstats.type     = FILEGEN_DAY;
-       peerstats.flag     = FGEN_FLAG_LINK; /* not yet enabled !!*/
+       setup_FILEGEN(&peerstats);
        filegen_register("peerstats", &peerstats);
-       
-       loopstats.fp       = NULL;
-       loopstats.prefix   = &statsdir[0];
-       loopstats.basename = (char*)emalloc(strlen(LOOPNAME)+1);
-       strcpy(loopstats.basename, LOOPNAME);
-       loopstats.id       = 0;
-       loopstats.type     = FILEGEN_DAY;
-       loopstats.flag     = FGEN_FLAG_LINK; /* not yet enabled !!*/
+
+       setup_FILEGEN(&loopstats);
        filegen_register("loopstats", &loopstats);
 
-       clockstats.fp      = NULL;
-       clockstats.prefix  = &statsdir[0];
-       clockstats.basename = (char*)emalloc(strlen(CLOCKNAME)+1);
-       strcpy(clockstats.basename, CLOCKNAME);
-       clockstats.id      = 0;
-       clockstats.type    = FILEGEN_DAY;
-       clockstats.flag    = FGEN_FLAG_LINK; /* not yet enabled !!*/
+       setup_FILEGEN(&clockstats);
        filegen_register("clockstats", &clockstats);
 
-       rawstats.fp      = NULL;
-       rawstats.prefix  = &statsdir[0];
-       rawstats.basename = (char*)emalloc(strlen(RAWNAME)+1);
-       strcpy(rawstats.basename, RAWNAME);
-       rawstats.id      = 0;
-       rawstats.type    = FILEGEN_DAY;
-       rawstats.flag    = FGEN_FLAG_LINK; /* not yet enabled !!*/
+       setup_FILEGEN(&rawstats);
        filegen_register("rawstats", &rawstats);
 
-       sysstats.fp      = NULL;
-       sysstats.prefix  = &statsdir[0];
-       sysstats.basename = (char*)emalloc(strlen(STANAME)+1);
-       strcpy(sysstats.basename, STANAME);
-       sysstats.id      = 0;
-       sysstats.type    = FILEGEN_DAY;
-       sysstats.flag    = FGEN_FLAG_LINK; /* not yet enabled !!*/
+       setup_FILEGEN(&sysstats);
        filegen_register("sysstats", &sysstats);
 
 #ifdef OPENSSL
-       cryptostats.fp   = NULL;
-       cryptostats.prefix = &statsdir[0];
-       cryptostats.basename = (char*)emalloc(strlen(CRYPTONAME)+1);
-       strcpy(cryptostats.basename, CRYPTONAME);
-       cryptostats.id   = 0;
-       cryptostats.type = FILEGEN_DAY;
-       cryptostats.flag = FGEN_FLAG_LINK; /* not yet enabled !!*/
+       setup_FILEGEN(&cryptostats);
        filegen_register("cryptostats", &cryptostats);
 #endif /* OPENSSL */
 
-#undef PEERNAME
-#undef LOOPNAME
-#undef CLOCKNAME
-#undef RAWNAME
-#undef STANAME
-#ifdef OPENSSL
-#undef CRYPTONAME
-#endif /* OPENSSL */
 }
 
 
@@ -281,7 +246,7 @@ hourly_stats(void)
 #ifndef NO_RENAME
                (void) rename(stats_temp_file, stats_drift_file);
 #else
-        /* we have no rename NFS of ftp in use*/
+               /* we have no rename NFS of ftp in use */
                if ((fp = fopen(stats_drift_file, "w")) == NULL) {
                        msyslog(LOG_ERR, "can't open %s: %m",
                            stats_drift_file);