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
|