[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] sysklogd/: add define klogd facility via command line
From: Brilliantov Kirill Vladimirovich <brilliantov () inbox ! ru>
Date: 2021-06-07 8:08:33
Message-ID: 20210607080833.1115-1-brilliantov () inbox ! ru
[Download RAW message or body]
---
sysklogd/klogd.c | 35 ++++++++++++++++++++++++++++++++---
sysklogd/syslogd_and_logger.c | 4 ++++
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index 728cc8d38..a2289925f 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -48,7 +48,7 @@
//applet:IF_KLOGD(APPLET(klogd, BB_DIR_SBIN, BB_SUID_DROP))
-//kbuild:lib-$(CONFIG_KLOGD) += klogd.o
+//kbuild:lib-$(CONFIG_KLOGD) += syslogd_and_logger.o
//usage:#define klogd_trivial_usage
//usage: "[-c N] [-n]"
@@ -56,10 +56,14 @@
//usage: "Kernel logger\n"
//usage: "\n -c N Print to console messages more urgent than prio N (1-8)"
//usage: "\n -n Run in foreground"
+//usage: "\n -f FACILITY Send to syslog with this facility instead 'kern'"
+/*
+ * Done in syslogd_and_logger.c:
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
+*/
/* The Linux-specific klogctl(3) interface does not rely on the filesystem and
@@ -151,8 +155,20 @@ enum {
KLOGD_LOGBUF_SIZE = COMMON_BUFSIZE,
OPT_LEVEL = (1 << 0),
OPT_FOREGROUND = (1 << 1),
+ OPT_FACILITY = (1 << 2),
};
+static int find_facility_by_name(const char *name)
+{
+ int i = 0;
+ do {
+ if (strcmp(name, bb_facilitynames[i].c_name) == 0)
+ return bb_facilitynames[i].c_val;
+ } while (facilitynames[++i].c_name);
+
+ return -1;
+}
+
/* TODO: glibc openlog(LOG_KERN) reverts to LOG_USER instead,
* because that's how they interpret word "default"
* in the openlog() manpage:
@@ -170,17 +186,28 @@ int klogd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int klogd_main(int argc UNUSED_PARAM, char **argv)
{
int i = 0;
+ int facility = LOG_KERN;
char *opt_c;
+ char *opt_f;
int opt;
int used;
setup_common_bufsiz();
- opt = getopt32(argv, "c:n", &opt_c);
+ opt = getopt32(argv, "c:nf:", &opt_c, &opt_f);
if (opt & OPT_LEVEL) {
/* Valid levels are between 1 and 8 */
i = xatou_range(opt_c, 1, 8);
}
+ if (opt & OPT_FACILITY) {
+ facility = find_facility_by_name(opt_f);
+ if (facility < 0) {
+ facility = LOG_KERN;
+ bb_error_msg("failed found facility '%s', will use default LOG_KERN",
+ opt_f);
+
+ }
+ }
if (!(opt & OPT_FOREGROUND)) {
bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
}
@@ -191,7 +218,7 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
* and openlog() also may use the same fd 3 if we swap them:
*/
klogd_open();
- openlog("kernel", 0, LOG_KERN);
+ openlog("kernel", 0, facility);
/*
* glibc problem: for some reason, glibc changes LOG_KERN to LOG_USER
* above. The logic behind this is that standard
@@ -297,3 +324,5 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
kill_myself_with_sig(bb_got_signal);
return EXIT_FAILURE;
}
+
+#undef log_buffer
diff --git a/sysklogd/syslogd_and_logger.c b/sysklogd/syslogd_and_logger.c
index 94d8273b6..5b1ec03f1 100644
--- a/sysklogd/syslogd_and_logger.c
+++ b/sysklogd/syslogd_and_logger.c
@@ -61,3 +61,7 @@ static const CODE *const bb_facilitynames = facilitynames;
#if ENABLE_LOGGER
#include "logger.c"
#endif
+
+#if ENABLE_KLOGD
+#include "klogd.c"
+#endif
--
2.30.2
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic