debuggers.hg
changeset 10914:6d44ab88d941
[BLKTAP] Properly daemonise the blktap control daemon. Fixes bug #709.
Signed-off-by: Harry Butterworth <butterwo@uk.ibm.com>
Signed-off-by: Harry Butterworth <butterwo@uk.ibm.com>
author | kfraser@localhost.localdomain |
---|---|
date | Mon Jul 31 18:07:25 2006 +0100 (2006-07-31) |
parents | 637fa5352fad |
children | 3fae79942240 |
files | tools/blktap/drivers/blktapctrl.c |
line diff
1.1 --- a/tools/blktap/drivers/blktapctrl.c Mon Jul 31 17:49:36 2006 +0100 1.2 +++ b/tools/blktap/drivers/blktapctrl.c Mon Jul 31 18:07:25 2006 +0100 1.3 @@ -622,6 +622,38 @@ static void print_drivers(void) 1.4 DPRINTF("Found driver: [%s]\n",dtypes[i]->name); 1.5 } 1.6 1.7 +/* Stevens. */ 1.8 +static void daemonize(void) 1.9 +{ 1.10 + pid_t pid; 1.11 + 1.12 + /* Separate from our parent via fork, so init inherits us. */ 1.13 + if ((pid = fork()) < 0) 1.14 + DPRINTF("Failed to fork daemon\n"); 1.15 + if (pid != 0) 1.16 + exit(0); 1.17 + 1.18 + /* Session leader so ^C doesn't whack us. */ 1.19 + setsid(); 1.20 + 1.21 + /* Let session leader exit so child cannot regain CTTY */ 1.22 + if ((pid = fork()) < 0) 1.23 + DPRINTF("Failed to fork daemon\n"); 1.24 + if (pid != 0) 1.25 + exit(0); 1.26 + 1.27 + /* Move off any mount points we might be in. */ 1.28 + if (chdir("/") == -1) 1.29 + DPRINTF("Failed to chdir\n"); 1.30 + 1.31 + /* Discard our parent's old-fashioned umask prejudices. */ 1.32 + umask(0); 1.33 + 1.34 + close(STDIN_FILENO); 1.35 + close(STDOUT_FILENO); 1.36 + close(STDERR_FILENO); 1.37 +} 1.38 + 1.39 int main(int argc, char *argv[]) 1.40 { 1.41 char *devname; 1.42 @@ -633,6 +665,7 @@ int main(int argc, char *argv[]) 1.43 1.44 __init_blkif(); 1.45 openlog("BLKTAPCTRL", LOG_CONS|LOG_ODELAY, LOG_DAEMON); 1.46 + daemonize(); 1.47 1.48 print_drivers(); 1.49 init_driver_list();