From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Craven Subject: Re: Shepherd redirect stdout/stderr to syslog Date: Mon, 5 Sep 2016 15:44:40 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bguCh-0001IC-MY for guix-devel@gnu.org; Mon, 05 Sep 2016 09:44:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bguCd-0000sE-HM for guix-devel@gnu.org; Mon, 05 Sep 2016 09:44:50 -0400 Received: from mail-yb0-x230.google.com ([2607:f8b0:4002:c09::230]:36756) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bguCc-0000rm-An for guix-devel@gnu.org; Mon, 05 Sep 2016 09:44:47 -0400 Received: by mail-yb0-x230.google.com with SMTP id 125so60035245ybe.3 for ; Mon, 05 Sep 2016 06:44:45 -0700 (PDT) In-Reply-To: List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel > 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))