[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-tools] [PATCH] xenstored: fix pid writing
Rusty, Anthony, looks like this was half applied, i.e. the pid writing part in daemonize was removed but there's no code now to write the pid file at all. I was going to apply the second part of this, but it's not correct since it will write out the pre-fork pid. With the changes from changeset 61cbf8f977ef85724fb76f2421218ec3f670ea9c, this now causes a new xenstored instance to get started everytime xend is started. We need to either bring back the checks within xend to avoid starting xenstored over and over again or make xenstored exit quietly if it detects another instance is already running. Either case needs us to have the pid writing back. christian On Fri, Aug 05, 2005 at 02:21:56PM +1000, Rusty Russell wrote: > When pid writing fails, we've already closed stderr, so all we can do is > fail silently. We should do the pid writing first. > > Secondly, we shouldn't do it for xenstored_test, the test version of the > daemon. > > Finally, we should hand the permissions to open() since we're using > O_CREAT. > > Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx> > > > diff -r 61cbf8f977ef tools/xenstore/utils.c > --- a/tools/xenstore/utils.c Thu Aug 4 18:51:55 2005 > +++ b/tools/xenstore/utils.c Fri Aug 5 14:20:08 2005 > @@ -84,9 +84,6 @@ > void daemonize(void) > { > pid_t pid; > - int fd; > - size_t len; > - char buf[100]; > > /* Separate from our parent via fork, so init inherits us. */ > if ((pid = fork()) < 0) > @@ -104,18 +101,6 @@ > chdir("/"); > /* Discard our parent's old-fashioned umask prejudices. */ > umask(0); > - > - fd = open("/var/run/xenstored.pid", O_RDWR | O_CREAT); > - if (fd == -1) { > - exit(1); > - } > - > - if (lockf(fd, F_TLOCK, 0) == -1) { > - exit(1); > - } > - > - len = sprintf(buf, "%d\n", getpid()); > - write(fd, buf, len); > } > > > diff -r 61cbf8f977ef tools/xenstore/xenstored_core.c > --- a/tools/xenstore/xenstored_core.c Thu Aug 4 18:51:55 2005 > +++ b/tools/xenstore/xenstored_core.c Fri Aug 5 14:20:08 2005 > @@ -1612,6 +1612,19 @@ > /* Debugging: daemonize() closes standard fds, so dup here. */ > tmpout = dup(STDOUT_FILENO); > if (dofork) { > +#ifndef TESTING > + size_t len; > + char buf[100]; > + int fd = open("/var/run/xenstored.pid", O_RDWR|O_CREAT, 0600); > + if (fd == -1) > + barf_perror("Failed to open /var/run/xenstored.pid"); > + > + if (lockf(fd, F_TLOCK, 0) == -1) > + barf("Pidfile locked: daemon already running?"); > + > + len = sprintf(buf, "%d\n", getpid()); > + write(fd, buf, len); > +#endif > openlog("xenstored", 0, LOG_DAEMON); > daemonize(); > } > > -- > A bad analogy is like a leaky screwdriver -- Richard Braakman > > > _______________________________________________ > Xen-tools mailing list > Xen-tools@xxxxxxxxxxxxxxxxxxx > http://lists.xensource.com/xen-tools > _______________________________________________ Xen-tools mailing list Xen-tools@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-tools
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |