From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 1/3] netconsole: terminate netcat background process on exit
Date: Sun, 3 May 2026 10:30:04 +0200 [thread overview]
Message-ID: <20260503083115.2763213-1-a.fatoum@barebox.org> (raw)
We ship no ncb utility and Debian doesn't package it, so the fallback
path with netcat is what everyone is going to hit.
Drop the ncb branches and make sure to actually kill the netcat process
and not only the subshell that spawned it.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
scripts/netconsole | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/scripts/netconsole b/scripts/netconsole
index c8109bb09569..7ab81a3a9191 100755
--- a/scripts/netconsole
+++ b/scripts/netconsole
@@ -34,26 +34,27 @@ for nc in netcat nc ; do
type ${nc} >/dev/null 2>&1 && break
done
-trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15
+cleanup() {
+ if [ -n "${listener_pid}" ] ; then
+ # The listener subshell is its own process group leader (see set -m
+ # below); kill the whole group so the netcat child dies with it.
+ kill -- -${listener_pid} 2>/dev/null
+ wait ${listener_pid} 2>/dev/null
+ fi
+ stty icanon echo intr ^C
+}
+trap cleanup EXIT INT QUIT TERM HUP
+
echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
stty -icanon -echo intr ^T
+set -m
(
-if type ncb 2>/dev/null ; then
- # see if ncb is in $PATH
- exec ncb ${port}
-
-elif [ -x ${0%/*}/ncb ] ; then
- # maybe it's in the same dir as the netconsole script
- exec ${0%/*}/ncb ${port}
-
-else
- # blah, just use regular netcat
while ${nc} -u -l -p ${port} < /dev/null ; do
:
done
-fi
) &
-pid=$!
+listener_pid=$!
+set +m
+
${nc} -u ${ip} ${port}
-kill ${pid} 2>/dev/null
--
2.47.3
next reply other threads:[~2026-05-03 8:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 8:30 Ahmad Fatoum [this message]
2026-05-03 8:30 ` [PATCH 2/3] netconsole: add support for binding to specific IP Ahmad Fatoum
2026-05-03 8:30 ` [PATCH 3/3] test: py: implement --port-forward option Ahmad Fatoum
2026-05-07 10:38 ` [PATCH 1/3] netconsole: terminate netcat background process on exit Sascha Hauer
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=20260503083115.2763213-1-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.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