busybox ip and the original ip utility behave differently when setting
the following route (verified with ip route show using the original ip
utility):
ip route add 10.0.0.138 dev eth0
Result for busybox ip:
# ip route add 10.0.0.138 dev eth0
# /usr/local/bin/ip route show
10.0.0.138 dev eth0
Result for ip:
# /usr/local/bin/ip route add 10.0.0.138 dev eth0
# /usr/local/bin/ip route show
10.0.0.138 dev eth0 scope link
A following "ip route add default via 10.0.0.138" fails for busybox
ip, since the kernel can not find a route to 10.0.0.138 (it replies
with Network is unreachable).
The reasons seems to be that the original ip utility explicitly sets
the scope after parsing all parameters. This is missing in busybox,
the attached patch fixes this. I took this from the original iproute
sources and removed some variables, which are not needed for busybox.
FEATURE_SH_STANDALONE_SHELL => FEATURE_SH_STANDALONE
FEATURE_EXEC_PREFER_APPLETS => FEATURE_PREFER_APPLETS
Make SH_STANDALONE depend on PREFER_APPLETS.
getopt.c: more randomconfig-induced fixes
- mark libiproute's matches() as deprecated. Convert to index_in_(sub)str_array()!
text data bss dec hex filename
314 0 0 314 13a ip.o.orig
200 0 0 200 c8 ip.o
Using a smallint for the key would save another byte.
echo: use fputs if no options are given. Code growth ~15 bytes.
Old:
# time ./busybox find $bigdir -exec echo {} \; >/dev/null
real 0m2.038s
user 0m0.761s
sys 0m0.953s
New:
# time ./busybox find $bigdir -exec echo {} \; >/dev/null
real 0m1.781s
user 0m0.781s
sys 0m0.939s
For comparison: without NOFORK:
# time find $bigdir -exec echo {} \; >/dev/null
real 1m51.129s
user 0m38.442s
sys 1m3.350s
find: use NOFORK/NOEXEC; small -exec buglet also eliminated
vfork_daemon_rexec: honor PREFER_APPLETS
echo: small size improvements
find -exec echo {} \; with PREFER_APPLETS=y runs 4 times faster
and now this fact is recorded in applets.h, not ash.c.
Several fixes to "--help + STANDALONE_SHELL" scenarios.
function old new delta
run_current_applet_and_exit - 355 +355
arith 2064 2073 +9
refresh 1148 1156 +8
getopt32 1068 1073 +5
telnet_main 1510 1514 +4
md5_sha1_sum_main 565 566 +1
xstrtoul_range_sfx 255 251 -4
packed_usage 22523 22514 -9
tryexec 255 203 -52
static.safe_applets 152 - -152
.rodata 131320 131128 -192
run_applet_by_name 869 506 -363
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 5/5 up/down: 382/-772) Total: -390 bytes
./busybox ash -c 'i=20000; while test $i != 0; do touch z; i=$((i-1)); done'
runs more than twice as fast with STANDALONE_SHELL versus without.