[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 15/23] os-posix: use global daemon_pipe instead of cr
From: |
Michael Tokarev |
Subject: |
[Qemu-devel] [PULL 15/23] os-posix: use global daemon_pipe instead of cryptic fds[1] |
Date: |
Sun, 2 Nov 2014 14:57:27 +0300 |
When asked to -daemonize, we fork a child and setup a pipe between
it and parent to pass exit status. os-posix.c used global fds[2]
array for that, but actually only the writing side of the pipe is
needed to be global, and this name is really too generic. Use
just one interger for the writing side of the pipe, and name it
daemon_pipe to be more understandable than cryptic fds[1].
Signed-off-by: Michael Tokarev <address@hidden>
Reviewed-by: Gonglei <address@hidden>
---
os-posix.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/os-posix.c b/os-posix.c
index e31a099..d687896 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -47,7 +47,7 @@
static struct passwd *user_pwd;
static const char *chroot_dir;
static int daemonize;
-static int fds[2];
+static int daemon_pipe;
void os_setup_early_signal_handling(void)
{
@@ -205,6 +205,7 @@ void os_daemonize(void)
{
if (daemonize) {
pid_t pid;
+ int fds[2];
if (pipe(fds) == -1) {
exit(1);
@@ -236,7 +237,8 @@ void os_daemonize(void)
}
close(fds[0]);
- qemu_set_cloexec(fds[1]);
+ daemon_pipe = fds[1];
+ qemu_set_cloexec(daemon_pipe);
setsid();
@@ -263,7 +265,7 @@ void os_setup_post(void)
ssize_t len;
again1:
- len = write(fds[1], &status, 1);
+ len = write(daemon_pipe, &status, 1);
if (len == -1 && (errno == EINTR)) {
goto again1;
}
@@ -296,7 +298,7 @@ void os_pidfile_error(void)
{
if (daemonize) {
uint8_t status = 1;
- if (write(fds[1], &status, 1) != 1) {
+ if (write(daemon_pipe, &status, 1) != 1) {
perror("daemonize. Writing to pipe\n");
}
} else
--
1.7.10.4
- [Qemu-devel] [PULL 02/23] bitops.h: Don't include qemu-common.h, (continued)
- [Qemu-devel] [PULL 02/23] bitops.h: Don't include qemu-common.h, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 11/23] virtio-9p-proxy: Fix sockfd leak, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 04/23] target-xtensa: mark XtensaConfig structs as unused, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 03/23] bitmap.h: Don't include qemu-common.h, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 12/23] virtio-9p-proxy: fix error return in proxy_init(), Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 17/23] pidfile: stop making pidfile error a special case, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 07/23] util: Improve os_mem_prealloc error message, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 05/23] target-arm: A64: remove redundant store, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 06/23] sparse: fix build, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 23/23] vdi: wrapped uuid_unparse() in #ifdef, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 15/23] os-posix: use global daemon_pipe instead of cryptic fds[1],
Michael Tokarev <=
- [Qemu-devel] [PULL 09/23] net/slirp: specify logbase for smbd, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 08/23] Revert "os-posix: report error message when lock file failed", Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 13/23] virtio-9p-proxy: improve error messages in connect_namedsocket(), Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 22/23] tap: fix possible fd leak in net_init_tap, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 18/23] os-posix: reorder parent notification for -daemonize, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 10/23] target-tricore: check return value before using it, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 21/23] tap: do not close(fd) in net_init_tap_one, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 20/23] target-i386: Remove unused model_features_t struct, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 19/23] tap_int.h: remove repeating NETWORK_SCRIPT defines, Michael Tokarev, 2014/11/02
- [Qemu-devel] [PULL 16/23] os-posix: replace goto again with a proper loop, Michael Tokarev, 2014/11/02