qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] Truncate pidfile in open


From: Zhaolei
Subject: [Qemu-devel] [PATCH] Truncate pidfile in open
Date: Fri, 4 Apr 2014 13:17:09 +0800

From: Zhao Lei <address@hidden>

qemu havn't cleanup old pidfile before write new:

 # echo "0000000000" > mypid
 # cat mypid
 0000000000
 #

 # qemu-system-x86_64 -pidfile ./mypid
 Could not initialize SDL(No available video device) - exiting
 # cat mypid
 29788
 0000
 #

Can be fixed by adding O_TRUNC in open.

Signed-off-by: Zhao Lei <address@hidden>
---
 os-posix.c | 2 +-
 os-win32.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index cb2a7f7..3509407 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -309,7 +309,7 @@ int qemu_create_pidfile(const char *filename)
     int len;
     int fd;
 
-    fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
+    fd = qemu_open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
     if (fd == -1) {
         return -1;
     }
diff --git a/os-win32.c b/os-win32.c
index 5f95caa..c783bb5 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -119,7 +119,7 @@ int qemu_create_pidfile(const char *filename)
     memset(&overlap, 0, sizeof(overlap));
 
     file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
-                      OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+                      CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 
     if (file == INVALID_HANDLE_VALUE) {
         return -1;
-- 
1.8.5.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]