aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Klötzke <jan@kloetzke.net>2019-12-16 22:56:53 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-11-22 14:33:58 +0100
commite9003caf6dce05034147bb6382b17154d428f575 (patch)
tree50dbb2d01f50ace1750c3ab018ec9f94fdffeeb5
parentd560030548cb237f9ef09a82fd6f372836655306 (diff)
downloadbusybox-w32-e9003caf6dce05034147bb6382b17154d428f575.tar.gz
busybox-w32-e9003caf6dce05034147bb6382b17154d428f575.tar.bz2
busybox-w32-e9003caf6dce05034147bb6382b17154d428f575.zip
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>
-rw-r--r--util-linux/mdev.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index d4f06c128..a67baf32e 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -80,7 +80,7 @@
80//kbuild:lib-$(CONFIG_MDEV) += mdev.o 80//kbuild:lib-$(CONFIG_MDEV) += mdev.o
81 81
82//usage:#define mdev_trivial_usage 82//usage:#define mdev_trivial_usage
83//usage: "[-s]" IF_FEATURE_MDEV_DAEMON(" | [-df]") 83//usage: "[-S] " IF_FEATURE_MDEV_DAEMON("[") "[-s]" IF_FEATURE_MDEV_DAEMON(" | [-df]]")
84//usage:#define mdev_full_usage "\n\n" 84//usage:#define mdev_full_usage "\n\n"
85//usage: "mdev -s is to be run during boot to scan /sys and populate /dev.\n" 85//usage: "mdev -s is to be run during boot to scan /sys and populate /dev.\n"
86//usage: IF_FEATURE_MDEV_DAEMON( 86//usage: IF_FEATURE_MDEV_DAEMON(
@@ -88,6 +88,9 @@
88//usage: " -f: stay in foreground.\n" 88//usage: " -f: stay in foreground.\n"
89//usage: ) 89//usage: )
90//usage: "\n" 90//usage: "\n"
91//usage: "optional arguments:\n"
92//usage: " -S: Log to syslog too\n"
93//usage: "\n"
91//usage: "Bare mdev is a kernel hotplug helper. To activate it:\n" 94//usage: "Bare mdev is a kernel hotplug helper. To activate it:\n"
92//usage: " echo /sbin/mdev >/proc/sys/kernel/hotplug\n" 95//usage: " echo /sbin/mdev >/proc/sys/kernel/hotplug\n"
93//usage: IF_FEATURE_MDEV_CONF( 96//usage: IF_FEATURE_MDEV_CONF(
@@ -113,6 +116,7 @@
113#include "common_bufsiz.h" 116#include "common_bufsiz.h"
114#include "xregex.h" 117#include "xregex.h"
115#include <linux/netlink.h> 118#include <linux/netlink.h>
119#include <syslog.h>
116 120
117/* "mdev -s" scans /sys/class/xxx, looking for directories which have dev 121/* "mdev -s" scans /sys/class/xxx, looking for directories which have dev
118 * file (it is of the form "M:m\n"). Example: /sys/class/tty/tty0/dev 122 * 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)
1237{ 1241{
1238 enum { 1242 enum {
1239 MDEV_OPT_SCAN = 1 << 0, 1243 MDEV_OPT_SCAN = 1 << 0,
1240 MDEV_OPT_DAEMON = 1 << 1, 1244 MDEV_OPT_SYSLOG = 1 << 1,
1241 MDEV_OPT_FOREGROUND = 1 << 2, 1245 MDEV_OPT_DAEMON = 1 << 2,
1246 MDEV_OPT_FOREGROUND = 1 << 3,
1242 }; 1247 };
1243 int opt; 1248 int opt;
1244 RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE); 1249 RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
@@ -1254,7 +1259,7 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
1254 1259
1255 xchdir("/dev"); 1260 xchdir("/dev");
1256 1261
1257 opt = getopt32(argv, "s" IF_FEATURE_MDEV_DAEMON("df")); 1262 opt = getopt32(argv, "sS" IF_FEATURE_MDEV_DAEMON("df"));
1258 1263
1259#if ENABLE_FEATURE_MDEV_CONF 1264#if ENABLE_FEATURE_MDEV_CONF
1260 G.filename = "/etc/mdev.conf"; 1265 G.filename = "/etc/mdev.conf";
@@ -1264,8 +1269,17 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
1264 } 1269 }
1265#endif 1270#endif
1266 1271
1272 if (opt & MDEV_OPT_SYSLOG) {
1273 openlog(applet_name, LOG_PID, LOG_DAEMON);
1274 logmode |= LOGMODE_SYSLOG;
1275 }
1276
1267#if ENABLE_FEATURE_MDEV_DAEMON 1277#if ENABLE_FEATURE_MDEV_DAEMON
1268 if (opt & MDEV_OPT_DAEMON) { 1278 if (opt & MDEV_OPT_DAEMON) {
1279 // there is no point in write()ing to /dev/null
1280 if (!(opt & MDEV_OPT_FOREGROUND))
1281 logmode &= ~LOGMODE_STDIO;
1282
1269 /* 1283 /*
1270 * Daemon mode listening on uevent netlink socket. Fork away 1284 * Daemon mode listening on uevent netlink socket. Fork away
1271 * after initial scan so that caller can be sure everything 1285 * after initial scan so that caller can be sure everything
@@ -1276,8 +1290,6 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
1276 if (!(opt & MDEV_OPT_FOREGROUND)) 1290 if (!(opt & MDEV_OPT_FOREGROUND))
1277 bb_daemonize_or_rexec(0, argv); 1291 bb_daemonize_or_rexec(0, argv);
1278 1292
1279 open_mdev_log(NULL, getpid());
1280
1281 daemon_loop(temp, fd); 1293 daemon_loop(temp, fd);
1282 } 1294 }
1283#endif 1295#endif