All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix bug #709 by daemonizing blktapctrl and closing stdin, stdout and stderr
@ 2006-07-31 15:15 Harry Butterworth
  2006-07-31 17:31 ` Muli Ben-Yehuda
  0 siblings, 1 reply; 13+ messages in thread
From: Harry Butterworth @ 2006-07-31 15:15 UTC (permalink / raw)
  To: xen-devel, andrew.warfield, julian.chesterfield

[-- Attachment #1: Type: text/plain, Size: 436 bytes --]

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 <butterwo@uk.ibm.com>

[-- Attachment #2: daemonize-blktapctrl.patch --]
[-- Type: text/x-patch, Size: 1270 bytes --]

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();

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-08-01 11:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.