All of lore.kernel.org
 help / color / mirror / Atom feed
From: Muli Ben-Yehuda <muli@il.ibm.com>
To: Harry Butterworth <harry@hebutterworth.freeserve.co.uk>
Cc: andrew.warfield@cl.cam.ac.uk, xen-devel@lists.xensource.com,
	julian.chesterfield@cl.cam.ac.uk
Subject: Re: [PATCH] Fix bug #709 by daemonizing blktapctrl and closing stdin, stdout and stderr
Date: Mon, 31 Jul 2006 20:31:58 +0300	[thread overview]
Message-ID: <20060731173158.GA5587@rhun.ibm.com> (raw)
In-Reply-To: <1154358942.7720.15.camel@localhost.localdomain>

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

  reply	other threads:[~2006-07-31 17:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-31 15:15 [PATCH] Fix bug #709 by daemonizing blktapctrl and closing stdin, stdout and stderr Harry Butterworth
2006-07-31 17:31 ` Muli Ben-Yehuda [this message]
2006-08-01 10:01   ` Harry Butterworth
2006-08-01 10:06     ` Muli Ben-Yehuda
2006-08-01 10:13       ` Keir Fraser
2006-08-01 10:18         ` Muli Ben-Yehuda
2006-08-01 10:20           ` Harry Butterworth
2006-08-01 10:27             ` Muli Ben-Yehuda
2006-08-01 10:33               ` Keir Fraser
2006-08-01 11:57                 ` Jimi Xenidis
2006-08-01 10:22           ` Keir Fraser
2006-08-01 10:19         ` Harry Butterworth
2006-08-01 10:24           ` Keir Fraser

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060731173158.GA5587@rhun.ibm.com \
    --to=muli@il.ibm.com \
    --cc=andrew.warfield@cl.cam.ac.uk \
    --cc=harry@hebutterworth.freeserve.co.uk \
    --cc=julian.chesterfield@cl.cam.ac.uk \
    --cc=xen-devel@lists.xensource.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.