From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keir Fraser Subject: Re: Re: [Xen-changelog] [xen-unstable] xenstored: Do not write to stderr if we are daemonised! Date: Wed, 01 Aug 2007 19:32:59 +0100 Message-ID: References: <20070801182027.GN31282@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20070801182027.GN31282@redhat.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "Daniel P. Berrange" , John Levon Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Good idea. Can't use _PATH_DEVNULL easily though, since it'll break Solaris again (no paths.h). Hardcoding /dev/null is not so bad -- the console daemon does this already. -- Keir On 1/8/07 19:20, "Daniel P. Berrange" wrote: > Yep, rather than closing FD's and setting the FILE* to NULL, the daeon > code should re-open /dev/null for stdin/out/err which is the traditional > approach for most UNIX daemons. > > if (dofork) { > int devnull; > devnull = open(_PATH_DEVNULL, O_RDWR); > close(STDIN_FILENO); > close(STDOUT_FILENO); > close(STDERR_FILENO); > dup2(devnull, STDIN_FILENO); > dup2(devnull, STDOUT_FILENO); > dup2(devnull, STDERR_FILENO); > close(devnull); > }