]> git.ipfire.org Git - pakfire.git/commitdiff
pty: Explicitely request to connect stdin/stdout
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 12:34:11 +0000 (12:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 12:34:11 +0000 (12:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/pty.h
src/libpakfire/jail.c
src/libpakfire/pty.c

index 6662d9db4a562e4c77ba6cbf0f105d39c44c232f..e1c8355e9cf9bfc8776d838fdc087556e3116aa9 100644 (file)
 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,
index d48f08b6656e4d8a678d7e7c7c2b57cbf770ea94..c6c0d6b9e4c2b922854ff467b74e0030e7f1d82f 100644 (file)
@@ -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;
index 806266ed8bc4023a6ae5fbaeb7d49368432ee544..21961a47e3516d05e48a4f1ee950d106c8396021 100644 (file)
@@ -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));