diff mbox

[1/4] os-posix: use global daemon_pipe instead of cryptic fds[1]

Message ID 6b6f5fbff3574bffafe4204d2153258fc4440120.1414681502.git.mjt@msgid.tls.msk.ru
State New
Headers show

Commit Message

Michael Tokarev Oct. 30, 2014, 3:07 p.m. UTC
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 <mjt@tls.msk.ru>
---
 os-posix.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Gonglei (Arei) Oct. 31, 2014, 4:57 a.m. UTC | #1
On 2014/10/30 23:07, Michael Tokarev wrote:

> 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 <mjt@tls.msk.ru>
> ---
>  os-posix.c |   10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)

Reviewed-by: Gonglei <arei.gonglei@huawei.com>

Best regards,
-Gonglei
diff mbox

Patch

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