Mercurial > hg > octave-jordi
changeset 17865:dde06c2ac6c6
improve signal handling in driver program
* main.in.cc (caught_signal): New file-scope variable.
(gui_driver_sig_handler): Set caught_signal here instead of calling
kill to pass signal to child process.
(main): In parent, handle case of child exiting with an uncaught
signal and case of a signal caught in the parent that should be passed
on to the child.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 06 Nov 2013 18:00:48 -0500 |
parents | 674e5eb2c709 |
children | ea0ecbe2eaf5 |
files | src/main.in.cc |
diffstat | 1 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main.in.cc +++ b/src/main.in.cc @@ -118,11 +118,13 @@ static pid_t gui_pid = 0; +static int caught_signal = -1; + static void gui_driver_sig_handler (int sig) { if (gui_pid > 0) - kill (gui_pid, sig); + caught_signal = sig; } static sig_handler * @@ -483,14 +485,27 @@ int status; - while (1) + while (true) { WAITPID (gui_pid, &status, 0); - if (WIFEXITED (status)) + if (caught_signal > 0) { - retval = WIFEXITED (status) ? WEXITSTATUS (status) : 127; + int sig = caught_signal; + + caught_signal = -1; + kill (gui_pid, sig); + } + else if (WIFEXITED (status)) + { + retval = WEXITSTATUS (status); + break; + } + else if (WIFSIGNALLED (status)) + { + std::cerr << "octave exited with signal " + << WTERMSIG (status) << std::endl; break; } }