From: Michael Tremer Date: Sun, 6 Oct 2024 12:47:34 +0000 (+0000) Subject: pty: Store events and add a description X-Git-Tag: 0.9.30~1140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f585eaa4e75cb343b69054cea2fc9580821234ee;p=pakfire.git pty: Store events and add a description Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pty.c b/src/libpakfire/pty.c index 0d63d8bc3..7c503b9fa 100644 --- a/src/libpakfire/pty.c +++ b/src/libpakfire/pty.c @@ -50,6 +50,9 @@ struct pakfire_pty_stdio { PAKFIRE_PTY_READY_TO_READ = (1 << 0), PAKFIRE_PTY_READY_TO_WRITE = (1 << 1), } io; + + // Event Source + sd_event_source* event; }; struct pakfire_pty { @@ -375,17 +378,23 @@ static int pakfire_pty_setup_forwarding(struct pakfire_pty* pty) { return r; // Add standard input to the event loop - r = sd_event_add_io(pty->loop, NULL, + r = sd_event_add_io(pty->loop, &pty->stdin.event, pty->stdin.fd, EPOLLIN|EPOLLET, pakfire_pty_stdin, pty); if (r) return r; + // Set description + sd_event_source_set_description(pty->stdin.event, "pty-stdin"); + // Add standard output to the event loop - r = sd_event_add_io(pty->loop, NULL, + r = sd_event_add_io(pty->loop, &pty->stdout.event, pty->stdout.fd, EPOLLOUT|EPOLLET, pakfire_pty_stdout, pty); if (r) return r; + // Set description + sd_event_source_set_description(pty->stdout.event, "pty-stdout"); + return 0; } @@ -478,13 +487,16 @@ static int pakfire_pty_setup(sd_event_source* source, int fd, uint32_t events, v return r; // Add the master file descriptor to the event loop - r = sd_event_add_io(pty->loop, NULL, pty->master.fd, - EPOLLIN|EPOLLOUT|EPOLLET, pakfire_pty_master, pty); + r = sd_event_add_io(pty->loop, &pty->master.event, + pty->master.fd, EPOLLIN|EPOLLOUT|EPOLLET, pakfire_pty_master, pty); if (r < 0) { CTX_ERROR(pty->ctx, "Could not add the master file descriptor: %s\n", strerror(-r)); return r; } + // Set description + sd_event_source_set_description(pty->master.event, "pty-master"); + // Do we need to set up PTY forwarding? if (pty->flags & PAKFIRE_PTY_FORWARD) { r = pakfire_pty_setup_forwarding(pty); @@ -501,7 +513,12 @@ static void pakfire_pty_free(struct pakfire_pty* pty) { pakfire_pty_restore_attrs(pty, &pty->stdin); if (pty->stdout.fd >= 0) pakfire_pty_restore_attrs(pty, &pty->stdout); - + if (pty->master.event) + sd_event_source_unref(pty->master.event); + if (pty->stdin.event) + sd_event_source_unref(pty->stdin.event); + if (pty->stdout.event) + sd_event_source_unref(pty->stdout.event); if (pty->socket[0] >= 0) close(pty->socket[0]); if (pty->socket[1] >= 0)