On Thu, 24 Jul 2025 15:20:19 +0200
Corinna Vinschen wrote:
> On Jul 24 15:13, Corinna Vinschen wrote:
> > On Jul 24 15:06, Corinna Vinschen wrote:
> > > On Jul 24 20:57, Takashi Yano wrote:
> > > > Previously, process_fd failed to correctly handle fhandlers using an
> > > > archetype. This was due to the missing PATH_OPEN flag in path_conv,
> > > > which caused build_fh_pc() to skip archetype initialization. The
> > > > root cause was a bug where open() did not set the PATH_OPEN flag
> > > > for fhandlers using an archetype.
> > > > 
> > > > This patch introduces a new method, path_conv::set_isopen(), to
> > > > explicitly set the PATH_OPEN flag in path_flags in fhandler_base::
> > > > open_with_arch().
> > > 
> > > Wouldn't this patch fix the problem as well?
> > > 
> > > diff --git a/winsup/cygwin/fhandler/console.cc 
> > > b/winsup/cygwin/fhandler/console.cc
> > > index 887e2ef722bf..2801c806edd5 100644
> > > --- a/winsup/cygwin/fhandler/console.cc
> > > +++ b/winsup/cygwin/fhandler/console.cc
> > > @@ -4311,7 +4311,7 @@ fhandler_console::init (HANDLE h, DWORD a, mode_t 
> > > bin, int64_t dummy)
> > >  {
> > >    // this->fhandler_termios::init (h, mode, bin);
> > >    /* Ensure both input and output console handles are open */
> > > -  int flags = 0;
> > > +  int flags = PC_OPEN;
> > >  
> > >    a &= GENERIC_READ | GENERIC_WRITE;
> > >    if (a == GENERIC_READ)
> > > diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
> > > index 77a363eb0e3b..10785e240091 100644
> > > --- a/winsup/cygwin/fhandler/pty.cc
> > > +++ b/winsup/cygwin/fhandler/pty.cc
> > > @@ -1015,7 +1015,7 @@ fhandler_pty_slave::close (int flag)
> > >  int
> > >  fhandler_pty_slave::init (HANDLE h, DWORD a, mode_t, int64_t dummy)
> > >  {
> > > -  int flags = 0;
> > > +  int flags = PC_OPEN;
> > >  
> > >    a &= GENERIC_READ | GENERIC_WRITE;
> > >    if (a == GENERIC_READ)
> > > 
> > > 
> > > Corinna
> > 
> > No, it wouldn't.  flags are not or'ed in the followup code.  Sigh.
> > 
> > diff --git a/winsup/cygwin/fhandler/console.cc 
> > b/winsup/cygwin/fhandler/console.cc
> 
> And no, this one wouldn't either. I'm not thinking straight ATM, sorry.

Thanks. The following patch also fixes the issue, however, the intent of
the code is more unclear than v2 patch, I think.
The root cause is the same for pty and console, but fixes are different.

diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index f1832a169..5a3d01698 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -681,6 +681,8 @@ build_fh_pc (path_conv& pc)
     {
       if (!fh->get_name ())
        fh->set_name (fh->dev ().native ());
+      if (pc.isopen ())
+       fh->pc.set_isopen (); // <- fix for pty
       fh->archetype = fh->clone ();
       debug_printf ("created an archetype (%p) for %s(%d/%d)", fh->archetype, 
fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor ());
       fh->archetype->archetype = NULL;
diff --git a/winsup/cygwin/fhandler/console.cc 
b/winsup/cygwin/fhandler/console.cc
index 887e2ef72..4994e3172 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -4321,6 +4321,7 @@ fhandler_console::init (HANDLE h, DWORD a, mode_t bin, 
int64_t dummy)
   if (a == (GENERIC_READ | GENERIC_WRITE))
     flags = O_RDWR;
   open_with_arch (flags | O_BINARY | (h ? 0 : O_NOCTTY));
+  pc.set_isopen (); // <- fix for console
 
   return !tcsetattr (0, &get_ttyp ()->ti);
 }
diff --git a/winsup/cygwin/local_includes/path.h 
b/winsup/cygwin/local_includes/path.h
index 1fd542c96..a9ce2c7e4 100644
--- a/winsup/cygwin/local_includes/path.h
+++ b/winsup/cygwin/local_includes/path.h
@@ -244,6 +244,7 @@ class path_conv
   int isopen () const {return path_flags & PATH_OPEN;}
   int isctty_capable () const {return path_flags & PATH_CTTY;}
   int follow_fd_symlink () const {return path_flags & PATH_RESOLVE_PROCFD;}
+  void set_isopen () {path_flags |= PATH_OPEN;}
   void set_cygexec (bool isset)
   {
     if (isset)

-- 
Takashi Yano <[email protected]>

Reply via email to