Bump to version 1.22.1
[platform/upstream/busybox.git] / miscutils / crond.c
index a459c6a..582dc99 100644 (file)
@@ -8,9 +8,22 @@
  * (version 2.3.2)
  * Vladimir Oleynik <dzo@simtreas.ru> (C) 2002
  *
- * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
+//usage:#define crond_trivial_usage
+//usage:       "-fbS -l N " IF_FEATURE_CROND_D("-d N ") "-L LOGFILE -c DIR"
+//usage:#define crond_full_usage "\n\n"
+//usage:       "       -f      Foreground"
+//usage:     "\n       -b      Background (default)"
+//usage:     "\n       -S      Log to syslog (default)"
+//usage:     "\n       -l      Set log level. 0 is the most verbose, default 8"
+//usage:       IF_FEATURE_CROND_D(
+//usage:     "\n       -d      Set log level, log to stderr"
+//usage:       )
+//usage:     "\n       -L      Log to file"
+//usage:     "\n       -c      Working dir"
+
 #include "libbb.h"
 #include <syslog.h>
 
@@ -35,7 +48,7 @@
 # define CRONUPDATE     "cron.update"
 #endif
 #ifndef MAXLINES
-# define MAXLINES       256    /* max lines in non-root crontabs */
+# define MAXLINES       256  /* max lines in non-root crontabs */
 #endif
 
 
@@ -123,7 +136,7 @@ static void crondlog(const char *ctl, ...)
                /* Syslog mode: all to syslog (logmode = LOGMODE_SYSLOG), */
                if (!DebugOpt && G.log_filename) {
                        /* Otherwise (log to file): we reopen log file at every write: */
-                       int logfd = open3_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND, 0666);
+                       int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND);
                        if (logfd >= 0)
                                xmove_fd(logfd, STDERR_FILENO);
                }
@@ -170,7 +183,7 @@ static void ParseField(char *user, char *ary, int modvalue, int off,
 
                /* Handle numeric digit or symbol or '*' */
                if (*ptr == '*') {
-                       n1 = 0;         /* everything will be filled */
+                       n1 = 0;  /* everything will be filled */
                        n2 = modvalue - 1;
                        skip = 1;
                        ++ptr;
@@ -243,7 +256,6 @@ static void ParseField(char *user, char *ary, int modvalue, int off,
                                        goto err;
                                }
                        } while (n1 != n2);
-
                }
                if (*ptr != ',') {
                        break;
@@ -304,13 +316,15 @@ static void FixDayDow(CronLine *line)
 //if crontab was reloaded: crond thinks that "new" job is different from "old"
 //even if they are in fact completely the same. Example
 //Crontab was:
-// 0-59 * * * job1
-// 0-59 * * * long_running_job2
+// 0-59 * * * job1
+// 0-59 * * * long_running_job2
 //User edits crontab to:
-// 0-59 * * * job1_updated
-// 0-59 * * * long_running_job2
+// 0-59 * * * job1_updated
+// 0-59 * * * long_running_job2
 //Bug: crond can now start another long_running_job2 even if old one
 //is still running.
+//OTOH most other versions of cron do not wait for job termination anyway,
+//they end up with multiple copies of jobs if they don't terminate soon enough.
 static void delete_cronfile(const char *userName)
 {
        CronFile **pfile = &G.cron_files;
@@ -847,7 +861,8 @@ int crond_main(int argc UNUSED_PARAM, char **argv)
 
        /* "-b after -f is ignored", and so on for every pair a-b */
        opt_complementary = "f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l")
-                       ":l+:d+"; /* -l and -d have numeric param */
+                       /* -l and -d have numeric param */
+                       ":l+" IF_FEATURE_CROND_D(":d+");
        opts = getopt32(argv, "l:L:fbSc:" IF_FEATURE_CROND_D("d:"),
                        &G.log_level, &G.log_filename, &G.crontab_dir_name
                        IF_FEATURE_CROND_D(,&G.log_level));
@@ -870,7 +885,7 @@ int crond_main(int argc UNUSED_PARAM, char **argv)
        xsetenv("SHELL", DEFAULT_SHELL); /* once, for all future children */
        crondlog(LVL8 "crond (busybox "BB_VER") started, log level %d", G.log_level);
        rescan_crontab_dir();
-       write_pidfile("/var/run/crond.pid");
+       write_pidfile(CONFIG_PID_FILE_PATH "/crond.pid");
 
        /* Main loop */
        t2 = time(NULL);