Signal handling issue with logread -f when using klish shell on OpenWrt

46 views
Skip to first unread message

Dharmik

unread,
Jan 16, 2026, 11:27:26 AMJan 16
to klish

I’m facing a strange issue with klish on OpenWrt and would love to hear your thoughts.

I set up OpenWrt with a non-root user and assigned klish as the login shell. Everything works fine in general, but I’m running into a problem with logread -f.

When I run logread -f inside a klish shell, it just never terminates. Ctrl+C doesn’t stop it, and it feels like the process is ignoring signals entirely.

To further experiment, I tried running `logread -f` as root works perfectly (with klish shell). I also made a new user with ash shell and the logread was fine there too. Other commands like ping and tcpdump handle signals correctly under klish

Because of this, I don’t think it’s a logread bug. It really seems like something about how klish handles or forwards signals, maybe around process groups or foreground control.

I did some debugging and signal handling looks like the likely culprit, but I’m not familiar enough with klish internals to be sure.

Is this a known behavior or limitation in klish?
Is there anything about how klish manages signals that could explain this?

Any pointers on where to look or how to debug this further would be really appreciated.

Thanks for your time.
Dharmik

Dharmik

unread,
Jan 19, 2026, 6:41:10 PM (13 days ago) Jan 19
to klish
From faff3ce80bc08c3230117a75cdf965116f791ea8 Mon Sep 17 00:00:00 2001
From: dharmik <dharmikp...@yahoo.com>
Date: Tue, 20 Jan 2026 05:02:01 +0530
Subject: [PATCH] ktpd_session: Fix Ctrl+C handling for commands with
 interrupt=true

When a command has interrupt=true and Ctrl+C is received, send SIGKILL
to the process group to ensure child processes are terminated.

This fixes an issue where processes like busybox logread (which ignores
SIGINT/SIGTERM) cannot be terminated with Ctrl+C when running under klish.

The fix detects the ^C character (0x03) in stdin when interrupt=true,
then kills the entire process group to ensure all children terminate.

Signed-off-by: Dharmik <dharmikp...@yahoo.com>
---
 klish/ktp/ktpd_session.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/klish/ktp/ktpd_session.c b/klish/ktp/ktpd_session.c
index c3ce23e..f112ef2 100644
--- a/klish/ktp/ktpd_session.c
+++ b/klish/ktp/ktpd_session.c
@@ -1014,6 +1014,7 @@ static bool_t ktpd_session_process_stdin(ktpd_session_t *ktpd, faux_msg_t *msg)
  faux_buf_t *bufin = NULL;
  int fd = -1;
  bool_t interrupt = BOOL_FALSE;
+ bool_t has_ctrl_c = BOOL_FALSE;
  const kaction_t *action = NULL;

  assert(ktpd);
@@ -1053,9 +1054,27 @@ static bool_t ktpd_session_process_stdin(ktpd_session_t *ktpd, faux_msg_t *msg)
  if (cur_len > 0)
  faux_buf_write(bufin, start, cur_len);
  } else {
+ // Check if ^C (0x03) is present in the input when interrupt=true
+ if (interrupt && memchr(line, 0x03, len)) {
+ has_ctrl_c = BOOL_TRUE;
+ }
  faux_buf_write(bufin, line, len);
  }

+ // Send SIGKILL to the process group to terminate child processes
+ // Note: busybox logread ignores SIGINT/SIGTERM, so SIGKILL is required
+ if (has_ctrl_c && ktpd->exec) {
+ kexec_contexts_node_t *iter = kexec_contexts_iter(ktpd->exec);
+ kcontext_t *context = kexec_contexts_each(&iter);
+ if (context) {
+ pid_t session_pid = kcontext_pid(context);
+ if (session_pid > 0) {
+ syslog(LOG_INFO, "klish-sigint: Sending SIGKILL to pgid=-%d", session_pid);
+ kill(-session_pid, SIGKILL);
+ }
+ }
+ }
+
  stdin_out(fd, bufin, BOOL_FALSE); // Non-blocking write
  if (faux_buf_len(bufin) == 0)
  return BOOL_TRUE;
--
2.34.1

Serj Kalichev

unread,
Jan 22, 2026, 6:44:50 AM (11 days ago) Jan 22
to kl...@googlegroups.com
Do you use "in" and "out" attributes of ACTION tag? To be interactive and get Ctrl^C the terminal (pseudo-terminal) is needed.

If logread ignores SIGINT how does it escape without klish?
--
You received this message because you are subscribed to the Google Groups "klish" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klish+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/klish/157d806c-3591-4b5e-b81f-764c58d38707n%40googlegroups.com.


Dmitry Kasyanov

unread,
Jan 22, 2026, 7:37:45 AM (11 days ago) Jan 22
to kl...@googlegroups.com
I encountered this problem in Klish 2.4.
For Ctrl-c to work, you need to run an external utility via sigexec:
sigexec logread -f


С уважением,
Дмитрий Касьянов.

чт, 22 янв. 2026 г., 14:44 Serj Kalichev <serj.k...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages