From: David Craven <david@craven.ch>
To: guix-devel <guix-devel@gnu.org>
Subject: Re: Shepherd redirect stdout/stderr to syslog
Date: Mon, 5 Sep 2016 15:44:40 +0200 [thread overview]
Message-ID: <CAL1_immoRNBh9OL2eN5sLN9c_w8NfiK5NTdAkG6VUgtTmspVSw@mail.gmail.com> (raw)
In-Reply-To: <CAL1_imkKFyXEYADntaGt-z2f=V9noYVLnPkBT8A95EbYHOwBmQ@mail.gmail.com>
> 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))
next prev parent reply other threads:[~2016-09-05 13:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-04 11:26 Shepherd redirect stdout/stderr to syslog David Craven
2016-09-05 13:44 ` David Craven [this message]
2016-09-05 21:14 ` Ludovic Courtès
2016-09-06 12:35 ` [PATCH] service: Honor #:log-file in make-forkexec-constructor David Craven
2016-09-06 12:36 ` David Craven
2016-09-06 19:13 ` Danny Milosavljevic
2016-09-06 20:02 ` David Craven
2016-09-11 13:34 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAL1_immoRNBh9OL2eN5sLN9c_w8NfiK5NTdAkG6VUgtTmspVSw@mail.gmail.com \
--to=david@craven.ch \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).