From 327d65f7be9ef32b48fafa66aa58835115a91c95 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 24 Feb 2020 02:50:39 -0800 Subject: [PATCH] Don't close and reopen tty files when running scripts. --- bb.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/bb.c b/bb.c index 9f81830..af06a4d 100644 --- a/bb.c +++ b/bb.c @@ -896,8 +896,6 @@ int run_script(bb_t *bb, const char *cmd) proc_t *proc = memcheck(calloc(1, sizeof(proc_t))); signal(SIGTTOU, SIG_IGN); if ((proc->pid = fork()) == 0) { - fclose(tty_out); tty_out = NULL; - fclose(tty_in); tty_in = NULL; pid_t pgrp = getpid(); (void)setpgid(0, pgrp); if (tcsetpgrp(STDIN_FILENO, pgrp)) @@ -916,11 +914,8 @@ int run_script(bb_t *bb, const char *cmd) setenv("BBCURSOR", bb->nfiles ? bb->files[bb->cursor]->fullname : "", 1); - int ttyout, ttyin; - ttyout = open("/dev/tty", O_RDWR); - ttyin = open("/dev/tty", O_RDONLY); - dup2(ttyout, STDOUT_FILENO); - dup2(ttyin, STDIN_FILENO); + dup2(fileno(tty_out), STDOUT_FILENO); + dup2(fileno(tty_in), STDIN_FILENO); execvp(args[0], args); err("Failed to execute command: '%s'", cmd); return -1;