public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Cc: Takashi Yano <takashi.yano@nifty.ne.jp>,
	Gregory Mason <grmason@epic.com>
Subject: [PATCH] Cygwin: console: Fix hangup of less on quit after the window is resized.
Date: Thu, 22 Dec 2022 20:48:13 +0900	[thread overview]
Message-ID: <20221222114813.1220-1-takashi.yano@nifty.ne.jp> (raw)

https://cygwin.com/pipermail/cygwin/2022-December/252737.html

If the less is started from non-cygwin shell and window size is
changed, it will hang-up when quitting. The cause of the proglem is
that less uses longjump() in signal handler. If the signal handler
is called while cygwin is acquiring the mutex, cygwin loses the
chance to release mutex. With this patch, the mutex is released
just before calling kill_pgrp() and re-acquired when kill_pgrp()
returns.

Reported-by: Gregory Mason <grmason@epic.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
---
 winsup/cygwin/fhandler/console.cc | 4 ++++
 winsup/cygwin/release/3.4.4       | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
index bbf4b0103..ee07c84f8 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -928,7 +928,11 @@ fhandler_console::send_winch_maybe ()
       if (wincap.has_con_24bit_colors () && !con_is_legacy
 	  && wincap.has_con_broken_tabs ())
 	fix_tab_position (get_output_handle ());
+      /* longjmp() may be called in the signal handler like less,
+	 so release input_mutex temporarily before kill_pgrp(). */
+      release_input_mutex ();
       get_ttyp ()->kill_pgrp (SIGWINCH);
+      acquire_input_mutex (mutex_timeout);
       return true;
     }
   return false;
diff --git a/winsup/cygwin/release/3.4.4 b/winsup/cygwin/release/3.4.4
index 6ac702375..3331b3166 100644
--- a/winsup/cygwin/release/3.4.4
+++ b/winsup/cygwin/release/3.4.4
@@ -3,3 +3,7 @@ Bug Fixes
 
 - Fix an uninitialized variable having weird side-effects in path handling.
   Addresses: https://cygwin.com/pipermail/cygwin/2022-December/252734.html
+
+- Fix hang-up of less on quit which occurs when it is started from non-cygwin
+  shell and window is resized.
+  Addresses: https://cygwin.com/pipermail/cygwin/2022-December/252737.html
-- 
2.39.0


                 reply	other threads:[~2022-12-22 11:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221222114813.1220-1-takashi.yano@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin-patches@cygwin.com \
    --cc=grmason@epic.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).