Hi Takashi,

It might be better if you could please document the wrong premise, as well as the right premise, and the reason for choosing the latter over the former, as in your other console patches?

In the comparison vs handle count, the reason for hard coding those magic numbers would perhaps be better expressed by defining meaningful symbolic names for those numbers, maybe also a named macro for picking the magic number to use, and some explanation of what those numbers, comparisons, and settings represent.


On 2024-11-08 04:43, Takashi Yano wrote:
Previously, the condition to clean up input/output mode was based
on wrong premise. This patch fixes that.

Fixes: 8ee8b0c974d7 ("Cygwin: console: Use GetCurrentProcessId() instead of 
myself->dwProcessId")
Signed-off-by: Takashi Yano <takashi.y...@nifty.ne.jp>
---
  winsup/cygwin/fhandler/console.cc | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler/console.cc 
b/winsup/cygwin/fhandler/console.cc
index 4efba61e2..2651e49a6 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -1976,7 +1976,8 @@ fhandler_console::close ()
acquire_output_mutex (mutex_timeout); - if (shared_console_info[unit])
+  if (shared_console_info[unit] && !myself->cygstarted
+      && (dev_t) myself->ctty == get_device ())
      {
        /* Restore console mode if this is the last closure. */
        OBJECT_BASIC_INFORMATION obi;
@@ -1984,8 +1985,7 @@ fhandler_console::close ()
        status = NtQueryObject (get_handle (), ObjectBasicInformation,
                              &obi, sizeof obi, NULL);
        if (NT_SUCCESS (status)
-         && obi.HandleCount <= (myself->cygstarted ? 2 : 3)
-         && (dev_t) myself->ctty == get_device ())
+         && obi.HandleCount == (con.owner == GetCurrentProcessId () ? 2 : 3))
        {
          /* Cleaning-up console mode for cygwin apps. */
          set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);

--
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                -- Antoine de Saint-Exupéry

Reply via email to