[libvirt PATCH 11/19] commandhelper: Factor out printDaemonization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 tests/commandhelper.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index fa32f6a435..01dd6f9e45 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -153,6 +153,19 @@ static int printFds(FILE *log)
     return 0;
 }
 
+static void printDaemonization(FILE *log, struct Arguments *args)
+{
+    int retries = 3;
+
+    if (args->daemonize_check) {
+        while ((getpgrp() == getppid()) && (retries-- > 0)) {
+            usleep(100 * 1000);
+        }
+    }
+
+    fprintf(log, "DAEMON:%s\n", getpgrp() != getppid() ? "yes" : "no");
+}
+
 int main(int argc, char **argv) {
     struct Arguments *args = parseArguments(argc, argv);
     size_t i;
@@ -162,7 +175,6 @@ int main(int argc, char **argv) {
     struct pollfd fds[3];
     char *buffers[3] = {NULL, NULL, NULL};
     size_t buflen[3] = {0, 0, 0};
-    size_t daemonize_retries = 3;
     char buf[1024];
     ssize_t got;
 
@@ -177,17 +189,7 @@ int main(int argc, char **argv) {
     if (printFds(log) != 0)
         goto cleanup;
 
-    while (true) {
-        bool daemonized = getpgrp() != getppid();
-
-        if (args->daemonize_check && !daemonized && daemonize_retries-- > 0) {
-            usleep(100*1000);
-            continue;
-        }
-
-        fprintf(log, "DAEMON:%s\n", daemonized ? "yes" : "no");
-        break;
-    }
+    printDaemonization(log, args);
 
     if (!(cwd = getcwd(NULL, 0)))
         goto cleanup;
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux