From 981c0eb8bc16c5ba69b3e3dce3e4dc860b82a9d6 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 3 Jun 2024 18:02:49 +0300 Subject: [PATCH] Shell: Only set terminal properties if STDIN is a TTY --- userspace/Shell/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/userspace/Shell/main.cpp b/userspace/Shell/main.cpp index 6b9c2171..feebfe41 100644 --- a/userspace/Shell/main.cpp +++ b/userspace/Shell/main.cpp @@ -612,7 +612,7 @@ pid_t execute_command_no_wait(BAN::Vector& args, int fd_in, int fd_ perror("setpgid"); exit(1); } - if (tcsetpgrp(0, getpgrp()) == -1) + if (isatty(0) && tcsetpgrp(0, getpgrp()) == -1) { perror("tcsetpgrp"); exit(1); @@ -644,7 +644,7 @@ int execute_command(BAN::Vector& args, int fd_in, int fd_out) if (waitpid(pid, &status, 0) == -1) ERROR_RETURN("waitpid", 1); - if (tcsetpgrp(0, getpgrp()) == -1) + if (isatty(0) && tcsetpgrp(0, getpgrp()) == -1) ERROR_RETURN("tcsetpgrp", 1); if (WIFSIGNALED(status)) @@ -722,7 +722,7 @@ int execute_piped_commands(BAN::Vector>& commands) exit_codes[i] = WEXITSTATUS(status); } - if (tcsetpgrp(0, getpgrp()) == -1) + if (isatty(0) && tcsetpgrp(0, getpgrp()) == -1) ERROR_RETURN("tcsetpgrp", 1); return exit_codes.back();