public inbox for dash@vger.kernel.org
 help / color / mirror / Atom feed
From: Abdullah <3bd3bdr@gmail.com>
To: dash@vger.kernel.org
Cc: Abdullah <3bd3bdr@gmail.com>
Subject: [PATCH] histedit: fix dash exiting when receiving a signal interactively
Date: Thu, 18 Sep 2025 03:33:58 +0300	[thread overview]
Message-ID: <20250918003435.11162-2-3bd3bdr@gmail.com> (raw)
In-Reply-To: <20250918003435.11162-1-3bd3bdr@gmail.com>

---
 src/input.c | 32 ++++++++++++++++++++++++++++----
 src/trap.c  | 16 +++++++++++++++-
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/src/input.c b/src/input.c
index c36d120..f775c9f 100644
--- a/src/input.c
+++ b/src/input.c
@@ -39,6 +39,7 @@
 #include <string.h>
 #include <termios.h>
 #include <unistd.h>
+#include <wchar.h>
 
 /*
  * This file implements the input routines used by the parser.
@@ -276,6 +277,11 @@ preadfd(void)
 	int unget;
 	int pnr;
 	int nr;
+#ifndef SMALL
+	const LineInfoW *liw;
+	wchar_t wbuf[2];
+	const wchar_t *wc;
+#endif
 
 	nr = input_get_lleft(parsefile);
 
@@ -306,9 +312,8 @@ retry:
 			rl_cp = el_gets(el, &el_len);
 			popstackmark(&smark);
 		}
-		if (rl_cp == NULL)
-			nr = 0;
-		else {
+
+		if (rl_cp) {
 			if (nr > el_len)
 				nr = el_len;
 			memcpy(buf, rl_cp, nr);
@@ -317,9 +322,28 @@ retry:
 				rl_cp += nr;
 			} else
 				rl_cp = 0;
+			return nr;
 		}
 
-		return nr;
+		/* Got a signal while reading. */
+		if (el_len < 0 && errno == EINTR && pending_sig) {
+			out2c('\r');
+			liw = el_wline(el);
+			/* Don't lose the current line.
+			 * el_wpush() takes a L'\0' terminated string.
+			 * el_wline() gives us a string with N elements.
+			 * Simple solution: el_wpush() it wchar-by-wchar.
+			 */
+			wbuf[1] = L'\0';
+			wc = liw->buffer;
+			while (wc < liw->lastchar) {
+				wbuf[0] = *wc++;
+				el_wpush(el, wbuf);
+			}
+			dotrap();
+			goto retry;
+		}
+		return 0;
 	}
 #endif
 
diff --git a/src/trap.c b/src/trap.c
index 23829a5..c045257 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -53,6 +53,7 @@
 #include "error.h"
 #include "trap.h"
 #include "mystring.h"
+#include "myhistedit.h"
 
 /*
  * Sigmode records the current value of the signal handlers for the various
@@ -243,7 +244,12 @@ setsignal(int signo)
 		}
 	}
 
-	if (signo == SIGCHLD)
+	if (
+		signo == SIGCHLD
+#if defined(WINCH) && !defined(SMALL)
+		|| signo == WINCH
+#endif
+	)
 		action = S_CATCH;
 
 	t = &sigmode[signo - 1];
@@ -321,6 +327,11 @@ onsig(int signo)
 			return;
 	}
 
+#if defined(SIGWINCH) && !defined(SMALL)
+	if (signo == SIGWINCH && el)
+		el_resize(el);
+#endif
+
 	gotsig[signo - 1] = 1;
 	pending_sig = signo;
 
@@ -397,6 +408,9 @@ setinteractive(int on)
 	setsignal(SIGINT);
 	setsignal(SIGQUIT);
 	setsignal(SIGTERM);
+#if defined(WINCH) && !defined(SMALL)
+	setsignal(WINCH);
+#endif
 }
 
 
-- 
2.51.0


  reply	other threads:[~2025-09-18  0:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18  0:33 Incorrect detection of EOF with interactive editline Abdullah
2025-09-18  0:33 ` Abdullah [this message]
2025-09-18  3:20   ` [PATCH] histedit: fix dash exiting when receiving a signal interactively Herbert Xu
     [not found]     ` <DCW6NI4KVK3I.1ALXRKL5V6UCM@gmail.com>
2025-09-22  3:43       ` Herbert Xu

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=20250918003435.11162-2-3bd3bdr@gmail.com \
    --to=3bd3bdr@gmail.com \
    --cc=dash@vger.kernel.org \
    /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