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

[Xen-changelog] [xen-unstable] Steal the write_pidfile function from xen

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Steal the write_pidfile function from xenstored_core, and use it to ensure
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 13 Dec 2006 17:35:24 +0000
Delivery-date: Wed, 13 Dec 2006 09:43:14 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Steal the write_pidfile function from xenstored_core, and use it to ensure, Xen patchbot-unstable <=