Discussion:
Question about stdbuf on OpenWRT
Nicholas Fitzkee
2017-06-18 05:40:19 UTC
Permalink
Hi all,

I'm trying to use stdbuf on OpenWRT and I'm having some problems getting the
correct behavior. As I'm learning, cross-compiling is not easy, so I'm not
sure if this is a bug or if I'm simply doing something wrong. Probably the
latter.

My application is rather convoluted, but I found a very nice test case on
the openwrt website (https://github.com/openwrt/packages/issues/1674) .
Running the following command buffers icmp entries when passed into awk:

tcpdump -eni eth0 -v icmp | awk '{print $1}'

If I ping an external website, the output of tcpdump is buffered so that awk
prints several lines at a time. The following command should fix this:

stdbuf -oL tcpdump -eni eth0 -v icmp | awk '{print $1}'

On my router, I get the following error message:

***@DD-WRT:/opt/bin# stdbuf -oL tcpdump -eni eth0 icmp
Error relocating /opt/bin/libstdbuf.so: __fprintf_chk: symbol not found

Libstdbuf.so is installed, and the program will work for trivial cases:

***@DD-WRT:/opt/bin# stdbuf --version
stdbuf (GNU coreutils) 8.27
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Padraig Brady.
***@DD-WRT:/opt/bin# stdbuf -oL date
Sat Jun 17 23:45:49 CDT 2017

I'm not sure where to start with this, and any advice would be appreciated.
The router/OS information is below, and the system is using libc 2.25.

Linux DD-WRT 4.9.30 #14 SMP Sat May 27 01:12:16 CEST 2017 armv7l GNU/Linux

Thanks,
Nick
Pádraig Brady
2017-06-18 19:08:10 UTC
Permalink
Post by Nicholas Fitzkee
Hi all,
I'm trying to use stdbuf on OpenWRT and I'm having some problems getting the
correct behavior. As I'm learning, cross-compiling is not easy, so I'm not
sure if this is a bug or if I'm simply doing something wrong. Probably the
latter.
My application is rather convoluted, but I found a very nice test case on
the openwrt website (https://github.com/openwrt/packages/issues/1674) .
tcpdump -eni eth0 -v icmp | awk '{print $1}'
If I ping an external website, the output of tcpdump is buffered so that awk
prints several lines at a time.
Note stdbuf only controls stdio buffering.
I think tcpdump has other internal buffering for efficiency
so to disable that you probably have to pass the --immediate-mode
option to tcpdump?
Post by Nicholas Fitzkee
stdbuf -oL tcpdump -eni eth0 -v icmp | awk '{print $1}'
Error relocating /opt/bin/libstdbuf.so: __fprintf_chk: symbol not found
Blerg. Yes this looks like a cross compile issue.
Specifically it looks like you're cross compiling with the FORTIFY_SOURCE
in your CFLAGS, while support for that is not present in your libc.
Note we set CFLAGS for libstdbuf.so to: -fPIC $(AM_CFLAGS)
This is correct I think according to:
https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html

So I'd look at getting these into the CFLAGS somehow when compiling the shared lib:

-fno-stack-protector -D_FORTIFY_SOURCE=0
Post by Nicholas Fitzkee
Sat Jun 17 23:45:49 CDT 2017
It's surprising that worked.

cheers,
Pádraig
Nicholas Fitzkee
2017-06-19 01:29:55 UTC
Permalink
Post by Pádraig Brady
-fno-stack-protector -D_FORTIFY_SOURCE=0
Perfect! That did the trick, and everything works fine now. I'll pass along
your solution to the OpenWRT developers. Thanks for the help.

Regards,
Nick

Loading...