return NULL;
}
+static int pakfire_pty_connect_null(struct pakfire_pty* pty) {
+ int fd = -EBADF;
+ int r;
+
+ // Open /dev/null
+ fd = open("/dev/null", O_RDONLY);
+ if (fd < 0) {
+ ERROR(pty->ctx, "Failed to open /dev/null: %m\n");
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Copy to the desired file descriptor
+ r = dup2(fd, STDIN_FILENO);
+ if (r < 0) {
+ ERROR(pty->ctx, "Failed to duplicate the file descriptor: %m\n");
+ r = -errno;
+ goto ERROR;
+ }
+
+ERROR:
+ if (fd >= 0)
+ close(fd);
+
+ return r;
+}
+
/*
Sets up the terminal in the child process...
*/
DEBUG(pty->ctx, "Opened a new terminal %d\n", fd);
// Connect the new terminal to standard input
- r = dup2(fd, STDIN_FILENO);
- if (r < 0) {
- ERROR(pty->ctx, "Failed to open standard input: %s\n", strerror(errno));
- r = -errno;
- goto ERROR;
+ if (pakfire_pty_has_flag(pty, PAKFIRE_PTY_CONNECT_STDIN)) {
+ r = dup2(fd, STDIN_FILENO);
+ if (r < 0) {
+ ERROR(pty->ctx, "Failed to open standard input: %s\n", strerror(errno));
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Otherwise we connect standard input to /dev/null
+ } else {
+ r = pakfire_pty_connect_null(pty);
+ if (r < 0)
+ goto ERROR;
}
// Connect the new terminal to standard output