From: Michael Tremer Date: Sun, 6 Oct 2024 14:12:13 +0000 (+0000) Subject: pty: Don't open standard input in read-only mode X-Git-Tag: 0.9.30~1134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb821eda7efab70359dbac038cb0b2440aef63af;p=pakfire.git pty: Don't open standard input in read-only mode Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/pty.h b/src/libpakfire/include/pakfire/pty.h index 9b7051244..3efa97a94 100644 --- a/src/libpakfire/include/pakfire/pty.h +++ b/src/libpakfire/include/pakfire/pty.h @@ -29,6 +29,10 @@ 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); diff --git a/src/libpakfire/pty.c b/src/libpakfire/pty.c index c7b4bfb60..90c76dcc0 100644 --- a/src/libpakfire/pty.c +++ b/src/libpakfire/pty.c @@ -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);