mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] netconsole: terminate netcat background process on exit
@ 2026-05-03  8:30 Ahmad Fatoum
  2026-05-03  8:30 ` [PATCH 2/3] netconsole: add support for binding to specific IP Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2026-05-03  8:30 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-07 10:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-03  8:30 [PATCH 1/3] netconsole: terminate netcat background process on exit Ahmad Fatoum
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox