[libvirt PATCH 13/19] commandhelper: Factor out printInput

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

 



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

diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 929de7a05d..d501e33e88 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -191,39 +191,20 @@ static int printCwd(FILE *log)
     return 0;
 }
 
-int main(int argc, char **argv) {
-    struct Arguments *args = parseArguments(argc, argv);
-    size_t i;
-    FILE *log = fopen(abs_builddir "/commandhelper.log", "w");
-    int ret = EXIT_FAILURE;
+static int printInput(struct Arguments *args)
+{
+    char buf[1024];
     struct pollfd fds[3];
     char *buffers[3] = {NULL, NULL, NULL};
     size_t buflen[3] = {0, 0, 0};
-    char buf[1024];
+    int ret = -1;
+    size_t i;
     ssize_t got;
 
-    if (!log || !args)
-        goto cleanup;
-
-    printArguments(log, argc, argv);
-
-    if (printEnvironment(log) != 0)
-        goto cleanup;
-
-    if (printFds(log) != 0)
-        goto cleanup;
-
-    printDaemonization(log, args);
-
-    if (printCwd(log) != 0)
-        goto cleanup;
-
-    fprintf(log, "UMASK:%04o\n", umask(0));
-
     if (args->close_stdin) {
         if (freopen("/dev/null", "r", stdin) != stdin)
             goto cleanup;
-        usleep(100*1000);
+        usleep(100 * 1000);
     }
 
     fprintf(stdout, "BEGIN STDOUT\n");
@@ -298,11 +279,43 @@ int main(int argc, char **argv) {
     fprintf(stderr, "END STDERR\n");
     fflush(stderr);
 
-    ret = EXIT_SUCCESS;
+    ret = 0;
 
  cleanup:
     for (i = 0; i < G_N_ELEMENTS(buffers); i++)
         free(buffers[i]);
+    return ret;
+}
+
+int main(int argc, char **argv) {
+    struct Arguments *args = parseArguments(argc, argv);
+    FILE *log = fopen(abs_builddir "/commandhelper.log", "w");
+    int ret = EXIT_FAILURE;
+
+    if (!log || !args)
+        goto cleanup;
+
+    printArguments(log, argc, argv);
+
+    if (printEnvironment(log) != 0)
+        goto cleanup;
+
+    if (printFds(log) != 0)
+        goto cleanup;
+
+    printDaemonization(log, args);
+
+    if (printCwd(log) != 0)
+        goto cleanup;
+
+    fprintf(log, "UMASK:%04o\n", umask(0));
+
+    if (printInput(args) != 0)
+        goto cleanup;
+
+    ret = EXIT_SUCCESS;
+
+ cleanup:
     if (args)
         free(args);
     if (log)
-- 
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