[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 02/02: service: Add #:file-creation-mask to 'make-forkexec-co
From: |
Ludovic Courtès |
Subject: |
[shepherd] 02/02: service: Add #:file-creation-mask to 'make-forkexec-constructor'. |
Date: |
Sun, 19 Apr 2020 10:26:45 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit 4b5f958035426e1a4fce1ada19be68b62d7b75df
Author: Diego Nicola Barbato <address@hidden>
AuthorDate: Tue Apr 7 13:38:47 2020 +0200
service: Add #:file-creation-mask to 'make-forkexec-constructor'.
* modules/shepherd/service.scm (exec-command): Add #:file-creation-mask
parameter and honor it.
(fork+exec-command): Add #:file-creation-mask parameter and pass it to
exec-command.
(make-forkexec-constructor): Add #:file-creation-mask parameter and pass
it
to fork+exec-command.
* doc/shepherd.texi (Service De- and Constructors): Adjust accordingly.
Signed-off-by: Ludovic Courtès <address@hidden>
---
doc/shepherd.texi | 9 +++++++--
modules/shepherd/service.scm | 22 ++++++++++++++++------
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index 9de9586..ed484c8 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -896,10 +896,12 @@ execution of the @var{command} was successful, @code{#t}
if not.
[#:pid-file #f] [#:pid-file-timeout (default-pid-file-timeout)] @
[#:log-file #f] @
[#: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
@@ -937,13 +939,16 @@ procedures.
[#:group #f] @
[#:log-file #f] @
[#:directory (default-service-directory)] @
+ [#:file-creation-mask #f] @
[#:environment-variables (default-environment-variables)]
@deffnx {procedure} fork+exec-command @var{command} @
[#:user #f] @
[#:group #f] @
[#: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 f284249..86bcbe5 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -777,12 +777,14 @@ daemon writing FILE is running in a separate PID
namespace."
(group #f)
(log-file #f)
(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
+COMMAND.
By default, COMMAND is run as the current user. If the USER keyword
argument is present and not false, change to USER immediately before
@@ -846,6 +848,9 @@ false."
(print-exception (current-error-port) #f key args)
(primitive-exit 1))))
+ (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
;; unlikely on 2.2.
@@ -877,6 +882,7 @@ false."
(group #f)
(log-file #f)
(directory (default-service-directory))
+ (file-creation-mask #f)
(environment-variables
(default-environment-variables)))
"Spawn a process that executed COMMAND as per 'exec-command', and return
@@ -892,6 +898,7 @@ its PID."
#:group group
#:log-file log-file
#:directory directory
+ #:file-creation-mask file-creation-mask
#:environment-variables environment-variables)
pid)))
@@ -902,13 +909,15 @@ its PID."
(directory (default-service-directory))
(environment-variables
(default-environment-variables))
+ (file-creation-mask #f)
(pid-file #f)
(pid-file-timeout
(default-pid-file-timeout))
(log-file #f))
"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
@@ -936,6 +945,7 @@ start."
#:group group
#:log-file log-file
#:directory directory
+ #:file-creation-mask file-creation-mask
#:environment-variables
environment-variables)))
(if pid-file