# HG changeset patch # User Anthony Liguori # Node ID e55633c669d11b48cf16d0ddaebbb836d7b3f5f6 # Parent 53cff3f88e45cb5230da39f86d84b6606da0cdbb Make sure to fork again after setsid() so that child cannot regain CTTY. Signed-off-by: Anthony Liguori diff -r 53cff3f88e45 -r e55633c669d1 tools/console/daemon/utils.c --- a/tools/console/daemon/utils.c Fri Dec 9 11:05:06 2005 +0000 +++ b/tools/console/daemon/utils.c Fri Dec 9 16:33:01 2005 -0500 @@ -90,6 +90,12 @@ setsid(); + if ((pid = fork()) > 0) { + exit(0); + } else if (pid == -1) { + err(errno, "fork() failed"); + } + /* redirect fd 0,1,2 to /dev/null */ if ((fd = open("/dev/null",O_RDWR)) == -1) { exit(1); diff -r 53cff3f88e45 -r e55633c669d1 tools/xenstore/xenstored_core.c --- a/tools/xenstore/xenstored_core.c Fri Dec 9 11:05:06 2005 +0000 +++ b/tools/xenstore/xenstored_core.c Fri Dec 9 16:33:01 2005 -0500 @@ -1491,6 +1491,13 @@ /* Session leader so ^C doesn't whack us. */ setsid(); + + /* Let session leader exit so child cannot regain CTTY */ + if ((pid = fork()) < 0) + barf_perror("Failed to fork daemon"); + if (pid != 0) + exit(0); + #ifndef TESTING /* Relative paths for socket names */ /* Move off any mount points we might be in. */ chdir("/");