WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] Fix bug #709 by daemonizing blktapctrl and closi

To: Harry Butterworth <harry@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] Fix bug #709 by daemonizing blktapctrl and closing stdin, stdout and stderr
From: Muli Ben-Yehuda <muli@xxxxxxxxxx>
Date: Mon, 31 Jul 2006 20:31:58 +0300
Cc: andrew.warfield@xxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxx, julian.chesterfield@xxxxxxxxxxxx
Delivery-date: Mon, 31 Jul 2006 10:32:24 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <1154358942.7720.15.camel@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1154358942.7720.15.camel@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.11
On Mon, Jul 31, 2006 at 04:15:42PM +0100, Harry Butterworth wrote:

> +static void daemonize(void)
> +{
> +     pid_t pid;
> +
> +     /* Separate from our parent via fork, so init inherits us. */
> +     if ((pid = fork()) < 0)
> +             DPRINTF("Failed to fork daemon\n");

It will be useful to know why fork() failed (i.e., print errno
directly or use sterror_r() and friends).

> +     if (pid != 0)
> +             exit(0);

If fork() failed, this will cause us to exit(0) which doesn't seem
particularly appropriate.

> +     /* Session leader so ^C doesn't whack us. */
> +     setsid();

In theory setsid() can fail.

> +     /* Let session leader exit so child cannot regain CTTY */
> +     if ((pid = fork()) < 0)
> +             DPRINTF("Failed to fork daemon\n");
> +     if (pid != 0)
> +             exit(0);

Same comment as above.
> +
> +#ifndef TESTING      /* Relative paths for socket names */
> +     /* Move off any mount points we might be in. */
> +     if (chdir("/") == -1)
> +             DPRINTF("Failed to chdir\n");
> +#endif
> +     /* Discard our parent's old-fashioned umask prejudices. */
> +     umask(0);
> +
> +        close(STDIN_FILENO);

Mixed tabs and spaces, ugh. Also, fileno(stdin) is nicer.

Cheers,
Muli

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>