]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
version: display more build information when using "-vv"
authorVincent Bernat <vincent@bernat.im>
Fri, 4 Mar 2016 21:03:38 +0000 (22:03 +0100)
committerVincent Bernat <vincent@bernat.im>
Fri, 4 Mar 2016 21:03:38 +0000 (22:03 +0100)
Display supported features as well as compilation flags used. This will
be useful to let integration tests autodetect compiled features.

configure.ac
src/Makefile.am
src/client/lldpcli.8.in
src/client/lldpcli.c
src/daemon/lldpd.8.in
src/daemon/lldpd.c
src/log.h
src/version.c [new file with mode: 0644]

index e8d3450866b5744bf8ba5c4f8a896aee2fb74def..fc89f1090e89b62313e94d74eb0fa95a2ee18307 100644 (file)
@@ -336,6 +336,13 @@ if test x"$os" = x"Linux"; then
     fi
 fi
 
+# Build date
+if test x"$SOURCE_DATE_EPOCH" != x; then
+   AC_DEFINE_UNQUOTED(BUILD_DATE, "[$SOURCE_DATE_EPOCH]", [Build date and time])
+fi
+AC_DEFINE_UNQUOTED(LLDP_CC, "[$CC $LLDP_CFLAGS $LLDP_CPPFLAGS $CFLAGS $CPPFLAGS]", [C compiler command])
+AC_DEFINE_UNQUOTED(LLDP_LD, "[$LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS]", [Linker compiler command])
+
 #######################
 # Output results
 AC_SUBST([LLDP_CFLAGS])
index 63e3c1f286939a12786bcf86e44ad4b71de106e7..ddbd1135e2e64ce448b41a6792e0c8fbdc313f98 100644 (file)
@@ -6,11 +6,11 @@ noinst_LTLIBRARIES = libcommon-daemon-lib.la libcommon-daemon-client.la
 include_HEADERS    = lldp-const.h
 
 libcommon_daemon_lib_la_SOURCES = \
-       log.c log.h \
+       log.c log.h version.c \
        marshal.c marshal.h \
        ctl.c ctl.h \
        lldpd-structs.c lldpd-structs.h lldp-const.h
 libcommon_daemon_lib_la_LIBADD  = compat/libcompat.la
 
-libcommon_daemon_client_la_SOURCES = log.c log.h lldp-const.h
+libcommon_daemon_client_la_SOURCES = log.c log.h version.c lldp-const.h
 libcommon_daemon_client_la_LIBADD  = compat/libcompat.la
index b318b8b1e489fc6ee286d11db081271222e1fca5..17f61672941bfdda101655520e9d77a65d09a3a4 100644 (file)
@@ -55,7 +55,7 @@ Specify the Unix-domain socket used for communication with
 .It Fl v
 Show
 .Nm
-version.
+version. When repeated, show more build information.
 .It Fl f Ar format
 Choose the output format. Currently
 .Em plain ,
index f04bdadc2f1210efb879697274f042e6a47e2c3e..ff4582338ee6e3cae60853ba0b04bc678a368227 100644 (file)
@@ -434,7 +434,7 @@ main(int argc, char *argv[])
        lldpctl_conn_t *conn = NULL;
        const char *options = is_lldpctl(argv[0])?"hdvf:u:":"hdsvf:c:u:";
 
-       int gotinputs = 0;
+       int gotinputs = 0, version = 0;
        struct inputs inputs;
        TAILQ_INIT(&inputs);
 
@@ -465,8 +465,7 @@ main(int argc, char *argv[])
                        ctlname = optarg;
                        break;
                case 'v':
-                       fprintf(stdout, "%s\n", PACKAGE_VERSION);
-                       exit(0);
+                       version++;
                        break;
                case 'f':
                        fmt = optarg;
@@ -484,6 +483,11 @@ main(int argc, char *argv[])
                }
        }
 
+       if (version) {
+               version_display(stdout, "lldpcli", version > 1);
+               exit(0);
+       }
+
        if (!gotinputs) {
                log_init(use_syslog, debug, __progname);
                lldpctl_log_level(debug + 1);
index d2a83ad25ca2ef9000c8246e6568750cf59a2881..a413ebc0ff0798ea6095c4ca0c9ab4c31155baee 100644 (file)
@@ -269,7 +269,7 @@ for configuration.
 .It Fl v
 Show
 .Nm
-version.
+version. When repeated, show more build information.
 .El
 .Sh FILTERING NEIGHBORS
 In a heterogeneous network, you may see several different hosts on the
index c815705d66957f89557e57cefa9c2d3e3cee82d6..3b35534b9348668ee0bf18c0b7d9bfa924e369d8 100644 (file)
@@ -1455,7 +1455,7 @@ lldpd_main(int argc, char *argv[], char *envp[])
        char *lsb_release = NULL;
        const char *lldpcli = LLDPCLI_PATH;
        int smart = 15;
-       int receiveonly = 0;
+       int receiveonly = 0, version = 0;
        int ctl;
 
 #ifdef ENABLE_PRIVSEP
@@ -1488,8 +1488,7 @@ lldpd_main(int argc, char *argv[], char *envp[])
                        usage();
                        break;
                case 'v':
-                       fprintf(stdout, "%s\n", PACKAGE_VERSION);
-                       exit(0);
+                       version++;
                        break;
                case 'd':
                        if (daemonize)
@@ -1607,6 +1606,11 @@ lldpd_main(int argc, char *argv[], char *envp[])
                }
        }
 
+       if (version) {
+               version_display(stdout, "lldpd", version > 1);
+               exit(0);
+       }
+
        if (ctlname == NULL) ctlname = LLDPD_CTL_SOCKET;
 
        /* Set correct smart mode */
index 09889d4f1882bc4222ceebe0a15a93bd2b4f2a86..4553446417df82f2e8c5f0aa9dc8c219506e2c76 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -18,6 +18,8 @@
 #ifndef _LOG_H
 #define _LOG_H
 
+#include <stdio.h>
+
 /* log.c */
 void             log_init(int, int, const char *);
 void             log_warn(const char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
@@ -31,4 +33,7 @@ void           log_register(void (*cb)(int, const char*));
 void             log_accept(const char *);
 void            log_level(int);
 
+/* version.c */
+void            version_display(FILE *, const char *, int);
+
 #endif
diff --git a/src/version.c b/src/version.c
new file mode 100644 (file)
index 0000000..e306649
--- /dev/null
@@ -0,0 +1,144 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+/*
+ * Copyright (c) 2016 Vincent Bernat <bernat@luffy.cx>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include "compat/compat.h"
+
+#ifndef BUILD_DATE
+# define BUILD_DATE __DATE__ " " __TIME__
+#endif
+
+static void
+version_display_array(FILE *destination, const char *prefix, const char *const *items)
+{
+       fprintf(destination, "%s", prefix);
+       size_t count = 0;
+       for (const char *const *p = items; *p; p++, count++)
+               fprintf(destination, "%s%s", count?", ":"", *p);
+       if (count == 0)
+               fprintf(destination, "(none)\n");
+       else
+               fprintf(destination, "\n");
+}
+
+void
+version_display(FILE *destination, const char *progname, int verbose)
+{
+       if (!verbose) {
+               fprintf(destination, "%s\n", PACKAGE_VERSION);
+               return;
+       }
+
+       const char *const lldp_features[] = {
+#ifdef ENABLE_LLDPMED
+               "LLDP-MED",
+#endif
+#ifdef ENABLE_DOT1
+               "Dot1",
+#endif
+#ifdef ENABLE_DOT3
+               "Dot3",
+#endif
+#ifdef ENABLE_CUSTOM
+               "Custom TLV",
+#endif
+               NULL};
+       const char *const protocols[] = {
+#ifdef ENABLE_CDP
+               "CDP",
+#endif
+#ifdef ENABLE_FDP
+               "FDP",
+#endif
+#ifdef ENABLE_EDP
+               "EDP",
+#endif
+#ifdef ENABLE_SONMP
+               "SONMP",
+#endif
+               NULL};
+       const char *const output_formats[] = {
+#ifdef USE_XML
+               "XML",
+#endif
+#ifdef USE_JSON
+               "JSON",
+#endif
+               NULL};
+
+
+       fprintf(destination, "%s %s\n", progname, PACKAGE_VERSION);
+       fprintf(destination, "  Built on " BUILD_DATE "\n");
+       fprintf(destination, "\n");
+
+       /* Features */
+       if (!strcmp(progname, "lldpd")) {
+               version_display_array(destination,
+                   "Additional LLDP features:    ", lldp_features);
+               version_display_array(destination,
+                   "Additional protocols:        ", protocols);
+               fprintf(destination,
+                   "SNMP support:                "
+#ifdef USE_SNMP
+                   "yes\n"
+#else
+                   "no\n"
+#endif
+                       );
+#ifdef HOST_OS_LINUX
+               fprintf(destination,
+                   "Old kernel support:          "
+#ifdef ENABLE_OLDIES
+                   "yes"
+#else
+                   "no"
+#endif
+                   " (Linux " MIN_LINUX_KERNEL_VERSION "+)\n");
+#endif
+#ifdef ENABLE_PRIVSEP
+               fprintf(destination,
+                   "Privilege separation:        " "enabled\n");
+               fprintf(destination,
+                   "Privilege separation user:   " PRIVSEP_USER "\n");
+               fprintf(destination,
+                   "Privilege separation group:  " PRIVSEP_GROUP "\n");
+               fprintf(destination,
+                   "Privilege separation chroot: " PRIVSEP_CHROOT "\n");
+#else
+               fprintf(destination,
+                   "Privilege separation:        " "disabled\n");
+#endif
+       }
+
+       if (!strcmp(progname, "lldpcli")) {
+               version_display_array(destination,
+                   "Additional output formats:   ", output_formats);
+       }
+
+       fprintf(destination, "\n");
+
+       /* Build */
+       fprintf(destination,
+           "C compiler command: %s\n", LLDP_CC);
+       fprintf(destination,
+           "Linker command:     %s\n", LLDP_LD);
+
+}