public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: cygwin-2 process handling
Date: Wed, 27 May 2015 12:39:00 -0000	[thread overview]
Message-ID: <20150527122312.GF16927@calimero.vinschen.de> (raw)
In-Reply-To: <20150521205357.2c125b3bcaf877d0843b52b1@nifty.ne.jp>

[-- Attachment #1: Type: text/plain, Size: 2044 bytes --]

Hi Takashi,

On May 21 20:53, Takashi Yano wrote:
> [...]
> I was looking into this problem, and found the PeekNamedPipe()
> call is blocked in fhandler_pty_master::close() when the problem
> occurs.
> 
> I had not noticed that, 
> 
> https://msdn.microsoft.com/en-us/library/windows/desktop/aa365779(v=vs.85).aspx
> 
> says:
> > The PeekNamedPipe function can block thread execution the same
> > way any I/O function can when called on a synchronous handle in
> > a multi-threaded application.
> 
> I have made a patch attached to resolve this problem. Please have
> a look.
> 
> With this patch, NtQueryObject() is used instead of PeekNamedPipe()
> to detect closure of the last master handle.
> 
> Please refer to the following discussion for more details.
> http://cygwin.com/ml/cygwin/2015-03/msg00221.html
> 
> 
> ChageLog is as follows.
> 
> 2015-05-21  Takashi Yano  <...>
> 
> 	* fhandler_tty.cc (fhandler_pty_master::close): Use NtQueryObject()
> 	instead of PeekNamedPipe() to detect closing the last master handle.
> [...]
> +  if (output_handle_local)
> +    {
> +      OBJECT_BASIC_INFORMATION obi;
> +      NTSTATUS status;
> +      ULONG hdl_cnt = 0;
> +
> +      status = NtQueryObject (output_handle_local, ObjectBasicInformation,
> +	  &obi, sizeof obi, NULL);
> +      if (!NT_SUCCESS (status))
> +	debug_printf ("NtQueryObject: %y", status);
> +      else
> +	hdl_cnt = obi.HandleCount;
> +      termios_printf("HandleCount: %d", hdl_cnt);
> +      if (hdl_cnt == 1)
> +	SetEvent (input_available_event);
> +      CloseHandle (output_handle_local);
> +    }
 
Isn't that racy?  Consider two processes doing that at the same time.
Both calls to NtQueryObject could come up with hdl_cnt == 2 and the
problem persists.

Wouldn't it be safer to call SetEvent(input_available_event) all the
time from here?


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2015-05-27 12:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-18 19:18 Michael Mauger
2015-05-19 17:36 ` Ken Brown
2015-05-20  1:19   ` Ken Brown
2015-05-21 12:13     ` Takashi Yano
2015-05-21 15:50       ` Ken Brown
2015-05-27 12:39       ` Corinna Vinschen [this message]
2015-05-27 15:57         ` Corinna Vinschen
2015-05-28 11:48           ` Corinna Vinschen
2015-05-28 12:44             ` Takashi Yano
2015-05-28 14:16               ` Takashi Yano
2015-05-28 15:53                 ` Corinna Vinschen
2015-06-07  0:03                   ` cygwin-2 process handling (about SIGHUP) Takashi Yano
2015-06-08 12:09                     ` Corinna Vinschen
2015-06-08 13:50                       ` Marco Atzeri
2015-06-08 14:18                         ` Corinna Vinschen
2015-05-28 12:09           ` cygwin-2 process handling Takashi Yano
2015-05-22 17:34 Michael Mauger

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=20150527122312.GF16927@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@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).