]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Initialize/reset file descriptors with EBADF
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 16:42:52 +0000 (16:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 16:42:52 +0000 (16:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pty.c

index f23490aa15510b047395d2416b4577ffffcd1b6c..31986fd1391ad0b9965864b7f25cddb91871216b 100644 (file)
@@ -208,7 +208,7 @@ static int pakfire_pty_restore_attrs(struct pakfire_pty* pty,
        if (stdio->close_fd)
                close(stdio->fd);
 
-       stdio->fd = -1;
+       stdio->fd = -EBADF;
 
        return 0;
 }
@@ -252,7 +252,7 @@ static int pakfire_pty_disconnect(struct pakfire_pty* pty) {
        // Close the PTY
        if (pty->master.fd >= 0) {
                close(pty->master.fd);
-               pty->master.fd = 1;
+               pty->master.fd = -EBADF;
        }
 
        // Restore any changed terminal attributes
@@ -893,7 +893,7 @@ static int pakfire_pty_send_master(struct pakfire_pty* pty) {
 
        // We can close the socket now
        close(pty->socket[1]);
-       pty->socket[1] = -1;
+       pty->socket[1] = -EBADF;
 
        return 0;
 }
@@ -930,7 +930,7 @@ static int pakfire_pty_recv_master(struct pakfire_pty* pty) {
 
        // We can close the socket now
        close(pty->socket[0]);
-       pty->socket[0] = -1;
+       pty->socket[0] = -EBADF;
 
        return 0;
 }
@@ -1008,11 +1008,11 @@ int pakfire_pty_create(struct pakfire_pty** pty, struct pakfire_ctx* ctx,
        p->flags = flags;
 
        // Initialize the master file descriptor
-       p->master.fd = -1;
+       p->master.fd = -EBADF;
 
        // Initialize standard input/output
-       p->stdin.fd  = -1;
-       p->stdout.fd = -1;
+       p->stdin.fd  = -EBADF;
+       p->stdout.fd = -EBADF;
 
        // Create a UNIX domain socket
        r = socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, p->socket);
@@ -1061,7 +1061,7 @@ struct pakfire_pty* pakfire_pty_unref(struct pakfire_pty* pty) {
        Sets up the terminal in the child process...
 */
 static int pakfire_pty_setup_terminal(struct pakfire_pty* pty) {
-       int fd = -1;
+       int fd = -EBADF;
        int r;
 
        // Open a new terminal
@@ -1139,7 +1139,7 @@ int pakfire_pty_open(struct pakfire_pty* pty) {
 
        // We are done with the master and close it now
        close(pty->master.fd);
-       pty->master.fd = -1;
+       pty->master.fd = -EBADF;
 
        // Listen to SIGWINCH
        r = sd_event_add_signal(pty->loop, &pty->sigwinch_event,