Browse Source

Only move fds from force_notify_fd if it is set!

Davin McCall 4 years ago
parent
commit
c09519aeab
1 changed files with 16 additions and 16 deletions
  1. 16 16
      src/run-child-proc.cc

+ 16 - 16
src/run-child-proc.cc

@@ -74,26 +74,26 @@ void service_record::run_child_proc(const char * const *args, const char *workin
 
     int minfd = (socket_fd == -1) ? 3 : 4;
 
-    // Move wpipefd/csfd/socket_fd to another fd if necessary:
-    if (wpipefd == force_notify_fd) {
-        if (move_reserved_fd(&wpipefd, minfd) == -1) {
-            goto failure_out;
+    if (force_notify_fd != -1) {
+        // Move wpipefd/csfd/socket_fd to another fd if necessary:
+        if (wpipefd == force_notify_fd) {
+            if (move_reserved_fd(&wpipefd, minfd) == -1) {
+                goto failure_out;
+            }
         }
-    }
-    if (csfd == force_notify_fd) {
-        if (move_reserved_fd(&csfd, minfd) == -1) {
-            goto failure_out;
+        if (csfd == force_notify_fd) {
+            if (move_reserved_fd(&csfd, minfd) == -1) {
+                goto failure_out;
+            }
         }
-    }
-    if (socket_fd == force_notify_fd) {
-        // Note that we might move this again later
-        if (move_reserved_fd(&socket_fd, 0) == -1) {
-            goto failure_out;
+        if (socket_fd == force_notify_fd) {
+            // Note that we might move this again later
+            if (move_reserved_fd(&socket_fd, 0) == -1) {
+                goto failure_out;
+            }
         }
-    }
 
-    // allocate the forced notification fd, if specified:
-    if (force_notify_fd != -1) {
+        // allocate the forced notification fd:
         if (notify_fd != force_notify_fd) {
             if (dup2(notify_fd, force_notify_fd) == -1) {
                 goto failure_out;