Closing bug 730. libbb run_parts is using scandir (a GNUism),
[oweals/busybox.git] / sysklogd / syslogd.c
index 888082924e9f86d0ab8939bdf661c693860521bc..9e030bd63dd957a66acdbae4ef57e1bf6d1aa51a 100644 (file)
@@ -55,7 +55,6 @@ static struct sockaddr_in remoteaddr;
 #endif
 
 /* options */
-static unsigned option_mask;
 /* Correct regardless of combination of CONFIG_xxx */
 enum {
        OPTBIT_mark = 0, // -m
@@ -298,7 +297,7 @@ static void message(char *fmt, ...)
        fl.l_len = 1;
 
 #ifdef CONFIG_FEATURE_IPC_SYSLOG
-       if ((option_mask & OPT_circularlog) && shbuf) {
+       if ((option_mask32 & OPT_circularlog) && shbuf) {
                char b[1024];
 
                va_start(arguments, fmt);
@@ -404,7 +403,7 @@ static void logMessage(int pri, char *msg)
        /* todo: supress duplicates */
 
 #ifdef CONFIG_FEATURE_REMOTE_LOG
-       if (option_mask & OPT_remotelog) {
+       if (option_mask32 & OPT_remotelog) {
                char line[MAXLINE + 1];
                /* trying connect the socket */
                if (-1 == remotefd) {
@@ -419,12 +418,12 @@ static void logMessage(int pri, char *msg)
                }
        }
 
-       if (option_mask & OPT_locallog)
+       if (option_mask32 & OPT_locallog)
 #endif
        {
                /* now spew out the message to wherever it is supposed to go */
                if (pri == 0 || LOG_PRI(pri) < logLevel) {
-                       if (option_mask & OPT_small)
+                       if (option_mask32 & OPT_small)
                                message("%s %s\n", timestamp, msg);
                        else
                                message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
@@ -531,7 +530,7 @@ static void doSyslogd(void)
        if (chmod(lfile, 0666) < 0) {
                bb_perror_msg_and_die("cannot set permission on %s", lfile);
        }
-       if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask & OPT_circularlog)) {
+       if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) {
                ipcsyslog_init();
        }
 
@@ -575,31 +574,31 @@ int syslogd_main(int argc, char **argv)
        char *p;
 
        /* do normal option parsing */
-       option_mask = bb_getopt_ulflags(argc, argv, OPTION_STR, OPTION_PARAM);
-       if (option_mask & OPT_mark) MarkInterval = atoi(opt_m) * 60; // -m
-       //if (option_mask & OPT_nofork) // -n
-       //if (option_mask & OPT_outfile) // -O
-       if (option_mask & OPT_loglevel) { // -l
-               logLevel = atoi(opt_l);
+       getopt32(argc, argv, OPTION_STR, OPTION_PARAM);
+       if (option_mask32 & OPT_mark) MarkInterval = xatoul_range(opt_m, 0, INT_MAX/60) * 60; // -m
+       //if (option_mask32 & OPT_nofork) // -n
+       //if (option_mask32 & OPT_outfile) // -O
+       if (option_mask32 & OPT_loglevel) { // -l
+               logLevel = xatoi_u(opt_l);
                /* Valid levels are between 1 and 8 */
                if (logLevel < 1 || logLevel > 8)
                        bb_show_usage();
        }
-       //if (option_mask & OPT_small) // -S
+       //if (option_mask32 & OPT_small) // -S
 #if ENABLE_FEATURE_ROTATE_LOGFILE
-       if (option_mask & OPT_filesize) logFileSize = atoi(opt_s) * 1024; // -s
-       if (option_mask & OPT_rotatecnt) { // -b
-               logFileRotate = atoi(opt_b);
+       if (option_mask32 & OPT_filesize) logFileSize = xatoul_range(opt_s, 0, INT_MAX/1024) * 1024; // -s
+       if (option_mask32 & OPT_rotatecnt) { // -b
+               logFileRotate = xatoi_u(opt_b);
                if (logFileRotate > 99) logFileRotate = 99; 
        }
 #endif
 #if ENABLE_FEATURE_REMOTE_LOG
-       if (option_mask & OPT_remotelog) { // -R
+       if (option_mask32 & OPT_remotelog) { // -R
                int port = 514;
                char *host = xstrdup(opt_R);
                p = strchr(host, ':');
                if (p) {
-                       port = atoi(p + 1);
+                       port = xatou16(p + 1);
                        *p = '\0';
                }
                remoteaddr.sin_family = AF_INET;
@@ -608,21 +607,19 @@ int syslogd_main(int argc, char **argv)
                remoteaddr.sin_port = htons(port);
                free(host);
        }
-       //if (option_mask & OPT_locallog) // -L
+       //if (option_mask32 & OPT_locallog) // -L
 #endif
 #if ENABLE_FEATURE_IPC_SYSLOG
-       if (option_mask & OPT_circularlog) { // -C
+       if (option_mask32 & OPT_circularlog) { // -C
                if (opt_C) {
-                       int buf_size = atoi(opt_C);
-                       if (buf_size >= 4)
-                               shm_size = buf_size * 1024;
+                       shm_size = xatoul_range(opt_C, 4, INT_MAX/1024) * 1024;
                }
        }
 #endif
 
        /* If they have not specified remote logging, then log locally */
-       if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask & OPT_remotelog))
-               option_mask |= OPT_locallog;
+       if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask32 & OPT_remotelog))
+               option_mask32 |= OPT_locallog;
 
        /* Store away localhost's name before the fork */
        gethostname(LocalHostName, sizeof(LocalHostName));
@@ -633,7 +630,7 @@ int syslogd_main(int argc, char **argv)
 
        umask(0);
 
-       if (!(option_mask & OPT_nofork)) {
+       if (!(option_mask32 & OPT_nofork)) {
 #ifdef BB_NOMMU
                vfork_daemon_rexec(0, 1, argc, argv, "-n");
 #else