[PATCH v2] zcip: Add environment variable for overriding log functionality
Michel Stam
m.stam at fugro.nl
Tue Nov 4 11:05:07 UTC 2014
Signed-off-by: Michel Stam <m.stam at fugro.nl>
---
docs/logging_and_backgrounding.txt | 2 ++
include/libbb.h | 1 +
libbb/Kbuild.src | 3 +++
libbb/logenv.c | 27 +++++++++++++++++++++++++++
networking/zcip.c | 6 ++++++
5 files changed, 39 insertions(+)
create mode 100644 libbb/logenv.c
diff --git a/docs/logging_and_backgrounding.txt b/docs/logging_and_backgrounding.txt
index 7e68855..0609a14 100644
--- a/docs/logging_and_backgrounding.txt
+++ b/docs/logging_and_backgrounding.txt
@@ -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),
diff --git a/include/libbb.h b/include/libbb.h
index d57f00e..cc2bea3 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -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
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index 0a9e803..f204816 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -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
index 0000000..5b81749
--- /dev/null
+++ b/libbb/logenv.c
@@ -0,0 +1,27 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2014 by Fugro Intersite B.V. <m.stam at fugro.nl>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+#include "libbb.h"
+#include <stdlib.h>
+#include <string.h>
+
+void FAST_FUNC bb_logenv_override(void)
+{
+ const char* mode = getenv("LOGGING");
+
+ if (mode == NULL)
+ return;
+
+ if (!strcmp(mode, "none"))
+ logmode = LOGMODE_NONE;
+# if ENABLE_FEATURE_SYSLOG
+ else if (!strcmp(mode, "syslog"))
+ logmode |= LOGMODE_SYSLOG;
+# endif
+}
diff --git a/networking/zcip.c b/networking/zcip.c
index 635d660..51ff588 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -35,6 +35,10 @@
//usage: "\n"
//usage: "\nWith no -q, runs continuously monitoring for ARP conflicts,"
//usage: "\nexits only on I/O errors (link down etc)"
+//usage: "\n"
+//usage: "\nUse the LOGGING environment variable to override default"
+//usage: "\nlogging behaviour (none to disable logging, syslog to log"
+//usage: "\nto syslog as well"
#include "libbb.h"
#include <netinet/ether.h>
@@ -249,6 +253,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
--
1.7.12.1
More information about the busybox
mailing list