struct pakfire_pty_stdio {
// File Descriptor
int fd;
+ unsigned close_fd:1;
// Buffer
char buffer[64 * 1024];
}
// Close the file descriptor
- close(stdio->fd);
+ if (stdio->close_fd)
+ close(stdio->fd);
+
stdio->fd = -1;
return 0;
if (!pakfire_pty_has_flag(pty, PAKFIRE_PTY_READ_ONLY)) {
pty->stdin.fd = pakfire_pty_reopen(pty, STDIN_FILENO, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (pty->stdin.fd < 0) {
- CTX_ERROR(pty->ctx, "Could not re-open standard input: %s\n", strerror(-pty->stdin.fd));
- return -pty->stdin.fd;
+ CTX_DEBUG(pty->ctx, "Could not re-open standard input: %s. Ignoring.\n", strerror(-pty->stdin.fd));
+
+ // Use the original file descriptor
+ pty->stdin.fd = STDIN_FILENO;
+
+ // Request to close the file descriptor afterwards
+ } else {
+ pty->stdin.close_fd = 1;
}
}
// Connect to standard output
pty->stdout.fd = pakfire_pty_reopen(pty, STDOUT_FILENO, O_WRONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (pty->stdout.fd < 0) {
- CTX_ERROR(pty->ctx, "Could not re-open standard output: %s\n", strerror(-pty->stdout.fd));
- return -pty->stdout.fd;
+ CTX_DEBUG(pty->ctx, "Could not re-open standard output: %s. Ignoring.\n", strerror(-pty->stdout.fd));
+
+ // Use the original file descriptor
+ pty->stdout.fd = STDOUT_FILENO;
+
+ // Request to close the file descriptor afterwards
+ } else {
+ pty->stdout.close_fd = 1;
}
// Copy the terminal dimensions to the PTY