From e491436967a912e6e7372f582b3bf5c9784b8209 Mon Sep 17 00:00:00 2001
'make-forkexec-constructor'.
* modules/shepherd/service.scm (exec-command): Add #:file-creation-mask
(fork+exec-command): Add #:file-creation-mask parameter and pass it to
(make-forkexec-constructor): Add #:file-creation-mask parameter and pass it
* doc/shepherd.texi (Service De- and Constructors): Adjust accordingly.
doc/shepherd.texi | 9 +++++++--
modules/shepherd/service.scm | 22 ++++++++++++++++------
2 files changed, 23 insertions(+), 8 deletions(-)
Toggle diff (114 lines)
diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index 3e61f5d..659eb82 100644
@@ -896,10 +896,12 @@ execution of the @var{command} was successful, @code{#t} if not.
[#:pid-file #f] [#:pid-file-timeout %pid-file-timeout] @
[#:directory (default-service-directory)] @
+ [#:file-creation-mask #f] @
[#:environment-variables (default-environment-variables)]
Return a procedure that forks a child process, closes all file
descriptors except the standard output and standard error descriptors, sets
-the current directory to @var{directory}, changes the environment to
+the current directory to @var{directory}, sets the umask to
+@var{file-creation-mask} unless it is @code{#f}, changes the environment to
@var{environment-variables} (using the @code{environ} procedure), sets the
current user to @var{user} and the current group to @var{group} unless they
are @code{#f}, and executes @var{command} (a list of strings.) The result of
@@ -935,13 +937,16 @@ procedures.
[#:directory (default-service-directory)] @
+ [#:file-creation-mask #f] @
[#:environment-variables (default-environment-variables)]
@deffnx {procedure} fork+exec-command @var{command} @
[#:directory (default-service-directory)] @
+ [#:file-creation-mask #f] @
[#:environment-variables (default-environment-variables)]
-Run @var{command} as the current process from @var{directory}, and with
+Run @var{command} as the current process from @var{directory}, with
+@var{file-creation-mask} if it's true, and with
@var{environment-variables} (a list of strings like @code{"PATH=/bin"}.)
File descriptors 1 and 2 are kept as is or redirected to @var{log-file}
if it's true, whereas file descriptor 0
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 9a4a5d9..d90b55b 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -771,12 +771,14 @@ daemon writing FILE is running in a separate PID namespace."
(directory (default-service-directory))
+ (file-creation-mask #f)
(environment-variables (default-environment-variables)))
- "Run COMMAND as the current process from DIRECTORY, and with
-ENVIRONMENT-VARIABLES (a list of strings like \"PATH=/bin\".) File
-descriptors 1 and 2 are kept as is or redirected to LOG-FILE if it's true,
-whereas file descriptor 0 (standard input) points to /dev/null; all other file
-descriptors are closed prior to yielding control to COMMAND.
+ "Run COMMAND as the current process from DIRECTORY, with FILE-CREATION-MASK
+if it's true, and with ENVIRONMENT-VARIABLES (a list of strings like
+\"PATH=/bin\"). File descriptors 1 and 2 are kept as is or redirected to
+LOG-FILE if it's true, whereas file descriptor 0 (standard input) points to
+/dev/null; all other file descriptors are closed prior to yielding control to
By default, COMMAND is run as the current user. If the USER keyword
argument is present and not false, change to USER immediately before
@@ -840,6 +842,9 @@ false."
(print-exception (current-error-port) #f key args)
+ (when file-creation-mask
+ (umask file-creation-mask))
;; As the last action, close file descriptors. Doing it last makes
;; "error in the finalization thread: Bad file descriptor" issues
@@ -871,6 +876,7 @@ false."
(directory (default-service-directory))
+ (file-creation-mask #f)
(default-environment-variables)))
"Spawn a process that executed COMMAND as per 'exec-command', and return
@@ -886,6 +892,7 @@ its PID."
+ #:file-creation-mask file-creation-mask
#:environment-variables environment-variables)
@@ -903,7 +910,8 @@ its PID."
"Return a procedure that forks a child process, closes all file
descriptors except the standard output and standard error descriptors, sets
-the current directory to @var{directory}, changes the environment to
+the current directory to @var{directory}, sets the umask to
+@var{file-creation-mask} unless it is @code{#f}, changes the environment to
@var{environment-variables} (using the @code{environ} procedure), sets the
current user to @var{user} and the current group to @var{group} unless they
are @code{#f}, and executes @var{command} (a list of strings.) The result of
@@ -918,6 +926,7 @@ start."
(directory (default-service-directory))
+ (file-creation-mask #f)
(environment-variables (default-environment-variables))
(pid-file-timeout %pid-file-timeout)
@@ -944,6 +953,7 @@ start."
+ #:file-creation-mask file-creation-mask