zcip: Add environment variable for overriding log functionality
authorMichel Stam <m.stam@fugro.nl>
Tue, 4 Nov 2014 11:19:04 +0000 (12:19 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 4 Nov 2014 11:19:04 +0000 (12:19 +0100)
function                                             old     new   delta
bb_logenv_override                                     -      70     +70
packed_usage                                       29969   30033     +64
zcip_main                                           1426    1431      +5
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/0 up/down: 139/0)             Total: 139 bytes

Signed-off-by: Michel Stam <m.stam@fugro.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
docs/logging_and_backgrounding.txt
include/libbb.h
libbb/Kbuild.src
libbb/logenv.c [new file with mode: 0644]
networking/zcip.c

index 7e6885560847429b30fbccc889a299cf387b738d..c76cd36532c2337081e052fcb3d63396238b0e12 100644 (file)
@@ -45,6 +45,8 @@ udhcpc - auto-backgrounds unless -f after lease is obtained,
 udhcpd - auto-backgrounds and do not log to stderr unless -f,
     otherwise logs to stderr, but option -S makes it log *also* to syslog
 zcip - auto-backgrounds and logs *also* to syslog unless -f
+    behaviour can be overridden with experimental LOGGING env.var
+    (can be set to either "none" or "syslog")
 
 Total: 13 applets (+1 obsolete),
  4 log to syslog by default (crond fakeidentd inetd zcip),
index d57f00e0e2f5f149ee87b6dd79b2b2ec80cdfc07..cc2bea32d53ff2a348fb41cfaff8389f32fb1549 100644 (file)
@@ -1104,6 +1104,7 @@ extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
 extern void bb_perror_nomsg(void) FAST_FUNC;
 extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
 extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
+extern void bb_logenv_override(void) FAST_FUNC;
 
 /* We need to export XXX_main from libbusybox
  * only if we build "individual" binaries
index 0a9e803d7718e50a9c134e5e7a453236ead005fc..f204816c5aa3fba8cc470c894808532cd7a976c7 100644 (file)
@@ -187,3 +187,6 @@ lib-$(CONFIG_PGREP) += xregcomp.o
 lib-$(CONFIG_PKILL) += xregcomp.o
 lib-$(CONFIG_DEVFSD) += xregcomp.o
 lib-$(CONFIG_FEATURE_FIND_REGEX) += xregcomp.o
+
+# Add the experimental logging functionality, only used by zcip
+lib-$(CONFIG_ZCIP) += logenv.o
diff --git a/libbb/logenv.c b/libbb/logenv.c
new file mode 100644 (file)
index 0000000..66c60bd
--- /dev/null
@@ -0,0 +1,24 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2014 by Fugro Intersite B.V. <m.stam@fugro.nl>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+#include "libbb.h"
+
+void FAST_FUNC bb_logenv_override(void)
+{
+       const char* mode = getenv("LOGGING");
+
+       if (!mode)
+               return;
+
+       if (strcmp(mode, "none") == 0)
+               logmode = LOGMODE_NONE;
+#if ENABLE_FEATURE_SYSLOG
+       else if (strcmp(mode, "syslog") == 0)
+               logmode = LOGMODE_SYSLOG;
+#endif
+}
index 635d660b3e92402419f17504a20229786e6b94e9..a3307c5c970a371c017796f266c6d20b20808d63 100644 (file)
@@ -33,6 +33,9 @@
 //usage:     "\n       -l x.x.0.0      Use this range instead of 169.254"
 //usage:     "\n       -v              Verbose"
 //usage:     "\n"
+//usage:     "\n$LOGGING=none          Suppress logging"
+//usage:     "\n$LOGGING=syslog        Log to syslog"
+//usage:     "\n"
 //usage:     "\nWith no -q, runs continuously monitoring for ARP conflicts,"
 //usage:     "\nexits only on I/O errors (link down etc)"
 
@@ -249,6 +252,8 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
                openlog(applet_name, 0, LOG_DAEMON);
                logmode |= LOGMODE_SYSLOG;
        }
+       bb_logenv_override();
+
        { // -l n.n.n.n
                struct in_addr net;
                if (inet_aton(l_opt, &net) == 0