mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 19:49:43 +00:00
fix pidfile option to work in WIN32
Explicit read/write locking pidfile under WIN32 is bit extreme nobody get the chance to read the pidfile. Convert to a write-only lock. Also, creating pidfile was disabled along with daemonize under WIN32. Enable it, but do not enable daemon support which doesn't exist under WIN32 atm. From: Juha Riihimäki <juha.riihimaki@nokia.com> Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com> Signed-off-by: Riku Voipio <riku.voipio@nokia.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
parent
1e8b27ca85
commit
099fe236d5
13
osdep.c
13
osdep.c
@ -133,25 +133,16 @@ int qemu_create_pidfile(const char *filename)
|
|||||||
return -1;
|
return -1;
|
||||||
#else
|
#else
|
||||||
HANDLE file;
|
HANDLE file;
|
||||||
DWORD flags;
|
|
||||||
OVERLAPPED overlap;
|
OVERLAPPED overlap;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
memset(&overlap, 0, sizeof(overlap));
|
||||||
|
|
||||||
/* Open for writing with no sharing. */
|
file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
|
||||||
file = CreateFile(filename, GENERIC_WRITE, 0, NULL,
|
|
||||||
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
|
||||||
if (file == INVALID_HANDLE_VALUE)
|
if (file == INVALID_HANDLE_VALUE)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
flags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
|
|
||||||
overlap.hEvent = 0;
|
|
||||||
/* Lock 1 byte. */
|
|
||||||
ret = LockFileEx(file, flags, 0, 0, 1, &overlap);
|
|
||||||
if (ret == 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* Write PID to file. */
|
|
||||||
len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
|
len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
|
||||||
ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
|
ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
|
||||||
&overlap, NULL);
|
&overlap, NULL);
|
||||||
|
4
vl.c
4
vl.c
@ -5761,16 +5761,18 @@ int main(int argc, char **argv, char **envp)
|
|||||||
signal(SIGTTOU, SIG_IGN);
|
signal(SIGTTOU, SIG_IGN);
|
||||||
signal(SIGTTIN, SIG_IGN);
|
signal(SIGTTIN, SIG_IGN);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (pid_file && qemu_create_pidfile(pid_file) != 0) {
|
if (pid_file && qemu_create_pidfile(pid_file) != 0) {
|
||||||
|
#ifndef _WIN32
|
||||||
if (daemonize) {
|
if (daemonize) {
|
||||||
uint8_t status = 1;
|
uint8_t status = 1;
|
||||||
write(fds[1], &status, 1);
|
write(fds[1], &status, 1);
|
||||||
} else
|
} else
|
||||||
|
#endif
|
||||||
fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
|
fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (kvm_enabled()) {
|
if (kvm_enabled()) {
|
||||||
int ret;
|
int ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user