guix-devel
[Top][All Lists]
Advanced

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

Re: Shepherd redirect stdout/stderr to syslog


From: David Craven
Subject: Re: Shepherd redirect stdout/stderr to syslog
Date: Mon, 5 Sep 2016 15:44:40 +0200

> Is redirecting stdout/stderr to syslog something that
> make-forkexec-constructor could/should do?

I looked into what would be involved. I included a diff that I didn't
test and don't expect to work.

The reason why I don't expect this to work is that running echo
"hello" > /dev/log errors. stracing logger "hello" shows that it makes
use of the socket and sendmsg syscalls instead of the usual open and
write syscalls. I don't understand why though, since what's the point
of everything being a file if they don't share the same interface?

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 49f6e8b..69c1cc2 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -712,12 +712,18 @@ false."

      ;; Close all the file descriptors except stdout and stderr.
      (let ((max-fd (max-file-descriptors)))
+       ;; Redirect stdin to use /dev/null
        (catch-system-error (close-fdes 0))
-
        ;; Make sure file descriptor zero is used, so we don't end up reusing
        ;; it for something unrelated, which can confuse some packages.
        (dup2 (open-fdes "/dev/null" O_RDONLY) 0)

+       ;; Redirect stout and stderr to use /dev/log
+       (catch-system-error (close-fdes 1))
+       (catch-system-error (close-fdes 2))
+       (dup2 (open-fdes "/dev/log" O_WRONLY) 1)
+       (dup2 (open-fdes "/dev/log" O_WRONLY) 2)
+
        (let loop ((i 3))
          (when (< i max-fd)
            (catch-system-error (close-fdes i))



reply via email to

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