]> git.ipfire.org Git - pakfire.git/commitdiff
pty: De-register events before closing the file descriptors
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 10 Oct 2024 10:03:25 +0000 (10:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 10 Oct 2024 10:03:25 +0000 (10:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pty.c

index 2320507064ce11990fba7b0d84a7a772cba59cb0..08115af63e32b2df1473729393fd7cb933ce70a0 100644 (file)
@@ -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)