- remove unused variable TOPDIR
[oweals/busybox.git] / sysklogd / klogd.c
index 94376fe52f9cb1f3a9af1d713569700164a7b584..e4c8a630e6b45e47110f6121cde46cf3231aebd0 100644 (file)
@@ -104,7 +104,7 @@ static void doKlogd(const int console_log_level)
                        }
                        if (log_buffer[i] == '\n') {
                                log_buffer[i] = '\0';   /* zero terminate this message */
-                               syslog(priority, start);
+                               syslog(priority, "%s", start);
                                start = &log_buffer[i + 1];
                                priority = LOG_INFO;
                        }
@@ -113,37 +113,24 @@ static void doKlogd(const int console_log_level)
        }
 }
 
+#define OPT_LEVEL        1
+#define OPT_FOREGROUND   2
+
 extern int klogd_main(int argc, char **argv)
 {
-       /* no options, no getopt */
-       int opt;
-       int doFork = TRUE;
-       unsigned char console_log_level = -1;
+       unsigned long opt;
+       char *c_arg;
+       int console_log_level = -1;
 
        /* do normal option parsing */
-       while ((opt = getopt(argc, argv, "c:n")) > 0) {
-               switch (opt) {
-               case 'c':
-                       if ((optarg == NULL) || (optarg[1] != '\0')) {
-                               bb_show_usage();
-                       }
-                       /* Valid levels are between 1 and 8 */
-                       console_log_level = *optarg - '1';
-                       if (console_log_level > 7) {
-                               bb_show_usage();
-                       }
-                       console_log_level++;
-
-                       break;
-               case 'n':
-                       doFork = FALSE;
-                       break;
-               default:
-                       bb_show_usage();
-               }
+       opt = bb_getopt_ulflags (argc, argv, "c:n", &c_arg);
+
+       if (opt & OPT_LEVEL) {
+               /* Valid levels are between 1 and 8 */
+               console_log_level = bb_xgetlarg(c_arg, 10, 1, 8);
        }
 
-       if (doFork) {
+       if (!(opt & OPT_FOREGROUND)) {
 #if defined(__uClinux__)
                vfork_daemon_rexec(0, 1, argc, argv, "-n");
 #else /* __uClinux__ */