]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Don't copy util functions in client.c
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 15 Sep 2009 16:08:58 +0000 (18:08 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 15 Sep 2009 16:08:58 +0000 (18:08 +0200)
This requires moving croak() to logging.c and avoiding use
of log functions in util.c.

Makefile.in
client.c
clientlog.c
logging.c
logging.h
util.c
util.h

index 632ef72a0fed61a71aa290edad2eeab7461c28b8..308ff2592d7fdedf44f2cb9944749e3b0541668c 100644 (file)
@@ -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))
index d034982cc2b9868d6ae108776f6b07320fb2753f..a8c4ad26702ea9c642aa8476d55002315d6db961 100644 (file)
--- 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. */
index a66c883048925530f5eed0acdfd7ea07109d500c..f3ca03391973ad8d061af33df5ec2b343262527b 100644 (file)
@@ -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
index d432762f0cebcea7e7debc3113a66ce0561d1d14..887d757b12d108dd99a998872c0d6202c39ee58f 100644 (file)
--- 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 */
+}
+
+/* ================================================== */
index 8ec9b935323fb99b7ebebdcf094e7063b10ebc04..b27006fa0c5dccd63954c306f90f452b8f070a0e 100644 (file)
--- 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 30cbd48c3bfb3eaf645f05757b50d0e8284e9f7e..b5f3cdf1abf1091a52974028a157873acf7660df 100644 (file)
--- 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 7ec7d2cf4b2a371c03448b63f365e03221f88c75..1c41b74d8ffcd8c5bfe69f3896db9e19c43346e1 100644 (file)
--- 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"