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 when opening a
fhandler that uses an archetype.

Addresses: https://cygwin.com/pipermail/cygwin/2025-May/258167.html
Fixes: 92ddb7429065 ("(build_pc_pc): Use fh_alloc to create. Set name from 
fh->dev if appropriate. Generate an archetype or point to one here.")
Reported-by: Christian Franke <[email protected]>
Reviewed-by: Corinna Vinschen <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>
---
 winsup/cygwin/dtable.cc             | 4 ++++
 winsup/cygwin/local_includes/path.h | 1 +
 winsup/cygwin/release/3.6.5         | 3 +++
 3 files changed, 8 insertions(+)

diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index f1832a169..6a99c99f9 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -674,6 +674,8 @@ build_fh_pc (path_conv& pc)
                    fh->archetype->get_handle ());
       if (!fh->get_name ())
        fh->set_name (fh->archetype->dev ().name ());
+      if (pc.isopen ())
+       fh->pc.set_isopen ();
     }
   else if (cygwin_finished_initializing && !pc.isopen ())
     fh->set_name (pc);
@@ -681,6 +683,8 @@ build_fh_pc (path_conv& pc)
     {
       if (!fh->get_name ())
        fh->set_name (fh->dev ().native ());
+      if (pc.isopen ())
+       fh->pc.set_isopen ();
       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/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)
diff --git a/winsup/cygwin/release/3.6.5 b/winsup/cygwin/release/3.6.5
index 3fbaa0c3a..b4d8b44d9 100644
--- a/winsup/cygwin/release/3.6.5
+++ b/winsup/cygwin/release/3.6.5
@@ -12,3 +12,6 @@ Fixes:
 
 - Fix multi-thread safety of system().
   Addresses: https://cygwin.com/pipermail/cygwin/2025-June/258324.html
+
+- Make process_fd correctly handle pty and console.
+  Addresses: https://cygwin.com/pipermail/cygwin/2025-May/258167.html
-- 
2.45.1

Reply via email to