From: Michael Tremer Date: Thu, 10 Oct 2024 10:03:25 +0000 (+0000) Subject: pty: De-register events before closing the file descriptors X-Git-Tag: 0.9.30~1096 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd1c3f67f91ff403743fc49c110119fa5d79d2fa;p=pakfire.git pty: De-register events before closing the file descriptors Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pty.c b/src/libpakfire/pty.c index 232050706..08115af63 100644 --- a/src/libpakfire/pty.c +++ b/src/libpakfire/pty.c @@ -224,15 +224,6 @@ static int pakfire_pty_store_attrs(struct pakfire_pty* pty, } static int pakfire_pty_disconnect(struct pakfire_pty* pty) { - if (pty->master.fd >= 0) { - close(pty->master.fd); - pty->master.fd = 1; - } - - // Restore any changed terminal attributes - pakfire_pty_restore_attrs(pty, &pty->stdin); - pakfire_pty_restore_attrs(pty, &pty->stdout); - // Clear events if (pty->master.event) pty->master.event = sd_event_source_unref(pty->master.event); @@ -243,6 +234,16 @@ static int pakfire_pty_disconnect(struct pakfire_pty* pty) { if (pty->sigwinch_event) pty->sigwinch_event = sd_event_source_unref(pty->sigwinch_event); + // Close the PTY + if (pty->master.fd >= 0) { + close(pty->master.fd); + pty->master.fd = 1; + } + + // Restore any changed terminal attributes + pakfire_pty_restore_attrs(pty, &pty->stdin); + pakfire_pty_restore_attrs(pty, &pty->stdout); + return 0; } @@ -890,7 +891,7 @@ static void pakfire_pty_free(struct pakfire_pty* pty) { // Output if (pty->output.iov_base) munmap(pty->output.iov_base, pty->output.iov_len); - if (pty->outputfd) + if (pty->outputfd >= 0) close(pty->outputfd); if (pty->loop)