direct-io.hg

changeset 8335:c8378d3c3af8

Make sure to fork again after setsid() so that child cannot regain CTTY.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
author Anthony Liguori <anthony@codemonkey.ws>
date Mon Dec 12 15:11:13 2005 +0000 (2005-12-12)
parents b4dfb49332d2
children d01b3b50ea64
files tools/console/daemon/utils.c tools/xenstore/xenstored_core.c
line diff
     1.1 --- a/tools/console/daemon/utils.c	Mon Dec 12 11:15:29 2005 +0000
     1.2 +++ b/tools/console/daemon/utils.c	Mon Dec 12 15:11:13 2005 +0000
     1.3 @@ -90,6 +90,12 @@ void daemonize(const char *pidfile)
     1.4  
     1.5  	setsid();
     1.6  
     1.7 +	if ((pid = fork()) > 0) {
     1.8 +		exit(0);
     1.9 +	} else if (pid == -1) {
    1.10 +		err(errno, "fork() failed");
    1.11 +	}
    1.12 +
    1.13  	/* redirect fd 0,1,2 to /dev/null */
    1.14  	if ((fd = open("/dev/null",O_RDWR)) == -1) {
    1.15  		exit(1);
     2.1 --- a/tools/xenstore/xenstored_core.c	Mon Dec 12 11:15:29 2005 +0000
     2.2 +++ b/tools/xenstore/xenstored_core.c	Mon Dec 12 15:11:13 2005 +0000
     2.3 @@ -1491,6 +1491,13 @@ static void daemonize(void)
     2.4  
     2.5  	/* Session leader so ^C doesn't whack us. */
     2.6  	setsid();
     2.7 +
     2.8 +	/* Let session leader exit so child cannot regain CTTY */
     2.9 +	if ((pid = fork()) < 0)
    2.10 +		barf_perror("Failed to fork daemon");
    2.11 +	if (pid != 0)
    2.12 +		exit(0);
    2.13 +
    2.14  #ifndef TESTING	/* Relative paths for socket names */
    2.15  	/* Move off any mount points we might be in. */
    2.16  	chdir("/");