WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-tools

Re: [Xen-tools] [PATCH] xenstored: fix pid writing

To: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
Subject: Re: [Xen-tools] [PATCH] xenstored: fix pid writing
From: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>
Date: Tue, 9 Aug 2005 10:07:01 +0100
Cc: Xen Tools <xen-tools@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Tue, 09 Aug 2005 09:05:16 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1123215716.10802.98.camel@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-tools-request@lists.xensource.com?subject=help>
List-id: Xen control tools developers <xen-tools.lists.xensource.com>
List-post: <mailto:xen-tools@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-tools>, <mailto:xen-tools-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-tools>, <mailto:xen-tools-request@lists.xensource.com?subject=unsubscribe>
References: <1123215716.10802.98.camel@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-tools-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.4.1i
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

<Prev in Thread] Current Thread [Next in Thread>