diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-04-30 14:47:28 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-04-30 14:47:28 +0200 |
| commit | 01a1a967c99d6ea75387c6ca8041e9061ea4a111 (patch) | |
| tree | 52dbb19bbf9236ca4f12c0005b444ffd5676c41c /miscutils | |
| parent | 07e5555a8f7469f6f45cacd7fc188816ae644f74 (diff) | |
| download | busybox-w32-01a1a967c99d6ea75387c6ca8041e9061ea4a111.tar.gz busybox-w32-01a1a967c99d6ea75387c6ca8041e9061ea4a111.tar.bz2 busybox-w32-01a1a967c99d6ea75387c6ca8041e9061ea4a111.zip | |
crond: tweak help text, make course less cryptic
function old new delta
packed_usage 29736 29740 +4
crond_main 1485 1486 +1
load_crontab 712 706 -6
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/Config.src | 34 | ||||
| -rw-r--r-- | miscutils/Kbuild.src | 1 | ||||
| -rw-r--r-- | miscutils/crond.c | 94 |
3 files changed, 68 insertions, 61 deletions
diff --git a/miscutils/Config.src b/miscutils/Config.src index 1da9800bd..1b2a3ae9a 100644 --- a/miscutils/Config.src +++ b/miscutils/Config.src | |||
| @@ -133,40 +133,6 @@ config CHRT | |||
| 133 | manipulate real-time attributes of a process. | 133 | manipulate real-time attributes of a process. |
| 134 | This requires sched_{g,s}etparam support in your libc. | 134 | This requires sched_{g,s}etparam support in your libc. |
| 135 | 135 | ||
| 136 | config CROND | ||
| 137 | bool "crond" | ||
| 138 | default y | ||
| 139 | select FEATURE_SYSLOG | ||
| 140 | help | ||
| 141 | Crond is a background daemon that parses individual crontab | ||
| 142 | files and executes commands on behalf of the users in question. | ||
| 143 | This is a port of dcron from slackware. It uses files of the | ||
| 144 | format /var/spool/cron/crontabs/<username> files, for example: | ||
| 145 | $ cat /var/spool/cron/crontabs/root | ||
| 146 | # Run daily cron jobs at 4:40 every day: | ||
| 147 | 40 4 * * * /etc/cron/daily > /dev/null 2>&1 | ||
| 148 | |||
| 149 | config FEATURE_CROND_D | ||
| 150 | bool "Support option -d to redirect output to stderr" | ||
| 151 | depends on CROND | ||
| 152 | default y | ||
| 153 | help | ||
| 154 | -d sets loglevel to 0 (most verbose) and directs all output to stderr. | ||
| 155 | |||
| 156 | config FEATURE_CROND_CALL_SENDMAIL | ||
| 157 | bool "Report command output via email (using sendmail)" | ||
| 158 | default y | ||
| 159 | depends on CROND | ||
| 160 | help | ||
| 161 | Command output will be sent to corresponding user via email. | ||
| 162 | |||
| 163 | config FEATURE_CROND_DIR | ||
| 164 | string "crond spool directory" | ||
| 165 | default "/var/spool/cron" | ||
| 166 | depends on CROND || CRONTAB | ||
| 167 | help | ||
| 168 | Location of crond spool. | ||
| 169 | |||
| 170 | config CRONTAB | 136 | config CRONTAB |
| 171 | bool "crontab" | 137 | bool "crontab" |
| 172 | default y | 138 | default y |
diff --git a/miscutils/Kbuild.src b/miscutils/Kbuild.src index 9e164f16e..8eaa82de9 100644 --- a/miscutils/Kbuild.src +++ b/miscutils/Kbuild.src | |||
| @@ -12,7 +12,6 @@ lib-$(CONFIG_BBCONFIG) += bbconfig.o | |||
| 12 | lib-$(CONFIG_BEEP) += beep.o | 12 | lib-$(CONFIG_BEEP) += beep.o |
| 13 | lib-$(CONFIG_CHAT) += chat.o | 13 | lib-$(CONFIG_CHAT) += chat.o |
| 14 | lib-$(CONFIG_CHRT) += chrt.o | 14 | lib-$(CONFIG_CHRT) += chrt.o |
| 15 | lib-$(CONFIG_CROND) += crond.o | ||
| 16 | lib-$(CONFIG_CRONTAB) += crontab.o | 15 | lib-$(CONFIG_CRONTAB) += crontab.o |
| 17 | lib-$(CONFIG_DC) += dc.o | 16 | lib-$(CONFIG_DC) += dc.o |
| 18 | lib-$(CONFIG_DEVFSD) += devfsd.o | 17 | lib-$(CONFIG_DEVFSD) += devfsd.o |
diff --git a/miscutils/crond.c b/miscutils/crond.c index 582dc991a..995ed9e0a 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* | 2 | /* |
| 3 | * crond -d[#] -c <crondir> -f -b | ||
| 4 | * | ||
| 5 | * run as root, but NOT setuid root | 3 | * run as root, but NOT setuid root |
| 6 | * | 4 | * |
| 7 | * Copyright 1994 Matthew Dillon (dillon@apollo.west.oic.com) | 5 | * Copyright 1994 Matthew Dillon (dillon@apollo.west.oic.com) |
| @@ -10,6 +8,43 @@ | |||
| 10 | * | 8 | * |
| 11 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 9 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
| 12 | */ | 10 | */ |
| 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 | ||
| 13 | 48 | ||
| 14 | //usage:#define crond_trivial_usage | 49 | //usage:#define crond_trivial_usage |
| 15 | //usage: "-fbS -l N " IF_FEATURE_CROND_D("-d N ") "-L LOGFILE -c DIR" | 50 | //usage: "-fbS -l N " IF_FEATURE_CROND_D("-d N ") "-L LOGFILE -c DIR" |
| @@ -17,12 +52,12 @@ | |||
| 17 | //usage: " -f Foreground" | 52 | //usage: " -f Foreground" |
| 18 | //usage: "\n -b Background (default)" | 53 | //usage: "\n -b Background (default)" |
| 19 | //usage: "\n -S Log to syslog (default)" | 54 | //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" |
| 21 | //usage: IF_FEATURE_CROND_D( | 56 | //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" |
| 23 | //usage: ) | 58 | //usage: ) |
| 24 | //usage: "\n -L Log to file" | 59 | //usage: "\n -L FILE Log to FILE" |
| 25 | //usage: "\n -c Working dir" | 60 | //usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs" |
| 26 | 61 | ||
| 27 | #include "libbb.h" | 62 | #include "libbb.h" |
| 28 | #include <syslog.h> | 63 | #include <syslog.h> |
| @@ -36,7 +71,7 @@ | |||
| 36 | #endif | 71 | #endif |
| 37 | 72 | ||
| 38 | 73 | ||
| 39 | #define TMPDIR CONFIG_FEATURE_CROND_DIR | 74 | #define CRON_DIR CONFIG_FEATURE_CROND_DIR |
| 40 | #define CRONTABS CONFIG_FEATURE_CROND_DIR "/crontabs" | 75 | #define CRONTABS CONFIG_FEATURE_CROND_DIR "/crontabs" |
| 41 | #ifndef SENDMAIL | 76 | #ifndef SENDMAIL |
| 42 | # define SENDMAIL "sendmail" | 77 | # define SENDMAIL "sendmail" |
| @@ -158,12 +193,10 @@ static void crondlog(const char *ctl, ...) | |||
| 158 | 193 | ||
| 159 | static const char DowAry[] ALIGN1 = | 194 | static const char DowAry[] ALIGN1 = |
| 160 | "sun""mon""tue""wed""thu""fri""sat" | 195 | "sun""mon""tue""wed""thu""fri""sat" |
| 161 | /* "Sun""Mon""Tue""Wed""Thu""Fri""Sat" */ | ||
| 162 | ; | 196 | ; |
| 163 | 197 | ||
| 164 | static const char MonAry[] ALIGN1 = | 198 | static const char MonAry[] ALIGN1 = |
| 165 | "jan""feb""mar""apr""may""jun""jul""aug""sep""oct""nov""dec" | 199 | "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" */ | ||
| 167 | ; | 200 | ; |
| 168 | 201 | ||
| 169 | static void ParseField(char *user, char *ary, int modvalue, int off, | 202 | static void ParseField(char *user, char *ary, int modvalue, int off, |
| @@ -393,8 +426,11 @@ static void load_crontab(const char *fileName) | |||
| 393 | while (1) { | 426 | while (1) { |
| 394 | CronLine *line; | 427 | CronLine *line; |
| 395 | 428 | ||
| 396 | if (!--maxLines) | 429 | if (!--maxLines) { |
| 430 | crondlog(WARN9 "user %s: too many lines", fileName); | ||
| 397 | break; | 431 | break; |
| 432 | } | ||
| 433 | |||
| 398 | n = config_read(parser, tokens, 6, 1, "# \t", PARSE_NORMAL | PARSE_KEEP_COPY); | 434 | n = config_read(parser, tokens, 6, 1, "# \t", PARSE_NORMAL | PARSE_KEEP_COPY); |
| 399 | if (!n) | 435 | if (!n) |
| 400 | break; | 436 | break; |
| @@ -410,6 +446,18 @@ static void load_crontab(const char *fileName) | |||
| 410 | #endif /* otherwise just ignore such lines */ | 446 | #endif /* otherwise just ignore such lines */ |
| 411 | continue; | 447 | continue; |
| 412 | } | 448 | } |
| 449 | //TODO: handle SHELL=, HOME= too? "man crontab" says: | ||
| 450 | //name = value | ||
| 451 | // | ||
| 452 | //where the spaces around the equal-sign (=) are optional, and any subsequent | ||
| 453 | //non-leading spaces in value will be part of the value assigned to name. | ||
| 454 | //The value string may be placed in quotes (single or double, but matching) | ||
| 455 | //to preserve leading or trailing blanks. | ||
| 456 | // | ||
| 457 | //Several environment variables are set up automatically by the cron(8) daemon. | ||
| 458 | //SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd | ||
| 459 | //line of the crontab's owner. HOME and SHELL may be overridden by settings | ||
| 460 | //in the crontab; LOGNAME may not. | ||
| 413 | /* check if a minimum of tokens is specified */ | 461 | /* check if a minimum of tokens is specified */ |
| 414 | if (n < 6) | 462 | if (n < 6) |
| 415 | continue; | 463 | continue; |
| @@ -441,10 +489,6 @@ static void load_crontab(const char *fileName) | |||
| 441 | 489 | ||
| 442 | file->cf_next = G.cron_files; | 490 | file->cf_next = G.cron_files; |
| 443 | G.cron_files = file; | 491 | G.cron_files = file; |
| 444 | |||
| 445 | if (maxLines == 0) { | ||
| 446 | crondlog(WARN9 "user %s: too many lines", fileName); | ||
| 447 | } | ||
| 448 | } | 492 | } |
| 449 | config_close(parser); | 493 | config_close(parser); |
| 450 | } | 494 | } |
| @@ -540,8 +584,8 @@ static void change_user(struct passwd *pas) | |||
| 540 | change_identity(pas); /* - initgroups, setgid, setuid */ | 584 | change_identity(pas); /* - initgroups, setgid, setuid */ |
| 541 | if (chdir(pas->pw_dir) < 0) { | 585 | if (chdir(pas->pw_dir) < 0) { |
| 542 | crondlog(WARN9 "chdir(%s)", pas->pw_dir); | 586 | crondlog(WARN9 "chdir(%s)", pas->pw_dir); |
| 543 | if (chdir(TMPDIR) < 0) { | 587 | if (chdir(CRON_DIR) < 0) { |
| 544 | crondlog(DIE9 "chdir(%s)", TMPDIR); /* exits */ | 588 | crondlog(DIE9 "chdir(%s)", CRON_DIR); /* exits */ |
| 545 | } | 589 | } |
| 546 | } | 590 | } |
| 547 | } | 591 | } |
| @@ -568,7 +612,7 @@ fork_job(const char *user, int mailFd, | |||
| 568 | pid = vfork(); | 612 | pid = vfork(); |
| 569 | if (pid == 0) { | 613 | if (pid == 0) { |
| 570 | /* CHILD */ | 614 | /* CHILD */ |
| 571 | /* initgroups, setgid, setuid, and chdir to home or TMPDIR */ | 615 | /* initgroups, setgid, setuid, and chdir to home or CRON_DIR */ |
| 572 | change_user(pas); | 616 | change_user(pas); |
| 573 | if (DebugOpt) { | 617 | if (DebugOpt) { |
| 574 | crondlog(LVL5 "child running %s", prog); | 618 | crondlog(LVL5 "child running %s", prog); |
| @@ -588,7 +632,6 @@ fork_job(const char *user, int mailFd, | |||
| 588 | } | 632 | } |
| 589 | 633 | ||
| 590 | if (pid < 0) { | 634 | if (pid < 0) { |
| 591 | /* FORK FAILED */ | ||
| 592 | crondlog(ERR20 "can't vfork"); | 635 | crondlog(ERR20 "can't vfork"); |
| 593 | err: | 636 | err: |
| 594 | pid = 0; | 637 | pid = 0; |
| @@ -614,7 +657,7 @@ static void start_one_job(const char *user, CronLine *line) | |||
| 614 | 657 | ||
| 615 | if (line->cl_mailto) { | 658 | if (line->cl_mailto) { |
| 616 | /* Open mail file (owner is root so nobody can screw with it) */ | 659 | /* Open mail file (owner is root so nobody can screw with it) */ |
| 617 | snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", TMPDIR, user, getpid()); | 660 | snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", CRON_DIR, user, getpid()); |
| 618 | mailFd = open(mailFile, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL | O_APPEND, 0600); | 661 | mailFd = open(mailFile, O_CREAT | O_TRUNC | O_WRONLY | O_EXCL | O_APPEND, 0600); |
| 619 | 662 | ||
| 620 | if (mailFd >= 0) { | 663 | if (mailFd >= 0) { |
| @@ -633,7 +676,7 @@ static void start_one_job(const char *user, CronLine *line) | |||
| 633 | unlink(mailFile); | 676 | unlink(mailFile); |
| 634 | } else { | 677 | } else { |
| 635 | /* rename mail-file based on pid of process */ | 678 | /* rename mail-file based on pid of process */ |
| 636 | char *mailFile2 = xasprintf("%s/cron.%s.%d", TMPDIR, user, (int)line->cl_pid); | 679 | char *mailFile2 = xasprintf("%s/cron.%s.%d", CRON_DIR, user, (int)line->cl_pid); |
| 637 | rename(mailFile, mailFile2); // TODO: xrename? | 680 | rename(mailFile, mailFile2); // TODO: xrename? |
| 638 | free(mailFile2); | 681 | free(mailFile2); |
| 639 | } | 682 | } |
| @@ -665,7 +708,7 @@ static void process_finished_job(const char *user, CronLine *line) | |||
| 665 | * End of primary job - check for mail file. | 708 | * End of primary job - check for mail file. |
| 666 | * If size has changed and the file is still valid, we send it. | 709 | * If size has changed and the file is still valid, we send it. |
| 667 | */ | 710 | */ |
| 668 | snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", TMPDIR, user, (int)pid); | 711 | snprintf(mailFile, sizeof(mailFile), "%s/cron.%s.%d", CRON_DIR, user, (int)pid); |
| 669 | mailFd = open(mailFile, O_RDONLY); | 712 | mailFd = open(mailFile, O_RDONLY); |
| 670 | unlink(mailFile); | 713 | unlink(mailFile); |
| 671 | if (mailFd < 0) { | 714 | if (mailFd < 0) { |
| @@ -706,7 +749,7 @@ static void start_one_job(const char *user, CronLine *line) | |||
| 706 | pid = vfork(); | 749 | pid = vfork(); |
| 707 | if (pid == 0) { | 750 | if (pid == 0) { |
| 708 | /* CHILD */ | 751 | /* CHILD */ |
| 709 | /* initgroups, setgid, setuid, and chdir to home or TMPDIR */ | 752 | /* initgroups, setgid, setuid, and chdir to home or CRON_DIR */ |
| 710 | change_user(pas); | 753 | change_user(pas); |
| 711 | if (DebugOpt) { | 754 | if (DebugOpt) { |
| 712 | crondlog(LVL5 "child running %s", DEFAULT_SHELL); | 755 | crondlog(LVL5 "child running %s", DEFAULT_SHELL); |
| @@ -853,8 +896,8 @@ int crond_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
| 853 | int crond_main(int argc UNUSED_PARAM, char **argv) | 896 | int crond_main(int argc UNUSED_PARAM, char **argv) |
| 854 | { | 897 | { |
| 855 | time_t t2; | 898 | time_t t2; |
| 856 | int rescan; | 899 | unsigned rescan; |
| 857 | int sleep_time; | 900 | unsigned sleep_time; |
| 858 | unsigned opts; | 901 | unsigned opts; |
| 859 | 902 | ||
| 860 | INIT_G(); | 903 | INIT_G(); |
| @@ -940,11 +983,10 @@ int crond_main(int argc UNUSED_PARAM, char **argv) | |||
| 940 | /* Usual case: time advances forward, as expected */ | 983 | /* Usual case: time advances forward, as expected */ |
| 941 | flag_starting_jobs(t1, t2); | 984 | flag_starting_jobs(t1, t2); |
| 942 | start_jobs(); | 985 | start_jobs(); |
| 986 | sleep_time = 60; | ||
| 943 | if (check_completions() > 0) { | 987 | if (check_completions() > 0) { |
| 944 | /* some jobs are still running */ | 988 | /* some jobs are still running */ |
| 945 | sleep_time = 10; | 989 | sleep_time = 10; |
| 946 | } else { | ||
| 947 | sleep_time = 60; | ||
| 948 | } | 990 | } |
| 949 | } | 991 | } |
| 950 | /* else: time jumped back, do not run any jobs */ | 992 | /* else: time jumped back, do not run any jobs */ |
