On Feb 28 18:32, Takashi Yano wrote: > On Mon, 28 Feb 2022 10:21:32 +0100 > Corinna Vinschen wrote: > > Hi Takashi, > > > > On Feb 27 09:46, Takashi Yano wrote: > > > - 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. > > > [...] > > > --- 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, > > > > Is it really necessary to run the InterlockedCompareExchange in a loop? > > What about > > > > if (WFMO(..., 100) == WAIT_TIMEOUT) > > { > > InterlockedCompareExchange (&sigExeced, 0, prev_sigExeced); > > WFMO(..., INFINITE); > > } > > > > ? > > If non-cygwin app ignores Ctrl-C (like cmd.exe), and if > you hit Ctrl-C twice or more, sigExeced should be cleared > everytime on Ctrl-C. Your code clears sigExeced only once, > doesn't it?
Oh, ok. Then, please go ahead. Thanks, Corinna