ia64/xen-unstable

changeset 10896:8b635f930187

Switch blktapctrl.c over to using standard system daemon(3) call. Current patch was not closing all FDs and redirecting output to /dev/null, preventing tapdisk from launching correctly.
author jchesterfield@dhcp92.uk.xensource.com
date Tue Aug 01 17:59:27 2006 +0100 (2006-08-01)
parents d323acca28a2
children 10b05c2e7947
files tools/blktap/drivers/blktapctrl.c
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Tue Aug 01 17:47:21 2006 +0100
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Tue Aug 01 17:59:27 2006 +0100
     1.3 @@ -61,6 +61,7 @@
     1.4  #define MSG_SIZE 4096
     1.5  #define MAX_TIMEOUT 10
     1.6  #define MAX_RAND_VAL 0xFFFF
     1.7 +#define MAX_ATTEMPTS 10
     1.8  
     1.9  int run = 1;
    1.10  int max_timeout = MAX_TIMEOUT;
    1.11 @@ -622,50 +623,18 @@ static void print_drivers(void)
    1.12  		DPRINTF("Found driver: [%s]\n",dtypes[i]->name);
    1.13  } 
    1.14  
    1.15 -/* Stevens. */
    1.16 -static void daemonize(void)
    1.17 -{
    1.18 -	pid_t pid;
    1.19 -
    1.20 -	/* Separate from our parent via fork, so init inherits us. */
    1.21 -	if ((pid = fork()) < 0)
    1.22 -		DPRINTF("Failed to fork daemon\n");
    1.23 -	if (pid != 0)
    1.24 -		exit(0);
    1.25 -
    1.26 -	/* Session leader so ^C doesn't whack us. */
    1.27 -	setsid();
    1.28 -
    1.29 -	/* Let session leader exit so child cannot regain CTTY */
    1.30 -	if ((pid = fork()) < 0)
    1.31 -		DPRINTF("Failed to fork daemon\n");
    1.32 -	if (pid != 0)
    1.33 -		exit(0);
    1.34 -
    1.35 -	/* Move off any mount points we might be in. */
    1.36 -	if (chdir("/") == -1)
    1.37 -		DPRINTF("Failed to chdir\n");
    1.38 -
    1.39 -	/* Discard our parent's old-fashioned umask prejudices. */
    1.40 -	umask(0);
    1.41 -
    1.42 -	close(STDIN_FILENO);
    1.43 -	close(STDOUT_FILENO);
    1.44 -	close(STDERR_FILENO);
    1.45 -}
    1.46 -
    1.47  int main(int argc, char *argv[])
    1.48  {
    1.49  	char *devname;
    1.50  	tapdev_info_t *ctlinfo;
    1.51 -	int tap_pfd, store_pfd, xs_fd, ret, timeout, pfd_count;
    1.52 +	int tap_pfd, store_pfd, xs_fd, ret, timeout, pfd_count, count=0;
    1.53  	struct xs_handle *h;
    1.54  	struct pollfd  pfd[NUM_POLL_FDS];
    1.55  	pid_t process;
    1.56  
    1.57  	__init_blkif();
    1.58  	openlog("BLKTAPCTRL", LOG_CONS|LOG_ODELAY, LOG_DAEMON);
    1.59 -	daemonize();
    1.60 +	daemon(0,0);
    1.61  
    1.62  	print_drivers();
    1.63  	init_driver_list();
    1.64 @@ -684,18 +653,28 @@ int main(int argc, char *argv[])
    1.65  		goto open_failed;
    1.66  	}
    1.67  
    1.68 + retry:
    1.69  	/* Set up store connection and watch. */
    1.70  	h = xs_daemon_open();
    1.71  	if (h == NULL) {
    1.72  		DPRINTF("xs_daemon_open failed -- "
    1.73  			"is xenstore running?\n");
    1.74 -		goto open_failed;
    1.75 +                if (count < MAX_ATTEMPTS) {
    1.76 +                        count++;
    1.77 +                        sleep(2);
    1.78 +                        goto retry;
    1.79 +                } else goto open_failed;
    1.80  	}
    1.81  	
    1.82  	ret = add_blockdevice_probe_watch(h, "Domain-0");
    1.83  	if (ret != 0) {
    1.84 -		DPRINTF("adding device probewatch\n");
    1.85 -		goto open_failed;
    1.86 +		DPRINTF("Failed adding device probewatch\n");
    1.87 +                if (count < MAX_ATTEMPTS) {
    1.88 +                        count++;
    1.89 +                        sleep(2);
    1.90 +                        xs_daemon_close(h);
    1.91 +                        goto retry;
    1.92 +                } else goto open_failed;
    1.93  	}
    1.94  
    1.95  	ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
    1.96 @@ -724,6 +703,7 @@ int main(int argc, char *argv[])
    1.97  		}
    1.98  	}
    1.99  
   1.100 +	xs_daemon_close(h);
   1.101  	ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_PASSTHROUGH );
   1.102  	close(ctlfd);
   1.103  	closelog();