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

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

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 1/3] Make xenstored manage its own pidfile
From: Anthony Liguori <aliguori@xxxxxxxxxx>
Date: Thu, 04 Aug 2005 11:03:11 -0500
Delivery-date: Thu, 04 Aug 2005 19:54:17 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
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>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)
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);
+       }
+
+       if (lockf(fd, F_TLOCK, 0) == -1) {
+               exit(1);
+       }
+
+       len = sprintf(buf, "%d\n", getpid());
+       write(fd, buf, len);
 }
 
 
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>