[[!meta title="Janovec Jiří"]] **Project name and homepage:** [Busybox](http://busybox.net) Assignment ====== [Bug #8626](https://bugs.busybox.net/show_bug.cgi?id=8626): Add support -i option to command logger in busybox to log PID. (This can be done using [syslog man pages](http://linux.die.net/man/3/syslog). ) Links documenting the results of my work ====== * [My communication with developers in a public mailing list archive](http://lists.busybox.net/pipermail/busybox/2016-March/083956.html) * [Bugzilla attachment 1](https://bugs.busybox.net/attachment.cgi?id=6391&action=diff) * [Bugzilla attachment 2](https://bugs.busybox.net/attachment.cgi?id=6396&action=diff) Presentation ========== * [[Presentation of the aim of my work in PDF |OSP_prvni.pdf]] ---------- Notes ======== - 8.3. 2016, 10.h , busybox found, browsing bugzilla - 8.3. 2016, 12-15.h, making patch - 10.3. 2016, 10:34:00 consultations on RM35OSP - 10.3. 2016, 12:52:29 CET , mailto:busybox@busybox.net, Subject: [PATCH] - Bugfix #8626, adds "option -i" to "lo... (I don't know where to find link yet.) - waiting to response - 19.3. 2016 17:53:09 Patch upload to bugzilla (automatic send email to some emails) - proč se sakra na bugzille zobrazuje diff proti minulému attachmentu a ne proti hlavní větvi ??? Small version:
diff --git a/sysklogd/logger.c b/sysklogd/logger.c
index b3ca857..58f9374 100644
--- a/sysklogd/logger.c
+++ b/sysklogd/logger.c
@@ -103,10 +103,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;
   
Full version:
diff --git a/sysklogd/logger.c b/sysklogd/logger.c
index b3ca857..25b82cc 100644
--- a/sysklogd/logger.c
+++ b/sysklogd/logger.c
@@ -15,6 +15,13 @@
 //config:	    messages to the system log (i.e. the 'syslogd' utility) so
 //config:	    they can be logged. This is generally used to help locate
 //config:	    problems that occur within programs and scripts.
+//config:
+//config:config FEATURE_LOG_PID
+//config:       bool "Log PID of logger"
+//config:       default n
+//config:       depends on LOGGER
+//config:       help
+//config:         This enables logger to log process id (PID).
 
 //applet:IF_LOGGER(APPLET(logger, BB_DIR_USR_BIN, BB_SUID_DROP))
 
@@ -24,6 +31,9 @@
 //usage:       "[OPTIONS] [MESSAGE]"
 //usage:#define logger_full_usage "\n\n"
 //usage:       "Write MESSAGE (or stdin) to syslog\n"
+//usage:        IF_FEATURE_LOG_PID(
+//usage:     "\n	-i      Log the process ID too"
+//usage:        )
 //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 (numeric or facility.level pair)"
@@ -39,6 +49,23 @@
 #include 
 */
 
+/* Options */
+enum {
+        OPTBIT_priority = 0, // -p
+        OPTBIT_stderr, // -s
+        OPTBIT_tag, // -t
+        IF_FEATURE_LOG_PID(OPTBIT_pid   ,)  // -i
+
+        OPT_priority    = 1 << OPTBIT_priority   ,
+        OPT_stderr      = 1 << OPTBIT_stderr     ,
+        OPT_tag         = 1 << OPTBIT_tag        ,
+        OPT_pid         = IF_FEATURE_LOG_PID((1 << OPTBIT_pid   )) + 0,
+};
+#define OPTION_STR "p:st:" \
+        IF_FEATURE_LOG_PID("i:" )
+#define OPTION_DECL *str_p, *str_t
+#define OPTION_PARAM &str_p, &str_t
+
 /* Decode a symbolic name to a numeric value
  * this function is based on code
  * Copyright (c) 1983, 1993
@@ -95,7 +122,7 @@ static int pencode(char *s)
 int logger_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int logger_main(int argc UNUSED_PARAM, char **argv)
 {
-	char *str_p, *str_t;
+	char OPTION_DECL;
 	int opt;
 	int i = 0;
 
@@ -103,14 +130,19 @@ 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, OPTION_STR, OPTION_PARAM);
+getopt32(argv, "p:st:i", &str_p, &str_t);
 
-	if (opt & 0x2) /* -s */
+	if (opt & OPT_stderr) /* -s */
 		i |= LOG_PERROR;
-	//if (opt & 0x4) /* -t */
+#if ENABLE_FEATURE_LOG_PID
+	if (opt & OPT_pid) /* -i */
+		i |= LOG_PID;
+#endif
+	//if (opt & OPT_tag) /* -t */
 	openlog(str_t, i, 0);
 	i = LOG_USER | LOG_NOTICE;
-	if (opt & 0x1) /* -p */
+	if (opt & OPT_priority) /* -p */
 		i = pencode(str_p);
 
 	argv += optind;