]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
jail: Initialize all file descriptors with -1
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 30 Jun 2023 13:30:45 +0000 (13:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 30 Jun 2023 13:30:45 +0000 (13:30 +0000)
It is not a good idea to use zero as that might be a valid fd.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index a7f22b5fb4d2128c4a06d6bca0911ce53403e955..fbdf7b3c5ef82049154c1468c598241525bd396d 100644 (file)
@@ -670,7 +670,7 @@ static int pakfire_jail_get_pipe_to_read(struct pakfire_jail* jail, int (*fds)[2
        // Close the write end of the pipe
        if (*fd_write) {
                close(*fd_write);
-               *fd_write = 0;
+               *fd_write = -1;
        }
 
        // Return the read end
@@ -685,7 +685,7 @@ static int pakfire_jail_get_pipe_to_write(struct pakfire_jail* jail, int (*fds)[
        // Close the read end of the pipe
        if (*fd_read) {
                close(*fd_read);
-               *fd_read = 0;
+               *fd_read = -1;
        }
 
        // Return the write end
@@ -731,7 +731,7 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec
                int fd = fds[i];
 
                // Skip fds which were not initialized
-               if (fd <= 0)
+               if (fd < 0)
                        continue;
 
                ev.events = EPOLLHUP;
@@ -1712,9 +1712,9 @@ static int __pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[],
                .flags = flags,
 
                .pipes = {
-                       .stdin  = { 0, 0 },
-                       .stdout = { 0, 0 },
-                       .stderr = { 0, 0 },
+                       .stdin  = { -1, -1 },
+                       .stdout = { -1, -1 },
+                       .stderr = { -1, -1 },
                },
 
                .communicate = {
@@ -1722,6 +1722,8 @@ static int __pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[],
                        .out  = communicate_out,
                        .data = data,
                },
+
+               .pidfd = -1,
        };
 
        DEBUG(jail->pakfire, "Executing jail...\n");