From b6da2c3fa5b62d73d6e8262498d81952d5a71874 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 11 Mar 2014 11:01:00 +0100 Subject: [PATCH] core: fix detection of terminated process in hook_process Check if the process is finished, even if stdout/stderr are not closed. Moreover, if the process was terminated by a signal, the return code is set to WEECHAT_HOOK_PROCESS_ERROR. --- ChangeLog.asciidoc | 1 + src/core/wee-hook.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index a5469b81a..8819c5b9a 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -15,6 +15,7 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] == Version 0.4.4 (under dev) +* core: fix detection of terminated process in hook_process * core: set option weechat.look.buffer_search_where to prefix_message by default * core: fix "/window scroll -N" on a buffer with free content * core: add option weechat.look.hotlist_add_conditions, remove option diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 04c2affef..bbc6b055b 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -1720,15 +1720,23 @@ hook_process_timer_cb (void *arg_hook_process, int remaining_calls) } else { - if (!HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDOUT]) - && !HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDERR])) + if (waitpid (HOOK_PROCESS(hook_process, child_pid), + &status, WNOHANG) > 0) { - if (waitpid (HOOK_PROCESS(hook_process, child_pid), &status, WNOHANG) > 0) + if (WIFEXITED(status)) { + /* child terminated normally */ rc = WEXITSTATUS(status); hook_process_send_buffers (hook_process, rc); unhook (hook_process); } + else if (WIFSIGNALED(status)) + { + /* child terminated by a signal */ + hook_process_send_buffers (hook_process, + WEECHAT_HOOK_PROCESS_ERROR); + unhook (hook_process); + } } }