guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 04/05: service: Gracefully handle non-existing log directorie


From: Ludovic Courtès
Subject: [shepherd] 04/05: service: Gracefully handle non-existing log directories.
Date: Mon, 29 Aug 2022 11:18:09 -0400 (EDT)

civodul pushed a commit to branch master
in repository shepherd.

commit b0d3f625543bcb32e94167c27cba153f9fc03acd
Author: Liliana Marie Prikler <liliana.prikler@gmail.com>
AuthorDate: Sat Apr 23 15:11:50 2022 +0200

    service: Gracefully handle non-existing log directories.
    
    * gnu/packages/services.scm (%service-file-logger): New variable,
    implementing...
    (service-file-logger): ... the old behaviour of this variable.  Catch system
    errors from %service-file-logger and handle them.
    
    Signed-off-by: Ludovic Courtès <ludo@gnu.org>
---
 modules/shepherd/service.scm | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 6df550c..fcab6c4 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -876,9 +876,9 @@ daemon writing FILE is running in a separate PID namespace."
               (try-again)
               (apply throw args)))))))
 
-(define (service-file-logger file input)
-  "Return a thunk meant to run as a fiber that reads from INPUT and logs it to
-FILE."
+(define (%service-file-logger file input)
+  "Like 'service-file-logger', but doesn't handle the case in which FILE does
+not exist."
   (let* ((fd     (open-fdes file (logior O_CREAT O_WRONLY O_APPEND) #o640))
          (output (fdopen fd "al")))
     (set-port-encoding! output "UTF-8")
@@ -897,6 +897,19 @@ FILE."
                  (format output "~a~a~%" prefix line)
                  (loop))))))))))
 
+(define (service-file-logger file input)
+  "Return a thunk meant to run as a fiber that reads from INPUT and logs it to
+FILE."
+  (catch 'system-error
+    (lambda ()
+      (%service-file-logger file input))
+    (lambda args
+      (if (= ENOENT (system-error-errno args))
+          (begin
+            (mkdir-p (dirname file))
+            (%service-file-logger file input))
+          (apply throw args)))))
+
 (define (service-builtin-logger command input)
   "Return a thunk meant to run as a fiber that reads from INPUT and logs to
 'log-output-port'."



reply via email to

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