[U-Boot] [PATCH] tools/netconsole: make a bit more robust and use ncb when possible

The netcat utility likes to exit when it receives an empty packet (as it thinks this means EOF). This can easily occur when working with command line editing as this behavior will be triggered when using backspace. Or with tabs and command line completion. Since the local ncb util does not have this "feature" and it supports broadcast udp, default to using that rather than netcat.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- tools/netconsole | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/netconsole b/tools/netconsole index 09c8981..aa30d9b 100755 --- a/tools/netconsole +++ b/tools/netconsole @@ -31,12 +31,24 @@ if [ -z "${ip}" ] || [ -n "$3" ] ; then fi
for nc in netcat nc ; do - type ${nc} >/dev/null && break + type ${nc} >/dev/null 2>&1 && break done
trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15 echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
stty -icanon -echo intr ^T -${nc} -u -l -p ${port} < /dev/null & -exec ${nc} -u ${ip} ${port} +( +if [ -x ./ncb ] ; then + exec ./ncb ${port} +elif [ -x ${0%/*}/ncb ] ; then + exec ${0%/*}/ncb ${port} +else + while ${nc} -u -l -p ${port} < /dev/null ; do + : + done +fi +) & +pid=$! +${nc} -u ${ip} ${port} +kill $pid 2>/dev/null

Dear Mike Frysinger,
In message 1231493902-7043-1-git-send-email-vapier@gentoo.org you wrote:
The netcat utility likes to exit when it receives an empty packet (as it thinks this means EOF). This can easily occur when working with command line editing as this behavior will be triggered when using backspace. Or with tabs and command line completion. Since the local ncb util does not have this "feature" and it supports broadcast udp, default to using that rather than netcat.
When would "ncb" not be available?
What else are the implications when using ncb versus netcat?
Why does your script tools/netconsole so far use netcat only, when we have the (as I read it) much better ncb anyway?
Best regards,
Wolfgang Denk

On Friday 16 January 2009 03:37:40 Wolfgang Denk wrote:
In message 1231493902-7043-1-git-send-email-vapier@gentoo.org you wrote:
The netcat utility likes to exit when it receives an empty packet (as it thinks this means EOF). This can easily occur when working with command line editing as this behavior will be triggered when using backspace. Or with tabs and command line completion. Since the local ncb util does not have this "feature" and it supports broadcast udp, default to using that rather than netcat.
When would "ncb" not be available?
What else are the implications when using ncb versus netcat?
Why does your script tools/netconsole so far use netcat only, when we have the (as I read it) much better ncb anyway?
people have to manually build ncb, plus ncb is a listen-only daemon. you still need nc to do the transmission. -mike

Dear Mike Frysinger,
In message 200901161407.57150.vapier@gentoo.org you wrote:
have this "feature" and it supports broadcast udp, default to using that rather than netcat.
When would "ncb" not be available?
What else are the implications when using ncb versus netcat?
Why does your script tools/netconsole so far use netcat only, when we have the (as I read it) much better ncb anyway?
people have to manually build ncb, plus ncb is a listen-only daemon. you still need nc to do the transmission.
You did not answer my other questions:
- When would "ncb" not be available?
- What else are the implications when using ncb versus netcat?
Best regards,
Wolfgang Denk

On Wednesday 21 January 2009 15:13:51 Wolfgang Denk wrote:
Dear Mike Frysinger,
In message 200901161407.57150.vapier@gentoo.org you wrote:
have this "feature" and it supports broadcast udp, default to using that rather than netcat.
When would "ncb" not be available?
What else are the implications when using ncb versus netcat?
Why does your script tools/netconsole so far use netcat only, when we have the (as I read it) much better ncb anyway?
people have to manually build ncb, plus ncb is a listen-only daemon. you still need nc to do the transmission.
You did not answer my other questions:
then i really have no idea what you're asking/talking about
- When would "ncb" not be available?
ncb is specific to u-boot: tools/ncb.c. most people will not bother to compile it as they'll just run the netconsole script. it certainly isnt compiled by default or integrated into the build system.
- What else are the implications when using ncb versus netcat?
ncb is looser with receiving udp packets so it works with broadcast packets. -mike

Dear Mike Frysinger,
In message 200901211539.26445.vapier@gentoo.org you wrote:
- When would "ncb" not be available?
ncb is specific to u-boot: tools/ncb.c. most people will not bother to compile it as they'll just run the netconsole script. it certainly isnt compiled by default or integrated into the build system.
- What else are the implications when using ncb versus netcat?
ncb is looser with receiving udp packets so it works with broadcast packets.
This sounds like arguments for NOT applying your patch which depends on ncb, or am I missing something?
Best regards,
Wolfgang Denk

On Wednesday 21 January 2009 15:57:56 Wolfgang Denk wrote:
In message 200901211539.26445.vapier@gentoo.org you wrote:
- When would "ncb" not be available?
ncb is specific to u-boot: tools/ncb.c. most people will not bother to compile it as they'll just run the netconsole script. it certainly isnt compiled by default or integrated into the build system.
- What else are the implications when using ncb versus netcat?
ncb is looser with receiving udp packets so it works with broadcast packets.
This sounds like arguments for NOT applying your patch which depends on ncb, or am I missing something?
like i said in the original changelog, the script will use ncb only if it exists (i.e. the user has compiled it and thus wants to use it). some people want the ncb behavior, some people do not. otherwise i really dont know what you're looking for here. -mike

On Friday 09 January 2009 04:38:22 Mike Frysinger wrote:
The netcat utility likes to exit when it receives an empty packet (as it thinks this means EOF). This can easily occur when working with command line editing as this behavior will be triggered when using backspace. Or with tabs and command line completion. Since the local ncb util does not have this "feature" and it supports broadcast udp, default to using that rather than netcat.
ping ... afaik, it should still apply fine -mike

Dear Mike Frysinger,
In message 200909090846.33499.vapier@gentoo.org you wrote:
On Friday 09 January 2009 04:38:22 Mike Frysinger wrote:
The netcat utility likes to exit when it receives an empty packet (as it thinks this means EOF). This can easily occur when working with command line editing as this behavior will be triggered when using backspace. Or with tabs and command line completion. Since the local ncb util does not have this "feature" and it supports broadcast udp, default to using that rather than netcat.
ping ... afaik, it should still apply fine
Maybe. But I still don't like the patch. Now, with the distance of a few months, I think it should be split into two parts:
1) "make a bit more robust"
I agree that this is kind of a bug fix; I think it can go in.
2) "use ncb when possible"
Here I really dislike the implementation of "when possible", which makes silent and undocumented assumptions about from which directory the script has to be run. I guess the "when possible" would almost always turn out to be false, so we might omit the patch alltogether, especially since it's also documented in "doc/README.NetConsole".
If we add it, we should follow standard UNIX philosophy and assume that you set your PATH accordingly to reach the tools you want to use.
Best regards,
Wolfgang Denk

On Wednesday 09 September 2009 09:28:42 Wolfgang Denk wrote:
Mike Frysinger wrote:
On Friday 09 January 2009 04:38:22 Mike Frysinger wrote:
The netcat utility likes to exit when it receives an empty packet (as it thinks this means EOF). This can easily occur when working with command line editing as this behavior will be triggered when using backspace. Or with tabs and command line completion. Since the local ncb util does not have this "feature" and it supports broadcast udp, default to using that rather than netcat.
ping ... afaik, it should still apply fine
Maybe. But I still don't like the patch. Now, with the distance of a few months, I think it should be split into two parts:
- "make a bit more robust"
I agree that this is kind of a bug fix; I think it can go in.
np
- "use ncb when possible"
Here I really dislike the implementation of "when possible", which makes silent and undocumented assumptions about from which directory the script has to be run. I guess the "when possible" would almost always turn out to be false, so we might omit the patch alltogether, especially since it's also documented in "doc/README.NetConsole".
If we add it, we should follow standard UNIX philosophy and assume that you set your PATH accordingly to reach the tools you want to use.
since ncb is compiled whenever netconsole is enabled, and people typically use this script with netconsole enabled, "when possible" tends to be line up fairly often. also, the broadcast aspect is pretty useful. i guess i could make it search PATH, but the idea was to have things "just work" rather than forcing people to install random utils into their PATH. -mike

Dear Mike Frysinger,
In message 200909091015.05454.vapier@gentoo.org you wrote:
- "use ncb when possible"
Here I really dislike the implementation of "when possible", which makes silent and undocumented assumptions about from which directory the script has to be run. I guess the "when possible" would almost always turn out to be false, so we might omit the patch alltogether, especially since it's also documented in "doc/README.NetConsole".
If we add it, we should follow standard UNIX philosophy and assume that you set your PATH accordingly to reach the tools you want to use.
since ncb is compiled whenever netconsole is enabled, and people typically use this script with netconsole enabled, "when possible" tends to be line up fairly often. also, the broadcast aspect is pretty useful. i guess i could
Agreed. But the code is based on the assumption that your current directory when attaching to the console of a target is the U-Boot source directory. For me, this is definitely not always the case. I might as well have /tftpboot or solilar as cwd.
make it search PATH, but the idea was to have things "just work" rather than forcing people to install random utils into their PATH.
I rather have people intentionally install tools to some directory in their PATH or set PATH intentionally to some tool directory rather than have tools suddenly and mysteriously break just because I run them from a different location.
Best regards,
Wolfgang Denk

On Wednesday 09 September 2009 10:32:44 Wolfgang Denk wrote:
Mike Frysinger wrote:
- "use ncb when possible"
Here I really dislike the implementation of "when possible", which makes silent and undocumented assumptions about from which directory the script has to be run. I guess the "when possible" would almost always turn out to be false, so we might omit the patch alltogether, especially since it's also documented in "doc/README.NetConsole".
If we add it, we should follow standard UNIX philosophy and assume that you set your PATH accordingly to reach the tools you want to use.
since ncb is compiled whenever netconsole is enabled, and people typically use this script with netconsole enabled, "when possible" tends to be line up fairly often. also, the broadcast aspect is pretty useful. i guess i could
Agreed. But the code is based on the assumption that your current directory when attaching to the console of a target is the U-Boot source directory. For me, this is definitely not always the case. I might as well have /tftpboot or solilar as cwd.
it takes multiple steps. first, the cwd and then based on argv0. so even if you're in a different place, if the script lives in the source tree when you execute it, it'll work fine.
make it search PATH, but the idea was to have things "just work" rather than forcing people to install random utils into their PATH.
I rather have people intentionally install tools to some directory in their PATH or set PATH intentionally to some tool directory rather than have tools suddenly and mysteriously break just because I run them from a different location.
if they're both installed into the same place, then it'll still work. i can add a PATH search in place of the cwd one as the argv0+PATH should handle both cases fine. -mike

The netcat utility likes to exit when it receives an empty packet (as it thinks this means EOF). This can easily occur when working with command line editing as this behavior will be triggered when using backspace. Or with tabs and command line completion. So create two netcat processes - one to only listen (and put it into a loop), and one to do the sending. Once the user quits the transmitting netcat, the listening one will be killed automatically.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- v2 - split the changes (robust and ncb)
tools/netconsole | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/netconsole b/tools/netconsole index 09c8981..6ef2723 100755 --- a/tools/netconsole +++ b/tools/netconsole @@ -31,12 +31,18 @@ if [ -z "${ip}" ] || [ -n "$3" ] ; then fi
for nc in netcat nc ; do - type ${nc} >/dev/null && break + type ${nc} >/dev/null 2>&1 && break done
trap "stty icanon echo intr ^C" 0 2 3 5 10 13 15 echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
stty -icanon -echo intr ^T -${nc} -u -l -p ${port} < /dev/null & -exec ${nc} -u ${ip} ${port} +( +while ${nc} -u -l -p ${port} < /dev/null ; do + : +done +) & +pid=$! +${nc} -u ${ip} ${port} +kill ${pid} 2>/dev/null

Dear Mike Frysinger,
In message 1252513221-2524-1-git-send-email-vapier@gentoo.org you wrote:
The netcat utility likes to exit when it receives an empty packet (as it thinks this means EOF). This can easily occur when working with command line editing as this behavior will be triggered when using backspace. Or with tabs and command line completion. So create two netcat processes - one to only listen (and put it into a loop), and one to do the sending. Once the user quits the transmitting netcat, the listening one will be killed automatically.
Signed-off-by: Mike Frysinger vapier@gentoo.org
v2
- split the changes (robust and ncb)
tools/netconsole | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk

The standard netcat, while ubiquitous, doesn't handle broadcast udp packets properly. The local ncb util does however. So if ncb can be located in the standard locations, automatically use that instead.
Signed-off-by: Mike Frysinger vapier@gentoo.org --- v2 - split the changes - search PATH rather than CWD - update docs
doc/README.NetConsole | 24 +++--------------------- tools/netconsole | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/doc/README.NetConsole b/doc/README.NetConsole index 639cc12..c8bcb90 100644 --- a/doc/README.NetConsole +++ b/doc/README.NetConsole @@ -36,27 +36,9 @@ you can just remove the -p option from the script. It turns out that 'netcat' cannot be used to listen to broadcast packets. We developed our own tool 'ncb' (see tools directory) that listens to broadcast packets on a given port and dumps them to the -standard output. use it as follows: - -+++++++++++++++++++++++++++++++++++++++++++ -#! /bin/bash - -[ $# = 1 ] || { echo "Usage: $0 target_ip" >&2 ; exit 1 ; } -TARGET_IP=$1 - -stty icanon echo intr ^T -./ncb & -nc -u ${TARGET_IP} 6666 -stty icanon echo intr ^C -kill 0 -+++++++++++++++++++++++++++++++++++++++++++ - -Again, this script takes exactly one argument, which is interpreted -as the target IP address (or host name, assuming DNS is working). The -script can be interrupted by pressing ^T (CTRL-T). - -The 'ncb' tool can be found in the tools directory; it will be built -when compiling for a board which has CONFIG_NETCONSOLE defined. +standard output. It will be built when compiling for a board which +has CONFIG_NETCONSOLE defined. If the netconsole script can find it +in PATH or in the same directory, it will be used instead.
For Linux, the network-based console needs special configuration. Minimally, the host IP address needs to be specified. This can be diff --git a/tools/netconsole b/tools/netconsole index 6ef2723..c8109bb 100755 --- a/tools/netconsole +++ b/tools/netconsole @@ -39,9 +39,20 @@ echo "NOTE: the interrupt signal (normally ^C) has been remapped to ^T"
stty -icanon -echo intr ^T ( -while ${nc} -u -l -p ${port} < /dev/null ; do - : -done +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=$! ${nc} -u ${ip} ${port}

Dear Mike Frysinger,
In message 1252513221-2524-2-git-send-email-vapier@gentoo.org you wrote:
The standard netcat, while ubiquitous, doesn't handle broadcast udp packets properly. The local ncb util does however. So if ncb can be located in the standard locations, automatically use that instead.
Signed-off-by: Mike Frysinger vapier@gentoo.org
v2
- split the changes
- search PATH rather than CWD
- update docs
doc/README.NetConsole | 24 +++--------------------- tools/netconsole | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 24 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
participants (2)
-
Mike Frysinger
-
Wolfgang Denk