[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
  • From: Anthony Liguori <aliguori@xxxxxxxxxx>
  • Date: Thu, 04 Aug 2005 11:03:11 -0500
  • Delivery-date: Thu, 04 Aug 2005 19:54:17 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.