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

[Xen-changelog] [xen-unstable] Steal the write_pidfile function from xenstored_core, and use it to ensure



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Node ID 87f220709073ea356eac71447d81bfb7814179b8
# Parent  e2792d1612b33b4cda7d81f70c66642291b4bc8c
Steal the write_pidfile function from xenstored_core, and use it to ensure
that blktapctrl only starts once.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/blktap/drivers/blktapctrl.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+)

diff -r e2792d1612b3 -r 87f220709073 tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c Wed Dec 13 11:13:08 2006 +0000
+++ b/tools/blktap/drivers/blktapctrl.c Wed Dec 13 11:23:01 2006 +0000
@@ -57,6 +57,8 @@
 #include "blktapctrl.h"
 #include "tapdisk.h"
 
+#define PIDFILE "/var/run/blktapctrl.pid"
+
 #define NUM_POLL_FDS 2
 #define MSG_SIZE 4096
 #define MAX_TIMEOUT 10
@@ -622,6 +624,29 @@ static void print_drivers(void)
                DPRINTF("Found driver: [%s]\n",dtypes[i]->name);
 } 
 
+static void write_pidfile(long pid)
+{
+       char buf[100];
+       int len;
+       int fd;
+
+       fd = open(PIDFILE, O_RDWR | O_CREAT, 0600);
+       if (fd == -1) {
+               DPRINTF("Opening pid file failed (%d)\n", errno);
+               exit(1);
+       }
+
+       /* We exit silently if daemon already running. */
+       if (lockf(fd, F_TLOCK, 0) == -1)
+               exit(0);
+
+       len = sprintf(buf, "%ld\n", pid);
+       if (write(fd, buf, len) != len) {
+               DPRINTF("Writing pid file failed (%d)\n", errno);
+               exit(1);
+       }
+}
+
 int main(int argc, char *argv[])
 {
        char *devname;
@@ -681,6 +706,7 @@ int main(int argc, char *argv[])
        ioctl(ctlfd, BLKTAP_IOCTL_SETMODE, BLKTAP_MODE_INTERPOSE );
 
        process = getpid();
+       write_pidfile(process);
        ret = ioctl(ctlfd, BLKTAP_IOCTL_SENDPID, process );
 
        /*Static pollhooks*/
@@ -716,3 +742,13 @@ int main(int argc, char *argv[])
        closelog();
        return -1;
 }
+
+/*
+ * Local variables:
+ *  c-file-style: "linux"
+ *  indent-tabs-mode: t
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */

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


 


Rackspace

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