]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
jail: Fix more fd checks
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Nov 2023 16:43:08 +0000 (16:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Nov 2023 16:43:08 +0000 (16:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index b13ff205abdcb01e69a893c4c3344ac8b57e4a39..ebcb6f31abce7cbf367779b19f227a772d09aad1 100644 (file)
@@ -519,7 +519,7 @@ static int pakfire_jail_create_timer(struct pakfire_jail* jail) {
        return fd;
 
 ERROR:
-       if (fd > 0)
+       if (fd >= 0)
                close(fd);
 
        return -1;
@@ -689,7 +689,7 @@ static int pakfire_jail_stream_stdin(struct pakfire_jail* jail,
                close(fd);
 
                // Reset the file-descriptor so it won't be closed again later
-               ctx->pipes.stdin[1] = 0;
+               ctx->pipes.stdin[1] = -1;
 
                // Report success
                r = 0;
@@ -710,7 +710,7 @@ static int pakfire_jail_setup_pipe(struct pakfire_jail* jail, int (*fds)[2], con
 
 static void pakfire_jail_close_pipe(struct pakfire_jail* jail, int fds[2]) {
        for (unsigned int i = 0; i < 2; i++)
-               if (fds[i])
+               if (fds[i] >= 0)
                        close(fds[i]);
 }
 
@@ -1022,11 +1022,11 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec
        }
 
 ERROR:
-       if (epollfd > 0)
+       if (epollfd >= 0)
                close(epollfd);
-       if (timerfd > 0)
+       if (timerfd >= 0)
                close(timerfd);
-       if (signalfd > 0)
+       if (signalfd >= 0)
                close(signalfd);
 
        return r;
@@ -2051,7 +2051,7 @@ ERROR:
        pakfire_jail_close_pipe(jail, ctx.pipes.stdin);
        pakfire_jail_close_pipe(jail, ctx.pipes.stdout);
        pakfire_jail_close_pipe(jail, ctx.pipes.stderr);
-       if (ctx.pidfd)
+       if (ctx.pidfd >= 0)
                close(ctx.pidfd);
        pakfire_jail_close_pipe(jail, ctx.pipes.log_INFO);
        pakfire_jail_close_pipe(jail, ctx.pipes.log_ERROR);