]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Create its own type
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 14:39:07 +0000 (14:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 14:39:07 +0000 (14:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/jail.c
src/pakfire/pty.c
src/pakfire/pty.h

index 13c3a34b1d379dfb05a8adbc4f2069b3aacab3d5..2ac7bfa088b10c0791c634cea9ecb4bf2c84ae2d 100644 (file)
@@ -129,7 +129,7 @@ typedef struct pakfire_jail_exec {
        int completed_fd;
 
        // PTY
-       struct pakfire_pty* pty;
+       pakfire_pty* pty;
 
        // Pipes
        struct pakfire_jail_pipes {
index 46819e1e97a22404ff7793e37056c8b133ba2033..91e773a4465267375ec27e9485653da47fdc21e1 100644 (file)
@@ -39,7 +39,7 @@
 
 #define MAX_LINE_LENGTH 16384
 
-struct pakfire_pty_stdio {
+typedef struct pakfire_pty_stdio {
        // File Descriptor
        int fd;
        unsigned close_fd:1;
@@ -60,7 +60,7 @@ struct pakfire_pty_stdio {
 
        // Event Source
        sd_event_source* event;
-};
+} pakfire_pty_stdio;
 
 struct pakfire_pty {
        pakfire_ctx* ctx;
@@ -73,14 +73,14 @@ struct pakfire_pty {
        int socket[2];
 
        // The master PTY
-       struct pakfire_pty_stdio master;
+       pakfire_pty_stdio master;
 
        // The path to the PTY
        char path[PATH_MAX];
 
        // Standard Input
-       struct pakfire_pty_stdio stdin;
-       struct pakfire_pty_stdio stdout;
+       pakfire_pty_stdio stdin;
+       pakfire_pty_stdio stdout;
 
        // SIGWINCH Event
        sd_event_source* sigwinch_event;
@@ -97,7 +97,7 @@ struct pakfire_pty {
        } state;
 };
 
-static int pakfire_pty_same_inode(struct pakfire_pty* pty, int fd1, int fd2) {
+static int pakfire_pty_same_inode(pakfire_pty* pty, int fd1, int fd2) {
        struct stat stat1;
        struct stat stat2;
        int r;
@@ -128,8 +128,8 @@ static int pakfire_pty_same_inode(struct pakfire_pty* pty, int fd1, int fd2) {
        return (stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino);
 }
 
-static int pakfire_pty_restore_attrs(struct pakfire_pty* pty,
-               struct pakfire_pty_stdio* stdio) {
+static int pakfire_pty_restore_attrs(pakfire_pty* pty,
+               pakfire_pty_stdio* stdio) {
        int flags;
        int r;
 
@@ -172,8 +172,8 @@ static int pakfire_pty_restore_attrs(struct pakfire_pty* pty,
        return 0;
 }
 
-static int pakfire_pty_store_attrs(struct pakfire_pty* pty,
-               struct pakfire_pty_stdio* stdio) {
+static int pakfire_pty_store_attrs(pakfire_pty* pty,
+               pakfire_pty_stdio* stdio) {
        int r;
 
        // Store all attributes
@@ -197,7 +197,7 @@ static int pakfire_pty_store_attrs(struct pakfire_pty* pty,
        return 0;
 }
 
-static int pakfire_pty_disconnect(struct pakfire_pty* pty) {
+static int pakfire_pty_disconnect(pakfire_pty* pty) {
        DEBUG(pty->ctx, "Disconnecting the PTY\n");
 
        // Clear events
@@ -223,7 +223,7 @@ static int pakfire_pty_disconnect(struct pakfire_pty* pty) {
        return 0;
 }
 
-static int pakfire_pty_drained(struct pakfire_pty* pty) {
+static int pakfire_pty_drained(pakfire_pty* pty) {
        int q;
        int r;
 
@@ -265,7 +265,7 @@ static int pakfire_pty_drained(struct pakfire_pty* pty) {
        return 1;
 }
 
-static int pakfire_pty_done(struct pakfire_pty* pty, int code) {
+static int pakfire_pty_done(pakfire_pty* pty, int code) {
        // Don't run this more than once
        if (pty->state == PAKFIRE_PTY_STATE_DONE)
                return 0;
@@ -288,7 +288,7 @@ static int pakfire_pty_done(struct pakfire_pty* pty, int code) {
 /*
        This function handles the forwarding between the different pipes...
 */
-static int pakfire_pty_forward(struct pakfire_pty* pty) {
+static int pakfire_pty_forward(pakfire_pty* pty) {
        int did_something;
        int r;
 
@@ -529,7 +529,7 @@ ERROR:
        Forwards any window size changes.
 */
 static int pakfire_pty_SIGWINCH(sd_event_source* source, const struct signalfd_siginfo* si, void* data) {
-       struct pakfire_pty* pty = data;
+       pakfire_pty* pty = data;
        struct winsize size;
        int r;
 
@@ -550,7 +550,7 @@ static int pakfire_pty_SIGWINCH(sd_event_source* source, const struct signalfd_s
        return 0;
 }
 
-static int pakfire_pty_drain(struct pakfire_pty* pty) {
+static int pakfire_pty_drain(pakfire_pty* pty) {
        // Log action
        DEBUG(pty->ctx, "Draining requested\n");
 
@@ -561,7 +561,7 @@ static int pakfire_pty_drain(struct pakfire_pty* pty) {
 }
 
 static int pakfire_pty_exit(sd_event_source* source, void* data) {
-       struct pakfire_pty* self = data;
+       pakfire_pty* self = data;
        int r;
 
        DEBUG(self->ctx, "Exiting the PTY...\n");
@@ -586,7 +586,7 @@ static int pakfire_pty_exit(sd_event_source* source, void* data) {
        return pakfire_pty_done(self, 0);
 }
 
-static int pakfire_pty_activity(struct pakfire_pty* pty, struct pakfire_pty_stdio* stdio, uint32_t events) {
+static int pakfire_pty_activity(pakfire_pty* pty, pakfire_pty_stdio* stdio, uint32_t events) {
        // Do we have data to read?
        if (events & (EPOLLIN|EPOLLHUP))
                stdio->io |= PAKFIRE_PTY_READY_TO_READ;
@@ -603,19 +603,19 @@ static int pakfire_pty_activity(struct pakfire_pty* pty, struct pakfire_pty_stdi
 }
 
 static int pakfire_pty_master(sd_event_source* source, int fd, uint32_t events, void* data) {
-       struct pakfire_pty* pty = data;
+       pakfire_pty* pty = data;
 
        return pakfire_pty_activity(pty, &pty->master, events);
 }
 
 static int pakfire_pty_stdin(sd_event_source* source, int fd, uint32_t events, void* data) {
-       struct pakfire_pty* pty = data;
+       pakfire_pty* pty = data;
 
        return pakfire_pty_activity(pty, &pty->stdin, events);
 }
 
 static int pakfire_pty_stdout(sd_event_source* source, int fd, uint32_t events, void* data) {
-       struct pakfire_pty* pty = data;
+       pakfire_pty* pty = data;
 
        return pakfire_pty_activity(pty, &pty->stdout, events);
 }
@@ -696,7 +696,7 @@ static void pakfire_pty_make_raw(struct termios* termios) {
        );
 }
 
-static int pakfire_pty_enable_raw_mode(struct pakfire_pty* pty) {
+static int pakfire_pty_enable_raw_mode(pakfire_pty* pty) {
        struct termios raw_attrs;
        int same;
        int r;
@@ -761,7 +761,7 @@ static int pakfire_pty_enable_raw_mode(struct pakfire_pty* pty) {
        return 0;
 }
 
-static int pakfire_pty_reopen(struct pakfire_pty* pty, int fd, int flags) {
+static int pakfire_pty_reopen(pakfire_pty* pty, int fd, int flags) {
        char path[PATH_MAX];
        int existing_flags;
        off_t offset;
@@ -803,7 +803,7 @@ static int pakfire_pty_reopen(struct pakfire_pty* pty, int fd, int flags) {
 /*
        Sets up PTY forwarding...
 */
-static int pakfire_pty_setup_forwarding(struct pakfire_pty* pty) {
+static int pakfire_pty_setup_forwarding(pakfire_pty* pty) {
        struct winsize size;
        int r;
 
@@ -899,7 +899,7 @@ static int pakfire_pty_setup_forwarding(struct pakfire_pty* pty) {
 /*
        Sends the master file descriptor to the parent process...
 */
-static int pakfire_pty_send_master(struct pakfire_pty* pty) {
+static int pakfire_pty_send_master(pakfire_pty* pty) {
        const size_t payload_length = sizeof(pty->master.fd);
        char buffer[CMSG_SPACE(payload_length)];
        int r;
@@ -938,7 +938,7 @@ static int pakfire_pty_send_master(struct pakfire_pty* pty) {
 /*
        Received the master file descriptor from the child process...
 */
-static int pakfire_pty_recv_master(struct pakfire_pty* pty) {
+static int pakfire_pty_recv_master(pakfire_pty* pty) {
        const size_t payload_length = sizeof(pty->master.fd);
        char buffer[CMSG_SPACE(payload_length)];
        int r;
@@ -976,7 +976,7 @@ static int pakfire_pty_recv_master(struct pakfire_pty* pty) {
        Called when the master socket is being received from the child process.
 */
 static int pakfire_pty_setup(sd_event_source* source, int fd, uint32_t events, void* data) {
-       struct pakfire_pty* pty = data;
+       pakfire_pty* pty = data;
        int r;
 
        // Receive the master file descriptor
@@ -1018,7 +1018,7 @@ static int pakfire_pty_setup(sd_event_source* source, int fd, uint32_t events, v
        return 0;
 }
 
-static void pakfire_pty_free(struct pakfire_pty* pty) {
+static void pakfire_pty_free(pakfire_pty* pty) {
        pakfire_pty_disconnect(pty);
 
        if (pty->socket[0] >= 0)
@@ -1040,8 +1040,8 @@ static void pakfire_pty_free(struct pakfire_pty* pty) {
        free(pty);
 }
 
-int pakfire_pty_create(struct pakfire_pty** pty, pakfire_ctx* ctx, sd_event* loop) {
-       struct pakfire_pty* p = NULL;
+int pakfire_pty_create(pakfire_pty** pty, pakfire_ctx* ctx, sd_event* loop) {
+       pakfire_pty* p = NULL;
        int r;
 
        // Allocate a new object
@@ -1098,13 +1098,13 @@ ERROR:
        return r;
 }
 
-struct pakfire_pty* pakfire_pty_ref(struct pakfire_pty* pty) {
+pakfire_pty* pakfire_pty_ref(pakfire_pty* pty) {
        ++pty->nrefs;
 
        return pty;
 }
 
-struct pakfire_pty* pakfire_pty_unref(struct pakfire_pty* pty) {
+pakfire_pty* pakfire_pty_unref(pakfire_pty* pty) {
        if (--pty->nrefs > 0)
                return pty;
 
@@ -1115,7 +1115,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) {
+static int pakfire_pty_setup_terminal(pakfire_pty* pty) {
        int fd = -EBADF;
        int r;
 
@@ -1163,7 +1163,7 @@ ERROR:
 /*
        Allocates a new PTY and must be called from the child process...
 */
-int pakfire_pty_open(struct pakfire_pty* pty) {
+int pakfire_pty_open(pakfire_pty* pty) {
        int r;
 
        // Allocate a new PTY
index c4653f2aeace0fe7383b7a64f9bfe4d0c5131f75..ef485661d6eb2f38548dcfcced5ec16115641ed2 100644 (file)
 #include <systemd/sd-event.h>
 
 #include <pakfire/ctx.h>
-#include <pakfire/filelist.h>
-#include <pakfire/log_stream.h>
 
-struct pakfire_pty;
+typedef struct pakfire_pty pakfire_pty;
 
-int pakfire_pty_create(struct pakfire_pty** pty, pakfire_ctx* ctx, sd_event* loop);
+int pakfire_pty_create(pakfire_pty** pty, pakfire_ctx* ctx, sd_event* loop);
 
-struct pakfire_pty* pakfire_pty_ref(struct pakfire_pty* pty);
-struct pakfire_pty* pakfire_pty_unref(struct pakfire_pty* pty);
+pakfire_pty* pakfire_pty_ref(pakfire_pty* pty);
+pakfire_pty* pakfire_pty_unref(pakfire_pty* pty);
 
-int pakfire_pty_open(struct pakfire_pty* pty);
+int pakfire_pty_open(pakfire_pty* pty);
 
 #endif /* PAKFIRE_PTY_H */