Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/miscutils/crond.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/miscutils/crond.c

    r3232 r3621  
    11/* vi: set sw=4 ts=4: */
    22/*
    3  * crond -d[#] -c <crondir> -f -b
    4  *
    53 * run as root, but NOT setuid root
    64 *
     
    119 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1210 */
     11//config:config CROND
     12//config:   bool "crond"
     13//config:   default y
     14//config:   select FEATURE_SYSLOG
     15//config:   help
     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
     23//config:
     24//config:config FEATURE_CROND_D
     25//config:   bool "Support option -d to redirect output to stderr"
     26//config:   depends on CROND
     27//config:   default y
     28//config:   help
     29//config:     -d N sets loglevel (0:most verbose) and directs all output to stderr.
     30//config:
     31//config:config FEATURE_CROND_CALL_SENDMAIL
     32//config:   bool "Report command output via email (using sendmail)"
     33//config:   default y
     34//config:   depends on CROND
     35//config:   help
     36//config:     Command output will be sent to corresponding user via email.
     37//config:
     38//config:config FEATURE_CROND_DIR
     39//config:   string "crond spool directory"
     40//config:   default "/var/spool/cron"
     41//config:   depends on CROND || CRONTAB
     42//config:   help
     43//config:     Location of crond spool.
     44
     45//applet:IF_CROND(APPLET(crond, BB_DIR_USR_SBIN, BB_SUID_DROP))
     46
     47//kbuild:lib-$(CONFIG_CROND) += crond.o
    1348
    1449//usage:#define crond_trivial_usage
     
    1853//usage:     "\n    -b  Background (default)"
    1954//usage:     "\n    -S  Log to syslog (default)"
    20 //usage:     "\n    -l  Set log level. 0 is the most verbose, default 8"
     55//usage:     "\n    -l N    Set log level. Most verbose:0, default:8"
    2156//usage:    IF_FEATURE_CROND_D(
    22 //usage:     "\n    -d  Set log level, log to stderr"
     57//usage:     "\n    -d N    Set log level, log to stderr"
    2358//usage:    )
    24 //usage:     "\n    -L  Log to file"
    25 //usage:     "\n    -c  Working dir"
     59//usage:     "\n    -L FILE Log to FILE"
     60//usage:     "\n    -c DIR  Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs"
    2661
    2762#include "libbb.h"
     63#include "common_bufsiz.h"
    2864#include <syslog.h>
    2965
     
    3773
    3874
    39 #define TMPDIR          CONFIG_FEATURE_CROND_DIR
     75#define CRON_DIR        CONFIG_FEATURE_CROND_DIR
    4076#define CRONTABS        CONFIG_FEATURE_CROND_DIR "/crontabs"
    4177#ifndef SENDMAIL
     
    70106    char *cl_mailto;                /* whom to mail results, may be NULL */
    71107#endif
     108    char *cl_shell;
    72109    /* ordered by size, not in natural order. makes code smaller: */
    73110    char cl_Dow[7];                 /* 0-6, beginning sunday */
     
    91128    OPT_d = (1 << 6) * ENABLE_FEATURE_CROND_D,
    92129};
    93 #if ENABLE_FEATURE_CROND_D
    94 # define DebugOpt (option_mask32 & OPT_d)
    95 #else
    96 # define DebugOpt 0
    97 #endif
    98 
    99130
    100131struct globals {
     
    107138    char *env_var_user;
    108139    char *env_var_home;
     140    char *env_var_shell;
     141    char *env_var_logname;
    109142#endif
    110143} FIX_ALIASING;
    111 #define G (*(struct globals*)&bb_common_bufsiz1)
     144#define G (*(struct globals*)bb_common_bufsiz1)
    112145#define INIT_G() do { \
     146    setup_common_bufsiz(); \
    113147    G.log_level = 8; \
    114148    G.crontab_dir_name = CRONTABS; \
    115149} while (0)
    116150
    117 
    118 /* 0 is the most verbose, default 8 */
    119 #define LVL5  "\x05"
    120 #define LVL7  "\x07"
    121 #define LVL8  "\x08"
    122 #define WARN9 "\x49"
    123 #define DIE9  "\xc9"
    124 /* level >= 20 is "error" */
    125 #define ERR20 "\x14"
    126 
    127 static void crondlog(const char *ctl, ...) __attribute__ ((format (printf, 1, 2)));
    128 static void crondlog(const char *ctl, ...)
     151/* Log levels:
     152 * 0 is the most verbose, default 8.
     153 * For some reason, in fact only 5, 7 and 8 are used.
     154 */
     155static void crondlog(unsigned level, const char *msg, va_list va)
     156{
     157    if (level >= G.log_level) {
     158        /*
     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).
     163         */
     164        syslog_level = LOG_INFO;
     165        bb_verror_msg(msg, va, /* strerr: */ NULL);
     166        syslog_level = LOG_ERR;
     167    }
     168}
     169
     170static void log5(const char *msg, ...)
    129171{
    130172    va_list va;
    131     int level = (ctl[0] & 0x1f);
    132 
    133     va_start(va, ctl);
    134     if (level >= (int)G.log_level) {
    135         /* Debug mode: all to (non-redirected) stderr, */
    136         /* Syslog mode: all to syslog (logmode = LOGMODE_SYSLOG), */
    137         if (!DebugOpt && G.log_filename) {
    138             /* Otherwise (log to file): we reopen log file at every write: */
    139             int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND);
    140             if (logfd >= 0)
    141                 xmove_fd(logfd, STDERR_FILENO);
    142         }
    143         /* When we log to syslog, level > 8 is logged at LOG_ERR
    144          * syslog level, level <= 8 is logged at LOG_INFO. */
    145         if (level > 8) {
    146             bb_verror_msg(ctl + 1, va, /* strerr: */ NULL);
    147         } else {
    148             char *msg = NULL;
    149             vasprintf(&msg, ctl + 1, va);
    150             bb_info_msg("%s: %s", applet_name, msg);
    151             free(msg);
    152         }
    153     }
     173    va_start(va, msg);
     174    crondlog(4, msg, va);
    154175    va_end(va);
    155     if (ctl[0] & 0x80)
    156         exit(20);
    157 }
     176}
     177
     178static void log7(const char *msg, ...)
     179{
     180    va_list va;
     181    va_start(va, msg);
     182    crondlog(7, msg, va);
     183    va_end(va);
     184}
     185
     186static void log8(const char *msg, ...)
     187{
     188    va_list va;
     189    va_start(va, msg);
     190    crondlog(8, msg, va);
     191    va_end(va);
     192}
     193
    158194
    159195static const char DowAry[] ALIGN1 =
    160196    "sun""mon""tue""wed""thu""fri""sat"
    161     /* "Sun""Mon""Tue""Wed""Thu""Fri""Sat" */
    162197;
    163198
    164199static const char MonAry[] ALIGN1 =
    165200    "jan""feb""mar""apr""may""jun""jul""aug""sep""oct""nov""dec"
    166     /* "Jan""Feb""Mar""Apr""May""Jun""Jul""Aug""Sep""Oct""Nov""Dec" */
    167201;
    168202
     
    268302    if (*ptr) {
    269303 err:
    270         crondlog(WARN9 "user %s: parse error at %s", user, base);
     304        bb_error_msg("user %s: parse error at %s", user, base);
    271305        return;
    272306    }
    273307
    274     if (DebugOpt && (G.log_level <= 5)) { /* like LVL5 */
    275         /* can't use crondlog, it inserts '\n' */
     308    /* can't use log5 (it inserts newlines), open-coding it */
     309    if (G.log_level <= 5 && logmode != LOGMODE_SYSLOG) {
    276310        int i;
    277311        for (i = 0; i < modvalue; ++i)
     
    369403    char *mailTo = NULL;
    370404#endif
     405    char *shell = NULL;
    371406
    372407    delete_cronfile(fileName);
    373408
    374409    if (!getpwnam(fileName)) {
    375         crondlog(LVL7 "ignoring file '%s' (no such user)", fileName);
     410        log7("ignoring file '%s' (no such user)", fileName);
    376411        return;
    377412    }
     
    394429            CronLine *line;
    395430
    396             if (!--maxLines)
     431            if (!--maxLines) {
     432                bb_error_msg("user %s: too many lines", fileName);
    397433                break;
     434            }
     435
    398436            n = config_read(parser, tokens, 6, 1, "# \t", PARSE_NORMAL | PARSE_KEEP_COPY);
    399437            if (!n)
    400438                break;
    401439
    402             if (DebugOpt)
    403                 crondlog(LVL5 "user:%s entry:%s", fileName, parser->data);
     440            log5("user:%s entry:%s", fileName, parser->data);
    404441
    405442            /* check if line is setting MAILTO= */
    406             if (0 == strncmp(tokens[0], "MAILTO=", 7)) {
     443            if (is_prefixed_with(tokens[0], "MAILTO=")) {
    407444#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
    408445                free(mailTo);
     
    411448                continue;
    412449            }
     450            if (is_prefixed_with(tokens[0], "SHELL=")) {
     451                free(shell);
     452                shell = xstrdup(&tokens[0][6]);
     453                continue;
     454            }
     455//TODO: handle HOME= too? "man crontab" says:
     456//name = value
     457//
     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.
     462//
     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.
     467
    413468            /* check if a minimum of tokens is specified */
    414469            if (n < 6)
     
    430485            line->cl_mailto = xstrdup(mailTo);
    431486#endif
     487            line->cl_shell = xstrdup(shell);
    432488            /* copy command */
    433489            line->cl_cmd = xstrdup(tokens[5]);
    434             if (DebugOpt) {
    435                 crondlog(LVL5 " command:%s", tokens[5]);
    436             }
    437490            pline = &line->cl_next;
    438491//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]);
     
    442495        file->cf_next = G.cron_files;
    443496        G.cron_files = file;
    444 
    445         if (maxLines == 0) {
    446             crondlog(WARN9 "user %s: too many lines", fileName);
    447         }
    448497    }
    449498    config_close(parser);
     499#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
     500    free(mailTo);
     501#endif
     502    free(shell);
    450503}
    451504
     
    483536    unlink(CRONUPDATE);
    484537    /* Re-chdir, in case directory was renamed & deleted */
    485     if (chdir(G.crontab_dir_name) < 0) {
    486         crondlog(DIE9 "chdir(%s)", G.crontab_dir_name);
    487     }
     538    xchdir(G.crontab_dir_name);
    488539
    489540    /* Scan directory and add associated users */
     
    492543        struct dirent *den;
    493544
     545        /* xopendir exists, but "can't open '.'" is not informative */
    494546        if (!dir)
    495             crondlog(DIE9 "chdir(%s)", "."); /* exits */
     547            bb_error_msg_and_die("can't open '%s'", G.crontab_dir_name);
    496548        while ((den = readdir(dir)) != NULL) {
    497549            if (strchr(den->d_name, '.') != NULL) {
     
    520572#endif
    521573
    522 static void set_env_vars(struct passwd *pas)
    523 {
     574static void set_env_vars(struct passwd *pas, const char *shell)
     575{
     576    /* POSIX requires crond to set up at least HOME, LOGNAME, PATH, SHELL.
     577     * We assume crond inherited suitable PATH.
     578     */
    524579#if SETENV_LEAKS
     580    safe_setenv(&G.env_var_logname, "LOGNAME", pas->pw_name);
    525581    safe_setenv(&G.env_var_user, "USER", pas->pw_name);
    526582    safe_setenv(&G.env_var_home, "HOME", pas->pw_dir);
    527     /* if we want to set user's shell instead: */
    528     /*safe_setenv(G.env_var_shell, "SHELL", pas->pw_shell);*/
     583    safe_setenv(&G.env_var_shell, "SHELL", shell);
    529584#else
     585    xsetenv("LOGNAME", pas->pw_name);
    530586    xsetenv("USER", pas->pw_name);
    531587    xsetenv("HOME", pas->pw_dir);
    532 #endif
    533     /* currently, we use constant one: */
    534     /*setenv("SHELL", DEFAULT_SHELL, 1); - done earlier */
     588    xsetenv("SHELL", shell);
     589#endif
    535590}
    536591
     
    540595    change_identity(pas); /* - initgroups, setgid, setuid */
    541596    if (chdir(pas->pw_dir) < 0) {
    542         crondlog(WARN9 "chdir(%s)", pas->pw_dir);
    543         if (chdir(TMPDIR) < 0) {
    544             crondlog(DIE9 "chdir(%s)", TMPDIR); /* exits */
    545         }
     597        bb_error_msg("can't change directory to '%s'", pas->pw_dir);
     598        xchdir(CRON_DIR);
    546599    }
    547600}
     
    551604
    552605static pid_t
    553 fork_job(const char *user, int mailFd,
    554         const char *prog,
    555         const char *shell_cmd /* if NULL, we run sendmail */
    556 ) {
     606fork_job(const char *user, int mailFd, CronLine *line, bool run_sendmail)
     607{
    557608    struct passwd *pas;
     609    const char *shell, *prog;
     610    smallint sv_logmode;
    558611    pid_t pid;
    559612
     
    561614    pas = getpwnam(user);
    562615    if (!pas) {
    563         crondlog(WARN9 "can't get uid for %s", user);
     616        bb_error_msg("can't get uid for %s", user);
    564617        goto err;
    565618    }
    566     set_env_vars(pas);
    567 
     619
     620    shell = line->cl_shell ? line->cl_shell : DEFAULT_SHELL;
     621    prog = run_sendmail ? SENDMAIL : shell;
     622
     623    set_env_vars(pas, shell);
     624
     625    sv_logmode = logmode;
    568626    pid = vfork();
    569627    if (pid == 0) {
    570628        /* CHILD */
    571         /* initgroups, setgid, setuid, and chdir to home or TMPDIR */
     629        /* initgroups, setgid, setuid, and chdir to home or CRON_DIR */
    572630        change_user(pas);
    573         if (DebugOpt) {
    574             crondlog(LVL5 "child running %s", prog);
    575         }
     631        log5("child running %s", prog);
    576632        if (mailFd >= 0) {
    577             xmove_fd(mailFd, shell_cmd ? 1 : 0);
     633            xmove_fd(mailFd, run_sendmail ? 0 : 1);
    578634            dup2(1, 2);
    579635        }
    580636        /* crond 3.0pl1-100 puts tasks in separate process groups */
    581637        bb_setpgrp();
    582         execlp(prog, prog, (shell_cmd ? "-c" : SENDMAIL_ARGS), shell_cmd, (char *) NULL);
    583         crondlog(ERR20 "can't execute '%s' for user %s", prog, user);
    584         if (shell_cmd) {
    585             fdprintf(1, "Exec failed: %s -c %s\n", prog, shell_cmd);
    586         }
    587         _exit(EXIT_SUCCESS);
    588     }
     638        if (!run_sendmail)
     639            execlp(prog, prog, "-c", line->cl_cmd, (char *) NULL);
     640        else
     641            execlp(prog, prog, SENDMAIL_ARGS, (char *) NULL);
     642        /*
     643         * I want this error message on stderr too,
     644         * even if other messages go only to syslog:
     645         */
     646        logmode |= LOGMODE_STDIO;
     647        bb_error_msg_and_die("can't execute '%s' for user %s", prog, user);
     648    }
     649    logmode = sv_logmode;
    589650
    590651    if (pid < 0) {
    591         /* FORK FAILED */
    592         crondlog(ERR20 "can't vfork");
     652        bb_perror_msg("vfork");
    593653 err:
    594654        pid = 0;
     
    615675    if (line->cl_mailto) {
    616676        /* Open mail file (owner is root so nobody can screw with it) */
    617         snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", TMPDIR, user, getpid());
     677        snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", CRON_DIR, user, getpid());
    618678        mailFd = open(mailFile, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL | O_APPEND, 0600);
    619679
     
    623683            line->cl_empty_mail_size = lseek(mailFd, 0, SEEK_CUR);
    624684        } else {
    625             crondlog(ERR20 "can't create mail file %s for user %s, "
     685            bb_error_msg("can't create mail file %s for user %s, "
    626686                    "discarding output", mailFile, user);
    627687        }
    628688    }
    629689
    630     line->cl_pid = fork_job(user, mailFd, DEFAULT_SHELL, line->cl_cmd);
     690    line->cl_pid = fork_job(user, mailFd, line, /*sendmail?*/ 0);
    631691    if (mailFd >= 0) {
    632692        if (line->cl_pid <= 0) {
     
    634694        } else {
    635695            /* rename mail-file based on pid of process */
    636             char *mailFile2 = xasprintf("%s/cron.%s.%d", TMPDIR, user, (int)line->cl_pid);
     696            char *mailFile2 = xasprintf("%s/cron.%s.%d", CRON_DIR, user, (int)line->cl_pid);
    637697            rename(mailFile, mailFile2); // TODO: xrename?
    638698            free(mailFile2);
     
    666726     * If size has changed and the file is still valid, we send it.
    667727     */
    668     snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", TMPDIR, user, (int)pid);
     728    snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", CRON_DIR, user, (int)pid);
    669729    mailFd = open(mailFile, O_RDONLY);
    670730    unlink(mailFile);
     
    684744    line->cl_empty_mail_size = 0;
    685745    /* if (line->cl_mailto) - always true if cl_empty_mail_size was nonzero */
    686         line->cl_pid = fork_job(user, mailFd, SENDMAIL, NULL);
     746        line->cl_pid = fork_job(user, mailFd, line, /*sendmail?*/ 1);
    687747}
    688748
     
    691751static void start_one_job(const char *user, CronLine *line)
    692752{
     753    const char *shell;
    693754    struct passwd *pas;
    694755    pid_t pid;
     
    696757    pas = getpwnam(user);
    697758    if (!pas) {
    698         crondlog(WARN9 "can't get uid for %s", user);
     759        bb_error_msg("can't get uid for %s", user);
    699760        goto err;
    700761    }
    701762
    702763    /* Prepare things before vfork */
    703     set_env_vars(pas);
     764    shell = line->cl_shell ? line->cl_shell : DEFAULT_SHELL;
     765    set_env_vars(pas, shell);
    704766
    705767    /* Fork as the user in question and run program */
     
    707769    if (pid == 0) {
    708770        /* CHILD */
    709         /* initgroups, setgid, setuid, and chdir to home or TMPDIR */
     771        /* initgroups, setgid, setuid, and chdir to home or CRON_DIR */
    710772        change_user(pas);
    711         if (DebugOpt) {
    712             crondlog(LVL5 "child running %s", DEFAULT_SHELL);
    713         }
     773        log5("child running %s", shell);
    714774        /* crond 3.0pl1-100 puts tasks in separate process groups */
    715775        bb_setpgrp();
    716         execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", line->cl_cmd, (char *) NULL);
    717         crondlog(ERR20 "can't execute '%s' for user %s", DEFAULT_SHELL, user);
    718         _exit(EXIT_SUCCESS);
     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);
    719778    }
    720779    if (pid < 0) {
    721         /* FORK FAILED */
    722         crondlog(ERR20 "can't vfork");
     780        bb_perror_msg("vfork");
    723781 err:
    724782        pid = 0;
     
    752810        ptm = localtime(&t);
    753811        for (file = G.cron_files; file; file = file->cf_next) {
    754             if (DebugOpt)
    755                 crondlog(LVL5 "file %s:", file->cf_username);
     812            log5("file %s:", file->cf_username);
    756813            if (file->cf_deleted)
    757814                continue;
    758815            for (line = file->cf_lines; line; line = line->cl_next) {
    759                 if (DebugOpt)
    760                     crondlog(LVL5 " line %s", line->cl_cmd);
     816                log5(" line %s", line->cl_cmd);
    761817                if (line->cl_Mins[ptm->tm_min]
    762818                 && line->cl_Hrs[ptm->tm_hour]
     
    764820                 && line->cl_Mons[ptm->tm_mon]
    765821                ) {
    766                     if (DebugOpt) {
    767                         crondlog(LVL5 " job: %d %s",
     822                    log5(" job: %d %s",
    768823                            (int)line->cl_pid, line->cl_cmd);
    769                     }
    770824                    if (line->cl_pid > 0) {
    771                         crondlog(LVL8 "user %s: process already running: %s",
     825                        log8("user %s: process already running: %s",
    772826                            file->cf_username, line->cl_cmd);
    773827                    } else if (line->cl_pid == 0) {
     
    798852            start_one_job(file->cf_username, line);
    799853            pid = line->cl_pid;
    800             crondlog(LVL8 "USER %s pid %3d cmd %s",
     854            log8("USER %s pid %3d cmd %s",
    801855                file->cf_username, (int)pid, line->cl_cmd);
    802856            if (pid < 0) {
     
    850904}
    851905
     906static void reopen_logfile_to_stderr(void)
     907{
     908    if (G.log_filename) {
     909        int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND);
     910        if (logfd >= 0)
     911            xmove_fd(logfd, STDERR_FILENO);
     912    }
     913}
     914
    852915int crond_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    853916int crond_main(int argc UNUSED_PARAM, char **argv)
    854917{
    855918    time_t t2;
    856     int rescan;
    857     int sleep_time;
     919    unsigned rescan;
     920    unsigned sleep_time;
    858921    unsigned opts;
    859922
     
    881944    }
    882945
     946    //signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */
     947
     948    reopen_logfile_to_stderr();
    883949    xchdir(G.crontab_dir_name);
    884     //signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */
    885     xsetenv("SHELL", DEFAULT_SHELL); /* once, for all future children */
    886     crondlog(LVL8 "crond (busybox "BB_VER") started, log level %d", G.log_level);
     950    log8("crond (busybox "BB_VER") started, log level %d", G.log_level);
    887951    rescan_crontab_dir();
    888952    write_pidfile(CONFIG_PID_FILE_PATH "/crond.pid");
     
    897961        long dt;
    898962
     963        /* Synchronize to 1 minute, minimum 1 second */
    899964        t1 = t2;
    900 
    901         /* Synchronize to 1 minute, minimum 1 second */
    902         sleep(sleep_time - (time(NULL) % sleep_time) + 1);
    903 
     965        sleep(sleep_time - (time(NULL) % sleep_time));
    904966        t2 = time(NULL);
    905967        dt = (long)t2 - (long)t1;
     968
     969        reopen_logfile_to_stderr();
    906970
    907971        /*
     
    932996        }
    933997        process_cron_update_file();
    934         if (DebugOpt)
    935             crondlog(LVL5 "wakeup dt=%ld", dt);
     998        log5("wakeup dt=%ld", dt);
    936999        if (dt < -60 * 60 || dt > 60 * 60) {
    937             crondlog(WARN9 "time disparity of %ld minutes detected", dt / 60);
     1000            bb_error_msg("time disparity of %ld minutes detected", dt / 60);
    9381001            /* and we do not run any jobs in this case */
    9391002        } else if (dt > 0) {
     
    9411004            flag_starting_jobs(t1, t2);
    9421005            start_jobs();
     1006            sleep_time = 60;
    9431007            if (check_completions() > 0) {
    9441008                /* some jobs are still running */
    9451009                sleep_time = 10;
    946             } else {
    947                 sleep_time = 60;
    9481010            }
    9491011        }
Note: See TracChangeset for help on using the changeset viewer.