[PATCH v2] Cygwin: pinfo: Fix exit code for non-cygwin apps which reads console.

Corinna Vinschen corinna-cygwin@cygwin.com
Mon Feb 28 09:21:32 GMT 2022


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);
    }

?


Corinna


More information about the Cygwin-patches mailing list