From: Harry Butterworth Subject: [PATCH] Fix bug #709 by daemonizing blktapctrl and closing stdin, stdout and stderr Date: Mon, 31 Jul 2006 16:15:42 +0100 Message-ID: <1154358942.7720.15.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-ORhXAxftSPCErkdhKgEM" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com, andrew.warfield@cl.cam.ac.uk, julian.chesterfield@cl.cam.ac.uk List-Id: xen-devel@lists.xenproject.org --=-ORhXAxftSPCErkdhKgEM Content-Type: text/plain Content-Transfer-Encoding: 7bit This patch fixes bug #709. I've tested it by running xm-test in both HVM and non-HVM mode. xm-test no longer hangs in the enforce-dom0-cpus test. I just copied the daemonize code from xenstored and added the lines to close the filedescriptors. This is a best effort without really 100% understanding exactly what blktapctrl is doing. Please review carefully before applying. Signed-off-by: Harry Butterworth --=-ORhXAxftSPCErkdhKgEM Content-Disposition: attachment; filename=daemonize-blktapctrl.patch Content-Type: text/x-patch; name=daemonize-blktapctrl.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit diff -r d2bf1a7cc131 -r 4dec6098b26f tools/blktap/drivers/blktapctrl.c --- a/tools/blktap/drivers/blktapctrl.c Sat Jul 29 13:05:59 2006 +++ b/tools/blktap/drivers/blktapctrl.c Mon Jul 31 15:07:56 2006 @@ -622,6 +622,39 @@ DPRINTF("Found driver: [%s]\n",dtypes[i]->name); } +/* Stevens. */ +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"); + if (pid != 0) + exit(0); + + /* Session leader so ^C doesn't whack us. */ + setsid(); + + /* Let session leader exit so child cannot regain CTTY */ + if ((pid = fork()) < 0) + DPRINTF("Failed to fork daemon\n"); + if (pid != 0) + exit(0); + +#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); + close(STDOUT_FILENO); + close(STDERR_FILENO); +} + int main(int argc, char *argv[]) { char *devname; @@ -633,6 +666,7 @@ __init_blkif(); openlog("BLKTAPCTRL", LOG_CONS|LOG_ODELAY, LOG_DAEMON); + daemonize(); print_drivers(); init_driver_list(); --=-ORhXAxftSPCErkdhKgEM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-ORhXAxftSPCErkdhKgEM--