ia64/xen-unstable

changeset 17326:21d9575c669e

xenstored: Delay forking until after listening sockets are
opened. Also, in startup xend script, delay further startup until
xenstored initial child process has exited. This serialises xenstored
startup with that of other daemons (e.g., xenconsoled).

Signed-off-by: Bastian Blank <waldi@debian.org>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 26 13:21:42 2008 +0000 (2008-03-26)
parents f471ea366546
children 30e20bb55da5
files tools/misc/xend tools/xenstore/xenstored_core.c
line diff
     1.1 --- a/tools/misc/xend	Wed Mar 26 13:15:33 2008 +0000
     1.2 +++ b/tools/misc/xend	Wed Mar 26 13:21:42 2008 +0000
     1.3 @@ -95,11 +95,17 @@ def start_xenstored():
     1.4          f.close()
     1.5      except:
     1.6          pass
     1.7 -    XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
     1.8 -    cmd = "xenstored --pid-file /var/run/xenstore.pid"
     1.9 -    if XENSTORED_TRACE:
    1.10 -        cmd += " -T /var/log/xen/xenstored-trace.log"
    1.11 -    s,o = commands.getstatusoutput(cmd)
    1.12 +    args = ['xenstored', "--pid-file", pidfname]
    1.13 +    if os.getenv("XENSTORED_TRACE"):
    1.14 +        args.extend(["-T", "/var/log/xen/xenstored-trace.log"])
    1.15 +    pid = os.fork()
    1.16 +    if pid == 0:
    1.17 +        os.execvp('xenstored', args)
    1.18 +    p, status = os.waitpid(pid, 0)
    1.19 +    if os.WIFEXITED(status):
    1.20 +        status = os.WEXITSTATUS(status)
    1.21 +        if status:
    1.22 +            raise RuntimeError("Failed to start xenstored: %d" % status)
    1.23  
    1.24  def start_consoled():
    1.25      if os.fork() == 0:
     2.1 --- a/tools/xenstore/xenstored_core.c	Wed Mar 26 13:15:33 2008 +0000
     2.2 +++ b/tools/xenstore/xenstored_core.c	Wed Mar 26 13:21:42 2008 +0000
     2.3 @@ -1839,13 +1839,6 @@ int main(int argc, char *argv[])
     2.4  		}
     2.5  	}
     2.6  
     2.7 -	if (dofork) {
     2.8 -		openlog("xenstored", 0, LOG_DAEMON);
     2.9 -		daemonize();
    2.10 -	}
    2.11 -	if (pidfile)
    2.12 -		write_pidfile(pidfile);
    2.13 -
    2.14  	/* Talloc leak reports go to stderr, which is closed if we fork. */
    2.15  	if (!dofork)
    2.16  		talloc_enable_leak_report_full();
    2.17 @@ -1899,16 +1892,21 @@ int main(int argc, char *argv[])
    2.18  	/* Restore existing connections. */
    2.19  	restore_existing_connections();
    2.20  
    2.21 -	if (outputpid) {
    2.22 -		printf("%ld\n", (long)getpid());
    2.23 -		fflush(stdout);
    2.24 -	}
    2.25 -
    2.26  	/* redirect to /dev/null now we're ready to accept connections */
    2.27  	if (dofork) {
    2.28  		int devnull = open("/dev/null", O_RDWR);
    2.29  		if (devnull == -1)
    2.30  			barf_perror("Could not open /dev/null\n");
    2.31 +
    2.32 +		openlog("xenstored", 0, LOG_DAEMON);
    2.33 +
    2.34 +		daemonize();
    2.35 +
    2.36 +		if (outputpid) {
    2.37 +			printf("%ld\n", (long)getpid());
    2.38 +			fflush(stdout);
    2.39 +		}
    2.40 +
    2.41  		dup2(devnull, STDIN_FILENO);
    2.42  		dup2(devnull, STDOUT_FILENO);
    2.43  		dup2(devnull, STDERR_FILENO);
    2.44 @@ -1916,6 +1914,9 @@ int main(int argc, char *argv[])
    2.45  		xprintf = trace;
    2.46  	}
    2.47  
    2.48 +	if (pidfile)
    2.49 +		write_pidfile(pidfile);
    2.50 +
    2.51  	signal(SIGHUP, trigger_reopen_log);
    2.52  
    2.53  	if (xce_handle != -1)