Don't copy util functions in client.c
This requires moving croak() to logging.c and avoiding use of log functions in util.c.
This commit is contained in:
parent
19f3a6bca8
commit
5a2b38378c
7 changed files with 28 additions and 62 deletions
|
@ -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))
|
||||
|
|
29
client.c
29
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. */
|
||||
|
|
|
@ -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
|
||||
|
|
16
logging.c
16
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 */
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
|
|
@ -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 */
|
||||
|
|
24
util.c
24
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 */
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
|
9
util.h
9
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"
|
||||
|
|
Loading…
Reference in a new issue