diff options
author | Takashi Yano <takashi.yano@nifty.ne.jp> | 2022-02-26 09:13:13 +0300 |
---|---|---|
committer | Takashi Yano <takashi.yano@nifty.ne.jp> | 2022-02-28 14:10:02 +0300 |
commit | f6db6f52aeec3a326a216530978ce8a4bea25cf0 (patch) | |
tree | 19bff664bf11cb10512f4b363bdef5068abe0d44 /winsup/cygwin/spawn.cc | |
parent | 15a35758d8490368fedfe595246b100c7af59a11 (diff) |
Cygwin: pinfo: Fix exit code for non-cygwin apps which reads console.
- The recent commit "Cygwin: pinfo: Fix exit code when non-cygwin app
exits by Ctrl-C." did not fix enough the issue. If a non-cygwin app
is reading the console, it will not return STATUS_CONTROL_C_EXIT
even if it is terminated by Ctrl-C. As a result, the previous patch
does not take effect.
This patch solves this issue by setting sigExeced to SIGINT in
ctrl_c_handler(). In addition, sigExeced will be cleared if the app
does not terminated within predetermined time period. The reason is
that the app does not seem to be terminated by the signal sigExeced.
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r-- | winsup/cygwin/spawn.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 3647580a6..3b54309a2 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -953,7 +953,15 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, if (sem) __posix_spawn_sem_release (sem, 0); if (ptys_need_cleanup || cons_need_cleanup) - WaitForSingleObject (pi.hProcess, INFINITE); + { + LONG prev_sigExeced = sigExeced; + while (WaitForSingleObject (pi.hProcess, 100) == WAIT_TIMEOUT) + /* If child process does not exit in predetermined time + period, the process does not seem to be terminated by + the signal sigExeced. Therefore, clear sigExeced here. */ + prev_sigExeced = + InterlockedCompareExchange (&sigExeced, 0, prev_sigExeced); + } if (ptys_need_cleanup) { fhandler_pty_slave::cleanup_for_non_cygwin_app (&ptys_handle_set, @@ -966,6 +974,11 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, fhandler_console::cleanup_for_non_cygwin_app (&cons_handle_set); fhandler_console::close_handle_set (&cons_handle_set); } + /* Make sure that ctrl_c_handler() is not on going. Calling + init_console_handler(false) locks until returning from + ctrl_c_handler(). This insures that setting sigExeced + on Ctrl-C key has been completed. */ + init_console_handler (false); myself.exit (EXITCODE_NOSET); break; case _P_WAIT: |