guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 01/05: service: 'exec-command' opens #:log-file in append mod


From: Ludovic Courtès
Subject: [shepherd] 01/05: service: 'exec-command' opens #:log-file in append mode.
Date: Fri, 2 Mar 2018 04:29:53 -0500 (EST)

civodul pushed a commit to branch master
in repository shepherd.

commit 7b4c88bac70f0bad82ef70fd5b682a49bc227478
Author: Ludovic Courtès <address@hidden>
Date:   Fri Mar 2 08:43:07 2018 +0100

    service: 'exec-command' opens #:log-file in append mode.
    
    Fixes <https://bugs.gnu.org/30649>.
    Reported by Andreas Enge <address@hidden>.
    
    * modules/shepherd/service.scm (exec-command): Open LOG-FILE with
    O_APPEND.  Avoid second 'open-fdes' call for stderr.
    * doc/shepherd.texi (Service De- and Constructors): Adjust accordingly.
---
 doc/shepherd.texi            | 12 +++++++-----
 modules/shepherd/service.scm | 10 +++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index 810336c..815091f 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -6,7 +6,7 @@
 
 @include version.texi
 @set OLD-YEARS 2002, 2003
address@hidden NEW-YEARS 2013, 2016
address@hidden NEW-YEARS 2013, 2016, 2018
 
 @copying
 Copyright @copyright{} @value{OLD-YEARS} Wolfgang J@"address@hidden
@@ -857,9 +857,9 @@ once that file has been created.  If @var{pid-file} does 
not show up in less
 than @var{pid-file-timeout} seconds, the service is considered as failing to
 start.
 
-When @var{log-file} is true, it must be the name of a file. The file will
-be removed if it exists and the services stdout and stderr will be
-redirected to it.
+When @var{log-file} is true, it names the file to which the service's
+standard output and standard error are redirected.  @var{log-file} is
+created if it does not exist, otherwise it is appended to.
 @end deffn
 
 @deffn {procedure} make-kill-destructor address@hidden
@@ -877,6 +877,7 @@ procedures.
 @deffn {procedure} exec-command @var{command} @
   [#:user #f] @
   [#:group #f] @
+  [#:log-file #f] @
   [#:directory (default-service-directory)] @
   [#:environment-variables (default-environment-variables)]
 @deffnx {procedure} fork+exec-command @var{command} @
@@ -886,7 +887,8 @@ procedures.
   [#:environment-variables (default-environment-variables)]
 Run @var{command} as the current process from @var{directory}, and with
 @var{environment-variables} (a list of strings like @code{"PATH=/bin"}.)
-File descriptors 1 and 2 are kept as is, whereas file descriptor 0
+File descriptors 1 and 2 are kept as is or redirected to @var{log-file}
+if it's true, whereas file descriptor 0
 (standard input) points to @file{/dev/null}; all other file descriptors
 are closed prior to yielding control to @var{command}.
 
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 83600e4..2224932 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -700,9 +700,9 @@ otherwise return the number that was read (a PID)."
                        (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, whereas file descriptor
-0 (standard input) points to /dev/null; all other file descriptors are
-closed prior to yielding control to COMMAND.
+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
@@ -734,8 +734,8 @@ false."
              ;; Redirect stout and stderr to use LOG-FILE.
              (catch-system-error (close-fdes 1))
              (catch-system-error (close-fdes 2))
-             (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 1)
-             (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY)) 2))
+             (dup2 (open-fdes log-file (logior O_CREAT O_WRONLY O_APPEND)) 1)
+             (dup2 1 2))
            (lambda (key . args)
              (format (current-error-port)
                      "failed to open log-file ~s:~%" log-file)



reply via email to

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