* [PATCH 1/3] Make xenstored manage its own pidfile
@ 2005-08-04 16:03 Anthony Liguori
2005-08-05 7:58 ` Muli Ben-Yehuda
0 siblings, 1 reply; 2+ messages in thread
From: Anthony Liguori @ 2005-08-04 16:03 UTC (permalink / raw)
To: xen-devel
[-- 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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH 1/3] Make xenstored manage its own pidfile
2005-08-04 16:03 [PATCH 1/3] Make xenstored manage its own pidfile Anthony Liguori
@ 2005-08-05 7:58 ` Muli Ben-Yehuda
0 siblings, 0 replies; 2+ messages in thread
From: Muli Ben-Yehuda @ 2005-08-05 7:58 UTC (permalink / raw)
To: Anthony Liguori; +Cc: xen-devel
On Thu, Aug 04, 2005 at 11:03:11AM -0500, Anthony Liguori wrote:
> 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
> 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);
How about exit(errno), with or without a descriptive message?
> + }
> +
> + if (lockf(fd, F_TLOCK, 0) == -1) {
> + exit(1);
Likewise?
> +
> + len = sprintf(buf, "%d\n", getpid());
> + write(fd, buf, len);
Check returen value from write?
Cheers,
Muli
--
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-08-05 7:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-04 16:03 [PATCH 1/3] Make xenstored manage its own pidfile Anthony Liguori
2005-08-05 7:58 ` Muli Ben-Yehuda
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.