X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=miscutils%2Fcrond.c;h=f6580a9d41543427a0facecb0c169421bbfc1a13;hb=9b70f197b4dd5be47c5d0d4479525efe012964ee;hp=6c54e1a8f66def75227fec533ddf57ee784ba934;hpb=72089cf6b4a77214ec4fd21d5ee5bf56958781cb;p=oweals%2Fbusybox.git diff --git a/miscutils/crond.c b/miscutils/crond.c index 6c54e1a8f..f6580a9d4 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -22,7 +22,7 @@ //config: 40 4 * * * /etc/cron/daily > /dev/null 2>&1 //config: //config:config FEATURE_CROND_D -//config: bool "Support option -d to redirect output to stderr" +//config: bool "Support -d (redirect output to stderr)" //config: depends on CROND //config: default y //config: help @@ -79,9 +79,9 @@ #include "common_bufsiz.h" #include -/* glibc frees previous setenv'ed value when we do next setenv() - * of the same variable. uclibc does not do this! */ -#if (defined(__GLIBC__) && !defined(__UCLIBC__)) /* || OTHER_SAFE_LIBC... */ +#if 0 +/* If libc tracks and reuses setenv()-allocated memory, ok to set this to 0 */ +/* Neither glibc nor uclibc do that! */ # define SETENV_LEAKS 0 #else # define SETENV_LEAKS 1 @@ -153,6 +153,7 @@ struct globals { const char *log_filename; const char *crontab_dir_name; /* = CRONTABS; */ CronFile *cron_files; + char *default_shell; #if SETENV_LEAKS char *env_var_user; char *env_var_home; @@ -700,7 +701,7 @@ fork_job(const char *user, int mailFd, CronLine *line, bool run_sendmail) goto err; } - shell = line->cl_shell ? line->cl_shell : DEFAULT_SHELL; + shell = line->cl_shell ? line->cl_shell : G.default_shell; prog = run_sendmail ? SENDMAIL : shell; set_env_vars(pas, shell); @@ -846,7 +847,7 @@ static pid_t start_one_job(const char *user, CronLine *line) } /* Prepare things before vfork */ - shell = line->cl_shell ? line->cl_shell : DEFAULT_SHELL; + shell = line->cl_shell ? line->cl_shell : G.default_shell; set_env_vars(pas, shell); /* Fork as the user in question and run program */ @@ -1020,13 +1021,17 @@ int crond_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - /* "-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") + opts = getopt32(argv, "^" + "l:L:fbSc:" IF_FEATURE_CROND_D("d:") + "\0" + /* "-b after -f is ignored", and so on for every pair a-b */ + "f-b:b-f:S-L:L-S" IF_FEATURE_CROND_D(":d-l") /* -l and -d have numeric param */ - ":l+" IF_FEATURE_CROND_D(":d+"); - opts = getopt32(argv, "l:L:fbSc:" IF_FEATURE_CROND_D("d:"), + ":l+" IF_FEATURE_CROND_D(":d+") + , &G.log_level, &G.log_filename, &G.crontab_dir_name - IF_FEATURE_CROND_D(,&G.log_level)); + IF_FEATURE_CROND_D(,&G.log_level) + ); /* both -d N and -l N set the same variable: G.log_level */ if (!(opts & OPT_f)) { @@ -1045,6 +1050,10 @@ int crond_main(int argc UNUSED_PARAM, char **argv) reopen_logfile_to_stderr(); xchdir(G.crontab_dir_name); + /* $SHELL, or current UID's shell, or DEFAULT_SHELL */ + /* Useful on Android where DEFAULT_SHELL /bin/sh may not exist */ + G.default_shell = xstrdup(get_shell_name()); + log8("crond (busybox "BB_VER") started, log level %d", G.log_level); rescan_crontab_dir(); write_pidfile(CONFIG_PID_FILE_PATH "/crond.pid");