The changes are working fine for me so far. But after trying more things with crond, I found a few more issues I wanted to fix, all related to environment variables. Another patch is attached. - When setting a variable in the crontab file, the value would have a newline at the end of it. That's because getline() returns the line with a newline at the end, and the code didn't strip that newline out. - The HOME variable was being sourced from what HOME was set to when crond was run, rather than what the user's home is in the passwd file. I believe the intention was to set HOME to what it is in the passwd file, but allow the crontab to override it. - I decided to also set LOGNAME to the username of the crontab's owner, since the posix manpage for crontab mentions that as one of the variables that should be set.
diff --git a/toys/pending/crond.c b/toys/pending/crond.c index b31f32a1..cef27ea0 100644 --- a/toys/pending/crond.c +++ b/toys/pending/crond.c @@ -275,6 +275,8 @@ STOP_PARSING: return; default: return; } + // strip the newline from val, if any + strtok(val, "\n"); if (!strcmp(name, "MAILTO")) cfile->mailto = xstrdup(val); else { v = xzalloc(sizeof(VAR)); @@ -429,15 +431,13 @@ static void do_fork(CRONFILE *cfile, JOB *job, int fd, char *prog) char *file = "/bin/sh"; if (setenv("USER", pwd->pw_name, 1)) _exit(1); + if (setenv("LOGNAME", pwd->pw_name, 1)) _exit(1); + if (setenv("HOME", pwd->pw_dir, 1)) _exit(1); for (v = vstart; v;) { if (!strcmp("SHELL", v->name)) file = v->val; if (setenv(v->name, v->val, 1)) _exit(1); if ((v=v->next) == vstart) break; } - if (!getenv("HOME")) { - if (setenv("HOME", pwd->pw_dir, 1)) - _exit(1); - } xsetuser(pwd); if (chdir(pwd->pw_dir)) loginfo(9, "chdir(%s)", pwd->pw_dir); if (prog) file = prog;
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net