ntp_util.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 1996, 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ntp_util.c - stuff I didn't have any other place for
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
# ifdef HAVE_SYS_IOCTL_H
# endif
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_unixtime.h"
#include "ntp_filegen.h"
#include "ntp_if.h"
#include "ntp_stdlib.h"
#ifdef DOSYNCTODR
#if !defined(VMS)
#include <sys/resource.h>
#endif /* VMS */
#endif
#if defined(VMS)
#include <descrip.h>
#endif /* VMS */
/*
* This contains odds and ends. Right now the only thing you'll find
* in here is the hourly stats printer and some code to support rereading
* the keys file, but I may eventually put other things in here such as
* code to do something with the leap bits.
*/
/*
* Name of the keys file
*/
static char *key_file_name;
/*
* The name of the drift_comp file and the temporary.
*/
static char *stats_drift_file;
static char *stats_temp_file;
extern l_fp zero_drift;
/*
* Statistics file stuff
*/
#ifndef NTP_VAR
#ifndef SYS_WINNT
#else
#endif /* SYS_WINNT */
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN 256
#endif
static FILEGEN clockstats;
/*
* We query the errno to see what kind of error occured
* when opening the drift file.
*/
#ifndef SYS_WINNT
extern int errno;
#endif /* SYS_WINNT */
/*
* This controls whether stats are written to the fileset. Provided
* so that xntpdc can turn off stats when the file system fills up.
*/
int stats_control;
#ifdef DEBUG
extern int debug;
#endif
/*
* init_util - initialize the utilities
*/
void
{
stats_drift_file = 0;
stats_temp_file = 0;
key_file_name = 0;
#define PEERNAME "peerstats"
#define LOOPNAME "loopstats"
#define CLOCKNAME "clockstats"
#define RAWNAME "rawstats"
clockstats.id = 0;
}
/*
* hourly_stats - print some interesting stats
*/
void
{
extern l_fp last_offset;
extern s_fp drift_comp;
#ifdef DOSYNCTODR
#ifdef HAVE_GETCLOCK
#endif
int o_prio;
/*
* Sometimes having a Sun can be a drag.
*
* The kernel variable dosynctodr controls whether the system's
* soft clock is kept in sync with the battery clock. If it
* is zero, then the soft clock is not synced, and the battery
* clock is simply left to rot. That means that when the system
* reboots, the battery clock (which has probably gone wacky)
* sets the soft clock. That means xntpd starts off with a very
* confused idea of what time it is. It then takes a large
* amount of time to figure out just how wacky the battery clock
* has made things drift, etc, etc. The solution is to make the
* battery clock sync up to system time. The way to do THAT is
* to simply set the time of day to the current time of day, but
* as quickly as possible. This may, or may not be a sensible
* thing to do.
*
* CAVEAT: settimeofday() steps the sun clock by about 800 us,
* so setting DOSYNCTODR seems a bad idea in the
* case of us resolution
*/
#if !defined(VMS)
{
goto skip;
}
#endif /* VMS */
#ifdef HAVE_GETCLOCK
#else /* not HAVE_GETCLOCK */
#endif /* not HAVE_GETCLOCK */
{
}
#if !defined(VMS)
#endif /* VMS */
skip:
#endif /* DOSYNCTODR */
sys_poll);
if (stats_drift_file != 0) {
return;
}
/* atomic */
#ifdef SYS_WINNT
#endif /* SYS_WINNT */
#ifndef NO_RENAME
#else
/* we have no rename NFS of ftp in use*/
return;
}
#endif
#if defined(VMS)
/* PURGE */
{
}
#endif
}
}
/*
* stats_config - configure the stats operation
*/
void
int item;
char *invalue; /* only one type so far */
{
int len;
/* Expand environment strings under Windows NT, since the command
* interpreter doesn't do this, the program must.
*/
#ifdef SYS_WINNT
{
switch(item) {
case STATS_FREQ_FILE:
break;
case STATS_STATSDIR:
break;
case STATS_PID_FILE:
break;
default:
break;
}
}
else
{
}
#else
#endif /* SYS_WINNT */
switch(item) {
case STATS_FREQ_FILE:
if (stats_drift_file != 0) {
(void) free(stats_drift_file);
(void) free(stats_temp_file);
stats_drift_file = 0;
stats_temp_file = 0;
}
break;
/*
* To avoid using the (possibly disruptive) stored
* drift value in the case where pll is disabled.
*/
"will *not* use clock drift file.");
break;
}
#if !defined(VMS)
#else
#endif /* VMS */
#if !defined(VMS)
#else
#endif /* VMS */
/*
* Open drift file and read frequency and mode.
*/
break;
}
break;
}
break;
}
{
if (cp)
*cp = '\0';
}
#ifdef DEBUG
if (debug > 0) {
}
#endif
break;
case STATS_STATSDIR:
"value for statsdir too long (>%d, sigh)",
sizeof(statsdir)-1);
} else {
get_systime(&now);
}
}
}
}
}
break;
case STATS_PID_FILE:
break;
}
break;
default:
/* oh well */
break;
}
}
/*
* record_peer_stats - write peer statistics to file
*
* file format:
* day (mjd)
* time (s past UTC midnight)
* peer (ip address)
* peer status word (hex)
* peer offset (s)
* peer delay (s)
* peer dispersion (s)
*/
void
struct sockaddr_in *addr;
int status;
{
#ifdef HAVE_GETCLOCK
#endif
if (!stats_control)
return;
#ifdef HAVE_GETCLOCK
#else /* not HAVE_GETCLOCK */
#endif /* not HAVE_GETCLOCK */
}
}
/*
* record_loop_stats - write loop filter statistics to file
*
* file format:
* day (mjd)
* time (s past midnight)
* offset (s)
* frequency (approx ppm)
* time constant (log base 2)
*/
void
unsigned poll;
{
#ifdef HAVE_GETCLOCK
#endif
if (!stats_control)
return;
#ifdef HAVE_GETCLOCK
#else /* not HAVE_GETCLOCK */
#endif /* not HAVE_GETCLOCK */
}
}
/*
* record_clock_stats - write clock statistics to file
*
* file format:
* day (mjd)
* time (s past midnight)
* peer (ip address)
* text message
*/
void
struct sockaddr_in *addr;
char *text;
{
#ifdef HAVE_GETCLOCK
#endif
if (!stats_control)
return;
#ifdef HAVE_GETCLOCK
#else /* not HAVE_GETCLOCK */
#endif /* not HAVE_GETCLOCK */
}
}
/*
* record_raw_stats - write raw timestamps to file
*
*
* file format
* time (s past midnight)
* peer ip address
* local ip address
* t1 t2 t3 t4 timestamps
*/
void
{
#ifdef HAVE_GETCLOCK
#endif
if (!stats_control)
return;
#ifdef HAVE_GETCLOCK
#else /* not HAVE_GETCLOCK */
#endif /* not HAVE_GETCLOCK */
}
}
/*
* getauthkeys - read the authentication keys from the specified file
*/
void
char *keyfile;
{
int len;
if (len == 0)
return;
if (key_file_name != 0) {
(void) free(key_file_name);
key_file_name = 0;
}
}
if (key_file_name == 0) {
#ifndef SYS_WINNT
(len + 1));
}
#else
(MAXPATHLEN));
}
{
}
#endif /* SYS_WINNT */
}
/*
* rereadkeys - read the authentication key file over again.
*/
void
{
if (key_file_name != 0)
}