[PATCH] - Bugfix #8626, adds "option -i" to "logger"

janovji3 at fel.cvut.cz janovji3 at fel.cvut.cz
Thu Mar 10 11:52:29 UTC 2016


  Package: busybox
  Version: v1.25.0.git
  Severity: ?

         This patch can fix bug #8626, add the "option -i" to the  
"logger". I have
         tested this on x86 system and it works. I have tested it against the
         GNU counterparts and the outputs are identical.


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;





         I'm new to opensource development, so I don't know the right  
way to send
         you patch. Your contributing guidline say to make small  
steps, but I also
         create bigger patch for logger.c inspired by syslogd.c  
(enable menuconfig
         option for -i and enable extending prameters). This version  
tested too.




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 <syslog.h>
  */

+/* 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;





More information about the busybox mailing list