From f22f4556c2260868561dfdc95a7a98a648840655 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sat, 1 Dec 2018 11:39:59 +0900 Subject: [PATCH] esh: exit subshells on SIGINT --- apps/sh.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/sh.c b/apps/sh.c index e7137696..7ed36403 100644 --- a/apps/sh.c +++ b/apps/sh.c @@ -352,8 +352,13 @@ hashmap_t * job_hash = NULL; void sig_break_loop(int sig) { /* Interrupt handler */ - break_while = sig; - signal(sig, sig_break_loop); + if ((shell_interactive == 1 && !is_subshell)) { + break_while = sig; + signal(sig, sig_break_loop); + } else { + signal(sig, SIG_DFL); + raise(sig); + } } void redraw_prompt_func(rline_context_t * context) { @@ -1854,6 +1859,10 @@ uint32_t shell_cmd_while(int argc, char * argv[]) { } do { pid = waitpid(child_pid, &ret_code, 0); + if (pid != -1 && WIFSIGNALED(ret_code)) { + int sig = WTERMSIG(ret_code); + if (sig == SIGINT) return 127; /* break */ + } } while (pid != -1 || (pid == -1 && errno != ECHILD)); } else { reset_pgrp();