diff options
author | Jan Klötzke | 2019-12-16 22:56:53 +0100 |
---|---|---|
committer | Denys Vlasenko | 2020-11-22 14:33:58 +0100 |
commit | e9003caf6dce05034147bb6382b17154d428f575 (patch) | |
tree | 50dbb2d01f50ace1750c3ab018ec9f94fdffeeb5 /util-linux/mdev.c | |
parent | d560030548cb237f9ef09a82fd6f372836655306 (diff) | |
download | busybox-e9003caf6dce05034147bb6382b17154d428f575.zip busybox-e9003caf6dce05034147bb6382b17154d428f575.tar.gz |
mdev: add syslog logging mode
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 <jan@kloetzke.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r-- | util-linux/mdev.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c index d4f06c1..a67baf3 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -80,7 +80,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( @@ -88,6 +88,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( @@ -113,6 +116,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 @@ -1237,8 +1241,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); @@ -1254,7 +1259,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"; @@ -1264,8 +1269,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 @@ -1276,8 +1290,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 |