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-devel

Re: [Xen-devel] [PATCH 1/3] Make xenstored manage its own pidfile

To: Anthony Liguori <aliguori@xxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH 1/3] Make xenstored manage its own pidfile
From: Muli Ben-Yehuda <mulix@xxxxxxxxx>
Date: Fri, 5 Aug 2005 10:58:20 +0300
Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Fri, 05 Aug 2005 07:56:24 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <42F23C3F.5070404@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <42F23C3F.5070404@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.6+20040907i
On Thu, Aug 04, 2005 at 11:03:11AM -0500, Anthony Liguori wrote:

> The following patch makes xenstored manage its own pidfile which makes 
> it impossible for it to be started multiple times.
> 
> Signed-off-by: Anthony Liguori <aliguori@xxxxxxxxxx
> 
> Regards,
> 
> Anthony Liguori

> diff -r 1d240086de52 tools/xenstore/utils.c
> --- a/tools/xenstore/utils.c  Thu Aug  4 15:02:09 2005
> +++ b/tools/xenstore/utils.c  Thu Aug  4 10:54:13 2005
> @@ -84,6 +84,9 @@
>  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)
> @@ -101,6 +104,18 @@
>       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);

How about exit(errno), with or without a descriptive message?

> +     }
> +
> +     if (lockf(fd, F_TLOCK, 0) == -1) {
> +             exit(1);

Likewise?

> +
> +     len = sprintf(buf, "%d\n", getpid());
> +     write(fd, buf, len);

Check returen value from write?

Cheers,
Muli
-- 
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

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