mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-11 16:00:50 -07:00
pidfile: stop making pidfile error a special case
In case of -daemonize, we write non-zero to the daemon pipe only if pidfile creation failed, so the parent will report error about pidfile problem. There's no need to make special case for this, since all other errors are reported by the child just fine. Let the parent report error and simplify logic in os_daemonize(). This way, we don't need os_pidfile_error() function, since it only prints error now, so put the error reporting printf into the only place where qemu_create_pidfile() is called, in vl.c. While at it, fix wrong indentation in os_daemonize(). Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
parent
ccea25f1c7
commit
fee78fd6d2
4 changed files with 9 additions and 30 deletions
31
os-posix.c
31
os-posix.c
|
|
@ -221,18 +221,14 @@ void os_daemonize(void)
|
|||
do {
|
||||
len = read(fds[0], &status, 1);
|
||||
} while (len < 0 && errno == EINTR);
|
||||
if (len != 1) {
|
||||
exit(1);
|
||||
}
|
||||
else if (status == 1) {
|
||||
fprintf(stderr, "Could not acquire pidfile\n");
|
||||
exit(1);
|
||||
} else {
|
||||
exit(0);
|
||||
}
|
||||
} else if (pid < 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* only exit successfully if our child actually wrote
|
||||
* a one-byte zero to our pipe, upon successful init */
|
||||
exit(len == 1 && status == 0 ? 0 : 1);
|
||||
|
||||
} else if (pid < 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
close(fds[0]);
|
||||
daemon_pipe = fds[1];
|
||||
|
|
@ -290,17 +286,6 @@ void os_setup_post(void)
|
|||
}
|
||||
}
|
||||
|
||||
void os_pidfile_error(void)
|
||||
{
|
||||
if (daemonize) {
|
||||
uint8_t status = 1;
|
||||
if (write(daemon_pipe, &status, 1) != 1) {
|
||||
perror("daemonize. Writing to pipe\n");
|
||||
}
|
||||
} else
|
||||
fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
void os_set_line_buffering(void)
|
||||
{
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue