]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Store events and add a description
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Oct 2024 12:47:34 +0000 (12:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Oct 2024 12:47:34 +0000 (12:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pty.c

index 0d63d8bc3599c7eb579b1c533de8a80621dff605..7c503b9fa1d0f5053f1de4d9fd38161a3aaff745 100644 (file)
@@ -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)