]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
logger: check availability of ntp_gettime()
authorSamuel Thibault <sthibault@debian.org>
Sun, 18 Jan 2015 21:44:54 +0000 (21:44 +0000)
committerSami Kerola <kerolasa@iki.fi>
Fri, 23 Jan 2015 19:57:22 +0000 (19:57 +0000)
Make compilation to work in systems which don't have sys/timex.h and its
ntp_gettime().

Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Samuel Thibault <sthibault@debian.org>
configure.ac
misc-utils/logger.c

index 3d77307fbd32ec7db4f3c4bf56a483f50ba77d4b..fce7e0e78474ed565da67283e6f23836760dca0b 100644 (file)
@@ -230,6 +230,7 @@ AC_CHECK_HEADERS([ \
        sys/swap.h \
        sys/syscall.h \
        sys/time.h \
+       sys/timex.h \
        sys/ttydefaults.h \
        sys/types.h \
        sys/un.h \
index 35caf9d9d7c812aff8cfd213f7c0188b8779a88f..03031dac971d71d3ecb021f3fdc0bb551f41e9b0 100644 (file)
@@ -44,7 +44,6 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
-#include <sys/timex.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 # include <systemd/sd-journal.h>
 #endif
 
+#ifdef HAVE_SYS_TIMEX_H
+# include <sys/timex.h>
+#endif
+
 enum {
        TYPE_UDP = (1 << 1),
        TYPE_TCP = (1 << 2),
@@ -325,7 +328,9 @@ static void syslog_rfc5424(const  struct logger_ctl *ctl, const char *msg)
 {
        char *buf, *tag = NULL, *hostname = NULL;
        char pid[32], time[64], timeq[80];
+#ifdef HAVE_SYS_TIMEX_H
        struct ntptimeval ntptv;
+#endif
        struct timeval tv;
        struct tm *tm;
        int len;
@@ -364,11 +369,13 @@ static void syslog_rfc5424(const  struct logger_ctl *ctl, const char *msg)
                snprintf(pid, sizeof(pid), " %d", ctl->pid);
 
        if (ctl->rfc5424_tq) {
+#ifdef HAVE_SYS_TIMEX_H
                if (ntp_gettime(&ntptv) == TIME_OK)
                        snprintf(timeq, sizeof(timeq),
                                 " [timeQuality tzKnown=\"1\" isSynced=\"1\" syncAccuracy=\"%ld\"]",
                                 ntptv.maxerror);
                else
+#endif
                        snprintf(timeq, sizeof(timeq),
                                 " [timeQuality tzKnown=\"1\" isSynced=\"0\"]");
        }