]> git.proxmox.com Git - mirror_qemu.git/blobdiff - os-posix.c
Separate qemu_pidfile() into OS specific versions
[mirror_qemu.git] / os-posix.c
index 612b6417371a60b4cd785fb7a7f5f3661141ef8c..38c29d1afe42ff3b2e7fc28f938e5798a2551053 100644 (file)
@@ -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;
+}