From 98863541c3130192c10031559a3989ec21a1e530 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 3 Nov 2016 19:42:25 -0700 Subject: [PATCH] lint: prefer early exits and continue Fix a location I missed in my earlier cleanup regarding early exits. --- src/proc.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/proc.cpp b/src/proc.cpp index d2ef46757..42850f6b7 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -318,26 +318,29 @@ static void handle_child_status(pid_t pid, int status) { } } - if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGQUIT)) { - if (!is_interactive_session) { - struct sigaction act; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler = SIG_DFL; - sigaction(SIGINT, &act, 0); - sigaction(SIGQUIT, &act, 0); - kill(getpid(), WTERMSIG(status)); - } else { - // In an interactive session, tell the principal parser to skip all blocks we're - // executing so control-C returns control to the user. - if (p && found_proc) { - parser_t::skip_all_blocks(); - } - } + // If the child process was not killed by a signal or other than SIGINT or SIGQUIT we're done. + if (!WIFSIGNALED(status) || (WTERMSIG(status) != SIGINT && WTERMSIG(status) != SIGQUIT)) { + return; + } + + if (is_interactive_session) { + // In an interactive session, tell the principal parser to skip all blocks we're executing + // so control-C returns control to the user. + if (p && found_proc) parser_t::skip_all_blocks(); + } else { + // Deliver the SIGINT or SIGQUIT signal to ourself since we're not interactive. + struct sigaction act; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + act.sa_handler = SIG_DFL; + sigaction(SIGINT, &act, 0); + sigaction(SIGQUIT, &act, 0); + kill(getpid(), WTERMSIG(status)); } #if 0 - // TODO: decide whether to eliminate this block or have it emit a warning message. + // TODO: Decide whether to eliminate this block or have it emit a warning message. + // WARNING: See the special short-circuit logic above vis-a-vis signals. if (!found_proc) { // A child we lost track of? There have been bugs in both subshell handling and in builtin // handling that have caused this previously...