From da63ba04988e68bca1395eff60cc362ea14e3c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Sat, 18 Nov 2017 13:58:07 +0100 Subject: Restore tty attributes if interactive child is terminated by signal Some programs like su(1) do not restore tty attributes like ECHO when they are terminated by receiving SIGINT. Other shells (bash, mksh, zsh) save tty attributes before executing an external command and restore them if the child exited due to the receipt of a signal. rc now does the same if it is interactive. --- glom.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'glom.c') diff --git a/glom.c b/glom.c index 7f90d9d..e6a36e7 100644 --- a/glom.c +++ b/glom.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include static List *backq(Node *, Node *); static List *bqinput(List *, int); @@ -249,12 +251,15 @@ static List *backq(Node *ifs, Node *n) { int p[2], sp; pid_t pid; List *bq; + struct termios t; if (n == NULL) return NULL; if (pipe(p) < 0) { uerror("pipe"); rc_error(NULL); } + if (interactive) + tcgetattr(0, &t); if ((pid = rc_fork()) == 0) { mvfd(p[1], 1); close(p[0]); @@ -266,6 +271,8 @@ static List *backq(Node *ifs, Node *n) { bq = bqinput(glom(ifs), p[0]); close(p[0]); rc_wait4(pid, &sp, TRUE); + if (interactive && WIFSIGNALED(sp)) + tcsetattr(0, TCSANOW, &t); setstatus(-1, sp); varassign("bqstatus", word(strstatus(sp), NULL), FALSE); sigchk(); -- cgit v1.2.3