Commit Graph

866 Commits

Author SHA1 Message Date
Stephen Heumann 16cd3c0619 Merge with BusyBox 1.24.0.
There's really only one bug fix in here that should be significant for GNO hush. The other changes should be inconsequential, AFAIK.
2015-10-17 01:10:35 -05:00
Denys Vlasenko e52da5570e libbb: auto_string() for efficient handling of temporary malloced stirngs
Use it in libiproute: get rid of one static string buffer.

function                                             old     new   delta
auto_string                                            -      51     +51
ll_index_to_name                                      10      49     +39
buffer_fill_and_print                                169     178      +9
scan_recursive                                       378     380      +2
decode_one_format                                    732     734      +2
cmdputs                                              334     332      -2
static.cur_saved                                       4       1      -3
static.nbuf                                           16       -     -16
printable_string                                      94      57     -37
ll_idx_n2a                                            53       -     -53
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 4/3 up/down: 103/-111)           Total: -8 bytes
   text	   data	    bss	    dec	    hex	filename
 939880	    992	  17496	 958368	  e9fa0	busybox_old
 939880	    992	  17480	 958352	  e9f90	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 17:59:56 +02:00
Denys Vlasenko 550bf5b4a4 remove global "jmp_buf die_jmp" from !FEATURE_PREFER_APPLETS builds
function                                             old     new   delta
xfunc_has_died                                         -      21     +21
sleep_much                                             -      12     +12
sleep10                                                -       9      +9
die_func                                               -       4      +4
fflush_stdout_and_exit                                35      36      +1
builtin_type                                         121     119      -2
die_sleep                                              4       -      -4
xfunc_die                                             60      24     -36
hush_main                                           1128    1011    -117
die_jmp                                              156       -    -156
------------------------------------------------------------------------------
(add/remove: 4/2 grow/shrink: 1/3 up/down: 47/-315)          Total: -268 bytes
   text	   data	    bss	    dec	    hex	filename
 939992	    992	  17652	 958636	  ea0ac	busybox_old
 939880	    992	  17496	 958368	  e9fa0	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-09 16:42:57 +02:00
Denys Vlasenko 5711a2a4ad libbb: more compact API for bb_parse_mode()
function                                             old     new   delta
make_device                                         2182    2188      +6
parse_command                                       1440    1443      +3
parse_params                                        1497    1499      +2
install_main                                         773     769      -4
mkdir_main                                           168     160      -8
getoptscmd                                           641     632      -9
builtin_umask                                        158     147     -11
bb_parse_mode                                        431     410     -21
umaskcmd                                             286     258     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/6 up/down: 11/-81)            Total: -70 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-07 17:55:33 +02:00
Bartosz Golaszewski 7448b513c8 libbb: add is_suffixed_with() function
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-25 16:36:43 +02:00
Denys Vlasenko c52cbea2bb libbb: add setsockopt_foo helpers
function                                             old     new   delta
setsockopt_int                                         -      23     +23
do_load                                              918     934     +16
setsockopt_SOL_SOCKET_int                              -      14     +14
setsockopt_keepalive                                   -      10     +10
setsockopt_SOL_SOCKET_1                                -      10     +10
buffer_fill_and_print                                169     178      +9
setsockopt_1                                           -       8      +8
nfsmount                                            3560    3566      +6
redirect                                            1277    1282      +5
tcpudpsvd_main                                      1782    1786      +4
d6_send_kernel_packet                                272     275      +3
i2cget_main                                          380     382      +2
ed_main                                             2544    2545      +1
scan_recursive                                       380     378      -2
nbdclient_main                                       492     490      -2
hash_find                                            235     233      -2
cmdputs                                              334     332      -2
parse_command                                       1443    1440      -3
static.two                                             4       -      -4
ntpd_main                                           1039    1035      -4
const_int_1                                            4       -      -4
const_IPTOS_LOWDELAY                                   4       -      -4
RCVBUF                                                 4       -      -4
ntp_init                                             474     469      -5
change_listen_mode                                   316     310      -6
uevent_main                                          416     409      -7
arping_main                                         1697    1690      -7
telnet_main                                         1612    1603      -9
socket_want_pktinfo                                   42      33      -9
setsockopt_reuseaddr                                  21      10     -11
setsockopt_broadcast                                  21      10     -11
httpd_main                                           772     757     -15
get_remote_transfer_fd                               109      94     -15
make_new_session                                     503     487     -16
ftpd_main                                           2177    2160     -17
read_bunzip                                         1896    1866     -30
common_traceroute_main                              4099    4058     -41
common_ping_main                                    1836    1783     -53
------------------------------------------------------------------------------
(add/remove: 5/4 grow/shrink: 8/21 up/down: 111/-283)        Total: -172 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-24 20:00:17 +02:00
Bartosz Golaszewski d077565bb2 unit-tests: remove unnecesary field from struct bbunit_listelem
In the initial submission struct bbunit_listelem was manipulated by
custom list functions implemented in bbunit.c. Since the tests are now
added to the list by llist_add_to_end(), which allocates the llist_t
objects behind the scenes, there's no need for the *next field.

function                                             old     new   delta
unit_main                                            142     141      -1
bbunit_strrstr_elem                                   24      16      -8
bbunit_obscure_weak_pass_elem                         24      16      -8
bbunit_obscure_strong_pass_elem                       24      16      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-25)             Total: -25 bytes

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-08-17 17:00:10 +02:00
Ron Yorston d840c5d139 libbb: add a function to make a copy of a region of memory
Introduce a library routine to package the idiom:

    p = xmalloc(b, n);
    memcpy(p, b, n);

and use it where possible.  The example in traceroute used xzalloc
but it didn't need to.

function                                             old     new   delta
xmemdup                                                -      32     +32
last_main                                            834     826      -8
make_device                                         2321    2311     -10
common_traceroute_main                              3698    3685     -13
readtoken1                                          3182    3168     -14
procps_scan                                         1222    1206     -16
forkchild                                            655     638     -17
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/6 up/down: 32/-78)            Total: -46 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-07-19 23:05:20 +02:00
Bernhard Reutner-Fischer 7d86384b24 include: Fallback to UTMP unless there is UTMPX support
Fixes compilation against uClibc-0.9.30 for instance

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-20 15:24:30 +02:00
Ron Yorston 61d6ae244a libbb: remove unnecessary argument to nonblock_immune_read
The loop_on_EINTR argument to nonblock_immune_read is always set to 1.

function                                             old     new   delta
xmalloc_reads                                        200     195      -5
pgetc                                                488     483      -5
argstr                                              1313    1308      -5
nonblock_immune_read                                 123      86     -37
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-52)             Total: -52 bytes

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-04-20 13:41:32 +02:00
Bernhard Reutner-Fischer 86a7f18f21 *: Switch to POSIX utmpx API
UTMP is SVID legacy, UTMPX is mandated by POSIX.

Glibc and uClibc have identical layout of UTMP and UTMPX, both of these
libc treat _PATH_UTMPX as _PATH_UTMP so from a user-perspective nothing
changes except the names of the API entrypoints.

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2015-04-02 23:03:46 +02:00
Ari Sundholm 911db16229 truncate: new applet
function                                             old     new   delta
truncate_main                                          -     161    +161
cwbkMG_suffixes                                        -     128    +128
packed_usage                                       30443   30459     +16
applet_names                                        2512    2521      +9
applet_main                                         1456    1460      +4
parse_command                                       1460    1463      +3
applet_nameofs                                       728     730      +2
applet_install_loc                                   182     183      +1
dd_suffixes                                          112       -    -112
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 10/3 up/down: 337/-133)         Total: 204 bytes

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:56:38 +01:00
Ari Sundholm 8893023ba2 dd: move suffix struct to xatonum.c
This way it can be used by other applets without duplication.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-22 17:41:04 +01:00
Denys Vlasenko 8dff01d06a libbb: introduce and use is_prefixed_with()
function                                             old     new   delta
is_prefixed_with                                       -      18     +18
complete_username                                     78      77      -1
man_main                                             737     735      -2
fsck_device                                          429     427      -2
unpack_ar_archive                                     80      76      -4
strip_unsafe_prefix                                  105     101      -4
singlemount                                         1054    1050      -4
rtc_adjtime_is_utc                                    90      86      -4
resolve_mount_spec                                    88      84      -4
parse_one_line                                      1029    1025      -4
parse_conf                                          1460    1456      -4
may_wakeup                                            83      79      -4
loadkmap_main                                        219     215      -4
get_irqs_from_stat                                   103      99      -4
get_header_cpio                                      913     909      -4
findfs_main                                           79      75      -4
fbsplash_main                                       1230    1226      -4
load_crontab                                         776     771      -5
expand_vars_to_list                                 1151    1146      -5
date_main                                            881     876      -5
skip_dev_pfx                                          30      24      -6
make_device                                         2199    2193      -6
complete_cmd_dir_file                                773     767      -6
run_applet_and_exit                                  715     708      -7
uudecode_main                                        321     313      -8
pwdx_main                                            197     189      -8
execute                                              568     560      -8
i2cdetect_main                                      1186    1176     -10
procps_scan                                         1242    1230     -12
procps_read_smaps                                   1017    1005     -12
process_module                                       746     734     -12
patch_main                                          1903    1891     -12
nfsmount                                            3572    3560     -12
stack_machine                                        126     112     -14
process_timer_stats                                  449     435     -14
match_fstype                                         111      97     -14
do_ipaddr                                           1344    1330     -14
open_list_and_close                                  359     343     -16
get_header_tar                                      1795    1779     -16
prepend_new_eth_table                                340     323     -17
fsck_main                                           1811    1794     -17
find_iface_state                                      56      38     -18
dnsd_main                                           1321    1303     -18
base_device                                          179     158     -21
find_keyword                                         104      82     -22
handle_incoming_and_exit                            2785    2762     -23
parse_and_put_prompt                                 774     746     -28
modinfo                                              347     317     -30
find_action                                          204     171     -33
update_passwd                                       1470    1436     -34
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/49 up/down: 18/-540)         Total: -522 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-03-12 17:48:34 +01:00
Denys Vlasenko da9212667c libbb: code shrink by factoring out common update_utmp_DEAD_PROCESS
function                                             old     new   delta
update_utmp_DEAD_PROCESS                               -      17     +17
telnetd_main                                        1685    1674     -11
mark_terminated                                       56      45     -11
handle_sigchld                                        74      63     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-01-05 15:37:58 +01:00
Stephen Heumann b1044cfa8f Properly report exit status values with the high bit set (128-255).
These were being reported as strange values because the WEXITSTATUS macro from the GNO headers would erroneously sign-extend them.

Thanks to Kelvin Sherlock for posting an example that demonstrated this problem.
2015-01-04 15:45:25 -06:00
Stephen Heumann ba2aa925bc Fix sigaddset/sigdelset/sigismember macros to support signals above 16.
The versions in the GNO 2.0.6 headers are broken--they don't account for int being 16-bit, so they cut off the higher signals.
2014-12-28 16:06:45 -06:00
Stephen Heumann 70ea37208b Merge with BusyBox 1.23.0.
The only substantive change is about when simple line input mode is used.

I also bumped the version number and included a GNO-version-specific component.
2014-12-27 13:33:41 -06:00
Stephen Heumann 3e96c3390f Check for TERM changes every time we read input.
Also, fix possible crashes when termcap entries aren't found.
2014-12-24 14:54:06 -06:00
Peter Kümmel a6588fa102 Make it possible to override LOGIN_FAIL_DELAY in CONFIG_EXTRA_CFLAGS
Signed-off-by: Peter Kümmel <syntheticpp@gmx.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-22 01:55:54 +01:00
Denys Vlasenko b4c11c1397 libarchive: add capability to unpack to mem.buffer
The performance and number of processes for a "depmod -a" with gzipped
modules was abysmal. This patch adds a code path without fork,
benefiting all users of xmalloc_open_zipped_read_close.

"modinfo radeon.ko.gz", a single-file reader, got 30% faster.
"depmod -a", which used to fork over 800 times, got 20% faster.

Heavily based on a patch by Lauri Kasanen <curaga@operamail.com>

function                                             old     new   delta
setup_transformer_on_fd                                -     159    +159
transformer_write                                      -     122    +122
fork_transformer                                       -     112    +112
xmalloc_open_zipped_read_close                        63     118     +55
read_bunzip                                         1866    1896     +30
xtransformer_write                                     -      19     +19
unzip_main                                          2449    2462     +13
bbunpack                                             755     766     +11
unpack_lzma_stream                                  2717    2723      +6
unpack_xz_stream                                    2393    2397      +4
unpack_Z_stream                                     1173    1175      +2
inflate_unzip                                        111     105      -6
check_signature16                                     70      63      -7
unpack_bz2_stream                                    359     349     -10
unpack_unxz                                           12       -     -12
unpack_unlzma                                         12       -     -12
unpack_uncompress                                     12       -     -12
unpack_gunzip                                         12       -     -12
unpack_bunzip2                                        12       -     -12
open_transformer                                     106      92     -14
inflate_unzip_internal                              1945    1916     -29
unpack_gz_stream                                     693     655     -38
open_zipped                                           89      47     -42
setup_unzip_on_fd                                    142      53     -89
------------------------------------------------------------------------------
(add/remove: 4/5 grow/shrink: 7/8 up/down: 533/-295)          Total: 238 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-12-07 00:44:00 +01:00
Stephen Heumann b4a362ef71 Make test report EXEC files (shell scripts) as executable. 2014-12-04 13:41:21 -06:00
Stephen Heumann fb9b298ca4 Implement "close-on-exec" functionality for GNO.
We do this by maintaining a mask (for each pid) giving the fds to be closed on exec. We wrap functions that close fds so that their close-on-exec bits can be cleared at that point.

This implementation may close the fds even if the execve operation ultimately fails.
2014-12-03 21:04:46 -06:00
Denys Vlasenko 04c1417602 libbb: use ARG_MAX for bb_arg_max() only if it's 60k+
Sometimes ARG_MAX is small (like 32k) yet sysconf(_SC_ARG_MAX)
is big, and people prefer using the bigger value.

OTOH, with sufficiently large ARG_MAX, further wins from
sysconf(_SC_ARG_MAX) being bigger are exponentially smaller:
you can see 4 times fewer fork+execs when you run find, but
when each execed process already takes a thousand parameters
it's likely execution time is dominated by what that process
does with each parameter.

Thus, with this change ARG_MAX is used if it's sufficiently big,
otherwise sysconf(_SC_ARG_MAX) is used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-26 15:17:59 +01:00
Stephen Heumann 334678c6e9 Change various uses of signal masks to use 32-bit values (previously half the signals were essentially cut off). 2014-11-25 17:43:14 -06:00
Stephen Heumann 5c972aa397 Fix our handling of process groups for job control, working around a couple GNO bugs.
*Most significantly, we avoid using setpgid(), because it doesn't work and in fact corrupts the kernel's process group table.
*Also, work around tctpgrp() returning garbage instead of 0 on success.

This adds an implementation of tcsetpgrp that works by reading the process tables to find a process in the appropriate group. This isn't used for the main job control operations, though, since it might be relatively slow.

At this point, basic job control seems to work.
2014-11-21 23:05:38 -06:00
Stephen Heumann 4d60cd1043 Fixes for environment variable handling on GNO:
* Push/pop environment to make sure it is isolated from our parents and children.
* Make all environment vars (and shell vars) case-insensitive, consistent with GNO's internal handling of environment vars.
* Wrap putenv and unsetenv to make sure they are called with lower-case variable names, which is necessary to maintain consistency between the environ array and the kernel's internal representation of variables.
2014-11-20 13:21:23 -06:00
Stephen Heumann 078f526df7 Fixes for terminal behavior on the GNO console 2014-11-19 12:52:05 -06:00
Stephen Heumann 2fd57a3bdc Add basic support for getting input escape sequences from termcap. 2014-11-12 23:25:01 -06:00
Stephen Heumann 5f6121c091 Add initial support for getting terminal information from termcap, instead of hard-coding vt100-style codes.
This currently only supports output, and still doesn't quite display correctly in some cases.
2014-11-11 20:58:06 -06:00
Stephen Heumann c37475dcbc Change vfork_and_run implementation to inspect the kernel's process tables to determine whether the child has really exec'd or exited.
This should avoid strange behavior due to races when the parent has resumed but the child is still running the exec* code in libc, which mainly manifests itself when running at low speed.

We also change to signaling the child's completion with SIGALRM, and setting an extra alarm in the parent in case the child doesn't actually do it.
2014-11-10 16:08:24 -06:00
Stephen Heumann 6d5e65b9df Fix corruption and hanging resulting from using _exit in forked processes by calling QuitGS directly instead.
GNO's _exit (contrary to its man page) does clean-up for stuff like the memory allocator, which is inappropriate in a forked child process and leads to hangs and crashes.
2014-11-09 18:49:58 -06:00
Stephen Heumann bff0844d44 Add code to get the path of the current executable, which we need to re-execute the shell.
On the GS, this uses GS/OS calls. Versions for OS X and Linux are also included.
2014-11-07 23:06:34 -06:00
Stephen Heumann 6bd3b140ea Misc. fixes related to file handling:
*Use .null instead of /dev/null
*Account for GNO's dup2(), which non-standardly returns 0 on success
*Always call open with appropriate number of arguments
*Use STDIN_FILENO instead of (implicitly) 0
2014-11-07 19:23:04 -06:00
Stephen Heumann cae994bc22 Add an emulation of waitpid that should be better than the one in libc.
In particular, it will buffer information about children other than the one being waited for, so it isn't lost. It can also emulate a non-blocking wait by arranging to interrupt the wait with a signal.
2014-11-07 12:12:18 -06:00
Stephen Heumann 9bc48e5ebf Add synchronization to prevent the parent from running concurrently with the child until the child execs or terminates.
Our approach is to have the parent wait for SIGUSR2, and send that from the child just before it calls exec* or _exit.
2014-11-06 23:29:42 -06:00
Stephen Heumann 3b1d003ea7 Handle globals more simply, declaring the "G" structure containing them directly in shell/hush.c.
This allows the "G" struct to show up in the debugger, so it can easily be inspected.
2014-11-06 13:08:38 -06:00
Stephen Heumann 9320c1e704 Set things up so hush can be build with debug code turned on.
This involved breaking things up into more segments in debug mode, since the code is larger. I also had to remove some unused extern definitions, which were causing link errors when debug code was enabled.

To enable debug code, pass "DEBUG=1" to make or build.gs.
2014-11-06 11:42:17 -06:00
Stephen Heumann c7f9c18893 Use GNO job control calls in place of unavailable POSIX ones. 2014-11-05 15:28:59 -06:00
Stephen Heumann a3c32aaa73 Revise terminal control code to use ioctls supported by GNO instead of termios calls that aren't supported. 2014-11-04 19:53:40 -06:00
Stephen Heumann 7e5a584f0c Use alternative code (also from BusyBox) for checking if the user is in a group, avoiding a call to getgroups(), which isn't supported.
This could actually be further simplified, since GNO doesn't really have group-based file permissions, but I'll leave that until later.
2014-11-04 16:24:41 -06:00
Michel Stam d3fabf89d7 zcip: Add environment variable for overriding log functionality
function                                             old     new   delta
bb_logenv_override                                     -      70     +70
packed_usage                                       29969   30033     +64
zcip_main                                           1426    1431      +5
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/0 up/down: 139/0)             Total: 139 bytes

Signed-off-by: Michel Stam <m.stam@fugro.nl>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-11-04 12:19:04 +01:00
Stephen Heumann 488a238ad7 Add an implementation of poll() written in terms of select(), to work around the lack of poll() on GNO.
This is a BSD-licensed poll() implementation by Brian M. Clapper. Its performance characteristics aren't as good as a "native" poll() would be, but this shouldn't be a problem in practice.
2014-11-03 12:26:43 -06:00
Stephen Heumann d4b2c3ce8b Various changes for GNO and ORCA/C compatibility. 2014-11-02 18:30:31 -06:00
Stephen Heumann 875b1bbd0e More GNO and ORCA/C compatibility fixes.
Everything in the shell directory now compiles.
2014-11-01 18:25:21 -05:00
Stephen Heumann 3577d48e74 Change the ARRAY_SIZE macro to work around an ORCA/C limitation. 2014-11-01 15:47:17 -05:00
Stephen Heumann 8f6869ae25 Miscellaneous changes for ORCA/C and GNO compatibility, mainly removing C99isms.
At this point, ORCA/C can process the main header files, and some smaller source files compile without errors.
2014-11-01 09:46:02 -05:00
Stephen Heumann b7676499be More removal of stuff that used long longs 2014-10-27 19:45:38 -05:00
Stephen Heumann 16c89af688 Change vfork calls to use vfork_and_run operation with GNO-compatible semantics 2014-10-27 13:10:11 -05:00
Stephen Heumann ef1a853400 Minimal changes to enable hush-only builds on OS X 2014-10-26 21:14:47 -05:00