From: Michael Tremer Date: Sat, 12 Oct 2024 12:34:11 +0000 (+0000) Subject: pty: Explicitely request to connect stdin/stdout X-Git-Tag: 0.9.30~1091 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5698cc7d8911d4e4f19cfbe6af4e02f46fd57d42;p=pakfire.git pty: Explicitely request to connect stdin/stdout Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/pty.h b/src/libpakfire/include/pakfire/pty.h index 6662d9db4..e1c8355e9 100644 --- a/src/libpakfire/include/pakfire/pty.h +++ b/src/libpakfire/include/pakfire/pty.h @@ -30,8 +30,10 @@ struct pakfire_pty; enum pakfire_pty_flags { - PAKFIRE_PTY_READ_ONLY = (1 << 0), - PAKFIRE_PTY_CAPTURE_OUTPUT = (1 << 1), + PAKFIRE_PTY_CONNECT_STDIN = (1 << 0), + PAKFIRE_PTY_CONNECT_STDOUT = (1 << 1), + PAKFIRE_PTY_INTERACTIVE = PAKFIRE_PTY_CONNECT_STDIN|PAKFIRE_PTY_CONNECT_STDOUT, + PAKFIRE_PTY_CAPTURE_OUTPUT = (1 << 2), }; int pakfire_pty_create(struct pakfire_pty** pty, diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index d48f08b66..c6c0d6b9e 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -1462,6 +1462,9 @@ PAKFIRE_EXPORT int pakfire_jail_exec(struct pakfire_jail* jail, // Are we running in interactive mode? if (pakfire_jail_exec_has_flag(&ctx, PAKFIRE_JAIL_INTERACTIVE)) { + // Make the PTY interactive + pty_flags |= PAKFIRE_PTY_INTERACTIVE; + // Enable networking ctx.flags |= PAKFIRE_JAIL_HAS_NETWORKING; @@ -1471,11 +1474,7 @@ PAKFIRE_EXPORT int pakfire_jail_exec(struct pakfire_jail* jail, r = -ENOTSUP; goto ERROR; } - } else { - // Make the PTY read-only - pty_flags |= PAKFIRE_PTY_READ_ONLY; - // Capture Output? if (output) pty_flags |= PAKFIRE_PTY_CAPTURE_OUTPUT; diff --git a/src/libpakfire/pty.c b/src/libpakfire/pty.c index 806266ed8..21961a47e 100644 --- a/src/libpakfire/pty.c +++ b/src/libpakfire/pty.c @@ -757,16 +757,8 @@ static int pakfire_pty_setup_forwarding(struct pakfire_pty* pty) { // Mark as forwarding pty->state = PAKFIRE_PTY_STATE_FORWARDING; - // Do nothing if we are in read-only mode - if (pakfire_pty_has_flag(pty, PAKFIRE_PTY_READ_ONLY)) { - // Nothing - - // Do nothing if we have a callback set - } else if (pty->stdin.callbacks.stdin_callback) { - // Nothing - // Connect to standard input - } else { + if (pty->flags & PAKFIRE_PTY_CONNECT_STDIN) { pty->stdin.fd = pakfire_pty_reopen(pty, STDIN_FILENO, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK); if (pty->stdin.fd < 0) { CTX_DEBUG(pty->ctx, "Could not re-open standard input: %s. Ignoring.\n", strerror(-pty->stdin.fd)); @@ -791,12 +783,8 @@ static int pakfire_pty_setup_forwarding(struct pakfire_pty* pty) { // Close the buffer in the end pty->stdout.close_fd = 1; - // Do nothing if we have a callback set - } else if (pty->stdout.callbacks.stdout_callback) { - // Nothing - // Connect to standard output - } else { + } else if (pty->flags & PAKFIRE_PTY_CONNECT_STDOUT) { pty->stdout.fd = pakfire_pty_reopen(pty, STDOUT_FILENO, O_WRONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK); if (pty->stdout.fd < 0) { CTX_DEBUG(pty->ctx, "Could not re-open standard output: %s. Ignoring.\n", strerror(-pty->stdout.fd));