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,
// 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;
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;
// 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));
// 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));