]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Don't open standard input in read-only mode
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Oct 2024 14:12:13 +0000 (14:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Oct 2024 14:12:13 +0000 (14:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/pty.h
src/libpakfire/pty.c

index 9b705124437be5e703fca083fd230453749e0bcc..3efa97a9481e18545fb5358031b4b6bf92a4c1e7 100644 (file)
 
 struct pakfire_pty;
 
+enum pakfire_pty_flags {
+       PAKFIRE_PTY_READ_ONLY = (1 << 0),
+};
+
 int pakfire_pty_create(struct pakfire_pty** pty,
        struct pakfire_ctx* ctx, sd_event* loop, int flags);
 
index c7b4bfb60b1166d085d931bd35c8a86859d15ce7..90c76dcc0f8ba8aee09a187a8226b79980546937 100644 (file)
@@ -90,6 +90,10 @@ struct pakfire_pty {
        } state;
 };
 
+static int pakfire_pty_has_flag(struct pakfire_pty* pty, int flag) {
+       return pty->flags & flag;
+}
+
 static int pakfire_pty_restore_attrs(struct pakfire_pty* pty,
                struct pakfire_pty_stdio* stdio) {
        int r;
@@ -502,25 +506,28 @@ static int pakfire_pty_setup_forwarding(struct pakfire_pty* pty) {
                }
        }
 
-       // Enable RAW mode on standard input
-       r = pakfire_pty_enable_raw_mode(pty, &pty->stdin);
-       if (r)
-               return r;
+       // Connect standard input unless we are in read-only mode
+       if (!pakfire_pty_has_flag(pty, PAKFIRE_PTY_READ_ONLY)) {
+               // Enable RAW mode on standard input
+               r = pakfire_pty_enable_raw_mode(pty, &pty->stdin);
+               if (r)
+                       return r;
+
+               // Add standard input to the event loop
+               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");
+       }
 
        // Enable RAW mode on standard output
        r = pakfire_pty_enable_raw_mode(pty, &pty->stdout);
        if (r)
                return r;
 
-       // Add standard input to the event loop
-       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, &pty->stdout.event,
                        pty->stdout.fd, EPOLLOUT|EPOLLET, pakfire_pty_stdout, pty);