[PATCH] histedit: fix dash exiting when receiving a signal interactively
Abdullah <[email protected]> Thu, 18 Sep 2025 03:33:58 +0300
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
---
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