]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Merged #38692 (use program base name in (sys)log)
authorFrancis Dupont <fdupont@isc.org>
Sat, 12 Sep 2015 17:21:18 +0000 (19:21 +0200)
committerFrancis Dupont <fdupont@isc.org>
Sat, 12 Sep 2015 17:21:18 +0000 (19:21 +0200)
RELNOTES
client/dhclient.c
dhcpctl/omshell.c
includes/omapip/omapip_p.h
includes/site.h
omapip/errwarn.c
relay/dhcrelay.c
server/dhcpd.c

index 8fa810a8c5186afa712de1054cb1a64ab1914e15..0619b420aa6b0be948e09b02a65690943f0af996 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -63,6 +63,13 @@ by Eric Young (eay@cryptsoft.com).
 - Corrected a static analyzer warning in common/execute.c
   [ISC-Bugs #40374]
 
+- ISC DHCP now follows the common convention to use the base name a
+  program is invoked with (aka argv[0], vs. a builtin name) for
+  logs. This should help differentiate syslog entires for DHCPv4 and
+  DHCPv6 servers. You can define OLD_LOG_NAME in includes/site.h to
+  keep the previous behavior.
+  [ISC-BUGS #38692]
+
                        Changes since 4.1-ESV-R12b1
 - None
 
index c55e221d05f647270d788975d0eb16b11d57adc0..0af763a66eecc8d628d337cb1348365bbe191859 100644 (file)
@@ -86,6 +86,8 @@ int wanted_ia_ta = 0;
 int wanted_ia_pd = 0;
 char *mockup_relay = NULL;
 
+char *progname = NULL;
+
 void run_stateless(int exit_mode);
 
 static void usage(void);
@@ -122,6 +124,12 @@ main(int argc, char **argv) {
 #endif /* DHCPv6 */
        char *s;
 
+#ifdef OLD_LOG_NAME
+       progname = "dhclient";
+#else
+       progname = argv[0];
+#endif
+
        /* Initialize client globals. */
        memset(&default_duid, 0, sizeof(default_duid));
 
@@ -138,7 +146,7 @@ main(int argc, char **argv) {
        else if (fd != -1)
                close(fd);
 
-       openlog("dhclient", DHCP_LOG_OPTIONS, LOG_DAEMON);
+       openlog(isc_file_basename(progname), DHCP_LOG_OPTIONS, LOG_DAEMON);
 
 #if !(defined(DEBUG) || defined(__CYGWIN32__))
        setlogmask(LOG_UPTO(LOG_INFO));
@@ -704,7 +712,7 @@ static void usage()
        log_info(url);
 
 
-       log_fatal("Usage: dhclient "
+       log_fatal("Usage: %s "
 #ifdef DHCPv6
                  "[-4|-6] [-SNTP1dvrx] [-nw] [-p <port>]\n"
 #else /* DHCPv6 */
@@ -713,7 +721,8 @@ static void usage()
                  "                [-s server-addr] [-cf config-file] "
                  "[-lf lease-file]\n"
                  "                [-pf pid-file] [--no-pid] [-e VAR=val]\n"
-                 "                [-sf script-file] [interface]");
+                 "                [-sf script-file] [interface]",
+                 isc_file_basename(progname));
 }
 
 void run_stateless(int exit_mode)
index 3b283ab8b0e822941308e2d498af87fa704d5ee3..e719e6dd59852ba8fc6e0c073ba3cb08f18c398d 100644 (file)
@@ -3,7 +3,7 @@
    Examine and modify omapi objects. */
 
 /*
- * Copyright (c) 2009-2011,2013,2014 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2009-2011,2013-2015 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2001-2003 by Internet Software Consortium
  *
@@ -63,7 +63,7 @@ int check_collection (struct packet *p, struct lease *l, struct collection *c)
 }
 void classify (struct packet *packet, struct class *class) { }
 
-static void usage (char *s) {
+static void usage (const char *s) {
        fprintf (stderr, "Usage: %s\n", s);
        exit (1);
 }
@@ -94,13 +94,21 @@ main(int argc, char **argv) {
        char s1[1024];
        int connected = 0;
        char hex_buf[1025];
+       char *progname;
+
+#ifdef OLD_LOG_NAME
+       progname = "omshell";
+#else
+       progname = argv[0];
+#endif
 
        for (i = 1; i < argc; i++) {
-               usage(argv[0]);
+               usage(isc_file_basename(progname));
        }
 
        /* Initially, log errors to stderr as well as to syslogd. */
-       openlog ("omshell", DHCP_LOG_OPTIONS, DHCPD_LOG_FACILITY);
+       openlog (isc_file_basename(progname),
+                DHCP_LOG_OPTIONS, DHCPD_LOG_FACILITY);
        status = dhcpctl_initialize ();
        if (status != ISC_R_SUCCESS) {
                fprintf (stderr, "dhcpctl_initialize: %s\n",
index 3fa4c92fb3c287077d25308cc3a8deceadb975c6..9edfb836d276deeb635a99f504c6384c163ff424 100644 (file)
@@ -3,7 +3,8 @@
    Private master include file for the OMAPI library. */
 
 /*
- * Copyright (c) 2009-2010,2014 by Internet Systems Consortium, Inc. ("ISC") 
+ * Copyright (c) 2014-2015 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2009-2010 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1996-2003 by Internet Software Consortium
  *
@@ -287,6 +288,8 @@ void do_percentm (char *obuf, const char *ibuf);
 isc_result_t uerr2isc (int);
 isc_result_t ns_rcode_to_isc (int);
 
+const char *isc_file_basename(const char *filename);
+
 extern omapi_message_object_t *omapi_registered_messages;
 
 #endif /* __OMAPIP_OMAPIP_P_H__ */
index c4168f811816fd76585221739a5fa41e3fcf3299..1b8380047d796fc1c2a1636991002c8a5666f1a2 100644 (file)
 
 /* #define USE_RAW_SOCKETS */
 
+/* Define this to keep the old program name (e.g., "dhcpd" for
+   the DHCP server) in place of the (base) name the program was
+   invoked with. */
+
+/* #define OLD_LOG_NAME */
+
 /* Define this to change the logging facility used by dhcpd. */
 
 /* #define DHCPD_LOG_FACILITY LOG_DAEMON */
index d68af04afc70311074d0066fb91b247b2ee36b18..b1d770e2592a9e6e16a16303da9f64b61cecc2ec 100644 (file)
@@ -4,7 +4,8 @@
 
 /*
  * Copyright (c) 1995 RadioMail Corporation.
- * Copyright (c) 2004,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2014-2015 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004,2007,2009 by Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1996-2003 by Internet Software Consortium
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -35,6 +36,7 @@
 
 #include <omapip/omapip_p.h>
 #include <errno.h>
+#include <string.h>
 #include <syslog.h>
 
 #ifdef DEBUG
@@ -361,3 +363,25 @@ char *pWSAError ()
   return "Unknown WinSock error";
 }
 #endif /* _WIN32 */
+
+/* From bind9 libisc */
+
+#ifndef _WIN32
+#define ISC_PATH_SEPARATOR '/'
+#else
+#defineISC_PATH_SEPARATOR '\\'
+#endif
+
+const char *
+isc_file_basename(const char *filename) {
+  char *s;
+
+  if (filename == NULL)
+    return (filename);
+
+  s = strrchr(filename, ISC_PATH_SEPARATOR);
+  if (s == NULL)
+    return (filename);
+
+  return (s + 1);
+}
index e5eaed58f7034ccd167cf0a96bf4de106f364753..8ab1d0878ca6f34aaf83a675958fae1e0599e8d4 100644 (file)
@@ -132,15 +132,17 @@ static const char message[] =
 static const char url[] =
 "For info, please visit https://www.isc.org/software/dhcp/";
 
+char *progname;
+
 #ifdef DHCPv6
 #define DHCRELAY_USAGE \
-"Usage: dhcrelay [-4] [-d] [-q] [-a] [-D]\n"\
+"Usage: %s [-4] [-d] [-q] [-a] [-D]\n"\
 "                     [-A <length>] [-c <hops>] [-p <port>]\n" \
 "                     [-pf <pid-file>] [--no-pid]\n"\
 "                     [-m append|replace|forward|discard]\n" \
 "                     [-i interface0 [ ... -i interfaceN]\n" \
 "                     server0 [ ... serverN]\n\n" \
-"       dhcrelay -6   [-d] [-q] [-I] [-c <hops>] [-p <port>]\n" \
+"       %s -6   [-d] [-q] [-I] [-c <hops>] [-p <port>]\n" \
 "                     [-pf <pid-file>] [--no-pid]\n"\
 "                     -l lower0 [ ... -l lowerN]\n" \
 "                     -u upper0 [ ... -u upperN]\n" \
@@ -148,7 +150,7 @@ static const char url[] =
 "       upper (server link): [address%%]interface"
 #else
 #define DHCRELAY_USAGE \
-"Usage: dhcrelay [-d] [-q] [-a] [-D] [-A <length>] [-c <hops>] [-p <port>]\n" \
+"Usage: %s [-d] [-q] [-a] [-D] [-A <length>] [-c <hops>] [-p <port>]\n" \
 "                [-pf <pid-file>] [--no-pid]\n"\
 "                [-m append|replace|forward|discard]\n" \
 "                [-i interface0 [ ... -i interfaceN]\n" \
@@ -156,7 +158,11 @@ static const char url[] =
 #endif
 
 static void usage() {
-       log_fatal(DHCRELAY_USAGE);
+       log_fatal(DHCRELAY_USAGE,
+#ifdef DHCPv6
+                 isc_file_basename(progname),
+#endif
+                 isc_file_basename(progname));
 }
 
 int 
@@ -175,6 +181,12 @@ main(int argc, char **argv) {
        int local_family_set = 0;
 #endif
 
+#ifdef OLD_LOG_NAME
+       progname = "dhcrelay";
+#else
+       progname = argv[0];
+#endif
+
        /* Make sure that file descriptors 0(stdin), 1,(stdout), and
           2(stderr) are open. To do this, we assume that when we
           open a file the lowest available file descriptor is used. */
@@ -188,7 +200,7 @@ main(int argc, char **argv) {
        else if (fd != -1)
                close(fd);
 
-       openlog("dhcrelay", DHCP_LOG_OPTIONS, LOG_DAEMON);
+       openlog(isc_file_basename(progname), DHCP_LOG_OPTIONS, LOG_DAEMON);
 
 #if !defined(DEBUG)
        setlogmask(LOG_UPTO(LOG_INFO));
@@ -371,7 +383,11 @@ main(int argc, char **argv) {
                        exit(0);
                } else if (!strcmp(argv[i], "--help") ||
                           !strcmp(argv[i], "-h")) {
-                       log_info(DHCRELAY_USAGE);
+                       log_info(DHCRELAY_USAGE,
+#ifdef DHCPv6
+                                isc_file_basename(progname),
+#endif
+                                isc_file_basename(progname));
                        exit(0);
                } else if (argv[i][0] == '-') {
                        usage();
index 7d217c686593b5e2c38c04d086c5faf8b150fb45..6a89badf956f1274e78ca6940fec9cb34cf6ba7a 100644 (file)
@@ -172,6 +172,10 @@ int omapi_port;
 trace_type_t *trace_srandom;
 #endif
 
+#ifndef UNIT_TEST
+char *progname;
+#endif
+
 static isc_result_t verify_addr (omapi_object_t *l, omapi_addr_t *addr) {
        return ISC_R_SUCCESS;
 }
@@ -267,6 +271,12 @@ main(int argc, char **argv) {
        char *set_chroot = 0;
 #endif /* PARANOIA */
 
+#ifdef OLD_LOG_NAME
+       progname = "dhcpd";
+#else
+       progname = argv[0];
+#endif
+
         /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
            2 (stderr) are open. To do this, we assume that when we
            open a file the lowest available file descriptor is used. */
@@ -304,7 +314,8 @@ main(int argc, char **argv) {
        dhcp_common_objects_setup ();
 
        /* Initially, log errors to stderr as well as to syslogd. */
-       openlog ("dhcpd", DHCP_LOG_OPTIONS, DHCPD_LOG_FACILITY);
+       openlog (isc_file_basename(progname),
+                DHCP_LOG_OPTIONS, DHCPD_LOG_FACILITY);
 
        for (i = 1; i < argc; i++) {
                if (!strcmp (argv [i], "-p")) {
@@ -1081,7 +1092,8 @@ void postconf_initialization (int quiet)
                                           &global_scope, oc, MDL)) {
                        if (db.len == 1) {
                                closelog ();
-                               openlog("dhcpd", DHCP_LOG_OPTIONS, db.data[0]);
+                               openlog(isc_file_basename(progname),
+                                       DHCP_LOG_OPTIONS, db.data[0]);
                                /* Log the startup banner into the new
                                   log file. */
                                if (!quiet) {
@@ -1204,7 +1216,7 @@ usage(void) {
        log_info(copyright);
        log_info(arr);
 
-       log_fatal("Usage: dhcpd [-p <UDP port #>] [-f] [-d] [-q] [-t|-T]\n"
+       log_fatal("Usage: %s [-p <UDP port #>] [-f] [-d] [-q] [-t|-T]\n"
 #ifdef DHCPv6
                  "             [-4|-6] [-cf config-file] [-lf lease-file]\n"
 #else /* !DHCPv6 */
@@ -1219,7 +1231,8 @@ usage(void) {
                  "             [-play trace-input-file]\n"
 #endif /* TRACING */
                  "             [-pf pid-file] [--no-pid] [-s server]\n"
-                 "             [if0 [...ifN]]");
+                 "             [if0 [...ifN]]",
+                 isc_file_basename(progname));
 }
 #endif