[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] [BLKTAP] Properly daemonise the blktap control daemon. Fixes bug #709.



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID 6d44ab88d941f335b639f015a4976b07515b9e9c
# Parent  637fa5352fad1490153638e34c4ff0705fb9b8e8
[BLKTAP] Properly daemonise the blktap control daemon. Fixes bug #709.
Signed-off-by: Harry Butterworth <butterwo@xxxxxxxxxx>
---
 tools/blktap/drivers/blktapctrl.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+)

diff -r 637fa5352fad -r 6d44ab88d941 tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c Mon Jul 31 17:49:36 2006 +0100
+++ b/tools/blktap/drivers/blktapctrl.c Mon Jul 31 18:07:25 2006 +0100
@@ -622,6 +622,38 @@ static void print_drivers(void)
                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);
+
+       /* Move off any mount points we might be in. */
+       if (chdir("/") == -1)
+               DPRINTF("Failed to chdir\n");
+
+       /* 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 +665,7 @@ int main(int argc, char *argv[])
 
        __init_blkif();
        openlog("BLKTAPCTRL", LOG_CONS|LOG_ODELAY, LOG_DAEMON);
+       daemonize();
 
        print_drivers();
        init_driver_list();

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.