From: Harlan Stenn Date: Wed, 21 Dec 2005 02:46:45 +0000 (-0500) Subject: [Bug 536] Clean up the filegen initialization X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b73d4dcdc99c55e173ad003708d424731b8df8f;p=thirdparty%2Fntp.git [Bug 536] Clean up the filegen initialization bk: 43a8c215hEmIbxr3BNcd9iOLjnE-vg --- diff --git a/ntpd/ntp_filegen.c b/ntpd/ntp_filegen.c index c7fcbc4b4d..294b0fe2d3 100644 --- a/ntpd/ntp_filegen.c +++ b/ntpd/ntp_filegen.c @@ -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 ( diff --git a/ntpd/ntp_util.c b/ntpd/ntp_util.c index 45840037f5..2c50dc1bfc 100644 --- a/ntpd/ntp_util.c +++ b/ntpd/ntp_util.c @@ -28,13 +28,13 @@ #endif #ifdef DOSYNCTODR -#if !defined(VMS) -#include -#endif /* VMS */ +# if !defined(VMS) +# include +# endif /* VMS */ #endif #if defined(VMS) -#include +# include #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);