GNU bug report logs - #30498
[PATCH shepherd] shepherd: If /dev/kmsg is writable, use it for logging.

Previous Next

Package: guix-patches;

Reported by: Danny Milosavljevic <dannym <at> scratchpost.org>

Date: Sat, 17 Feb 2018 12:21:02 UTC

Severity: normal

Tags: patch

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

Full log


Message #35 received at 30498 <at> debbugs.gnu.org (full text, mbox):

From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: ludo <at> gnu.org (Ludovic Courtès)
Cc: 30498 <at> debbugs.gnu.org
Subject: Re: [bug#30498] [WIP v2 shepherd] shepherd: If /dev/kmsg is
 writable, use it for logging.
Date: Sat, 3 Mar 2018 23:37:15 +0100
[Message part 1 (text/plain, inline)]
I think that just something like this is missing:

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 83600e4..481203d 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -728,20 +728,37 @@ false."
        ;; it for something unrelated, which can confuse some packages.
        (dup2 (open-fdes "/dev/null" O_RDONLY) 0)
 
-       (when log-file
-         (catch #t
-           (lambda ()
-             ;; 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))
-           (lambda (key . args)
-             (format (current-error-port)
-                     "failed to open log-file ~s:~%" log-file)
-             (print-exception (current-error-port) #f key args)
-             (primitive-exit 1))))
-
+       (if log-file
+           (catch #t
+             (lambda ()
+               ;; 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))
+             (lambda (key . args)
+               (format (current-error-port)
+                       "failed to open log-file ~s:~%" log-file)
+               (print-exception (current-error-port) #f key args)
+               (primitive-exit 1)))
+           (catch #t
+             (lambda ()
+               ;; Make sure the child has stdout/stderr that can be used.
+               ;; We sometimes set current-error-port to a softport.
+               ;; libguile would then autoconnect /dev/null -
+               ;; which we don't want.
+               ;; Also, cryptsetup interactively asks for a password,
+               ;; so we don't want /dev/kmsg either.
+               ;; In a user shepherd all this is not necessary -
+               ;; but then, port->fdes will not fail.
+               (when (not (false-if-exception (port->fdes (current-output-port))))
+                 (dup2 (open-fdes "/dev/console" (logior O_WRONLY)) 1))
+               (when (not (false-if-exception (port->fdes (current-error-port))))
+                 (dup2 (open-fdes "/dev/console" (logior O_WRONLY)) 2)))
+             (lambda (key . args)
+               (format (current-error-port) "failed to open stdout/stderr\n")
+               (print-exception (current-error-port) #f key args)
+               (primitive-exit 1))))
        (let loop ((i 3))
          (when (< i max-fd)
            ;; First try to close any ports associated with file descriptor I.

Patch starting from master attached for convenience.
[shepherd-klog.patch (text/x-patch, attachment)]
[Message part 3 (application/pgp-signature, inline)]

This bug report was last modified 7 years and 126 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.