From: Michael Tremer Date: Sat, 12 Oct 2024 16:42:52 +0000 (+0000) Subject: pty: Initialize/reset file descriptors with EBADF X-Git-Tag: 0.9.30~1068 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=101d1675f3efaeb65452eb1b41f35206a694a178;p=pakfire.git pty: Initialize/reset file descriptors with EBADF Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pty.c b/src/libpakfire/pty.c index f23490aa1..31986fd13 100644 --- a/src/libpakfire/pty.c +++ b/src/libpakfire/pty.c @@ -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,