All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: xen-devel <xen-devel@lists.xensource.com>
Subject: [PATCH 1/3] Make xenstored manage its own pidfile
Date: Thu, 04 Aug 2005 11:03:11 -0500	[thread overview]
Message-ID: <42F23C3F.5070404@us.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 203 bytes --]

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@us.ibm.com

Regards,

Anthony Liguori

[-- Attachment #2: xenstored_pidfile.diff --]
[-- Type: text/x-patch, Size: 669 bytes --]

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);
 }
 
 

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

             reply	other threads:[~2005-08-04 16:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-04 16:03 Anthony Liguori [this message]
2005-08-05  7:58 ` [PATCH 1/3] Make xenstored manage its own pidfile Muli Ben-Yehuda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42F23C3F.5070404@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.