]> git.proxmox.com Git - mirror_qemu.git/commitdiff
pidfile: stop making pidfile error a special case
authorMichael Tokarev <mjt@tls.msk.ru>
Thu, 30 Oct 2014 14:40:48 +0000 (17:40 +0300)
committerMichael Tokarev <mjt@tls.msk.ru>
Sun, 2 Nov 2014 07:04:34 +0000 (10:04 +0300)
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>
include/qemu-common.h
os-posix.c
os-win32.c
vl.c

index b87e9c2d8bfb362aeaf789765bd3f106d0c2cc0c..f8622141a80b44bc9e00609d63b529d67addc0b4 100644 (file)
@@ -357,7 +357,6 @@ char *qemu_find_file(int type, const char *name);
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(void);
 void os_parse_cmd_args(int index, const char *optarg);
-void os_pidfile_error(void);
 
 /* Convert a byte between binary and BCD.  */
 static inline uint8_t to_bcd(uint8_t val)
index eada8d4685669a3f00bf0eba0860a73137878109..52e989797da91abbe8c3819c20e5708e5694a616 100644 (file)
@@ -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);
index 5f95caac1590a24efb6b208161c034c0c79674a4..c0daf8e189e469acf1f8a958aacf65a77f6fccfb 100644 (file)
@@ -104,11 +104,6 @@ void os_parse_cmd_args(int index, const char *optarg)
     return;
 }
 
-void os_pidfile_error(void)
-{
-    fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
-}
-
 int qemu_create_pidfile(const char *filename)
 {
     char buffer[128];
diff --git a/vl.c b/vl.c
index f6b35469428f46660a4a418a9029e77247988d5e..150524c718faf8b67955c951f3e0f05ffcc53979 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -3999,7 +3999,7 @@ int main(int argc, char **argv, char **envp)
 #endif
 
     if (pid_file && qemu_create_pidfile(pid_file) != 0) {
-        os_pidfile_error();
+        fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
         exit(1);
     }