[libvirt PATCH 10/19] commandhelper: Factor out printFds

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

 



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

diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 14c7302633..fa32f6a435 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -130,10 +130,32 @@ static int printEnvironment(FILE *log)
     return ret;
 }
 
+static int printFds(FILE *log)
+{
+    long int open_max = sysconf(_SC_OPEN_MAX);
+    size_t i;
+
+    if (open_max < 0)
+        return -1;
+
+    for (i = 0; i < open_max; i++) {
+        int ignore;
+
+        if (i == fileno(log))
+            continue;
+
+        if (fcntl(i, F_GETFD, &ignore) == -1 && errno == EBADF)
+            continue;
+
+        fprintf(log, "FD:%zu\n", i);
+    }
+
+    return 0;
+}
+
 int main(int argc, char **argv) {
     struct Arguments *args = parseArguments(argc, argv);
     size_t i;
-    int open_max;
     char *cwd;
     FILE *log = fopen(abs_builddir "/commandhelper.log", "w");
     int ret = EXIT_FAILURE;
@@ -152,19 +174,8 @@ int main(int argc, char **argv) {
     if (printEnvironment(log) != 0)
         goto cleanup;
 
-    open_max = sysconf(_SC_OPEN_MAX);
-    if (open_max < 0)
+    if (printFds(log) != 0)
         goto cleanup;
-    for (i = 0; i < open_max; i++) {
-        int f;
-        int closed;
-        if (i == fileno(log))
-            continue;
-        closed = fcntl(i, F_GETFD, &f) == -1 &&
-            errno == EBADF;
-        if (!closed)
-            fprintf(log, "FD:%zu\n", i);
-    }
 
     while (true) {
         bool daemonized = getpgrp() != getppid();
-- 
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