diff --git a/Makefile.in b/Makefile.in index 632ef72..308ff25 100644 --- a/Makefile.in +++ b/Makefile.in @@ -46,7 +46,7 @@ OBJS = util.o sched.o regress.o local.o \ EXTRA_OBJS=@EXTRA_OBJECTS@ CLI_OBJS = client.o md5.o nameserv.o getdate.o cmdparse.o \ - pktlength.o + pktlength.o util.o SRCS = $(patsubst %.o,%.c,$(OBJS)) EXTRA_SRCS = $(patsubst %.o,%.c,$(EXTRA_OBJS)) diff --git a/client.c b/client.c index d034982..a8c4ad2 100644 --- a/client.c +++ b/client.c @@ -39,6 +39,7 @@ #include "cmdparse.h" #include "pktlength.h" #include "memory.h" +#include "util.h" #ifdef FEAT_READLINE #ifdef USE_EDITLINE @@ -94,34 +95,6 @@ time_to_log_form(time_t t) return buffer; } -/* ================================================== */ - -static char * -UTI_RefidToString(unsigned long ref_id) -{ - unsigned int a, b, c, d; - static char result[64]; - a = (ref_id>>24) & 0xff; - b = (ref_id>>16) & 0xff; - c = (ref_id>> 8) & 0xff; - d = (ref_id>> 0) & 0xff; - snprintf(result, sizeof(result), "%c%c%c%c", a, b, c, d); - return result; -} - -static char * -UTI_IPToDottedQuad(unsigned long ip) -{ - unsigned long a, b, c, d; - static char result[64]; - a = (ip>>24) & 0xff; - b = (ip>>16) & 0xff; - c = (ip>> 8) & 0xff; - d = (ip>> 0) & 0xff; - snprintf(result, sizeof(result), "%ld.%ld.%ld.%ld", a, b, c, d); - return result; -} - /* ================================================== */ /* Read a single line of commands from standard input. Eventually we might want to use the GNU readline library. */ diff --git a/clientlog.c b/clientlog.c index a66c883..f3ca033 100644 --- a/clientlog.c +++ b/clientlog.c @@ -40,6 +40,7 @@ #include "memory.h" #include "reports.h" #include "util.h" +#include "logging.h" /* Number of bits of address per layer of the table. This value has been chosen on the basis that a server will predominantly be serving diff --git a/logging.c b/logging.c index d432762..887d757 100644 --- a/logging.c +++ b/logging.c @@ -214,3 +214,19 @@ LOG_GoDaemon(void) } /* ================================================== */ +/* Force a core dump and exit without doing abort() or assert(0). + These do funny things with the call stack in the core file that is + generated, which makes diagnosis difficult. */ + +int +croak(const char *file, int line, const char *msg) +{ + int a; + LOG(LOGS_ERR, LOGF_Util, "Unexpected condition [%s] at %s:%d, core dumped", + msg, file, line); + a = * (int *) 0; + return a; /* Can't happen - this stops the optimiser optimising the + line above */ +} + +/* ================================================== */ diff --git a/logging.h b/logging.h index 8ec9b93..b27006f 100644 --- a/logging.h +++ b/logging.h @@ -95,4 +95,13 @@ extern void LOG_GoDaemon(void); #define LOG_FATAL LOG_Position(__FILE__, __LINE__, ""); LOG_Fatal_Function #endif /* defined (__GNUC__) */ +/* Like assert(0) */ + +#if defined(LINUX) && defined(__alpha__) +#define CROAK(message) assert(0) /* Added JGH Feb 24 2001 FIXME */ +#else +extern int croak(const char *file, int line, const char *msg); +#define CROAK(message) croak(__FILE__, __LINE__, message); +#endif + #endif /* GOT_LOGGING_H */ diff --git a/util.c b/util.c index 30cbd48..b5f3cdf 100644 --- a/util.c +++ b/util.c @@ -31,7 +31,6 @@ #include "sysincl.h" #include "util.h" -#include "logging.h" /* ================================================== */ @@ -65,21 +64,14 @@ UTI_CompareTimevals(struct timeval *a, struct timeval *b) } else if (a->tv_sec > b->tv_sec) { return +1; } else { - if (a->tv_sec != b->tv_sec) { - CROAK("a->tv_sec != b->tv_sec"); - } if (a->tv_usec < b->tv_usec) { return -1; } else if (a->tv_usec > b->tv_usec) { return +1; } else { - if (a->tv_usec != b->tv_usec) { - CROAK("a->tv_usec != b->tv_usec"); - } return 0; } } - CROAK("Impossible"); /* Shouldn't be able to fall through. */ } /* ================================================== */ @@ -346,19 +338,3 @@ UTI_Int64ToTimeval(NTP_int64 *src, } /* ================================================== */ -/* Force a core dump and exit without doing abort() or assert(0). - These do funny things with the call stack in the core file that is - generated, which makes diagnosis difficult. */ - -int -croak(const char *file, int line, const char *msg) -{ - int a; - LOG(LOGS_ERR, LOGF_Util, "Unexpected condition [%s] at %s:%d, core dumped", - msg, file, line); - a = * (int *) 0; - return a; /* Can't happen - this stops the optimiser optimising the - line above */ -} - -/* ================================================== */ diff --git a/util.h b/util.h index 7ec7d2c..1c41b74 100644 --- a/util.h +++ b/util.h @@ -88,15 +88,6 @@ extern void UTI_TimevalToInt64(struct timeval *src, NTP_int64 *dest); extern void UTI_Int64ToTimeval(NTP_int64 *src, struct timeval *dest); -/* Like assert(0) */ - -#if defined(LINUX) && defined(__alpha__) -#define CROAK(message) assert(0) /* Added JGH Feb 24 2001 FIXME */ -#else -extern int croak(const char *file, int line, const char *msg); -#define CROAK(message) croak(__FILE__, __LINE__, message); -#endif - #if defined (INLINE_UTILITIES) #define INLINE_STATIC inline static #include "util.c"