1 /* vi: set sw=4 ts=4: */
3 * run as root, but NOT setuid root
5 * Copyright 1994 Matthew Dillon (dillon@apollo.west.oic.com)
7 * Vladimir Oleynik <dzo@simtreas.ru> (C) 2002
9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
12 //config: bool "crond"
14 //config: select FEATURE_SYSLOG
16 //config: Crond is a background daemon that parses individual crontab
17 //config: files and executes commands on behalf of the users in question.
18 //config: This is a port of dcron from slackware. It uses files of the
19 //config: format /var/spool/cron/crontabs/<username> files, for example:
20 //config: $ cat /var/spool/cron/crontabs/root
21 //config: # Run daily cron jobs at 4:40 every day:
22 //config: 40 4 * * * /etc/cron/daily > /dev/null 2>&1
24 //config:config FEATURE_CROND_D
25 //config: bool "Support option -d to redirect output to stderr"
26 //config: depends on CROND
29 //config: -d N sets loglevel (0:most verbose) and directs all output to stderr.
31 //config:config FEATURE_CROND_CALL_SENDMAIL
32 //config: bool "Report command output via email (using sendmail)"
34 //config: depends on CROND
36 //config: Command output will be sent to corresponding user via email.
38 //config:config FEATURE_CROND_DIR
39 //config: string "crond spool directory"
40 //config: default "/var/spool/cron"
41 //config: depends on CROND || CRONTAB
43 //config: Location of crond spool.
45 //applet:IF_CROND(APPLET(crond, BB_DIR_USR_SBIN, BB_SUID_DROP))
47 //kbuild:lib-$(CONFIG_CROND) += crond.o
49 //usage:#define crond_trivial_usage
50 //usage: "-fbS -l N " IF_FEATURE_CROND_D("-d N ") "-L LOGFILE -c DIR"
51 //usage:#define crond_full_usage "\n\n"
52 //usage: " -f Foreground"
53 //usage: "\n -b Background (default)"
54 //usage: "\n -S Log to syslog (default)"
55 //usage: "\n -l N Set log level. Most verbose:0, default:8"
56 //usage: IF_FEATURE_CROND_D(
57 //usage: "\n -d N Set log level, log to stderr"
59 //usage: "\n -L FILE Log to FILE"
60 //usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs"
63 #include "common_bufsiz.h"
66 /* glibc frees previous setenv'ed value when we do next setenv()
67 * of the same variable. uclibc does not do this! */
68 #if (defined(__GLIBC__) && !defined(__UCLIBC__)) /* || OTHER_SAFE_LIBC... */
69 # define SETENV_LEAKS 0
71 # define SETENV_LEAKS 1
75 #define CRON_DIR CONFIG_FEATURE_CROND_DIR
76 #define CRONTABS CONFIG_FEATURE_CROND_DIR "/crontabs"
78 # define SENDMAIL "sendmail"
81 # define SENDMAIL_ARGS "-ti"
84 # define CRONUPDATE "cron.update"
87 # define MAXLINES 256 /* max lines in non-root crontabs */
91 typedef struct CronFile {
92 struct CronFile *cf_next;
93 struct CronLine *cf_lines;
95 smallint cf_wants_starting; /* bool: one or more jobs ready */
96 smallint cf_has_running; /* bool: one or more jobs running */
97 smallint cf_deleted; /* marked for deletion (but still has running jobs) */
100 typedef struct CronLine {
101 struct CronLine *cl_next;
102 char *cl_cmd; /* shell command */
103 pid_t cl_pid; /* >0:running, <0:needs to be started in this minute, 0:dormant */
104 #if ENABLE_FEATURE_CROND_CALL_SENDMAIL
105 int cl_empty_mail_size; /* size of mail header only, 0 if no mailfile */
106 char *cl_mailto; /* whom to mail results, may be NULL */
109 /* ordered by size, not in natural order. makes code smaller: */
110 char cl_Dow[7]; /* 0-6, beginning sunday */
111 char cl_Mons[12]; /* 0-11 */
112 char cl_Hrs[24]; /* 0-23 */
113 char cl_Days[32]; /* 1-31 */
114 char cl_Mins[60]; /* 0-59 */
128 OPT_d = (1 << 6) * ENABLE_FEATURE_CROND_D,
132 unsigned log_level; /* = 8; */
133 time_t crontab_dir_mtime;
134 const char *log_filename;
135 const char *crontab_dir_name; /* = CRONTABS; */
136 CronFile *cron_files;
141 char *env_var_logname;
144 #define G (*(struct globals*)bb_common_bufsiz1)
145 #define INIT_G() do { \
146 setup_common_bufsiz(); \
148 G.crontab_dir_name = CRONTABS; \
152 * 0 is the most verbose, default 8.
153 * For some reason, in fact only 5, 7 and 8 are used.
155 static void crondlog(unsigned level, const char *msg, va_list va)
157 if (level >= G.log_level) {
159 * We are called only for info meesages.
160 * Warnings/errors use plain bb_[p]error_msg's, which
161 * need not touch syslog_level
162 * (they are ok with LOG_ERR default).
164 syslog_level = LOG_INFO;
165 bb_verror_msg(msg, va, /* strerr: */ NULL);
166 syslog_level = LOG_ERR;
170 static void log5(const char *msg, ...)
174 crondlog(4, msg, va);
178 static void log7(const char *msg, ...)
182 crondlog(7, msg, va);
186 static void log8(const char *msg, ...)
190 crondlog(8, msg, va);
195 static const char DowAry[] ALIGN1 =
196 "sun""mon""tue""wed""thu""fri""sat"
199 static const char MonAry[] ALIGN1 =
200 "jan""feb""mar""apr""may""jun""jul""aug""sep""oct""nov""dec"
203 static void ParseField(char *user, char *ary, int modvalue, int off,
204 const char *names, char *ptr)
205 /* 'names' is a pointer to a set of 3-char abbreviations */
211 // this can't happen due to config_read()
218 /* Handle numeric digit or symbol or '*' */
220 n1 = 0; /* everything will be filled */
224 } else if (isdigit(*ptr)) {
227 n1 = strtol(ptr, &endp, 10) + off;
229 n2 = strtol(ptr, &endp, 10) + off;
231 ptr = endp; /* gcc likes temp var for &endp */
236 for (i = 0; names[i]; i += 3) {
237 /* was using strncmp before... */
238 if (strncasecmp(ptr, &names[i], 3) == 0) {
251 /* handle optional range '-' */
255 if (*ptr == '-' && n2 < 0) {
261 * collapse single-value ranges, handle skipmark, and fill
262 * in the character array appropriately.
269 skip = strtol(ptr + 1, &endp, 10);
270 ptr = endp; /* gcc likes temp var for &endp */
274 * fill array, using a failsafe is the easiest way to prevent
283 n1 = (n1 + 1) % modvalue;
286 ary[n1 % modvalue] = 1;
289 if (--failsafe == 0) {
304 bb_error_msg("user %s: parse error at %s", user, base);
308 /* can't use log5 (it inserts newlines), open-coding it */
309 if (G.log_level <= 5 && logmode != LOGMODE_SYSLOG) {
311 for (i = 0; i < modvalue; ++i)
312 fprintf(stderr, "%d", (unsigned char)ary[i]);
313 bb_putchar_stderr('\n');
317 static void FixDayDow(CronLine *line)
323 for (i = 0; i < ARRAY_SIZE(line->cl_Dow); ++i) {
324 if (line->cl_Dow[i] == 0) {
329 for (i = 0; i < ARRAY_SIZE(line->cl_Days); ++i) {
330 if (line->cl_Days[i] == 0) {
335 if (weekUsed != daysUsed) {
337 memset(line->cl_Days, 0, sizeof(line->cl_Days));
339 memset(line->cl_Dow, 0, sizeof(line->cl_Dow));
344 * delete_cronfile() - delete user database
346 * Note: multiple entries for same user may exist if we were unable to
347 * completely delete a database due to running processes.
349 //FIXME: we will start a new job even if the old job is running
350 //if crontab was reloaded: crond thinks that "new" job is different from "old"
351 //even if they are in fact completely the same. Example
354 // 0-59 * * * * long_running_job2
355 //User edits crontab to:
356 // 0-59 * * * * job1_updated
357 // 0-59 * * * * long_running_job2
358 //Bug: crond can now start another long_running_job2 even if old one
360 //OTOH most other versions of cron do not wait for job termination anyway,
361 //they end up with multiple copies of jobs if they don't terminate soon enough.
362 static void delete_cronfile(const char *userName)
364 CronFile **pfile = &G.cron_files;
367 while ((file = *pfile) != NULL) {
368 if (strcmp(userName, file->cf_username) == 0) {
369 CronLine **pline = &file->cf_lines;
372 file->cf_has_running = 0;
373 file->cf_deleted = 1;
375 while ((line = *pline) != NULL) {
376 if (line->cl_pid > 0) {
377 file->cf_has_running = 1;
378 pline = &line->cl_next;
380 *pline = line->cl_next;
385 if (file->cf_has_running == 0) {
386 *pfile = file->cf_next;
387 free(file->cf_username);
392 pfile = &file->cf_next;
396 static void load_crontab(const char *fileName)
398 struct parser_t *parser;
402 #if ENABLE_FEATURE_CROND_CALL_SENDMAIL
407 delete_cronfile(fileName);
409 if (!getpwnam(fileName)) {
410 log7("ignoring file '%s' (no such user)", fileName);
414 parser = config_open(fileName);
418 maxLines = (strcmp(fileName, "root") == 0) ? 65535 : MAXLINES;
420 if (fstat(fileno(parser->fp), &sbuf) == 0 && sbuf.st_uid == DAEMON_UID) {
421 CronFile *file = xzalloc(sizeof(CronFile));
425 file->cf_username = xstrdup(fileName);
426 pline = &file->cf_lines;
432 bb_error_msg("user %s: too many lines", fileName);
436 n = config_read(parser, tokens, 6, 1, "# \t", PARSE_NORMAL | PARSE_KEEP_COPY);
440 log5("user:%s entry:%s", fileName, parser->data);
442 /* check if line is setting MAILTO= */
443 if (is_prefixed_with(tokens[0], "MAILTO=")) {
444 #if ENABLE_FEATURE_CROND_CALL_SENDMAIL
446 mailTo = (tokens[0][7]) ? xstrdup(&tokens[0][7]) : NULL;
447 #endif /* otherwise just ignore such lines */
450 if (is_prefixed_with(tokens[0], "SHELL=")) {
452 shell = xstrdup(&tokens[0][6]);
455 //TODO: handle HOME= too? "man crontab" says:
458 //where the spaces around the equal-sign (=) are optional, and any subsequent
459 //non-leading spaces in value will be part of the value assigned to name.
460 //The value string may be placed in quotes (single or double, but matching)
461 //to preserve leading or trailing blanks.
463 //Several environment variables are set up automatically by the cron(8) daemon.
464 //SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd
465 //line of the crontab's owner. HOME and SHELL may be overridden by settings
466 //in the crontab; LOGNAME may not.
468 /* check if a minimum of tokens is specified */
471 *pline = line = xzalloc(sizeof(*line));
472 /* parse date ranges */
473 ParseField(file->cf_username, line->cl_Mins, 60, 0, NULL, tokens[0]);
474 ParseField(file->cf_username, line->cl_Hrs, 24, 0, NULL, tokens[1]);
475 ParseField(file->cf_username, line->cl_Days, 32, 0, NULL, tokens[2]);
476 ParseField(file->cf_username, line->cl_Mons, 12, -1, MonAry, tokens[3]);
477 ParseField(file->cf_username, line->cl_Dow, 7, 0, DowAry, tokens[4]);
479 * fix days and dow - if one is not "*" and the other
480 * is "*", the other is set to 0, and vise-versa
483 #if ENABLE_FEATURE_CROND_CALL_SENDMAIL
484 /* copy mailto (can be NULL) */
485 line->cl_mailto = xstrdup(mailTo);
487 line->cl_shell = xstrdup(shell);
489 line->cl_cmd = xstrdup(tokens[5]);
490 pline = &line->cl_next;
491 //bb_error_msg("M[%s]F[%s][%s][%s][%s][%s][%s]", mailTo, tokens[0], tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]);
495 file->cf_next = G.cron_files;
498 config_close(parser);
499 #if ENABLE_FEATURE_CROND_CALL_SENDMAIL
505 static void process_cron_update_file(void)
510 fi = fopen_for_read(CRONUPDATE);
513 while (fgets(buf, sizeof(buf), fi) != NULL) {
514 /* use first word only */
515 skip_non_whitespace(buf)[0] = '\0';
522 static void rescan_crontab_dir(void)
526 /* Delete all files until we only have ones with running jobs (or none) */
528 for (file = G.cron_files; file; file = file->cf_next) {
529 if (!file->cf_deleted) {
530 delete_cronfile(file->cf_username);
535 /* Remove cron update file */
537 /* Re-chdir, in case directory was renamed & deleted */
538 xchdir(G.crontab_dir_name);
540 /* Scan directory and add associated users */
542 DIR *dir = opendir(".");
545 /* xopendir exists, but "can't open '.'" is not informative */
547 bb_error_msg_and_die("can't open '%s'", G.crontab_dir_name);
548 while ((den = readdir(dir)) != NULL) {
549 if (strchr(den->d_name, '.') != NULL) {
552 load_crontab(den->d_name);
559 /* We set environment *before* vfork (because we want to use vfork),
560 * so we cannot use setenv() - repeated calls to setenv() may leak memory!
561 * Using putenv(), and freeing memory after unsetenv() won't leak */
562 static void safe_setenv(char **pvar_val, const char *var, const char *val)
564 char *var_val = *pvar_val;
567 bb_unsetenv_and_free(var_val);
569 *pvar_val = xasprintf("%s=%s", var, val);
574 static void set_env_vars(struct passwd *pas, const char *shell)
576 /* POSIX requires crond to set up at least HOME, LOGNAME, PATH, SHELL.
577 * We assume crond inherited suitable PATH.
580 safe_setenv(&G.env_var_logname, "LOGNAME", pas->pw_name);
581 safe_setenv(&G.env_var_user, "USER", pas->pw_name);
582 safe_setenv(&G.env_var_home, "HOME", pas->pw_dir);
583 safe_setenv(&G.env_var_shell, "SHELL", shell);
585 xsetenv("LOGNAME", pas->pw_name);
586 xsetenv("USER", pas->pw_name);
587 xsetenv("HOME", pas->pw_dir);
588 xsetenv("SHELL", shell);
592 static void change_user(struct passwd *pas)
594 /* careful: we're after vfork! */
595 change_identity(pas); /* - initgroups, setgid, setuid */
596 if (chdir(pas->pw_dir) < 0) {
597 bb_error_msg("can't change directory to '%s'", pas->pw_dir);
602 // TODO: sendmail should be _run-time_ option, not compile-time!
603 #if ENABLE_FEATURE_CROND_CALL_SENDMAIL
606 fork_job(const char *user, int mailFd, CronLine *line, bool run_sendmail)
609 const char *shell, *prog;
613 /* prepare things before vfork */
614 pas = getpwnam(user);
616 bb_error_msg("can't get uid for %s", user);
620 shell = line->cl_shell ? line->cl_shell : DEFAULT_SHELL;
621 prog = run_sendmail ? SENDMAIL : shell;
623 set_env_vars(pas, shell);
625 sv_logmode = logmode;
629 /* initgroups, setgid, setuid, and chdir to home or CRON_DIR */
631 log5("child running %s", prog);
633 xmove_fd(mailFd, run_sendmail ? 0 : 1);
636 /* crond 3.0pl1-100 puts tasks in separate process groups */
639 execlp(prog, prog, "-c", line->cl_cmd, (char *) NULL);
641 execlp(prog, prog, SENDMAIL_ARGS, (char *) NULL);
643 * I want this error message on stderr too,
644 * even if other messages go only to syslog:
646 logmode |= LOGMODE_STDIO;
647 bb_error_msg_and_die("can't execute '%s' for user %s", prog, user);
649 logmode = sv_logmode;
652 bb_perror_msg("vfork");
655 } /* else: PARENT, FORK SUCCESS */
658 * Close the mail file descriptor.. we can't just leave it open in
659 * a structure, closing it later, because we might run out of descriptors
667 static void start_one_job(const char *user, CronLine *line)
673 line->cl_empty_mail_size = 0;
675 if (line->cl_mailto) {
676 /* Open mail file (owner is root so nobody can screw with it) */
677 snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", CRON_DIR, user, getpid());
678 mailFd = open(mailFile, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL | O_APPEND, 0600);
681 fdprintf(mailFd, "To: %s\nSubject: cron: %s\n\n", line->cl_mailto,
683 line->cl_empty_mail_size = lseek(mailFd, 0, SEEK_CUR);
685 bb_error_msg("can't create mail file %s for user %s, "
686 "discarding output", mailFile, user);
690 line->cl_pid = fork_job(user, mailFd, line, /*sendmail?*/ 0);
692 if (line->cl_pid <= 0) {
695 /* rename mail-file based on pid of process */
696 char *mailFile2 = xasprintf("%s/cron.%s.%d", CRON_DIR, user, (int)line->cl_pid);
697 rename(mailFile, mailFile2); // TODO: xrename?
704 * process_finished_job - called when job terminates and when mail terminates
706 static void process_finished_job(const char *user, CronLine *line)
719 if (line->cl_empty_mail_size <= 0) {
720 /* End of job and no mail file, or end of sendmail job */
725 * End of primary job - check for mail file.
726 * If size has changed and the file is still valid, we send it.
728 snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", CRON_DIR, user, (int)pid);
729 mailFd = open(mailFile, O_RDONLY);
735 if (fstat(mailFd, &sbuf) < 0
736 || sbuf.st_uid != DAEMON_UID
737 || sbuf.st_nlink != 0
738 || sbuf.st_size == line->cl_empty_mail_size
739 || !S_ISREG(sbuf.st_mode)
744 line->cl_empty_mail_size = 0;
745 /* if (line->cl_mailto) - always true if cl_empty_mail_size was nonzero */
746 line->cl_pid = fork_job(user, mailFd, line, /*sendmail?*/ 1);
749 #else /* !ENABLE_FEATURE_CROND_CALL_SENDMAIL */
751 static void start_one_job(const char *user, CronLine *line)
757 pas = getpwnam(user);
759 bb_error_msg("can't get uid for %s", user);
763 /* Prepare things before vfork */
764 shell = line->cl_shell ? line->cl_shell : DEFAULT_SHELL;
765 set_env_vars(pas, shell);
767 /* Fork as the user in question and run program */
771 /* initgroups, setgid, setuid, and chdir to home or CRON_DIR */
773 log5("child running %s", shell);
774 /* crond 3.0pl1-100 puts tasks in separate process groups */
776 execl(shell, shell, "-c", line->cl_cmd, (char *) NULL);
777 bb_error_msg_and_die("can't execute '%s' for user %s", shell, user);
780 bb_perror_msg("vfork");
787 #define process_finished_job(user, line) ((line)->cl_pid = 0)
789 #endif /* !ENABLE_FEATURE_CROND_CALL_SENDMAIL */
792 * Determine which jobs need to be run. Under normal conditions, the
793 * period is about a minute (one scan). Worst case it will be one
796 static void flag_starting_jobs(time_t t1, time_t t2)
800 /* Find jobs > t1 and <= t2 */
802 for (t = t1 - t1 % 60; t <= t2; t += 60) {
811 for (file = G.cron_files; file; file = file->cf_next) {
812 log5("file %s:", file->cf_username);
813 if (file->cf_deleted)
815 for (line = file->cf_lines; line; line = line->cl_next) {
816 log5(" line %s", line->cl_cmd);
817 if (line->cl_Mins[ptm->tm_min]
818 && line->cl_Hrs[ptm->tm_hour]
819 && (line->cl_Days[ptm->tm_mday] || line->cl_Dow[ptm->tm_wday])
820 && line->cl_Mons[ptm->tm_mon]
823 (int)line->cl_pid, line->cl_cmd);
824 if (line->cl_pid > 0) {
825 log8("user %s: process already running: %s",
826 file->cf_username, line->cl_cmd);
827 } else if (line->cl_pid == 0) {
829 file->cf_wants_starting = 1;
837 static void start_jobs(void)
842 for (file = G.cron_files; file; file = file->cf_next) {
843 if (!file->cf_wants_starting)
846 file->cf_wants_starting = 0;
847 for (line = file->cf_lines; line; line = line->cl_next) {
849 if (line->cl_pid >= 0)
852 start_one_job(file->cf_username, line);
854 log8("USER %s pid %3d cmd %s",
855 file->cf_username, (int)pid, line->cl_cmd);
857 file->cf_wants_starting = 1;
860 file->cf_has_running = 1;
867 * Check for job completion, return number of jobs still running after
870 static int check_completions(void)
874 int num_still_running = 0;
876 for (file = G.cron_files; file; file = file->cf_next) {
877 if (!file->cf_has_running)
880 file->cf_has_running = 0;
881 for (line = file->cf_lines; line; line = line->cl_next) {
884 if (line->cl_pid <= 0)
887 r = waitpid(line->cl_pid, NULL, WNOHANG);
888 if (r < 0 || r == line->cl_pid) {
889 process_finished_job(file->cf_username, line);
890 if (line->cl_pid == 0) {
891 /* sendmail was not started for it */
894 /* else: sendmail was started, job is still running, fall thru */
896 /* else: r == 0: "process is still running" */
897 file->cf_has_running = 1;
899 //FIXME: if !file->cf_has_running && file->deleted: delete it!
900 //otherwise deleted entries will stay forever, right?
901 num_still_running += file->cf_has_running;
903 return num_still_running;
906 static void reopen_logfile_to_stderr(void)
908 if (G.log_filename) {
909 int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND);
911 xmove_fd(logfd, STDERR_FILENO);
915 int crond_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
916 int crond_main(int argc UNUSED_PARAM, char **argv)
925 /* "-b after -f is ignored", and so on for every pair a-b */
926 opt_complementary = "f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l")
927 /* -l and -d have numeric param */
928 ":l+" IF_FEATURE_CROND_D(":d+");
929 opts = getopt32(argv, "l:L:fbSc:" IF_FEATURE_CROND_D("d:"),
930 &G.log_level, &G.log_filename, &G.crontab_dir_name
931 IF_FEATURE_CROND_D(,&G.log_level));
932 /* both -d N and -l N set the same variable: G.log_level */
934 if (!(opts & OPT_f)) {
935 /* close stdin, stdout, stderr.
936 * close unused descriptors - don't need them. */
937 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
940 if (!(opts & OPT_d) && G.log_filename == NULL) {
941 /* logging to syslog */
942 openlog(applet_name, LOG_CONS | LOG_PID, LOG_CRON);
943 logmode = LOGMODE_SYSLOG;
946 //signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */
948 reopen_logfile_to_stderr();
949 xchdir(G.crontab_dir_name);
950 log8("crond (busybox "BB_VER") started, log level %d", G.log_level);
951 rescan_crontab_dir();
952 write_pidfile(CONFIG_PID_FILE_PATH "/crond.pid");
963 /* Synchronize to 1 minute, minimum 1 second */
965 sleep(sleep_time - (time(NULL) % sleep_time));
967 dt = (long)t2 - (long)t1;
969 reopen_logfile_to_stderr();
972 * The file 'cron.update' is checked to determine new cron
973 * jobs. The directory is rescanned once an hour to deal
976 * Check for time jump. Disparities over an hour either way
977 * result in resynchronization. A negative disparity
978 * less than an hour causes us to effectively sleep until we
979 * match the original time (i.e. no re-execution of jobs that
980 * have just been run). A positive disparity less than
981 * an hour causes intermediate jobs to be run, but only once
984 * When running jobs, the inequality used is greater but not
985 * equal to t1, and less then or equal to t2.
987 if (stat(G.crontab_dir_name, &sbuf) != 0)
988 sbuf.st_mtime = 0; /* force update (once) if dir was deleted */
989 if (G.crontab_dir_mtime != sbuf.st_mtime) {
990 G.crontab_dir_mtime = sbuf.st_mtime;
995 rescan_crontab_dir();
997 process_cron_update_file();
998 log5("wakeup dt=%ld", dt);
999 if (dt < -60 * 60 || dt > 60 * 60) {
1000 bb_error_msg("time disparity of %ld minutes detected", dt / 60);
1001 /* and we do not run any jobs in this case */
1002 } else if (dt > 0) {
1003 /* Usual case: time advances forward, as expected */
1004 flag_starting_jobs(t1, t2);
1007 if (check_completions() > 0) {
1008 /* some jobs are still running */
1012 /* else: time jumped back, do not run any jobs */
1015 return 0; /* not reached */