This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v5 1/1] Cygwin: pty: add pseudo console support.


On Apr 16 09:41, Takashi Yano wrote:
> On Mon, 15 Apr 2019 10:38:32 +0200 Corinna Vinschen wrote:
> > This is supposed to be combined with the preceeding code to a single
> > expression in the end, right?
> 
> Do you mean this code and the preceding code should be executed
> exclusively? If so, the answer is no. If the stderr is pty slave,
> the message should be written to both output_handle and
> output_handle_cyg. The reason will be described later.
> 
> > I don't quite understand why writing
> > to STD_ERROR_HANDLE doesn't work.  Is STD_ERROR_HANDLE not connected
> > to the ConPty?
> 
> You are right. STD_ERROR_HANDLE (output_handle) is connected to
> the ConPTY. The data written to output_handle is fowarded to
> to_master_cyg in the master, then displayed. to_master_cyg is
> duplicated to output_handle_cyg in the slave. Therefore, both
> writing to output_handle and writing to output_handle_cyg seem
> to work, at first glance.
> 
> However, in the fact, the code below stops forwarding if the
> process is a cygwin process. 
> +	  /* Avoid duplicating slave output which is already sent to
> +	     to_master_cyg */
> +	  if (!get_ttyp ()->switch_to_pcon)
> +	    continue;
> 
> The role of the code above is as follows. ConPTY sometimes redraws
> screen based on its own screen buffer. The screen buffer has only
> the data written to output_handle. Basically, cygwin apps use
> output_handle_cyg and native apps use output_handle. Terefore,
> outputs from cygwin apps are disappeared at that time. To avoid
> this, the data write to output_handle_cyg is pushed into the ConPTY
> screen buffer by WriteFile() to output_handle. To prevent the data
> from being displayed twice, forwarding is stopped by the code above
> if the process is a cygwin app.
> 
> In strace.cc, writing to output_handle is necessary for pushing
> the data into ConPTY screen buffer, and writing to output_handle_cyg
> is necessary for displaying it.

Huh, crazy.  Thanks for explaining the context.

> 
> > > +      fhandler_base *fh = ::cygheap->fdtab[2];
> > > +      if (fh && fh->get_major () == DEV_PTYS_MAJOR)
> > 
> > For a quick test if the process is connected to a pty, you can
> > use `if (istty_slave_dev (myself->ctty))'
> 
> Thanks for advice. My code is checking if the stderr is pty or
> not, and write the message to output_handle_cyg if the stderr
> is pty. If the stderr is redirected to another device, writing
> is not done. Does istty_slave_dev() checking work same for
> stderr if it is redirected? How can I get output_handle_cyg
> after checking using istty_slave_dev()?

Well... I didn't really think about it.  YOu would have to
fetch ::cygheap->fdtab[2] anyway so checking myself->ctty
doesn't really help.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]