]> granicus.if.org Git - cronie/commitdiff
The sysadmin may want to arrange for the PATH to be correct in the
authorTom Jones <tom@oxix.org>
Thu, 11 Oct 2012 12:00:56 +0000 (14:00 +0200)
committerMarcela Mašláňová <mmaslano@redhat.com>
Thu, 11 Oct 2012 12:00:56 +0000 (14:00 +0200)
environment from which cron is launched.  This new option tells
cron to not overwrite this path for itself or for the child cron
jobs.

Signed-off-by: Marcela Mašláňová <mmaslano@redhat.com>
man/cron.8
src/cron.c
src/entry.c
src/globals.h

index d378927372a6ed9ff4c929f6f661d46a8d641e34..ab21f2a540ca6af954567a6033a39af86e5ffe1e 100644 (file)
@@ -167,6 +167,9 @@ installed or if mail is disabled.
 .TP
 .B "\-x"
 This option allows you to set debug flags. 
+.TP
+.B "\-P"
+Don't set PATH.  PATH is instead inherited from the environment.
 .SH SIGNALS
 When the \s-2SIGHUP\s+2 is received, the 
 .I Cron 
index ee1d2a8f51ca872cfbc2534162101ab96a6abfab..a5328508e93776d760a11126a6c4b5e983b0565d 100644 (file)
@@ -192,6 +192,7 @@ int main(int argc, char *argv[]) {
 
        SyslogOutput = 0;
        NoFork = 0;
+       ChangePath = 1;
        parse_args(argc, argv);
 
        bzero((char *) &sact, sizeof sact);
@@ -212,9 +213,12 @@ int main(int argc, char *argv[]) {
        set_cron_uid();
        check_spool_dir();
 
-       if (putenv("PATH=" _PATH_DEFPATH) < 0) {
-               log_it("CRON", pid, "DEATH", "can't putenv PATH", errno);
-               exit(1);
+       if (ChangePath) {
+               if (putenv("PATH=" _PATH_DEFPATH) < 0) {
+                       log_it("CRON", pid, "DEATH", "can't putenv PATH",
+                               errno);
+                       exit(1);
+               }
        }
 
        /* Get the default locale character set for the mail 
@@ -650,7 +654,7 @@ static void sigchld_reaper(void) {
 static void parse_args(int argc, char *argv[]) {
        int argch;
 
-       while (-1 != (argch = getopt(argc, argv, "hnpsix:m:c"))) {
+       while (-1 != (argch = getopt(argc, argv, "hnpsiPx:m:c"))) {
                switch (argch) {
                        case 'x':
                                if (!set_debug_flags(optarg))
@@ -668,6 +672,9 @@ static void parse_args(int argc, char *argv[]) {
                        case 'i':
                                DisableInotify = 1;
                                break;
+                       case 'P':
+                               ChangePath = 0;
+                               break;
                        case 'm':
                                strncpy(MailCmd, optarg, MAX_COMMAND);
                                break;
index 8eff42adbcb167b12c6786976467d20f2b7c9289..f09427cd9dd011b09e878ea5ce3c5fa1fe7d90e5 100644 (file)
@@ -314,7 +314,7 @@ entry *load_entry(FILE * file, void (*error_func) (), struct passwd *pw,
        }
 #ifndef LOGIN_CAP
        /* If login.conf is in used we will get the default PATH later. */
-       if (!env_get("PATH", e->envp)) {
+       if (ChangePath && !env_get("PATH", e->envp)) {
                if (glue_strings(envstr, sizeof envstr, "PATH", _PATH_DEFPATH, '=')) {
                        if ((tenvp = env_set(e->envp, envstr)) == NULL) {
                                ecode = e_memory;
index c7a811d16519e18f0476654ad43e9ca06622819b..8abdb73f422b95ac12f5425dc41c22a1f7bdef62 100644 (file)
@@ -73,6 +73,7 @@ XTRN int        PermitAnyCrontab;
 XTRN char       MailCmd[MAX_COMMAND];
 XTRN char       cron_default_mail_charset[MAX_ENVSTR];
 XTRN int        EnableClustering;
+XTRN int       ChangePath;
  
 #if DEBUGGING
 XTRN int       DebugFlags INIT(0);