Report failure of setting fcntl(FD_CLOEXEC) as error
authorJagger <robert@swiecki.net>
Mon, 20 Jun 2016 20:59:29 +0000 (22:59 +0200)
committerJagger <robert@swiecki.net>
Mon, 20 Jun 2016 20:59:29 +0000 (22:59 +0200)
contain.c

index 90afdea383e2adc035998fdaa76af5cce11b0595..be0e4dc0cd3e95c8225e453036588191e81ac858 100644 (file)
--- a/contain.c
+++ b/contain.c
@@ -215,9 +215,15 @@ static bool containMakeFdsCOENaive(struct nsjconf_t *nsjconf)
                }
                if (containPassFd(nsjconf, fd)) {
                        LOG_D("FD=%d will be passed to the child process", fd);
-                       TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, flags & ~(FD_CLOEXEC)));
+                       if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, flags & ~(FD_CLOEXEC))) == -1) {
+                               PLOG_E("Could not set FD_CLOEXEC for FD=%d", fd);
+                               return false;
+                       }
                } else {
-                       TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, flags | FD_CLOEXEC));
+                       if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, flags | FD_CLOEXEC)) == -1) {
+                               PLOG_E("Could not set FD_CLOEXEC for FD=%d", fd);
+                               return false;
+                       }
                }
        }
        return true;
@@ -262,10 +268,16 @@ static bool containMakeFdsCOEProc(struct nsjconf_t *nsjconf)
                }
                if (containPassFd(nsjconf, fd)) {
                        LOG_D("FD=%d will be passed to the child process", fd);
-                       TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, flags & ~(FD_CLOEXEC)));
+                       if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, flags & ~(FD_CLOEXEC))) == -1) {
+                               PLOG_E("Could not clear FD_CLOEXEC for FD=%d", fd);
+                               return false;
+                       }
                } else {
                        LOG_D("FD=%d will be closed before execve()", fd);
-                       TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, flags | FD_CLOEXEC));
+                       if (TEMP_FAILURE_RETRY(fcntl(fd, F_SETFD, flags | FD_CLOEXEC)) == -1) {
+                               PLOG_E("Could not set FD_CLOEXEC for FD=%d", fd);
+                               return false;
+                       }
                }
        }
        return true;