If mdev is run as daemon it should be possible to forward the debug
messages to syslog. This feature might be useful if mdev is run with -s
during boot too. OTOH it makes no sense for the daemon to log to
mdev.log. This can be handled by a syslog daemon way better. If the
daemon stays in the foreground due to -f, the messages are still written
to stderr as before.

Signed-off-by: Jan Klötzke <[email protected]>
---
 util-linux/mdev.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 91c4ff466..1ef7a029e 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -81,7 +81,7 @@
 //kbuild:lib-$(CONFIG_MDEV) += mdev.o
 
 //usage:#define mdev_trivial_usage
-//usage:       "[-s]" IF_FEATURE_MDEV_DAEMON(" | [-df]")
+//usage:       "[-S] " IF_FEATURE_MDEV_DAEMON("[") "[-s]" 
IF_FEATURE_MDEV_DAEMON(" | [-df]]")
 //usage:#define mdev_full_usage "\n\n"
 //usage:       "mdev -s is to be run during boot to scan /sys and populate 
/dev.\n"
 //usage:       IF_FEATURE_MDEV_DAEMON(
@@ -89,6 +89,9 @@
 //usage:       "       -f: stay in foreground.\n"
 //usage:       )
 //usage:       "\n"
+//usage:       "optional arguments:\n"
+//usage:       "       -S: Log to syslog too\n"
+//usage:       "\n"
 //usage:       "Bare mdev is a kernel hotplug helper. To activate it:\n"
 //usage:       "       echo /sbin/mdev >/proc/sys/kernel/hotplug\n"
 //usage:       IF_FEATURE_MDEV_CONF(
@@ -114,6 +117,7 @@
 #include "common_bufsiz.h"
 #include "xregex.h"
 #include <linux/netlink.h>
+#include <syslog.h>
 
 /* "mdev -s" scans /sys/class/xxx, looking for directories which have dev
  * file (it is of the form "M:m\n"). Example: /sys/class/tty/tty0/dev
@@ -1244,8 +1248,9 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
 {
        enum {
                MDEV_OPT_SCAN       = 1 << 0,
-               MDEV_OPT_DAEMON     = 1 << 1,
-               MDEV_OPT_FOREGROUND = 1 << 2,
+               MDEV_OPT_SYSLOG     = 1 << 1,
+               MDEV_OPT_DAEMON     = 1 << 2,
+               MDEV_OPT_FOREGROUND = 1 << 3,
        };
        int opt;
        RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
@@ -1261,7 +1266,7 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
 
        xchdir("/dev");
 
-       opt = getopt32(argv, "s" IF_FEATURE_MDEV_DAEMON("df"));
+       opt = getopt32(argv, "sS" IF_FEATURE_MDEV_DAEMON("df"));
 
 #if ENABLE_FEATURE_MDEV_CONF
        G.filename = "/etc/mdev.conf";
@@ -1271,8 +1276,17 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
        }
 #endif
 
+       if (opt & MDEV_OPT_SYSLOG) {
+               openlog(applet_name, LOG_PID, LOG_DAEMON);
+               logmode |= LOGMODE_SYSLOG;
+       }
+
 #if ENABLE_FEATURE_MDEV_DAEMON
        if (opt & MDEV_OPT_DAEMON) {
+               // there is no point in write()ing to /dev/null
+               if (!(opt & MDEV_OPT_FOREGROUND))
+                       logmode &= ~LOGMODE_STDIO;
+
                /*
                 * Daemon mode listening on uevent netlink socket. Fork away
                 * after initial scan so that caller can be sure everything
@@ -1283,8 +1297,6 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
                if (!(opt & MDEV_OPT_FOREGROUND))
                        bb_daemonize_or_rexec(0, argv);
 
-               open_mdev_log(NULL, getpid());
-
                daemon_loop(temp, fd);
        }
 #endif
-- 
2.20.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to