diff options
author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2021-08-09 10:37:07 -0400 |
---|---|---|
committer | Dale Mellor <mcron-lsfnyl@rdmp.org> | 2021-12-30 04:00:11 +0000 |
commit | 8b27157f579611666019c3ed517d3f6bc265f394 (patch) | |
tree | 2f0fd747ca260620604cf013c81218714df71727 /src/mcron | |
parent | 271b1f21fa32493eb24dd207b45c84d4dc97a16e (diff) | |
download | mcron-8b27157f579611666019c3ed517d3f6bc265f394.tar.gz mcron-8b27157f579611666019c3ed517d3f6bc265f394.tar.bz2 mcron-8b27157f579611666019c3ed517d3f6bc265f394.zip |
base: Handle nonexistent user home directories.
This is useful for running jobs as the "nobody" user, for example.
* src/mcron/base.scm (run-job): Catch the ENOENT (2, "No such file or
directory") error when attempting to change directory to the user home
directory.
Diffstat (limited to 'src/mcron')
-rw-r--r-- | src/mcron/base.scm | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/mcron/base.scm b/src/mcron/base.scm index f7b727d..037a9b7 100644 --- a/src/mcron/base.scm +++ b/src/mcron/base.scm @@ -182,7 +182,17 @@ next value." (λ () (setgid (passwd:gid (job:user job))) (setuid (passwd:uid (job:user job))) - (chdir (passwd:dir (job:user job))) + ;; Handle the case where the home directory points to a nonexistent + ;; location, as can be the case when running the job as the "nobody" + ;; user. + (catch 'system-error + (lambda () + (chdir (passwd:dir (job:user job)))) + (lambda args + (let ((errno (system-error-errno args))) + (cond + ((= ENOENT errno) (chdir "/")) + (else (throw 'system-error args)))))) (modify-environment (job:environment job) (job:user job)) ((job:action job))) (λ () |