[PATCH 1/1] logger: add '-i' flag for optional PID to syslog messages

Joachim Wiberg troglobit at gmail.com
Wed Nov 23 12:38:46 UTC 2022


The -i flag in the util-linux, and upstream sysklogd, projects add
PID to syslog messages, using the LOG_PID flag.

Signed-off-by: Joachim Wiberg <troglobit at gmail.com>
---
 sysklogd/logger.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sysklogd/logger.c b/sysklogd/logger.c
index 04b2c8e3b..8424ae206 100644
--- a/sysklogd/logger.c
+++ b/sysklogd/logger.c
@@ -21,9 +21,10 @@
 //kbuild:lib-$(CONFIG_LOGGER) += syslogd_and_logger.o
 
 //usage:#define logger_trivial_usage
-//usage:       "[-s] [-t TAG] [-p PRIO] [MESSAGE]"
+//usage:       "[-i] [-s] [-t TAG] [-p PRIO] [MESSAGE]"
 //usage:#define logger_full_usage "\n\n"
 //usage:       "Write MESSAGE (or stdin) to syslog\n"
+//usage:     "\n	-i	Log PID of logger to system log"
 //usage:     "\n	-s	Log to stderr as well as the system log"
 //usage:     "\n	-t TAG	Log using the specified tag (defaults to user name)"
 //usage:     "\n	-p PRIO	Priority (number or FACILITY.LEVEL pair)"
@@ -105,10 +106,12 @@ int logger_main(int argc UNUSED_PARAM, char **argv)
 	str_t = uid2uname_utoa(geteuid());
 
 	/* Parse any options */
-	opt = getopt32(argv, "p:st:", &str_p, &str_t);
+	opt = getopt32(argv, "p:st:i", &str_p, &str_t);
 
 	if (opt & 0x2) /* -s */
 		i |= LOG_PERROR;
+	if (opt & 0x8) /* -i */
+		i |= LOG_PID;
 	//if (opt & 0x4) /* -t */
 	openlog(str_t, i, 0);
 	i = LOG_USER | LOG_NOTICE;
-- 
2.34.1



More information about the busybox mailing list