bug-mcron
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] base: Handle nonexistent user home directories.


From: Maxim Cournoyer
Subject: [PATCH v2] base: Handle nonexistent user home directories.
Date: Tue, 17 Aug 2021 19:23:59 -0400

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.
---
 src/mcron/base.scm | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

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)))
         (λ ()
-- 
2.32.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]