aboutsummaryrefslogtreecommitdiff
path: root/os-posix.c
diff options
context:
space:
mode:
authorJes Sorensen <Jes.Sorensen@redhat.com>2010-10-26 10:39:25 +0200
committerBlue Swirl <blauwirbel@gmail.com>2010-10-30 08:02:39 +0000
commitbc4a957c46acd8f4b2f2ffe6b2f90512325924dd (patch)
treee386df6724907c5e1b4bdf6535e4245c830086fe /os-posix.c
parentff753bb9a60780e7af93288ac55bf1277a30cff7 (diff)
Separate qemu_pidfile() into OS specific versions
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'os-posix.c')
-rw-r--r--os-posix.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/os-posix.c b/os-posix.c
index 612b641737..38c29d1afe 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -361,3 +361,24 @@ int qemu_eventfd(int fds[2])
return qemu_pipe(fds);
}
+
+int qemu_create_pidfile(const char *filename)
+{
+ char buffer[128];
+ int len;
+ int fd;
+
+ fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
+ if (fd == -1) {
+ return -1;
+ }
+ if (lockf(fd, F_TLOCK, 0) == -1) {
+ return -1;
+ }
+ len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
+ if (write(fd, buffer, len) != len) {
+ return -1;
+ }
+
+ return 0;
+}