From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH v2] Cygwin: pinfo: Fix exit code for non-cygwin apps which reads console.
Date: Mon, 28 Feb 2022 10:44:51 +0100 [thread overview]
Message-ID: <YhyZk1JonIErhPal@calimero.vinschen.de> (raw)
In-Reply-To: <20220228183202.9236c4f2bbeacb65a816be64@nifty.ne.jp>
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
prev parent reply other threads:[~2022-02-28 9:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-27 0:46 Takashi Yano
2022-02-28 9:21 ` Corinna Vinschen
2022-02-28 9:32 ` Takashi Yano
2022-02-28 9:44 ` Corinna Vinschen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YhyZk1JonIErhPal@calimero.vinschen.de \
--to=corinna-cygwin@cygwin.com \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).