Compare commits

...

917 Commits

Author SHA1 Message Date
Denys Vlasenko
ceaffde511 Bump version to 1.27.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03 13:40:46 +02:00
Denys Vlasenko
7fdb764e2e scripts/randomtest: update things which can't be tested on uclibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03 02:33:08 +02:00
Denys Vlasenko
4ee824f6ba randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-03 01:22:13 +02:00
Denys Vlasenko
48c803a206 ash: fix $HOME/.profile reading if !ASH_EXPAND_PRMT, take 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-01 23:26:12 +02:00
Denys Vlasenko
e9aba3e7ea ash: fix 'trap - 65'
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-01 21:09:27 +02:00
Denys Vlasenko
ba4fbca8a8 udhcpc6: make -O OPT work
Patch is based on work by tiggerswelt.net.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-28 19:18:17 +02:00
Denys Vlasenko
ae2b9f286c modutils: delete unused replace_underscores()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-28 19:10:29 +02:00
Denys Vlasenko
470bebe672 udhcpc6: add comments about option 39, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-27 18:31:08 +02:00
Denys Vlasenko
f56ddf2e4c ash: fix $HOME/.profile reading if !ASH_EXPAND_PRMT
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-27 17:51:07 +02:00
Denys Vlasenko
9f4b4226a4 pgrep: implement -a
function                                             old     new   delta
pgrep_main                                           640     726     +86

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-26 21:10:47 +02:00
Denys Vlasenko
234b82ca19 udhcpc6: add support for timezones
Basedon patch by Bernd Holzmüller <bernd.holzmueller@tiggerswelt.net>

function                                             old     new   delta
option_to_env                                        504     580     +76

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-26 19:42:48 +02:00
Denys Vlasenko
4add757929 pgrep: fix pgrep -flx "sleep 11" - saw "sleep 11" processes as "sleep 11 "
function                                             old     new   delta
pgrep_main                                           584     597     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-26 14:41:53 +02:00
Denys Vlasenko
1c013fae28 archival: add option -k "keep" to gzip/bzip2/lzop, add -U "nokeep" to lzop
function                                             old     new   delta
bbunpack                                             745     779     +34
lzop_main                                             93     121     +28
do_lzo_compress                                      320     328      +8
packed_usage                                       31685   31653     -32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 70/-32)             Total: 38 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-15 18:07:04 +02:00
Denys Vlasenko
5d72ae53c9 fix "ifdef ENABLE_foo": should always be "#if ENABLE_foo"
function                                             old     new   delta
pack_gzip                                           1729    1789     +60
fill_window                                          220     216      -4
static.gzip_level_config                              24       -     -24
gzip_main                                            275     192     -83
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 60/-111)           Total: -51 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-15 17:11:59 +02:00
Denys Vlasenko
45100b8d07 unshare: fix help text; select LONG_OPTS instead depending on them
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-14 16:20:02 +02:00
Assaf Gordon
62d1e98fbd setpriv: new applet
Add a minimal 'setpriv' implementation supporting the NO_NEW_PRIVS bit.
Typical usage:

    $ busybox setpriv sudo uname
    Linux
    $ busybox setpriv --nnp sudo uname
    sudo: effective uid is not 0, is /usr/bin/sudo on a file system with
    the 'nosuid' option set or an NFS file system without root privileges?

function                                             old     new   delta
packed_usage                                       31580   31685    +105
setpriv_main                                           -      87     +87
prctl                                                  -      53     +53
static.setpriv_longopts                                -      22     +22
applet_names                                        2620    2628      +8
applet_main                                         1516    1520      +4
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 3/0 up/down: 279/0)             Total: 279 bytes

Signed-off-by: Assaf Gordon <assafgordon@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-14 11:46:52 +02:00
André Draszik
2f24d30d01 iproute: support for filtering by and printing of scope
This patch adds filtering by and printing of 'scope' to the
ip route command, taken from the upstream ip command.

x86_64:
function                                             old     new   delta
iproute_list_or_flush                               1548    1674    +126
print_route                                         2394    2469     +75
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 201/0)             Total: 201 bytes

mipsel:
iproute_list_or_flush                               1952    2096    +144
print_route                                         2580    2696    +116
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/0 up/down: 260/0)             Total: 260 bytes

Signed-off-by: André Draszik <git@andred.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-13 19:59:59 +02:00
Ming Liu
978307f8a1 tar: add IF_FEATURE_* checks
A following linking error was observed:
| ==========
| archival/lib.a(tar.o): In function `tar_main':
| archival/tar.c:1168: undefined reference to `unpack_Z_stream'
| archival/tar.c:1168: undefined reference to `unpack_Z_stream'
| ld: busybox_unstripped: hidden symbol `unpack_Z_stream' isn't defined
| ld: final link failed: Bad value

this happened with clang compiler, with the following configs:
| CONFIG_TAR=y
| # CONFIG_FEATURE_SEAMLESS_Z is not set

which can be fixed by adding IF_FEATURE_* checks in.

Signed-off-by: Ming Liu <peter.x.liu@external.atlascopco.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-13 19:13:37 +02:00
Stefan Tomanek
192dce4b84 ip rule: add suppress_{prefixlength,ifgroup} options
function                                             old     new   delta
iprule_modify                                        816     887     +71
print_rule                                           610     680     +70
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 141/0)             Total: 141 bytes

Signed-off-by: Stefan Tomanek <stefan.tomanek@wertarbyte.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-06-13 19:06:09 +02:00
Youfu Zhang
6683d1cbb4 ash: fix incorrect path in describe_command
$ PATH=/extra/path:/usr/sbin:/usr/bin:/sbin:/bin \
> busybox sh -xc 'command -V ls; command -V ls; command -Vp ls; command -vp ls'
+ command -V ls
ls is /bin/ls
+ command -V ls
ls is a tracked alias for /bin/ls
+ command -Vp ls
ls is a tracked alias for (null)
+ command -vp ls
Segmentation fault

describe_command should respect `path' argument. Looking up in the hash table
may gives incorrect index in entry.u.index and finally causes incorrect output
or SIGSEGV.

function                                             old     new   delta
describe_command                                     386     313     -73

Signed-off-by: Youfu Zhang <zhangyoufu@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-26 17:37:35 +02:00
Laurent Bercot
2599937c4e ls: fix support for long options when FEATURE_LS_COLOR is deselected
Declaration of ls_longopts and initialization of applet_long_options
were incorrectly guarded with ENABLE_FEATURE_LS_COLOR; that yielded a
"ls: NO_OPT: \xff" error message when long options were selected and
color support was not. This patch ensures long options are
initialized separately from color support.

Signed-off-by: Laurent Bercot <ska-dietlibc@skarnet.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-26 16:50:53 +02:00
Denys Vlasenko
13d72c3fd9 add/remove-shell: copy /etc/shells mode to new file
function                                             old     new   delta
add_remove_shell_main                                259     300     +41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-26 16:45:28 +02:00
Denys Vlasenko
f547041940 ash,hush: fix SIGCHLD interrupting read builtin
function                                             old     new   delta
readcmd                                              169     217     +48
shell_builtin_read                                  1087    1097     +10
localcmd                                             366     364      -2
builtin_read                                         197     193      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 58/-6)              Total: 52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-22 19:34:45 +02:00
James Byrne
0c63299b84 sv: update to match version 2.1.2 of runit
Backport from upstream versions:
2.1.2
Sun, 10 Aug 2014 18:01:54 +0000
  * sv.c: properly format status command's output on failure cases.
  * sv.c: support optional LSB init script actions reload and
    try-restart.
  * sv.c: fix typo that may lead to wrong output from sv when reporting
    status of multiple service directories.

2.1.1
Sun, 04 Oct 2009 20:28:38 +0000
  * sv.c: on 'down', send runsv the 'down' command properly if not yet
    done (e.g. when taken up with 'once').

    [Remove previous workaround added to BusyBox version].

1.9.0
Mon, 05 May 2008 22:00:13 +0000
  * sv.c: service name is also relative to the current directory if it
    ends with a slash.

1.8.0
Fri, 21 Sep 2007 00:33:56 +0000
  * sv.c: fix race on check for down if pid is 0 and state is run or
    finish.

1.7.1
Sat, 04 Nov 2006 19:23:29 +0000
  * sv.c: properly wait for a service to be restarted on 'restart';
    support checks through -v for pause, cont, kill.

function                                             old     new   delta
sv                                                  1184    1280     +96
control                                              132     180     +48
status                                               118     139     +21
out                                                   64      85     +21
svstatus_print                                       334     344     +10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 196/0)             Total: 196 bytes

Signed-off-by: James Byrne <james.byrne at origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-15 21:40:18 +02:00
Denys Vlasenko
bcb5764822 runsv: update to match version 2.1.2 of runit
Backport from upstream versions:
2.1.0
Thu, 24 Sep 2009 22:49:33 +0000
  * runsv.c: exit with error if [log/]supervise/control exists, but is
    not a fifo.
    [Code abstracted into a separate function to make it more compact
    for BusyBox.]

1.9.0
Mon, 05 May 2008 22:00:13 +0000
  * runsv.c: create temporary new status files for log/supervise/
    actually in log/supervise/.

1.7.2
Tue, 21 Nov 2006 15:13:47 +0000
  * runsv.c: really don't act on commands in state finish; minor.

function                                             old     new   delta
open_control                                           -     135    +135
update_status                                        553     612     +59
custom                                               223     242     +19
ctrl                                                 426     422      -4
warn_cannot                                           21      10     -11
runsv_main                                          1786    1662    -124
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/3 up/down: 213/-139)           Total: 74 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-15 19:44:48 +02:00
Denys Vlasenko
79c0d7332a svlogd.c: support -ttt (dateTtime instead of date_time)
Backport from upstream version:
1.7.0
Sat, 07 Oct 2006 18:24:17 +0000
  * svlogd.c: new option -ttt: prefix log messages with sortable UTC
    timestamp YYYY-MM-DDTHH:MM:SS.xxxxx.

function                                             old     new   delta
svlogd_main                                         1429    1454     +25
packed_usage                                       31575   31580      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-15 19:12:09 +02:00
Denys Vlasenko
ed820ccda1 udhcpc: do not accept --background on NOMMU (same as -b)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-08 15:11:02 +02:00
Denys Vlasenko
741bfa9a72 udhcpc: fix "udhcpc -x hostname:<name> not working on nommu"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-08 15:02:07 +02:00
Denys Vlasenko
c5d16e92c1 diff: fix -N and nonexistent files. Closes 7454
function                                             old     new   delta
diffreg                                             1253    1310     +57
diff_main                                           1329    1355     +26
create_J                                            1819    1821      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 85/0)               Total: 85 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-05 18:39:22 +02:00
Denys Vlasenko
0cc9b1843d vi: survive if stdin is nonblocking. closes 9851
function                                             old     new   delta
readit                                                55      69     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-05-02 20:39:02 +02:00
Denys Vlasenko
a1a3b595e1 time: inplement -f FMT
function                                             old     new   delta
time_main                                           1076    1134     +58
packed_usage                                       31577   31572      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-28 18:01:18 +02:00
Tommi Rantala
5fe5be210c time: implement -a, -o FILE
function                                             old     new   delta
time_main                                           1052    1076     +24
packed_usage                                       31571   31577      +6

Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-28 17:54:14 +02:00
Tommi Rantala
854174f7dd time: document -p in usage
Signed-off-by: Tommi Rantala <tommi.t.rantala@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-28 17:34:32 +02:00
Markus Gothe
9c7ee1439a lsscsi: new applet
function                                             old     new   delta
lsscsi_main                                            -     326    +326
applet_names                                        2613    2620      +7
applet_main                                         1512    1516      +4
applet_install_loc                                   189     190      +1
packed_usage                                       31566   31560      -6
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/1 up/down: 338/-6)            Total: 332 bytes

Signed-off-by: Markus Gothe <nietzsche@lysator.liu.se>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-18 19:26:26 +02:00
Denys Vlasenko
10ad622dc2 Spelling fixes in comments, documentation, tests and examples
By klemens <ka7@github.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17 16:13:32 +02:00
Denys Vlasenko
d85352b4ff factor: fix stray semicolon
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17 15:57:07 +02:00
Denys Vlasenko
8352b717ce factor: support "no-argvs" usage
function                                             old     new   delta
factorize_numstr                                       -      72     +72
packed_usage                                       31562   31566      +4
factor_main                                          109     101      -8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 76/-8)              Total: 68 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-14 14:23:49 +02:00
Denys Vlasenko
44c0ab4102 libbb: fix "error: redefinition of 'is_tty_secure'"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 17:55:05 +02:00
Denys Vlasenko
107159ef1c factor: improve comments for sieving logic... also fix a typo
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 13:38:16 +02:00
Denys Vlasenko
933dcf1c8a fix "loginutils/Config.in:319 error: Overlong line"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 13:37:05 +02:00
Denys Vlasenko
021d50405b factor: improve comments for sieving logic
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 13:34:40 +02:00
Denys Vlasenko
a3de0b3b86 libbb: make check_password() also return CHECKPASS_PW_HAS_EMPTY_PASSWORD
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 13:04:05 +02:00
Denys Vlasenko
335681ca8e su: FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY
When this feature is enabled, blank passwords are not accepted by su
unless the user is on a secure TTY defined in /etc/securetty. This
resembles the default PAM configuration of some Linux distros which
specify the nullok_secure option for pam_unix.so.

Based on patch by Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 12:57:04 +02:00
Kaarle Ritvanen
517a82c5b6 login: move check_securetty to libbb
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 12:39:03 +02:00
Denys Vlasenko
c054822027 factor: tweak comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-13 10:51:13 +02:00
Denys Vlasenko
6c149f4d9a ash: implement "exec -a ARGV0 CMD ARGV1..."
function                                             old     new   delta
execcmd                                               71     112     +41
shellexec                                            221     224      +3
evalcommand                                         1158    1161      +3
localcmd                                             364     366      +2
unaliascmd                                           163     154      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 49/-9)              Total: 40 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 21:31:32 +02:00
Denys Vlasenko
e139ae307e ash: make shellexec capable of using separate argv[0] and filename to exec
function                                             old     new   delta
execcmd                                               71      78      +7
shellexec                                            221     224      +3
evalcommand                                         1158    1161      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 21:02:33 +02:00
Denys Vlasenko
352ddd3d21 Tweak GETOPT_RESET comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 20:21:34 +02:00
Kaarle Ritvanen
835ad3a984 libbb: GETOPT_RESET macro
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 20:11:34 +02:00
Denys Vlasenko
c5496d3585 grep: FEATURE_GREP_CONTEXT should be available for "fgrep only" too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 17:53:54 +02:00
Denys Vlasenko
e31ca2e9b2 catv: convert this bbox-specific applet into "cat -v"
function                                             old     new   delta
cat_main                                             150     320    +170
packed_usage                                       31511   31552     +41
applet_install_loc                                   190     189      -1
applet_main                                         1516    1512      -4
applet_names                                        2618    2613      -5
catv_main                                            227       -    -227
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/3 up/down: 211/-237)          Total: -26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 17:17:29 +02:00
Denys Vlasenko
d9eb40c185 fix errors found with make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 15:48:19 +02:00
Denys Vlasenko
0cecbe7d5d Sort more misplaced applets into coreutils or util-linux
No code changes

Surprisingly, nice and renice are coming from different packages :)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 14:16:29 +02:00
Denys Vlasenko
783d57af7b Sort some miscutils/ applets into coreutils or util-linux
No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-12 13:58:40 +02:00
Denys Vlasenko
ac47a00e2e partprobe: new applet
function                                             old     new   delta
partprobe_main                                         -      79     +79
packed_usage                                       31485   31511     +26
applet_names                                        2608    2618     +10
applet_main                                         1512    1516      +4
applet_install_loc                                   189     190      +1
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/0 up/down: 120/0)             Total: 120 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 19:17:59 +02:00
Denys Vlasenko
1bc0bd13b5 w: new applet, alias to "who -H"
function                                             old     new   delta
who_main                                             451     463     +12
packed_usage                                       31477   31485      +8
applet_main                                         1508    1512      +4
applet_names                                        2606    2608      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 26/0)               Total: 26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 18:17:03 +02:00
Denys Vlasenko
67918b32ab fallocate: new applet
NAME
       fallocate - preallocate or deallocate space to a file
SYNOPSIS
       fallocate [-c|-p|-z] [-o offset] -l length [-n] filename
       fallocate -d [-o offset] [-l length] filename
DESCRIPTION
       fallocate  is  used  to manipulate the allocated disk space for a file,
       either to deallocate or preallocate it.  For filesystems which  support
       the  fallocate system call, preallocation is done quickly by allocating
       blocks and marking them as uninitialized, requiring no IO to  the  data
       blocks.   This  is  much faster than creating a file by filling it with
       zeroes.

function                                             old     new   delta
fallocate_main                                         -     179    +179
applet_names                                        2597    2606      +9
applet_main                                         1504    1508      +4
applet_suid                                           94      95      +1
applet_install_loc                                   188     189      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 13:33:54 +02:00
Denys Vlasenko
b9512fa6b3 fsfreeze: new applet
NAME
       fsfreeze - suspend access to a filesystem (Ext3/4, ReiserFS, JFS, XFS)
SYNOPSIS
       fsfreeze --freeze|--unfreeze mountpoint
DESCRIPTION
       fsfreeze suspends or resumes access to a filesystem.
       fsfreeze halts any new access to the filesystem and creates a stable
       image on disk.
AVAILABILITY
       The fsfreeze command is part of the util-linux 2.28

function                                             old     new   delta
fsfreeze_main                                          -      81     +81
applet_names                                        2597    2606      +9
applet_main                                         1504    1508      +4
applet_suid                                           94      95      +1
applet_install_loc                                   188     189      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 11:53:05 +02:00
Denys Vlasenko
a976aaab0b factor: remove debug code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 07:50:42 +02:00
Denys Vlasenko
8a134ec680 libbb: move isqrt from factor, use it in diff too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 07:34:56 +02:00
Denys Vlasenko
10673c44f1 factor: much faster, and very slightly larger isqrt()
function                                             old     new   delta
isqrt_odd                                             70      88     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-11 07:02:42 +02:00
Denys Vlasenko
cc1f8ba489 factor: don't be too clever in isqrt - be small instead
function                                             old     new   delta
isqrt_odd                                            111      70     -41

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 18:30:35 +02:00
Denys Vlasenko
ad5394d591 factor: add code to test isqrt() correctness
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 13:53:57 +02:00
Denys Vlasenko
dd3a395053 factor: 25% faster sieving
function                                             old     new   delta
factorize                                            287     260     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 12:10:46 +02:00
Denys Vlasenko
4908c79a01 factor: better comments, slightl more clever conversion even->odd
function                                             old     new   delta
isqrt_odd                                            114     111      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 11:47:48 +02:00
Denys Vlasenko
f428f1dc6c factor: fix HALF_FMT usage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 10:13:14 +02:00
Denys Vlasenko
12dc4fbf18 factor: fix comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 00:41:11 +02:00
Denys Vlasenko
bef1713217 factor: a bit more simple isqrt
function                                             old     new   delta
isqrt_odd                                             87      80      -7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 00:28:26 +02:00
Denys Vlasenko
c6476dca54 factor: simpler isqrt
function                                             old     new   delta
isqrt_odd                                            102      87     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-10 00:24:16 +02:00
Denys Vlasenko
c804d4ec5c factor: factor2 variable is unused now, drop it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 23:19:47 +02:00
Denys Vlasenko
7e5f2f3b51 factor: expand comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 23:12:38 +02:00
Denys Vlasenko
1d232fd440 factor: 30% faster code (estimate max possible factor just once)
function                                             old     new   delta
factorize                                              -     161    +161
isqrt_odd                                              -     102    +102
factor_main                                          281     110    -171
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/1 up/down: 263/-171)           Total: 92 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 22:54:57 +02:00
Denys Vlasenko
c1b5b2a190 nl: fix copyright message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 21:19:29 +02:00
Denys Vlasenko
ee7f75d94f factor: new applet
thus far only able to factor up to ULLONG_MAX

function                                             old     new   delta
factor_main                                            -     378    +378
packed_usage                                       31427   31502     +75
applet_names                                        2590    2597      +7
applet_main                                         1500    1504      +4
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 464/0)             Total: 464 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-09 21:18:43 +02:00
Denys Vlasenko
87ae0fe095 nproc: new applet
function                                             old     new   delta
nproc_main                                             -      98     +98
applet_names                                        2584    2590      +6
applet_main                                         1496    1500      +4
applet_install_loc                                   187     188      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 21:47:53 +02:00
Denys Vlasenko
0f7f1ae094 shred: smaller code
function                                             old     new   delta
shred_main                                           361     356      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 21:10:00 +02:00
Denys Vlasenko
2f59bf39e2 shred: new applet
function                                             old     new   delta
shred_main                                             -     361    +361
packed_usage                                       31427   31467     +40
applet_names                                        2578    2584      +6
applet_main                                         1492    1496      +4
run_applet_and_exit                                  679     682      +3
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/0 up/down: 414/0)             Total: 414 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 20:45:08 +02:00
Denys Vlasenko
42776708f2 init: dont send "Sent SIGTERM to all" msg to syslog: we just TERMed it!
While at it, explain FEATURE_INIT_SYSLOG

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 19:13:09 +02:00
Denys Vlasenko
7121bb8023 ipaddress: tweak help text more: mention "brd +" syntax
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 18:22:41 +02:00
Denys Vlasenko
4eaa0f7729 ipaddress: tweak help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 18:14:46 +02:00
Denys Vlasenko
eb76abb4f7 iproute: add "a" command as a synonym to "add"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 17:33:26 +02:00
Denys Vlasenko
826bdcd51c libiproute: FACT_FUNCization
function                                             old     new   delta
get_addr_1                                           258     287     +29
next_arg                                               -      22     +22
print_neigh                                          885     902     +17
do_iplink                                           1269    1276      +7
get_unsigned                                          54      55      +1
get_u32                                               54      55      +1
get_u16                                               62      63      +1
rt_addr_n2a                                           53      52      -1
ipaddr_modify                                       1229    1226      -3
get_addr32                                            58      54      -4
invarg_1_to_2                                         18      12      -6
inet_addr_match                                      109     103      -6
duparg2                                               18      12      -6
duparg                                                18      12      -6
print_addrinfo                                      1231    1223      -8
ipneigh_list_or_flush                                724     714     -10
incomplete_command                                    10       -     -10
iproute_get                                          847     835     -12
ipaddr_list_or_flush                                1265    1253     -12
get_prefix                                           356     344     -12
do_add_or_delete                                    1162    1150     -12
get_addr                                              73      58     -15
iproute_list_or_flush                               1210    1191     -19
parse_args                                          1434    1412     -22
print_rule                                           634     610     -24
iprule_modify                                        864     816     -48
print_route                                         1621    1565     -56
iproute_modify                                      1221    1164     -57
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 6/20 up/down: 78/-349)         Total: -271 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 17:15:40 +02:00
Denys Vlasenko
d5342a1ad1 iproute: support advmss option
function                                             old     new   delta
iproute_modify                                      1164    1221     +57
str_is_lock                                            -      22     +22
packed_usage                                       31372   31382     +10
do_iproute                                           157     132     -25
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/1 up/down: 89/-25)             Total: 64 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-07 17:00:53 +02:00
Denys Vlasenko
1140bf39ab iproute: update help text, add commented-out code for unsupported options
function                                             old     new   delta
packed_usage                                       31327   31372     +45
do_iproute                                           132     157     +25
iproute_modify                                      1162    1164      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 72/0)               Total: 72 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-06 17:54:38 +02:00
Denys Vlasenko
2d4823b65b iplink: implement "set promisc on|off". Closes 4682
function                                             old     new   delta
do_iplink                                           1232    1269     +37
packed_usage                                       31337   31327     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-06 16:06:04 +02:00
Denys Vlasenko
a7386bb35b ip link: tidying up
Misplaced comment. --help was wrong: dynamic on|off is not supported.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-06 15:55:29 +02:00
Denys Vlasenko
4f0b540d08 modprobe: do not descend into /etc/modprobe.d/DIR/. Closes 8686
Also expanded comments in recursive_action.c

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-06 15:23:26 +02:00
Denys Vlasenko
0d6e3ad663 modprobe-small: fix "modprobe non-existing-module" exitcode (should be 1)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-06 13:45:00 +02:00
Ben Hutchings
803c85a207 modprobe: read modules.builtin
This allows explicit probing to succeed when the requested module
is actually built-in, and corrects the error message for removal.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-06 11:54:04 +02:00
Denys Vlasenko
9c192e7f94 examples: make udhcpc script handle /32 netmasks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-06 00:53:43 +02:00
Jody Bruchon
19578b4edf Add help text for 'uniq -i'
Signed-off-by: Jody Bruchon <jody@jodybruchon.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-05 18:51:27 +02:00
Denys Vlasenko
e7ac7abf06 nl: use CONFIG_NL, not CONFIG_UNIQ
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-05 18:31:19 +02:00
Denys Vlasenko
d88f94a5df nl: new applet; also implement cat -nb (similar functionality to nl)
function                                             old     new   delta
nl_main                                                -     201    +201
print_numbered_lines                                   -     115    +115
cat_main                                              36     149    +113
static.nl_longopts                                     -     106    +106
packed_usage                                       31081   31182    +101
applet_main                                         1488    1492      +4
applet_names                                        2575    2578      +3
applet_suid                                           93      94      +1
applet_install_loc                                   186     187      +1
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 6/0 up/down: 645/0)             Total: 645 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-05 18:17:17 +02:00
Denys Vlasenko
5d561ef634 tls: do not compile in TLS_RSA_WITH_NULL_SHA256 code if unreachable
function                                             old     new   delta
tls_handshake                                       1595    1588      -7
xwrite_encrypted                                     244     209     -35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-04 01:41:15 +02:00
Denys Vlasenko
229d3c467d tls: avoid using int16 in pstm code
function                                             old     new   delta
pstm_div                                            1472    1522     +50
psRsaEncryptPub                                      403     413     +10
pstm_2expt                                            91      96      +5
pstm_clear                                            68      72      +4
pstm_init                                             39      42      +3
pstm_unsigned_bin_size                                36      37      +1
pstm_montgomery_reduce                               398     399      +1
pstm_init_size                                        45      46      +1
pstm_zero                                             39      38      -1
pstm_set                                              35      34      -1
pstm_read_unsigned_bin                               112     109      -3
pstm_mulmod                                          123     120      -3
pstm_mod                                             116     113      -3
pstm_cmp                                              57      54      -3
pstm_sub                                             107     102      -5
pstm_to_unsigned_bin                                 157     151      -6
pstm_clamp                                            63      57      -6
pstm_add                                             116     108      -8
pstm_grow                                             81      72      -9
pstm_count_bits                                       57      48      -9
pstm_init_copy                                        84      72     -12
pstm_cmp_mag                                          93      78     -15
pstm_sqr_comba                                       567     551     -16
pstm_montgomery_calc_normalization                   158     140     -18
pstm_copy                                            115      92     -23
pstm_lshd                                            133     109     -24
pstm_mul_comba                                       525     500     -25
pstm_mul_d                                           251     224     -27
s_pstm_sub                                           256     228     -28
s_pstm_add                                           370     337     -33
pstm_div_2d                                          444     409     -35
pstm_mul_2                                           195     156     -39
pstm_rshd                                            154     104     -50
pstm_mul_2d                                          247     186     -61
pstm_exptmod                                        1524    1463     -61
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/27 up/down: 75/-524)         Total: -449 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-03 21:53:29 +02:00
Denys Vlasenko
636c3b627c tls: merge sha1 and sha256 hmac functions
function                                             old     new   delta
hmac_begin                                             -     196    +196
hmac_sha256                                           61      68      +7
hmac                                                 250      87    -163
hmac_sha256_begin                                    190       -    -190
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/1 up/down: 203/-353)         Total: -150 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-03 17:43:44 +02:00
Denys Vlasenko
6e99f1cb45 tls: replace aes encryption/decryption by much smaller one
The replacement code is ~6 times slower,
but drastically decreases size of tls_aes.o:

text	data	bss	dec	hex	filename
8050	0	0	8050	1f72	tls_aes_OLD.o
2461	0	0	2461	99d	tls_aes.o

function                                             old     new   delta
sbox                                                   -     256    +256
rsbox                                                  -     256    +256
KeyExpansion                                           -     197    +197
Subword                                                -      66     +66
AddRoundKey                                            -      61     +61
static.Rcon                                            -      10     +10
rcon                                                  40       -     -40
setup_mix                                             80       -     -80
setup_mix2                                           123       -    -123
aes_cbc_decrypt                                     1377     971    -406
aes_cbc_encrypt                                     1375     644    -731
psAesInit                                            848       -    -848
Te4                                                 1024       -   -1024
TE0                                                 1024       -   -1024
TD0                                                 1024       -   -1024
Td4                                                 1040       -   -1040
------------------------------------------------------------------------------
(add/remove: 6/8 grow/shrink: 0/2 up/down: 846/-6340)       Total: -5494 bytes

This code is based on public domain "tiny-AES128-C" code.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-01 20:11:59 +02:00
Jody Bruchon
8808f7fc2e uniq: add -i option to ignore case
Signed-off-by: Jody Bruchon <jody@jodybruchon.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-30 18:15:54 +02:00
Kang-Che Sung
257734855c Update depmod & modprobe upstream help text in comments
No code changes.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-28 18:26:21 +02:00
Denys Vlasenko
ab03061615 udhcp6: move misplaced comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-27 22:49:12 +02:00
Denys Vlasenko
ed898ed2dd udhcp6: fix releasing
Patch is based on work by tiggerswelt.net. They say:
"
We wanted udhcpc6 to release its IPv6-Addresses on
quit (-R-commandline-option) which turned out to generate once again
kind of garbage on the network-link.
We tracked this down to two issues:

 - udhcpc6 uses a variable called "srv6_buf" to send packets to
   the dhcp6-server, but this variable is never initialized correctly
   and contained kind of a garbage-address

 - The address of the dhcp6-server is usually a link-local-address,
   that requires an interface-index when using connect() on an AF_INET6-
   socket

We added an
additional parameter for ifindex to d6_send_kernel_packet() and made
d6_recv_raw_packet() to capture the address of the dhcp6-server and
forward it to its callee.
"

Three last patches together:

function                                             old     new   delta
d6_read_interface                                      -     454    +454
d6_recv_raw_packet                                     -     283    +283
option_to_env                                        249     504    +255
.rodata                                           165226  165371    +145
send_d6_discover                                     195     237     +42
send_d6_select                                       118     159     +41
send_d6_renew                                        173     186     +13
send_d6_release                                      162     173     +11
opt_req                                                -      10     +10
d6_send_kernel_packet                                304     312      +8
opt_fqdn_req                                           -       6      +6
d6_mcast_from_client_config_ifindex                   48      51      +3
d6_find_option                                        63      61      -2
udhcpc6_main                                        2416    2411      -5
static.d6_recv_raw_packet                            266       -    -266
------------------------------------------------------------------------------
(add/remove: 5/1 grow/shrink: 8/2 up/down: 1271/-273)         Total: 998 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-27 22:44:22 +02:00
Denys Vlasenko
64d58aa806 udhcp6: fix problems found running against dnsmasq
Patch is based on work by tiggerswelt.net. They say:
"
But when we tried to use dnsmasq on server-side, udhcpc6 was unable to
forward the acquired address to its setup-script although the
IPv6-Address had been assigned by the server as we could see via
tcpdump. We traced this issue down to a problem on how udhcpc6 parses
DHCPv6-Options: When moving to next option, a pointer-address is
increased and a length buffer is decreased by the length of the option.
The problem is that it is done in this order:

  option += 4 + option[3];
  len_m4 -= 4 + option[3];

But this has to be switched as the length is decreased by the length of
the *next* option, not the current one. This affected both - internal
checks if a required option is present and the function to expose
options to the environment of the setup-script.
There was also a bug parsing D6_OPT_STATUS_CODE Options, that made
dnsmasq not work as udhcpc6 thought it is receiving a non-positive
status-code (because it did not parse the status-code as required in RFC
3315).
In addition we introduced basic support for RFC 3646 (OPTION_DNS_SERVERS
and OPTION_DOMAIN_LIST) and RFC 4704 (OPTION_CLIENT_FQDN).
"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-27 22:41:59 +02:00
Denys Vlasenko
e09f5e3045 udhcp6: read_interface should save link-local ipv6 address
Patch is based on work by tiggerswelt.net. They say:
"Using this patch it was no problem to acquire an IPv6-Address via DHCPv6
using ISC DHCPD6 on server-side."

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-27 22:41:59 +02:00
Yousong Zhou
8f3bf4f0d3 vi: avoid touching a new file with ZZ when no editing has been done
This is the behaviour observed with standard vim and busybox vi of at
least 1.22.1.  It was changed with commit "32afd3a vi: some
simplifications" which happened before 1.23.0.

Mistyping filename on command line happens fairly often and it's better
we restore the old behaviour to avoid a few unnecessary flash writes and
sometimes efforts of debugging bugs caused by those unneeded stray
files.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-24 21:13:10 +01:00
Andrei Gherzan
e3b65ab43d switch_root: don't bail out when console doesn't exist
Busybox is very often used in initramfs at the end of which usually
there is a switch_root to the actual rootfs. There are many cases where
the console kernel argument is either just a placeholder (for example
RaspberryPi uses serial0 and serial1) or configured as null to avoid any
console messages - usually you would see such of a setup in production
environments.

Currently busybox bails out if can't open the console argument. If this
happenes in initramfs and if the console=null for example, you get in a
blind kernel panic. Avoid this by only warning instead of dying.

function                                             old     new   delta
switch_root_main                                     371     368      -3

Signed-off-by: Andrei Gherzan <andrei@gherzan.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-24 16:39:08 +01:00
Denys Vlasenko
876c121ccb whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-24 15:00:12 +01:00
Denys Vlasenko
f4a670a911 paste: delimiter list use should restart for each new output line
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-23 17:58:32 +01:00
Denys Vlasenko
f1db95abfb typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-23 17:41:59 +01:00
Maxime Coste
d2383f57cd paste: new applet
function                                             old     new   delta
paste_main                                             -     493    +493
packed_usage                                       31019   31070     +51
applet_names                                        2569    2575      +6
applet_main                                         1484    1488      +4
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 554/0)             Total: 554 bytes

Signed-off-by: Maxime Coste <mawww@kakoune.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-23 17:35:52 +01:00
Rostislav Skudnov
dba0dc1999 dd: call fsync() only once before exiting if conv=fsync is specified
Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-16 20:54:35 +01:00
Denys Vlasenko
a98db793cf Revert "umount: make -d always active, add -D to suppress it"
This reverts commit 86a03bee1d.

Since now our "mount -oloop" creates AUTOCLEARed loopdevs, we no longer
need our umount to destroy loopdevs to match the usual util-linux behaviour.

Now this revert fixes another, opposite bug: "explicit" mount /dev/loopN
and then umount must not drop loopdevs!

User complaint is as follows:

It seems LOOP_CLR_FD called on a loop-*partition* removes the mapping of
the whole *device* - which results in the following:

root@LEDE:/# loop=$(losetup -f)
root@LEDE:/# echo ${loop}
/dev/loop2
root@LEDE:/# losetup ${loop} /IMAGE
root@LEDE:/# ls -l ${loop}*
brw-------  1 root root     7,   2 Mar  6 20:09 /dev/loop2
root@LEDE:/# partprobe ${loop}
root@LEDE:/# ls -l ${loop}*
brw-------  1 root  root    7,   2 Mar  6 20:09 /dev/loop2
brw-------  1 root  root  259,   8 Mar  6 21:59 /dev/loop2p1
brw-------  1 root  root  259,   9 Mar  6 21:59 /dev/loop2p2
brw-------  1 root  root  259,  10 Mar  6 21:59 /dev/loop2p3
brw-------  1 root  root  259,  11 Mar  6 21:59 /dev/loop2p4
brw-------  1 root  root  259,  12 Mar  6 21:59 /dev/loop2p5
brw-------  1 root  root  259,  13 Mar  6 21:59 /dev/loop2p6
brw-------  1 root  root  259,  14 Mar  6 21:59 /dev/loop2p7
brw-------  1 root  root  259,  15 Mar  6 21:59 /dev/loop2p8
root@LEDE:/# mount ${loop}p8 /MOUNT       # mount loop partition
root@LEDE:/# losetup -a | grep $loop      # loop dev mapping still there
/dev/loop2: 0 /mnt/IMAGE
root@LEDE:/# strace umount /MOUNT 2> /log # unmount loop partition
root@LEDE:/# losetup -a | grep ${loop}    # loop device mapping is gone
root@LEDE:/# grep -i loop /log
open("/dev/loop2p7", O_RDONLY|O_LARGEFILE) = 3
ioctl(3, LOOP_CLR_FD)                   = 0
root@LEDE:/#

The strace was done to figure out, if maybe umount wrongly ioctl()'s the
parent device instead of the partition - it doesn't.

I already wasn't a fan of umount implicitly removing the mapping in the
first place (as I usually setup and release loop devices with `losetup`
and scripts needed to call umount differently in order to work and
outside busybox).

However taking above (kernel-)behaviour into account - umount calling
ioctl(LOOP_CLR_FD) unconditionally potentially causes some nasty side
effects

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-16 17:51:06 +01:00
Denys Vlasenko
ab518eea9c mount: create loop devices with LO_FLAGS_AUTOCLEAR flag
The "autolooped" mount (mount [-oloop] IMAGE /DIR/DIR)
always creates AUTOCLEARed loopdevs, so that umounting
drops them (and this does not require any code in the
umount userspace).
This happens since circa linux-2.6.25:
	commit 96c5865559cee0f9cbc5173f3c949f6ce3525581
	Date:    Wed Feb 6 01:36:27 2008 -0800
	Subject: Allow auto-destruction of loop devices
IOW: in this case, umount does not have to use -d
to drop the loopdev.

The explicit loop mount (mount /dev/loopN /DIR/DIR)
does not do this. In this case, umount without -d
should not drop loopdev.
Unfortunately, bbox umount currently always implies -d,
this probably needs fixing.

function                                             old     new   delta
set_loop                                             537     597     +60
singlemount                                         1101    1138     +37
losetup_main                                         419     432     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 110/0)             Total: 110 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-16 16:55:47 +01:00
Denys Vlasenko
018804204f runit: fix chpst -n -N -u USER
busybox's chpst first switches user/group and then tries to call nice().
Once the root priviledges are dropped, process priority can only be lowered.
So negative nice values don't work anymore.
Upstream version of chpst correctly calls nice() before switching user.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-13 22:35:30 +01:00
Denys Vlasenko
e88608eae2 vi: don't touch file with :x when modified_count == 0
Along with it, there are other changes

 - Check for uppercase X is removed as the expression will be always false and
   :X itself is another totally different command in standard vim
 - The status line will show number of written lines instead of lines requested
   by the colon command.  This is also how the standard vim is doing, though
   the difference is that '!' has to be explicitly specified in vim to allow
   partial writes

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-03-13 20:50:42 +01:00
Glenn Matthews
02a2a278f6 reset: before calling execvp(), reset needs to flush stdout
Signed-off-by: Glenn Matthews <glmatthe@cisco.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-17 23:02:06 +01:00
Kang-Che Sung
74c2215086 Fix FEATURE_{GZIP,BZIP2}_DECOMPRESS link error
... when gzip is selected but not gunzip nor zcat, or when bzip2 is
selected but not bunzip2 nor bzcat.

This regression is introduced in b130f9f758
("Allow 'gzip -d' and 'bzip2 -d' without gunzip or bunzip2")

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-17 20:15:27 +01:00
Denys Vlasenko
7c67f1e9ab udhcpc: make sure we do not overflow poll timeout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-17 19:20:32 +01:00
Denys Vlasenko
94dcfd8cc0 nc_bloaty: use poll() instead of select()
function                                             old     new   delta
readwrite                                            829     715    -114

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-17 17:48:59 +01:00
Denys Vlasenko
52a515d187 udhcp: use poll() instead of select()
function                                             old     new   delta
udhcp_sp_read                                         65      46     -19
udhcp_sp_fd_set                                       79      54     -25
udhcpd_main                                         1530    1482     -48
udhcpc_main                                         2780    2730     -50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-142)           Total: -142 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-16 23:25:44 +01:00
Denys Vlasenko
dc207f6696 udhcp: do not clobber errno by signal handler
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-16 20:04:19 +01:00
Denys Vlasenko
5b3b468ec0 nc: use poll() instead of select()
function                                             old     new   delta
nc_main                                              943     866     -77

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-16 17:17:17 +01:00
Denys Vlasenko
0ec4d08ea3 tls: covert i/o loop from using select() to poll()
function                                             old     new   delta
tls_run_copy_loop                                    377     282     -95

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-16 16:51:18 +01:00
Denys Vlasenko
c39ee04705 sendmail: allow "+" symbol in recipient. Closes 9646
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-12 21:57:22 +01:00
Kang-Che Sung
af316aabf2 modprobe-small: define and use DEPMOD_OPT_n (option mask)
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-12 21:41:24 +01:00
Kang-Che Sung
c393b1e919 modprobe-small: document '-n' in depmod usage
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-12 21:24:02 +01:00
Denys Vlasenko
c2b18583a3 modprobe_small: if only MODPROBE and DEPMOD are selected, no need to test for them
function                                             old     new   delta
modprobe_main                                        321     306     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-07 16:41:25 +01:00
Kang-Che Sung
415cc42b6a Reorder modutils config options & fix yet more dependency
- modprobe can indirectly benefit from FEATURE_2_4_MODULES and
  FEATURE_INSMOD_TRY_MAP options.
- The position of config FEATURE_INSMOD_TRY_MMAP prevented some other
  config options from indenting under FEATURE_2_4_MODULES. Reorder to
  fix this.
- FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED is now moved to
  Config.src under "Common options" section. (I wished to edit this
  config so that it also work with "big" modutils, but it's not done at
  the moment. Sorry.)

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-05 19:11:01 +01:00
Kang-Che Sung
4ae658f077 modutils: fix config options dependency (2)
- The modprobe-small implementation of rmmod no longer chdir's to
  "/lib/modules/`uname -r`" as it was not necessary for rmmod's
  operation. (And it no longer need to die if such modules directory
  doesn't exist.)
- Configs DEFAULT_MODULES_DIR and DEFAULT_DEPMOD_FILE no longer depend
  on MODPROBE_SMALL as the latter may not enable depmod or modprobe
  that requires these configs.
- Clarify DEFAULT_DEPMOD_FILE's description regarding the ".bb" name
  suffix.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-05 19:02:34 +01:00
Denys Vlasenko
8cc1ab3c11 httpd: use "Content-Length", not "-length"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-04 23:19:30 +01:00
Rostislav Skudnov
8762512fdb Replace int -> uint to avoid signed integer overflow
An example of such an error (should be compiled with DEBUG_SANITIZE):

runtime error: left shift of 1 by 31 places cannot be represented in
type 'int'

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-04 23:10:22 +01:00
Denys Vlasenko
c31b54fd81 tls: fold AES CBC en/decryption into single functions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-04 16:23:49 +01:00
Denys Vlasenko
5b05d9db29 wget/tls: session_id of zero length is ok (arxiv.org responds with such)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-03 18:23:52 +01:00
Denys Vlasenko
5f7c82b32f ash: add INT_OFF/ON around allocations
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-03 13:00:06 +01:00
Denys Vlasenko
b6871c1965 ps: avoid -o stat to contain spaces. Closes 9631
function                                             old     new   delta
procps_scan                                         1227    1236      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-02 13:04:30 +01:00
Kang-Che Sung
b1d6a2c624 cmdline module options can be disabled on "big" modutils
Allow module options on command line to be disabled on "big" modutils.

Config FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE is renamed to
FEATURE_CMDLINE_MODULE_OPTIONS and no longer depends on !MODPROBE_SMALL

(I'm not sure if disabling this is useful on "big" modutils, but at
least the macro can serve as a marker and ensure both implementations
of same feature have consistent behavior.)

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-01 10:14:05 +01:00
Kang-Che Sung
264cb01540 modutils: remove redundant "select PLATFORM_LINUX" configs
It is enough to have only applets' configs select PLATFORM_LINUX.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-01 01:43:32 +01:00
Kang-Che Sung
fdfd716a85 modprobe-small: move lsmod code out of modprobe_main()
Having lsmod code inside modprobe_main() makes some of the applet name
checking code awkward. Besides, this make busybox x86_64 binary a few
bytes smaller. :)

function                                  old     new   delta
lsmod_main                                  -      23     +23
modprobe_main                             599     564     -35
-------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 23/-35) Total: -12 bytes

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-01 01:33:37 +01:00
Denys Vlasenko
dc7637d0aa modprobe-small: improve config help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-01 01:22:37 +01:00
Felix Fietkau
b5b21126ca ash: improve / fix glob expansion
When using musl libc glob() a very long string can cause glob() to fail,
which leads to an out of memory error being raised by ash.

This can happen easily if a very long quoted string contains *, even
though no glob expansion should ever be performed on it (since it's
quoted).

Fix this by properly parsing control characters and escaping and only
accept unquoted metacharacters. While we're at it, unify this check for
libc and built-in glob expansion

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-31 21:58:55 +01:00
Denys Vlasenko
d6ace66973 taskset: simplify code a bit; tweak --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-30 22:20:06 +01:00
Denys Vlasenko
ca659f84b2 modprobe-small: fix --help texts, they are from "big" modutils
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-30 19:21:12 +01:00
Kang-Che Sung
065e988e7a modutils: fix config options dependency
module.aliases and module.symbols files have no use in modprobe-small
implementation. So FEATURE_MODUTILS_ALIAS and FEATURE_MODUTILS_SYMBOLS
will depend on !MODPROBE_SMALL.

The try_to_mmap_module() function is not called in modprobe-small.c,
so I will let FEATURE_INSMOD_TRY_MMAP depend on !MODPROBE_SMALL for
now.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>

Likewise, FEATURE_2_4_MODULES is not used by modprobe-small.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-30 19:14:50 +01:00
Denys Vlasenko
67f6db6b27 wget: add a big explanation what TLS code implements and what does not
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-30 16:27:37 +01:00
Denys Vlasenko
35b54a3c24 libbb: match_fstype() is unreadable in the extreme, fixing it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-30 00:45:05 +01:00
Denys Vlasenko
eba7fe6bb9 vi,fsck: do not use build timestamp unconditionally. Closes 9626
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-29 19:14:26 +01:00
Denys Vlasenko
86663910ba taskset: separate "current" and "new" strings
Better for constant sharing:

   text	   data	    bss	    dec	    hex	filename
 912997	    485	   6856	 920338	  e0b12	busybox_old
 912988	    485	   6856	 920329	  e0b09	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-29 18:59:38 +01:00
Denys Vlasenko
b181ca7552 typo in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-29 18:48:58 +01:00
Denys Vlasenko
ef0e76cc27 taskset: rewrite to be task size-agnostic
function                                             old     new   delta
packed_usage                                       31130   31190     +60
taskset_main                                         623     525     -98
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 60/-98)            Total: -38 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-29 18:19:29 +01:00
Denys Vlasenko
205d48e948 *: add comment about APPLET_ODDNAME format
It confused me more than once

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-29 14:57:33 +01:00
Denys Vlasenko
b4b12bf234 httpd: defend against attempts to OOM us. Closes 9611
We were strdup'ing "Cookie: foo" every time we saw it.

function                                             old     new   delta
handle_incoming_and_exit                            2733    2821     +88

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-26 19:35:40 +01:00
Denys Vlasenko
4d417709b0 adduser: help for -G GRP is misleading, fix it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-26 18:54:12 +01:00
Denys Vlasenko
786c9dc0c1 sh: fix FEATURE_SH_STANDALONE help text: it does not enable NOFORK
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-26 18:31:51 +01:00
Denys Vlasenko
9967c9949e libbb: spawn_and_wait() fflushes before forking NOEXEC; child reinits logmode
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-26 01:13:58 +01:00
Denys Vlasenko
06f20bf675 link: new applet
coreutils grew itself a tiny simplistic alternative to ln:

	Usage: link FILE LINK

	Create hard LINK to FILE

function                                             old     new   delta
link_main                                              -      75     +75
packed_usage                                       31114   31131     +17
applet_names                                        2564    2569      +5
applet_main                                         1480    1484      +4
applet_install_loc                                   185     186      +1
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 4/0 up/down: 102/0)             Total: 102 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-26 00:27:53 +01:00
Denys Vlasenko
7dd906a388 xxd: make -p output lines actually end with a newline
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 17:00:38 +01:00
Denys Vlasenko
62a9b18547 xxd: implement -p
While at it, tweaked hexdump --help

function                                             old     new   delta
xxd_main                                             364     414     +50
packed_usage                                       31097   31114     +17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 16:50:30 +01:00
Denys Vlasenko
cb8e84e65a libbb: shrink sump.c
function                                             old     new   delta
dot_flags_width_chars                                  -      16     +16
int_convs                                              -       7      +7
lcc                                                    7       -      -7
index_str                                             16       -     -16
rewrite                                             1013     937     -76
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/1 up/down: 23/-99)            Total: -76 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 16:21:00 +01:00
Denys Vlasenko
b13b618335 ftpd/ls: show directories first
Old TODO finally done

function                                             old     new   delta
ls_main                                              548     568     +20
packed_usage                                       31116   31097     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 04:52:45 +01:00
Denys Vlasenko
8a2657cbf5 hexdump/xxd: a bit more condensed formats
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 03:07:39 +01:00
Denys Vlasenko
0f4364775f xxd: new applet
Yet Another Hexdumper

function                                             old     new   delta
xxd_main                                               -     364    +364
packed_usage                                       31046   31116     +70
applet_names                                        2560    2564      +4
applet_main                                         1476    1480      +4
rewrite                                             1022    1013      -9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/1 up/down: 442/-9)            Total: 433 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-25 01:58:00 +01:00
Andrey Mozzhuhin
2181fb4af8 ftpd: new option -a ANON_USER to allow anonymous logins
Anonymous ftpd login is useful even when ftpd authentication feature
is enabled. Anonymous logins provide simple password-less connection
for FTP clients.

To allow password-less connection user command line option '-a USER' is
added. This option specifies the system user to use when
'anonymous' username is given in USER command. No password is required
in this case.

function                                             old     new   delta
ftpd_main                                           2164    2232     +68
packed_usage                                       31015   31046     +31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 99/0)               Total: 99 bytes

Signed-off-by: Andrey Mozzhuhin <amozzhuhin@yandex.ru>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24 23:04:25 +01:00
Denys Vlasenko
dff9fefd50 wget: add support for -S --server-response
Based on the patch by stephane.billiart@gmail.com

function                                             old     new   delta
ftpcmd                                                87     129     +42
fgets_and_trim                                        86     119     +33
static.wget_longopts                                 234     252     +18
packed_usage                                       31002   31015     +13
wget_main                                           2535    2540      +5
gethdr                                               158     163      +5
retrieve_file_data                                   424     428      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/0 up/down: 120/0)             Total: 120 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24 21:41:43 +01:00
Denys Vlasenko
bca4ea8b68 remove "local" bashism from a few scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24 20:52:42 +01:00
Denys Vlasenko
89193f985b tls: can download kernels now :)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24 18:08:07 +01:00
Denys Vlasenko
1500b3a50d tls: if got CERTIFICATE_REQUEST, send an empty CERTIFICATE
wolfssl test server is not satisfied by an empty one,
but some real servers might be.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24 17:06:10 +01:00
Denys Vlasenko
49ecee098d tls: add 2nd cipher_id, TLS_RSA_WITH_AES_128_CBC_SHA, so far it doesn't work
Good news that TLS_RSA_WITH_AES_256_CBC_SHA256 still works with new code ;)

This change adds inevitable extension to have different sized hashes and AES key sizes.
In libbb, md5_end() and shaX_end() are extended to return result size instead of void -
this helps *a lot* in tls (the cost is ~5 bytes per _end() function).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24 16:00:54 +01:00
Denys Vlasenko
9a64c3337c ls: convert DISP_DIRNAME to a bool variable
function                                             old     new   delta
ls_main                                              553     548      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 20:46:12 +01:00
Denys Vlasenko
ccc1699e3e ls: get rid of opt_flags[], handle -l1c through option_mask32
function                                             old     new   delta
display_single                                       885     888      +3
scan_and_display_dirs_recur                          496     486     -10
opt_flags                                             11       -     -11
ls_main                                              618     553     -65
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 3/-86)             Total: -83 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 20:43:06 +01:00
Denys Vlasenko
92c6898e10 ls: handle -x through option_mask32, remove default -C from --help
function                                             old     new   delta
packed_usage                                       31024   31002     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 20:21:14 +01:00
Denys Vlasenko
4cde4cca65 ls: handle -d and -R through option_mask32
function                                             old     new   delta
scan_and_display_dirs_recur                          545     550      +5
display_single                                      1039    1044      +5
append_char                                           67      68      +1
display_files                                        399     396      -3
ls_main                                              736     717     -19
opt_flags                                             68      11     -57
.rodata                                           168864  168784     -80
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/4 up/down: 11/-159)          Total: -148 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 20:08:22 +01:00
Denys Vlasenko
96d9c5bdbd ls: handle -p and -F through option_mask32
function                                             old     new   delta
display_single                                      1039    1044      +5
append_char                                           67      68      +1
display_files                                        399     396      -3
scan_and_display_dirs_recur                          545     541      -4
ls_main                                              736     722     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/3 up/down: 6/-21)             Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 19:56:13 +01:00
Denys Vlasenko
51b01fda30 ls: LIST_ID_NAME/ID_NUMERIC/LOPT/LONG are the same, merge as LONG
Also, handle -n and --full-time using option_mask32

function                                             old     new   delta
scan_and_display_dirs_recur                          548     545      -3
display_single                                      1053    1039     -14
ls_main                                              777     736     -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-58)             Total: -58 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 19:42:12 +01:00
Denys Vlasenko
a1cbaca1ba ls: make -Z output compatible with GNU coreutils 8.25
This also makes it clear that LIST_MODEBITS == LIST_LOPT

function                                             old     new   delta
ls_main                                              752     777     +25
display_files                                        400     399      -1
display_single                                      1055    1053      -2
my_stat                                              320     317      -3
packed_usage                                       32311   32280     -31
.rodata                                           168895  168864     -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/5 up/down: 25/-68)            Total: -43 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 19:30:14 +01:00
Denys Vlasenko
2c3131d88e ls: LIST_NLINKS/SIZE/DATE_TIME/SYMLINK are always the same, merge as LIST_LOPT
They are always set and cleared together

function                                             old     new   delta
append_char                                           69      68      -1
display_single                                       910     908      -2
ls_main                                              677     664     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-16)             Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 19:05:11 +01:00
Denys Vlasenko
5d43ddc59b ls: handle -s through option_mask32
function                                             old     new   delta
scan_and_display_dirs_recur                          493     494      +1
sort_and_display_files                               424     423      -1
ls_main                                              682     677      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 18:43:43 +01:00
Denys Vlasenko
b60686cc2a ls: handle -i through option_mask32
function                                             old     new   delta
sort_and_display_files                               420     424      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 18:34:11 +01:00
Denys Vlasenko
f5bd6f631c ls: handle -a and -A through option_mask32
function                                             old     new   delta
ls_main                                              685     682      -3

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 18:24:05 +01:00
Denys Vlasenko
11540a8da4 ls: handle all sort options through option_mask32
function                                             old     new   delta
packed_usage                                       31007   31024     +17
my_stat                                              318     324      +6
sort_and_display_files                               419     420      +1
print_name                                           216     217      +1
sortcmp                                              228     216     -12
opt_flags                                             96      64     -32
ls_main                                              732     685     -47
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/3 up/down: 25/-91)            Total: -66 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 18:01:48 +01:00
Denys Vlasenko
7a18b9502a tls: reorder tls_handshake_data fields for smaller size, tweak comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 16:37:04 +01:00
Denys Vlasenko
b5bf1913d3 tls: send EMPTY_RENEGOTIATION_INFO_SCSV in our client hello
Hoped this can make cdn.kernel.org to like us more. Nope.
While at it, made error reporting more useful.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 16:12:17 +01:00
Denys Vlasenko
9492da7e63 tls: set TLS_DEBUG to 0; placate a gcc indentation warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 01:15:13 +01:00
Denys Vlasenko
9a647c326a separate TLS code into a library, use in in wget
A new applet, ssl_client, is the TLS debug thing now.
It doubles as wget's NOMMU helper.
In MMU mode, wget still forks, but then directly calls TLS code,
without execing.

This can also be applied to sendmail/popmail (SMTPS / SMTP+starttls support)
and nc --ssl (ncat, nmap's nc clone, has such option).

function                                             old     new   delta
tls_handshake                                          -    1691   +1691
tls_run_copy_loop                                      -     443    +443
ssl_client_main                                        -     128    +128
packed_usage                                       30978   31007     +29
wget_main                                           2508    2535     +27
applet_names                                        2553    2560      +7
...
xwrite_encrypted                                     360     342     -18
tls_main                                            2127       -   -2127
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 13/8 up/down: 2351/-2195)       Total: 156 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-23 01:08:16 +01:00
Denys Vlasenko
e1f90d13fa ls: -1 should be ignored by -l (and options which imply -l)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-22 22:02:19 +01:00
Denys Vlasenko
f580baf94a ls: more correct handling of -c, -u
function                                             old     new   delta
my_stat                                              302     318     +16
packed_usage                                       30977   30969      -8
display_single                                       928     910     -18
sortcmp                                              258     228     -30
ls_main                                              776     732     -44
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/4 up/down: 16/-100)           Total: -84 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-22 19:02:57 +01:00
Denys Vlasenko
194b2ebd2a ls: replace -e with --full-time, add --group-directories-first, delete -K
-K and -e were non-standard

function                                             old     new   delta
static.ls_longopts                                     9      47     +38
ls_main                                              748     776     +28
display_single                                       901     928     +27
sortcmp                                              254     258      +4
ls_options                                            32      31      -1
opt_flags                                            100      96      -4
packed_usage                                       31032   30977     -55
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/3 up/down: 97/-60)             Total: 37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-22 17:32:20 +01:00
Denys Vlasenko
12389889c0 ip: better --help
Was:
    Usage: ip [OPTIONS] address|route|link|tunnel|neigh|rule [COMMAND]

    ip [OPTIONS] OBJECT [COMMAND]
    where OBJECT := address|route|link|tunnel|neigh|rule
    OPTIONS := -f[amily] inet|inet6|link | -o[neline]

User: instead of repeating list of OBJECTs twice, you could at least
show available COMMANDs...

Now:
    Usage: ip [OPTIONS] address|route|link|tunnel|neigh|rule [COMMAND]

    OPTIONS := -f[amily] inet|inet6|link | -o[neline]
    COMMAND :=
    ip addr add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]
    ip route list|flush|add|del|change|append|replace|test ROUTE
    ip link set IFACE [up|down] [arp on|off] | show [IFACE]
    ip tunnel add|change|del|show [NAME]
        [mode ipip|gre|sit]
        [remote ADDR] [local ADDR] [ttl TTL]
    ip neigh show|flush [to PREFIX] [dev DEV] [nud STATE]
    ip rule [list] | add|del SELECTOR ACTION

While at it, tweak tc --help too (it stays disabled, thus no effect)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-21 14:27:07 +01:00
Denys Vlasenko
8908c1d4f5 more ip --help fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-21 03:56:46 +01:00
Denys Vlasenko
f3d705f41b make --help texts smaller
function                                             old     new   delta
packed_usage                                       31035   30968     -67

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-21 03:46:57 +01:00
Denys Vlasenko
bbc7bee966 make --help texts more uniform
function                                             old     new   delta
packed_usage                                       31062   31035     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-21 02:49:58 +01:00
Denys Vlasenko
f6e20724d4 tls: reorder tls_state fields for smaller offsets
function                                             old     new   delta
xwrite_encrypted                                     363     360      -3
xwrite_and_update_handshake_hash                     117     114      -3
tls_xread_handshake_block                             72      69      -3
tls_error_die                                        211     202      -9
tls_get_outbuf                                        64      49     -15
tls_main                                            2163    2127     -36
tls_xread_record                                     702     639     -63
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-132)           Total: -132 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-21 02:08:34 +01:00
Denys Vlasenko
dd2577f21a tls: send SNI in the client hello
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 22:48:41 +01:00
Denys Vlasenko
0af5265180 tls: check size on "MAC-only, no crypt" code path too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 21:23:10 +01:00
Denys Vlasenko
54b927d78b tls: AES decrypt does one unnecessary memmove
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 21:19:38 +01:00
Denys Vlasenko
3916139ac4 tls: make input buffer grow as needed
As it turns out, it goes only up to "inbuf_size:4608"
for kernel.org - fixed 18kb buffer was x4 larger than necessary.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 20:27:06 +01:00
Denys Vlasenko
9731ca7611 password utils: improve --help, make DEFAULT_PASSWD_ALGO visible if CHPASSWD
Was:
    $ cryptpw --help
    ...
    Print crypt(3) hashed PASSWORD

        -P,--password-fd=N	Read password from fd N
        -m,--method=TYPE	Encryption method
        -S,--salt=SALT

User: "What methods exist? which one os default?"

Now:
    Print crypt(3) hashed PASSWORD

        -P,--password-fd N	Read password from fd N
        -m,--method TYPE	des,md5,sha256/512 (default des)
        -S,--salt SALT

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 19:47:49 +01:00
Denys Vlasenko
38972a8df1 tls: improve i/o loop
With tls_has_buffered_record(), entire kernel.org response
is printed at once, without 6 second pause to see its delayed EOF.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 19:11:14 +01:00
Denys Vlasenko
e7863f394e tls: was psAesDecrypt'ing one block too many, trashing buffered data
For the first time

printf "GET / HTTP/1.1\r\nHost: kernel.org\r\n\r\n" | ./busybox tls kernel.org

successfully reads entire server response and TLS shutdown.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 18:04:04 +01:00
Denys Vlasenko
6e511393f9 rdate: time(NULL) is shorter than time(&var)
function                                             old     new   delta
rdate_main                                           251     246      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 16:07:14 +01:00
Denys Vlasenko
179e88bec9 rdate: make it do something remotely sane, facing 32-bit time overflow
function                                             old     new   delta
rdate_main                                           251     254      +3
packed_usage                                       31029   31023      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 16:03:48 +01:00
Denys Vlasenko
19e695ebad tls: do not use common_bufsiz
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 14:27:58 +01:00
Denys Vlasenko
a0aae9f714 tls: decode alerts and in particular, EOF alert.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 14:12:10 +01:00
Denys Vlasenko
abbf17abcc tls: add the i/o loop - largish rework of i/o buffering
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-20 03:15:09 +01:00
Denys Vlasenko
f7806f9d8f tls: fix ROL/ROR x86 optimization
ALWAYS_INLINE:

function                                             old     new   delta
psAesInitKey                                         825     824      -1
ROR                                                    5       -      -5
setup_mix2                                           148     134     -14
psAesDecryptBlock                                   1184    1139     -45
psAesEncryptBlock                                   1193    1102     -91
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/4 up/down: 0/-156)           Total: -156 bytes

ALWAYS_INLINE + __builtin_constant_p(shift_cnt):

function                                             old     new   delta
ROR                                                    5       -      -5
psAesInitKey                                         825     818      -7
setup_mix2                                           148     123     -25
psAesDecryptBlock                                   1184    1078    -106
psAesEncryptBlock                                   1193    1017    -176
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/4 up/down: 0/-319)           Total: -319 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 16:45:41 +01:00
Denys Vlasenko
432f1ae2ff tls: tested PSTM_X86_64, not enabling it - too large
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 16:32:38 +01:00
Denys Vlasenko
6b1b004845 tls: commented out psPool_t use
function                                             old     new   delta
psAesEncrypt                                         159     162      +3
der_binary_to_pstm                                    42      40      -2
xwrite_and_hash                                      437     434      -3
xread_tls_block                                      446     443      -3
pstm_div_2d                                          449     444      -5
psAesDecrypt                                         179     174      -5
pstm_init_size                                        52      45      -7
pstm_init                                             46      39      -7
pstm_to_unsigned_bin                                 165     157      -8
tls_main                                            1265    1256      -9
pstm_mulmod                                          132     123      -9
pstm_mod                                             125     116      -9
pstm_init_copy                                        93      84      -9
psAesInitKey                                         840     825     -15
send_client_key_exchange                             362     342     -20
psAesInit                                            103      80     -23
psRsaEncryptPub                                      429     403     -26
psAesDecryptBlock                                   1211    1184     -27
psAesEncryptBlock                                   1223    1193     -30
pstm_exptmod                                        1582    1524     -58
pstm_div                                            1557    1472     -85
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/20 up/down: 3/-360)          Total: -357 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 15:51:00 +01:00
Denys Vlasenko
1bfc4b85a7 ntpd: print result of hostname resolution
This is particularly useful if hostname resolution is triggered by
host non-reachability: I saw this in real-life, without the message
it is not at all obvious that IP that we use for a specific host
has changed.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 14:42:34 +01:00
Denys Vlasenko
704c606f48 fdisk: add typical values of -H and -S to --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 14:29:42 +01:00
Denys Vlasenko
cccf8e735d tls: teach it to decrypt AES256-encrypted data
This adds decryption only.
There is no MAC verification, code simply throws away MAC.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 00:20:45 +01:00
Denys Vlasenko
a9e1866806 tls: trim comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-18 21:00:23 +01:00
Denys Vlasenko
b5dfc3dfd6 tls: teach it to send AES256-encrypted data
>> CLIENT_HELLO
wrote 50 bytes
insize:0 tail:0
got block len:74
got HANDSHAKE
<< SERVER_HELLO
insize:79 tail:0
got block len:2397
got HANDSHAKE
<< CERTIFICATE
key bytes:271, first:0x00
server_rsa_pub_key.size:256
insize:2402 tail:0
got block len:4
got HANDSHAKE
<< SERVER_HELLO_DONE
>> CLIENT_KEY_EXCHANGE
wrote 267 bytes
master secret:c51df5b1e3b3f57373cdd8ea28e8ce562059636cf9f585d0b89c7f4bacec97e674d7b91f93e7b500cb64637f240c3b78
client_write_MAC_key:3b0b7e2bab241b629c37eb3a3824f09b39fe71a00876b0c8026dda16ef0d2f82
client_write_key:d36e801470ed2f0a8fc886ac25df57ffbe4265d06e3192122c4ef4df1e32fab2
>> CHANGE_CIPHER_SPEC
from secret: c51df5b1e3b3f57373cdd8ea28e8ce562059636cf9f585d0b89c7f4bacec97e674d7b91f93e7b500cb64637f240c3b78
from labelSeed: 636c69656e742066696e6973686564b22e0e6008b8ee218cc02e4a93e4a42b570535f9b57662e262d43b379d125b69
=> digest: a45bfee8ed6507a2a9920d0c
>> FINISHED
before crypt: 5 hdr + 16 data + 32 hash bytes
writing 5 + 16 IV + 64 encrypted bytes, padding_length:0x0f
wrote 85 bytes
insize:9 tail:0
got block len:1
<< CHANGE_CIPHER_SPEC
insize:6 tail:0
got block len:80
< hdr_type:22 ver:3.3 len:80 type:21 len24:9541723 |1591985b...a3da|

The last line is the server's FINISHED response, encrypted.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-18 20:37:24 +01:00
Denys Vlasenko
b7e9ae6e9f tls: added AES code and made it compile. not used yet
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-18 17:20:27 +01:00
Denys Vlasenko
c8ba23bcec tls: massage writing for encryption support; finer-grained debug
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-18 06:45:50 +01:00
Denys Vlasenko
5d1662ea1c tls: address one easy FIXME, tidy up comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-17 18:17:27 +01:00
Denys Vlasenko
e69d78c038 tls: process CHANGE_CIPHER_SPEC and FINISHED from server
Successfully finishes handshake with test servers using NULL-SHA256
cipher.

The "only" thing remaining before there is a chance
this can actually work with real servers is AES encrypt/decrypt.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-17 17:24:11 +01:00
Denys Vlasenko
fe0588df3b tls: rearrange function order, improve comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-17 17:04:24 +01:00
Denys Vlasenko
e2cb3b990f tls: make our send_client_finished() pass server check
sha256 hash should be calculated over incoming handshake packets too!

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-17 16:53:36 +01:00
Denys Vlasenko
9a6897a48a tls: format FINISHED message properly for unencrypted, but sha256 signed mode
Now it at least looks correct, but unfortunately "openssl s_server"
says my hash is wrong.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-16 23:26:33 +01:00
Denys Vlasenko
4e08a123b0 Assorted warning fixes and added a comment, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-16 17:31:05 +01:00
Denys Vlasenko
936e83e694 tls: add sha256 hmac and prf code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-16 04:25:01 +01:00
Denys Vlasenko
6c73aaff38 cryptpw: support "rounds=NNNNNNN$" thing in salts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-15 21:48:31 +01:00
Denys Vlasenko
16e7f697f8 libbb: eliminate redundant variable in sha_crypt
function                                             old     new   delta
sha_crypt                                           1136    1130      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-15 20:59:32 +01:00
Denys Vlasenko
b8935d00b0 sha512: use larger constant table only if sha512 is in fact selected
function                                             old     new   delta
sha_K                                                640     256    -384

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-15 20:16:27 +01:00
Denys Vlasenko
3f8ecd933a tls: rearrange code, add/improve comments, fix whitespace, no real changes here
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-15 14:16:51 +01:00
Denys Vlasenko
c5540d61f6 tls: send CHANGE_CIPHER_SPEC
To "actually implement it" will take more work...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-15 02:17:03 +01:00
Denys Vlasenko
f78ad0938b whitespace fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-15 00:18:22 +01:00
Denys Vlasenko
11d0096516 tls: format and send CLIENT_KEY_EXCHANGE
$ ./busybox tls kernel.org
insize:0 tail:0
got block len:74
got HANDSHAKE
got SERVER_HELLO
insize:79 tail:4265
got block len:4392
got HANDSHAKE
got CERTIFICATE
entered der @0x8b217a7:0x30 len:1452 inner_byte @0x8b217ab:0x30
entered der @0x8b217ab:0x30 len:1172 inner_byte @0x8b217af:0xa0
skipped der 0xa0, next byte 0x02
skipped der 0x02, next byte 0x30
skipped der 0x30, next byte 0x30
skipped der 0x30, next byte 0x30
skipped der 0x30, next byte 0x30
skipped der 0x30, next byte 0x30
entered der @0x8b218b4:0x30 len:418 inner_byte @0x8b218b8:0x30
skipped der 0x30, next byte 0x03
entered der @0x8b218c7:0x03 len:399 inner_byte @0x8b218cb:0x00
key bytes:399, first:0x00
entered der @0x8b218cc:0x30 len:394 inner_byte @0x8b218d0:0x02
binary bytes:385, first:0x00
skipped der 0x02, next byte 0x02
binary bytes:3, first:0x01
server_rsa_pub_key.size:384
insize:4397 tail:9
got block len:4
got SERVER_HELLO_DONE
insize:9 tail:0
^C

Next step: send CHANGE_CIPHER_SPEC... and actually implement it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-15 00:12:42 +01:00
Denys Vlasenko
2a17d1fc9b tls: DER length byte 0x81 is actually valid
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-14 22:38:25 +01:00
Denys Vlasenko
b1003f7019 tls: a bit more work
$ ./busybox tls kernel.org
insize:0 tail:0
got block len:74
got HANDSHAKE
got SERVER_HELLO
insize:79 tail:4406
got block len:4392
got HANDSHAKE
got CERTIFICATE
entered der @0x8f7e723:0x30 len:1452 inner_byte @0x8f7e727:0x30
entered der @0x8f7e727:0x30 len:1172 inner_byte @0x8f7e72b:0xa0
skipped der 0xa0, next byte 0x02
skipped der 0x02, next byte 0x30
skipped der 0x30, next byte 0x30
skipped der 0x30, next byte 0x30
skipped der 0x30, next byte 0x30
skipped der 0x30, next byte 0x30
entered der @0x8f7e830:0x30 len:418 inner_byte @0x8f7e834:0x30
skipped der 0x30, next byte 0x03
entered der @0x8f7e843:0x03 len:399 inner_byte @0x8f7e847:0x00
copying key bytes:399, first:0x00
insize:4397 tail:9
got block len:4
got SERVER_HELLO_DONE

Now need to teach it to send ClientKeyExchange...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-14 13:57:16 +01:00
Denys Vlasenko
ceff6b0ea9 tls: work-in-progress TLS1.2 test applet
function                                             old     new   delta
tls_main                                               -     733    +733
dump                                                   -     230    +230
xread_tls_block                                        -     180    +180
get_der_len                                            -      76     +76
enter_der_item                                         -      70     +70
skip_der_item                                          -      56     +56
get24be                                                -      24     +24
tls_error_die                                          -      19     +19
packed_usage                                       31010   31027     +17
applet_names                                        2549    2553      +4
applet_main                                         1472    1476      +4
applet_suid                                           92      93      +1
applet_install_loc                                   184     185      +1
------------------------------------------------------------------------------
(add/remove: 9/0 grow/shrink: 5/0 up/down: 1415/0)           Total: 1415 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-14 12:49:32 +01:00
Denys Vlasenko
a6f8651911 wget: fix for brain-damaged HTTP servers. Closes 9471
write(3, "GET / HTTP/1.1\r\nUser-Agent: Wget\r\nConnection: close\r\n\r\n", 74) = 74
shutdown(3, SHUT_WR)    = 0
alarm(900)              = 900
read(3, "", 1024)       = 0
write(2, "wget: error getting response\n", 29) = 29
exit(1)

The peer simply does not return anything. It closes its connection.

Probably it detects wget closing its writing end: shutdown(3, SHUT_WR).

The point it, closing write side of the socket is _valid_ for HTTP.
wget sent the full request, it won't be sending anything more:
it will only receive the response, and that's it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 20:16:45 +01:00
Denys Vlasenko
098b713c7b ash: commented-out possible fix for 7694
bash has a feature: it restores termios after a successful wait for
a foreground job which had at least one stopped or sigkilled member.
The probable rationale is that SIGSTOP and SIGKILL can preclude task from
properly restoring tty state. Should we do this too?
A reproducer: ^Z an interactive python:

$ python
Python 2.7.12 (...)
>>> ^Z
    { python leaves tty in -icanon -echo state. We do survive that... }
 [1]+  Stopped                    python
    { ...however, next program (python no.2) does not survive it well: }
$ python
Python 2.7.12 (...)
>>> Traceback (most recent call last):
    { above, I typed "qwerty<CR>", but -echo state is still in effect }
  File "<stdin>", line 1, in <module>
NameError: name 'qwerty' is not defined

The implementation is modeled on bash code and seems to work.
However, I'm not sure we should do this. For one: what if I'd fg
the stopped python instead? It'll be confused by "restored" tty state.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 19:59:03 +01:00
Denys Vlasenko
4c179373e0 ash: 16-bit ->nprocs field is a pain for many CPUs
function                                             old     new   delta
getoptscmd                                           527     540     +13
getjob                                               280     286      +6
makejob                                              278     282      +4
forkchild                                            602     600      -2
waitcmd                                              208     205      -3
showjob                                              382     379      -3
getstatus                                             83      80      -3
dowait                                               408     405      -3
freejob                                               93      89      -4
fg_bgcmd                                             290     286      -4
forkshell                                            260     255      -5
killcmd                                              224     218      -6
jobno                                                 17      11      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/10 up/down: 23/-39)           Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 18:44:15 +01:00
Denys Vlasenko
ed15dde60a Move FEATURE_AUTOWIDTH config option to two applets which use it
No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 16:35:52 +01:00
Denys Vlasenko
6c1f348fa7 Move FEATURE_USE_TERMIOS config option to two applets which use it
No code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 16:27:12 +01:00
Denys Vlasenko
01ccdd1d3c libbb: consolidate the code to set termios unbuffered mode
function                                             old     new   delta
set_termios_to_raw                                     -     116    +116
count_lines                                           72      74      +2
powertop_main                                       1458    1430     -28
top_main                                             943     914     -29
more_main                                            759     714     -45
fsck_minix_main                                     2969    2921     -48
conspy_main                                         1197    1135     -62
rawmode                                               99      36     -63
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 118/-275)         Total: -157 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 16:17:59 +01:00
Denys Vlasenko
8944c67b1f hush: reinstate [[ builtin
Mike deleted it:

    commit 39456a18a1
    Author: Mike Frysinger <vapier@gentoo.org>
    Date:   Sat Mar 28 12:21:57 2009 +0000

    stop lying about [[ test support

probably because it was not properly ifdefed around, and was enabled
even when bash compat is off.

I just tested it - it works:

$ [ *.diff = z.diff ]; echo $?
0
$ [[ *.diff = z.diff ]]; echo $?
1

Of course, not all numerous bash tricks of [[ ]] are implemented...

function                                             old     new   delta
bltins2                                               60      72     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 14:22:00 +01:00
Kang-Che Sung
027d3ab57d hush: split bash compatible extensions into separate defines. No code changes
Splitting these options makes it self-documenting about what
bash-compatible features we have.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 14:18:30 +01:00
Denys Vlasenko
7d4aec0c3e ash: split bash compatible extensions into separate defines. No code changes
Splitting these options makes it self-documenting about what
bash-compatible features we have.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 14:00:38 +01:00
Denys Vlasenko
a8a075acfe busybox: stop depending on FEATURE_AUTOWIDTH for applet list
Many other appletw don't - they unconditionally use get_terminal_wodth(),
and here the amount of code saved by FEATURE_AUTOWIDTH=n is tiny.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 10:52:24 +01:00
Denys Vlasenko
0fd9fb4244 top: FEATURE_USE_TERMIOS shouldn't control reading of screen size
It controls whether we take input.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 10:50:08 +01:00
Denys Vlasenko
c5891fe1af more: hardcode FEATURE_USE_TERMIOS=y in this applet; code shrink
function                                             old     new   delta
get_wh                                                 -      27     +27
tcsetattr_tty_TCSANOW                                  -      18     +18
gotsig                                                35      27      -8
more_main                                            835     759     -76
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 45/-84)            Total: -39 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-11 10:38:52 +01:00
Denys Vlasenko
80f806cac9 hush: shorten output of "help" builtin
text	   data	    bss	    dec	    hex	filename
 891272	    485	   6856	 898613	  db635	busybox_old
 891232	    485	   6856	 898573	  db60d	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 16:51:10 +01:00
Denys Vlasenko
a1184af5f8 hush: reorder builtins (cd and pwd ought to be close, etc), no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 15:58:02 +01:00
Denys Vlasenko
f35ad3bd12 init: rename FEATURE_EXTRA_QUIET -> FEATURE_INIT_QUIET
The former name had no INIT anywhere in its name, sounded generic

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 15:24:13 +01:00
Denys Vlasenko
2b4c258e74 ash: revert "make dot command search current directory first"
Reverts this:
    commit 8ad78e1ec7
    Author: Denis Vlasenko <vda.linux@googlemail.com>
    Date:   Sun Feb 15 12:40:30 2009 +0000
    ash: make dot command search current directory first, as bash does.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 15:18:38 +01:00
Denys Vlasenko
265062d59d shells: make hush test optional, rename ASH_BUILTIN_foo -> ASH_foo
This makes hash and ash more symmetrical wrt config menu and config
options.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 15:13:30 +01:00
Denys Vlasenko
f560422fa0 Big cleanup in config help and description
Redundant help texts (one which only repeats the description)
are deleted.

Descriptions and help texts are trimmed.

Some config options are moved, even across menus.

No config option _names_ are changed.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 14:58:54 +01:00
Kang-Che Sung
f10f7a21d4 Allow FAST_FUNC to be overridden at build time
Busybox uses FAST_FUNC macro to tweak with IA-32 calling conventions in
order to make the function call slightly smaller or slightly faster.
However, when I experiment with GCC's LTO (Link Time Optimization), I
discovered that FAST_FUNC could hinder LTO's optimization so that the
resulting executable become a few bytes larger (than what is compiled
without FAST_FUNC).

This change allows to specify e.g.
	CONFIG_EXTRA_CFLAGS="-DFAST_FUNC= -flto"
and compile with LTO without a source code hack.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 18:52:32 +01:00
Kang-Che Sung
61a91af63d kill: optimizations for single-applet build
* Fix a bug with a configuration in which the shell's kill builtin
  would be mistreated as a killall command (i.e. '-q' works, and
  'kill process_name' succeeds when it shouldn't):

    CONFIG_ASH_JOB_CONTROL=y
    CONFIG_HUSH_KILL=y
    # CONFIG_KILL is not set
    CONFIG_KILLALL=y
    # CONFIG_KILLALL5 is not set

* Optimize out unneeded code when the relevant applets are not
  selected.

* Move kbuild lines about shells' kill builtins from Kbuild.src to
  kill.c, to accompany the new HAVE_SH_KILL macro. I hope this would
  make maintanence a little bit easier.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 18:46:58 +01:00
Denys Vlasenko
1cc6804f69 hush: make echo builtin optional
It's a bit overkill (who would want it off?) but ash already has it
configurable. Let's be symmetric.

Also tweak kbuild logic to use ASH_BUILTIN_ECHO to select echo.o,
not ASH.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 17:10:04 +01:00
Kang-Che Sung
53487a8d22 kill: need not build kill.c when ash's job control is off
ash kill builtin depends on the job control config option.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 17:02:51 +01:00
Denys Vlasenko
e7b54d0fcc make_single_applets.sh: show errors and warnings
While at it, fix one warning in modprobe-small.c

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 16:31:21 +01:00
Denys Vlasenko
590402bb55 unlzma: expand comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 14:28:25 +01:00
Denys Vlasenko
3989e5adf4 unlzma: fix erroneous "while" instead of "if". Closes 4682
These parts of the code essentially check whether
stepping back by rep0 goes negative or not.

LZMA SDK from lzma1604.7z has the following in the corresponding places:

... = dic[dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0)]

Clearly, not loop here.

Technically, "while" here works: if condition is false (because pos
underflowed), it iterates once, adds header.dict_size (a.k.a. dicBufSize),
this makes pos positive but smaller than header.dict_size, and loop exits.

Now we'll just check for negative result of subtraction, which is less code:

function                                             old     new   delta
unpack_lzma_stream                                  2659    2641     -18

(I hope 2 Gbyte+ dictionaries won't be in use soon).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 14:02:55 +01:00
Denys Vlasenko
8c1d857d25 unzip: match "Defl:?" display with info-zip; cosmetic code shuffling
Large nested indented code blocks made more sane with a few gotos.

function                                             old     new   delta
unzip_main                                          2491    2519     +28

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 13:10:10 +01:00
Denys Vlasenko
6b4f4b5284 unzip: optional support for xz
function                                             old     new   delta
unzip_main                                          2476    2491     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 11:12:01 +01:00
Denys Vlasenko
2a0867a5ed unzip: optional support for bzip2 and lzma
function                                             old     new   delta
unzip_main                                          2376    2476    +100
bbunpack                                             750     745      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 10:58:37 +01:00
Denys Vlasenko
6bf52b615d modprobe-small: build fixes
Was throwing some build errors:

CONFIG_MODPROBE_SMALL=y
CONFIG_DEPMOD=y
CONFIG_LSMOD=y
CONFIG_MODINFO=y
CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y

error: unused variable 'exitcode'

modutils/modprobe-small.c: In function 'modprobe_main':
modutils/modprobe-small.c:1060: error: control reaches end of non-void function

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 09:48:58 +01:00
Explorer09
80172e4622 modprobe-small: optimizations for single applet build
(I'm requesting for a review first because I fear such an aggressive
change could lead to bugs. While I observe the sizes have reduced, I
haven't test the functionality of each applet after that. So please
test before merging.)

Aggressively cut off unneeded code when the relevant applets are not
built.

Correct dependencies of FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE and
FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED.

Don't bother with the '-r' option check if only rmmod is built (assume
true then), or when neither rmmod or mobprobe is built (assume false
then).

Size comparison before and after the change (single applet
configuration):

     text    data     bss     dec     hex filename
    34778     946     112   35836    8bfc old/busybox_DEPMOD
    34151     946     112   35209    8989 new/busybox_DEPMOD

    34903     946     112   35961    8c79 old/busybox_INSMOD
    28316     778     112   29206    7216 new/busybox_INSMOD

    35228     962     112   36302    8dce old/busybox_LSMOD
     5011     706      40    5757    167d new/busybox_LSMOD

    34830     946     112   35888    8c30 old/busybox_MODPROBE
    34795     946     112   35853    8c0d new/busybox_MODPROBE

    34718     946     112   35776    8bc0 old/busybox_RMMOD
     7502     714     104    8320    2080 new/busybox_RMMOD

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 09:31:17 +01:00
Kang-Che Sung
b130f9f758 Allow 'gzip -d' and 'bzip2 -d' without gunzip or bunzip2
Idea copied from the "ip" applet.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 09:03:31 +01:00
Denys Vlasenko
fb87d93d1e ash: fix a bug in argv restoration after sourcing a file
if sourced file "shift"ed argvs so that $1 is NULL, restore wasn't done.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 08:22:06 +01:00
Denys Vlasenko
2b1559056c hush: fix a bug in argv restoration after sourcing a file
if sourced file "shift"ed argvs so that $1 is NULL, restore wasn't done.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 08:13:21 +01:00
Denys Vlasenko
4e4f88e569 hush: global_args_malloced is used only if set builtin is enabled
function                                             old     new   delta
run_pipe                                            1623    1635     +12
builtin_source                                       210     222     +12
save_and_replace_G_args                               70      60     -10
builtin_shift                                        132      94     -38
restore_G_args                                        98       -     -98
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/2 up/down: 24/-146)          Total: -122 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 07:57:38 +01:00
Denys Vlasenko
cc2fd5a986 hush: fix 'defined but not used' warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 06:19:55 +01:00
Denys Vlasenko
5362cc4b8c hush: remove redundand test for ENABLE_HUSH_JOB
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 05:57:13 +01:00
Denys Vlasenko
fd68f1e80d hush: fix kill builtin without jobs support
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 05:47:57 +01:00
Denys Vlasenko
442a414d66 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 05:11:09 +01:00
Denys Vlasenko
41ade05cac hush: conditionalize print_escaped() on EXPORT || TRAP
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:56:24 +01:00
Denys Vlasenko
4471969db2 hush: make memleak builtin optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:44:41 +01:00
Denys Vlasenko
6ec76d8719 hush: make export builtin optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:40:41 +01:00
Denys Vlasenko
d5933b1125 hush: make umask builtin optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:31:39 +01:00
Denys Vlasenko
10d5ece64a hush: make set/unset builtins optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 18:28:43 +01:00
Denys Vlasenko
7a85c60e7e hush: make read and trap builtins optional
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 17:40:18 +01:00
Denys Vlasenko
1125d7d680 hush: kill builtin and kill %jobspec support
Also made it and printf, type and wait builtins optional.

function                                             old     new   delta
builtin_kill                                           -     323    +323
bltins1                                              336     348     +12
builtin_type                                         114     116      +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 337/0)             Total: 337 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 17:19:38 +01:00
Denys Vlasenko
d5b5c2fa15 hush: support %%, %+ and % jobspec (meaning "current job")
function                                             old     new   delta
parse_jobspec                                         83     133     +50
builtin_wait                                         278     283      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 15:46:04 +01:00
Laurent Bercot
0ef478f01b httpd: fix address family for reverse proxy client socket
When httpd proxies a request to another server, it first creates
an AF_INET socket, then resolves the server name to a sockaddr,
then connects to it. This fails if the server name resolves to
an IPv6 address.

This patch ensures that the socket is created with the correct
address family (AF_INET6 if the server resolves to an IPv6 address
and AF_INET otherwise).

Signed-off-by: Laurent Bercot <ska-dietlibc@skarnet.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 15:14:38 +01:00
Kang-Che Sung
4d06b31453 build system: no longer prompt for PLATFORM_LINUX option
With the new "select PLATFORM_LINUX" mechanism
(commit e3b1a1fd28), the PLATFORM_LINUX
option alone no longer has any purpose of changing program behavior or
affecting compiled code. So there is no longer need to prompt user of
this config question.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 14:43:54 +01:00
Kang-Che Sung
d5e7ff0292 bunzip2: fix code bloat caused by zcat's seamless magic
This example single-applet configuration would trigger the bloat:

    CONFIG_FEATURE_SEAMLESS_XZ=y
    CONFIG_FEATURE_SEAMLESS_LZMA=y
    CONFIG_FEATURE_SEAMLESS_BZ2=y
    CONFIG_FEATURE_SEAMLESS_GZ=y
    CONFIG_BUNZIP2=y
    # CONFIG_ZCAT is not set
    # All other applets disabled

Here, the resulting "busybox-bunzip2" binary would contain
unpack_gz_stream, unpack_lzma_stream and unpack_xz_stream functions
code. In other words, the gzip, lzma and xz decompressors' code are
linked into the binary unnecessarily.

This happens because SEAMLESS_MAGIC != 0 and compiler is unable
to figure out that SEAMLESS_MAGIC bit is never set.

Fix this by disabling SEAMLESS_MAGIC option flag (setting its value
to 0) when zcat is disabled. This will help the compiler optimize out
bbunpack() and no longer generate open_zipped() function call.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 14:31:06 +01:00
Kang-Che Sung
a474728e82 ash: fix "kill %1" not working if CONFIG_ASH is disabled
ix ash "kill %1" not working if CONFIG_ASH is disabled but
ash is launched by 'sh' or 'bash' name

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 14:27:34 +01:00
Denys Vlasenko
0ffac1cc22 unzip: do not use CDF.extra_len, read local file header. Closes 9536
While at it, shorten many field and variable names.

function                                             old     new   delta
unzip_main                                          2334    2376     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-08 14:14:19 +01:00
Denys Vlasenko
86584e134e ash: fix open fds leaking in redirects. Closes 9561
commit e19923f665 deleted clearredir()
call in shellexec():

	ash: [REDIR] Remove redundant CLOEXEC calls
	Upstream commit:

	Now that we're marking file descriptors as CLOEXEC in savefd, we no longer
	need to close them on exec or in setinputfd.

but it missed one place where we don't set CLOEXEC. Fixing this.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-07 10:16:56 +01:00
Denys Vlasenko
fe93624fb6 Automatically disable FEATURE_COMPRESS_USAGE for small builds.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-06 19:16:36 +01:00
Kang-Che Sung
6cd0294725 ash: explicltly group ash options
This would makes all ash options indented inside "ash" in menuconfig.
It appears that menuconfig has a limit at tracking multiple dependency
lines like this (it looks like a "diamond problem" but I'm not sure if
it is):

               ---ASH <----------
              /                  \       ASH_OPTIMIZE_FOR_SIZE
    !NOMMU <-*----SH_IS_ASH <----[OR] <--ASH_INTERNAL_GLOB
              \                  /       ASH_RANDOM_SUPPORT
               ---BASH_IS_ASH <--        [...]

The kconfig-language document [1] states that:

> If a menu entry somehow depends on the previous entry, it can be
> made a submenu of it. First, the previous (parent) symbol must be
> part of the dependency list and then one of these two conditions
> must be true:
> - the child entry must become invisible, if the parent is set to 'n'

    [BusyBox ash used to satisfy this, but no longer does]

> - the child entry must only be visible, if the parent is visible

    [BusyBox ash configs actually satisfy this, but because of
     "diamond" above this might not be easily detected]

So I found out a direct workaround: by making ash options explicitly
depend on !NOMMU, we can tell menuconfig that rule 2 above is satisfied
without any more tracking.

               ---------------------
              /                     \
    !NOMMU <-*-----ASH <--------     \
              \                 \     \        ASH_OPTIMIZE_FOR_SIZE
               *---SH_IS_ASH <---[OR]-[AND] <--ASH_INTERNAL_GLOB
                \                /             ASH_RANDOM_SUPPORT
                 --BASH_IS_ASH <-              [...]

So all ash options would now be indented under "ash".

[1] "Documentation/kbuild/kconfig-language.txt" in Linux kernel source

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-06 17:03:18 +01:00
Natanael Copa
b62ea34afe ntpd: improve postponed hostname resolution
Run the namelookup from the main loop so a misspelled first ntp server
name does not block everything forever.

This fixes the following situation which would block forever:
  $ sudo ./busybox ntpd -dn -p foobar  -p pool.ntp.org
  ntpd: bad address 'foobar'
  ntpd: bad address 'foobar'
  ntpd: bad address 'foobar'
  ...

New behavior:
  ntpd: bad address 'foobar'
  ntpd: sending query to 137.190.2.4
  ntpd: reply from 137.190.2.4: offset:-1.009775 delay:0.175550 status:0x24 strat:1 refid:0x00535047 rootdelay:0.000000 reach:0x01
  ntpd: sending query to 137.190.2.4
  ntpd: reply from 137.190.2.4: offset:-1.009605 delay:0.175461 status:0x24 strat:1 refid:0x00535047 rootdelay:0.000000 reach:0x03
  ntpd: sending query to 137.190.2.4
  ntpd: reply from 137.190.2.4: offset:-1.005327 delay:0.167027 status:0x24 strat:1 refid:0x00535047 rootdelay:0.000000 reach:0x07
  ntpd: sending query to 137.190.2.4
  ntpd: bad address 'foobar'
  ntpd: reply from 137.190.2.4: offset:-1.046349 delay:0.248705 status:0x24 strat:1 refid:0x00535047 rootdelay:0.000000 reach:0x0f

This patch is based on Kaarle Ritvanens work.
http://lists.busybox.net/pipermail/busybox/2016-May/084197.html

function                                             old     new   delta
ntpd_main                                           1061    1079     +18
ntp_init                                             556     560      +4
resolve_peer_hostname                                 81      75      -6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 22/-6)              Total: 16 bytes

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-06 16:21:09 +01:00
Cristian Ionescu-Idbohrn
e6add210b2 unzip: remove now-pointless lseek which returns current position
archival/unzip.c: In function 'read_next_cdf':
archival/unzip.c:271:8: warning: variable 'org' set but
                                 not used [-Wunused-but-set-variable]
  off_t org;
        ^~~

Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-05 19:07:54 +01:00
Denys Vlasenko
ecba2944d5 typo fix in config help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-05 11:47:28 +01:00
Denys Vlasenko
e3c4db8b39 unzip: properly use CDF to find compressed files. Closes 9536
function                                             old     new   delta
unzip_main                                          2437    2350     -87

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-05 11:43:53 +01:00
Waldemar Brodkorb
9c083f599a modutils: remove special handling of uClibc
Commit 3a45b87ac3 (modutils: support finit_module syscall) introduced
macro finit_module. But it is not defined for uClibc.

The compilation for busybox fails for MIPS with:
With uClibc, we get following build errors:

  modutils/lib.a(modutils.o): In function `bb_init_module':
  modutils.c:(.text.bb_init_module+0x94): undefined reference to `finit_module'
  modutils.c:(.text.bb_init_module+0xa0): undefined reference to `finit_module'

We can just use syscall() without any need for the
uClibc wrappers.

Newer versions of uClibc-ng (>1.0.20) will remove the
module syscall wrappers.

Found via Buildroot autobuilders:
http://autobuild.buildroot.net/results/556/55655daef23788fb3967f801ec8b79e9bed7122b/build-end.log

function                                             old     new   delta
bb_delete_module                                      26      32      +6
bb_init_module                                        90      95      +5
delete_module                                         37       -     -37
init_module                                           53       -     -53
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 2/0 up/down: 11/-90)            Total: -79 bytes

Reported-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-04 13:32:09 +01:00
Kang-Che Sung
9529115c4c shell: clarify help text of CONFIG_{SH,BASH}_IS_* options
Mention the behavior if user selects CONFIG_SH_IS_ASH but not
CONFIG_ASH. We will be explicit that invocations like "busybox ash"
will not work for such configuration.

Also clarify help text of CONFIG_BASH_IS_* that bash compatibility in
ash is not complete. (It shouldn't be anyway - ash can't support every
bash quirk out there.)

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-04 12:29:04 +01:00
Denys Vlasenko
c6137ba510 udhcp: tweak config order and menu item names
All other applets are listed simply by their name, no reason why
dumpleases doesn't do that.

Group all udhcpd feature options directly after it.

Put "NOT READY" into udhcpc6 item (some users actually tried to use it,
and complained).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-04 12:13:38 +01:00
Jörg Krause
c6725b0af6 Fix dependency for IFUPDOWN_UDHCPC_CMD_OPTIONS
Commit a8c696bf09 makes ifup and ifdown
individually selectable, but forgets to update the dependency to
IFUPDOWN_UDHCPC_CMD_OPTIONS, so it is not selectable anymore.

This patch fixes the dependency by checking for IFUP or IFDOWN, instead
of the obsolete IFUPDOWN.

Also, it drops dependency on UDHCPC: udhcpc on the target system
does not have to come from the _same_ binary.

Signed-off-by: Jörg Krause <joerg.krause@embedded.rocks>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-03 12:29:52 +01:00
Tito Ragusa
d3720828ea README_distro_proposal.txt: typo fixes
Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-03 12:25:18 +01:00
Cristian Ionescu-Idbohrn
f1d76b64a0 appletlib: avoid warning on unused function ingroup
libbb/appletlib.c:558:12: warning: 'ingroup' defined but
                                   not used [-Wunused-function]
 static int ingroup(uid_t u, gid_t g)
            ^~~~~~~

That function is used only if FEATURE_SUID_CONFIG is also enabled.

Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-03 12:01:15 +01:00
Denys Vlasenko
b05bcaf29c hush: correct exitcode for unterminated ')' - exitcode2.tests testcase
function                                             old     new   delta
parse_stream                                        2595    2609     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-03 11:47:50 +01:00
Ron Yorston
ea7d2f6ec0 ash: fix error code regression
The commit 'ash,hush: set exit code 127 in "sh /does/not/exist" case'
only partly implemented the dash commit '[ERROR] Allow the originator
of EXERROR to set the exit status'.  This resulted in incorrect error
codes for a syntax error:

   $ )
   $ echo $?
   0

or a redirection error for a special builtin:

   $ rm -f xxx
   $ eval cat <xxx
   $ echo $?
   0

Signed-off-by: Ron Yorston <rmy@pobox.com>
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-03 11:18:23 +01:00
Denys Vlasenko
bddbeb82bf qemu_multiarch_testing: small improvements
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-02 13:48:06 +01:00
Denys Vlasenko
7890035452 tcpudp: define SO_ORIGINAL_DST directly, not via include
musl does not like including linux/netfilter_ipv4.h
(enum / #define collision in two headers, resulting in "3 = 3"
type situation in enum definition).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-02 10:46:08 +01:00
Denys Vlasenko
1f71014fd6 depmod: don't build it if MODPROBE_SMALL=y
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:12:48 +01:00
Denys Vlasenko
96f1d6b70c Update to examples/var_service/README_distro_proposal.txt
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-25 20:41:00 +01:00
Denys Vlasenko
7d5c881bd0 make_single_applets.sh: SH_IS_HUSH needs special handling too
Well, in fact it works (make oldconfig throws only a warning when it sees
both SH_IS_HUSH=y and SH_IS_NONE=y), but let's be nice.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 19:42:53 +01:00
Denys Vlasenko
0b8835861b Make it possible to select "sh" and "bash" aliases without selecting ash or hush
The same can be done for msh, but we are probably better off just deleting it
in a next versio or two.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 16:56:43 +01:00
Denys Vlasenko
04c1a2a2c4 Make RMMOD=y by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 15:57:26 +01:00
Denys Vlasenko
3bf4d69250 Make INSMOD=y by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 15:22:44 +01:00
Denys Vlasenko
100aea8486 Remove FEATURE_IFUPDOWN_IP_BUILTIN and FEATURE_IFUPDOWN_IFCONFIG_BUILTIN
They merely enable ip or ifconfig/route. There is already a way to do this
on the same menuconfig page.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 15:20:16 +01:00
Denys Vlasenko
a1cd0d9849 modprobe-small: make applets individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 15:13:16 +01:00
Denys Vlasenko
ce3a98a222 Make DPKG=y and DPKG_DEB=y by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 13:52:53 +01:00
Denys Vlasenko
4ea0ebdd42 Selinux complains about deprecated selinux/flask.h, stop including it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 13:52:13 +01:00
Denys Vlasenko
1afa494fd1 Make FEATURE_USERNAME_COMPLETION=y by default
This matches bash behavior on Fedora

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 13:40:24 +01:00
Denys Vlasenko
10c01a711f make_single_applets.sh: a tool to check single-applet builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 13:39:22 +01:00
Denys Vlasenko
9cc3d3ab21 fix breakage found by mass one-applet builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-23 02:42:26 +01:00
Denys Vlasenko
7c5dea399b ip: make ip aliases individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-22 22:30:13 +01:00
Denys Vlasenko
5d27cb3640 Make POST upload example script easier to use
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-22 15:33:11 +01:00
Denys Vlasenko
6704746c69 shell: move "config" blocks above their use in coditional includes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-22 15:21:58 +01:00
Denys Vlasenko
4acd393eba Update information on building httpd and wget helpers
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-22 15:13:37 +01:00
Denys Vlasenko
326edc3e37 Tweak some config defaults; fix MODPROBE_SMALL ordering in "make config"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-22 14:36:49 +01:00
Denys Vlasenko
2166952ec3 ash: clarify uclibc glob() bug in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-21 21:04:16 +01:00
Denys Vlasenko
3a4cdf45f9 ash: error out if ASH_INTERNAL_GLOB is not selected on uClibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-21 04:13:23 +01:00
Denys Vlasenko
b5b1d2c5a8 Start 1.27.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-21 03:33:42 +01:00
Denys Vlasenko
dc3701d2e7 Bump version to 1.26.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-20 03:00:43 +01:00
Lukasz Nowak
b42107f215 libiproute: handle table ids larger than 255
Linux kernel, starting from 2.6.19 allows ip table ids to have 32-bit values.
In order to preserve compatibility, the old 8-bit field: rtm_table is still
in use when table id is lower than 256.

Add support for the 32-bit table id (RTA_TABLE attribute) in:
- ip route print
- ip route modify
- ip rule print
- ip rule modify

Add printing of table ids to ip route.

Changes are compatible with the mainline iproute2 utilities.

These changes are required for compatibility with ConnMan, which by default
uses table ids greater than 255.

function                                             old     new   delta
print_route                                         1588    1637     +49
do_iproute                                          2187    2222     +35
do_iprule                                            955     987     +32
print_rule                                           617     630     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 129/0)             Total: 129 bytes

Signed-off-by: Lukasz Nowak <lnowak@tycoint.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-18 18:56:49 +01:00
Denys Vlasenko
e184a88356 df: implement -B n<suff> and -B <suff> formats of -B option
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 19:56:31 +01:00
Denys Vlasenko
76de3257f7 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 19:17:12 +01:00
Denys Vlasenko
2fe66b1d2d ash: fix signed char expansion bug
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 17:39:12 +01:00
Denys Vlasenko
b6afcc7819 shell: suppress "unused var/func" warnings on some configs
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 16:30:20 +01:00
Denys Vlasenko
4f13a70507 suppress glibc "use sysmacros.h for major" warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 16:29:32 +01:00
Denys Vlasenko
df25df784f randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 14:33:53 +01:00
Denys Vlasenko
de912f0153 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 11:08:51 +01:00
Denys Vlasenko
52ae098011 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-12 09:26:16 +01:00
Denys Vlasenko
ac5d324540 randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-10 20:57:00 +01:00
Mike Frysinger
c6f35241b3 selinux: drop deprecated headers
The selinux guys want you to get class values at runtime by converting
textual names into constants.  Drop the deprecated headers and switch
to the new format.

This API has been around for years, so there shouldn't be an issue
with backwards compatibility.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-12-09 18:30:30 -05:00
Mike Frysinger
1cda879080 setfiles: fix build failure after common_bufsiz change
Commit 47cfbf32fd ("*: add most of the
required setup_common_bufsiz() calls") switched this tool over to use
the common_bufsiz logic but missed including the header leading to a
build failure when enabled:
selinux/setfiles.c:80:30: error: 'bb_common_bufsiz1' undeclared (first use in this function)

URL: https://bugs.gentoo.org/600106
Reported-by: Jonas Jelten <jj@stusta.net>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-12-09 18:14:12 -05:00
Mike Frysinger
2098c3511c mdev.conf: rename hw_random to hwrng
The kernel broke the name years ago, but didn't notice until it was much
too late.  Rename the node to match expectations of userland software,
and what the kernel itself documents in its Kconfig help:
	This provides a device that's usually called /dev/hwrng, ...

URL: https://marc.info/?l=linux-crypto-vger&m=144249767024990&w=2
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-12-09 16:12:15 -05:00
Denys Vlasenko
548620c18b randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-08 12:24:48 +01:00
Denys Vlasenko
4051a99f5f svc: new applet (daemontools-compatible version of "sv")
function                                             old     new   delta
sv                                                     -    1199   +1199
svc_main                                               -     145    +145
packed_usage                                       30255   30364    +109
applet_names                                        2437    2441      +4
applet_main                                         1420    1424      +4
find_applet_by_name                                  125     126      +1
sv_main                                             1201       9   -1192
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/1 up/down: 1462/-1192)        Total: 270 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-05 13:56:40 +01:00
Denys Vlasenko
4bd0c2ab38 fix musl problem with dirname, now for all users of bb_make_directory()
function                                             old     new   delta
bb_make_directory                                    412     419      +7
install_main                                         793     769     -24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-24)             Total: -17 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-04 10:42:07 +01:00
Denys Vlasenko
fdb4421e00 README_distro_proposal.txt: writeup about runit adoption
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-03 14:06:55 +01:00
Denys Vlasenko
718e4fd564 top: fix help text: with !TERMIOS, no keys are affected top output
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-03 12:09:50 +01:00
Denys Vlasenko
cf2600c366 install: fix musl problem with dirname
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-12-03 11:49:23 +01:00
Denys Vlasenko
7d877fc931 Do not print useless empty line after list of applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-28 01:29:28 +01:00
Denys Vlasenko
1d3a04a3a4 Code style fixes, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-28 01:22:57 +01:00
Denys Vlasenko
038a977d47 lineedit: simplify code a bit
function                                             old     new   delta
lineedit_read_key                                    155     162      +7
put_prompt                                            51      46      -5
read_line_input                                     3722    3715      -7
cmdedit_setwidth                                      81      50     -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 7/-43)             Total: -36 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-28 01:10:16 +01:00
Denys Vlasenko
2c769c69b2 makedevs: make special node creation idempotent
When makedevs is called for a second time with the same device file,
it fails because the files already exist and mknod() gives -EEXIST.

Ignore EEXIST errors.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27 23:27:54 +01:00
Denys Vlasenko
bff71d3b9d lineedit: fix two bugs in SIGWINCH signal handling
(1) restore entire sigaction, not only signal handler function
(2) do not use stdio when not sure WINCH did not interrupt a printf() or such.

function                                             old     new   delta
cmdedit_setwidth                                       -      81     +81
read_line_input                                     3682    3722     +40
lineedit_read_key                                    138     155     +17
put_prompt                                            55      51      -4
win_changed                                           93      47     -46
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 138/-50)            Total: 88 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27 22:25:07 +01:00
Denys Vlasenko
710b6ce9b0 fdisk_gpt: simplify GPT partition name printing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27 20:47:01 +01:00
Denys Vlasenko
29516ac0e4 fdisk: sanitize partition name printing; drop "Code" column; get rid of one static var
function                                             old     new   delta
list_table                                          2335    2373     +38
fill_bounds                                          131     128      -3
part_array_len                                         4       -      -4
get_boot                                            1584    1574     -10
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/2 up/down: 38/-17)             Total: 21 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27 06:13:43 +01:00
Denys Vlasenko
351ab8278e dpkg-deb: shorten code, improve help text
function                                             old     new   delta
packed_usage                                       30261   30236     -25
dpkg_deb_main                                        437     401     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-61)             Total: -61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27 04:48:53 +01:00
Denys Vlasenko
6747bdac88 dpkg-deb: remove unused FEATURE_DPKG_DEB_EXTRACT_ONLY config option
Its usage in C code was removed in 2004.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-27 03:57:08 +01:00
Denys Vlasenko
ccc9985c45 find: fix handling of trailing slashes in -name PATTERN comparisons
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-25 20:14:33 +01:00
Denys Vlasenko
4b89d512b1 ash,hush: make ^C in interactive mode visually much closer to bash behavior
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-25 03:41:03 +01:00
Denys Vlasenko
24860fa09c Move FEATURE_BUFFERS_USE_foo options to library tuning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24 22:30:52 +01:00
Denys Vlasenko
1255925a61 Move locale, unicode, and "use sendfile?" options to library tuning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24 22:18:55 +01:00
Denys Vlasenko
336022663a Collapse three levers of menuconfig to two levels.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24 22:08:12 +01:00
Denys Vlasenko
8660aeb312 ash,hush: ^C from command line should set $? to 128+SIGINT
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24 17:44:02 +01:00
Rostislav Skudnov
2e4ef38743 lineedit: fix handling of repeating Alt-b, Alt-f, Alt-d, Alt-Backspace
These key combinations should repeat correctly when the keys are
pressed and held.

Before this change, they do this erratically - many repeats are "eaten"
because they are treated as unrecognized ESC seqs:
ESC 0x7f is treated by Alt+baskspace, but ESC 0x7f ESC 0x7f ESC 0x7f
is unrecognized.

Escape sequences corresponding to these key combinations are moved from
read_line_input to lineedit_read_key.

Also, these key sequences are now enabled regardless of whether
FEATURE_EDITING_VI is set, since Vim does not actually support these key
combinations, but they are present in readline library.

function                                             old     new   delta
static.esccmds                                        93     103     +10
read_line_input                                     3737    3687     -50

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24 15:04:00 +01:00
Aaro Koskinen
cb810c48c0 patch: fix matching failure
Fix matching failure when plist is advanced while checking for buffered
lines - the lines in the hunk that are about to be added should be
skipped when checking for matching context.

Also add a valid test case that fails with current busybox and is fixed
by the change.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24 11:40:36 +01:00
Aaro Koskinen
2eff59667d patch: fix debug log failure
If we reach the end of plist it means the input has still data while we
are expecting EOF. Fix the log to avoid a crash.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-24 11:38:56 +01:00
Denys Vlasenko
5bbee27c0f Remove outdated comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 21:51:11 +01:00
Denys Vlasenko
f7683cdf83 Convert all udhcp applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 18:54:59 +01:00
Denys Vlasenko
a8e52da774 Convert all selinux/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 18:46:40 +01:00
Denys Vlasenko
15fb91cefb test: make [ and [[ forms individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 18:31:48 +01:00
Denys Vlasenko
73f743a381 Remove remnants of disabled "length" applet
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 14:54:38 +01:00
Denys Vlasenko
7caf1369f5 Make dos2unix/unix2dos independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 14:52:19 +01:00
Denys Vlasenko
af3f420116 Convert all coreutils/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 14:46:56 +01:00
Denys Vlasenko
5b966c6180 Make "hd" independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 11:53:12 +01:00
Denys Vlasenko
dd898c9f33 Convert all util-linux/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 11:46:32 +01:00
Denys Vlasenko
e5dd71f94f Remove trailing empty lines
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 10:43:39 +01:00
Denys Vlasenko
6d9329935c Convert all console-tools/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 10:39:27 +01:00
Denys Vlasenko
c19f7584e1 Convert all mailutils/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 09:58:03 +01:00
Denys Vlasenko
29e2c45a5b tc: consolidate its disabled bits
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 09:51:33 +01:00
Denys Vlasenko
8342397801 Make ping6 and traceroute6 selectable independently from ping/traceroute
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 09:25:57 +01:00
Denys Vlasenko
6bfab0c49f ipneigh: add this shortcur similar to other "ip <CMD>" shortcuts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 09:18:05 +01:00
Denys Vlasenko
3148e0c05b Rename FEATURE_FTP_WRITE and FEATURE_FTP_AUTHENTICATION to *_FTPD_*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 09:07:44 +01:00
Denys Vlasenko
47367e1d50 Convert all networking/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 09:05:14 +01:00
Denys Vlasenko
e32b64c4ec Convert all modutils/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 07:54:52 +01:00
Denys Vlasenko
5467d268f0 Make killall and killall5 selecatable independent from kill
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 06:43:46 +01:00
Denys Vlasenko
f8f81ed7aa Convert all procps/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-23 06:23:44 +01:00
Denys Vlasenko
f88e3bfa8d Convert all miscutils/* applets to "new style" applet definitions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-22 23:54:17 +01:00
Denys Vlasenko
fb4da16711 Split miscutils/Config.src items into miscutils/*.c files
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-22 23:14:24 +01:00
Denys Vlasenko
9f8eb1ee76 httpd: explain why we use sprintf and why it should be fine
While at it, fix a pathological case where it is not fine:
-r REALM with some 8-kbyte long REALM would overflow the buffer.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-22 02:23:35 +01:00
Denys Vlasenko
7e8218f9b2 Fix allnoconfig warnings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-18 21:42:44 +01:00
Denys Vlasenko
f4d0f4e7a9 applets.h.sh: a script to check applet names against config options
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-17 15:34:16 +01:00
Denys Vlasenko
10880cc20f Make mkfs.vfat and mkdosfs individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-16 16:18:50 +01:00
Denys Vlasenko
0581a2f304 Make mke2fs and mkfs.ext2 individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-16 16:12:11 +01:00
Denys Vlasenko
eb3fdc843e Make bzcat, lzcat, xzcat, zcat, lzopcat, unlzop individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-16 15:45:05 +01:00
Denys Vlasenko
a8c696bf09 Make ifup and ifdown individually selectable.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-14 18:31:07 +01:00
Denys Vlasenko
f417ffd88f Make swapon and swapoff individually selectable.
For example, without swapoff, code shrinks by 277 bytes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-14 17:30:50 +01:00
Denys Vlasenko
1924e99ad3 Make grep/egrep/fgrep independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-14 05:09:48 +01:00
Denys Vlasenko
97e9a72c71 Make halt/poweroff/reboot independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-14 04:55:04 +01:00
Denys Vlasenko
c314ca9016 Make setarch/linux32/linux64 independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-13 22:56:04 +01:00
Denys Vlasenko
67fd2f2858 dnsdomainname: split it from "hostname", make it independently selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-13 22:35:10 +01:00
Denys Vlasenko
9655f95d0f tar: handle pax-encoded utf8 filenames and link names. Closes 9406
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-11 17:56:45 +01:00
Denys Vlasenko
87e039d016 hush: make getch/peek functions directly called
Indirect calls are more difficult to predict.
Unfortunately, on x64 direct call is 5 bytes while indirect "call (reg+ofs)"
is 3 bytes:

function                                             old     new   delta
i_getch                                                -      82     +82
i_peek                                                 -      63     +63
parse_stream                                        2531    2579     +48
parse_dollar                                         771     797     +26
parse_redirect                                       296     321     +25
add_till_closing_bracket                             408     420     +12
encode_string                                        256     265      +9
i_peek_and_eat_bkslash_nl                             93      99      +6
add_till_backquote                                   110     114      +4
parse_and_run_stream                                 139     141      +2
expand_vars_to_list                                 1143    1144      +1
static_peek                                            6       -      -6
setup_string_in_str                                   39      18     -21
setup_file_in_str                                     40      19     -21
static_get                                            27       -     -27
file_peek                                             52       -     -52
file_get                                              65       -     -65
------------------------------------------------------------------------------
(add/remove: 2/4 grow/shrink: 9/2 up/down: 278/-192)           Total: 86 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 22:35:05 +01:00
Denys Vlasenko
00a06b9715 hush: renumber PIPE_foo, make PIPE_SEQ = 0
PIPE_SEQ is used most often, having it zero makes code smaller:

function                                             old     new   delta
done_word                                            719     707     -12
parse_stream                                        2546    2531     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 20:35:53 +01:00
Denys Vlasenko
6c635d62d4 hush: small optimization in run_list
I thought gcc can detect this itself. It doesn't.

function                                             old     new   delta
run_list                                            1030    1021      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 20:26:11 +01:00
Denys Vlasenko
5cc9bf6a21 hush: deindent large block of code, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 17:34:44 +01:00
Denys Vlasenko
1eada9ad8d hush: simplify insert_bg_jobs
function                                             old     new   delta
insert_bg_job                                        366     281     -85

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 17:28:45 +01:00
Denys Vlasenko
830ea35484 hush: make "wait %1" less likely to play with signal mask
Was playing with "sleep 3 | exit 3 & wait %1" and noticed that often
SIGCHLD arrives even before I get to signal masking. Can avoid it in this
case.

function                                             old     new   delta
wait_for_child_or_signal                             228     265     +37

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 04:59:11 +01:00
Denys Vlasenko
02affb4afd hush: rework "wait %jobspec" to work in non-interactive shells too
Also add tests. wait5.tests so far fails (but works for ash and dash).

function                                             old     new   delta
builtin_wait                                         305     283     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 00:59:29 +01:00
Denys Vlasenko
26ad94bedc hush: "wait $!; echo $?" should return 127 if $! already exited
It would be nice to provide bash-like "remember las exitcode"
thingy, but it's a bit complex. For now, match ash and dash.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-07 23:07:21 +01:00
Denys Vlasenko
62b717b75e hush: implement "wait %jobspec"
function                                             old     new   delta
parse_jobspec                                          -      83     +83
job_exited_or_stopped                                  -      79     +79
builtin_wait                                         236     302     +66
wait_for_child_or_signal                             199     228     +29
checkjobs                                            142     158     +16
builtin_jobs                                          59      68      +9
process_wait_result                                  453     408     -45
builtin_fg_bg                                        272     203     -69
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/2 up/down: 282/-114)          Total: 168 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-07 22:12:18 +01:00
Denys Vlasenko
4e1c8b4f6a hush: factor out %jobspec parsing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-07 20:06:40 +01:00
Denys Vlasenko
5d5a611df2 hush: comment fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-07 19:36:50 +01:00
Denys Vlasenko
4224647c8d hush: do not allow sh -c '{ echo boo }'
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-07 16:22:35 +01:00
Aaro Koskinen
46443a383c cpio: add ownership (-R) test cases
Add ownership (-R) test cases.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-04 22:32:46 +01:00
Denys Vlasenko
aeaee43d5a hush: case logic for setting $? was still wrong
Resetting to 0 should happen in "esac". Matched branch must
still see previous $?.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-04 20:14:04 +01:00
Denys Vlasenko
30bfcf612b hush: non-matching "case" statement sets $? to 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-04 18:52:48 +01:00
Denys Vlasenko
672a55e606 hush: allow { cmd } to not be terminated by semicolon in some cases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-04 18:46:14 +01:00
Denys Vlasenko
06b114900f ash: fix "duplicate local" code (forgot to re-enable interrupts)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-04 16:43:18 +01:00
Denys Vlasenko
834aba3b72 comment and readme updates
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-04 14:13:58 +01:00
Denys Vlasenko
79e2598c48 su: expand help; simplify passing of -c CMD to run_shell()
Also, added a comment about bug 9401 (TIOCSTI input injection).

function                                             old     new   delta
packed_usage                                       30909   30932     +23
su_main                                              470     487     +17
sulogin_main                                         260     258      -2
run_applet_and_exit                                  681     678      -3
run_shell                                            166     126     -40

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-03 22:13:08 +01:00
Denys Vlasenko
2b288236e8 loadfont: 32k size limit is not enough
Since our "read to malloced buf" routines only gradually grow
allocations, let's be generous here and allow 128k.

Reported by Alex Henrie <alexhenrie24@gmail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-03 20:57:37 +01:00
Denys Vlasenko
1ab7c2fc6d ash: while (!got_sig) pause() is not reliable, use sigsuspend()
dash was doing it for a reason. Unfortunately, it had no comment why...
now I know.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-03 20:22:54 +01:00
Denys Vlasenko
2e6af54971 man: remove -Tascii from nroff invocation
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-31 14:05:34 +01:00
Denys Vlasenko
7c3c92c533 man: make width selection more thorough; explain how to override it
Fedora's "man CMD >file" still uses terminal width, not 80 (but disables formatting),
this change mimics that.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-31 01:52:18 +01:00
Denys Vlasenko
a92a74961d man: allow nroff and tbl commands be overridden; unmangle writing to files
Parse this in config files:
	 DEFINE col ...
	 DEFINE tbl ...
	 DEFINE nroff ...
Add width options to nroff command line.
Use "tbl", not "gtbl", as default tbl command.
Export GROFF_NO_SGR=1 and use "col -b -p -x" instead of pager when writing to file.

function                                             old     new   delta
man_main                                             735     863    +128
if_redefined                                           -      64     +64
show_manpage                                         199     169     -30
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/1 up/down: 192/-30)           Total: 162 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-30 22:31:30 +01:00
Denys Vlasenko
d4f3db9427 ash: if using libc glob(), skip it if no metachars are in word
This saves making tons of pointless stat() calls

function                                             old     new   delta
expandarg                                            888     921     +33

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-30 18:41:01 +01:00
Denys Vlasenko
474ed06c39 ash: fix bit-rotten debug infrastructure
DEBUG = 2 output was a bit messed up

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-30 18:30:29 +01:00
Denys Vlasenko
493b9cae80 ash: make popfile() anfter popallfiles() safe
In this example:

	ash -c 'readonly x; echo $(command eval x=2)'

evalstring() is called after forkchild(), which calls popallfiles().
On exception, evalstring() will popfile().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-30 18:27:14 +01:00
Denys Vlasenko
9db74e49e5 hush: fix "(sleep 1; exit 3) & sleep 2; echo $?; wait $!; echo $?"
"wait $!" may be just a bit too late: backgrounded $! is gone.
Do not bomb out in this case.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-28 22:39:12 +02:00
Denys Vlasenko
7e6753609d hush: fix "wait PID"
It was not properly interruptible, and did not update job status
(the exited processes were still thought of as running).

function                                             old     new   delta
process_wait_result                                    -     453    +453
wait_for_child_or_signal                               -     199    +199
run_list                                             996    1002      +6
checkjobs_and_fg_shell                                41      43      +2
builtin_wait                                         328     215    -113
checkjobs                                            516     142    -374
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/2 up/down: 660/-487)          Total: 173 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-28 21:59:09 +02:00
Denys Vlasenko
8f7b0248ad ash: use pause(), not sigsuspend(), in wait builtin
Same effect, smaller code

function                                             old     new   delta
dowait                                               463     374     -89

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-28 17:16:11 +02:00
Denys Vlasenko
d81e9f5093 ash: fix interactive "command eval STRING" exiting on errors.
This bug is also present in current dash

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-28 15:43:50 +02:00
Denys Vlasenko
458c1f218b ash: [JOBS] Fix dowait signal race
Upstream commit:

    Date: Sun, 22 Feb 2009 18:10:01 +0800
    [JOBS] Fix dowait signal race

    This test program by Alexey Gladkov can cause dash to enter an
    infinite loop in waitcmd.

    #!/bin/dash
    trap "echo TRAP" USR1
    stub() {
        echo ">>> STUB $1" >&2
        sleep $1
        echo "<<< STUB $1" >&2
        kill -USR1 $$
    }
    stub 3 &
    stub 2 &
    until { echo "###"; wait; } do
    echo "*** $?"
    done

    The problem is that if we get a signal after the wait3 system
    call has returned but before we get to INTON in dowait, then
    we can jump back up to the top and lose the exit status.  So
    if we then wait for the job that has just exited, then it'll
    stay there forever.

    I made the original change that caused this bug to fix pretty
    much the same bug but in the opposite direction.  That is, if
    we get a signal after we enter wait3 but before we hit the kernel
    then it too can cause the wait to go on forever (assuming the
    child doesn't exit).

    In fact this is pretty much exactly the scenario that you'll
    find in glibc's documentation on pause().  The solution is given
    there too, in the form of sigsuspend, which is the only way to
    do the check and wait atomically.

    So this patch fixes Alexey's race without reintroducing the old
    bug by converting the blocking wait3 to a sigsuspend.

    In order to do this we need to set a signal handler for SIGCHLD,
    so the code has been modified to always do that.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

I failed to reproduce the bug (it requires precise timing), but it seems real.

function                                             old     new   delta
dowait                                               284     463    +179
setsignal                                            301     326     +25
signal_handler                                        59      76     +17
ash_main                                            1481    1487      +6
localcmd                                             350     348      -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 227/-2)            Total: 225 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 23:51:19 +02:00
Denys Vlasenko
c0663c7cd2 ash: [SIGNAL] Remove EXSIG
Upstream commit 1:

    Date: Sun, 22 Feb 2009 18:16:13 +0800
    [SIGNAL] Remove EXSIG

    Now that waitcmd no longer uses EXSIG we can remove it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Upstream commit 2:

    Date: Thu, 2 Oct 2014 21:07:55 +0800
    [ERROR] Set exitstatus in onint

    Currently the exit status when we receive SIGINT is set in evalcommand
    which means that it doesn't always get set.  For example, if you press
    CTRL-C at the prompt of an interactive dash, the exit status is not
    set to 130 as it is in many other Bourne shells.

    This patch fixes this by moving the setting of the exit status into
    onint which also simplifies evalcommand.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Upstream commit 3:

    Date: Fri, 3 Oct 2014 14:07:07 +0800
    [EVAL] Do not clobber exitstatus in evalcommand

    All originators of EXERROR have been setting the exitstatus for
    a while now.  So it is no longer appropriate to set it explicitly
    in evalcommand.

    In fact doing so may cause the original exitstatus to be lost.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Last three coomits:
function                                             old     new   delta
waitcmd                                              186     224     +38
dowait                                               276     284      +8
waitforjob                                           104     107      +3
localcmd                                             348     350      +2
showjobs                                              64      61      -3
forkshell                                            263     260      -3
raise_interrupt                                       93      67     -26
blocking_wait_with_raise_on_sig                       40       -     -40
evalcommand                                         1264    1208     -56
evaltree                                             809     498    -311

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 21:13:49 +02:00
Denys Vlasenko
6918811014 ash: open-code blocking_dowait_with_raise_on_sig()
There is in fact only one callsite.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 21:13:24 +02:00
Denys Vlasenko
b543bdadb3 ash: return to DOWAIT_* constants similar to dash, no logic changes
This loses an insignificant optimization, but may allow backporting
of some recent-ish dash fixes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 21:13:24 +02:00
Denys Vlasenko
3f44a6be58 ash: delete leftovers from "simplify EOF/newline handling in list parser" commit
This commit should have deleted these two statements:

    commit c0e007663d
    Author: Ron Yorston <rmy@pobox.com>
    Date:   Thu Oct 29 11:30:55 2015 +0000
    ash: simplify EOF/newline handling in list parser

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 14:49:21 +02:00
Denys Vlasenko
5ac04f2f02 ash: [EXPAND] Fix ifsfirst/ifslastp leak
Upstream commit:

    Date: Wed, 8 Sep 2010 20:07:26 +0800
    [EXPAND] Fix ifsfirst/ifslastp leak

    As it stands expandarg may return with a non-NULL ifslastp which
    then confuses any subsequent ifsbreakup user that doesn't clear
    it directly.

    What's worse, if we get interrupted before we hit ifsfree in
    expandarg we will leak memory.

    This patch fixes this by always calling ifsfree in expandarg
    thus ensuring that ifslastp is always NULL on the normal path.
    It also adds an ifsfree call to the RESET path to ensure that
    memory isn't leaked.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Fallout 1:

    Date: Mon, 18 Oct 2010 10:55:42 +0800
    [EXPAND] Fix ifsfirst/ifslastp leak in casematch

    The commit f42e443bb511ed3224f09b4fcf0772438ebdbbfa

        [EXPAND] Fix ifsfirst/ifslastp leak

    revealed yet another ifsfirst/ifslastp leak in casematch.
    Previously it was hidden because ifsfirst/ifslastp was cleared
    unconditionally on entry (which caused the leakage of those
    entries).

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Fallout 2:

    Date: Sun, 28 Nov 2010 21:09:51 +0800
    [EXPAND] Free IFS state in evalbackcmd

    On Sun, Nov 07, 2010 at 04:04:20PM -0600, Jonathan Nieder wrote:
    > Herbert Xu wrote:
    > > commit f42e443bb511ed3224f09b4fcf0772438ebdbbfa
    > > Author: Herbert Xu <herbert@gondor.apana.org.au>
    > > Date:   Wed Sep 8 20:07:26 2010 +0800
    > >
    > >     [EXPAND] Fix ifsfirst/ifslastp leak
    >
    > Another puzzle bisecting to f42e443bb.  This one comes from the
    > grub-mkconfig script:
    >
    >  $ sh -c 'datadir=/usr/share; pkgdatadir=${datadir}/`cat`' 2>&1 | cat -A
    >  cat: M-^\^M^F^HM-4^M^F^HM-(^M^F^H: No such file or directory$
    >  cat: M-(^M^F^H: No such file or directory$
    >
    > Still reproducible with 016b529.  I'll try to find time to look into
    > it, but thought you might like to know nevertheless.

    This is the symptom of another leak.  In this case evalbackcmd
    occurs in the middle of an expansion (as it should) but the forked
    child never clears the previous IFS state.

    This patch adds the missing ifsfree call.

    This wasn't as much of a problem as the previously discovered leaks
    since all it means is that the child gets to carry around the parent's
    expansion state and the child is usually short-lived.

    Reported-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Fallout 3:

    Date: Tue, 15 Mar 2011 16:01:34 +0800
    [EXPAND] Free IFS state after here document expansion

    Here's another bug bisecting to f42e443bb ([EXPAND] Fix
    ifsfirst/ifslastp leak, 2010-09-08).  It was found with the following
    test case, based on the configure script for Tracker:

        dash -x -c '
                <<-_ACEOF
                $@
                _ACEOF
                exec
        ' - abcdefgh
        +
        + exec   ?a
        exec: 1: : Permission denied

    The missing ifsfree call is in expandarg when it returns to openhere
    during here document expansion.

    Reported-by: Aurelien Jarno <aurel32@debian.org>
    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
ifsfree                                                -      66     +66
ash_main                                            1490    1495      +5
argstr                                              1154    1159      +5
evalcase                                             275     270      -5
expandarg                                            972     888     -84
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 76/-89)            Total: -13 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 14:46:50 +02:00
Denys Vlasenko
455e422814 ash: move ifsbreakup() and ifsfree() up
Preparatory patch.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 14:46:17 +02:00
Denys Vlasenko
b4f51d32d2 ash: partially sync with dash on "fork if traps are set" logic
Upstream commit "[EVAL] Force fork if any trap is set, not just on EXIT"
had a similar code as our fix to that bug.
Eliminate some superficial differences.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 12:55:09 +02:00
Denys Vlasenko
2eb0a7e1b9 ash: [SHELL] Expand ENV before using it
Upstream commit:

    Date: Sun, 13 Jul 2008 21:51:52 +0800
    [SHELL] Expand ENV before using it

    Per POSIX ENV needs to undergo parameter expansion.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 11:28:59 +02:00
Denys Vlasenko
70392331a9 ash: comment tweaks, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-27 02:31:55 +02:00
Denys Vlasenko
65a8b859a9 ash: optimize tryexec(): avoid one allocation
There was a bug in tryexec which bbox had fixed in 2003.
dash had a smaller fix in 2007. Copy it. It is smaller,
although it is also more quirky (requires argv[-1] to exist).

Upstream commit 1:

    Date: Mon, 15 Oct 2007 20:24:28 +0800
    [EXEC] Fixed execing of scripts with no hash-bang

    The function tryexec used the original name instead of the path found through
    PATH search.  This patch fixes that.

    Test case:

        trap 'rm -f $TMP' EXIT
        TMP=$(tempfile -s nosuchthing)

        cat <<- EOF > $TMP
                echo OK
        EOF
        chmod u+x $TMP

        cd /
        PATH=${TMP%/*} ${TMP##*/}

    Old result:

        /bin/sh: Can't open filelgY4Fanosuchthing

    New result:

        OK

Upstream commit 2:

    Date: Sun, 23 Dec 2007 11:02:26 +0800
    [EVAL] Fix bad pointer arithmetic in evalcommand

    dash dies on sparc with a SIGBUS due to an arithmetic error introduced
    with commit 03b4958, this patch fixes it.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
evalcommand                                         1261    1264      +3
dotcmd                                               321     319      -2
tryexec                                              115      64     -51
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 3/-53)             Total: -50 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 22:29:11 +02:00
Denys Vlasenko
0e081d01a8 ash: [CD] Lookup PWD after going through CDPATH
Upstream commit:

    Date: Mon, 31 Aug 2009 22:06:41 +1000
    [CD] Lookup PWD after going through CDPATH

    On Tue, Jul 14, 2009 at 09:39:03PM +0000, Eric Blake wrote:
    > For the cd command, POSIX 2008 requires that after all pathnames in CDPATH
    > have been tested and failed in step 5, then step 6 interprets the directory
    > argument relative to PWD.  In other words, this demonstrates a bug:
    >
    > $ dash -c 'cd /tmp; mkdir -p foo; CDPATH=oops; cd foo; echo $?; pwd'
    > cd: 1: can't cd to foo
    > 2
    > /tmp
    >
    > while bash gets it correct:
    >
    > $ bash -c 'cd /tmp; mkdir -p foo; CDPATH=oops; cd foo; echo $?; pwd'
    > 0
    > /tmp/foo

    This patch fixes the problem.

    Reported-by: Eric Blake <ebb9@byu.net>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
cdcmd                                                667     680     +13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 19:56:05 +02:00
Denys Vlasenko
a318bba199 ash: [MEMALLOC] Made grabstackblock an inline wrapper for stalloc
Upstream patch:

    Date: Fri, 5 Oct 2007 23:26:45 +0800
    [MEMALLOC] Made grabstackblock an inline wrapper for stalloc

    The function grabstackblock is identical in semantics to stalloc within its
    input constraints.

function                                             old     new   delta
dotcmd                                               319     321      +2
grabstackblock                                        19       5     -14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 18:26:27 +02:00
Denys Vlasenko
dbef38a74b ash: [VAR] Remove setvarsafe
Upstream commit:

    Date: Sat, 6 Oct 2007 21:18:58 +0800
    [VAR] Remove setvarsafe

    The only user of setvarsafe is getopts.  However, we can achieve the same
    result by pre-setting the value of shellparam.optind.

function                                             old     new   delta
getoptscmd                                           614     515     -99
setvarsafe                                           147       -    -147
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-246)           Total: -246 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 17:54:32 +02:00
Denys Vlasenko
35c2a136cd ash: use shellparam.optind/optoff in getopts() directly, not through pointers
This is a preparatory patch for next change

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 17:34:26 +02:00
Denys Vlasenko
3df1410a00 ash: [PARSER] Size optimisations in parameter expansion parser
Upstream commit:

    Date: Thu, 4 Oct 2007 22:20:38 +0800
    [PARSER] Size optimisations in parameter expansion parser

    Merge flags into subtype.
    Do not write subtype out twice.
    Add likely flag on ${ vs. $NAME.
    Kill unnecessary (and bogus) PEOA check.

function                                             old     new   delta
readtoken1                                          2891    2860     -31

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 16:41:13 +02:00
Denys Vlasenko
350e686f3b ash: [PARSER] Recognise here-doc delimiters terminated by EOF
Upstream commit 1:

    Date: Wed, 26 Sep 2007 17:14:16 +0800
    [PARSER] Recognise here-doc delimiters terminated by EOF

    Previously dash required a <newline> character to be present in order for
    a here-document delimiter to be detected.  Allowing EOF in the absence of
    a <newline> to play the same purpose allows some intuitive scripts to
    succeed.  POSIX seems to be silence on this so this should be OK.

    Test case:

        eval 'cat <<- NOT
                test
        NOT'
        echo OK

    Old result:

        test
        NOTOK

    New result:

        test
        OK

Upstream commit 2:

    Date: Sat, 20 Oct 2007 18:49:31 +0800
    [PARSER] Fix here-doc corruption

    The change

        [PARSER] Recognise here-doc delimiters terminated by EOF

    introduced a regerssion whereby lines starting with eofmark but are not equal
    to eofmark would be corrupted.  This patch fixes it.

    Test case:

        cat << _ACEOF
        _ASBOX
        _ACEOF

    Old result:

        SASBOX

    New result:

        _ASBOX

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 16:26:45 +02:00
Denys Vlasenko
f15aa57a7f ash: [PARSER] Fix parsing of ${##1}
Upstream commit:

    Date: Thu, 4 Oct 2007 22:15:10 +0800
    [PARSER] Fix parsing of ${##1}

    Previously dash treated ${##1} as a length operation.  This patch fixes that.

    Test case:

        set -- a
        echo ${##1}OK

    Old result:

        1OK

    New result:

        OK

This was a real bug in ash (but not in hush).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 15:56:53 +02:00
Denys Vlasenko
e19923f665 ash: [REDIR] Remove redundant CLOEXEC calls
Upstream commit:

    Date: Sun, 6 May 2007 19:28:56 +1000
    [REDIR] Remove redundant CLOEXEC calls

    Now that we're marking file descriptors as CLOEXEC in savefd, we no longer
    need to close them on exec or in setinputfd.

function                                             old     new   delta
ash_main                                            1478    1492     +14
setinputfile                                         224     226      +2
readtoken1                                          2752    2750      -2
shellexec                                            208     198     -10
clearredir                                            30       -     -30
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/2 up/down: 16/-42)            Total: -26 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 15:38:44 +02:00
Denys Vlasenko
647746076a ash: [REDIR] Replace copyfd by savefd and use dup2 elsewhere
Upstream commit:

    Date: Sat, 12 May 2007 18:00:57 +1000
    [REDIR] Replace copyfd by savefd and use dup2 elsewhere

    There are two kinds of users to copyfd, those that want to copy an fd to
    an exact value and those that want to move an fd to a value >= 10.  The
    former can simply use dup2 directly while the latter share a lot of common
    code that now constitutes savefd.

This does not change much, just reducing our divergence from dash code.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 15:24:30 +02:00
Denys Vlasenko
4135a75ab0 typo fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 13:15:35 +02:00
Denys Vlasenko
a513bf3c3c ash: [BUILTIN] Treat OPTIND=0 in the same way as OPTIND=1
Upstream commit:

    Date: Sat, 6 Oct 2007 18:59:31 +0800
    [BUILTIN] Treat OPTIND=0 in the same way as OPTIND=1

    Previously setting OPTIND to 0 would cause subsequent getopts calls to fail.
    This patch makes dash reset the getopts parameters the same way as OPTIND=1.

    Both behaviours are allowed by POSIX but other common shells do tolerate this
    case.

function                                             old     new   delta
getoptsreset                                          24      30      +6
getoptscmd                                           632     614     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 02:03:37 +02:00
Denys Vlasenko
88e15703ac ash: [PARSER] Report substition errors at expansion time
Upstreams commit:

    Date: Mon, 8 Oct 2007 21:32:25 +0800
    [PARSER] Report substition errors at expansion time

    On Wed, Apr 11, 2007 at 01:24:21PM -0700, Micah Cowan wrote:
    > This operation fails on Ubuntu:
    >
    >     $ /bin/sh -c 'if false; then d="${foo/bar}"; fi'
    >     /bin/sh: Syntax error: Bad substitution
    >
    > When used with other POSIX shells it succeeds. While semantically the
    > variable reference ${foo/bar} is not valid, this is not a syntax error
    > according to POSIX, and since the variable assignment expression is
    > never invoked (because it's within an "if false") it should not be seen
    > as an error.
    >
    > I ran into this because after restarting my system I could no longer log
    > in. It turns out that the problem was (a) I had edited .gnomerc to
    > source my .bashrc file so that my environment would be set properly, and
    > (b) I had added some new code to my .bashrc WITHIN A CHECK FOR BASH!
    > that used bash's ${var/match/sub} feature. Even though this code was
    > within a "case $BASH_VERSION; in *[0-9]*) ... esac (so dash would never
    > execute it since that variable is not set), it still caused dash to
    > throw up.
    >
    > FYI, some relevant details from POSIX:
    >
    > Section 2.3, Token Recognition:
    >
    > 5. If the current character is an unquoted '$' or '`', the shell shall
    > identify the start of any candidates for parameter expansion ( Parameter
    > Expansion), command substitution ( Command Substitution), or arithmetic
    > expansion ( Arithmetic Expansion) from their introductory unquoted
    > character sequences: '$' or "${", "$(" or '`', and "$((", respectively.
    > The shell shall read sufficient input to determine the end of the unit
    > to be expanded (as explained in the cited sections).
    >
    > Section 2.6.2, Parameter Expansion:
    >
    > The format for parameter expansion is as follows:
    >
    >     ${expression}
    >
    > where expression consists of all characters until the matching '}'. Any
    > '}' escaped by a backslash or within a quoted string, and characters in
    > embedded arithmetic expansions, command substitutions, and variable
    > expansions, shall not be examined in determining the matching '}'.
    > [...]
    >
    > The parameter name or symbol can be enclosed in braces, which are
    > optional except for positional parameters with more than one digit or
    > when parameter is followed by a character that could be interpreted as
    > part of the name. The matching closing brace shall be determined by
    > counting brace levels, skipping over enclosed quoted strings, and
    > command substitutions.
    > ---
    > In addition to bash I've checked Solaris /bin/sh and ksh and they don't
    > report an error.
    >
    > -----
    > Micah Cowan:
    >
    > The applicable portion of POSIX is in XCU 2.10.1:
    >
    > "The WORD tokens shall have the word expansion rules applied to them
    > immediately before the associated command is executed, not at the time
    > the command is parsed."
    >
    > This seems fairly clear to me.

    This patch moves the error detection to expansion time.

    Test case:

    	if false; then
    		echo ${a!7}
    	fi
    	echo OK

    Old result:

	dash: Syntax error: Bad substitution

    New result:

	OK

function                                             old     new   delta
evalvar                                              574     585     +11
readtoken1                                          2763    2750     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-26 01:55:56 +02:00
Denys Vlasenko
eaf9436b08 ash: [REDIR] Move null redirect checks into caller
Upstream commit:

    Date: Thu, 27 May 2010 14:21:17 +0800
    [REDIR] Move null redirect checks into caller

    The null redirect checks were added as an optimisation to avoid
    unnecessary memory allocations.  However, we could avoid this
    completely by simply making the caller avoid making a redirection
    unless it is not null.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
evaltree                                             784     809     +25
evalcommand                                         1251    1261     +10
hashvar                                               59      62      +3
dotcmd                                               321     319      -2
clearredir                                            37      30      -7
popredir                                             183     162     -21
redirect                                            1264    1233     -31
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/4 up/down: 63/-61)            Total: -23 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 21:46:03 +02:00
Denys Vlasenko
2a6d29ad5c ash: [PARSER] Do not show prompts in expandstr
Upstream patch:

    Date: Thu, 27 Dec 2007 13:57:07 +1100
    [PARSER] Do not show prompts in expandstr

    Once I fixed the previous problem it became apparent that we never dealt
    with prompts with new-lines in them correctly.  The problem is that we
    showed a secondary prompt for each of them.

    This patch disables prompt generation in expandstr.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
expandstr                                            102     127     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 21:17:52 +02:00
Denys Vlasenko
579ad107a6 ash: [EXPAND] Removed herefd hack
Upstream commit:

    Date: Sun, 11 Nov 2007 15:00:06 +0800
    [EXPAND] Removed herefd hack

    The herefd hack goes back more than a decade.  it limits the amount of
    memory we have to allocate when expanding here-documents by writing the
    result out from time to time.  However, it's no longer safe because the
    stack is used to place intermediate results too and there we certainly
    don't want to write them out should we be short on memory.

    In any case, with today's computers we can afford to keep the entire
    result in memory and write them out at the end.

function                                             old     new   delta
redirect                                            1268    1264      -4
ash_main                                            1485    1478      -7
subevalvar                                          1157    1132     -25
growstackstr                                          54      24     -30
argstr                                              1192    1154     -38
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-104)           Total: -104 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 21:10:20 +02:00
Denys Vlasenko
caee80cd3d ash: [SHELL] Move flushall to the point just before _exit
Upstream commit:

    We need to flush at the very end in case we've generated any errors
    before that.  The flushall call cannot perform a longjmp so it's
    safe there.

    Date: Sat, 22 Sep 2007 20:50:21 +0800
    [SHELL] Move flushall to the point just before _exit

    We need to flush at the very end in case we've generated any errors
    before that.  The flushall call cannot perform a longjmp so it's
    safe there.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 20:49:53 +02:00
Denys Vlasenko
7aec86820d ash: [EVAL] Let funcnode refer to a function definition, not its first command
Upstream patch:

    Date: Tue, 15 Mar 2011 15:44:47 +0800
    [EVAL] Let funcnode refer to a function definition, not its first command

    It is not unrelated: I changed the meaning of struct funcnode's field n
    to refer to the function definition, rather than the list of the
    function's commands, because I needed to refer to the function
    definition node from evalfun, which only gets passed a funcnode. But it
    is something that could be applied independently (without being useful
    by itself), so I've attached it as a separate patch for easier review.

    Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 20:26:02 +02:00
Denys Vlasenko
20a2cd6291 ash: [REDIR] Remove EMFILE special case
Upstream commit:

    Date: Sun, 6 May 2007 12:01:37 +1000
    [REDIR] Remove EMFILE special case

    No caller of copyfd need to ignore EMFILE so we can remove the special
    case and just let it call sh_error on any error.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 19:04:39 +02:00
Denys Vlasenko
cf98b0c085 ash: [EVAL] Check exit for eval NSUBSHELL
Upstream commit:

    Date: Tue, 6 Jul 2010 17:50:37 +0800
    [PATCH 161/277] [EVAL] Check exit for eval NSUBSHELL

    Example:

    $ dash -c 'set -e; (false); echo here'
    here

    With this commit, dash exits 1 before echo.

    The bug was reported by Stefan Fritsch through
     http://bugs.debian.org/514863

    Signed-off-by: Gerrit Pape <pape@smarden.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

This was fixed differently in our tree:

    Date:   Fri Sep 16 19:04:02 2016 +0000
    ash: exit after subshell error when errexit option is set

    When "set -e" option is on, shell must exit when any command fails,
    including compound commands of the form (compound-list) executed in a
    subshell. Bash and dash shells have this behaviour.

    Also add a corresponding testcase.

    Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
    Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 18:19:39 +02:00
Denys Vlasenko
960ca385b7 ash: add comment explaining "set -e; $(cmd)" discrepancy
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 18:12:15 +02:00
Denys Vlasenko
6a94cee409 ash: reduce code differences from upstream
Upstream commit:

    Date: Wed, 8 Sep 2010 16:21:52 +0800
    [JOBS] Debug compile fix

    No point in tracing a no longer undeclared "ps->cmd", fixes:
    jobs.c: In function \u2018commandtext\u2019:
    jobs.c:1192: error: \u2018ps\u2019 undeclared (first use in this function)
    jobs.c:1192: error: (Each undeclared identifier is reported only once
    jobs.c:1192: error: for each function it appears in.)

    Signed-off-by: maximilian attems <max@stro.at>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 17:41:06 +02:00
Denys Vlasenko
1825e4f935 ash: remove unused EXSHELLPROC
Upstream commit:

    Date: Sun, 28 Nov 2010 20:47:07 +0800
    [BUILTIN] Stop documenting EXSHELLPROC

    At some point between ash 0.3.5-11.0.1 and ash 0.3.8-37, Debian
    ash stopped using the EXSHELLPROC exception to handle shell
    scripts without a magic number.

    Remove all remaining references to it to avoid confusion.

    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 17:26:56 +02:00
Denys Vlasenko
061a09091f ash: [BUILTIN] Use EXEXIT in place of EXEXEC
Upstream commit:

    Date: Sun, 28 Nov 2010 20:44:37 +0800
    [BUILTIN] Use EXEXIT in place of EXEXEC

    The intended semantics of EXEXEC are identical to EXEXIT, so
    simplify by using EXEXIT directly.

    Functional change: in edge cases (exec within a trap handler),
    this causes the exit status from exec not to be clobbered.
    For example, without this patch:

     $ sh -c 'trap "exec nonexistent" EXIT'; echo $?
     exec: 1: nonexistent: not found
     0

    And with it:

     $ sh -c 'trap "exec nonexistent" EXIT'; echo $?
     exec: 1: nonexistent: not found
     127

    Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 17:24:25 +02:00
Denys Vlasenko
b7adf7ac32 ash,hush: set exit code 127 in "sh /does/not/exist" case
Upstream commit 1 for ash:

    [ERROR] Allow the originator of EXERROR to set the exit status

    Some errors have exit status values specified by POSIX and it is
    therefore desirable to be able to set the exit status at the EXERROR
    source rather than in main.c.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Upstream commit 2 for ash:

    [INPUT] Use exit status 127 when the script to run does not exist

    This commit makes dash exit with return code 127 instead of 2 if
    started as non-interactive shell with a non-existent command_file
    specified as argument (or a directory), as documented in
     http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html#tag_04_128_14

    The wrong exit code was reported by Clint Adams and Jari Aalto through
     http://bugs.debian.org/548743
     http://bugs.debian.org/548687

    Signed-off-by: Gerrit Pape <pape@smarden.org>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

NB: in fact, http://bugs.debian.org/548687 was not fixed by this:
"sh /dir/" thinks that EISDIR error on read is EOF, and exits 0.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 17:00:13 +02:00
Denys Vlasenko
f11c6989ba udhcpc: check read of overload option data byte to be within packet
function                                             old     new   delta
udhcp_get_option                                     220     225      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 14:26:36 +02:00
Brian Foley
f9beeb22e2 udhcpc: check read of option length byte to be within packet
function                                             old     new   delta
udhcp_get_option                                     215     220      +5
udhcp_run_script                                     802     803      +1

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-25 14:20:55 +02:00
Tito Ragusa
69312e87b0 strings: implement -t radix
v2: minor code cleanup, no changes.
v1: Implement -t radix option.
    Fix help text for -o option.

Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-24 21:52:10 +02:00
Denys Vlasenko
db74c6caed ash: explain EXP_REDIR and why we (dont) glob redir filenames
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-24 21:12:33 +02:00
Brian Foley
61d5997b58 awk: fix segfault on for loop syntax error
Parsing "for()" segfaults as awk fails to find loop iteration expressions.

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-24 02:09:56 +02:00
Denys Vlasenko
1336052a49 lineedit: fix completion with applet names. closes 9361
Patch by Ron Yorston <rmy@pobox.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-24 01:25:05 +02:00
Ron Yorston
5ccb0e92fa ash: return exit status of nofork applets
The commit 'ash: eval: Return status in eval functions' changed how
exit status is handled in eval functions.  The case of nofork
applets was missed, resulting in the incorrect status potentially
being returned for nofork applets when FEATURE_SH_NOFORK is enabled.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-24 01:18:13 +02:00
Denys Vlasenko
6bbb48fadf examples: update var_service/README again
Added "ps -AH e" example

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-14 19:02:11 +02:00
Denys Vlasenko
e43000f2d4 typo fixes in doc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-14 18:48:05 +02:00
Denys Vlasenko
93ff2b4b5f examples: update var_service/README again
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-14 18:38:08 +02:00
Denys Vlasenko
ee2d19445b examples: update var_service/README
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-14 18:22:50 +02:00
Denys Vlasenko
662634b829 telnetd: ifdef out a buggy error handling code path
Here, not handling the error is would just eat one input 0xff char.
Correct handling would need even more corner case handling,
as-is buggy handling corrupts the buffer.
Since we just been told by kernel that pty is ready,
EAGAIN should not be happening here anyway.

function                                             old     new   delta
telnetd_main                                        1798    1785     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-13 16:17:06 +02:00
Denys Vlasenko
85100a7067 cpio: fix restoration of file ownership, closes 9306
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-12 20:56:46 +02:00
Denys Vlasenko
57727d478d telnet: code shrink
put_iac2(w,c) is mostly used with constants, fold them into one arg

function                                             old     new   delta
put_iac2_merged                                        -      46     +46
telnet_main                                         1603    1583     -20
con_escape                                           285     257     -28
put_iac2                                              50       -     -50
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 46/-98)            Total: -52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-12 20:42:58 +02:00
Denys Vlasenko
26d88d6bbd telnetd: add another handshake example in comments, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-12 20:09:22 +02:00
Denys Vlasenko
b6d421b635 telnetd: treat all 2-byte IACs in 240..249 range as NOPs.
A bit of future-proofing. Some of them can stand just being ignored.

function                                             old     new   delta
telnetd_main                                        1791    1798      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-12 19:41:33 +02:00
Denys Vlasenko
122c47ac02 telnetd: fix corner case of input processing of 0xff bytes
I managed to reproduce the bug, with some difficulty.

function                                             old     new   delta
telnetd_main                                        1780    1791     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-12 19:13:46 +02:00
Denys Vlasenko
0190c41bb2 telnetd: fix a corner case where CRLF->CR translation can misbehave
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-12 17:36:57 +02:00
Denys Vlasenko
2a54b3e86e telnetd: fix handling of short writes to pty
If a write to pty is short, remove_iacs() can be run on a buffer repeatedly.
This, for example, can eat 0xff chars (IACs, in telnet terms).

Rework the logic to handle IACs in a special "write to pty" function.

function                                             old     new   delta
telnetd_main                                        1662    1750     +88

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-12 14:54:10 +02:00
Denys Vlasenko
713b513353 more: accept and ignore a bunch of options
Alpine Linux stumbled over "more -s":
http://bugs.alpinelinux.org/issues/5190

function                                             old     new   delta
more_main                                            857     872     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-11 15:29:38 +02:00
Denys Vlasenko
3720a61daf ifupdown: rewrite state file atomically
By user's request.
Decided to not use fcntl(F_SETLKW) in lieu of problems with locking
on networked filesystems. The existence of /var/run/ifstate.new
is treated as a write lock. rename() provides atomicity.

function                                             old     new   delta
ifupdown_main                                       1019    1122    +103

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-09 23:04:16 +02:00
Denys Vlasenko
ec1ea16337 tcpsvd: don't keep shared fd open if fd limit is reached. closes 9331
Also, much improved help text.

function                                             old     new   delta
packed_usage                                       30652   30851    +199
tcpudpsvd_main                                      1782    1784      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-07 15:56:47 +02:00
Denys Vlasenko
561639a68c ash: all blocks in function node copying must be SHELL_ALIGNed
Previous commit probably introduced a bug:
non-matching size calculation in size counting and
actual copying caused by SHELL_ALIGN being applied differently!
This won't bite if string sizes are also SHELL_ALIGNed.
Thus fixing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-07 04:28:33 +02:00
Denys Vlasenko
d43be87591 ash testsuite: fix false positives
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-07 04:07:05 +02:00
Denys Vlasenko
4c438b5ba4 ash: get rid of two global data variables
function                                             old     new   delta
calcsize                                             126     147     +21
funcstring_end                                         -       4      +4
sizenodelist                                          28      24      -4
funcstringsize                                         4       -      -4
funcstring                                             4       -      -4
funcblocksize                                          4       -      -4
nodeckstrdup                                          48      39      -9
evaltree                                             828     788     -40
------------------------------------------------------------------------------
(add/remove: 1/3 grow/shrink: 1/4 up/down: 25/-105)           Total: -40 bytes
   text	   data	    bss	    dec	    hex	filename
 943376	    916	  14292	 958584	  ea078	busybox_old
 943344	    916	  14284	 958544	  ea050	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-07 04:05:15 +02:00
Denys Vlasenko
f37e1155aa ash: comment out free(p) just before _exit, tweak some outdated comments
Planned to sync exitshell up to dash, turned out ours is better :)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-07 03:17:28 +02:00
Denys Vlasenko
2972e2c4ac wget: there is no -s option in GNU Wget 1.18, we should be compatible
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-04 04:23:09 +02:00
Denys Vlasenko
a85740c8af dhcp: merge leases.c and static_leases.c into dhcpd.c
function                                             old     new   delta
send_offer                                           292     461    +169
udhcpd_main                                         1531    1588     +57
read_leases                                          330     332      +2
add_lease                                            314     312      -2
find_lease_by_mac                                     68       -     -68
find_free_or_expired_nip                             174       -    -174
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 3/1 up/down: 228/-244)          Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-04 00:56:58 +02:00
Denys Vlasenko
d2ae66cb3e dhcp: merge most of static_leases.c into dhcpd.c
function                                             old     new   delta
read_staticlease                                     121     222    +101
add_static_lease                                      48       -     -48
log_static_leases                                     68       -     -68
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/0 up/down: 101/-116)          Total: -15 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-04 00:56:58 +02:00
Denys Vlasenko
2bf2931d52 dhcp: merge files.c into dhcpd.c
Added NOINLINE to two function, since my version of gcc would actualy increase
code size otherwise.

I see no size changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-04 00:56:58 +02:00
Denys Vlasenko
095ddf7669 examples: add example of a DHCP server
As usual, by multiplying directories - "dhcpd_eth0", "dhcpd_wlan1"
you can run many servers on different interfaces.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 23:43:44 +02:00
Denys Vlasenko
7f0ebbc69e hush: add commented-out debug printouts in "memleak" built-in
Allocation addresses of malloc() are jittery,
thought I had a mem leak in hush, but it was malloc variability.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 17:42:53 +02:00
Denys Vlasenko
a769390da6 hush: fix a memory corruption when exported variable is modified
The construct such as this:

t=1
export t
t=new_value1

had a small probability of momentarily using free()d value.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 15:01:06 +02:00
Denys Vlasenko
04465dad66 hush: fix exitcode on exec failure with EACCES - should be 126
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 01:01:15 +02:00
Denys Vlasenko
c775f829db sh testsuite: add tests for exitcode on failure to exec
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:55:34 +02:00
Denys Vlasenko
2feaa227a4 shell: delete all msh tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:51:29 +02:00
Denys Vlasenko
9793fc576a hush testsuite: fix another false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:14:26 +02:00
Denys Vlasenko
d3b4e5ec6a hust testsuite: fix a false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:10:20 +02:00
Denys Vlasenko
a62bc80571 ash testsuite: add most of hust tests which pass for ash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:06:55 +02:00
Denys Vlasenko
ce332a23a3 ash: [PARSER] Add nlprompt/nlnoprompt helpers
Upstream commit:

    Date: Mon, 29 Sep 2014 22:53:53 +0800
    [PARSER] Add nlprompt/nlnoprompt helpers

    This patch adds the nlprompt/nlnoprompt helpers to isolate code
    dealing with newlines and prompting.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 23:47:34 +02:00
Denys Vlasenko
80729a4472 whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 22:33:15 +02:00
Denys Vlasenko
db7f4c203b hush: add var4.tests, var5.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 21:13:13 +02:00
Denys Vlasenko
61508d9624 hush: fix var3.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 21:12:02 +02:00
Denys Vlasenko
ebedb9478d sh: do not print empty line at the end of "help" output
It's pointless.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:45:09 +02:00
Denys Vlasenko
df303ae117 sh testsuite: sync ash-redir/ and hush-redir/
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:32:52 +02:00
Denys Vlasenko
c7a774dde4 sh testsuite: sync ash-misc/source* and hush-misc/source*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:23:14 +02:00
Denys Vlasenko
0ba99705a1 sh testsuite: sync ash-vars/ and hush-vars/
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:17:15 +02:00
Denys Vlasenko
e3354bc44a ash testsuite: update some of variable tests with newer versions from hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:08:04 +02:00
Denys Vlasenko
c4cf542c57 sh testsuite: create hush-redir/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:55:51 +02:00
Denys Vlasenko
1b73f8471a sh testsuite: create hush-heredoc/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:49:46 +02:00
Denys Vlasenko
5d6b8729ed hush testsuite: add many tests from ash testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:39:31 +02:00
Denys Vlasenko
888527ccee ash: undo "tokname hack"
dash has tokendlist[] array to decide which tokens end lists.
We store it as first byte of each tokname_array[i].

Switch to bit array, name it like dash (tokendlist), drop special
1st byte of tokname_array[i]. This brings us closer to dash, and
shrinks the binary, because many more string aliasing opportunities
are now open:

function                                             old     new   delta
pstrcmp1                                               -      16     +16
readtoken1                                          2852    2858      +6
list                                                 326     327      +1
pstrcmp                                               16      15      -1
tokname                                               45      42      -3
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/2 up/down: 23/-4)              Total: 19 bytes
   text	   data	    bss	    dec	    hex	filename
 943556	    916	  14292	 958764	  ea12c	busybox_old
 943463	    916	  14292	 958671	  ea0cf	busybox_unstripped
^^^^^^^ note this!

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 16:54:17 +02:00
Denys Vlasenko
bc1a00843f ash: placate gcc: "warning: ! is only applied to the left hand side of =="
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 15:31:33 +02:00
Denys Vlasenko
ae4bd34e6b hush testsuite: add glob_dir.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 15:20:57 +02:00
Denys Vlasenko
8e2c9cc2fc ash: fix globbing bugs when using glibc glob()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 15:17:15 +02:00
Denys Vlasenko
37dc08b874 ash: style fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 04:38:07 +02:00
Denys Vlasenko
0cdb7ea380 ash: support "--" in "source" builtin
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 03:16:00 +02:00
Denys Vlasenko
0aaaa50b45 ash: expand: Fixed "$@" expansion when EXP_FULL is false
Upstream commit:

    Date: Thu, 1 Jan 2015 07:53:10 +1100
    expand: Fixed "$@" expansion when EXP_FULL is false

    The commit 3c06acdac0b1ba0e0acdda513a57ee6e31385dce ([EXPAND]
    Split unquoted $@/$* correctly when IFS is set but empty) broke
    the case where $@ is in quotes and EXP_FULL is false.

    In that case we should still emit IFS as field splitting is not
    performed.

    Reported-by: Juergen Daubert <jue@jue.li>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 02:46:56 +02:00
Denys Vlasenko
42eeb255c1 test: fix compile error in last commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 02:35:13 +02:00
Denys Vlasenko
de89205bdf test: memory leak: free group id list
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 01:49:13 +02:00
Denys Vlasenko
ff59b7b112 ash,hush: add a test that "continue" does not cripple traps
Both shells pass this test.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 23:28:02 +02:00
Denys Vlasenko
b98b4c103f ash: fix return_in_trap1.tests failure
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 23:25:12 +02:00
Denys Vlasenko
3ed7e2749a ash testsuite: add return_in_trap1.tests
Currently it fails

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 22:36:14 +02:00
Denys Vlasenko
04b46bced9 hush: 'return' should have effect earlier
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 22:28:03 +02:00
Denys Vlasenko
0dd8e45d42 ash: [EXPAND] Optimise nulonly away and just use quoted as before
Upstream commit:

    Date: Wed, 8 Oct 2014 20:09:56 +0800
    [EXPAND] Optimise nulonly away and just use quoted as before

    This patch makes a small optimisation by using the same value for
    quoted between evalvar and varvalue by eliminating nulonly and
    passing along quoted instead.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 21:02:06 +02:00
Denys Vlasenko
88ac97d02d ash: [EXPAND] Do not split quoted VSLENGTH and VSTRIM
Upstream patch:

    Date: Wed, 8 Oct 2014 15:42:08 +0800
    [EXPAND] Do not split quoted VSLENGTH and VSTRIM

    Currently VSLENGTH and VSTRIM* are field-split even within quotes.
    This is obviously wrong.  This patch fixes that.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 20:55:02 +02:00
Denys Vlasenko
c4d4380a07 ash: [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty
Upstream commit:

    Date: Wed, 8 Oct 2014 15:24:23 +0800
    [EXPAND] Split unquoted $@/$* correctly when IFS is set but empty

    Currently we do not field-split $@/$* when it isn't quoted and IFS
    is set but empty.  This is obviously wrong.  This patch fixes this.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 20:35:10 +02:00
Denys Vlasenko
a2633aa819 hush: add func6.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 20:12:10 +02:00
Denys Vlasenko
35ec818fa2 ash: fix "return N" not setting $? in loop conditionals
Upstream commit 1:

    Date: Mon, 6 Oct 2014 20:45:04 +0800
    [EVAL] Move common skipcount logic into skiploop

    The functions evalloop and evalfor share the logic on checking
    and updating skipcount.  This patch moves that into the helper
    function skiploop.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Upstream commit 2:

    Date: Mon, 6 Oct 2014 21:22:43 +0800
    [BUILTIN] Allow return in loop conditional to set exit status

    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=332954

    When return is used in a loop conditional the exit status will
    be lost because we always set the exit status at the end of the
    loop to that of the last command executed in the body.

    This is counterintuitive and contrary to what most other shells do.

    This patch fixes this by always preserving the exit status of
    return when it is used in a loop conditional.

    The patch was originally written by Gerrit Pape <pape@smarden.org>.

    Reported-by: Stephane Chazelas <stephane_chazelas@yahoo.fr>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 19:56:52 +02:00
Denys Vlasenko
1b8e0e8adf ash testsuite: remove two more inadvertent bashisms
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 17:43:04 +02:00
Denys Vlasenko
cc0056db5c ash testsuite: remove two inadvertent bashisms
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 17:30:21 +02:00
Denys Vlasenko
4d12e944ea ash: [ERROR] Set exitstatus in onint
Partially backported this commit:

    Date: Thu, 2 Oct 2014 21:07:55 +0800
    [ERROR] Set exitstatus in onint

    Currently the exit status when we receive SIGINT is set in evalcommand
    which means that it doesn't always get set.  For example, if you press
    CTRL-C at the prompt of an interactive dash, the exit status is not
    set to 130 as it is in many other Bourne shells.

    This patch fixes this by moving the setting of the exit status into
    onint which also simplifies evalcommand.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

The part after "if (evalbltin(cmdentry.u.cmd, argc, argv, flags))"
causes testsuite failures in signal handling, so left unchanged.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 16:03:11 +02:00
Denys Vlasenko
0840c91909 ash: [EVAL] Revert SKIPEVAL into EXEXIT
Upstream commit:

    Date:   Tue Aug 11 20:56:53 2009 +1000
    [EVAL] Revert SKIPEVAL into EXEXIT

    Now that eval handles EV_TESTED correctly, we can remove the
    SKIPEVAL hack and simply use EXEXIT for set -e.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 15:27:44 +02:00
Denys Vlasenko
7b3fa1e441 ash: [EVAL] Pass EV_TESTED into evalcmd
Upstream commit:

    Date:   Tue Aug 11 20:48:15 2009 +1000
    [EVAL] Pass EV_TESTED into evalcmd

    This patch fixes the case where the eval command is used with
    set -e and as part of a construct that should not cause the
    shell to abort, e.g., as part of the condition of an if statement.

    This is achieved by propagating the EV_TESTED flag into the
    evalstring function through evalcmd.  As this alters the prototype
    of evalcmd it is now invoked explicitly by evalbltin.  The built-in
    infrastructure has been changed to accomodate this special case.

    In order to ensure that the EXIT trap is properly executed this
    patch clears evalskip in exitshell.  This wasn't needed before
    because of the broken way evalstring worked where it always clears
    evalskip when called by minusc.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Although, I failed to create a reproducer for this.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 15:10:16 +02:00
Denys Vlasenko
08089c7c85 ash: fix a thinko in the last commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 14:47:52 +02:00
Denys Vlasenko
514b51ddf3 ash: make internal globbing code selectable from config
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 14:33:08 +02:00
Denys Vlasenko
cac4d002e7 ash: explain how "command" is handled, and shrink it a bit
function                                             old     new   delta
getoptscmd                                           641     632      -9
commandcmd                                            79      69     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19)             Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 03:02:25 +02:00
Denys Vlasenko
e627ac95be ash: [VAR] Initialise OPTIND after importing environment
Upstream commit 1:

    Date: Fri, 23 Aug 2013 21:27:42 +1000
    [VAR] Initialise OPTIND after importing environment

    On Sat, Mar 23, 2013 at 01:46:20AM +0000, Chris F.A. Johnson wrote:
    >   According to both the dash man page and the POSIX spec, "When the
    >   shell is invoked, OPTIND is initialized to 1."
    >
    >   However, it actually takes the value of the environment variable
    >   if it exists:
    >
    > $ OPTIND=4 dash -c 'echo "$OPTIND"'
    > 4
    > $ OPTIND=4 bash -c 'echo "$OPTIND"'
    > 1
    > $ OPTIND=4 ksh -c 'echo "$OPTIND"'
    > 1
    > $ OPTIND=4 ksh93 -c 'echo "$OPTIND"'
    > 1

    This patch fixes this by initialising OPTIND after importing the
    environment.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Upstream commit 2:

    Date: Tue, 7 Oct 2014 22:24:42 +0800
    [VAR] Use setvareq to set OPTIND initially

    There is no need to setvarint to set the initial value of OPTIND
    of one.  This patch switchs to setvareq which also lets us avoid
    an unnecessary memory allocation.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 14:46:41 +02:00
Denys Vlasenko
6a0710e954 ash: [BUILTIN] Merge SKIPFUNC/SKIPFILE and only clear SKIPFUNC when leaving dotcmd
Upstream commit:

    Date: Sat, 9 Jul 2011 22:05:22 +0800
    [BUILTIN] Merge SKIPFUNC/SKIPFILE and only clear SKIPFUNC when leaving dotcmd

    Currently upon leaving a dotcmd the evalskip state is reset so
    if a continue/break statement is used within a dot script it would
    have no effect outside of the dot script.

    This is inconsistent with other shells.

    This patch is based on one by Jilles Tjoelker and only clears
    SKIPFUNC when leaving a dot script.  As a result continue/break
    will remain in effect.

    It also merges SKIPFUNC/SKIPFILE as they have no practical difference.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 14:46:41 +02:00
Denys Vlasenko
ed6ff5edfc hush: enable "msh is deprecated" message in msh stub
After giving a few more years for everyone to notice and migrate,
can nuke all remains of msh.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 12:28:37 +02:00
Denys Vlasenko
50e6d42c19 ash: Avoid overflow for very long variable name
Upstream commit:

    Date: Tue, 3 Jul 2012 17:32:33 +0800
    Avoid overflow for very long variable name

    Otherwise, this:
      $ perl -le 'print "v"x(2**31+1) ."=1"' | dash
    provokes integer overflow

    Signed-off-by: Jim Meyering <meyering@redhat.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 11:35:54 +02:00
Denys Vlasenko
b6838b520a ash: [VAR] Sanitise environment variable names on entry
Upstream commit:

    Date: Sat, 25 Feb 2012 15:35:18 +0800
    [VAR] Sanitise environment variable names on entry

    On Tue, Feb 14, 2012 at 10:48:48AM +0000, harald@redhat.com wrote:
    > "export -p" prints all environment variables, without checking if the
    > environment variable is a valid dash variable name.
    >
    > IMHO, the only valid usecase for "export -p" is to eval the output.
    >
    > $ eval $(export -p); echo OK
    > OK
    >
    > Without this patch the following test does error out with:
    >
    > test.py:
    > import os
    > os.environ["test-test"]="test"
    > os.environ["test_test"]="test"
    > os.execv("./dash", [ './dash', '-c', 'eval $(export -p); echo OK' ])
    >
    > $ python test.py
    > ./dash: 1: export: test-test: bad variable name
    >
    > Of course the results can be more evil, if the environment variable
    > name is crafted, that it injects valid shell code.

    This patch fixes the issue by sanitising all environment variable names
    upon entry into the shell.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 11:33:47 +02:00
Denys Vlasenko
a2d121cc1b ash: [EVAL] Avoid using undefined handler
Upstream commit:

    Date: Fri, 8 Jul 2011 16:41:24 +0800
    [EVAL] Avoid using undefined handler

    * src/eval.c (evalbltin, evalfun): Set savehandler before calling
    setjmp with the possible "goto *done", where savehandler is used.
    Otherwise, clang warns that "Assigned value is garbage or undefined"
    at the point where "savehandler" is used on the RHS.

    Signed-off-by: Jim Meyering <meyering@redhat.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 11:30:11 +02:00
Denys Vlasenko
53d6e03a0a ash: remove dead stores and unused variables
Upstream commit 1:

    Date: Fri, 8 Jul 2011 16:12:20 +0800
    [MEMALLOC] Avoid gcc warning: variable 'oldstackp' set but not used

    * src/memalloc.c (growstackblock): Remove declaration and set of
    set-but-not-used variable.  Also remove a stray space-before-TAB.

    Signed-off-by: Jim Meyering <meyering@redhat.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Upstream commit 2:

    Date: Fri, 8 Jul 2011 16:16:11 +0800
    [MEMALLOC] Avoid clang warning about dead store to "size"

    * src/memalloc.c (makestrspace): Remove dead store.

    Signed-off-by: Jim Meyering <meyering@redhat.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 11:24:12 +02:00
Denys Vlasenko
60ca834358 ash: [MEMALLOC] Add pushstackmark
Upstream commit:

    Author: Herbert Xu <herbert@gondor.apana.org.au>
    Date:   Sat Oct 6 00:45:52 2007 +0800

    [MEMALLOC] Add pushstackmark

    This patch gets rid of the stack mark tracking hack by allocating a little
    bit of stack memory if we're at risk of planting a stack mark which may be
    grown later.  To do this a new function pushstackmark is added which lets
    the user pick a bigger amount to allocate since some users do that anyway
    after setting a stack mark.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 11:21:21 +02:00
Denys Vlasenko
08755f9bcb hush: fix typo in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 02:02:25 +02:00
Denys Vlasenko
4074d49557 hush: fix interactive input handling of backslash+newline
function                                             old     new   delta
fgetc_interactive                                      -     258    +258
i_peek_and_eat_bkslash_nl                             43      93     +50
static_peek2                                           7       -      -7
setup_string_in_str                                   46      39      -7
setup_file_in_str                                     47      40      -7
file_peek                                             72      52     -20
expand_vars_to_list                                 1167    1143     -24
file_peek2                                            74       -     -74
file_get                                             326      65    -261
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 1/5 up/down: 308/-400)          Total: -92 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-30 01:49:53 +02:00
Denys Vlasenko
0448c55cc8 hush: G.user_input_buf[] is needed only if line editing is enabled
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 20:25:44 +02:00
Denys Vlasenko
7a24e8ffeb shell testsuite: add trailing newline to var_unbackslash1.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 20:02:53 +02:00
Denys Vlasenko
46e6498b2a hush: speed optimizations
Make o_addchr() faster: do not call o_grow_by() each time.
Create i_getch_and_eat_bkslash_nl(), use it instead of peek+getch pair.

function                                             old     new   delta
o_addchr                                              42      54     +12
parse_dollar                                         761     771     +10
o_grow_by                                             48      37     -11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 24/-11)             Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 19:50:55 +02:00
Denys Vlasenko
657086a3dc hush: fix handling of by backslash-newline in $((arith)) and $(cmd)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 18:07:42 +02:00
Denys Vlasenko
d17a91db6e hush: rework input char buffering to allow more than one-deep peek
...this time with actual hush.c changes too :)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 18:02:37 +02:00
Denys Vlasenko
459293b1c5 ash: fix arithmetic closing )) split by backslash-newline
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 17:58:58 +02:00
Denys Vlasenko
73c3e074df ash: [PARSER] Handle backslash newlines properly after dollar sign
Fixes var_unbackslash1.tests failure.

Upstream commit:

    [PARSER] Handle backslash newlines properly after dollar sign

    On Tue, Aug 26, 2014 at 12:34:42PM +0000, Eric Blake wrote:
    > On 08/26/2014 06:15 AM, Oleg Bulatov wrote:
    > > While playing with sh generators I found that dash and bash have different
    > > interpretations for <slash><newline> sequence.
    > >
    > > $ dash -c 'EDIT=xxx; echo $EDIT\
    > >> OR'
    > > xxxOR
    >
    > Buggy.
    > >
    > > $ dash -c 'echo "$\
    > > (pwd)"'
    > > $(pwd)
    > >
    > > Is it undefined behaviour in POSIX?
    >
    > No, it's well-defined, and dash is buggy.
    ...

    I agree.  This patch should resolve this problem and similar ones
    affecting blackslash newlines after we encounter a dollar sign.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 17:17:04 +02:00
Denys Vlasenko
8286513838 hush: rework input char buffering to allow more than one-deep peek
This fixes backslash+newline continuation in
	$VAR\
	NAME
construct. (ash has a bug there as well).

function                                             old     new   delta
file_peek2                                             -      74     +74
parse_dollar                                         746     773     +27
expand_vars_to_list                                 1143    1167     +24
setup_string_in_str                                   32      46     +14
setup_file_in_str                                     33      47     +14
file_get                                             264     278     +14
static_peek2                                           -       7      +7
file_peek                                             91      72     -19
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/1 up/down: 174/-19)           Total: 155 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 16:59:06 +02:00
Denys Vlasenko
3b4d04b77e ash: input: Allow two consecutive calls to pungetc
Upstream commit:

    input: Allow two consecutive calls to pungetc

    The commit ef91d3d6a4c39421fd3a391e02cd82f9f3aee4a8 ([PARSER]
    Handle backslash newlines properly after dollar sign) created
    cases where we make two consecutive calls to pungetc.  As we
    don't explicitly support that there are corner cases where you
    end up with garbage input leading to undefined behaviour.

    This patch adds explicit support for two consecutive calls to
    pungetc.

    Reported-by: Jilles Tjoelker <jilles@stack.nl>
    Reported-by: Juergen Daubert <jue@jue.li>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

In bbox case, bashism >& may need two pungetc() too.

function                                             old     new   delta
pgetc                                                514     555     +41
pushstring                                           114     144     +30
basepf                                                52      76     +24
popstring                                            134     151     +17
parse_command                                       1584    1585      +1
pungetc                                               12       9      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/1 up/down: 113/-3)            Total: 110 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 02:11:19 +02:00
Denys Vlasenko
78c9c736ab hush: fix 'eval ""' handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 01:44:17 +02:00
Denys Vlasenko
992e0ff7e9 hush: fix ". EMPTY_LINE" not setting $? to 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 01:27:09 +02:00
Denys Vlasenko
46a45ce02f ash: jobs: Don't attempt to access job table for job %0
Upstream commit:

    jobs: Don't attempt to access job table for job %0

    If job %0 is (mistakenly) specified, an out-of-bounds access to the
    jobtab occurs in function getjob() if num = 0:

            jp = jobtab + 0 - 1

    Fix this by checking that the job number is larger than 0 before
    accessing the jobtab.

    Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 01:10:08 +02:00
Denys Vlasenko
928e2a7ef4 ash: [EVAL] Make eval with empty arguments return 0
This is a backport of upstream commit:

    [EVAL] Make eval with empty arguments return 0

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 00:30:31 +02:00
Denys Vlasenko
8e2bc47d62 ash: [EVAL] Fix use-after-free in dotrap/evalstring
From upstream:

    [EVAL] Fix use-after-free in dotrap/evalstring

    The function dotrap calls evalstring using the stored trap string.
    If evalstring then unsets that exact trap string then we will end
    up using freed memory.

    This patch fixes it by making evalstring always duplicate the string
    before using it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-28 23:02:57 +02:00
Denys Vlasenko
7ee7c6fc20 ash: Remove unused EV_BACKCMD flag
The original ash defered forking commands in backquotes so builtins
    could be run in the same context as the shell.  This behavior was
    controlled using the EV_BACKCMD to evaltree.

    Unfortunately, as Matthias Scheler noticed in 1999 (NetBSD PR/7814),
    the result was counterintuitive; for example, echo "`cd /`" would
    change the cwd.  So ash 0.3.5 left out that optimization.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-28 19:44:16 +02:00
Denys Vlasenko
eb17b6f6c9 ash: eval: Return status in eval functions
Backported from dash:

    eval: Return status in eval functions

    The exit status is currently clobbered too early for case statements
    and loops.  This patch fixes it by making the eval functions return
    the current exit status and setting them in one place -- evaltree.

    Harald van Dijk pointed out a number of bugs in the original patch.

function                                             old     new   delta
evalcommand                                         1226    1242     +16
cmdloop                                              383     398     +15
evalfor                                              223     227      +4
evalcase                                             271     275      +4
localcmd                                             348     350      +2
evaltreenr                                           927     928      +1
evaltree                                             927     928      +1
evalsubshell                                         150     151      +1
evalpipe                                             356     357      +1
parse_command                                       1585    1584      -1
evalloop                                             177     164     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 9/2 up/down: 45/-14)             Total: 31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-28 19:41:57 +02:00
Denys Vlasenko
1c32e49bdf traceroute: cleanup and fixes for packet size calculations
Remove FEATURE_TRACEROUTE_SOURCE_ROUTE: it's off by default, and
source routing is not used in real world.

Tested that "traceroute -n ::1 100" and "traceroute -n 127.0.0.1 100"
both send 100 byte IP packets (this matches what traceroute on Fedora
Rawhide is doing).

function                                             old     new   delta
common_traceroute_main                              3731    3738      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-28 18:44:48 +02:00
Denys Vlasenko
61fcc8c781 vi: fix '' command (goto to prev context)
The '' command in vi doesn't currently work because after the first
apostrophe is read, the next character is converted to an integer
between 0 and 25 inclusive (for indexing the array of marks). The
comparison of the converted character with an apostrophe therefore never
succeeds, meaning that '' doesn't do anything.

Based on the patch by Francis Rounds <francis.rounds@4bridgeworks.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-28 16:23:05 +02:00
Denys Vlasenko
b09ab448b8 mount: for cifs, dont insert "ip=ADDR" option if user gave it explicitly
This makes it possible to use scoped IPv6 addresses:

mount -t cifs -o ip=<ADDR>%<iface_id> //<ADDR>/test test

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-27 21:02:35 +02:00
Denys Vlasenko
dea3bdbefe examples: wpa_supplicant.conf has a wrong field deleted in examples
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-26 20:47:17 +02:00
Denys Vlasenko
5093c8c4aa mount: tweak "IPv6 scoped addr" commit
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-26 20:36:30 +02:00
Denys Vlasenko
3c18e3051d libbb: make xmalloc_sockaddr2dotted use NI_NUMERICSCOPE
Gives "mount -t cifs //fe80::6a05:caff:fe3e:dbf5%eth0/test test"
a chance to work: mount must pass "ip=numeric_IPv6%numeric_iface_id"
in the omunt option string. Currently, it does not.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-26 19:53:04 +02:00
Denys Vlasenko
525209ac94 libbb/speed_table.c: expand comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-26 14:37:12 +02:00
Denys Vlasenko
4537f83d52 typo fix in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-26 08:52:52 +02:00
Denys Vlasenko
557482c1cb ash: in heredoc code, fix access past the end of allocated memory. Closes 9276
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-25 21:24:04 +02:00
Denys Vlasenko
13f20919b2 ash: fix handling of NULs in $'abc\000def\x00asd'. Closes 9286
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-25 20:54:25 +02:00
Denys Vlasenko
bcf47eaa1f ifupdown: improve help text, add comment about run-parts error msg
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-25 02:05:24 +02:00
Denys Vlasenko
65ba7113e3 libbb: handle \S in /etc/issue
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-24 23:50:43 +02:00
Linus Walleij
d526b11897 AUTHORS: Add myself to AUTHORS
Instead of complaining that my authorship of the rewrite of
the mdev to use /sys/dev is totally gone from the git history
I bravely take credit by adding myself to the AUTHORS file
instead, he he.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-22 11:25:02 +02:00
Denys Vlasenko
b3f29b452a ash: use glob() from libc
Adapted from dash.
The "homegrown" glob code is retained (ifdef'ed out).
This changes was inspired by bug 9261, which detected out-of bounds use of heap
for 2098 byte long name in the "homegrown" code. This is still not fixed...

function                                             old     new   delta
expandarg                                            960     982     +22
static.syntax_index_table                             26      25      -1
static.spec_symbls                                    27      26      -1
static.metachars                                       4       -      -4
addfname                                              42       -     -42
msort                                                126       -    -126
expmeta                                              528       -    -528
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 1/2 up/down: 22/-702)          Total: -680 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-21 16:25:58 +02:00
Denys Vlasenko
d8330ca4a4 examples/var_service/supplicant_if: new service example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-20 18:09:00 +02:00
Denys Vlasenko
92d98f0612 ifupdown: when flushing addresses with "ip", add label %label%
User report:

or our board we setup eth0:0 on a 10.10.10.x/29 netwrok.

The problem is ip addr flush dev eth0:0 removes all ip addresses from
eth0.  You can see this if you run
ip -stat -stat addr flush dev eth0:0

2: eth0    inet 172.27.105.10/22 brd 172.27.107.255 scope global eth0
       valid_lft forever preferred_lft forever
2: eth0    inet 10.10.10.9/29 scope global eth0:0
       valid_lft forever preferred_lft forever
2: eth0    inet6 fe80::a2f6:fdff:fe18:2b13/64 scope link
       valid_lft forever preferred_lft forever

*** Round 1, deleting 3 addresses ***
*** Flush is complete after 1 round ***

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-20 17:31:11 +02:00
Denys Vlasenko
244fdd45c7 ash: fix handling of bashism $'xxx' with high-bit chars. Closes 9236
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-20 17:04:09 +02:00
Denys Vlasenko
d6a37d86ba hush: document better where bad redirect syntax is detected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-20 16:22:24 +02:00
Hauke Mehrtens
4ff86df861 libnetlink: fix alignment of netlink messages
A padding to align a message should not only be added between
different attributes of a netlink message, but also at the end of the
message to pad it to the correct size.

Without this patch the following command does not work and returns an
error code:
ip link add type nlmon

Without this ip from busybox sends this:

sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000},
	msg_namelen=12, msg_iov=[{iov_base={{len=45, ...},
		"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon"}, iov_len=45}],
	msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 45
return value: 2

The normal ip utile from iproute2 sends this:

sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000},
	msg_namelen=12, msg_iov=[{iov_base={{len=48, ...},
		"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon\0\0\0"}, iov_len=48}],
	msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48
return value: 0

With this patch ip from busybox sends this:

sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000},
	msg_namelen=12, msg_iov=[{iov_base={{len=48, ...},
		"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\20\0\22\0\t\0\1nlmon\0\0\0"}, iov_len=48}],
	msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 48
return value: 0

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-18 22:55:47 +02:00
Denys Vlasenko
0ae0509679 libbb: do not use fflush_unlocked, musl does not like fflush_unlocked(NULL)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-18 21:49:30 +02:00
Rostislav Skudnov
204c7fb229 ash: exit after subshell error when errexit option is set
When "set -e" option is on, shell must exit when any command fails,
including compound commands of the form (compound-list) executed in a
subshell. Bash and dash shells have this behaviour.

Also add a corresponding testcase.

Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-17 23:28:23 +02:00
Denys Vlasenko
b157eb13cb fdisk: fix CONFIG_FEATURE_SUN_LABEL=y build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-17 21:05:06 +02:00
Denys Vlasenko
7373759947 fix "aloc" -> "alloc" typos
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-17 20:58:22 +02:00
Denys Vlasenko
7bc3d39695 ash: add a FIXME for bug 9246
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-17 20:53:47 +02:00
Francis Rounds
d2c5de0130 svlogd: strip leading '!' from processor lines
When using svlogd's processor functionality to run arbitrary commands
on log rotation, the line in the config is executed verbatim, i.e. the
exclamation mark is included.

For example, if the config file contains:

    s100
    !cat

then when it's time to rotate the log files after each 100 bytes, sh -c
"!cat" will be run, instead of sh -c "cat" as intended. The result is
svlogd logging

    /bin/bash: !cat: command not found
    svlogd: warning: processor failed, restart: /tmp/svlogd/

over and over again as it keeps attempting to execute the processor and
failing (unless you happen to have a "!cat" binary around :)).

Skipping the exclamation mark when performing the wstrdup() fixes the
issue.

Signed-off-by: Francis Rounds <francis.rounds@4bridgeworks.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-15 14:05:04 +02:00
Denys Vlasenko
de1996dac5 vi: make "g<key>" error message less likely to show garbage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-15 13:53:42 +02:00
Denys Vlasenko
7cef4817d6 libbb:/send_to_from: do not require that "to" should have the same AF. Closes 9146
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-15 13:20:51 +02:00
Mike Frysinger
3a45b87ac3 modutils: support finit_module syscall
On some systems like Chromium OS, loading modules from non-verified
filesystems is denied.  Only finit_module is allowed because an open
fd is passed which can be checked against a verified location.

Change the module loading code to first attempt finit_module and if
that fails for whatever reason, fall back to the existing logic.

On x86_64, this adds ~80 bytes to modutils/modutils.o and ~68 bytes
to modutils/modprobe-small.o.

Signed-off-by: Mike Frysinger <vapier@chromium.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-15 12:16:33 +02:00
Denys Vlasenko
7fa799a97d less: switch off nonblock on kbd_fd before exit
This is only necessary if we use stdout fd.

function                                             old     new   delta
less_exit                                             32      51     +19
less_main                                           2540    2543      +3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 22/0)               Total: 22 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-13 21:05:48 +02:00
Denys Vlasenko
3c0e579a06 less: fall back to using fd #1 for keyboard reading. Closes 9231
function                                             old     new   delta
less_main                                           2535    2540      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-13 20:53:38 +02:00
Denys Vlasenko
20a3262cd7 mdev: create devices from /sys/dev
Currently some new devices that have a bus but no class will
be missed by mdev coldplug device creation after boot. This
happens because mdev recursively searches /sys/class which will
by definition only find class devices.

Some important devices such as iio and gpiochip does not have
a class. But users will need them.

This switches from using /sys/class as the place to look for
devices to create to using /sys/dev where all char and block
devices are listed.

The subsystem lookup code that provide the G.subsystem
environment variable is changed from using the directory
name of the class device to instead dereference the
"subsystem" symlink for the device, and look at the last
element of the path of the symlink for the subsystem, which
will work with class devices and bus devices alike. (The new
bus-only devices only symlink to the /sys/bus/* hierarchy.)

We delete the legacy kernel v2.6.2x /sys/block device path
code as part of this change. It's too old to be kept alive.

Tested on kernel v4.6-rc2 with a bunch of devices, including
some IIO and gpiochip devices.

With a print inserted before make_device() the log looks
like so:

Create device from "/sys/dev/char/1:1", subsystem "mem"
Create device from "/sys/dev/char/1:2", subsystem "mem"
Create device from "/sys/dev/char/1:3", subsystem "mem"
Create device from "/sys/dev/char/1:5", subsystem "mem"
(...)
Create device from "/sys/dev/block/179:56", subsystem "block"
Create device from "/sys/dev/block/179:64", subsystem "block"

function                                             old     new   delta
mdev_main                                           1388    1346     -42
dirAction                                            134      14    -120
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-162)           Total: -162 bytes

Cc: Isaac Dunham <ibid.ag@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-07 14:09:01 +02:00
Denys Vlasenko
b9f56e82da sendmail: make it possible to pause after connection helper is started
If a non-starttls helper is in use, initial 220 response is processed by us,
not by helper.
Some servers consider us to be a spammer if we don't wait for it.

It is not in protocol, but it is a real-life problem.

The workaround in this patch is a magic envvar, $SMTP_ANTISPAM_DELAY:

...
	-H 'PROG ARGS'	Run connection helper. Examples:
		openssl s_client -quiet -tls1 -starttls smtp -connect smtp.gmail.com:25
		openssl s_client -quiet -tls1 -connect smtp.gmail.com:465
			$SMTP_ANTISPAM_DELAY: seconds to wait after helper connect
...

By using it, people can tweak sendmail behavior even if sendmail invocation
is buried in some scripts.

function                                             old     new   delta
packed_usage                                       30464   30497     +33
sendmail_main                                       1185    1206     +21
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 54/0)               Total: 54 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-07 13:16:33 +02:00
Serj Kalichev
d42cdc2222 volume_id: Add support for UBIFS
Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-06 18:31:01 +02:00
Denys Vlasenko
9fd61be191 libbb/xwrite: print errno on "short write" errors
Lauri Kasanen:
:: Over at TinyCore, we receive a huge number of questions of the type "I
:: got "short write", what does it mean?". Mostly for the rpi port and when
:: using bb wget.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-05 15:20:10 +02:00
Denys Vlasenko
76787a7e02 libbb/speed_table.c: survive B115200 and B230400 not fitting into 16 bits
Seen on OSX.
While at it, expand baud table with B500000..B4000000

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-01 11:44:13 +02:00
Denys Vlasenko
ef15970d7e *: placate some compile warnings on OSX
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-01 11:16:22 +02:00
Denys Vlasenko
76d72376e0 sed: fix "sed n (flushes pattern space, terminates early)" testcase failure
Patch based on work by Dengke Du <dengke.du@windriver.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-01 01:59:11 +02:00
Denys Vlasenko
9ff910de6b wget: treat 201,202,203 as success codes too. Closes 9211
This matches "standard" wget.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-31 13:28:53 +02:00
Denys Vlasenko
d811aaa43c sha3sum: fix config text (it's no longer only 512-bit)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-29 15:20:15 +02:00
Denys Vlasenko
71a090f187 sha3: fix to conform to final SHA3 padding standard, add -a BITS option
function                                             old     new   delta
hash_file                                            331     396     +65
md5_sha1_sum_main                                    485     538     +53
packed_usage                                       30423   30464     +41
sha3_begin                                            17      31     +14
sha3_hash                                            101     110      +9
sha3_end                                              41      49      +8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-29 14:05:25 +02:00
Denys Vlasenko
d3d7f085eb hexdump: fix numerous bugs in handling of backslashes
Was:
	t=48\\	t=45\\	t=4c\\	t=4c\\	t=4f\\	t=0a\\
Now:
	=48=\n	=45=\n	=4c=\n	=4c=\n	=4f=\n	=0a=\n

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-26 20:14:31 +02:00
Peter Korsgaard
b6355e2bb5 udhcpc: Unconditionally call deconfig script, not only if lease is active
The udhcpc script may be used to setup fallback configuration (E.G. IPv4LL,
fixed IP address, ..) that also needs to be cleaned up on release (E.G.
when SIGUSR2 is called or on shutdown with -R), so unconditionally call
deconfig.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-26 18:46:34 +02:00
Denys Vlasenko
0dddbc1a59 build system: always rewrite NUM_APPLETS.h
Conditional rewrite can keep NUM_APPLETS.h mtime old,
this causes make to try to regenerate it at every invocation.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-23 20:21:36 +02:00
Denys Vlasenko
29483ffb07 fdisk: tweak some messages
"Total allocated sectors 2021315 greater than the maximum 2020356"

maximum what?

Turns out, that's the CHS size of the disk.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-23 17:18:45 +02:00
Denys Vlasenko
607f2b404e fdisk: print much less cryptic partition table
Before:

   Device Boot      Start         End      Blocks  Id System
/dev/sdb1   *           1         998      255471+  6 FAT16

What are "blocks"? What is that "+"?
How big is this partition?
Is start/end shown came from LBA fields or CHS fields?
Why are we torturing the user??

After:

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sdb1 *  0,1,1       996,15,32           32     510974     510943  249M  6 FAT16

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-23 16:13:33 +02:00
Denys Vlasenko
6b76e23454 man: fix parsing of "DEFINE pager xyz". Closes 8976
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22 21:41:05 +02:00
Denys Vlasenko
d035528261 init: fix for FreeBSD console opening. Closes 9031
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22 20:56:58 +02:00
Denys Vlasenko
2cf9fa6e59 unshare: --network should be --net. Closes 9116
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22 20:19:34 +02:00
Kang-Che Sung
b28897849f docs: Update filenames in keep_data_small.txt
The filenames in docs/keep_data_small.txt are a little bit outdated.
It's better to change it to the current name.

decompress_unzip.c -> decompress_gunzip.c
(since commit 774bce8e8b)
libbb/messages.c -> libbb/ptr_to_globals.c
(since commit 574f2f4394)

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22 20:15:50 +02:00
Denys Vlasenko
aa3576a29b hush: fix "redirects can close script fd" bug
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22 19:54:12 +02:00
Denys Vlasenko
d8e61bbf13 build system: different fix for include/applet_tables.h/include/NUM_APPLETS.h
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-21 22:00:20 +02:00
Denys Vlasenko
de3da6bf87 wget/ssl_helper: update to wolfssl-3.9.8
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-21 03:39:39 +02:00
Denys Vlasenko
7b25b1c5b2 hush: do not leak script fds into NOEXEC children
We set all opened script fds to CLOEXEC, thus making then go away
after fork+exec.
Unfortunately, CLOFORK does not exist. NOEXEC children will still see those fds open.

For one, "ls" applet is NOEXEC. Therefore running "ls -l /proc/self/fd"
in a script from standalone shell shows this:

lrwx------    1 root     root            64 Aug 20 15:17 0 -> /dev/pts/3
lrwx------    1 root     root            64 Aug 20 15:17 1 -> /dev/pts/3
lrwx------    1 root     root            64 Aug 20 15:17 2 -> /dev/pts/3
lr-x------    1 root     root            64 Aug 20 15:17 3 -> /path/to/top/level/script
lr-x------    1 root     root            64 Aug 20 15:17 4 -> /path/to/sourced/SCRIPT1
...

with as many open fds as there are ". SCRIPTn" nest levels.
Fix it by closing these fds after fork (only for NOEXEC children).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-20 15:58:34 +02:00
Denys Vlasenko
869994cf4f hush: bit better comments in redirect code. No logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-20 15:16:00 +02:00
Denys Vlasenko
e9abe75fda hush: cmd and arithmetic also need the fix for FILE rewind
Discovered by running testsuite with a newest glibc

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-19 20:15:26 +02:00
Denys Vlasenko
215b0ca6e4 hush: fix a bug in FEATURE_SH_STANDALONE=y config. Closes 9186
Run this in a "sh SCRIPT":

sha256sum /dev/null
echo END

sha256sum is a NOEXEC applet. It runs in a forked child. Then child exit()s.
By this time, entire script is read, and buffered in a FILE object
from fopen("SCRIPT"). But fgetc() did not consume entire input.
exit() lseeks back by -9 bytes, from <eof> to 'e' in 'echo'.
(this may be libc-specific).
This change of fd position *is shared with the parent*!

Now parent can read more, and it thinks there is another "echo END".
End result: two "echo END"s are run.

Fix this by _exit()ing instead.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-19 18:43:06 +02:00
Denys Vlasenko
aedc3fe19f top: move free(prev_hist) out of signal path
It was seen being called recursively on repeated signals,
leading to double free

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-19 11:07:31 +02:00
Denys Vlasenko
b11be131b7 ifplugd: if SIOCSIFFLAGS fails with ENODEV, don't die
Some user managed to hit a race where iface is gone between SIOCGIFFLAGS
and SIOCSIFFLAGS (!). If SIOCSIFFLAGS fails, treat it the same as failed
SIOCGIFFLAGS

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-16 20:39:52 +02:00
Denys Vlasenko
110c6bb413 less: fix bracket search to match behavior of less 481
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-16 15:27:30 +02:00
Denys Vlasenko
252559601f less: fix SEGV
testcase: echo "" | less, then press ')' key

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-16 15:09:40 +02:00
Natanael Copa
560cf8c7eb gzip: add test that checks that -9 compresses better than -1
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-15 01:31:17 +02:00
Natanael Copa
71cfbce655 gzip: fix compression level bug. Closes 9131
fix broken logic to get the gzip_level_config value from options -1 to
-9.

This fixes an off-by-one bug that caused gzip -9 output bigger files
than the other compression levels.

It fixes so that compression level 1 to 3 are actually mapped to level 4
as comments say.

It also fixes that levels -4 to -9 is mapped to correct level and avoids
out-of-bounds access.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-15 01:26:28 +02:00
Natanael Copa
7e6f9316a8 lineedit: trivial codeshrink for vi-mode
Introduce and use BB_isalnum_or_underscore().

function                                             old     new   delta
BB_isalnum_or_underscore                               -      43     +43
vi_word_motion                                       162     150     -12
vi_end_motion                                        163     145     -18
vi_back_motion                                       198     179     -19
BB_isalnum                                            39       -     -39
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/3 up/down: 43/-88)            Total: -45 bytes

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-14 23:30:29 +02:00
Denys Vlasenko
9e5820a862 build system: fix include/NUM_APPLETS.h generation
TBH, it's more like "work around my bad makefile-fu" than "fix"...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-14 02:54:27 +02:00
Denys Vlasenko
4548293799 libiproute: eliminate some redundant zero stores
function                                             old     new   delta
do_iprule                                            974     955     -19
rtnl_dump_request                                    173     146     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-46)             Total: -46 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-14 02:08:56 +02:00
Denys Vlasenko
34ecc3b7ae ip: fix an improper optimization: req.r.rtm_scope may be nonzero here
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-14 01:30:34 +02:00
Denys Vlasenko
98c50f93fe cp: fix -i for POSIX mode. Closes 9106
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-13 23:23:48 +02:00
Miroslav Lichvar
150dc7a2b4 ntpd: respond only to client and symmetric active packets
The busybox NTP implementation doesn't check the NTP mode of packets
received on the server port and responds to any packet with the right
size. This includes responses from another NTP server. An attacker can
send a packet with a spoofed source address in order to create an
infinite loop of responses between two busybox NTP servers. Adding
more packets to the loop increases the traffic between the servers
until one of them has a fully loaded CPU and/or network.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-01 20:25:06 +02:00
Denys Vlasenko
6b5abc9596 service/fw example: do not ruin $if[], use different name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-30 22:29:10 +02:00
Denys Vlasenko
ed72761843 wget: run s_client helper with -servername HOST
This is necessary for multi-hosted TLSed web sites.

function                                             old     new   delta
spawn_https_helper_openssl                           334     441    +107

Based on a patch by Jeremy Chadwick <jdc@koitsu.org>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-25 21:34:57 +02:00
Denys Vlasenko
9d20297ba8 ssl_helper.sh: strip was invoked incorrectly
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-25 17:12:46 +02:00
Denys Vlasenko
3191ec7cce var_service/fw: optionally flush all netdevs; optionally prefer one 0/0 routing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-25 16:28:57 +02:00
Denys Vlasenko
f8ddbe1ccc ash: fix handling of ${VAR: -2}
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-25 03:56:00 +02:00
Denys Vlasenko
0fb0045aa9 config: disentangle PREFER_APPLETS from SH_STANDALONE and SH_NOFORK
On user request.
I thought enabling/disabling them all together is more consistent.
Evidently, some people do want them to be separately selectable.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-22 18:48:38 +02:00
Denys Vlasenko
49117b4800 hush: fix a possible bug
Not sure this was actually a triggerable bug, but the code looked flaky.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-21 14:42:13 +02:00
Denys Vlasenko
e695ac97fd typo fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-19 17:48:55 +02:00
Denys Vlasenko
e5814a5a42 ash: do not leave SIGQUIT ignored on "exec CMD"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-16 18:33:55 +02:00
Denys Vlasenko
ca003385f1 cp: make verbose cp show symlink copies too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-14 20:58:39 +02:00
Denys Vlasenko
2a4d7f44a4 sendmail: include -H and -S in short help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-14 20:06:44 +02:00
Denys Vlasenko
9de7509aa0 sendmail: improve help text
* explain which server we contact by default
* explain when auth is done
* -t is not implied! remove that from help text

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-14 19:14:54 +02:00
Denys Vlasenko
2ae86ad1c6 trylink: use "mktemp tmp.XXXXXXXXXX" to placate OS X
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-12 13:54:35 +02:00
Denys Vlasenko
b0056ea86d {md5,shaN}sum: make -c EMPTY fail
function                                             old     new   delta
md5_sha1_sum_main                                    466     485     +19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-11 19:51:08 +02:00
Denys Vlasenko
f6348e50ef examples: add a useful "see abridged log" script for ntpd service example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-10 20:15:28 +02:00
Denys Vlasenko
d2f4241d2e cpio: tweak help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-08 12:52:24 +02:00
Denys Vlasenko
237bedd499 getopt32: add new syntax of 'o:+' and 'o:*' for -o NUM and -o LIST
In many cases, this aqllows to drop use of opt_complementary.
Approximately -400 bytes:

function                                             old     new   delta
getopt32                                            1423    1502     +79
opt_string                                            17      18      +1
OPT_STR                                               24      25      +1
uniq_main                                            416     406     -10
timeout_main                                         279     269     -10
sulogin_main                                         270     260     -10
readprofile_main                                    1825    1815     -10
ps_main                                              543     533     -10
pidof_main                                           245     235     -10
pgrep_main                                           611     601     -10
od_main                                             2600    2590     -10
mkfs_minix_main                                     2684    2674     -10
mkfs_ext2_main                                      2603    2593     -10
microcom_main                                        712     702     -10
makemime_main                                        315     305     -10
ionice_main                                          282     272     -10
inetd_main                                          2074    2064     -10
ifplugd_main                                        1144    1134     -10
halt_main                                            353     343     -10
getopt_main                                          636     626     -10
fdisk_main                                          2854    2844     -10
env_main                                             206     196     -10
dmesg_main                                           319     309     -10
conspy_main                                         1214    1204     -10
awk_main                                             981     971     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/22 up/down: 81/-220)         Total: -139 bytes
   text	   data	    bss	    dec	    hex	filename
 919373	    906	  14060	 934339	  e41c3	busybox_old
 918969	    906	  14060	 933935	  e402f	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-06 21:58:02 +02:00
Denys Vlasenko
0844b5afe2 whois: implement -i
function                                             old     new   delta
whois_main                                           654     675     +21
packed_usage                                       30355   30356      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-06 17:16:27 +02:00
Denys Vlasenko
1035c92e2d whois: make it actually work
It was doing way too simplistic work of just querying the server,
no redirects, no query massaging. This required user to know a lot about whois,
and enter at least three queries for each host to get meaningful information.

function                                             old     new   delta
whois_main                                           209     646    +437

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-06 15:45:41 +02:00
Denys Vlasenko
f4f8fe841c build system: fix a few warnings for allnoconfig build
Not that allnoconfig build is useful in any way...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-05 21:43:28 +02:00
Ron Yorston
1b0dcc02dd libbb: suppress warning about run_applet_and_exit
When busybox is configured to contain a single applet an unnecessary
declaration of run_applet_and_exit results in a warning.  Move the
declaration to avoid this.

Reported-by: Lauri Kasanen <curaga@operamail.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-05 21:21:36 +02:00
Denys Vlasenko
ee772a0d90 arp: fix buffer overflow. Closes 9071
function                                             old     new   delta
arp_main                                            1910    1898     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-04 17:38:01 +02:00
Denys Vlasenko
44399e00ff udhcpc: run "deconfig" script in manual renew state too. closes 9061
The bug was seen when the following is done:

    # killall 1 udhpc; killall 2 udhpc

Performing a DHCP renew
state: 2 -> 5
Sending renew...
Entering released state
state: 5 -> 6  <<<<<<<<<<<<<< not calling script!!!!

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-03 20:26:44 +02:00
Denys Vlasenko
aabb0a93e9 ntpd: daemonize before DNS resolution
This resolves the following use case problem:

"I start ntpd by default from /etc/init.d

There might be no working network connection (not configured properly for
whatever reason, hardware problems, whatelse).

With busybox 1.25 ntpd seems to loop forever if now NTP servers are found,
blocking the boot process  and I never get a login to solve a possible pb or
to do a first time configuration."

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-07-03 17:58:54 +02:00
Denys Vlasenko
5b8c89d1f2 build system: make CONFIG_FEATURE_USE_BSS_TAIL less funky
CONFIG_FEATURE_USE_BSS_TAIL code was aliasing bb_common_bufsiz1 to _end.
This is unreliable: _end may be not sufficiently aligned.

Change code to simply enlarge COMMON_BUFSIZE when we detect that _end
has significant amount of space to the end of page.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-29 15:00:52 +02:00
Natanael Copa
8f4faa1e3d df: use f_frsize instead of f_bsize for correct sizes
Use the correct field f_frsize instead of f_bsize.

The statfs f_bsize is the "Optimal transfer block size" while the
f_frsize is the "Fragment size (since Linux 2.6)". On some FUSE
filesystems those may differ.

Fixes bug 9046

URL: https://bugs.busybox.net/show_bug.cgi?id=9046

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-24 04:12:01 +02:00
Bartosz Golaszewski
59f8197624 i2cdump: don't use common_bufsiz1
Commit e6a2f4cc changed the way common_bufsiz1 works. Now it needs to
be initialized before using, but i2cdump wasn't updated by said patch.

Since the fact that we're using common_bufsiz1 here isn't obvious (no
G_INIT() macro, no other global variables), drop it and simply
allocate the integer array required for block reads on the stack.

Tested with i2c block read on a Lenovo Thinkpad laptop.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-24 03:58:43 +02:00
Jonas Danielsson
4d5acd2d42 ping: populate icmp_id field for "simple" ping too
The ICMP RFC says that identifier and sequence number may be zero.
Having them zero for a Echo message, along with a data of zero's
as well will result in a Echo reply message with only zero's.

Some NAT implementations seem to get the checksum wrong on these
packages. Setting a checksum of 0x0 instead of 0xffff.

Through NAT:
  Internet Control Message Protocol
      Type: 0 (Echo (ping) reply)
      Code: 0
      Checksum: 0x0000 [incorrect, should be 0xffff]
      Identifier (BE): 0 (0x0000)
      Identifier (LE): 0 (0x0000)
      Sequence number (BE): 0 (0x0000)
      Sequence number (LE): 0 (0x0000)
      Data (56 bytes)
          Data: 000000000000000000000000000000000000000000000000...
          [Length: 56]

Without NAT:
  Internet Control Message Protocol
      Type: 0 (Echo (ping) reply)
      Code: 0
      Checksum: 0xffff [correct]
      Identifier (BE): 0 (0x0000)
      Identifier (LE): 0 (0x0000)
      Sequence number (BE): 0 (0x0000)
      Sequence number (LE): 0 (0x0000)
      [Request frame: 189]
      [Response time: 0.024 ms]
      Data (56 bytes)
          Data: 000000000000000000000000000000000000000000000000...
          [Length: 56]

And this in turn will make some hardware MAC checksum offloading
engines drop the packet.

(This was seen with a Synopsis MAC, the same one used in for instance the
stmmac Ethernet driver in the linux kernel.)

This change can be seen as a workaround for bugs in other layers.
But just setting an identifier for the Echo message packet will
avoid prodding the hornets nest.

function                                             old     new   delta
common_ping_main                                     424     500     +76

Signed-off-by: Jonas Danielsson <jonasdn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-23 18:26:32 +02:00
Denys Vlasenko
9ca56f9621 Start 1.26.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-22 03:10:21 +02:00
Denys Vlasenko
c3b34d8b39 Bump version to 1.25.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-22 00:58:56 +02:00
Denys Vlasenko
10c0e91786 libarchive: fix xmalloc_open_zipped_read_close()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-21 02:04:16 +02:00
Denys Vlasenko
7cf45ae10e setsid: fix broken -c
This did not work: setsid sh -c 'anything'

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 23:50:26 +02:00
Denys Vlasenko
e24e88697a typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 16:28:53 +02:00
Denys Vlasenko
ea9ebc011b scripts/trylink: libbusybox fix
gcc 6.1.1 can emit empty line with spaces

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 12:23:35 +02:00
Denys Vlasenko
df3ec0e2f7 libarchive: fix open_zipped()
Last commit broke it (on both MMU and NOMMU)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:42:00 +02:00
Denys Vlasenko
984b0a613a libarchive: fix xmalloc_open_zipped_read_close() on NOMMU
The somewhat new "unpack in memory" code was broken
for xmalloc_open_zipped_read_close() on NOMMU: we seek back
over signature, but then expect it to be already consumed.
Stop seeking back in this case.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:06:42 +02:00
Denys Vlasenko
ecf25cb5bc randomconfig fixes 5: false positive for tar; mount emits corrupted message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:04:04 +02:00
Denys Vlasenko
5c3e060604 modprobe-small: fix bogus handling of unpack errors
"modprobe minix; echo $?"

Was:
modprobe: corrupted data
modprobe: read error from 'kernel/fs/minix/minix.ko.xz': No such file or directory
modprobe: corrupted data
modprobe: read error from 'kernel/fs/minix/minix.ko.xz': No such file or directory
modprobe: corrupted data
modprobe: read error from 'kernel/fs/minix/minix.ko.xz'
modprobe: 'kernel/fs/minix/minix.ko.xz': Success
0

Now:
modprobe: corrupted data
modprobe: read error from 'kernel/fs/minix/minix.ko.xz'
1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:02:40 +02:00
Denys Vlasenko
0ad872baf3 randomconfig fixes 4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 01:40:19 +02:00
Denys Vlasenko
94046d0495 randomconfig fixes 3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 00:36:21 +02:00
Denys Vlasenko
bb0bf287d8 randomconfig fixes 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-19 21:54:04 +02:00
Denys Vlasenko
015db5800c randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-19 18:15:33 +02:00
Ron Yorston
ce824aecf2 libbb: move common code into run_applet_and_exit
Both calls to run_applet_and_exit are followed by the same code
to print an error message and return status 127.  Remove this
duplication and make run_applet_and_exit static.

function                                             old     new   delta
run_applet_and_exit                                  675     667      -8
main                                                 119      92     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-35)             Total: -35 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-19 15:16:27 +02:00
Ron Yorston
ba12081a9e Allow "busybox <applet>" to work when busybox is disabled
A recent commit made it possible to disable BusyBox's --install
and --list options.  However it also stopped "busybox <applet>
<params>" from working.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-18 19:15:20 +02:00
Denys Vlasenko
e4caf1dd9c ntpd: retry initial DNS resolution (forever, no timeout for now).
Some users start ntpd on boot, and don't babysit it. If it dies because
DNS is not yet up and therefore NTP servers can't be found, users are
not happy.

Example behavior with a peer name which can't be resolved:

ntpd: bad address 'qwe.rty.ghj.kl'
...5 sec...
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
...

Based on the patch by Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>

function                                             old     new   delta
resolve_peer_hostname                                  -      81     +81
ntpd_main                                           1130    1061     -69
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 81/-69)             Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-06 02:26:49 +02:00
Natanael Copa
b684d1b186 libbb: fix time parsing of [[CC]YY]MMDDhhmm[.SS]. Closes 8951
If SS is not given a value, it is assumed to be zero.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-31 02:50:54 +02:00
Denys Vlasenko
8e95068c7f Make busybox an optional applet
If it's disabled, code shrinks by about 900 bytes:

function                                             old     new   delta
usr_bin                                               10       -     -10
usr_sbin                                              11       -     -11
install_dir                                           20       -     -20
applet_install_loc                                   184       -    -184
run_applet_and_exit                                  686      21    -665
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 0/1 up/down: 0/-890)           Total: -890 bytes
   text    data     bss     dec     hex filename
 911327     493    7336  919156   e0674 busybox_old
 909848     493    7336  917677   e00ad busybox_unstripped

but busybox executable by itself does not say anything useful:

$ busybox
busybox: applet not found

Based on the patch by Ron Yorston <rmy@pobox.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-31 02:44:34 +02:00
Denys Vlasenko
877dedb825 cp: add -u/--update and --remove-destination
Based on the patch by wdlkmpx@gmail.com

function                                             old     new   delta
copy_file                                           1546    1644     +98
add_partition                                       1270    1362     +92
ask_and_unlink                                        95     133     +38
do_iproute                                           132     157     +25
decode_one_format                                    710     715      +5
cp_main                                              369     374      +5
ubirename_main                                       198     202      +4
read_package_field                                   232     230      -2
bb_make_directory                                    421     412      -9
packed_usage                                       30505   30476     -29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/3 up/down: 267/-40)           Total: 227 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-27 00:46:38 +02:00
Denys Vlasenko
852e8dd734 arping: avoid use of ether_ntoa(). Closes 8926
This is the only non-debug use of ether_ntoa(). By not using it,
we reduce bss:

function                                             old     new   delta
arping_main                                         1568    1665     +97
static.asc                                            18       -     -18
ether_ntoa                                            57       -     -57
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/0 up/down: 97/-75)             Total: 22 bytes
   text    data     bss     dec     hex filename
 911020     493    7352  918865   e0551 busybox_old
 911069     493    7336  918898   e0572 busybox_unstripped

Also, "standard" arping zero-pads MAC. ether_ntoa() does not.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-26 21:35:46 +02:00
Denys Vlasenko
f2559e5c2b sed: fix append command to match GNU sed 4.2.1
This closes one testcase failure

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-06 18:25:56 +02:00
Denys Vlasenko
2fbc3123a2 flock: merge spawn_and_wait() code patchs for -c and sans-c uses
function                                             old     new   delta
flock_main                                           334     319     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 18:21:32 +02:00
Denys Vlasenko
e1d426fd65 flock: fix -c; improve error handling of fork+exec
function                                             old     new   delta
flock_main                                           254     334     +80

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 18:19:49 +02:00
Szabolcs Nagy
4ab372d49a ip: fix problem on mips64 n64 big endian musl systems
Use designated initializers for struct msghdr.
The struct layout is non-portable and musl libc does not match what busybox expects.

Signed-off-by: Szabolcs Nagy <nsz@port70.net>
Tested-by: Waldemar Brodkorb <wbx@openadk.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 17:39:02 +02:00
Denys Vlasenko
cbdff15bb7 sed: understand \n,\r and \t in i and a commands. Closes 8871
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 16:18:03 +02:00
Denys Vlasenko
4c8fa34417 generate_BUFSIZ.sh: yet another tweak
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 14:13:35 +02:00
Denys Vlasenko
3e134ebf6a *: slap on a few ALIGN1/2s where appropriate
The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map"

   text	   data	    bss	    dec	    hex	filename
 829901	   4086	   1904	 835891	  cc133	busybox_before
 829665	   4086	   1904	 835655	  cc047	busybox

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-22 18:09:21 +02:00
Denys Vlasenko
663d1da1e6 scripts/trylink: document DATA_SEGMENT_ALIGN() hack
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-22 02:00:04 +02:00
Denys Vlasenko
7ff24bd5fb generate_BUFSIZ.sh: catch BUFSIZE < 1024 also on "big" builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-22 00:24:53 +02:00
Denys Vlasenko
d7b502c059 build system: fix generate_BUFSIZ.sh to not alternate 1k and malloc builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 23:52:35 +02:00
Denys Vlasenko
93e1aaa1c7 libbb: constify *bb_common_bufsiz1 (if it is compiled to be a pointer)
This lets gcc optimize much better:

   text	   data	    bss	    dec	    hex	filename
 922846	    910	  13056	 936812	  e4b6c	busybox_unstripped.nonconst
 920255	    910	  13056	 934221	  e414d	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 21:47:45 +02:00
Denys Vlasenko
f56fb5eb11 libbb: make "COMMON_BUFSIZE = 1024 bytes, the buffer will be malloced" work
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 21:03:51 +02:00
Denys Vlasenko
df70a43af2 udhcp: add setup_common_bufsiz() as needed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 18:54:36 +02:00
Denys Vlasenko
9de2e5a222 *: hopefully all setup_common_bufsiz() are in place
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 18:38:51 +02:00
Denys Vlasenko
47cfbf32fd *: add most of the required setup_common_bufsiz() calls
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 18:18:48 +02:00
Denys Vlasenko
e6a2f4cc5a libbb: make bb_common_bufsiz1 1 kbyte, add capability to use bss tail for it
The config item is FEATURE_USE_BSS_TAIL. When it is off (default):

function                                             old     new   delta
read_config                                          210     228     +18
doCommands                                          2279    2294     +15
ipneigh_list_or_flush                                763     772      +9
ipaddr_list_or_flush                                1256    1261      +5
display_process_list                                1301    1306      +5
conspy_main                                         1378    1383      +5
do_lzo_compress                                      352     355      +3
do_lzo_decompress                                    565     567      +2
push                                                  46      44      -2
inetd_main                                          2136    2134      -2
uevent_main                                          421     418      -3
addLines                                              97      92      -5
bb_common_bufsiz1                                   8193    1024   -7169
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/5 up/down: 62/-7181)        Total: -7119 bytes
   text	   data	    bss	    dec	    hex	filename
 829850	   4086	   9080	 843016	  cdd08	busybox_old
 829901	   4086	   1904	 835891	  cc133	busybox_unstripped

FEATURE_USE_BSS_TAIL=y:

read_config                                          210     228     +18
doCommands                                          2279    2294     +15
ipneigh_list_or_flush                                763     772      +9
ipaddr_list_or_flush                                1256    1261      +5
display_process_list                                1301    1306      +5
conspy_main                                         1378    1383      +5
do_lzo_compress                                      352     355      +3
do_lzo_decompress                                    565     567      +2
inetd_main                                          2136    2134      -2
bb_common_bufsiz1                                   8193       -   -8193
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 8/1 up/down: 62/-8195)        Total: -8133 bytes
   text	   data	    bss	    dec	    hex	filename
 829850	   4086	   9080	 843016	  cdd08	busybox_old
 829911	   4086	    880	 834877	  cbd3d	busybox_unstripped

FIXME: setup_common_bufsiz() calls are missing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 17:39:11 +02:00
Denys Vlasenko
5598bdf0d3 unzip: shorter code for date/time generation
function                                             old     new   delta
unzip_main                                          2426    2414     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-18 02:38:32 +02:00
Denys Vlasenko
07bd979921 unzip: better match for "standard" unzip's output; string shrinkage
function                                             old     new   delta
unzip_main                                          2490    2426     -64
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-64)             Total: -64 bytes
   text    data     bss     dec     hex filename
 924008     906   17160  942074   e5ffa busybox_old
 923846     906   17160  941912   e5f58 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-18 01:43:24 +02:00
Denys Vlasenko
bca4deee83 unzip: fix percent overflow; show "stored" files properly
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-18 01:14:05 +02:00
Denys Vlasenko
0ccf52a9fb unzip: fix a case where we find wrong CDE. Closes 8821
function                                             old     new   delta
unzip_main                                          2472    2490     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-17 21:05:34 +02:00
Ron Yorston
84ba50c32f ash: bash-compatible $'...' shouldn't expand in double quotes
Bash doesn't expand its $'...' construct in double quotes:

   $ echo "$'a\tb'"
   $'a\tb'

Change BusyBox ash to do the same.  This also fixes a problem with
here documents where BusyBox ash gave an incorrect result for:

   $ cat <<EOF
   > '$'
   > EOF
   '$'

Reported-by: Timo Teras <timo.teras@iki.fi>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-15 22:16:46 +02:00
Ron Yorston
2b91958dff Rewrite iteration through applet names to save a few bytes
function                                             old     new   delta
run_applet_and_exit                                  758     755      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3)               Total: -3 bytes

In standalone shell mode the saving increases to 17 bytes.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-15 22:13:51 +02:00
Denys Vlasenko
e4d925b889 sed: support "-f -" idiom
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-08 00:20:36 +02:00
Mike Frysinger
d7d4750e1e unrpm: clean up
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-04 01:39:17 -04:00
Mike Frysinger
ee22fe8793 undeb: clean up
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-04 01:35:34 -04:00
Mike Frysinger
ea1b44412a syslogd: minor tweaks to text
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-04 01:28:32 -04:00
Bjørn Forsman
d63d77a7f0 kconfig/lxdialog: get ncurses CFLAGS with pkg-config
This makes "make menuconfig" also work on systems where ncurses is not
installed in a standard location (such as on NixOS).

This patch changes ccflags() so that it tries pkg-config first, and only
if pkg-config fails does it go back to the fallback/manual checks. This
is the same algorithm that ldflags() already uses.

Signed-off-by: Bjørn Forsman <bjorn.forsman@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Michal Marek
935fe68236 kbuild: Make scripts executable
The Makefiles call the respective interpreter explicitly, but this makes
it easier to use the scripts manually.

Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Yann E. MORIN
d35ba8b5ed kconfig/lxdialog: rationalise the include paths where to find {.n}curses{,w}.h
The current code does this:

    if [ -f /usr/include/ncursesw/curses.h ]; then
        echo '-I/usr/include/ncursesw -DCURSES_LOC="<ncursesw/curses.h>"'
    elif [ -f /usr/include/ncurses/ncurses.h ]; then
        echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
    elif [ -f /usr/include/ncurses/curses.h ]; then
        echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"'
    [...]

This is merely inconsistent:
  - adding the full path to the directory in the -I directive,
  - especially since that path is already a sub-path of the system
    include path,
  - and then repeating the sub-path in the #include directive.

Rationalise each include directive:
  - only use the filename in the #include directive,
  - keep the -I directives: they are always searched for before the
    system include path; this ensures the correct header is used.

Using the -I directives and the filename-only in #include is more in
line with how pkg-config behaves, eg.:
    $ pkg-config --cflags ncursesw
    -I/usr/include/ncursesw

This paves the way for using pkg-config for CFLAGS, too, now we use it
to find the libraries.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Justin Lecher
e62c715b3e menuconfig: optionally use pkg-config to detect ncurses libs
When building ncurses with --with-termlib several symbols get moved from
libncurses.so to libtinfo.so. Thus when linking with libncurses.so, one
additionally needs to link with libtinfo.so.

The ncurses pkg-config module will be used to detect the necessary libs for
linking. If not available the old heuristic for detection of the ncurses libs
will be used.

Signed-off-by: Justin Lecher <jlec@gentoo.org>
Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Krzysztof Mazur
f755430d79 menuconfig: fix extended colors ncurses support
The ncurses library allows for extended colors. The support for extended
colors support depends on wide-character support. ncurses headers
enable extended colors (NCURSES_EXT_COLORS) only when wide-character
support is enabled (NCURSES_WIDECHAR).

The "make menuconfig" uses wide-character ncursesw library, which can be
compiled with wide-character support, but does not define NCURSES_WIDECHAR
and it's using headers without wide-character (and extended colors) support.

This fixes problems with colors on systems with enabled extended colors
(like PLD Linux). Without this patch "make menuconfig" is hard to use.

Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Jean Delvare
8c3f943410 kbuild: Fix gcc -x syntax
The correct syntax for gcc -x is "gcc -x assembler", not
"gcc -xassembler". Even though the latter happens to work, the former
is what is documented in the manual page and thus what gcc wrappers
such as icecream do expect.

This isn't a cosmetic change. The missing space prevents icecream from
recognizing compilation tasks it can't handle, leading to silent kernel
miscompilations.

Besides me, credits go to Michael Matz and Dirk Mueller for
investigating the miscompilation issue and tracking it down to this
incorrect -x parameter syntax.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Cc: Bernhard Walle <bernhard@bwalle.de>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Yaakov Selkowitz
74f58ed48c kconfig: fix check-lxdialog for DLL platforms
Import libraries on Cygwin and MinGW/MSYS use the .dll.a suffix, so
checking this suffix is necessary to make sure ncurses will still be
found when built without static libraries.

Signed-off-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Yaakov Selkowitz
a0f24a06df kconfig: check ncursesw headers first in check-lxdialog
Commit 8c41e5e363db55d91aa3b1cdce4ab02ad9821de7 added a check for
ncursesw/curses.h for the case where ncurses and ncursesw are build
separately but only one is installed.  But if both are installed,
the headers ncurses/curses.h and ncursesw/curses.h differ, and since
libncursesw will be found first, so should ncursesw/curses.h.

Signed-off-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Junio C Hamano
f48bd92285 kconfig: fix menuconfig on debian lenny
In 60f33b8 (kconfig: get rid of stray a.o, support ncursesw, 2006-01-15),
support to link menuconfig with ncursesw library was added.  To compute
the linker command option -l, we check "libncursesw.{so,a,dylib}" to allow
ncursesw to be used as a replacement ncurses.  However, when checking what
header file to include, we do not check /usr/include/ncursesw directory.

Add /usr/include/ncursesw to the list of directories that are checked.
With this patch, on my Debian Lenny box with libncursesw5-dev package but
not libncurses5-dev package, I can say "make menuconfig".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Mike Frysinger
993dab7822 Revert "lxdialog: fix ncursesw include detection"
This reverts commit e91bc53d0c.

Let's get back to a state that matches upstream so we can pull in all of
their fixes from the last few years.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:58:50 -04:00
Ron Yorston
b22061718d find_applet_by_name: loop index should be signed
The loop

   for (j = ARRAY_SIZE(applet_nameofs)-1; j >= 0; j--) {

was intended to terminate when j goes negative, so j needs to be signed.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 22:29:35 +02:00
Denys Vlasenko
6aab9928de whitespace and namespace cleanups
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 22:24:51 +02:00
Sven Eisenberg
b068cf2a7e ubirmvol: Implement -N switch for ubirmvol
function                                             old     new   delta
get_volid_by_name                                      -     125    +125
ubi_devnum_from_devname                                -      43     +43
ubi_tools_main                                      1215    1220      +5
packed_usage                                       30674   30655     -19
ubirename_main                                       394     221    -173
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 1/2 up/down: 173/-192)          Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 22:01:43 +02:00
Sven Eisenberg
cb92640998 ubirename: new applet
function                                             old     new   delta
ubirename_main                                         -     394    +394
packed_usage                                       30611   30674     +63
applet_names                                        2530    2540     +10

Signed-off-by: Sven Eisenberg <sven.eisenberg@novero.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 20:12:03 +02:00
Denys Vlasenko
46b494635e libbb: speed up error_msg functions
function                                             old     new   delta
bb_verror_msg                                        386     466     +80

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 16:55:03 +02:00
Denys Vlasenko
bc14f4d13d main(): add a TODO about finding a use for _end[] area
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 16:06:42 +02:00
Denys Vlasenko
056e1f558c trylink: on failure, print a hint about CONFIG_EXTRA_LDLIBS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 15:38:53 +02:00
Denys Vlasenko
1cf68e3033 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 22:57:17 +02:00
Denys Vlasenko
a93e4fd376 find_applet_by_name: add an example of faster linear search code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 22:54:23 +02:00
Denys Vlasenko
8b0f459af7 nsenter,unshare: work around older header
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 19:00:44 +02:00
Denys Vlasenko
b14374a5ba sort: "-o FILE", not "-o", is the syntax
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 18:20:26 +02:00
Denys Vlasenko
8220399173 nsenter,unshare: share common code; fix a bug of not closing all fds
function                                             old     new   delta
xvfork_parent_waits_and_exits                          -      64     +64
exec_prog_or_SHELL                                     -      39     +39
unshare_main                                         873     810     -63
nsenter_main                                         663     596     -67
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 106/-130)          Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 18:06:24 +02:00
Denys Vlasenko
c87e81f944 sort: help text does not need to say that -mST are supported but ignored
Such information is useless for users of "sort --help"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 17:39:50 +02:00
Denys Vlasenko
dd02a05e08 build system: finer-grained selection of search speedup table.
KNOWN_APPNAME_OFFSETS=8 versus KNOWN_APPNAME_OFFSETS=0:

function                                             old     new   delta
find_applet_by_name                                   55     136     +81
applet_nameofs                                         -      14     +14
run_applet_and_exit                                  757     758      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 15:18:26 +02:00
Denys Vlasenko
9f2f96edfa unshare: remove stale comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 04:44:39 +02:00
Bartosz Golaszewski
80c934a251 nsenter: new applet
function                                             old     new   delta
nsenter_main                                           -     663    +663
.rodata                                           155147  155612    +465
packed_usage                                       30536   30708    +172
nsenter_longopts                                       -     116    +116
open_by_path_or_target                                 -      58     +58
applet_names                                        2518    2526      +8
applet_main                                         2920    2928      +8
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 4/0 up/down: 1490/0)           Total: 1490 bytes
   text	   data	    bss	    dec	    hex	filename
 827956	   4078	   9080	 841114	  cd59a	busybox_old
 829214	   4086	   9080	 842380	  cda8c	busybox_unstripped

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-01 22:19:35 +02:00
Denys Vlasenko
c4199f22d0 libbb: two new functions: wait_for_exitstatus(pid), xfchdir(fd)
Bartosz Golaszewski proposed xfchdir()

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-01 22:12:44 +02:00
Bartosz Golaszewski
29b33b63d4 unshare: new applet
function                                             old     new   delta
unshare_main                                           -     873    +873
.rodata                                           154444  155131    +687
packed_usage                                       30329   30520    +191
unshare_longopts                                       -     106    +106
mount_namespaces                                       -      99     +99
mount_or_die                                           -      51     +51
ns_list                                                -      48     +48
wait_for_exitstatus                                    -      41     +41
opt_str                                                -      17     +17
applet_names                                        2510    2518      +8
applet_main                                         2912    2920      +8
applet_suid                                           91      92      +1
applet_install_loc                                   182     183      +1
------------------------------------------------------------------------------
(add/remove: 8/0 grow/shrink: 6/0 up/down: 2131/0)           Total: 2131 bytes
   text	   data	    bss	    dec	    hex	filename
 826110	   4070	   9080	 839260	  cce5c	busybox_old
 827961	   4078	   9080	 841119	  cd59f	busybox_unstripped

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-01 19:44:39 +02:00
Denys Vlasenko
52977a7d60 Rename FEATURE_INITRD to LINUXRC and make it separate, not an alias to init
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-31 00:42:57 +02:00
Denys Vlasenko
a27dc33f97 make MKPASSWD a separate config option, not an automatic alias to cryptpw
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-31 00:32:39 +02:00
Denys Vlasenko
f75a96d74c udhcp: fix capitalization of two messages
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:49:45 +02:00
Denys Vlasenko
16efe19128 dhcpd: string reuse
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:44:52 +02:00
Denys Vlasenko
8f2e99c813 udhcp: get rid of bb_info_msg()
function                                             old     new   delta
udhcpd_main                                         1501    1531     +30
d6_recv_raw_packet                                   251     264     +13
perform_d6_release                                   188     198     +10
udhcpc6_main                                        2443    2449      +6
udhcp_recv_raw_packet                                582     588      +6
udhcp_recv_kernel_packet                             132     138      +6
send_d6_renew                                        140     146      +6
d6_recv_kernel_packet                                118     124      +6
send_renew                                            77      82      +5
send_discover                                         85      90      +5
send_decline                                          84      89      +5
send_d6_select                                        97     102      +5
send_d6_discover                                     174     179      +5
perform_release                                      167     172      +5
count_lines                                           72      74      +2
udhcpc_main                                         2836    2837      +1
bb_info_msg                                          125       -    -125
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 17/4 up/down: 117/-180)         Total: -63 bytes
   text	   data	    bss	    dec	    hex	filename
 924935	    906	  17160	 943001	  e6399	busybox_old
 924736	    906	  17160	 942802	  e62d2	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:41:23 +02:00
Denys Vlasenko
80f0f1d712 setfiles: switch bb_info_msg to printf
Presumably, bb_info_msg was used here for syslog logging (-l),
but there is no actual code to activate syslog logging.
Added a TODO note on that, so that selinux users would notice
and fix if needed.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:17:35 +02:00
Denys Vlasenko
2a17fbe88a sulogin: use bb_error_msg instead of bb_info_msg; better message
Historic "System Maintenance Mode" message is a tiny bit cryptic.
Let's say explicitly what we are doing: we are giving user a shell
(presumably to do some maintenance in single-user mode).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 17:36:20 +02:00
Denys Vlasenko
32c08acba3 sulogin: remove suid paranoia code, explain why it's not necessary
function                                             old     new   delta
sulogin_main                                         325     270     -55

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 17:27:32 +02:00
Denys Vlasenko
8ac6effb02 sulogin: Dorp incorrect comment about suid-ness
Sulogin is not a suid app, should fail if run by non-root.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:50:19 +02:00
Denys Vlasenko
c418f48d8d fsck: use printf for message, not bb_info_msg
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:30:24 +02:00
Denys Vlasenko
3b757f0798 mkfs_vfat: use bb_error_msg for logging, not bb_info_msg
This affects only a commented-out code section which searches for bad blocks

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:23:10 +02:00
Denys Vlasenko
cde1199e01 zcip: use bb_error_msg for logging, not bb_info_msg
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:22:13 +02:00
Denys Vlasenko
066e76befe Replace a few more bb_info_msg's by bb_error_msg or printf
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:20:28 +02:00
Denys Vlasenko
76b680c7a8 Use bb_error_msg instead of bb_info_msg in all commented-out debug printouts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:04:37 +02:00
Ron Yorston
610c4c385b applet_tables: save space by removing applet name offsets
The array applet_nameofs consumes two bytes per applet.  It encodes

   nofork/noexec flags
   suid flags
   the offset of the applet name in the applet_name string

Change the applet_table build tool to store the flags in two separate
arrays (applet_flags and applet_suid).  Replace applet_nameofs[] with a
smaller version that only stores a limited number of offsets.

This requires changes to the macros APPLET_IS_NOFORK, APPLET_IS_NOEXEC
and APPLET_SUID.

   According to Valgrind the original find_applet_by_name required
   353 cycles per call, averaged over all names.  Adjusting the number
   of known offsets allows space to be traded off against execution time:

      KNOWN_OFFSETS     cycles     bytes (wrt KNOWN_OFFSETS = 0)

           0             9057        -
           2             4604       32
           4             2407       75
           8             1342       98
          16              908      130
          32              884      194

   This patch uses KNOWN_OFFSETS = 8.

v2:
   Remove some dead code from the applet_table tool;
   Treat the applet in the middle of the table as a special case.

v3:
   Use the middle applet to adjust the start of the linear search as
   well as the last applet found.

v4:
   Use an augmented linear search in find_applet_by_name.
   Drop the special treatment of the middle name from get_applet_name:
   most of the advantage now derives from the last stored value.

v5:
   Don't store index in applet_nameofs, it can be calculated.

v6:
   Tweaks by Denys

function                                             old     new   delta
find_applet_by_name                                   25     125    +100
applet_suid                                            -      92     +92
run_applet_no_and_exit                               452     460      +8
run_applet_and_exit                                  695     697      +2
applet_name_compare                                   31       -     -31
applet_nameofs                                       734      14    -720
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 3/1 up/down: 202/-751)         Total: -549 bytes
   text       data        bss        dec        hex    filename
 925464        906      17160     943530      e65aa    busybox_old
 924915        906      17160     942981      e6385    busybox_unstripped

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 00:44:11 +02:00
Denys Vlasenko
9844d7e830 Revert "networking: properly initialize ipv6 scope id for printing it"
This reverts commit 2fb63292f7.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-29 19:27:00 +02:00
Denys Vlasenko
20dd499341 modprobe: skip non-.conf files only in subdirectories
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-29 19:23:55 +02:00
Denys Vlasenko
31c984dd69 umount: build fix for older glibc
Based on a patch by Veli-Pekka Peltola <veli-pekka.peltola@ray.fi>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-28 22:23:33 +02:00
Timo Teräs
2fb63292f7 networking: properly initialize ipv6 scope id for printing it
Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-28 22:16:48 +02:00
Denys Vlasenko
73dfdda92e grep: make errors other than "not found" result in exit code 2. Closes 8796
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-28 22:12:09 +02:00
Mike Frysinger
b9b7aa1910 ash_test: ignore generated files
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-22 18:15:24 -04:00
Mike Frysinger
787972f60b ash_test: printenv: fix missing includes
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-22 18:15:14 -04:00
Ron Yorston
3e3bfb896e ash: fix corruption of ${#var} if $var contains UTF-8 characters
As reported in bug 8506:

   $ X=abcdÉfghÍjklmnÓpqrstÚvwcyz
   $ echo ${#X}
   abcd26

The result should be 26.

This regression was introduced by:

   <d68d1fb> 2015-05-18 [Ron Yorston]  ash: code shrink around varvalue

The length in characters was being used to discard the contents of
the variable instead of the length in bytes.

URL: https://bugs.busybox.net/8506
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-22 18:19:29 -04:00
Denys Vlasenko
6701e91d84 wget: make -T timeout work on header reads too. Closes 8636
function                                             old     new   delta
set_alarm                                              -      27     +27
fgets_and_trim                                        76      92     +16
wget_main                                           2610    2616      +6
open_socket                                           64      54     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-17 21:52:42 +01:00
Denys Vlasenko
0d1b71e8e6 nmeter: reinstate and document -d-1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 17:54:17 +01:00
Denys Vlasenko
41b1e2c392 nmeter: remove undocumented %NNNd specifier
function                                             old     new   delta
nmeter_main                                          707     745     +38
init_functions                                        48      44      -4
init_delay                                            63       -     -63
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 38/-67)            Total: -29 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 16:13:23 +01:00
Denys Vlasenko
a63e2a8cb2 nmeter: simple code shrink here and there
function                                             old     new   delta
nmeter_main                                          709     707      -2
init_cr                                               15      12      -3
collect_time                                         141     131     -10
collect_cpu                                          610     593     -17
init_cpu                                              82      63     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-51)             Total: -51 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 16:06:29 +01:00
Denys Vlasenko
8a26fda98c nmeter: convert field list to bit list
function                                             old     new   delta
rdval                                                 34     157    +123
collect_int                                          123     122      -1
collect_thread_nr                                     65      62      -3
collect_blk                                          559     552      -7
collect_if                                           207     199      -8
collect_fork                                         119     111      -8
collect_ctx                                          119     111      -8
collect_fd                                            81      71     -10
collect_swp                                          120     107     -13
collect_cpu                                          623     610     -13
collect_mem                                          371     339     -32
rdval_loadavg                                         38       -     -38
vrdval                                               170       -    -170
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/10 up/down: 123/-311)        Total: -188 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 15:52:40 +01:00
Denys Vlasenko
99c71c9e80 nmeter: code shrink
function                                             old     new   delta
put                                                   52      43      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 15:28:49 +01:00
Denys Vlasenko
e4de8c6316 nmeter: fix a bug with unterminated varargs
function                                             old     new   delta
collect_mem                                          361     371     +10
collect_swp                                          116     120      +4
vrdval                                               168     170      +2
collect_thread_nr                                     63      65      +2
collect_int                                          121     123      +2
collect_if                                           205     207      +2
collect_fork                                         117     119      +2
collect_fd                                            79      81      +2
collect_ctx                                          117     119      +2
collect_cpu                                          621     623      +2
collect_blk                                          557     559      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 11/0 up/down: 32/0)              Total: 32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 15:22:42 +01:00
Denys Vlasenko
fd5a2b7b04 New example config: android_502_defconfig
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-14 22:28:53 +01:00
Denys Vlasenko
23961b2fd3 more bionic fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-14 19:34:15 +01:00
Denys Vlasenko
dbb58a3879 fixes for problems found by bionic build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-14 18:23:33 +01:00
Denys Vlasenko
1b7c17391d udhcpc: fix a warning in debug code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-11 00:26:58 +01:00
Denys Vlasenko
d474ffc682 udhcp: fix a SEGV on malformed RFC1035-encoded domain name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-10 11:47:58 +01:00
Denys Vlasenko
d2b820b540 renice: tweak help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-07 15:21:54 +01:00
Denys Vlasenko
ea351b9742 ls: fix columnar output. Closes 8731
In coreutils/ls.c, 1.19 introduced commit
2f7d9e8903, removing the variable tabstops and
hard coding the column separation to 2 characters, but was not done correctly.
The column_width assumes a gap of 1 character, so the computed number of
columns exceeds the terminal width when many small files are encountered.

A minor problem but surprisingly annoying.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-06 17:53:11 +01:00
Denys Vlasenko
7849ccb61c inotifyd: swap meaning of 'y' and 'm' events in help text. Closes 8726
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-06 17:35:16 +01:00
Denys Vlasenko
86d9f60f3a udhcpc: do not use -t NUM for counting "select" packets, use 3
Otherwise, "-t 0" usage may end up sending them forever
if server does not respond.

function                                             old     new   delta
udhcpc_main                                         2846    2836     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-04 17:00:56 +01:00
Denys Vlasenko
aee7cd82be ntpd: add experimental patch
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-04 07:36:04 +01:00
Denys Vlasenko
c8641962e4 ntpd: if peer does not reply anymore, try re-resolving its hostname
function                                             old     new   delta
ntpd_main                                           1053    1130     +77
add_peers                                            166     195     +29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-04 07:26:08 +01:00
Denys Vlasenko
f37f28199f ntpd: do not use a peer more than once (say, if two peers resolve to the same IP)
function                                             old     new   delta
add_peers                                             98     166     +68

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-04 07:06:53 +01:00
Denys Vlasenko
4c48a64747 ntpd: more informative poll lowering message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-03 22:02:30 +01:00
Denys Vlasenko
35e063e1b9 ifupdowm: fix "warning: unused variable 'iface_list'"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-03 02:19:16 +01:00
Hans Dedecker
abe8f7515a dhcpc: Use client IP address as source address for DHCP renew/rebind messages
RFC2131 paragraph 4.1 states DHCP messages broadcast by a client prior to
that client obtaining its IP address must have the source IP address
field in the header set to 0.
Request messages transmitted in renewing and rebinding state need to use
the obtained IP address as source IP address in the header; this behavior
lines up with other implementations like ISC dhcp client.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-03 02:05:53 +01:00
Christian Lindeberg
ea2b71be66 udhcpd: keep expired leases at startup
Let udhcpd retain the information about expired leases when restarting
so that the leases are reserved until they possibly become the oldest
expired lease.

This reduces the frequency of IP address changes for example when the
DHCP server and a group of clients, who do not store and request their
previously offered IP address across restarts, are collectively restarted
and the startup order of the clients are not guaranteed.

Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-01 19:23:22 +01:00
Nicolas Cavallari
e5aba88712 ifupdown: allow duplicate interface definitions
This patch allow to have multiple interface definitions, much like
Debian's ifupdown.  More specifically, it removes the check for a
duplicate definition, so the impact on binary size should be fairly
minimal.

This configuration:

iface eth0 inet static
        address 192.168.0.15
        netmask 255.255.0.0
        gateway 192.168.0.1

iface eth0 inet static
        address 10.0.0.1
        netmask 255.255.255.0

Will add two addresses to eth0 if ip is used.  If ifconfig is used,
the standards methods will likely not stack, but the administrator may
still use the manual method.  The DHCP method may work depending on the
DHCP client in use.

This is a fairly advanced feature for power users who knows what they
are doing.  There are not many other network configuration systems that
allows multiple addresses on an interface.

Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-01 18:59:08 +01:00
Denys Vlasenko
352f79acbd udhcpc: fix OPTION_6RD parsing (could overflow its malloced buffer)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-26 15:54:56 +01:00
Denys Vlasenko
5bec08cebd udhcp: trivial shrink
function                                             old     new   delta
dname_dec                                            337     332      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-26 14:56:18 +01:00
Arnout Vandecappelle (Essensium/Mind)
5fa9fefddc taskset: fix non-fancy cpuset printing on big-endian
The non-fancy version of the from_cpuset uses CPU_SETSIZE as if it
represents the number of bytes in the cpuset, while it is actually
the number of bits. This leads to out-of-bounds accesses on the
cpu_set_t in the big-endian case. Basically all uses of CPU_SETSIZE
have to be divided by 8. This is done correctly in the fancy version
of from_cpuset.

In addition, the big-endian case is completely wrong to begin with.
All standard C libraries that I know of implement cpu_set_t as an
unsigned long array, so both for big and little endian, the least
significant bits are in the beginning of the array. Therefore, the
approach taken for the little endian case is equally valid. We only
need special handling for big endian when CPU_SETSIZE is large and
we use an unsigned long long to get more bits out.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-26 14:36:24 +01:00
Denys Vlasenko
03718bb274 ntpd: print packet delay in clock update message
function                                             old     new   delta
update_local_clock                                   820     826      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-24 01:22:45 +01:00
Mike Frysinger
3a5cc98902 modprobe: only parse files that end in .conf
This matches behavior with kmod which has been the standard for a long
time at this point.

URL: https://bugs.busybox.net/8021
Reported-by: Jö <jorrit@jorrit.de>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-02-12 23:26:51 -05:00
Mike Frysinger
43e56639c6 build: add a sanitizer debug option
Building & running with ASAN is super helpful, so add a dedicated config
knob for it.  This way people don't have to guess at the right compiler
settings in order to get a good build.  We can just tell people to enable
this one option.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-02-12 22:12:47 -05:00
Denys Vlasenko
8efcc9589b networking: allow dot at the end of the domain name in dhcp response
Patch based on Balaji Punnuru <balaji.punnuru@gmail.com> work.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-11 17:44:44 +01:00
Nicolas Carrier
29eae728e9 init: make the command-line rewrite optional
When launched as PID 1 and after parsing its arguments, init wipes all
all of them except argv[0] and rewrites argv[0] to contain only "init",
so that its command-line appears solely as "init" in tools such as ps.

This patch adds the FEATURE_INIT_MODIFY_CMDLINE which, if set to n, will
make init preserve all its arguments including argv[0], be they parsed or
ignored.
The original command-line used to launch init can then be retrieved in
/proc/1/cmdline on Linux, for example.

Signed-off-by: Nicolas Carrier <nicolas.carrier@parrot.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-11 14:23:33 +01:00
Denys Vlasenko
383201e725 ntpd: shorter message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-10 07:06:31 +01:00
Denys Vlasenko
fc47fcefb6 ntpd: step when |offset| > 1 sec, not 0.125 sec
update_local_clock                                   769     820     +51
recv_and_process_peer_pkt                            838     862     +24
reset_peer_stats                                     137     133      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 75/-4)              Total: 71 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-10 06:55:07 +01:00
Felix Fietkau
f2c043acfc busybox: fix uninitialized memory when displaying IPv6 addresses
After commit 8e74adab01
("libbb: make INET[6]_rresolve use sockaddr2{host,dotted}_noport")
INET_sprint6 uses more than just sin6_addr, it also tries to display the
scope id, which is uninitialized when called from ife_print6.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-01 02:20:25 +01:00
Rafał Miłecki
c30a5b1373 dd: support iflag=skip_bytes
It allows specifying amount of bytes directly (not only amount of
blocks) is also supported by GNU's Coreutils.

function                                             old     new   delta
parse_comma_flags                                      -      93     +93
static.iflag_words                                     -      12     +12
dd_main                                             1569    1580     +11
packed_usage                                       30591   30600      +9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/0 up/down: 125/0)             Total: 125 bytes

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-01 02:17:28 +01:00
Kylie McClain
40eea690c7 Fix compiling with musl's utmp stubs
This patch fixes compiling busybox with FEATURE_UTMP and _WTMP enabled.
musl, while not really support utmp/wtmp, provides stub functions, as well
as variables such as _PATH_UTMP, so that programs using utmp or wtmp can
still compile fine.

My reasoning for this patch is that on Exherbo, I'm currently trying to get
us to be able to use the same busybox config file for both glibc and musl
systems, using utmp/wtmp on systems that support it, and using the stubs
on musl without needing two different configs.

As of latest musl git, it provides all utmp functions needed; 1.1.12 doesn't,
but I sent a patch to Rich to add the utmp{,x}name functions expected to
exist, which was merged into musl upstream.

Signed-off-by: Kylie McClain <somasissounds@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-01 01:36:05 +01:00
Ron Yorston
4a79224cfc printf: short-circuit output when argument to %b includes \c
printf wasn't correctly handling \c in an argument to the %b format
specifier.

   printf %bXX OK\\c

returned 'OK\cXX' rather than the expected 'OK'.

function                                             old     new   delta
printf_main                                          886     899     +13

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-31 22:23:05 +01:00
Denys Vlasenko
2a4bba3ce2 sed: make 's///w FILE' actually write to FILE. Closes 8251
function                                             old     new   delta
add_cmd                                             1167    1210     +43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-24 15:52:16 +01:00
Denys Vlasenko
eb5091070f patch: correctly handle "patch FILE_TO_PATCH" form. Closes 7736
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-23 05:13:15 +01:00
Denys Vlasenko
c7e47cf627 dos2unix: try to preserve ownership. closes 8311
function                                             old     new   delta
dos2unix_main                                        426     441     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-17 03:50:36 +01:00
Denys Vlasenko
ccf7f0e4d3 setsid: implement -c
function                                             old     new   delta
setsid_main                                           53      96     +43
packed_usage                                       30846   30833     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-17 01:10:53 +01:00
Mike Frysinger
6a70db85cf truncate: use O_WRONLY|O_NONBLOCK
This matches coreutils behavior.  We don't read the fd, and truncation
does not need blocking.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-01-13 13:30:20 -05:00
Ari Sundholm
e111a16404 truncate: always set mode when opening file to avoid fortify errors
Busybox crashes due to no mode being given when opening:
$ ./busybox truncate -s 1M foo
*** invalid open64 call: O_CREAT without mode ***: ./busybox terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7f66d921338f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f66d92aac9c]
/lib/x86_64-linux-gnu/libc.so.6(+0xeb6aa)[0x7f66d928b6aa]
./busybox[0x4899f9]
======= Memory map: ========
00400000-004d0000 r-xp 00000000 00:1a 137559                             /home/ari/busybox/busybox
006cf000-006d0000 r--p 000cf000 00:1a 137559                             /home/ari/busybox/busybox
006d0000-006d1000 rw-p 000d0000 00:1a 137559                             /home/ari/busybox/busybox
006d1000-006d4000 rw-p 00000000 00:00 0
014e7000-01508000 rw-p 00000000 00:00 0                                  [heap]
7f66d8f8a000-7f66d8fa0000 r-xp 00000000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d8fa0000-7f66d919f000 ---p 00016000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d919f000-7f66d91a0000 rw-p 00015000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d91a0000-7f66d935b000 r-xp 00000000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d935b000-7f66d955a000 ---p 001bb000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955a000-7f66d955e000 r--p 001ba000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955e000-7f66d9560000 rw-p 001be000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d9560000-7f66d9565000 rw-p 00000000 00:00 0
7f66d9565000-7f66d966a000 r-xp 00000000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d966a000-7f66d9869000 ---p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d9869000-7f66d986a000 r--p 00104000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986a000-7f66d986b000 rw-p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986b000-7f66d988e000 r-xp 00000000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a64000-7f66d9a67000 rw-p 00000000 00:00 0
7f66d9a8a000-7f66d9a8d000 rw-p 00000000 00:00 0
7f66d9a8d000-7f66d9a8e000 r--p 00022000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8e000-7f66d9a8f000 rw-p 00023000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8f000-7f66d9a90000 rw-p 00000000 00:00 0
7ffc47761000-7ffc47782000 rw-p 00000000 00:00 0                          [stack]
7ffc477ab000-7ffc477ad000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)
$

Fix this by simply always setting the mode, as it doesn't hurt even
when O_CREAT is not specified.

This bug is a regression introduced in fc3e40e, as xopen(), which
was originally used, would automatically set the mode.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-01-13 13:28:01 -05:00
Denys Vlasenko
bae8f98633 login: add commented-out PAM double password avoidance from BZ 4003
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-03 22:43:40 +01:00
Aaro Koskinen
76915bf738 nandwrite: implement -n (read/write without ecc)
Implement -n (read/write without ecc).

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-02 01:33:01 +01:00
Ari Sundholm
dbf5a6da6a blkdiscard: new applet
function                                             old     new   delta
blkdiscard_main                                        -     264    +264

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-02 01:18:32 +01:00
Cristian Ionescu-Idbohrn
c2a2625bcb ash: suppress a compilation warning
Reported by gcc (Debian 5.3.1-4) 5.3.1 20151219

shell/ash.c: In function 'evaltree':
shell/ash.c:8432:19: warning: logical not is only applied to the left hand side of comparison

Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-02 00:52:29 +01:00
Denys Vlasenko
911d265faf mount: support "nofail" option. Closes 8551
function                                             old     new   delta
singlemount                                         1045    1060     +15
mount_option_str                                     338     345      +7
mount_it_now                                         355     361      +6
mount_options                                        172     176      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 32/0)               Total: 32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-30 20:11:34 +01:00
Denys Vlasenko
ce4bc1ed04 iproute: support "scope". Closes 8561
function                                             old     new   delta
iproute_modify                                      1051    1120     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-30 17:32:51 +01:00
Denys Vlasenko
6c634f7968 swaponoff: fix compile-time warning
CC      util-linux/swaponoff.o
cc1: warnings being treated as errors
util-linux/swaponoff.c: In function 'swap_enable_disable':
util-linux/swaponoff.c💯 warning: passing argument 1 of 'resolve_mount_spec' from incompatible pointer type
make[1]: *** [util-linux/swaponoff.o] Error 1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-18 19:02:31 +01:00
Pascal Bach
2c0d3f5fd0 chpasswd: support -c argument and respect DEFAULT_PASSWD_ALGO
Signed-off-by: Pascal Bach <pascal.bach@siemens.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-18 19:01:14 +01:00
Ari Sundholm
b505251242 include/platform.h: Remove extra #endif introduced in 6df9612.
It causes the compilation to fail.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-17 15:54:04 -05:00
Chris Renshaw
6df961257d Resolve linker issues with Android API 21 (dprintf, tcdrain)
Signed-off-by: Chris Renshaw <osm0sis@outlook.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-17 16:42:41 +01:00
Mike Frysinger
e0942acb9e blkid: add bcache support
URL: https://bugs.gentoo.org/508596
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-16 14:42:25 -05:00
Mike Frysinger
5f11ec3f6a swapon/swapoff: refine the -e (ifexists) option
The -e option should only apply to swapon, and it should swallow all
errors/warnings when the device does not exist.  So delete the flag
from the swapoff patch and unify the check in the swapoff path.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-16 12:59:08 -05:00
Mike Frysinger
77e2bde6a5 trylink: include LDFLAGS when checking linkage
The user might be including options in their LDFLAGS (like -fuse-ld=gold)
that change the behavior of the linker and thus change the results of the
flag tests.  Make sure we include the user's LDFLAGS when running these
tests so we filter out flags that will fail when used later on.

URL: https://bugs.gentoo.org/499712
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-01 11:25:10 -05:00
Denys Vlasenko
196e400441 modutils: fix build error with !DEPMOD
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-06 15:50:28 +01:00
Timo Teräs
48dc80bbba modutils: merge module_entry and module_info to common
This merges the in-memory module info structures of modprobe
and depmod. This allows sharing hashing by modulename code
improving depmod runtime with almost factor of 2x.

function                                             old     new   delta
get_or_add_modentry                                    -      17     +17
do_modprobe                                          590     601     +11
moddb_get_or_create                                    -      10     +10
load_modules_dep                                     195     205     +10
moddb_get                                              -       7      +7
add_probe                                             81      78      -3
modprobe_main                                        721     714      -7
depmod_main                                          553     543     -10
config_file_action                                   434     421     -13
helper_get_module                                    160     144     -16
parse_module                                         343     320     -23
order_dep_list                                       105      82     -23
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/7 up/down: 55/-95)            Total: -40 bytes

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-05 18:54:55 +01:00
Denys Vlasenko
34adecc2b0 TODO file: remove mpstat, iostat, powertop - we have them now
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 19:39:54 +01:00
Ron Yorston
95ebcf79ff ash: add support for bash 'function' keyword
Where the POSIX shell allows functions to be defined as:

   name () compound-command [ redirections ]

bash adds the alternative syntax:

   function name [()] compound-command [ redirections ]

Implement this in ash's bash compatibility mode.  Most compound
commands work (for/while/until/if/case/[[]]/{}); one exception is:

   function f (echo "no way!")

The other two variants work:

   f() (echo "ok")
   function f() (echo "also ok")

function                                             old     new   delta
parse_command                                       1555    1744    +189
tokname_array                                        232     240      +8
.rodata                                           155612  155566     -46
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 197/-46)           Total: 151 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 19:30:24 +01:00
Denys Vlasenko
bc9bee01f3 hush-misc/func_args1.tests: remove "UNFIXED BUG", it does not fail
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 14:50:19 +01:00
Ron Yorston
85405c80a2 ash: copy function tests from hush testsuite
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 14:48:16 +01:00
Denys Vlasenko
2cf4591413 i2c_tools: suppress "'blen' may be used uninitialized in this function"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:58:03 +01:00
Bartosz Golaszewski
5ed6989d80 i2cdump: display the numeric value for block read ioctl() errors
This makes busybox i2cdump compatible with the upstream version, which
also displays the numeric error value in case of a block read failure.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:10 +01:00
Bartosz Golaszewski
74bb9d5e63 i2cdump: bail-out if block read fails
We should bail-out if i2c_smbus_read_block_data() or
i2c_smbus_read_i2c_block_data() return 0 or less. Add the missing check
for the former and fix the existing for the latter.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Bartosz Golaszewski
1fe75b8ef1 i2cdump: use I2C block mode for the 'i' mode parameter
Currently we're calling i2c_smbus_read_block_data() for both 'i' and 's'
mode parameters. If the bus doesn't support SMBus block mode, then the
i2c access ioctl() fails. Make i2cdump behave compatibly with upstream
version by calling i2c_smbus_read_i2c_block_data() for I2C block.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Bartosz Golaszewski
1cde5f79d4 i2cdump: don't read block data in non-block modes
We currently read data twice in byte mode. Add a check to avoid calling
i2c_smbus_read_i2c_block_data() if we're not in I2C or SMBus block mode.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Bartosz Golaszewski
fc8eb056ea i2cdetect: coding style: add a space after 'for'
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Bartosz Golaszewski
99f025a499 i2cdetect: fix address skipping in auto mode
If the bus doesn't support SMBus Quick Write or Receive Byte commands
and we're running in auto mode all addresses will be skipped resulting
in an empty table being printed.

This is caused by not restoring the auto mode after it's been changed
for certain address ranges - we need an additional variable to hold the
temporary state.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Natanael Copa
1062391365 ifupdown: use -x hostname:NAME with udhcpc
The -H NAME is deprecated in udhcpc. See commit
2017d48c0d

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-31 14:19:06 +01:00
Denys Vlasenko
6bd3fff51a [g]unzip: fix recent breakage.
Also, do emit error message we so painstakingly pass from gzip internals

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 23:41:53 +01:00
Ron Yorston
95650a86d1 ash: allow popredir to be called if the stack is empty
If /tmp/test.sh is a script that tries to run a second script which
happens to be non-executable this:

   command . /tmp/test.sh

causes a seg fault.

This is because clearredir is called in the error path to clear the
stack of redirections.  The normal path then calls popredir, but popredir
fails when the stack is empty.

Reported-by: Bastian Bittorf <bittorf@bluebottle.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 22:23:13 +01:00
Ron Yorston
8c55dc79a7 ash: fix EXEXEC status clobbering
evalcommand always clobbers the exit status in case of an EXEXEC
which means that exec always fails with exit status 2 regardless
of what it actually returns.

This patch adds the missing check for EXEXEC so that the correct
exit status is preserved.  It causes the test ash-misc/exec.tests
to succeed.

Based on commit 7f68426 in dash git, by Herbert Xu.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 22:19:48 +01:00
Ron Yorston
e939856c87 ash: add tests for failures of the exec and command builtins
The exec builtin should return an exit status of 127 if the command
can't be found.  It doesn't:  it returns 2.

If the command builtin is used to source a script that runs a second
script that doesn't exist ash should issue an error.  Instead it seg
faults.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 22:19:06 +01:00
Denys Vlasenko
ace833028f stat: make -f optional. This allows to build stat for non-linux systems
function                                             old     new   delta
packed_usage                                       30761   30706     -55

Based on the patch by Ron Yorston.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 22:10:44 +01:00
Denys Vlasenko
fe0dc34746 lineedit: FEATURE_REVERSE_SEARCH should not depend on SAVEHISTORY
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 21:39:19 +01:00
Ron Yorston
f23264b35f lineedit: search applets as well as PATH for tab completion
In standalone shell mode search the applet table as well as PATH
when tab completing a command.

Use a stupid linear search:  we're also about to read all the
directories on PATH so efficiency isn't a big concern.

function                                             old     new   delta
add_match                                              -      53     +53
complete_cmd_dir_file                                687     724     +37
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 90/0)               Total: 90 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 19:49:33 +01:00
Ron Yorston
ae57af6e78 busybox: alter help message in standalone shell mode
Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 19:00:38 +01:00
Denys Vlasenko
112889d706 hush: copy for.tests from ash testsuite
This test passes for hush

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 22:37:25 +01:00
Ron Yorston
c0e007663d ash: simplify EOF/newline handling in list parser
Processing of here documents in ash has had a couple of breakages
which are now the subject of tests.  This commit should fix both.

It is based on the following commit in dash git by Herbert Xu:

   <7c245aa> [PARSER] Simplify EOF/newline handling in list parser

(See git://git.kernel.org/pub/scm/utils/dash/dash.git)

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 21:44:11 +01:00
Ron Yorston
6bd2fabc52 Revert "ash: fix a SEGV case in an invalid heredoc" xxx
This reverts commit 7e66102f76 but
leaves the test in place as it's still valid.

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 21:42:30 +01:00
Ron Yorston
713f07d906 ash: fix error during recursive processing of here document
Save the value of the checkkwd flag to prevent it being clobbered
during recursion.

Based on commit ec2c84d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
readtoken                                            190     203     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:45:36 +01:00
Denys Vlasenko
7b14ede049 ash tests: make test print test name before it is run
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:34:20 +01:00
Ron Yorston
ef2386b80a ash: only allow local variables in functions
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:33:44 +01:00
Ron Yorston
3f221113a5 ash: respect -p flag when command builtin is run with -v/-V
The command builtin should only check the default path, not $PATH,
when the -p flag is used along with -v/-V.

Based on commits 65ae84b (by Harald van Dijk) and 29ee27d (by Herbert
Xu) from git://git.kernel.org/pub/scm/utils/dash/dash.git).

function                                             old     new   delta
commandcmd                                            72      87     +15
describe_command                                     437     450     +13
typecmd                                               84      86      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 30/0)               Total: 30 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:05:32 +01:00
Denys Vlasenko
e2f32c02b1 ash: fix command -- crash
busybox sh -c 'command --' segfaults because parse_command_args
returns a pointer to a null pointer.

Based on commit 18071c7 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Gerrit Pape.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:46:40 +01:00
Ron Yorston
383b885ff7 ash: save a few bytes in code to parse case statements
Based on commit 49b82fc from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
parse_command                                       1563    1555      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-8)               Total: -8 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:36:08 +01:00
Ron Yorston
ab80e01cd9 ash: allow newline after variable name in for loop
Newline is a valid delimiter between the variable name and `in`
keyword in for loops.

Based on commit 22e8fb4 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
parse_command                                       1568    1563      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5)               Total: -5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:30:55 +01:00
Ron Yorston
9121510dc6 ash: add test for issue with here document
This used to work but doesn't now:

foo () {
cat <<EOF && { echo "$1" ; }
$1
EOF
}

foo "bar"

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:12:03 +01:00
Denys Vlasenko
4c8576fea1 modinfo: fix "-F firmware", add "intree" field display
function                                             old     new   delta
shortcuts                                              -      52     +52
modinfo                                              317     330     +13
display                                               77      87     +10
packed_usage                                       30752   30761      +9
modinfo_main                                         351     345      -6
static.shortcuts                                      48       -     -48
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 3/1 up/down: 84/-54)             Total: 30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-28 18:07:46 +01:00
Denys Vlasenko
4840325351 lzop: eliminate variable, use "int" as return type
Based on patch by Maxin B. John <maxin.john@intel.com>

function                                             old     new   delta
pack_lzop                                            870     859     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-28 15:33:19 +01:00
Timo Teräs
82c2fad26c fbsplash: use virtual y size in mmap size calculations
The virtual y can be larger - and we can be even writing there since
we are taking into account the y offset. Avoids possible crash.
But use it only if set, seems it is not set if virtual area is not
allocated (though, often fbcon allocates some scrollback area).

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-27 21:32:00 +01:00
Aaro Koskinen
cddc98eab7 gzip: add support for --no-name long option
Add support for --no-name long option. Just silently ignore it
like the short -n option.

This allows to use busybox gzip with Lynx browser.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-27 21:30:43 +01:00
Aaro Koskinen
fbe50cf6bc gunzip: add support for long options
Add support for long options.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-27 21:28:50 +01:00
Denys Vlasenko
1de25a6e87 unzip: test for bad archive SEGVing
function                                             old     new   delta
huft_build                                          1296    1300      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-26 19:33:05 +01:00
Richard Genoud
d683c5c2f1 tr: support octal ranges
now, we can do printf "a\tb\tcdef\n" | ./busybox tr -d "\1-\14b-e"
af

and bonus, we save some bytes.

function                                             old     new   delta
expand                                               718     699     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-19)             Total: -19
bytes

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-26 17:18:07 +01:00
Timo Teräs
028524317d ifupdown: pass interface device name for ipv6 route commands
IPv6 routes need the device argument for link-local routes, or they
cannot be used at all. E.g. "gateway fe80::def" seems to be used in
some places, but kernel refuses to insert the route unless device
name is explicitly specified in the route addition.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-26 17:06:12 +01:00
Denys Vlasenko
db700330d8 tweak defconfig
MONOTONIC_SYSCALL=y by default

FEATURE_LAST_SMALL is gone: now FEATURE_LAST_FANCY is a "bool", not a "choice".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-25 20:36:03 +01:00
Denys Vlasenko
0269789537 inetd: make FEATURE_INETD_RPC off by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-25 20:10:46 +01:00
Ron Yorston
8814431aca libiproute: use if_nametoindex
Saves 87 bytes.  Assuming, of course, all platforms have it.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 22:04:36 +02:00
Aaro Koskinen
6d777b75ed xargs: make -I imply -r
Make -I imply -r (GNU findutils seems to do the same).

Fixes the following bug:

        $ echo -n | xargs -I% echo %
        Segmentation fault

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 22:01:29 +02:00
Denys Vlasenko
f98705a00c dumpleases: string reuse
text	   data	    bss	    dec	    hex	filename
 926254	    906	  17160	 944320	  e68c0	busybox_old
 926242	    906	  17160	 944308	  e68b4	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 20:45:10 +02:00
Isaac Dunham
d320a1e7a5 dumpleases: new option -d to show time in seconds
function                                             old     new   delta
dumpleases_main                                      493     534     +41
static.dumpleases_longopts                            31      41     +10
packed_usage                                       30777   30752     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 51/-25)             Total: 26 bytes

Signed-off-by: Isaac Dunham <ibid.ag@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 20:28:04 +02:00
Denys Vlasenko
334e12ac6a zcip: ...ad suppress the warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 19:15:44 +02:00
Denys Vlasenko
49d51598ac zcip: do not query current time if we won't use the result
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 19:14:04 +02:00
Denys Vlasenko
bf1866c183 tweak zcip service example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 18:57:32 +02:00
Denys Vlasenko
1a1cfedbef Tweak README
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 14:58:58 +02:00
Denys Vlasenko
4f8ecf273c update network service examples
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 14:55:33 +02:00
Denys Vlasenko
d32a1a4054 New example of a service: examples/var_service/zcip_if
Zeroconf for IPv4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 05:30:58 +02:00
Denys Vlasenko
9a51217668 dumpleases: make host names sanitized to shell-friendly condition
function                                             old     new   delta
add_lease                                            271     298     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 04:45:22 +02:00
Denys Vlasenko
941e7a4919 reuse a string
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 04:19:56 +02:00
Denys Vlasenko
cd13974b20 rmmod: fix bad error message
Before:

    ># busybox_old rmmod gtrhfhdfghdf
    rmmod: can't unload 'gtrhfhdfghdf': unknown symbol in module, or unknown parameter

    After:

    ># busybox rmmod gtrhfhdfghdf
    rmmod: can't unload module 'gtrhfhdfghdf': No such file or directory

function                                             old     new   delta
modprobe_main                                        726     721      -5
do_modprobe                                          599     590      -9
rmmod_main                                           187     169     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-32)             Total: -32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 04:17:04 +02:00
Denys Vlasenko
2e9a0662bc MODPROBE_SMALL is not experimental anymore
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 04:13:16 +02:00
Denys Vlasenko
049b007865 pmap: fix bogus {no such process} comm field text
function                                             old     new   delta
read_cmdline                                         246     266     +20
procps_get_maps                                      196     193      -3
packed_usage                                       30413   30404      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 20/-12)              Total: 8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 03:45:57 +02:00
Denys Vlasenko
00da72bee0 tidy up strtok use
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23 18:43:16 +02:00
Denys Vlasenko
59f8475924 httpd: fix heap buffer overflow. Closes 8426
function                                             old     new   delta
send_headers                                         654     677     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23 11:49:04 +02:00
Denys Vlasenko
d3d6534b2a wget: if stderr is not a tty, progress bar shouldn't use tty-tricks
function                                             old     new   delta
bb_progress_update                                   706     768     +62

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23 02:01:38 +02:00
Denys Vlasenko
641caaec3d libbb: factor out code which queries screen width
function                                             old     new   delta
get_terminal_width                                     -      17     +17
stty_main                                           1196    1197      +1
pstree_main                                          321     319      -2
ls_main                                              735     731      -4
watch_main                                           232     225      -7
bb_progress_update                                   714     706      -8
ps_main                                              555     543     -12
run_applet_and_exit                                  708     695     -13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 18/-46)            Total: -28 byte

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23 01:44:22 +02:00
Denys Vlasenko
a960748748 tar: add a test that we don't write into symlinks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 16:37:01 +02:00
Denys Vlasenko
accd9eeb71 remove systemd support
systemd people are not willing to play nice with the rest of the world.
Therefore there is no reason for the rest of the world to cooperate with them.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 16:01:57 +02:00
Denys Vlasenko
537389cedd tar: fix files skipped with --strip_components not resetting selinux context
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 13:38:09 +02:00
Denys Vlasenko
f167e4503d tar: shrink hardlink name handling code
function                                             old     new   delta
data_extract_all                                    1069    1040     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 13:30:34 +02:00
Denys Vlasenko
62ae323df0 tar: implement --version for buildroot
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 13:22:26 +02:00
Denys Vlasenko
6c563e370d tar: add support for --strip-components=N
function                                             old     new   delta
data_extract_all                                     882     995    +113
tar_longopts                                         290     309     +19
tar_main                                             938     942      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 136/0)             Total: 136 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 01:07:13 +02:00
Denys Vlasenko
c47917865d login: explain -h HOST option better
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-21 16:06:40 +02:00
Denys Vlasenko
92e1b0826d wget: make Bartosz's "wget --passive-ftp -nd -t 3" work
function                                             old     new   delta
static.wget_longopts                                 166     234     +68
wget_main                                           2608    2610      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 21:51:52 +02:00
Denys Vlasenko
edcd5dcc9b typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 18:15:01 +02:00
Denys Vlasenko
58d0e20ad0 scripts/trylink: remove $CPPFLAGS
We don't use it in final link, should not use it in check_FOO then.
This uncovered a logic bug in glibc check...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 16:40:43 +02:00
Denys Vlasenko
5134010d88 scripts/trylink: fix bit-rotted linker option verification
To that end, *make it complain* when check_cc fails on options
we usually want to succeed.

   text	   data	    bss	    dec	    hex	filename
 929697	    932	  17692	 948321	  e7861	busybox-1.23.2/busybox
 915361	    911	  17484	 933756	  e3f7c	busybox-1.23.2.fixed/busybox

 927725	    932	  17448	 946105	  e6fb9	busybox-1.24.0/busybox
 913630	    911	  17240	 931781	  e37c5	busybox-1.24.0.fixed/busybox

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 16:16:16 +02:00
Denys Vlasenko
76efb3ed33 qemu_multiarch_testing/README: add a list of qemu's needed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 12:58:37 +02:00
Denys Vlasenko
f2ccefb946 setarch: add support for '-R' (disable randomization)
This commit adds support for the -R flag of setarch, which disables
randomization of the virtual address space.

function                                             old     new   delta
setarch_main                                         115     150     +35
packed_usage                                       30664   30651     -13

Signed-off-by: Jan Heylen <heyleke@gmail.com>
Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 23:26:50 +02:00
Denys Vlasenko
0506e292b5 sort: fix ENDCHAR handling in "-kSTART,N.ENDCHAR"
function                                             old     new   delta
get_key                                              505     503      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 19:27:26 +02:00
Denys Vlasenko
d1ed3e68b8 sort: code shrink
function                                             old     new   delta
compare_keys                                         738     695     -43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 19:13:06 +02:00
Denys Vlasenko
fd19faf705 remove extra debug printout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 14:48:24 +02:00
Denys Vlasenko
2e86a5c98d sort: fix key with delimiters breakage
function                                             old     new   delta
get_key                                              509     505      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 14:44:51 +02:00
Denys Vlasenko
3d0805e9e7 libbb: make parse_chown_usergroup_or_die() set unspecified uid/gid to -1
function                                             old     new   delta
parse_chown_usergroup_or_die                         102     115     +13
chown_main                                           190     175     -15
start_stop_daemon_main                              1043    1027     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 13/-31)            Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 04:37:19 +02:00
Denys Vlasenko
526d85831e libbb: get_uidgid() always called with allow_numeric=1
function                                             old     new   delta
xget_uidgid                                           30      25      -5
make_device                                         2188    2183      -5
main                                                 797     792      -5
get_uidgid                                           240     225     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 04:27:17 +02:00
Denys Vlasenko
f3d58a29be od: get rid of (almost all) statics
function                                             old     new   delta
od_main                                             2565    2600     +35
check_and_close                                      113     115      +2
static.prev_pair_equal                                 1       -      -1
static.first                                           1       -      -1
exit_code                                              1       -      -1
string_min                                             4       -      -4
n_specs                                                4       -      -4
in_stream                                              4       -      -4
format_address                                         4       -      -4
file_list                                              4       -      -4
bytes_per_block                                        4       -      -4
get_lcm                                              120     115      -5
pseudo_offset                                          8       -      -8
------------------------------------------------------------------------------
(add/remove: 0/10 grow/shrink: 2/1 up/down: 37/-40)            Total: -3 bytes
   text	   data	    bss	    dec	    hex	filename
 938487	    932	  17392	 956811	  e998b	busybox_old
 938519	    924	  17360	 956803	  e9983	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 02:51:56 +02:00
Denys Vlasenko
c4fb8c6ad5 fsck: do not use statics
function                                             old     new   delta
fsck_main                                           1794    1812     +18
packed_usage                                       30662   30664      +2
kill_all_if_got_signal                                60      62      +2
create_fs_device                                     158     160      +2
static.kill_sent                                       1       -      -1
skip_root                                              1       -      -1
serialize                                              1       -      -1
parallel_root                                          1       -      -1
noexecute                                              1       -      -1
fs_type_negated                                        1       -      -1
force_all_parallel                                     1       -      -1
verbose                                                4       -      -4
num_running                                            4       -      -4
num_args                                               4       -      -4
max_running                                            4       -      -4
instance_list                                          4       -      -4
fstype                                                 4       -      -4
fs_type_list                                           4       -      -4
fs_type_flag                                           4       -      -4
filesys_last                                           4       -      -4
filesys_info                                           4       -      -4
args                                                   4       -      -4
wait_one                                             309     300      -9
ignore                                               196     174     -22
------------------------------------------------------------------------------
(add/remove: 0/18 grow/shrink: 4/2 up/down: 24/-82)           Total: -58 bytes
   text    data     bss     dec     hex filename
 938527     932   17448  956907   e99eb busybox_old
 938487     932   17392  956811   e998b busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 02:24:14 +02:00
Denys Vlasenko
36647abcc3 chattr,lsattr: shorten help message
function                                             old     new   delta
packed_usage                                       30662   30645     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 01:29:20 +02:00
Denys Vlasenko
95dee81a46 loginutils/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 01:20:36 +02:00
Denys Vlasenko
28826ac8c0 debianutils/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 00:52:26 +02:00
Denys Vlasenko
854bb6879d printutils/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 00:45:46 +02:00
Denys Vlasenko
0863e1a576 runit/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 00:41:28 +02:00
Denys Vlasenko
000eda41c0 e2fsprogs/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-18 22:40:23 +02:00
Denys Vlasenko
d34f300db6 sysklogd/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-18 22:40:09 +02:00
Aaro Koskinen
2735bc00e3 cpio: implement -R/--owner
Implement -R/--owner to force ownership of files.

function                                             old     new   delta
cpio_main                                            532     586     +54
get_header_cpio                                      909     939     +30
print                                                 36      65     +29
cpio_o                                               804     832     +28
cpio_TRAILER                                           -      11     +11
packed_usage                                       30667   30662      -5
static.trailer                                        11       -     -11
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 4/1 up/down: 152/-16)           Total: 136 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-16 17:24:46 +02:00
Denys Vlasenko
93dd9fd90a du: extra compat: with -k and -m, round sizes up
function                                             old     new   delta
print                                                 36      65     +29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-15 21:33:34 +02:00
Denys Vlasenko
5251135bc1 better pinger service example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-15 02:10:11 +02:00
Denys Vlasenko
4ad702c0a7 top: make sort field for 's' mode less confusing
function                                             old     new   delta
display_topmem_process_list                          542     565     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-14 22:30:47 +02:00
Denys Vlasenko
926d801fa5 libiproute: make rt_addr_n2a() and format_host() return auto strings
function                                             old     new   delta
rt_addr_n2a                                           56      53      -3
print_addrinfo                                      1227    1178     -49
print_neigh                                          933     881     -52
print_rule                                           689     617     -72
print_tunnel                                         640     560     -80
print_route                                         1727    1588    -139
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-395)           Total: -395 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-14 13:56:42 +02:00
Denys Vlasenko
0f296a3a56 libiproute: rename invarg(a,b) to invarg_1_to_2(a,b)
invarg(a,b) - "invalid argument", but how a and b enter the message?

invarg_1_to_2(a,b) is somewhat easier to read: "invalid argument 'a' to 'b'"

Audit of usage revealed a number of bad uses, with too long messages.

   text	   data	    bss	    dec	    hex	filename
 938848	    932	  17448	 957228	  e9b2c	busybox_old
 938788	    932	  17448	 957168	  e9af0	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-14 13:21:01 +02:00
Curt Brune
69934701fd networking: add 'ip neigh' command
This patch ports the 'ip neigh' command, originally written by Alexey
Kuznetsov, <kuznet@ms2.inr.ac.ru>, to busybox.

The base of the port is the version of iproute that shipped with
Debian Squeeze, taken from:

  http://http.debian.net/debian/pool/main/i/iproute/iproute_20100519.orig.tar.gz

This patch has actively been used by the Open Network Install
Environment (ONIE) project for over 3 years without incident.

function                                             old     new   delta
print_neigh                                            -     933    +933
ipneigh_list_or_flush                                  -     742    +742
get_hz                                                 -     109    +109
do_ipneigh                                             -      62     +62
do_iproute                                          2112    2153     +41
packed_usage                                       30647   30667     +20
ipneigh_main                                           -      14     +14
static.ip_neigh_commands                               -      12     +12
static.nuds                                            -       9      +9
static.ip_func_ptrs                                   32      36      +4
print_route                                         1858    1727    -131
------------------------------------------------------------------------------
(add/remove: 8/0 grow/shrink: 3/1 up/down: 1946/-131)        Total: 1815 bytes

Signed-off-by: Curt Brune <curt@cumulusnetworks.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-14 12:53:47 +02:00
Denys Vlasenko
7b85ec30b5 *: more BUILD_BUG_ON conversions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 17:17:34 +02:00
Ron Yorston
4d0c1ea478 wget: shrink code if https isn't supported
If FEATURE_WGET_OPENSSL and FEATURE_WGET_SSL_HELPER are both disabled
there's no point in checking for https URLs.

function                                             old     new   delta
P_HTTPS                                                6       -      -6
.rodata                                           155501  155469     -32
parse_url                                            476     423     -53
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-91)             Total: -91 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 14:56:22 +02:00
Denys Vlasenko
ab3964db4e libbb: introduce kernel-style BUILD_BUG_ON()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 14:50:20 +02:00
Denys Vlasenko
f7ad927c20 ftpd: make DIR parameter work for non-root too: chdir to it instead of chroot
Unfortunately, chroot() works only for root user, because of attacks
on setuid binaries (make DIR/lib/ld-linux.so a shell, hardlink to
a setuid binary, chroot to DIR, execute it and get root shell).

function                                             old     new   delta
ftpd_main                                           2160    2180     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 13:49:53 +02:00
Denys Vlasenko
bf74fb4497 typo fix in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 12:34:35 +02:00
Denys Vlasenko
6390a3a4e5 whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 01:51:37 +02:00
Denys Vlasenko
450a367a11 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 01:49:06 +02:00
Denys Vlasenko
b5dabd9078 libpwdgrp: fix comment discrepancies
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 00:31:02 +02:00
Denys Vlasenko
966423d403 Start 1.25.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 14:36:39 +02:00
1099 changed files with 36098 additions and 15179 deletions

View File

@ -146,6 +146,10 @@ Rob Sullivan <cogito.ergo.cogito@gmail.com>
Linus Torvalds
mkswap, fsck.minix, mkfs.minix
Linus Walleij
fbset and fbsplash config RGBA parsing
rewrite of mdev helper to create devices from /sys/dev
Mark Whitley <markw@codepoet.org>
grep, sed, cut, xargs(previous),
style-guide, new-applet-HOWTO, bug fixes, etc.
@ -174,3 +178,6 @@ Mike Frysinger <vapier@gentoo.org>
Jie Zhang <jie.zhang@analog.com>
fixed two bugs in msh and hush (exitcode of killed processes)
Maxime Coste <mawww@kakoune.org>
paste implementation

399
Config.in
View File

@ -11,15 +11,18 @@ config HAVE_DOT_CONFIG
menu "Busybox Settings"
menu "General Configuration"
config DESKTOP
bool "Enable options for full-blown desktop systems"
default y
help
Enable options and features which are not essential.
Select this only if you plan to use busybox on full-blown
desktop machine with common Linux distro, not on an embedded box.
Select this if you plan to use busybox on full-blown desktop machine
with common Linux distro, which needs higher level of command-line
compatibility.
If you are preparing your build to be used on an embedded box
where you have tighter control over the entire set of userspace
tools, you can unselect this option for smaller code size.
config EXTRA_COMPAT
bool "Provide compatible behavior for rare corner cases (bigger code)"
@ -47,41 +50,6 @@ config USE_PORTABLE_CODE
compiler other than gcc.
If you do use gcc, this option may needlessly increase code size.
config PLATFORM_LINUX
bool "Enable Linux-specific applets and features"
default y
help
For the most part, busybox requires only POSIX compatibility
from the target system, but some applets and features use
Linux-specific interfaces.
Answering 'N' here will disable such applets and hide the
corresponding configuration options.
choice
prompt "Buffer allocation policy"
default FEATURE_BUFFERS_USE_MALLOC
help
There are 3 ways BusyBox can handle buffer allocations:
- Use malloc. This costs code size for the call to xmalloc.
- Put them on stack. For some very small machines with limited stack
space, this can be deadly. For most folks, this works just fine.
- Put them in BSS. This works beautifully for computers with a real
MMU (and OS support), but wastes runtime RAM for uCLinux. This
behavior was the only one available for BusyBox versions 0.48 and
earlier.
config FEATURE_BUFFERS_USE_MALLOC
bool "Allocate with Malloc"
config FEATURE_BUFFERS_GO_ON_STACK
bool "Allocate on the Stack"
config FEATURE_BUFFERS_GO_IN_BSS
bool "Allocate in the .bss section"
endchoice
config SHOW_USAGE
bool "Show applet usage messages"
default y
@ -116,9 +84,21 @@ config FEATURE_COMPRESS_USAGE
and have very little memory, this might not be a win. Otherwise,
you probably want this.
config BUSYBOX
bool "Include busybox applet"
default y
help
The busybox applet provides general help regarding busybox and
allows the included applets to be listed. It's also required
if applet links are to be installed at runtime.
If you can live without these features disabling this will save
some space.
config FEATURE_INSTALLER
bool "Support --install [-s] to install applet links at runtime"
default y
depends on BUSYBOX
help
Enable 'busybox --install [-s]' support. This will allow you to use
busybox at runtime to create hard links or symlinks for all the
@ -132,153 +112,15 @@ config INSTALL_NO_USR
will install applets only to /bin and /sbin,
never to /usr/bin or /usr/sbin.
config LOCALE_SUPPORT
bool "Enable locale support (system needs locale for this to work)"
default n
help
Enable this if your system has locale support and you would like
busybox to support locale settings.
config UNICODE_SUPPORT
bool "Support Unicode"
default y
help
This makes various applets aware that one byte is not
one character on screen.
Busybox aims to eventually work correctly with Unicode displays.
Any older encodings are not guaranteed to work.
Probably by the time when busybox will be fully Unicode-clean,
other encodings will be mainly of historic interest.
config UNICODE_USING_LOCALE
bool "Use libc routines for Unicode (else uses internal ones)"
default n
depends on UNICODE_SUPPORT && LOCALE_SUPPORT
help
With this option on, Unicode support is implemented using libc
routines. Otherwise, internal implementation is used.
Internal implementation is smaller.
config FEATURE_CHECK_UNICODE_IN_ENV
bool "Check $LC_ALL, $LC_CTYPE and $LANG environment variables"
default n
depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE
help
With this option on, Unicode support is activated
only if locale-related variables have the value of the form
"xxxx.utf8"
Otherwise, Unicode support will be always enabled and active.
config SUBST_WCHAR
int "Character code to substitute unprintable characters with"
depends on UNICODE_SUPPORT
default 63
help
Typical values are 63 for '?' (works with any output device),
30 for ASCII substitute control code,
65533 (0xfffd) for Unicode replacement character.
config LAST_SUPPORTED_WCHAR
int "Range of supported Unicode characters"
depends on UNICODE_SUPPORT
default 767
help
Any character with Unicode value bigger than this is assumed
to be non-printable on output device. Many applets replace
such chars with substitution character.
The idea is that many valid printable Unicode chars are
nevertheless are not displayed correctly. Think about
combining charachers, double-wide hieroglyphs, obscure
characters in dozens of ancient scripts...
Many terminals, terminal emulators, xterms etc will fail
to handle them correctly. Choose the smallest value
which suits your needs.
Typical values are:
126 - ASCII only
767 (0x2ff) - there are no combining chars in [0..767] range
(the range includes Latin 1, Latin Ext. A and B),
code is ~700 bytes smaller for this case.
4351 (0x10ff) - there are no double-wide chars in [0..4351] range,
code is ~300 bytes smaller for this case.
12799 (0x31ff) - nearly all non-ideographic characters are
available in [0..12799] range, including
East Asian scripts like katakana, hiragana, hangul,
bopomofo...
0 - off, any valid printable Unicode character will be printed.
config UNICODE_COMBINING_WCHARS
bool "Allow zero-width Unicode characters on output"
default n
depends on UNICODE_SUPPORT
help
With this option off, any Unicode char with width of 0
is substituted on output.
config UNICODE_WIDE_WCHARS
bool "Allow wide Unicode characters on output"
default n
depends on UNICODE_SUPPORT
help
With this option off, any Unicode char with width > 1
is substituted on output.
config UNICODE_BIDI_SUPPORT
bool "Bidirectional character-aware line input"
default n
depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE
help
With this option on, right-to-left Unicode characters
are treated differently on input (e.g. cursor movement).
config UNICODE_NEUTRAL_TABLE
bool "In bidi input, support non-ASCII neutral chars too"
default n
depends on UNICODE_BIDI_SUPPORT
help
In most cases it's enough to treat only ASCII non-letters
(i.e. punctuation, numbers and space) as characters
with neutral directionality.
With this option on, more extensive (and bigger) table
of neutral chars will be used.
config UNICODE_PRESERVE_BROKEN
bool "Make it possible to enter sequences of chars which are not Unicode"
default n
depends on UNICODE_SUPPORT
help
With this option on, on line-editing input (such as used by shells)
invalid UTF-8 bytes are not substituted with the selected
substitution character.
For example, this means that entering 'l', 's', ' ', 0xff, [Enter]
at shell prompt will list file named 0xff (single char name
with char value 255), not file named '?'.
config PAM
bool "Support for PAM (Pluggable Authentication Modules)"
bool "Support PAM (Pluggable Authentication Modules)"
default n
help
Use PAM in some busybox applets (currently login and httpd) instead
of direct access to password database.
config FEATURE_USE_SENDFILE
bool "Use sendfile system call"
default y
select PLATFORM_LINUX
help
When enabled, busybox will use the kernel sendfile() function
instead of read/write loops to copy data between file descriptors
(for example, cp command does this a lot).
If sendfile() doesn't work, copying code falls back to read/write
loop. sendfile() was originally implemented for faster I/O
from files to sockets, but since Linux 2.6.33 it was extended
to work for many more file types.
config LONG_OPTS
bool "Support for --long-options"
bool "Support --long-options"
default y
help
Enable this if you want busybox applets to use the gnu --long-option
@ -345,7 +187,7 @@ config PID_FILE_PATH
specify a pidfile path.
config FEATURE_SUID
bool "Support for SUID/SGID handling"
bool "Support SUID/SGID handling"
default y
help
With this option you can install the busybox binary belonging
@ -485,9 +327,18 @@ config FEATURE_HAVE_RPC
# This is automatically selected if any of enabled applets need it.
# You do not need to select it manually.
endmenu
config PLATFORM_LINUX
bool #No description makes it a hidden option
default n
#help
# For the most part, busybox requires only POSIX compatibility
# from the target system, but some applets and features use
# Linux-specific interfaces.
#
# This is automatically selected if any applet or feature requires
# Linux-specific interfaces. You do not need to select it manually.
menu 'Build Options'
comment 'Build Options'
config STATIC
bool "Build BusyBox as a static binary (no shared libs)"
@ -662,93 +513,7 @@ config EXTRA_LDLIBS
help
Additional LDLIBS to pass to the linker with -l.
endmenu
menu 'Debugging Options'
config DEBUG
bool "Build BusyBox with extra Debugging symbols"
default n
help
Say Y here if you wish to examine BusyBox internals while applets are
running. This increases the size of the binary considerably, and
should only be used when doing development. If you are doing
development and want to debug BusyBox, answer Y.
Most people should answer N.
config DEBUG_PESSIMIZE
bool "Disable compiler optimizations"
default n
depends on DEBUG
help
The compiler's optimization of source code can eliminate and reorder
code, resulting in an executable that's hard to understand when
stepping through it with a debugger. This switches it off, resulting
in a much bigger executable that more closely matches the source
code.
config UNIT_TEST
bool "Build unit tests"
default n
help
Say Y here if you want to build unit tests (both the framework and
test cases) as a Busybox applet. This results in bigger code, so you
probably don't want this option in production builds.
config WERROR
bool "Abort compilation on any warning"
default n
help
Selecting this will add -Werror to gcc command line.
Most people should answer N.
choice
prompt "Additional debugging library"
default NO_DEBUG_LIB
help
Using an additional debugging library will make BusyBox become
considerable larger and will cause it to run more slowly. You
should always leave this option disabled for production use.
dmalloc support:
----------------
This enables compiling with dmalloc ( http://dmalloc.com/ )
which is an excellent public domain mem leak and malloc problem
detector. To enable dmalloc, before running busybox you will
want to properly set your environment, for example:
export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile
The 'debug=' value is generated using the following command
dmalloc -p log-stats -p log-non-free -p log-bad-space \
-p log-elapsed-time -p check-fence -p check-heap \
-p check-lists -p check-blank -p check-funcs -p realloc-copy \
-p allow-free-null
Electric-fence support:
-----------------------
This enables compiling with Electric-fence support. Electric
fence is another very useful malloc debugging library which uses
your computer's virtual memory hardware to detect illegal memory
accesses. This support will make BusyBox be considerable larger
and run slower, so you should leave this option disabled unless
you are hunting a hard to find memory problem.
config NO_DEBUG_LIB
bool "None"
config DMALLOC
bool "Dmalloc"
config EFENCE
bool "Electric-fence"
endchoice
endmenu
menu 'Installation Options ("make install" behavior)'
comment 'Installation Options ("make install" behavior)'
choice
prompt "What kind of applet links to install"
@ -814,12 +579,104 @@ config PREFIX
help
Define your directory to install BusyBox files/subdirs in.
comment 'Debugging Options'
config DEBUG
bool "Build BusyBox with extra Debugging symbols"
default n
help
Say Y here if you wish to examine BusyBox internals while applets are
running. This increases the size of the binary considerably, and
should only be used when doing development. If you are doing
development and want to debug BusyBox, answer Y.
Most people should answer N.
config DEBUG_PESSIMIZE
bool "Disable compiler optimizations"
default n
depends on DEBUG
help
The compiler's optimization of source code can eliminate and reorder
code, resulting in an executable that's hard to understand when
stepping through it with a debugger. This switches it off, resulting
in a much bigger executable that more closely matches the source
code.
config DEBUG_SANITIZE
bool "Enable runtime sanitizers (ASAN/LSAN/USAN/etc...)"
default n
help
Say Y here if you want to enable runtime sanitizers. These help
catch bad memory accesses (e.g. buffer overflows), but will make
the executable larger and slow down runtime a bit.
This adds -fsanitize=foo options to gcc command line.
If you aren't developing/testing busybox, say N here.
config UNIT_TEST
bool "Build unit tests"
default n
help
Say Y here if you want to build unit tests (both the framework and
test cases) as a Busybox applet. This results in bigger code, so you
probably don't want this option in production builds.
config WERROR
bool "Abort compilation on any warning"
default n
help
This adds -Werror to gcc command line.
Most people should answer N.
choice
prompt "Additional debugging library"
default NO_DEBUG_LIB
help
Using an additional debugging library will make BusyBox become
considerable larger and will cause it to run more slowly. You
should always leave this option disabled for production use.
dmalloc support:
----------------
This enables compiling with dmalloc ( http://dmalloc.com/ )
which is an excellent public domain mem leak and malloc problem
detector. To enable dmalloc, before running busybox you will
want to properly set your environment, for example:
export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile
The 'debug=' value is generated using the following command
dmalloc -p log-stats -p log-non-free -p log-bad-space \
-p log-elapsed-time -p check-fence -p check-heap \
-p check-lists -p check-blank -p check-funcs -p realloc-copy \
-p allow-free-null
Electric-fence support:
-----------------------
This enables compiling with Electric-fence support. Electric
fence is another very useful malloc debugging library which uses
your computer's virtual memory hardware to detect illegal memory
accesses. This support will make BusyBox be considerable larger
and run slower, so you should leave this option disabled unless
you are hunting a hard to find memory problem.
config NO_DEBUG_LIB
bool "None"
config DMALLOC
bool "Dmalloc"
config EFENCE
bool "Electric-fence"
endchoice
endmenu
source libbb/Config.in
endmenu
comment "Applets"
source archival/Config.in

View File

@ -1,5 +1,5 @@
VERSION = 1
PATCHLEVEL = 24
PATCHLEVEL = 27
SUBLEVEL = 0
EXTRAVERSION =
NAME = Unnamed
@ -610,7 +610,8 @@ quiet_cmd_busybox__ ?= LINK $@
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
"$(core-y)" \
"$(libs-y)" \
"$(LDLIBS)"
"$(LDLIBS)" \
&& $(srctree)/scripts/generate_BUFSIZ.sh --post include/common_bufsiz.h
# Generate System.map
quiet_cmd_sysmap = SYSMAP
@ -844,12 +845,15 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
# Split autoconf.h into include/linux/config/*
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h
quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h
cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
#bbox# piggybacked generation of few .h files
include/config/MARKER: scripts/basic/split-include include/autoconf.h
$(call cmd,split_autoconf)
$(call cmd,gen_bbconfigopts)
$(call cmd,gen_common_bufsiz)
@touch $@
# Generate some files
@ -965,6 +969,7 @@ CLEAN_FILES += busybox busybox_unstripped* busybox.links \
MRPROPER_DIRS += include/config include2
MRPROPER_FILES += .config .config.old include/asm .version .old_version \
include/NUM_APPLETS.h \
include/common_bufsiz.h \
include/autoconf.h \
include/bbconfigopts.h \
include/bbconfigopts_bz2.h \

View File

@ -75,6 +75,11 @@ else
CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
endif
endif
ifeq ($(CONFIG_DEBUG_SANITIZE),y)
CFLAGS += $(call cc-option,-fsanitize=address,)
CFLAGS += $(call cc-option,-fsanitize=leak,)
CFLAGS += $(call cc-option,-fsanitize=undefined,)
endif
# If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
ARCH_FPIC ?= -fpic

2
TODO
View File

@ -258,5 +258,3 @@ vdprintf() -> similar sized functionality
* more support for advanced linux 2.6.x features, see: iotop
most likely there is more
* even more support for statistics: mpstat, iostat, powertop....

View File

@ -29,7 +29,7 @@ applets/applets.o: include/usage_compressed.h include/applet_tables.h
applets/applet_tables: .config include/applets.h
applets/usage: .config include/applets.h
applets/usage_pod: .config include/applet_tables.h include/applets.h
applets/usage_pod: .config include/applets.h include/applet_tables.h
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets
@ -37,11 +37,21 @@ quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
include/usage_compressed.h: applets/usage $(srctree_slash)applets/usage_compressed
$(call cmd,gen_usage_compressed)
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h include/NUM_APPLETS.h
cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h include/NUM_APPLETS.h
include/applet_tables.h: applets/applet_tables
$(call cmd,gen_applet_tables)
include/NUM_APPLETS.h: applets/applet_tables
$(call cmd,gen_applet_tables)
# In fact, include/applet_tables.h depends only on applets/applet_tables,
# and is generated by it. But specifying only it can run
# applets/applet_tables twice, possibly in parallel.
# We say that it also needs NUM_APPLETS.h
#
# Unfortunately, we need to list the same command,
# and it can be executed twice (sequentially).
# The alternative is to not list any command,
# and then if include/applet_tables.h is deleted, it won't be rebuilt.
#
include/applet_tables.h: include/NUM_APPLETS.h applets/applet_tables
$(call cmd,gen_applet_tables)

View File

@ -41,8 +41,6 @@ struct bb_applet {
enum { NUM_APPLETS = ARRAY_SIZE(applets) };
static int offset[NUM_APPLETS];
static int cmp_name(const void *a, const void *b)
{
const struct bb_applet *aa = a;
@ -62,24 +60,30 @@ static int str_isalnum_(const char *s)
int main(int argc, char **argv)
{
int i;
int ofs;
// unsigned MAX_APPLET_NAME_LEN = 1;
int i, j;
// In find_applet_by_name(), before linear search, narrow it down
// by looking at N "equidistant" names. With ~350 applets:
// KNOWN_APPNAME_OFFSETS cycles
// 0 9057
// 2 4604 + ~100 bytes of code
// 4 2407 + 4 bytes
// 8 1342 + 8 bytes
// 16 908 + 16 bytes
// 32 884 + 32 bytes
// With 8, int16_t applet_nameofs[] table has 7 elements.
int KNOWN_APPNAME_OFFSETS = 8;
// With 128 applets we do two linear searches, with 1..7 strcmp's in the first one
// and 1..16 strcmp's in the second. With 256 apps, second search does 1..32 strcmp's.
if (NUM_APPLETS < 128)
KNOWN_APPNAME_OFFSETS = 4;
if (NUM_APPLETS < 32)
KNOWN_APPNAME_OFFSETS = 0;
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
ofs = 0;
for (i = 0; i < NUM_APPLETS; i++) {
offset[i] = ofs;
ofs += strlen(applets[i].name) + 1;
}
/* We reuse 4 high-order bits of offset array for other purposes,
* so if they are indeed needed, refuse to proceed */
if (ofs > 0xfff)
return 1;
if (!argv[1])
return 1;
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (i < 0)
return 1;
@ -94,7 +98,27 @@ int main(int argc, char **argv)
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main);
}
printf("\n");
printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS);
if (KNOWN_APPNAME_OFFSETS > 0) {
int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS];
for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++)
index[i] = i * NUM_APPLETS / KNOWN_APPNAME_OFFSETS;
ofs = 0;
for (i = 0; i < NUM_APPLETS; i++) {
for (j = 0; j < KNOWN_APPNAME_OFFSETS; j++)
if (i == index[j])
offset[j] = ofs;
ofs += strlen(applets[i].name) + 1;
}
/* If the list of names is too long refuse to proceed */
if (ofs > 0xffff)
return 1;
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
for (i = 1; i < KNOWN_APPNAME_OFFSETS; i++)
printf("%d,\n", offset[i]);
printf("};\n\n");
}
//printf("#ifndef SKIP_definitions\n");
printf("const char applet_names[] ALIGN1 = \"\"\n");
@ -119,20 +143,41 @@ int main(int argc, char **argv)
printf("};\n");
printf("#endif\n\n");
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("0x%04x,\n",
offset[i]
#if ENABLE_FEATURE_PREFER_APPLETS
+ (applets[i].nofork << 12)
+ (applets[i].noexec << 13)
#endif
#if ENABLE_FEATURE_SUID
+ (applets[i].need_suid << 14) /* 2 bits */
#endif
);
#if ENABLE_FEATURE_PREFER_APPLETS \
|| ENABLE_FEATURE_SH_STANDALONE \
|| ENABLE_FEATURE_SH_NOFORK
printf("const uint8_t applet_flags[] ALIGN1 = {\n");
i = 0;
while (i < NUM_APPLETS) {
int v = applets[i].nofork + (applets[i].noexec << 1);
if (++i < NUM_APPLETS)
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 2;
if (++i < NUM_APPLETS)
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 4;
if (++i < NUM_APPLETS)
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 6;
printf("0x%02x,\n", v);
i++;
}
printf("};\n\n");
#endif
#if ENABLE_FEATURE_SUID
printf("const uint8_t applet_suid[] ALIGN1 = {\n");
i = 0;
while (i < NUM_APPLETS) {
int v = applets[i].need_suid; /* 2 bits */
if (++i < NUM_APPLETS)
v |= applets[i].need_suid << 2;
if (++i < NUM_APPLETS)
v |= applets[i].need_suid << 4;
if (++i < NUM_APPLETS)
v |= applets[i].need_suid << 6;
printf("0x%02x,\n", v);
i++;
}
printf("};\n\n");
#endif
#if ENABLE_FEATURE_INSTALLER
printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
@ -147,27 +192,28 @@ int main(int argc, char **argv)
printf("};\n");
#endif
//printf("#endif /* SKIP_definitions */\n");
// printf("\n");
// printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
if (argv[2]) {
char line_old[80];
char line_new[80];
FILE *fp;
char line_new[80];
// char line_old[80];
line_old[0] = 0;
fp = fopen(argv[2], "r");
if (fp) {
fgets(line_old, sizeof(line_old), fp);
fclose(fp);
}
sprintf(line_new, "#define NUM_APPLETS %u\n", NUM_APPLETS);
if (strcmp(line_old, line_new) != 0) {
// line_old[0] = 0;
// fp = fopen(argv[2], "r");
// if (fp) {
// fgets(line_old, sizeof(line_old), fp);
// fclose(fp);
// }
// if (strcmp(line_old, line_new) != 0) {
fp = fopen(argv[2], "w");
if (!fp)
return 1;
fputs(line_new, fp);
}
// }
}
return 0;

View File

@ -36,6 +36,9 @@ echo ''
#0000040 114 105 135 040 133 055 141 040 101 103 124 111 117 116 106 111
# 042514 020135 026533 020141 041501 044524 047117 044506
echo "#define UNPACKED_USAGE_LENGTH `$loc/usage | wc -c`"
echo
echo '#define PACKED_USAGE \'
## Breaks on big-endian systems!
## # Extra effort to avoid using "od -t x1": -t is not available

View File

@ -90,6 +90,8 @@ int main(void)
printf("%s\n\n", usage_array[i].aname);
}
}
printf("=back\n\n");
return 0;
}

View File

@ -8,32 +8,22 @@ menu "Archival Utilities"
config FEATURE_SEAMLESS_XZ
bool "Make tar, rpm, modprobe etc understand .xz data"
default y
help
Make tar, rpm, modprobe etc understand .xz data.
config FEATURE_SEAMLESS_LZMA
bool "Make tar, rpm, modprobe etc understand .lzma data"
default y
help
Make tar, rpm, modprobe etc understand .lzma data.
config FEATURE_SEAMLESS_BZ2
bool "Make tar, rpm, modprobe etc understand .bz2 data"
default y
help
Make tar, rpm, modprobe etc understand .bz2 data.
config FEATURE_SEAMLESS_GZ
bool "Make tar, rpm, modprobe etc understand .gz data"
default y
help
Make tar, rpm, modprobe etc understand .gz data.
config FEATURE_SEAMLESS_Z
bool "tar, rpm, modprobe etc understand .Z data"
default n
help
Make tar, rpm, modprobe etc understand .Z data.
bool "Make tar, rpm, modprobe etc understand .Z data"
default n # it is ancient
INSERT

View File

@ -4,7 +4,7 @@
#
# Licensed under GPLv2, see file LICENSE in this source tree.
libs-y += libarchive/
libs-y += libarchive/
lib-y:=

View File

@ -22,26 +22,16 @@
//config: default n # needs to be improved to be able to replace binutils ar
//config: help
//config: ar is an archival utility program used to create, modify, and
//config: extract contents from archives. An archive is a single file holding
//config: a collection of other files in a structure that makes it possible to
//config: retrieve the original individual files (called archive members).
//config: The original files' contents, mode (permissions), timestamp, owner,
//config: and group are preserved in the archive, and can be restored on
//config: extraction.
//config: extract contents from archives. In practice, it is used exclusively
//config: for object module archives used by compilers.
//config:
//config: The stored filename is limited to 15 characters. (for more information
//config: see long filename support).
//config: ar has 60 bytes of overheads for every stored file.
//config:
//config: This implementation of ar can extract archives, it cannot create or
//config: modify them.
//config: On an x86 system, the ar applet adds about 1K.
//config:
//config: Unless you have a specific application which requires ar, you should
//config: probably say N here.
//config: probably say N here: most compilers come with their own ar utility.
//config:
//config:config FEATURE_AR_LONG_FILENAMES
//config: bool "Support for long filenames (not needed for debs)"
//config: bool "Support long filenames (not needed for debs)"
//config: default y
//config: depends on AR
//config: help

View File

@ -9,17 +9,24 @@
/* lzop_main() uses bbunpack(), need this: */
//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o
/* bzip2_main() too: */
//kbuild:lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += bbunzip.o
/* gzip_main() too: */
//kbuild:lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += bbunzip.o
/* Note: must be kept in sync with archival/lzop.c */
enum {
OPT_STDOUT = 1 << 0,
OPT_FORCE = 1 << 1,
/* only some decompressors: */
OPT_VERBOSE = 1 << 2,
OPT_QUIET = 1 << 3,
OPT_DECOMPRESS = 1 << 4,
OPT_TEST = 1 << 5,
SEAMLESS_MAGIC = (1 << 31) * SEAMLESS_COMPRESSION,
OPT_KEEP = 1 << 2,
OPT_VERBOSE = 1 << 3,
OPT_QUIET = 1 << 4,
OPT_DECOMPRESS = 1 << 5,
OPT_TEST = 1 << 6,
SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION,
};
static
@ -121,7 +128,7 @@ int FAST_FUNC bbunpack(char **argv,
if (!(option_mask32 & SEAMLESS_MAGIC)) {
init_transformer_state(&xstate);
xstate.check_signature = 1;
/*xstate.signature_skipped = 0; - already is */
/*xstate.src_fd = STDIN_FILENO; - already is */
xstate.dst_fd = STDOUT_FILENO;
status = unpacker(&xstate);
@ -176,8 +183,11 @@ int FAST_FUNC bbunpack(char **argv,
}
/* Delete _source_ file */
del = filename;
if (option_mask32 & OPT_KEEP) /* ... unless -k */
del = NULL;
}
xunlink(del);
if (del)
xunlink(del);
free_name:
if (new_name != filename)
free(new_name);
@ -190,7 +200,10 @@ int FAST_FUNC bbunpack(char **argv,
return exitcode;
}
#if ENABLE_UNCOMPRESS || ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNXZ
#if ENABLE_UNCOMPRESS \
|| ENABLE_FEATURE_BZIP2_DECOMPRESS \
|| ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \
|| ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
static
char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
{
@ -220,7 +233,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
//config:config UNCOMPRESS
//config: bool "uncompress"
//config: default n
//config: default n # ancient
//config: help
//config: uncompress is used to decompress archives created by compress.
//config: Not much used anymore, replaced by gzip/gunzip.
@ -231,7 +244,16 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uncompress_main(int argc UNUSED_PARAM, char **argv)
{
// (N)compress 4.2.4.4:
// -d If given, decompression is done instead
// -c Write output on stdout, don't remove original
// -b Parameter limits the max number of bits/code
// -f Forces output file to be generated
// -v Write compression statistics
// -V Output vesion and compile options
// -r Recursive. If a filename is a directory, descend into it and compress everything
getopt32(argv, "cf");
argv += optind;
return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
@ -264,11 +286,12 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
* Ken Turkowski, Dave Mack and Peter Jannesen.
*/
//usage:#define gunzip_trivial_usage
//usage: "[-cft] [FILE]..."
//usage: "[-cfkt] [FILE]..."
//usage:#define gunzip_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage: "\n -t Test file integrity"
//usage:
//usage:#define gunzip_example_usage
@ -286,16 +309,28 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
//config:config GUNZIP
//config: bool "gunzip"
//config: default y
//config: select FEATURE_GZIP_DECOMPRESS
//config: help
//config: gunzip is used to decompress archives created by gzip.
//config: You can use the `-t' option to test the integrity of
//config: an archive, without decompressing it.
//config:
//config:config ZCAT
//config: bool "zcat"
//config: default y
//config: select FEATURE_GZIP_DECOMPRESS
//config: help
//config: Alias to "gunzip -c".
//config:
//config:config FEATURE_GUNZIP_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on (GUNZIP || ZCAT) && LONG_OPTS
//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
//applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
#if ENABLE_GUNZIP
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_ZCAT(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
#if ENABLE_FEATURE_GZIP_DECOMPRESS
static
char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
{
@ -321,6 +356,17 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
}
return filename;
}
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
static const char gunzip_longopts[] ALIGN1 =
"stdout\0" No_argument "c"
"to-stdout\0" No_argument "c"
"force\0" No_argument "f"
"test\0" No_argument "t"
"no-name\0" No_argument "n"
;
#endif
/*
* Linux kernel build uses gzip -d -n. We accept and ignore it.
* Man page says:
@ -337,19 +383,22 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int gunzip_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, "cfvqdtn");
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
applet_long_options = gunzip_longopts;
#endif
getopt32(argv, "cfkvqdtn");
argv += optind;
/* If called as zcat...
* Normally, "zcat" is just "gunzip -c".
* But if seamless magic is enabled, then we are much more clever.
*/
if (applet_name[1] == 'c')
if (ENABLE_ZCAT && applet_name[1] == 'c')
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
}
#endif
#endif /* FEATURE_GZIP_DECOMPRESS */
/*
@ -359,11 +408,12 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//usage:#define bunzip2_trivial_usage
//usage: "[-cf] [FILE]..."
//usage: "[-cfk] [FILE]..."
//usage:#define bunzip2_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:#define bzcat_trivial_usage
//usage: "[FILE]..."
//usage:#define bzcat_full_usage "\n\n"
@ -372,6 +422,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//config:config BUNZIP2
//config: bool "bunzip2"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
//config: bunzip2 is a compression utility using the Burrows-Wheeler block
//config: sorting text compression algorithm, and Huffman coding. Compression
@ -381,18 +432,24 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//config:
//config: Unless you have a specific application which requires bunzip2, you
//config: should probably say N here.
//config:
//config:config BZCAT
//config: bool "bzcat"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
//config: Alias to "bunzip2 -c".
//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
#if ENABLE_BUNZIP2
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
#if ENABLE_FEATURE_BZIP2_DECOMPRESS
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, "cfvqdt");
getopt32(argv, "cfkvqdt");
argv += optind;
if (applet_name[2] == 'c') /* bzcat */
if (ENABLE_BZCAT && applet_name[2] == 'c') /* bzcat */
option_mask32 |= OPT_STDOUT;
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
@ -409,44 +466,26 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//usage:#define unlzma_trivial_usage
//usage: "[-cf] [FILE]..."
//usage: "[-cfk] [FILE]..."
//usage:#define unlzma_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define lzma_trivial_usage
//usage: "-d [-cf] [FILE]..."
//usage: "-d [-cfk] [FILE]..."
//usage:#define lzma_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define lzcat_trivial_usage
//usage: "[FILE]..."
//usage:#define lzcat_full_usage "\n\n"
//usage: "Decompress to stdout"
//usage:
//usage:#define unxz_trivial_usage
//usage: "[-cf] [FILE]..."
//usage:#define unxz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage:
//usage:#define xz_trivial_usage
//usage: "-d [-cf] [FILE]..."
//usage:#define xz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage:
//usage:#define xzcat_trivial_usage
//usage: "[FILE]..."
//usage:#define xzcat_full_usage "\n\n"
//usage: "Decompress to stdout"
//config:config UNLZMA
//config: bool "unlzma"
@ -460,38 +499,52 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//config: The BusyBox unlzma applet is limited to decompression only.
//config: On an x86 system, this applet adds about 4K.
//config:
//config:config FEATURE_LZMA_FAST
//config: bool "Optimize unlzma for speed"
//config: default n
//config: depends on UNLZMA
//config:config LZCAT
//config: bool "lzcat"
//config: default y
//config: help
//config: This option reduces decompression time by about 25% at the cost of
//config: a 1K bigger binary.
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
//config: compression algorithm, and range coding. Compression
//config: is generally considerably better than that achieved by the bzip2
//config: compressors.
//config:
//config: The BusyBox unlzma applet is limited to decompression only.
//config: On an x86 system, this applet adds about 4K.
//config:
//config:config LZMA
//config: bool "Provide lzma alias which supports only unpacking"
//config: bool "lzma -d"
//config: default y
//config: depends on UNLZMA
//config: help
//config: Enable this option if you want commands like "lzma -d" to work.
//config: IOW: you'll get lzma applet, but it will always require -d option.
//config:
//config:config FEATURE_LZMA_FAST
//config: bool "Optimize for speed"
//config: default n
//config: depends on UNLZMA || LZCAT || LZMA
//config: help
//config: This option reduces decompression time by about 25% at the cost of
//config: a 1K bigger binary.
//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
//applet:IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat))
//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_LZCAT(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat))
//applet:IF_LZMA( APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
#if ENABLE_UNLZMA
//kbuild:lib-$(CONFIG_LZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_LZMA) += bbunzip.o
#if ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlzma_main(int argc UNUSED_PARAM, char **argv)
{
IF_LZMA(int opts =) getopt32(argv, "cfvqdt");
IF_LZMA(int opts =) getopt32(argv, "cfkvqdt");
# if ENABLE_LZMA
/* lzma without -d or -t? */
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
bb_show_usage();
# endif
/* lzcat? */
if (applet_name[2] == 'c')
if (ENABLE_LZCAT && applet_name[2] == 'c')
option_mask32 |= OPT_STDOUT;
argv += optind;
@ -500,36 +553,66 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
#endif
//usage:#define unxz_trivial_usage
//usage: "[-cfk] [FILE]..."
//usage:#define unxz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define xz_trivial_usage
//usage: "-d [-cfk] [FILE]..."
//usage:#define xz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define xzcat_trivial_usage
//usage: "[FILE]..."
//usage:#define xzcat_full_usage "\n\n"
//usage: "Decompress to stdout"
//config:config UNXZ
//config: bool "unxz"
//config: default y
//config: help
//config: unxz is a unlzma successor.
//config:
//config:config XZ
//config: bool "Provide xz alias which supports only unpacking"
//config:config XZCAT
//config: bool "xzcat"
//config: default y
//config: help
//config: Alias to "unxz -c".
//config:
//config:config XZ
//config: bool "xz -d"
//config: default y
//config: depends on UNXZ
//config: help
//config: Enable this option if you want commands like "xz -d" to work.
//config: IOW: you'll get xz applet, but it will always require -d option.
//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
//applet:IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat))
//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_XZCAT(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat))
//applet:IF_XZ( APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
#if ENABLE_UNXZ
//kbuild:lib-$(CONFIG_XZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_XZ) += bbunzip.o
#if ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unxz_main(int argc UNUSED_PARAM, char **argv)
{
IF_XZ(int opts =) getopt32(argv, "cfvqdt");
IF_XZ(int opts =) getopt32(argv, "cfkvqdt");
# if ENABLE_XZ
/* xz without -d or -t? */
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
bb_show_usage();
# endif
/* xzcat? */
if (applet_name[2] == 'c')
if (ENABLE_XZCAT && applet_name[2] == 'c')
option_mask32 |= OPT_STDOUT;
argv += optind;

View File

@ -19,6 +19,15 @@
//config:
//config: Unless you have a specific application which requires bzip2, you
//config: should probably say N here.
//config:
//config:config FEATURE_BZIP2_DECOMPRESS
//config: bool "Enable decompression"
//config: default y
//config: depends on BZIP2 || BUNZIP2 || BZCAT
//config: help
//config: Enable -d (--decompress) and -t (--test) options for bzip2.
//config: This will be automatically selected if bunzip2 or bzcat is
//config: enabled.
//applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
@ -28,9 +37,13 @@
//usage:#define bzip2_full_usage "\n\n"
//usage: "Compress FILEs (or stdin) with bzip2 algorithm\n"
//usage: "\n -1..9 Compression level"
//usage: IF_FEATURE_BZIP2_DECOMPRESS(
//usage: "\n -d Decompress"
//usage: "\n -t Test file integrity"
//usage: )
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
#include "libbb.h"
#include "bb_archive.h"
@ -184,13 +197,13 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
opt_complementary = "s2"; /* -s means -2 (compatibility) */
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfv" IF_BUNZIP2("dt") "123456789qzs");
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
if (opt & 0x18) // -d and/or -t
opt = getopt32(argv, "cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs");
#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
if (opt & 0x30) // -d and/or -t
return bunzip2_main(argc, argv);
opt >>= 5;
opt >>= 6;
#else
opt >>= 3;
opt >>= 4;
#endif
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
opt |= 0x100; /* if nothing else, assume -9 */
@ -201,6 +214,6 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
}
argv += optind;
option_mask32 &= 0x7; /* ignore all except -cfv */
option_mask32 &= 0xf; /* ignore all except -cfkv */
return bbunpack(argv, compressStream, append_ext, "bz2");
}

View File

@ -11,6 +11,7 @@
* Only supports new ASCII and CRC formats
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
//config:config CPIO
@ -22,13 +23,13 @@
//config: cpio has 110 bytes of overheads for every stored file.
//config:
//config: This implementation of cpio can extract cpio archives created in the
//config: "newc" or "crc" format, it cannot create or modify them.
//config: "newc" or "crc" format.
//config:
//config: Unless you have a specific application which requires cpio, you
//config: should probably say N here.
//config:
//config:config FEATURE_CPIO_O
//config: bool "Support for archive creation"
//config: bool "Support archive creation"
//config: default y
//config: depends on CPIO
//config: help
@ -36,7 +37,7 @@
//config: format only.
//config:
//config:config FEATURE_CPIO_P
//config: bool "Support for passthrough mode"
//config: bool "Support passthrough mode"
//config: default y
//config: depends on FEATURE_CPIO_O
//config: help
@ -46,14 +47,14 @@
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
//usage:#define cpio_trivial_usage
//usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
//usage: "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]")
//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
//usage: " [EXTR_FILE]..."
//usage:#define cpio_full_usage "\n\n"
//usage: "Extract or list files from a cpio archive"
//usage: "Extract (-i) or list (-t) files from a cpio archive"
//usage: IF_FEATURE_CPIO_O(", or"
//usage: "\ncreate an archive" IF_FEATURE_CPIO_P(" (-o) or copy files (-p)")
//usage: " using file list on stdin"
//usage: "\ntake file list from stdin and create an archive (-o)"
//usage: IF_FEATURE_CPIO_P(" or copy files (-p)")
//usage: )
//usage: "\n"
//usage: "\nMain operation mode:"
@ -71,6 +72,7 @@
//usage: "\n -v Verbose"
//usage: "\n -u Overwrite"
//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
//usage: "\n -R USER[:GRP] Set owner of created files"
//usage: IF_FEATURE_CPIO_O(
//usage: "\n -H newc Archive format"
//usage: )
@ -130,7 +132,7 @@
-I FILE File to use instead of standard input
-L, --dereference Dereference symbolic links (copy the files
that they point to instead of copying the links)
-R, --owner=[USER][:.][GROUP] Set owner of created files
-R, --owner=[USER][:.][GRP] Set owner of created files
Options valid in --extract and --pass-through modes:
-d, --make-directories Create leading directories where needed
@ -150,7 +152,8 @@ enum {
OPT_PRESERVE_MTIME = (1 << 6),
OPT_DEREF = (1 << 7),
OPT_FILE = (1 << 8),
OPTBIT_FILE = 8,
OPT_OWNER = (1 << 9),
OPTBIT_OWNER = 9,
IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
@ -163,7 +166,18 @@ enum {
OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
};
#define OPTION_STR "it0uvdmLF:"
#define OPTION_STR "it0uvdmLF:R:"
struct globals {
struct bb_uidgid_t owner_ugid;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
void BUG_cpio_globals_too_big(void);
#define INIT_G() do { \
setup_common_bufsiz(); \
G.owner_ugid.uid = -1L; \
G.owner_ugid.gid = -1L; \
} while (0)
#if ENABLE_FEATURE_CPIO_O
static off_t cpio_pad4(off_t size)
@ -181,7 +195,6 @@ static off_t cpio_pad4(off_t size)
* It's ok to exit instead of return. */
static NOINLINE int cpio_o(void)
{
static const char trailer[] ALIGN1 = "TRAILER!!!";
struct name_s {
struct name_s *next;
char name[1];
@ -223,6 +236,11 @@ static NOINLINE int cpio_o(void)
bb_simple_perror_msg_and_die(name);
}
if (G.owner_ugid.uid != (uid_t)-1L)
st.st_uid = G.owner_ugid.uid;
if (G.owner_ugid.gid != (gid_t)-1L)
st.st_gid = G.owner_ugid.gid;
if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
st.st_size = 0; /* paranoia */
@ -275,7 +293,7 @@ static NOINLINE int cpio_o(void)
} else {
/* If no (more) hardlinks to output,
* output "trailer" entry */
name = trailer;
name = cpio_TRAILER;
/* st.st_size == 0 is a must, but for uniformity
* in the output, we zero out everything */
memset(&st, 0, sizeof(st));
@ -323,7 +341,7 @@ static NOINLINE int cpio_o(void)
}
if (!line) {
if (name != trailer)
if (name != cpio_TRAILER)
goto next_link;
/* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
return EXIT_SUCCESS;
@ -339,6 +357,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
{
archive_handle_t *archive_handle;
char *cpio_filename;
char *cpio_owner;
IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
unsigned opt;
@ -353,12 +372,14 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
"pass-through\0" No_argument "p"
#endif
#endif
"owner\0" Required_argument "R"
"verbose\0" No_argument "v"
"quiet\0" No_argument "\xff"
"to-stdout\0" No_argument "\xfe"
;
#endif
INIT_G();
archive_handle = init_handle();
/* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
@ -369,14 +390,21 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
/* -L makes sense only with -o or -p */
#if !ENABLE_FEATURE_CPIO_O
opt = getopt32(argv, OPTION_STR, &cpio_filename);
opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner);
#else
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"),
&cpio_filename, &cpio_owner, &cpio_fmt);
#endif
argv += optind;
if (opt & OPT_OWNER) { /* -R */
parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner);
archive_handle->cpio__owner = G.owner_ugid;
}
#if !ENABLE_FEATURE_CPIO_O
if (opt & OPT_FILE) { /* -F */
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
}
#else
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
argv += optind;
if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
}

View File

@ -18,7 +18,7 @@
* known difference between busybox dpkg and the official dpkg that i don't
* consider important, its worth keeping a note of differences anyway, just to
* make it easier to maintain.
* - the first value for the confflile: field isnt placed on a new line.
* - the first value for the confflile: field isn't placed on a new line.
* - when installing a package the status: field is placed at the end of the
* section, rather than just after the package: field.
*
@ -28,7 +28,7 @@
//config:config DPKG
//config: bool "dpkg"
//config: default n
//config: default y
//config: select FEATURE_SEAMLESS_GZ
//config: help
//config: dpkg is a medium-level tool to install, build, remove and manage
@ -110,7 +110,7 @@ typedef struct common_node_s {
edge_t **edge;
} common_node_t;
/* Currently it doesnt store packages that have state-status of not-installed
/* Currently it doesn't store packages that have state-status of not-installed
* So it only really has to be the size of the maximum number of packages
* likely to be installed at any one time, so there is a bit of leeway here */
#define STATUS_HASH_PRIME 8191
@ -205,7 +205,7 @@ static int search_name_hashtable(const char *key)
return probe_address;
}
/* this DOESNT add the key to the hashtable
/* this DOESN'T add the key to the hashtable
* TODO make it consistent with search_name_hashtable
*/
static unsigned search_status_hashtable(const char *key)
@ -467,7 +467,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
version = strchr(field2, '(');
if (version == NULL) {
edge->operator = VER_ANY;
/* Get the versions hash number, adding it if the number isnt already in there */
/* Get the versions hash number, adding it if the number isn't already in there */
edge->version = search_name_hashtable("ANY");
} else {
/* Skip leading ' ' or '(' */
@ -496,7 +496,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
/* Truncate version at trailing ' ' or ')' */
version[strcspn(version, " )")] = '\0';
/* Get the versions hash number, adding it if the number isnt already in there */
/* Get the versions hash number, adding it if the number isn't already in there */
edge->version = search_name_hashtable(version);
}
@ -562,7 +562,7 @@ static int read_package_field(const char *package_buffer, char **field_name, cha
offset_name_end = offset;
offset_value_start = next_offset;
}
/* TODO: Name might still have trailing spaces if ':' isnt
/* TODO: Name might still have trailing spaces if ':' isn't
* immediately after name */
break;
case '\n':
@ -776,7 +776,7 @@ static void index_status_file(const char *filename)
const unsigned package_num = fill_package_struct(control_buffer);
if (package_num != -1) {
status_node = xmalloc(sizeof(status_node_t));
/* fill_package_struct doesnt handle the status field */
/* fill_package_struct doesn't handle the status field */
status_line = strstr(control_buffer, "Status:");
if (status_line != NULL) {
status_line += 7;
@ -850,7 +850,7 @@ static void write_status_file(deb_file_t **deb_file)
if (status_hashtable[status_num] != NULL) {
const char *status_from_hashtable = name_hashtable[status_hashtable[status_num]->status];
if (strcmp(status_from_file, status_from_hashtable) != 0) {
/* New status isnt exactly the same as old status */
/* New status isn't exactly the same as old status */
const int state_status = get_status(status_num, 3);
if ((strcmp("installed", name_hashtable[state_status]) == 0)
|| (strcmp("unpacked", name_hashtable[state_status]) == 0)
@ -919,7 +919,7 @@ static void write_status_file(deb_file_t **deb_file)
}
}
}
/* If the package from the status file wasnt handle above, do it now*/
/* If the package from the status file wasn't handle above, do it now*/
if (!write_flag) {
fprintf(new_status_file, "%s\n\n", control_buffer);
}
@ -946,7 +946,7 @@ static void write_status_file(deb_file_t **deb_file)
if (errno != ENOENT)
bb_error_msg_and_die("can't create backup status file");
/* Its ok if renaming the status file fails because status
* file doesnt exist, maybe we are starting from scratch */
* file doesn't exist, maybe we are starting from scratch */
bb_error_msg("no status file found, creating new one");
}
@ -1061,7 +1061,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
}
/* Check dependendcies */
/* Check dependentcies */
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
int status_num = 0;
int number_of_alternatives = 0;
@ -1244,7 +1244,7 @@ static void run_package_script_or_die(const char *package_name, const char *scri
script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
/* If the file doesnt exist is isnt fatal */
/* If the file doesn't exist it isn't fatal */
result = access(script_path, F_OK) ? EXIT_SUCCESS : system(script_path);
free(script_path);
if (result)
@ -1839,7 +1839,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
) {
status_node = xmalloc(sizeof(status_node_t));
status_node->package = deb_file[deb_count]->package;
/* reinstreq isnt changed to "ok" until the package control info
/* reinstreq isn't changed to "ok" until the package control info
* is written to the status file*/
status_node->status = search_name_hashtable("install reinstreq not-installed");
status_hashtable[status_num] = status_node;

View File

@ -7,7 +7,7 @@
//config:config DPKG_DEB
//config: bool "dpkg_deb"
//config: default n
//config: default y
//config: select FEATURE_SEAMLESS_GZ
//config: help
//config: dpkg-deb unpacks and provides information about Debian archives.
@ -16,29 +16,20 @@
//config:
//config: Unless you have a specific application which requires dpkg-deb,
//config: say N here.
//config:
//config:config FEATURE_DPKG_DEB_EXTRACT_ONLY
//config: bool "Extract only (-x)"
//config: default n
//config: depends on DPKG_DEB
//config: help
//config: This reduces dpkg-deb to the equivalent of
//config: "ar -p <deb> data.tar.gz | tar -zx". However it saves space as none
//config: of the extra dpkg-deb, ar or tar options are needed, they are linked
//config: to internally.
//applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb))
//kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
//usage:#define dpkg_deb_trivial_usage
//usage: "[-cefxX] FILE [argument]"
//usage: "[-cefxX] FILE [DIR]"
//usage:#define dpkg_deb_full_usage "\n\n"
//usage: "Perform actions on Debian packages (.debs)\n"
//usage: "\n -c List contents of filesystem tree"
//usage: "\n -e Extract control files to [argument] directory"
//usage: "\n -f Display control field name starting with [argument]"
//usage: "\n -x Extract packages filesystem tree to directory"
//usage: "\n -X Verbose extract"
//usage: "Perform actions on Debian packages (.deb)\n"
//usage: "\n -c List files"
//usage: "\n -f Print control fields"
//usage: "\n -e Extract control files to DIR (default: ./DEBIAN)"
//usage: "\n -x Extract files to DIR (no default)"
//usage: "\n -X Verbose -x"
//usage:
//usage:#define dpkg_deb_example_usage
//usage: "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n"
@ -49,18 +40,17 @@
#define DPKG_DEB_OPT_CONTENTS 1
#define DPKG_DEB_OPT_CONTROL 2
#define DPKG_DEB_OPT_FIELD 4
#define DPKG_DEB_OPT_EXTRACT 8
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 8
#define DPKG_DEB_OPT_EXTRACT 16
int dpkg_deb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dpkg_deb_main(int argc, char **argv)
int dpkg_deb_main(int argc UNUSED_PARAM, char **argv)
{
archive_handle_t *ar_archive;
archive_handle_t *tar_archive;
llist_t *control_tar_llist = NULL;
unsigned opt;
const char *extract_dir;
int need_args;
/* Setup the tar archive handle */
tar_archive = init_handle();
@ -89,53 +79,45 @@ int dpkg_deb_main(int argc, char **argv)
llist_add_to(&control_tar_llist, (char*)"control.tar.xz");
#endif
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
/* Must have 1 or 2 args */
opt_complementary = "-1:?2:c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
opt = getopt32(argv, "cefXx");
argv += optind;
argc -= optind;
//argc -= optind;
if (opt & DPKG_DEB_OPT_CONTENTS) {
extract_dir = argv[1];
if (opt & DPKG_DEB_OPT_CONTENTS) { // -c
tar_archive->action_header = header_verbose_list;
if (extract_dir)
bb_show_usage();
}
extract_dir = NULL;
need_args = 1;
if (opt & DPKG_DEB_OPT_CONTROL) {
ar_archive->accept = control_tar_llist;
tar_archive->action_data = data_extract_all;
if (1 == argc) {
extract_dir = "./DEBIAN";
} else {
need_args++;
}
}
if (opt & DPKG_DEB_OPT_FIELD) {
/* Print the entire control file
* it should accept a second argument which specifies a
* specific field to print */
if (opt & DPKG_DEB_OPT_FIELD) { // -f
/* Print the entire control file */
//TODO: standard tool accepts an optional list of fields to print
ar_archive->accept = control_tar_llist;
llist_add_to(&(tar_archive->accept), (char*)"./control");
tar_archive->filter = filter_accept_list;
tar_archive->action_data = data_extract_to_stdout;
if (extract_dir)
bb_show_usage();
}
if (opt & DPKG_DEB_OPT_EXTRACT) {
tar_archive->action_header = header_list;
}
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
if (opt & DPKG_DEB_OPT_CONTROL) { // -e
ar_archive->accept = control_tar_llist;
tar_archive->action_data = data_extract_all;
need_args = 2;
if (!extract_dir)
extract_dir = "./DEBIAN";
}
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { // -Xx
if (opt & DPKG_DEB_OPT_EXTRACT_VERBOSE)
tar_archive->action_header = header_list;
tar_archive->action_data = data_extract_all;
if (!extract_dir)
bb_show_usage();
}
if (need_args != argc) {
bb_show_usage();
}
/* Standard tool supports "-" */
tar_archive->src_fd = ar_archive->src_fd = xopen_stdin(argv[0]);
tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
/* Work out where to extract the files */
/* 2nd argument is a dir name */
if (argv[1]) {
extract_dir = argv[1];
}
if (extract_dir) {
mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
xchdir(extract_dir);

View File

@ -48,11 +48,9 @@ aa: 85.1% -- replaced with aa.gz
//config: bool "Enable long options"
//config: default y
//config: depends on GZIP && LONG_OPTS
//config: help
//config: Enable use of long options, increases size by about 106 Bytes
//config:
//config:config GZIP_FAST
//config: int "Trade memory for gzip speed (0:small,slow - 2:fast,big)"
//config: int "Trade memory for speed (0:small,slow - 2:fast,big)"
//config: default 0
//config: range 0 2
//config: depends on GZIP
@ -72,20 +70,33 @@ aa: 85.1% -- replaced with aa.gz
//config: is 6. If levels 1-3 are specified, 4 is used.
//config: If this option is not selected, -N options are ignored and -9
//config: is used.
//config:
//config:config FEATURE_GZIP_DECOMPRESS
//config: bool "Enable decompression"
//config: default y
//config: depends on GZIP || GUNZIP || ZCAT
//config: help
//config: Enable -d (--decompress) and -t (--test) options for gzip.
//config: This will be automatically selected if gunzip or zcat is
//config: enabled.
//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_GZIP) += gzip.o
//usage:#define gzip_trivial_usage
//usage: "[-cfd" IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
//usage: "[-cfk" IF_FEATURE_GZIP_DECOMPRESS("dt") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
//usage:#define gzip_full_usage "\n\n"
//usage: "Compress FILEs (or stdin)\n"
//usage: IF_FEATURE_GZIP_LEVELS(
//usage: "\n -1..9 Compression level"
//usage: )
//usage: IF_FEATURE_GZIP_DECOMPRESS(
//usage: "\n -d Decompress"
//usage: "\n -t Test file integrity"
//usage: )
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define gzip_example_usage
//usage: "$ ls -la /tmp/busybox*\n"
@ -265,7 +276,7 @@ enum {
* input file length plus MIN_LOOKAHEAD.
*/
#ifndef ENABLE_FEATURE_GZIP_LEVELS
#if !ENABLE_FEATURE_GZIP_LEVELS
max_chain_length = 4096,
/* To speed up deflation, hash chains are never searched beyond this length.
@ -304,7 +315,7 @@ enum {
struct globals {
#ifdef ENABLE_FEATURE_GZIP_LEVELS
#if ENABLE_FEATURE_GZIP_LEVELS
unsigned max_chain_length;
unsigned max_lazy_match;
unsigned good_match;
@ -2152,7 +2163,7 @@ static const char gzip_longopts[] ALIGN1 =
"to-stdout\0" No_argument "c"
"force\0" No_argument "f"
"verbose\0" No_argument "v"
#if ENABLE_GUNZIP
#if ENABLE_FEATURE_GZIP_DECOMPRESS
"decompress\0" No_argument "d"
"uncompress\0" No_argument "d"
"test\0" No_argument "t"
@ -2160,6 +2171,7 @@ static const char gzip_longopts[] ALIGN1 =
"quiet\0" No_argument "q"
"fast\0" No_argument "1"
"best\0" No_argument "9"
"no-name\0" No_argument "n"
;
#endif
@ -2178,14 +2190,14 @@ static const char gzip_longopts[] ALIGN1 =
*/
int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#if ENABLE_GUNZIP
#if ENABLE_FEATURE_GZIP_DECOMPRESS
int gzip_main(int argc, char **argv)
#else
int gzip_main(int argc UNUSED_PARAM, char **argv)
#endif
{
unsigned opt;
#ifdef ENABLE_FEATURE_GZIP_LEVELS
#if ENABLE_FEATURE_GZIP_LEVELS
static const struct {
uint8_t good;
uint8_t chain_shift;
@ -2208,25 +2220,22 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
applet_long_options = gzip_longopts;
#endif
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789");
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
if (opt & 0x18) // -d and/or -t
opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789");
#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
if (opt & 0x30) // -d and/or -t
return gunzip_main(argc, argv);
#endif
#ifdef ENABLE_FEATURE_GZIP_LEVELS
opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */
#if ENABLE_FEATURE_GZIP_LEVELS
opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 8 : 6; /* drop cfkv[dt]qn bits */
if (opt == 0)
opt = 1 << 6; /* default: 6 */
/* Map 1..3 to 4 */
if (opt & 0x7)
opt |= 1 << 4;
opt = ffs(opt >> 3);
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
max_chain_length = 1 << gzip_level_config[opt].chain_shift;
good_match = gzip_level_config[opt].good;
max_lazy_match = gzip_level_config[opt].lazy2 * 2;
nice_match = gzip_level_config[opt].nice2 * 2;
#endif
option_mask32 &= 0x7; /* retain only -cfv */
option_mask32 &= 0xf; /* retain only -cfkv */
/* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, G1.l_buf, INBUFSIZ);

View File

@ -4,7 +4,7 @@
#
# Licensed under GPLv2 or later, see file LICENSE in this source tree.
lib-y:=
lib-y:= common.o
COMMON_FILES:= \
\
@ -48,16 +48,26 @@ lib-$(CONFIG_CPIO) += get_header_cpio.o
lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
lib-$(CONFIG_UNLZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
lib-$(CONFIG_LZOPCAT) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
lib-$(CONFIG_BUNZIP2) += open_transformer.o decompress_bunzip2.o
# 'bzip2 -d', bunzip2 or bzcat selects FEATURE_BZIP2_DECOMPRESS
lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += open_transformer.o decompress_bunzip2.o
lib-$(CONFIG_FEATURE_UNZIP_BZIP2) += open_transformer.o decompress_bunzip2.o
lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o
lib-$(CONFIG_LZCAT) += open_transformer.o decompress_unlzma.o
lib-$(CONFIG_LZMA) += open_transformer.o decompress_unlzma.o
lib-$(CONFIG_FEATURE_UNZIP_LZMA) += open_transformer.o decompress_unlzma.o
lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
lib-$(CONFIG_XZCAT) += open_transformer.o decompress_unxz.o
lib-$(CONFIG_XZ) += open_transformer.o decompress_unxz.o
lib-$(CONFIG_FEATURE_UNZIP_XZ) += open_transformer.o decompress_unxz.o
# 'gzip -d', gunzip or zcat selects FEATURE_GZIP_DECOMPRESS
lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += open_transformer.o decompress_gunzip.o
lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o
lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
lib-$(CONFIG_GZIP) += open_transformer.o
lib-$(CONFIG_BZIP2) += open_transformer.o
lib-$(CONFIG_LZOP) += open_transformer.o

View File

@ -0,0 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
const char cpio_TRAILER[] ALIGN1 = "TRAILER!!!";

View File

@ -11,6 +11,12 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
file_header_t *file_header = archive_handle->file_header;
int dst_fd;
int res;
char *hard_link;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
char *dst_name;
#else
# define dst_name (file_header->name)
#endif
#if ENABLE_FEATURE_TAR_SELINUX
char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
@ -23,11 +29,49 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
#endif
/* Hard links are encoded as regular files of size 0
* with a nonempty link field */
hard_link = NULL;
if (S_ISREG(file_header->mode) && file_header->size == 0)
hard_link = file_header->link_target;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
dst_name = file_header->name;
if (archive_handle->tar__strip_components) {
unsigned n = archive_handle->tar__strip_components;
do {
dst_name = strchr(dst_name, '/');
if (!dst_name || dst_name[1] == '\0') {
data_skip(archive_handle);
goto ret;
}
dst_name++;
/*
* Link target is shortened only for hardlinks:
* softlinks restored unchanged.
*/
if (hard_link) {
// GNU tar 1.26 does not check that we reached end of link name:
// if "dir/hardlink" is hardlinked to "file",
// tar xvf a.tar --strip-components=1 says:
// tar: hardlink: Cannot hard link to '': No such file or directory
// and continues processing. We silently skip such entries.
hard_link = strchr(hard_link, '/');
if (!hard_link || hard_link[1] == '\0') {
data_skip(archive_handle);
goto ret;
}
hard_link++;
}
} while (--n != 0);
}
#endif
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
char *slash = strrchr(file_header->name, '/');
char *slash = strrchr(dst_name, '/');
if (slash) {
*slash = '\0';
bb_make_directory(file_header->name, -1, FILEUTILS_RECUR);
bb_make_directory(dst_name, -1, FILEUTILS_RECUR);
*slash = '/';
}
}
@ -35,12 +79,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) {
/* Remove the entry if it exists */
if (!S_ISDIR(file_header->mode)) {
/* Is it hardlink?
* We encode hard links as regular files of size 0 with a symlink */
if (S_ISREG(file_header->mode)
&& file_header->link_target
&& file_header->size == 0
) {
if (hard_link) {
/* Ugly special case:
* tar cf t.tar hardlink1 hardlink2 hardlink1
* results in this tarball structure:
@ -48,22 +87,22 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
* hardlink2 -> hardlink1
* hardlink1 -> hardlink1 <== !!!
*/
if (strcmp(file_header->link_target, file_header->name) == 0)
if (strcmp(hard_link, dst_name) == 0)
goto ret;
}
/* Proceed with deleting */
if (unlink(file_header->name) == -1
if (unlink(dst_name) == -1
&& errno != ENOENT
) {
bb_perror_msg_and_die("can't remove old file %s",
file_header->name);
dst_name);
}
}
}
else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
/* Remove the existing entry if its older than the extracted entry */
struct stat existing_sb;
if (lstat(file_header->name, &existing_sb) == -1) {
if (lstat(dst_name, &existing_sb) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat old file");
}
@ -73,30 +112,26 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
&& !S_ISDIR(file_header->mode)
) {
bb_error_msg("%s not created: newer or "
"same age file exists", file_header->name);
"same age file exists", dst_name);
}
data_skip(archive_handle);
goto ret;
}
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
else if ((unlink(dst_name) == -1) && (errno != EISDIR)) {
bb_perror_msg_and_die("can't remove old file %s",
file_header->name);
dst_name);
}
}
/* Handle hard links separately
* We encode hard links as regular files of size 0 with a symlink */
if (S_ISREG(file_header->mode)
&& file_header->link_target
&& file_header->size == 0
) {
/* hard link */
res = link(file_header->link_target, file_header->name);
if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
/* Handle hard links separately */
if (hard_link) {
res = link(hard_link, dst_name);
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
/* shared message */
bb_perror_msg("can't create %slink "
"from %s to %s", "hard",
file_header->name,
file_header->link_target);
"%s to %s", "hard",
dst_name,
hard_link);
}
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
goto ret;
@ -106,17 +141,17 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
switch (file_header->mode & S_IFMT) {
case S_IFREG: {
/* Regular file */
char *dst_name;
char *dst_nameN;
int flags = O_WRONLY | O_CREAT | O_EXCL;
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
flags = O_WRONLY | O_CREAT | O_TRUNC;
dst_name = file_header->name;
dst_nameN = dst_name;
#ifdef ARCHIVE_REPLACE_VIA_RENAME
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME)
/* rpm-style temp file name */
dst_name = xasprintf("%s;%x", dst_name, (int)getpid());
dst_nameN = xasprintf("%s;%x", dst_name, (int)getpid());
#endif
dst_fd = xopen3(dst_name,
dst_fd = xopen3(dst_nameN,
flags,
file_header->mode
);
@ -124,32 +159,33 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
close(dst_fd);
#ifdef ARCHIVE_REPLACE_VIA_RENAME
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) {
xrename(dst_name, file_header->name);
free(dst_name);
xrename(dst_nameN, dst_name);
free(dst_nameN);
}
#endif
break;
}
case S_IFDIR:
res = mkdir(file_header->name, file_header->mode);
res = mkdir(dst_name, file_header->mode);
if ((res == -1)
&& (errno != EISDIR) /* btw, Linux doesn't return this */
&& (errno != EEXIST)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't make dir %s", file_header->name);
bb_perror_msg("can't make dir %s", dst_name);
}
break;
case S_IFLNK:
/* Symlink */
//TODO: what if file_header->link_target == NULL (say, corrupted tarball?)
res = symlink(file_header->link_target, file_header->name);
if ((res == -1)
res = symlink(file_header->link_target, dst_name);
if (res != 0
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
/* shared message */
bb_perror_msg("can't create %slink "
"from %s to %s", "sym",
file_header->name,
"%s to %s", "sym",
dst_name,
file_header->link_target);
}
break;
@ -157,11 +193,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
res = mknod(file_header->name, file_header->mode, file_header->device);
res = mknod(dst_name, file_header->mode, file_header->device);
if ((res == -1)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't create node %s", file_header->name);
bb_perror_msg("can't create node %s", dst_name);
}
break;
default:
@ -186,20 +222,20 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
#endif
/* GNU tar 1.15.1 uses chown, not lchown */
chown(file_header->name, uid, gid);
chown(dst_name, uid, gid);
}
/* uclibc has no lchmod, glibc is even stranger -
* it has lchmod which seems to do nothing!
* so we use chmod... */
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) {
chmod(file_header->name, file_header->mode);
chmod(dst_name, file_header->mode);
}
if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
struct timeval t[2];
t[1].tv_sec = t[0].tv_sec = file_header->mtime;
t[1].tv_usec = t[0].tv_usec = 0;
utimes(file_header->name, t);
utimes(dst_name, t);
}
}

View File

@ -112,8 +112,7 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
bb_copyfd_exact_size(archive_handle->src_fd, p[1], -file_header->size);
close(p[1]);
if (safe_waitpid(pid, &status, 0) == -1)
bb_perror_msg_and_die("waitpid");
status = wait_for_exitstatus(pid);
if (WIFEXITED(status) && WEXITSTATUS(status))
bb_error_msg_and_die("'%s' returned status %d",
archive_handle->tar__to_command, WEXITSTATUS(status));

View File

@ -134,7 +134,7 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
/* Avoid 32-bit overflow (dump bit buffer to top of output) */
if (bit_count >= 24) {
bits = bd->inbufBits & ((1 << bit_count) - 1);
bits = bd->inbufBits & ((1U << bit_count) - 1);
bits_wanted -= bit_count;
bits <<= bits_wanted;
bit_count = 0;
@ -158,11 +158,11 @@ static int get_next_block(bunzip_data *bd)
{
struct group_data *hufGroup;
int dbufCount, dbufSize, groupCount, *base, *limit, selector,
i, j, t, runPos, symCount, symTotal, nSelectors, byteCount[256];
i, j, runPos, symCount, symTotal, nSelectors, byteCount[256];
int runCnt = runCnt; /* for compiler */
uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
uint32_t *dbuf;
unsigned origPtr;
unsigned origPtr, t;
dbuf = bd->dbuf;
dbufSize = bd->dbufSize;
@ -308,7 +308,7 @@ static int get_next_block(bunzip_data *bd)
base = hufGroup->base - 1;
limit = hufGroup->limit - 1;
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
/* Calculate permute[]. Concurrently, initialize temp[] and limit[]. */
pp = 0;
for (i = minLen; i <= maxLen; i++) {
int k;

View File

@ -305,11 +305,11 @@ static int huft_build(const unsigned *b, const unsigned n,
unsigned i; /* counter, current code */
unsigned j; /* counter */
int k; /* number of bits in current code */
unsigned *p; /* pointer into c[], b[], or v[] */
const unsigned *p; /* pointer into c[], b[], or v[] */
huft_t *q; /* points to current table */
huft_t r; /* table entry for structure assignment */
huft_t *u[BMAX]; /* table stack */
unsigned v[N_MAX]; /* values in order of bit length */
unsigned v[N_MAX + 1]; /* values in order of bit length. last v[] is never used */
int ws[BMAX + 1]; /* bits decoded stack */
int w; /* bits decoded */
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
@ -324,7 +324,7 @@ static int huft_build(const unsigned *b, const unsigned n,
/* Generate counts for each bit length */
memset(c, 0, sizeof(c));
p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */
p = b;
i = n;
do {
c[*p]++; /* assume all entries <= BMAX */
@ -364,8 +364,12 @@ static int huft_build(const unsigned *b, const unsigned n,
*xp++ = j;
}
/* Make a table of values in order of bit lengths */
p = (unsigned *) b;
/* Make a table of values in order of bit lengths.
* To detect bad input, unused v[i]'s are set to invalid value UINT_MAX.
* In particular, last v[i] is never filled and must not be accessed.
*/
memset(v, 0xff, sizeof(v));
p = b;
i = 0;
do {
j = *p++;
@ -432,7 +436,9 @@ static int huft_build(const unsigned *b, const unsigned n,
/* set up table entry in r */
r.b = (unsigned char) (k - w);
if (p >= v + n) {
if (/*p >= v + n || -- redundant, caught by the second check: */
*p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/
) {
r.e = 99; /* out of values--invalid code */
} else if (*p < s) {
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
@ -517,8 +523,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
e = t->e;
if (e > 16)
do {
if (e == 99)
abort_unzip(PASS_STATE_ONLY);;
if (e == 99) {
abort_unzip(PASS_STATE_ONLY);
}
bb >>= t->b;
k -= t->b;
e -= 16;
@ -554,8 +561,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
e = t->e;
if (e > 16)
do {
if (e == 99)
if (e == 99) {
abort_unzip(PASS_STATE_ONLY);
}
bb >>= t->b;
k -= t->b;
e -= 16;
@ -821,8 +829,9 @@ static int inflate_block(STATE_PARAM smallint *e)
b_dynamic >>= 4;
k_dynamic -= 4;
if (nl > 286 || nd > 30)
if (nl > 286 || nd > 30) {
abort_unzip(PASS_STATE_ONLY); /* bad lengths */
}
/* read in bit-length-code lengths */
for (j = 0; j < nb; j++) {
@ -903,12 +912,14 @@ static int inflate_block(STATE_PARAM smallint *e)
bl = lbits;
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
if (i != 0)
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
bd = dbits;
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
if (i != 0)
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
/* set up data for inflate_codes() */
inflate_codes_setup(PASS_STATE bl, bd);
@ -996,6 +1007,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
error_msg = "corrupted data";
if (setjmp(error_jmp)) {
/* Error from deep inside zip machinery */
bb_error_msg(error_msg);
n = -1;
goto ret;
}
@ -1118,9 +1130,8 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
uint8_t os_flags_UNUSED;
} PACKED formatted;
} header;
struct BUG_header {
char BUG_header[sizeof(header) == 8 ? 1 : -1];
};
BUILD_BUG_ON(sizeof(header) != 8);
/*
* Rewind bytebuffer. We use the beginning because the header has 8
@ -1190,7 +1201,7 @@ unpack_gz_stream(transformer_state_t *xstate)
if (check_signature16(xstate, GZIP_MAGIC))
return -1;
#else
if (xstate->check_signature) {
if (!xstate->signature_skipped) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
@ -1199,7 +1210,7 @@ unpack_gz_stream(transformer_state_t *xstate)
return -1;
}
if (magic2 == COMPRESS_MAGIC) {
xstate->check_signature = 0;
xstate->signature_skipped = 2;
return unpack_Z_stream(xstate);
}
if (magic2 != GZIP_MAGIC)

View File

@ -278,9 +278,10 @@ unpack_lzma_stream(transformer_state_t *xstate)
if (state >= LZMA_NUM_LIT_STATES) {
int match_byte;
uint32_t pos = buffer_pos - rep0;
uint32_t pos;
while (pos >= header.dict_size)
pos = buffer_pos - rep0;
if ((int32_t)pos < 0)
pos += header.dict_size;
match_byte = buffer[pos];
do {
@ -336,9 +337,11 @@ unpack_lzma_stream(transformer_state_t *xstate)
);
if (!rc_is_bit_1(rc, prob2)) {
#if ENABLE_FEATURE_LZMA_FAST
uint32_t pos = buffer_pos - rep0;
uint32_t pos;
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
while (pos >= header.dict_size)
pos = buffer_pos - rep0;
if ((int32_t)pos < 0)
pos += header.dict_size;
previous_byte = buffer[pos];
goto one_byte1;
@ -429,10 +432,25 @@ unpack_lzma_stream(transformer_state_t *xstate)
}
len += LZMA_MATCH_MIN_LEN;
/*
* LZMA SDK has this optimized:
* it precalculates size and copies many bytes
* in a loop with simpler checks, a-la:
* do
* *(dest) = *(dest + ofs);
* while (++dest != lim);
* and
* do {
* buffer[buffer_pos++] = buffer[pos];
* if (++pos == header.dict_size)
* pos = 0;
* } while (--cur_len != 0);
* Our code is slower (more checks per byte copy):
*/
IF_NOT_FEATURE_LZMA_FAST(string:)
do {
uint32_t pos = buffer_pos - rep0;
while (pos >= header.dict_size)
if ((int32_t)pos < 0)
pos += header.dict_size;
previous_byte = buffer[pos];
IF_NOT_FEATURE_LZMA_FAST(one_byte2:)
@ -448,6 +466,9 @@ unpack_lzma_stream(transformer_state_t *xstate)
} while (len != 0 && buffer_pos < header.dst_size);
/* FIXME: ...........^^^^^
* shouldn't it be "global_pos + buffer_pos < header.dst_size"?
* It probably should, but it is a "do we accidentally
* unpack more bytes than expected?" check - which
* never happens for well-formed compression data...
*/
}
}

View File

@ -55,7 +55,7 @@ unpack_xz_stream(transformer_state_t *xstate)
iobuf.out = membuf + BUFSIZ;
iobuf.out_size = BUFSIZ;
if (!xstate || xstate->check_signature == 0) {
if (!xstate || xstate->signature_skipped) {
/* Preload XZ file signature */
strcpy((char*)membuf, HEADER_MAGIC);
iobuf.in_size = HEADER_MAGIC_SIZE;

View File

@ -52,6 +52,11 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
&major, &minor, &namesize) != 10)
bb_error_msg_and_die("damaged cpio file");
file_header->mode = mode;
/* "cpio -R USER:GRP" support: */
if (archive_handle->cpio__owner.uid != (uid_t)-1L)
uid = archive_handle->cpio__owner.uid;
if (archive_handle->cpio__owner.gid != (gid_t)-1L)
gid = archive_handle->cpio__owner.gid;
file_header->uid = uid;
file_header->gid = gid;
file_header->mtime = mtime;
@ -75,7 +80,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
/* Update offset amount and skip padding before file contents */
data_align(archive_handle, 4);
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
if (strcmp(file_header->name, cpio_TRAILER) == 0) {
/* Always round up. ">> 9" divides by 512 */
archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9;
goto create_hardlinks;

View File

@ -60,13 +60,21 @@ static unsigned long long getOctal(char *str, int len)
}
#define GET_OCTAL(a) getOctal((a), sizeof(a))
#define TAR_EXTD (ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX)
#if !TAR_EXTD
#define process_pax_hdr(archive_handle, sz, global) \
process_pax_hdr(archive_handle, sz)
#endif
/* "global" is 0 or 1 */
static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global)
{
#if !TAR_EXTD
unsigned blk_sz = (sz + 511) & (~511);
seek_by_read(archive_handle->src_fd, blk_sz);
#else
unsigned blk_sz = (sz + 511) & (~511);
char *buf, *p;
unsigned blk_sz;
blk_sz = (sz + 511) & (~511);
p = buf = xmalloc(blk_sz + 1);
xread(archive_handle->src_fd, buf, blk_sz);
archive_handle->offset += blk_sz;
@ -104,30 +112,39 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
p[-1] = '\0';
value = end + 1;
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (!global && is_prefixed_with(value, "path=")) {
value += sizeof("path=") - 1;
free(archive_handle->tar__longname);
archive_handle->tar__longname = xstrdup(value);
continue;
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (!global) {
if (is_prefixed_with(value, "path=")) {
value += sizeof("path=") - 1;
free(archive_handle->tar__longname);
archive_handle->tar__longname = xstrdup(value);
continue;
}
if (is_prefixed_with(value, "linkpath=")) {
value += sizeof("linkpath=") - 1;
free(archive_handle->tar__linkname);
archive_handle->tar__linkname = xstrdup(value);
continue;
}
}
#endif
# endif
#if ENABLE_FEATURE_TAR_SELINUX
# if ENABLE_FEATURE_TAR_SELINUX
/* Scan for SELinux contexts, via "RHT.security.selinux" keyword.
* This is what Red Hat's patched version of tar uses.
*/
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
free(archive_handle->tar__sctx[global]);
archive_handle->tar__sctx[global] = xstrdup(value);
continue;
}
#endif
# endif
}
free(buf);
#endif
}
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
@ -170,7 +187,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* the message and we don't check whether we indeed
* saw zero block directly before this. */
if (i == 0) {
bb_error_msg("short read");
/* GNU tar 1.29 will be silent if tar archive ends abruptly
* (if there are no zero blocks at all, and last read returns zero,
* not short read 0 < len < 512). Complain only if
* the very first read fails. Grrr.
*/
if (archive_handle->offset == 0)
bb_error_msg("short read");
/* this merely signals end of archive, not exit(1): */
return EXIT_FAILURE;
}
@ -186,7 +209,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
archive_handle->offset += i;
/* If there is no filename its an empty header */
if (tar.name[0] == 0 && tar.prefix[0] == 0) {
if (tar.name[0] == 0 && tar.prefix[0] == 0
/* Have seen a tar archive with pax 'x' header supplying UTF8 filename,
* with actual file having all name fields NUL-filled. Check this: */
&& !p_longname
) {
if (archive_handle->tar__end) {
/* Second consecutive empty header - end of archive.
* Read until the end to empty the pipe from gz or bz2
@ -418,6 +445,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* Everything up to and including last ".." component is stripped */
overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
//TODO: do the same for file_header->link_target?
/* Strip trailing '/' in directories */
/* Must be done after mode is set as '/' is used to check if it's a directory */

View File

@ -17,6 +17,10 @@ archive_handle_t* FAST_FUNC init_handle(void)
archive_handle->action_data = data_skip;
archive_handle->filter = filter_accept_all;
archive_handle->seek = seek_by_jump;
#if ENABLE_CPIO || ENABLE_RPM2CPIO || ENABLE_RPM
archive_handle->cpio__owner.uid = (uid_t)-1L;
archive_handle->cpio__owner.gid = (gid_t)-1L;
#endif
return archive_handle;
}

View File

@ -13,16 +13,13 @@ void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
{
if (xstate->check_signature) {
if (!xstate->signature_skipped) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
bb_error_msg("invalid magic");
#if 0 /* possible future extension */
if (xstate->check_signature > 1)
xfunc_die();
#endif
return -1;
}
xstate->signature_skipped = 2;
}
return 0;
}
@ -102,7 +99,7 @@ void check_errors_in_children(int signo)
/* transformer(), more than meets the eye */
#if BB_MMU
void FAST_FUNC fork_transformer(int fd,
int check_signature,
int signature_skipped,
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
)
#else
@ -123,7 +120,7 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
IF_DESKTOP(long long) int r;
transformer_state_t xstate;
init_transformer_state(&xstate);
xstate.check_signature = check_signature;
xstate.signature_skipped = signature_skipped;
xstate.src_fd = fd;
xstate.dst_fd = fd_pipe.wr;
r = transformer(&xstate);
@ -168,12 +165,11 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
uint16_t b16[2];
uint32_t b32[1];
} magic;
int offset;
transformer_state_t *xstate;
offset = -2;
xstate = xzalloc(sizeof(*xstate));
xstate->src_fd = fd;
xstate->signature_skipped = 2;
/* .gz and .bz2 both have 2-byte signature, and their
* unpack_XXX_stream wants this header skipped. */
@ -202,7 +198,7 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
if (ENABLE_FEATURE_SEAMLESS_XZ
&& magic.b16[0] == XZ_MAGIC1
) {
offset = -6;
xstate->signature_skipped = 6;
xread(fd, magic.b32, sizeof(magic.b32[0]));
if (magic.b32[0] == XZ_MAGIC2) {
xstate->xformer = unpack_xz_stream;
@ -224,18 +220,8 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
*/
// USE_FOR_MMU(xstate->xformer = copy_stream;)
// USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
/* fall through to seeking bck over bytes we read earlier */
USE_FOR_NOMMU(found_magic:)
/* NOMMU version of fork_transformer execs
* an external unzipper that wants
* file position at the start of the file.
*/
xlseek(fd, offset, SEEK_CUR);
USE_FOR_MMU(found_magic:)
/* In MMU case, if magic was found, seeking back is not necessary */
found_magic:
return xstate;
}
@ -254,6 +240,12 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
# else
/* NOMMU version of fork_transformer execs
* an external unzipper that wants
* file position at the start of the file.
*/
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
# endif
free(xstate);
@ -296,14 +288,22 @@ int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
return -1;
fd = xstate->src_fd;
if (xstate->xformer) {
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
# else
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
# endif
if (xstate->xformer) {
fork_transformer_with_no_sig(fd, xstate->xformer);
} else {
/* the file is not compressed */
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
}
/* else: the file is not compressed */
# else
/* NOMMU can't avoid the seek :( */
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
if (xstate->xformer) {
fork_transformer_with_sig(fd, xstate->xformer, xstate->xformer_prog);
} /* else: the file is not compressed */
# endif
free(xstate);
return fd;
@ -331,6 +331,9 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
}
} else {
/* File is not compressed */
//FIXME: avoid seek
xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
image = xmalloc_read(xstate->src_fd, maxsz_p);
}

View File

@ -486,11 +486,11 @@ static __always_inline void XZ_FUNC rc_normalize(struct rc_dec *rc)
}
/*
* Decode one bit. In some versions, this function has been splitted in three
* Decode one bit. In some versions, this function has been split in three
* functions so that the compiler is supposed to be able to more easily avoid
* an extra branch. In this particular version of the LZMA decoder, this
* doesn't seem to be a good idea (tested with GCC 3.3.6, 3.4.6, and 4.3.3
* on x86). Using a non-splitted version results in nicer looking code too.
* on x86). Using a non-split version results in nicer looking code too.
*
* NOTE: This must return an int. Do not make it return a bool or the speed
* of the code generated by GCC 3.x decreases 10-15 %. (GCC 4.3 doesn't care,

View File

@ -31,46 +31,66 @@
//config: help
//config: Lzop compression/decompresion.
//config:
//config:config UNLZOP
//config: bool "unlzop"
//config: default n # INCOMPAT: upstream lzop does not provide such tool
//config: help
//config: Lzop decompresion.
//config:
//config:config LZOPCAT
//config: bool "lzopcat"
//config: default n # INCOMPAT: upstream lzop does not provide such tool
//config: help
//config: Alias to "unlzop -c".
//config:
//config:config LZOP_COMPR_HIGH
//config: bool "lzop compression levels 7,8,9 (not very useful)"
//config: default n
//config: depends on LZOP
//config: depends on LZOP || UNLZOP || LZOPCAT
//config: help
//config: High levels (7,8,9) of lzop compression. These levels
//config: are actually slower than gzip at equivalent compression ratios
//config: and take up 3.2K of code.
//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
//applet:IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
//applet:IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_UNLZOP( APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
//applet:IF_LZOPCAT(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
//kbuild:lib-$(CONFIG_LZOP) += lzop.o
//kbuild:lib-$(CONFIG_UNLZOP) += lzop.o
//kbuild:lib-$(CONFIG_LZOPCAT) += lzop.o
//usage:#define lzop_trivial_usage
//usage: "[-cfvd123456789CF] [FILE]..."
//usage: "[-cfUvd123456789CF] [FILE]..."
//usage:#define lzop_full_usage "\n\n"
//usage: " -1..9 Compression level"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -U Delete input files"
///////: "\n -k Keep input files" (default, so why bother documenting?)
//usage: "\n -v Verbose"
//usage: "\n -F Don't store or verify checksum"
//usage: "\n -C Also write checksum of compressed block"
//usage:
//usage:#define lzopcat_trivial_usage
//usage: "[-vCF] [FILE]..."
//usage: "[-vF] [FILE]..."
//usage:#define lzopcat_full_usage "\n\n"
//usage: " -v Verbose"
//usage: "\n -F Don't store or verify checksum"
//usage: "\n -F Don't verify checksum"
//usage:
//usage:#define unlzop_trivial_usage
//usage: "[-cfvCF] [FILE]..."
//usage: "[-cfkvF] [FILE]..."
//usage:#define unlzop_full_usage "\n\n"
//usage: " -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -U Delete input files"
///////: "\n -k Keep input files" (default, so why bother documenting?)
//usage: "\n -v Verbose"
//usage: "\n -F Don't store or verify checksum"
//usage: "\n -F Don't verify checksum"
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
#include "liblzo_interface.h"
@ -443,8 +463,8 @@ struct globals {
chksum_t chksum_in;
chksum_t chksum_out;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
//#define G (*ptr_to_globals)
//#define INIT_G() do {
// SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
@ -456,27 +476,33 @@ struct globals {
//#define LZOP_VERSION_STRING "1.01"
//#define LZOP_VERSION_DATE "Apr 27th 2003"
#define OPTION_STRING "cfvqdt123456789CF"
// lzop wants to be weird:
// unlike all other compressosrs, its -k "keep" option is the default,
// and -U is used to delete the source. We will invert the bit after getopt().
#define OPTION_STRING "cfUvqdt123456789CFk"
/* Note: must be kept in sync with archival/bbunzip.c */
enum {
OPT_STDOUT = (1 << 0),
OPT_FORCE = (1 << 1),
OPT_VERBOSE = (1 << 2),
OPT_QUIET = (1 << 3),
OPT_DECOMPRESS = (1 << 4),
OPT_TEST = (1 << 5),
OPT_1 = (1 << 6),
OPT_2 = (1 << 7),
OPT_3 = (1 << 8),
OPT_4 = (1 << 9),
OPT_5 = (1 << 10),
OPT_6 = (1 << 11),
OPT_789 = (7 << 12),
OPT_KEEP = (1 << 2),
OPT_VERBOSE = (1 << 3),
OPT_QUIET = (1 << 4),
OPT_DECOMPRESS = (1 << 5),
OPT_TEST = (1 << 6),
OPT_1 = (1 << 7),
OPT_2 = (1 << 8),
OPT_3 = (1 << 9),
OPT_4 = (1 << 10),
OPT_5 = (1 << 11),
OPT_6 = (1 << 12),
OPT_7 = (1 << 13),
OPT_8 = (1 << 14),
OPT_C = (1 << 15),
OPT_F = (1 << 16),
OPT_9 = (1 << 15),
OPT_C = (1 << 16),
OPT_F = (1 << 17),
OPT_k = (1 << 18),
OPT_789 = OPT_7 | OPT_8 | OPT_9
};
/**********************************************************************/
@ -640,7 +666,7 @@ static int lzo_get_method(header_t *h)
/**********************************************************************/
// compress a file
/**********************************************************************/
static NOINLINE smallint lzo_compress(const header_t *h)
static NOINLINE int lzo_compress(const header_t *h)
{
unsigned block_size = LZO_BLOCK_SIZE;
int r = 0; /* LZO_E_OK */
@ -650,7 +676,6 @@ static NOINLINE smallint lzo_compress(const header_t *h)
uint32_t d_adler32 = ADLER32_INIT_VALUE;
uint32_t d_crc32 = CRC32_INIT_VALUE;
int l;
smallint ok = 1;
uint8_t *wrk_mem = NULL;
if (h->method == M_LZO1X_1)
@ -732,7 +757,7 @@ static NOINLINE smallint lzo_compress(const header_t *h)
free(wrk_mem);
free(b1);
free(b2);
return ok;
return 1;
}
static FAST_FUNC void lzo_check(
@ -753,7 +778,7 @@ static FAST_FUNC void lzo_check(
/**********************************************************************/
// decompress a file
/**********************************************************************/
static NOINLINE smallint lzo_decompress(const header_t *h)
static NOINLINE int lzo_decompress(const header_t *h)
{
unsigned block_size = LZO_BLOCK_SIZE;
int r;
@ -761,7 +786,6 @@ static NOINLINE smallint lzo_decompress(const header_t *h)
uint32_t c_adler32 = ADLER32_INIT_VALUE;
uint32_t d_adler32 = ADLER32_INIT_VALUE;
uint32_t c_crc32 = CRC32_INIT_VALUE, d_crc32 = CRC32_INIT_VALUE;
smallint ok = 1;
uint8_t *b1;
uint32_t mcs_block_size = MAX_COMPRESSED_SIZE(block_size);
uint8_t *b2 = NULL;
@ -865,7 +889,7 @@ static NOINLINE smallint lzo_decompress(const header_t *h)
}
free(b2);
return ok;
return 1;
}
/**********************************************************************/
@ -897,7 +921,7 @@ static NOINLINE smallint lzo_decompress(const header_t *h)
* chksum_out
* The rest is identical.
*/
static const unsigned char lzop_magic[9] = {
static const unsigned char lzop_magic[9] ALIGN1 = {
0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
};
@ -1050,7 +1074,7 @@ static void lzo_set_method(header_t *h)
h->level = level;
}
static smallint do_lzo_compress(void)
static int do_lzo_compress(void)
{
header_t header;
@ -1078,7 +1102,7 @@ static smallint do_lzo_compress(void)
/**********************************************************************/
// decompress
/**********************************************************************/
static smallint do_lzo_decompress(void)
static int do_lzo_decompress(void)
{
header_t header;
@ -1111,11 +1135,18 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, OPTION_STRING);
argv += optind;
/* -U is "anti -k", invert bit for bbunpack(): */
option_mask32 ^= OPT_KEEP;
/* -k disables -U (if any): */
/* opt_complementary = "k-U"; - nope, only handles -Uk, not -kU */
if (option_mask32 & OPT_k)
option_mask32 |= OPT_KEEP;
/* lzopcat? */
if (applet_name[4] == 'c')
if (ENABLE_LZOPCAT && applet_name[4] == 'c')
option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS);
/* unlzop? */
if (applet_name[4] == 'o')
if (ENABLE_UNLZOP && applet_name[4] == 'o')
option_mask32 |= OPT_DECOMPRESS;
global_crc32_table = crc32_filltable(NULL, 0);

View File

@ -29,6 +29,7 @@
//usage: "\n -qpc List config files"
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
#include "rpm.h"
@ -93,8 +94,8 @@ struct globals {
rpm_index **mytags;
int tagcount;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
static void extract_cpio(int fd, const char *source_rpm)
{

View File

@ -49,13 +49,15 @@
//config: create compressed archives. It's probably the most widely used
//config: UNIX archive program.
//config:
//config:config FEATURE_TAR_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on TAR && LONG_OPTS
//config:
//config:config FEATURE_TAR_CREATE
//config: bool "Enable archive creation"
//config: bool "Enable -c (archive creation)"
//config: default y
//config: depends on TAR
//config: help
//config: If you enable this option you'll be able to create
//config: tar archives using the `-c' option.
//config:
//config:config FEATURE_TAR_AUTODETECT
//config: bool "Autodetect compressed tarballs"
@ -74,7 +76,7 @@
//config: a list of files to include or exclude from an archive.
//config:
//config:config FEATURE_TAR_OLDGNU_COMPATIBILITY
//config: bool "Support for old tar header format"
//config: bool "Support old tar header format"
//config: default y
//config: depends on TAR || DPKG
//config: help
@ -93,22 +95,12 @@
//config: tarballs still exist.
//config:
//config:config FEATURE_TAR_GNU_EXTENSIONS
//config: bool "Support for GNU tar extensions (long filenames)"
//config: bool "Support GNU tar extensions (long filenames)"
//config: default y
//config: depends on TAR || DPKG
//config: help
//config: With this option busybox supports GNU long filenames and
//config: linknames.
//config:
//config:config FEATURE_TAR_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on TAR && LONG_OPTS
//config: help
//config: Enable use of long options, increases size by about 400 Bytes
//config:
//config:config FEATURE_TAR_TO_COMMAND
//config: bool "Support for writing to an external program"
//config: bool "Support writing to an external program (--to-command)"
//config: default y
//config: depends on TAR && FEATURE_TAR_LONG_OPTIONS
//config: help
@ -121,20 +113,17 @@
//config: default y
//config: depends on TAR
//config: help
//config: Enables use of user and group names in tar. This affects contents
//config: Enable use of user and group names in tar. This affects contents
//config: listings (-t) and preserving permissions when unpacking (-p).
//config: +200 bytes.
//config:
//config:config FEATURE_TAR_NOPRESERVE_TIME
//config: bool "Enable -m (do not preserve time) option"
//config: bool "Enable -m (do not preserve time) GNU option"
//config: default y
//config: depends on TAR
//config: help
//config: With this option busybox supports GNU tar -m
//config: (do not preserve time) option.
//config:
//config:config FEATURE_TAR_SELINUX
//config: bool "Support for extracting SELinux labels"
//config: bool "Support extracting SELinux labels"
//config: default n
//config: depends on TAR && SELINUX
//config: help
@ -146,18 +135,23 @@
#include <fnmatch.h>
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
/* FIXME: Stop using this non-standard feature */
#ifndef FNM_LEADING_DIR
# define FNM_LEADING_DIR 0
#endif
//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
#define DBG(...) ((void)0)
#if 0
# define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
#else
# define DBG(...) ((void)0)
#endif
#define DBG_OPTION_PARSING 0
#define block_buf bb_common_bufsiz1
#define INIT_G() do { setup_common_bufsiz(); } while (0)
#if ENABLE_FEATURE_TAR_CREATE
@ -535,8 +529,8 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
/*
* Check to see if we are dealing with a hard link.
* If so -
* Treat the first occurance of a given dev/inode as a file while
* treating any additional occurances as hard links. This is done
* Treat the first occurrence of a given dev/inode as a file while
* treating any additional occurrences as hard links. This is done
* by adding the file information to the HardLinkInfo linked list.
*/
tbInfo->hlInfo = NULL;
@ -855,6 +849,7 @@ enum {
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
OPTBIT_STRIP_COMPONENTS,
OPTBIT_NORECURSION,
IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,)
OPTBIT_NUMERIC_OWNER,
@ -879,12 +874,13 @@ enum {
OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J
OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
OPT_STRIP_COMPONENTS = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_STRIP_COMPONENTS)) + 0, // strip-components
OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS),
};
@ -928,6 +924,7 @@ static const char tar_longopts[] ALIGN1 =
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
"touch\0" No_argument "m"
# endif
"strip-components\0" Required_argument "\xf9"
"no-recursion\0" No_argument "\xfa"
# if ENABLE_FEATURE_TAR_TO_COMMAND
"to-command\0" Required_argument "\xfb"
@ -957,6 +954,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
llist_t *excludes = NULL;
#endif
INIT_G();
/* Initialise default values */
tar_handle = init_handle();
@ -971,17 +969,29 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
/* Prepend '-' to the first argument if required */
opt_complementary = "--:" // first arg is options
"tt:vv:" // count -t,-v
IF_FEATURE_TAR_FROM("X::T::") // cumulative lists
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // cumulative lists for --exclude
"\xff::" // --exclude=PATTERN is a list
#endif
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
":\xf9+" // --strip-components=NUM
#endif
;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
applet_long_options = tar_longopts;
#endif
#if ENABLE_DESKTOP
/* Lie to buildroot when it starts asking stupid questions. */
if (argv[1] && strcmp(argv[1], "--version") == 0) {
// Output of 'tar --version' examples:
// tar (GNU tar) 1.15.1
// tar (GNU tar) 1.25
// bsdtar 2.8.3 - libarchive 2.8.3
puts("tar (busybox) " BB_VER);
return 0;
}
if (argv[1] && argv[1][0] != '-') {
/* Compat:
* 1st argument without dash handles options with parameters
@ -1010,18 +1020,22 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
#endif
opt = getopt32(argv,
"txC:f:Oopvk"
IF_FEATURE_TAR_CREATE( "ch" )
IF_FEATURE_SEAMLESS_BZ2( "j" )
IF_FEATURE_SEAMLESS_LZMA("a" )
IF_FEATURE_TAR_FROM( "T:X:")
IF_FEATURE_SEAMLESS_GZ( "z" )
IF_FEATURE_SEAMLESS_XZ( "J" )
IF_FEATURE_SEAMLESS_Z( "Z" )
IF_FEATURE_TAR_CREATE( "ch" )
IF_FEATURE_SEAMLESS_BZ2( "j" )
IF_FEATURE_SEAMLESS_LZMA("a" )
IF_FEATURE_TAR_FROM( "T:*X:*")
IF_FEATURE_SEAMLESS_GZ( "z" )
IF_FEATURE_SEAMLESS_XZ( "J" )
IF_FEATURE_SEAMLESS_Z( "Z" )
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
, &base_dir // -C dir
, &tar_filename // -f filename
IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
, &tar_handle->tar__strip_components // --strip-components
#endif
IF_FEATURE_TAR_TO_COMMAND(, &(tar_handle->tar__to_command)) // --to-command
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
, &excludes // --exclude
@ -1029,11 +1043,49 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
, &verboseFlag // combined count for -t and -v
, &verboseFlag // combined count for -t and -v
);
//bb_error_msg("opt:%08x", opt);
#if DBG_OPTION_PARSING
bb_error_msg("opt: 0x%08x", opt);
# define showopt(o) bb_error_msg("opt & %s(%x): %x", #o, o, opt & o);
showopt(OPT_TEST );
showopt(OPT_EXTRACT );
showopt(OPT_BASEDIR );
showopt(OPT_TARNAME );
showopt(OPT_2STDOUT );
showopt(OPT_NOPRESERVE_OWNER);
showopt(OPT_P );
showopt(OPT_VERBOSE );
showopt(OPT_KEEP_OLD );
showopt(OPT_CREATE );
showopt(OPT_DEREFERENCE );
showopt(OPT_BZIP2 );
showopt(OPT_LZMA );
showopt(OPT_INCLUDE_FROM );
showopt(OPT_EXCLUDE_FROM );
showopt(OPT_GZIP );
showopt(OPT_XZ );
showopt(OPT_COMPRESS );
showopt(OPT_NOPRESERVE_TIME );
showopt(OPT_STRIP_COMPONENTS);
showopt(OPT_NORECURSION );
showopt(OPT_2COMMAND );
showopt(OPT_NUMERIC_OWNER );
showopt(OPT_NOPRESERVE_PERM );
showopt(OPT_OVERWRITE );
showopt(OPT_ANY_COMPRESS );
bb_error_msg("base_dir:'%s'", base_dir);
bb_error_msg("tar_filename:'%s'", tar_filename);
bb_error_msg("verboseFlag:%d", verboseFlag);
bb_error_msg("tar_handle->tar__to_command:'%s'", tar_handle->tar__to_command);
bb_error_msg("tar_handle->tar__strip_components:%u", tar_handle->tar__strip_components);
return 0;
# undef showopt
#endif
argv += optind;
if (verboseFlag) tar_handle->action_header = header_verbose_list;
if (verboseFlag == 1) tar_handle->action_header = header_list;
if (verboseFlag)
tar_handle->action_header = header_verbose_list;
if (verboseFlag == 1)
tar_handle->action_header = header_list;
if (opt & OPT_EXTRACT)
tar_handle->action_data = data_extract_all;
@ -1135,9 +1187,10 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
// signal(SIGCHLD, check_errors_in_children);
#if ENABLE_FEATURE_TAR_CREATE
/* Create an archive */
if (opt & OPT_CREATE) {
#if SEAMLESS_COMPRESSION
# if SEAMLESS_COMPRESSION
const char *zipMode = NULL;
if (opt & OPT_COMPRESS)
zipMode = "compress";
@ -1149,7 +1202,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
zipMode = "lzma";
if (opt & OPT_XZ)
zipMode = "xz";
#endif
# endif
/* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tar_handle->src_fd, verboseFlag,
(opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
@ -1157,26 +1210,32 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
tar_handle->accept,
tar_handle->reject, zipMode);
}
#endif
if (opt & OPT_ANY_COMPRESS) {
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
USE_FOR_NOMMU(const char *xformer_prog;)
if (opt & OPT_COMPRESS)
USE_FOR_MMU(xformer = unpack_Z_stream;)
if (opt & OPT_COMPRESS) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_Z(xformer = unpack_Z_stream;))
USE_FOR_NOMMU(xformer_prog = "uncompress";)
if (opt & OPT_GZIP)
USE_FOR_MMU(xformer = unpack_gz_stream;)
}
if (opt & OPT_GZIP) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_GZ(xformer = unpack_gz_stream;))
USE_FOR_NOMMU(xformer_prog = "gunzip";)
if (opt & OPT_BZIP2)
USE_FOR_MMU(xformer = unpack_bz2_stream;)
}
if (opt & OPT_BZIP2) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_BZ2(xformer = unpack_bz2_stream;))
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
if (opt & OPT_LZMA)
USE_FOR_MMU(xformer = unpack_lzma_stream;)
}
if (opt & OPT_LZMA) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_LZMA(xformer = unpack_lzma_stream;))
USE_FOR_NOMMU(xformer_prog = "unlzma";)
if (opt & OPT_XZ)
USE_FOR_MMU(xformer = unpack_xz_stream;)
}
if (opt & OPT_XZ) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_XZ(xformer = unpack_xz_stream;))
USE_FOR_NOMMU(xformer_prog = "unxz";)
}
fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
/* Can't lseek over pipes */

View File

@ -16,7 +16,6 @@
* TODO
* Zip64 + other methods
*/
//config:config UNZIP
//config: bool "unzip"
//config: default y
@ -24,8 +23,34 @@
//config: unzip will list or extract files from a ZIP archive,
//config: commonly found on DOS/WIN systems. The default behavior
//config: (with no options) is to extract the archive into the
//config: current directory. Use the `-d' option to extract to a
//config: directory of your choice.
//config: current directory.
//config:
//config:config FEATURE_UNZIP_CDF
//config: bool "Read and use Central Directory data"
//config: default y
//config: depends on UNZIP
//config: help
//config: If you know that you only need to deal with simple
//config: ZIP files without deleted/updated files, SFX archives etc,
//config: you can reduce code size by unselecting this option.
//config: To support less trivial ZIPs, say Y.
//config:
//config:config FEATURE_UNZIP_BZIP2
//config: bool "Support compression method 12 (bzip2)"
//config: default y
//config: depends on FEATURE_UNZIP_CDF && DESKTOP
// FEATURE_UNZIP_CDF is needed, otherwise we can't find start of next file
// DESKTOP is needed to get back uncompressed length
//config:
//config:config FEATURE_UNZIP_LZMA
//config: bool "Support compression method 14 (lzma)"
//config: default y
//config: depends on FEATURE_UNZIP_CDF && DESKTOP
//config:
//config:config FEATURE_UNZIP_XZ
//config: bool "Support compression method 95 (xz)"
//config: default y
//config: depends on FEATURE_UNZIP_CDF && DESKTOP
//applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
@ -45,11 +70,17 @@
#include "libbb.h"
#include "bb_archive.h"
#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
#else
# define dbg(...) ((void)0)
#endif
enum {
#if BB_BIG_ENDIAN
ZIP_FILEHEADER_MAGIC = 0x504b0304,
ZIP_CDF_MAGIC = 0x504b0102, /* central directory's file header */
ZIP_CDE_MAGIC = 0x504b0506, /* "end of central directory" record */
ZIP_CDF_MAGIC = 0x504b0102, /* CDF item */
ZIP_CDE_MAGIC = 0x504b0506, /* End of CDF */
ZIP_DD_MAGIC = 0x504b0708,
#else
ZIP_FILEHEADER_MAGIC = 0x04034b50,
@ -74,30 +105,20 @@ typedef union {
uint32_t ucmpsize PACKED; /* 18-21 */
uint16_t filename_len; /* 22-23 */
uint16_t extra_len; /* 24-25 */
} formatted PACKED;
/* filename follows (not NUL terminated) */
/* extra field follows */
/* data follows */
} fmt PACKED;
} zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */
/* Check the offset of the last element, not the length. This leniency
* allows for poor packing, whereby the overall struct may be too long,
* even though the elements are all in the right place.
*/
struct BUG_zip_header_must_be_26_bytes {
char BUG_zip_header_must_be_26_bytes[
offsetof(zip_header_t, formatted.extra_len) + 2
== ZIP_HEADER_LEN ? 1 : -1];
};
#define FIX_ENDIANNESS_ZIP(zip_header) do { \
(zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \
(zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \
(zip_header).formatted.modtime = SWAP_LE16((zip_header).formatted.modtime ); \
(zip_header).formatted.moddate = SWAP_LE16((zip_header).formatted.moddate ); \
(zip_header).formatted.crc32 = SWAP_LE32((zip_header).formatted.crc32 ); \
(zip_header).formatted.cmpsize = SWAP_LE32((zip_header).formatted.cmpsize ); \
(zip_header).formatted.ucmpsize = SWAP_LE32((zip_header).formatted.ucmpsize ); \
(zip_header).formatted.filename_len = SWAP_LE16((zip_header).formatted.filename_len); \
(zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
} while (0)
#define FIX_ENDIANNESS_ZIP(zip) \
do { if (BB_BIG_ENDIAN) { \
(zip).fmt.crc32 = SWAP_LE32((zip).fmt.crc32 ); \
(zip).fmt.cmpsize = SWAP_LE32((zip).fmt.cmpsize ); \
(zip).fmt.ucmpsize = SWAP_LE32((zip).fmt.ucmpsize ); \
(zip).fmt.filename_len = SWAP_LE16((zip).fmt.filename_len); \
(zip).fmt.extra_len = SWAP_LE16((zip).fmt.extra_len ); \
}} while (0)
#define CDF_HEADER_LEN 42
@ -109,44 +130,44 @@ typedef union {
uint16_t version_needed; /* 2-3 */
uint16_t cdf_flags; /* 4-5 */
uint16_t method; /* 6-7 */
uint16_t mtime; /* 8-9 */
uint16_t mdate; /* 10-11 */
uint16_t modtime; /* 8-9 */
uint16_t moddate; /* 10-11 */
uint32_t crc32; /* 12-15 */
uint32_t cmpsize; /* 16-19 */
uint32_t ucmpsize; /* 20-23 */
uint16_t file_name_length; /* 24-25 */
uint16_t extra_field_length; /* 26-27 */
uint16_t filename_len; /* 24-25 */
uint16_t extra_len; /* 26-27 */
uint16_t file_comment_length; /* 28-29 */
uint16_t disk_number_start; /* 30-31 */
uint16_t internal_file_attributes; /* 32-33 */
uint32_t external_file_attributes PACKED; /* 34-37 */
uint16_t internal_attributes; /* 32-33 */
uint32_t external_attributes PACKED; /* 34-37 */
uint32_t relative_offset_of_local_header PACKED; /* 38-41 */
} formatted PACKED;
/* filename follows (not NUL terminated) */
/* extra field follows */
/* file comment follows */
} fmt PACKED;
} cdf_header_t;
struct BUG_cdf_header_must_be_42_bytes {
char BUG_cdf_header_must_be_42_bytes[
offsetof(cdf_header_t, formatted.relative_offset_of_local_header) + 4
== CDF_HEADER_LEN ? 1 : -1];
};
#define FIX_ENDIANNESS_CDF(cdf) \
do { if (BB_BIG_ENDIAN) { \
(cdf).fmt.version_made_by = SWAP_LE16((cdf).fmt.version_made_by); \
(cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed); \
(cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \
(cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \
(cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \
(cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \
(cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \
(cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \
(cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len); \
(cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \
(cdf).fmt.file_comment_length = SWAP_LE16((cdf).fmt.file_comment_length); \
(cdf).fmt.external_attributes = SWAP_LE32((cdf).fmt.external_attributes); \
}} while (0)
#define FIX_ENDIANNESS_CDF(cdf_header) do { \
(cdf_header).formatted.crc32 = SWAP_LE32((cdf_header).formatted.crc32 ); \
(cdf_header).formatted.cmpsize = SWAP_LE32((cdf_header).formatted.cmpsize ); \
(cdf_header).formatted.ucmpsize = SWAP_LE32((cdf_header).formatted.ucmpsize ); \
(cdf_header).formatted.file_name_length = SWAP_LE16((cdf_header).formatted.file_name_length); \
(cdf_header).formatted.extra_field_length = SWAP_LE16((cdf_header).formatted.extra_field_length); \
(cdf_header).formatted.file_comment_length = SWAP_LE16((cdf_header).formatted.file_comment_length); \
IF_DESKTOP( \
(cdf_header).formatted.version_made_by = SWAP_LE16((cdf_header).formatted.version_made_by); \
(cdf_header).formatted.external_file_attributes = SWAP_LE32((cdf_header).formatted.external_file_attributes); \
) \
} while (0)
#define CDE_HEADER_LEN 16
#define CDE_LEN 16
typedef union {
uint8_t raw[CDE_HEADER_LEN];
uint8_t raw[CDE_LEN];
struct {
/* uint32_t signature; 50 4b 05 06 */
uint16_t this_disk_no;
@ -155,25 +176,43 @@ typedef union {
uint16_t cdf_entries_total;
uint32_t cdf_size;
uint32_t cdf_offset;
/* uint16_t file_comment_length; */
/* .ZIP file comment (variable size) */
} formatted PACKED;
} cde_header_t;
/* uint16_t archive_comment_length; */
/* archive comment follows */
} fmt PACKED;
} cde_t;
struct BUG_cde_header_must_be_16_bytes {
char BUG_cde_header_must_be_16_bytes[
sizeof(cde_header_t) == CDE_HEADER_LEN ? 1 : -1];
#define FIX_ENDIANNESS_CDE(cde) \
do { if (BB_BIG_ENDIAN) { \
(cde).fmt.cdf_offset = SWAP_LE32((cde).fmt.cdf_offset); \
}} while (0)
struct BUG {
/* Check the offset of the last element, not the length. This leniency
* allows for poor packing, whereby the overall struct may be too long,
* even though the elements are all in the right place.
*/
char BUG_zip_header_must_be_26_bytes[
offsetof(zip_header_t, fmt.extra_len) + 2
== ZIP_HEADER_LEN ? 1 : -1];
char BUG_cdf_header_must_be_42_bytes[
offsetof(cdf_header_t, fmt.relative_offset_of_local_header) + 4
== CDF_HEADER_LEN ? 1 : -1];
char BUG_cde_must_be_16_bytes[
sizeof(cde_t) == CDE_LEN ? 1 : -1];
};
#define FIX_ENDIANNESS_CDE(cde_header) do { \
(cde_header).formatted.cdf_offset = SWAP_LE32((cde_header).formatted.cdf_offset); \
} while (0)
enum { zip_fd = 3 };
#if ENABLE_DESKTOP
/* This value means that we failed to find CDF */
#define BAD_CDF_OFFSET ((uint32_t)0xffffffff)
#if !ENABLE_FEATURE_UNZIP_CDF
# define find_cdf_offset() BAD_CDF_OFFSET
#else
/* Seen in the wild:
* Self-extracting PRO2K3XP_32.exe contains 19078464 byte zip archive,
* where CDE was nearly 48 kbytes before EOF.
@ -182,28 +221,31 @@ enum { zip_fd = 3 };
* To make extraction work, bumped PEEK_FROM_END from 16k to 64k.
*/
#define PEEK_FROM_END (64*1024)
/* This value means that we failed to find CDF */
#define BAD_CDF_OFFSET ((uint32_t)0xffffffff)
/* NB: does not preserve file position! */
static uint32_t find_cdf_offset(void)
{
cde_header_t cde_header;
cde_t cde;
unsigned char *buf;
unsigned char *p;
off_t end;
unsigned char *buf = xzalloc(PEEK_FROM_END);
uint32_t found;
end = lseek(zip_fd, 0, SEEK_END);
if (end == (off_t) -1)
return BAD_CDF_OFFSET;
end = xlseek(zip_fd, 0, SEEK_END);
end -= PEEK_FROM_END;
if (end < 0)
end = 0;
dbg("Looking for cdf_offset starting from 0x%"OFF_FMT"x", end);
xlseek(zip_fd, end, SEEK_SET);
buf = xzalloc(PEEK_FROM_END);
full_read(zip_fd, buf, PEEK_FROM_END);
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
found = BAD_CDF_OFFSET;
p = buf;
while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) {
while (p <= buf + PEEK_FROM_END - CDE_LEN - 4) {
if (*p != 'P') {
p++;
continue;
@ -215,41 +257,62 @@ static uint32_t find_cdf_offset(void)
if (*++p != 6)
continue;
/* we found CDE! */
memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN);
FIX_ENDIANNESS_CDE(cde_header);
memcpy(cde.raw, p + 1, CDE_LEN);
FIX_ENDIANNESS_CDE(cde);
/*
* I've seen .ZIP files with seemingly valid CDEs
* where cdf_offset points past EOF - ??
* Ignore such CDEs:
* This check ignores such CDEs:
*/
if (cde_header.formatted.cdf_offset < end + (p - buf))
break;
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
if (cde.fmt.cdf_offset < end + (p - buf)) {
found = cde.fmt.cdf_offset;
dbg("Possible cdf_offset:0x%x at 0x%"OFF_FMT"x",
(unsigned)found, end + (p-3 - buf));
dbg(" cdf_offset+cdf_size:0x%x",
(unsigned)(found + SWAP_LE32(cde.fmt.cdf_size)));
/*
* We do not "break" here because only the last CDE is valid.
* I've seen a .zip archive which contained a .zip file,
* uncompressed, and taking the first CDE was using
* the CDE inside that file!
*/
}
}
free(buf);
return cde_header.formatted.cdf_offset;
dbg("Found cdf_offset:0x%x", (unsigned)found);
return found;
};
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
{
off_t org;
uint32_t magic;
org = xlseek(zip_fd, 0, SEEK_CUR);
if (cdf_offset == BAD_CDF_OFFSET)
return cdf_offset;
if (!cdf_offset)
cdf_offset = find_cdf_offset();
if (cdf_offset != BAD_CDF_OFFSET) {
xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
FIX_ENDIANNESS_CDF(*cdf_ptr);
cdf_offset += 4 + CDF_HEADER_LEN
+ cdf_ptr->formatted.file_name_length
+ cdf_ptr->formatted.extra_field_length
+ cdf_ptr->formatted.file_comment_length;
dbg("Reading CDF at 0x%x", (unsigned)cdf_offset);
xlseek(zip_fd, cdf_offset, SEEK_SET);
xread(zip_fd, &magic, 4);
/* Central Directory End? Assume CDF has ended.
* (more correct method is to use cde.cdf_entries_total counter)
*/
if (magic == ZIP_CDE_MAGIC) {
dbg("got ZIP_CDE_MAGIC");
return 0; /* EOF */
}
xread(zip_fd, cdf->raw, CDF_HEADER_LEN);
FIX_ENDIANNESS_CDF(*cdf);
dbg(" filename_len:%u extra_len:%u file_comment_length:%u",
(unsigned)cdf->fmt.filename_len,
(unsigned)cdf->fmt.extra_len,
(unsigned)cdf->fmt.file_comment_length
);
cdf_offset += 4 + CDF_HEADER_LEN
+ cdf->fmt.filename_len
+ cdf->fmt.extra_len
+ cdf->fmt.file_comment_length;
xlseek(zip_fd, org, SEEK_SET);
return cdf_offset;
};
#endif
@ -271,32 +334,66 @@ static void unzip_create_leading_dirs(const char *fn)
free(name);
}
static void unzip_extract(zip_header_t *zip_header, int dst_fd)
static void unzip_extract(zip_header_t *zip, int dst_fd)
{
if (zip_header->formatted.method == 0) {
transformer_state_t xstate;
if (zip->fmt.method == 0) {
/* Method 0 - stored (not compressed) */
off_t size = zip_header->formatted.ucmpsize;
off_t size = zip->fmt.ucmpsize;
if (size)
bb_copyfd_exact_size(zip_fd, dst_fd, size);
} else {
return;
}
init_transformer_state(&xstate);
xstate.bytes_in = zip->fmt.cmpsize;
xstate.src_fd = zip_fd;
xstate.dst_fd = dst_fd;
if (zip->fmt.method == 8) {
/* Method 8 - inflate */
transformer_state_t xstate;
init_transformer_state(&xstate);
xstate.bytes_in = zip_header->formatted.cmpsize;
xstate.src_fd = zip_fd;
xstate.dst_fd = dst_fd;
if (inflate_unzip(&xstate) < 0)
bb_error_msg_and_die("inflate error");
/* Validate decompression - crc */
if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
if (zip->fmt.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
bb_error_msg_and_die("crc error");
}
/* Validate decompression - size */
if (zip_header->formatted.ucmpsize != xstate.bytes_out) {
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_error_msg("bad length");
}
}
#if ENABLE_FEATURE_UNZIP_BZIP2
else if (zip->fmt.method == 12) {
/* Tested. Unpacker reads too much, but we use CDF
* and will seek to the correct beginning of next file.
*/
xstate.bytes_out = unpack_bz2_stream(&xstate);
if (xstate.bytes_out < 0)
bb_error_msg_and_die("inflate error");
}
#endif
#if ENABLE_FEATURE_UNZIP_LZMA
else if (zip->fmt.method == 14) {
/* Not tested yet */
xstate.bytes_out = unpack_lzma_stream(&xstate);
if (xstate.bytes_out < 0)
bb_error_msg_and_die("inflate error");
}
#endif
#if ENABLE_FEATURE_UNZIP_XZ
else if (zip->fmt.method == 95) {
/* Not tested yet */
xstate.bytes_out = unpack_xz_stream(&xstate);
if (xstate.bytes_out < 0)
bb_error_msg_and_die("inflate error");
}
#endif
else {
bb_error_msg_and_die("unsupported method %u", zip->fmt.method);
}
/* Validate decompression - size */
if (zip->fmt.ucmpsize != xstate.bytes_out) {
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_error_msg("bad length");
}
}
@ -313,15 +410,12 @@ int unzip_main(int argc, char **argv)
{
enum { O_PROMPT, O_NEVER, O_ALWAYS };
zip_header_t zip_header;
smallint quiet = 0;
IF_NOT_DESKTOP(const) smallint verbose = 0;
IF_NOT_FEATURE_UNZIP_CDF(const) smallint verbose = 0;
smallint listing = 0;
smallint overwrite = O_PROMPT;
smallint x_opt_seen;
#if ENABLE_DESKTOP
uint32_t cdf_offset;
#endif
unsigned long total_usize;
unsigned long total_size;
unsigned total_entries;
@ -404,7 +498,7 @@ int unzip_main(int argc, char **argv)
break;
case 'v': /* Verbose list */
IF_DESKTOP(verbose++;)
IF_FEATURE_UNZIP_CDF(verbose++;)
listing = 1;
break;
@ -461,7 +555,7 @@ int unzip_main(int argc, char **argv)
if (overwrite == O_PROMPT)
overwrite = O_NEVER;
} else {
static const char extn[][5] = { ".zip", ".ZIP" };
static const char extn[][5] ALIGN1 = { ".zip", ".ZIP" };
char *ext = src_fn + strlen(src_fn);
int src_fd;
@ -488,11 +582,11 @@ int unzip_main(int argc, char **argv)
printf("Archive: %s\n", src_fn);
if (listing) {
puts(verbose ?
" Length Method Size Ratio Date Time CRC-32 Name\n"
"-------- ------ ------- ----- ---- ---- ------ ----"
" Length Method Size Cmpr Date Time CRC-32 Name\n"
"-------- ------ ------- ---- ---------- ----- -------- ----"
:
" Length Date Time Name\n"
" -------- ---- ---- ----"
" Length Date Time Name\n"
"--------- ---------- ----- ----"
);
}
}
@ -519,82 +613,114 @@ int unzip_main(int argc, char **argv)
total_usize = 0;
total_size = 0;
total_entries = 0;
#if ENABLE_DESKTOP
cdf_offset = 0;
#endif
cdf_offset = find_cdf_offset(); /* try to seek to the end, find CDE and CDF start */
while (1) {
uint32_t magic;
zip_header_t zip;
mode_t dir_mode = 0777;
#if ENABLE_DESKTOP
#if ENABLE_FEATURE_UNZIP_CDF
mode_t file_mode = 0666;
#endif
/* Check magic number */
xread(zip_fd, &magic, 4);
/* Central directory? It's at the end, so exit */
if (magic == ZIP_CDF_MAGIC)
break;
#if ENABLE_DESKTOP
/* Data descriptor? It was a streaming file, go on */
if (magic == ZIP_DD_MAGIC) {
/* skip over duplicate crc32, cmpsize and ucmpsize */
unzip_skip(3 * 4);
continue;
}
#endif
if (magic != ZIP_FILEHEADER_MAGIC)
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
/* Read the file header */
xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN);
FIX_ENDIANNESS_ZIP(zip_header);
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
}
#if !ENABLE_DESKTOP
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0009)) {
bb_error_msg_and_die("zip flags 1 and 8 are not supported");
}
#else
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0001)) {
/* 0x0001 - encrypted */
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
}
if (cdf_offset != BAD_CDF_OFFSET) {
cdf_header_t cdf_header;
cdf_offset = read_next_cdf(cdf_offset, &cdf_header);
/*
* Note: cdf_offset can become BAD_CDF_OFFSET after the above call.
if (!ENABLE_FEATURE_UNZIP_CDF || cdf_offset == BAD_CDF_OFFSET) {
/* Normally happens when input is unseekable.
*
* Valid ZIP file has Central Directory at the end
* with central directory file headers (CDFs).
* After it, there is a Central Directory End structure.
* CDFs identify what files are in the ZIP and where
* they are located. This allows ZIP readers to load
* the list of files without reading the entire ZIP archive.
* ZIP files may be appended to, only files specified in
* the CD are valid. Scanning for local file headers is
* not a correct algorithm.
*
* We try to do the above, and resort to "linear" reading
* of ZIP file only if seek failed or CDE wasn't found.
*/
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0008)) {
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
* only from Central Directory. See unzip_doc.txt
*/
zip_header.formatted.crc32 = cdf_header.formatted.crc32;
zip_header.formatted.cmpsize = cdf_header.formatted.cmpsize;
zip_header.formatted.ucmpsize = cdf_header.formatted.ucmpsize;
uint32_t magic;
/* Check magic number */
xread(zip_fd, &magic, 4);
/* CDF item? Assume there are no more files, exit */
if (magic == ZIP_CDF_MAGIC) {
dbg("got ZIP_CDF_MAGIC");
break;
}
if ((cdf_header.formatted.version_made_by >> 8) == 3) {
/* This archive is created on Unix */
dir_mode = file_mode = (cdf_header.formatted.external_file_attributes >> 16);
/* Data descriptor? It was a streaming file, go on */
if (magic == ZIP_DD_MAGIC) {
dbg("got ZIP_DD_MAGIC");
/* skip over duplicate crc32, cmpsize and ucmpsize */
unzip_skip(3 * 4);
continue;
}
if (magic != ZIP_FILEHEADER_MAGIC)
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
dbg("got ZIP_FILEHEADER_MAGIC");
xread(zip_fd, zip.raw, ZIP_HEADER_LEN);
FIX_ENDIANNESS_ZIP(zip);
if (zip.fmt.zip_flags & SWAP_LE16(0x0008)) {
bb_error_msg_and_die("zip flag %s is not supported",
"8 (streaming)");
}
}
if (cdf_offset == BAD_CDF_OFFSET
&& (zip_header.formatted.zip_flags & SWAP_LE16(0x0008))
) {
/* If it's a streaming zip, we _require_ CDF */
bb_error_msg_and_die("can't find file table");
#if ENABLE_FEATURE_UNZIP_CDF
else {
/* cdf_offset is valid (and we know the file is seekable) */
cdf_header_t cdf;
cdf_offset = read_next_cdf(cdf_offset, &cdf);
if (cdf_offset == 0) /* EOF? */
break;
# if 1
xlseek(zip_fd,
SWAP_LE32(cdf.fmt.relative_offset_of_local_header) + 4,
SEEK_SET);
xread(zip_fd, zip.raw, ZIP_HEADER_LEN);
FIX_ENDIANNESS_ZIP(zip);
if (zip.fmt.zip_flags & SWAP_LE16(0x0008)) {
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
* only from Central Directory.
*/
zip.fmt.crc32 = cdf.fmt.crc32;
zip.fmt.cmpsize = cdf.fmt.cmpsize;
zip.fmt.ucmpsize = cdf.fmt.ucmpsize;
}
# else
/* CDF has the same data as local header, no need to read the latter...
* ...not really. An archive was seen with cdf.extra_len == 6 but
* zip.extra_len == 0.
*/
memcpy(&zip.fmt.version,
&cdf.fmt.version_needed, ZIP_HEADER_LEN);
xlseek(zip_fd,
SWAP_LE32(cdf.fmt.relative_offset_of_local_header) + 4 + ZIP_HEADER_LEN,
SEEK_SET);
# endif
if ((cdf.fmt.version_made_by >> 8) == 3) {
/* This archive is created on Unix */
dir_mode = file_mode = (cdf.fmt.external_attributes >> 16);
}
}
#endif
if (zip.fmt.zip_flags & SWAP_LE16(0x0001)) {
/* 0x0001 - encrypted */
bb_error_msg_and_die("zip flag %s is not supported",
"1 (encryption)");
}
dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x",
(unsigned)zip.fmt.cmpsize,
(unsigned)zip.fmt.extra_len,
(unsigned)zip.fmt.ucmpsize
);
/* Read filename */
free(dst_fn);
dst_fn = xzalloc(zip_header.formatted.filename_len + 1);
xread(zip_fd, dst_fn, zip_header.formatted.filename_len);
dst_fn = xzalloc(zip.fmt.filename_len + 1);
xread(zip_fd, dst_fn, zip.fmt.filename_len);
/* Skip extra header bytes */
unzip_skip(zip_header.formatted.extra_len);
unzip_skip(zip.fmt.extra_len);
/* Guard against "/abspath", "/../" and similar attacks */
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
@ -603,114 +729,129 @@ int unzip_main(int argc, char **argv)
if (find_list_entry(zreject, dst_fn)
|| (zaccept && !find_list_entry(zaccept, dst_fn))
) { /* Skip entry */
i = 'n';
} else {
if (listing) {
/* List entry */
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
if (!verbose) {
// " Length Date Time Name\n"
// " -------- ---- ---- ----"
printf( "%9u %02u-%02u-%02u %02u:%02u %s\n",
(unsigned)zip_header.formatted.ucmpsize,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
dst_fn);
total_usize += zip_header.formatted.ucmpsize;
} else {
unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize;
percents = percents * 100;
if (zip_header.formatted.ucmpsize)
percents /= zip_header.formatted.ucmpsize;
// " Length Method Size Ratio Date Time CRC-32 Name\n"
// "-------- ------ ------- ----- ---- ---- ------ ----"
printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n",
(unsigned)zip_header.formatted.ucmpsize,
(unsigned)zip_header.formatted.cmpsize,
(unsigned)percents,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
zip_header.formatted.crc32,
dst_fn);
total_usize += zip_header.formatted.ucmpsize;
total_size += zip_header.formatted.cmpsize;
}
i = 'n';
} else if (dst_fd == STDOUT_FILENO) {
/* Extracting to STDOUT */
i = -1;
} else if (last_char_is(dst_fn, '/')) {
/* Extract directory */
if (stat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
if (!quiet) {
printf(" creating: %s\n", dst_fn);
}
unzip_create_leading_dirs(dst_fn);
if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
xfunc_die();
}
} else {
if (!S_ISDIR(stat_buf.st_mode)) {
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "directory");
}
}
i = 'n';
} else {
/* Extract file */
check_file:
if (stat(dst_fn, &stat_buf) == -1) {
/* File does not exist */
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
i = 'y';
} else {
/* File already exists */
if (overwrite == O_NEVER) {
i = 'n';
} else if (S_ISREG(stat_buf.st_mode)) {
/* File is regular file */
if (overwrite == O_ALWAYS) {
i = 'y';
} else {
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
my_fgets80(key_buf);
i = key_buf[0];
}
} else {
/* File is not regular file */
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "regular file");
}
}
}
goto skip_cmpsize;
}
switch (i) {
if (listing) {
/* List entry */
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
(zip.fmt.moddate >> 5) & 0xf, // mm: 0x01e0
(zip.fmt.moddate) & 0x1f, // dd: 0x001f
(zip.fmt.moddate >> 9) + 1980, // yy: 0xfe00
(zip.fmt.modtime >> 11), // hh: 0xf800
(zip.fmt.modtime >> 5) & 0x3f // mm: 0x07e0
// seconds/2 not shown, encoded in -- 0x001f
);
if (!verbose) {
// " Length Date Time Name\n"
// "--------- ---------- ----- ----"
printf( "%9u " "%s " "%s\n",
(unsigned)zip.fmt.ucmpsize,
dtbuf,
dst_fn);
} else {
char method6[7];
unsigned long percents;
sprintf(method6, "%6u", zip.fmt.method);
if (zip.fmt.method == 0) {
strcpy(method6, "Stored");
}
if (zip.fmt.method == 8) {
strcpy(method6, "Defl:N");
/* normal, maximum, fast, superfast */
IF_DESKTOP(method6[5] = "NXFS"[(zip.fmt.zip_flags >> 1) & 3];)
}
percents = zip.fmt.ucmpsize - zip.fmt.cmpsize;
if ((int32_t)percents < 0)
percents = 0; /* happens if ucmpsize < cmpsize */
percents = percents * 100;
if (zip.fmt.ucmpsize)
percents /= zip.fmt.ucmpsize;
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
// "-------- ------ ------- ---- ---------- ----- -------- ----"
printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
(unsigned)zip.fmt.ucmpsize,
method6,
(unsigned)zip.fmt.cmpsize,
(unsigned)percents,
dtbuf,
zip.fmt.crc32,
dst_fn);
total_size += zip.fmt.cmpsize;
}
total_usize += zip.fmt.ucmpsize;
goto skip_cmpsize;
}
if (dst_fd == STDOUT_FILENO) {
/* Extracting to STDOUT */
goto do_extract;
}
if (last_char_is(dst_fn, '/')) {
/* Extract directory */
if (stat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
if (!quiet) {
printf(" creating: %s\n", dst_fn);
}
unzip_create_leading_dirs(dst_fn);
if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
xfunc_die();
}
} else {
if (!S_ISDIR(stat_buf.st_mode)) {
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "directory");
}
}
goto skip_cmpsize;
}
check_file:
/* Extract file */
if (stat(dst_fn, &stat_buf) == -1) {
/* File does not exist */
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
goto do_open_and_extract;
}
/* File already exists */
if (overwrite == O_NEVER) {
goto skip_cmpsize;
}
if (!S_ISREG(stat_buf.st_mode)) {
/* File is not regular file */
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "regular file");
}
/* File is regular file */
if (overwrite == O_ALWAYS)
goto do_open_and_extract;
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
my_fgets80(key_buf);
switch (key_buf[0]) {
case 'A':
overwrite = O_ALWAYS;
case 'y': /* Open file and fall into unzip */
do_open_and_extract:
unzip_create_leading_dirs(dst_fn);
#if ENABLE_DESKTOP
#if ENABLE_FEATURE_UNZIP_CDF
dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode);
#else
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
#endif
case -1: /* Unzip */
do_extract:
if (!quiet) {
printf(" inflating: %s\n", dst_fn);
printf(/* zip.fmt.method == 0
? " extracting: %s\n"
: */ " inflating: %s\n", dst_fn);
}
unzip_extract(&zip_header, dst_fd);
unzip_extract(&zip, dst_fd);
if (dst_fd != STDOUT_FILENO) {
/* closing STDOUT is potentially bad for future business */
close(dst_fd);
@ -719,9 +860,9 @@ int unzip_main(int argc, char **argv)
case 'N':
overwrite = O_NEVER;
case 'n':
/* Skip entry data */
unzip_skip(zip_header.formatted.cmpsize);
case 'n': /* Skip entry data */
skip_cmpsize:
unzip_skip(zip.fmt.cmpsize);
break;
case 'r':
@ -734,7 +875,7 @@ int unzip_main(int argc, char **argv)
goto check_file;
default:
printf("error: invalid response [%c]\n", (char)i);
printf("error: invalid response [%c]\n", (char)key_buf[0]);
goto check_file;
}
@ -743,21 +884,25 @@ int unzip_main(int argc, char **argv)
if (listing && quiet <= 1) {
if (!verbose) {
// " Length Date Time Name\n"
// " -------- ---- ---- ----"
printf( " -------- -------\n"
"%9lu" " %u files\n",
total_usize, total_entries);
// " Length Date Time Name\n"
// "--------- ---------- ----- ----"
printf( " --------%21s" "-------\n"
"%9lu%21s" "%u files\n",
"",
total_usize, "", total_entries);
} else {
unsigned long percents = total_usize - total_size;
if ((long)percents < 0)
percents = 0; /* happens if usize < size */
percents = percents * 100;
if (total_usize)
percents /= total_usize;
// " Length Method Size Ratio Date Time CRC-32 Name\n"
// "-------- ------ ------- ----- ---- ---- ------ ----"
printf( "-------- ------- --- -------\n"
"%8lu" "%17lu%4u%% %u files\n",
total_usize, total_size, (unsigned)percents,
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
// "-------- ------ ------- ---- ---------- ----- -------- ----"
printf( "-------- ------- ----%28s" "----\n"
"%8lu" "%17lu%4u%%%28s" "%u files\n",
"",
total_usize, total_size, (unsigned)percents, "",
total_entries);
}
}

View File

@ -118,7 +118,6 @@ CONFIG_FEATURE_CPIO_O=y
CONFIG_FEATURE_CPIO_P=y
CONFIG_DPKG=y
CONFIG_DPKG_DEB=y
CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY=y
CONFIG_GUNZIP=y
CONFIG_GZIP=y
CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
@ -266,11 +265,6 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@ -388,9 +382,9 @@ CONFIG_FEATURE_KILL_REMOVED=y
CONFIG_FEATURE_KILL_DELAY=1
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_HALT=y
# CONFIG_FEATURE_CALL_TELINIT is not set
CONFIG_TELINIT_PATH=""
@ -458,15 +452,12 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
CONFIG_FEATURE_INSMOD_TRY_MMAP=y
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@ -525,7 +516,6 @@ CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
CONFIG_MKSWAP=y
CONFIG_FEATURE_MKSWAP_UUID=y
CONFIG_MORE=y
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_VOLUMEID=y
CONFIG_FEATURE_VOLUMEID_EXT=y
CONFIG_FEATURE_VOLUMEID_BTRFS=y
@ -760,7 +750,6 @@ CONFIG_TFTP_DEBUG=y
CONFIG_TRACEROUTE=y
CONFIG_TRACEROUTE6=y
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE=y
CONFIG_FEATURE_TRACEROUTE_USE_ICMP=y
CONFIG_UDHCPD=y
CONFIG_DHCPRELAY=y
@ -881,9 +870,9 @@ CONFIG_FEATURE_SH_IS_HUSH=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set

View File

@ -130,7 +130,6 @@ CONFIG_FEATURE_SEAMLESS_Z=y
# CONFIG_FEATURE_CPIO_P is not set
# CONFIG_DPKG is not set
# CONFIG_DPKG_DEB is not set
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
# CONFIG_GUNZIP is not set
# CONFIG_GZIP is not set
# CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
@ -278,7 +277,6 @@ CONFIG_TRUE=y
# CONFIG_WHOAMI is not set
# CONFIG_YES is not set
# CONFIG_FEATURE_PRESERVE_HARDLINKS is not set
# CONFIG_FEATURE_AUTOWIDTH is not set
# CONFIG_FEATURE_HUMAN_READABLE is not set
# CONFIG_FEATURE_MD5_SHA1_SUM_CHECK is not set
@ -393,9 +391,9 @@ CONFIG_FEATURE_VI_MAX_LEN=0
CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SCTTY is not set
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_FEATURE_INITRD is not set
# CONFIG_LINUXRC is not set
# CONFIG_HALT is not set
# CONFIG_FEATURE_CALL_TELINIT is not set
CONFIG_TELINIT_PATH=""
@ -528,7 +526,6 @@ CONFIG_FDISK_SUPPORT_LARGE_DISKS=y
# CONFIG_MKSWAP is not set
# CONFIG_FEATURE_MKSWAP_UUID is not set
# CONFIG_MORE is not set
# CONFIG_FEATURE_USE_TERMIOS is not set
CONFIG_VOLUMEID=y
# CONFIG_FEATURE_VOLUMEID_EXT is not set
# CONFIG_FEATURE_VOLUMEID_BTRFS is not set
@ -762,7 +759,6 @@ CONFIG_IFUPDOWN_IFSTATE_PATH=""
# CONFIG_TRACEROUTE is not set
# CONFIG_TRACEROUTE6 is not set
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
# CONFIG_TUNCTL is not set
# CONFIG_FEATURE_TUNCTL_UG is not set
@ -875,9 +871,9 @@ CONFIG_SV_DEFAULT_SERVICE_DIR=""
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set

View File

@ -128,7 +128,6 @@ CONFIG_FEATURE_CPIO_O=y
CONFIG_FEATURE_CPIO_P=y
# CONFIG_DPKG is not set
# CONFIG_DPKG_DEB is not set
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
CONFIG_GUNZIP=y
CONFIG_GZIP=y
CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
@ -277,11 +276,6 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@ -405,9 +399,9 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_HALT=y
# CONFIG_FEATURE_CALL_TELINIT is not set
CONFIG_TELINIT_PATH=""
@ -473,15 +467,12 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@ -541,7 +532,6 @@ CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
CONFIG_MKSWAP=y
CONFIG_FEATURE_MKSWAP_UUID=y
CONFIG_MORE=y
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_VOLUMEID=y
CONFIG_FEATURE_VOLUMEID_EXT=y
CONFIG_FEATURE_VOLUMEID_BTRFS=y
@ -778,7 +768,6 @@ CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
CONFIG_TRACEROUTE=y
CONFIG_TRACEROUTE6=y
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
CONFIG_TUNCTL=y
CONFIG_FEATURE_TUNCTL_UG=y
@ -895,9 +884,9 @@ CONFIG_ASH_BASH_COMPAT=y
CONFIG_ASH_JOB_CONTROL=y
CONFIG_ASH_ALIAS=y
CONFIG_ASH_GETOPTS=y
CONFIG_ASH_BUILTIN_ECHO=y
CONFIG_ASH_BUILTIN_PRINTF=y
CONFIG_ASH_BUILTIN_TEST=y
CONFIG_ASH_ECHO=y
CONFIG_ASH_PRINTF=y
CONFIG_ASH_TEST=y
CONFIG_ASH_CMDCMD=y
# CONFIG_ASH_MAIL is not set
CONFIG_ASH_OPTIMIZE_FOR_SIZE=y

View File

@ -89,13 +89,11 @@ CONFIG_PREFIX="./_install"
#
# Busybox Library Tuning
#
# CONFIG_FEATURE_SYSTEMD is not set
# CONFIG_FEATURE_RTMINMAX is not set
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
# CONFIG_FEATURE_FAST_TOP is not set
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
# CONFIG_FEATURE_EDITING is not set
CONFIG_FEATURE_EDITING_MAX_LEN=0
# CONFIG_FEATURE_EDITING_VI is not set
@ -135,7 +133,6 @@ CONFIG_FEATURE_CPIO_O=y
CONFIG_FEATURE_CPIO_P=y
CONFIG_DPKG=y
CONFIG_DPKG_DEB=y
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
CONFIG_GUNZIP=y
CONFIG_GZIP=y
# CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
@ -291,11 +288,6 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@ -424,9 +416,9 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
CONFIG_MESG=y
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
@ -495,15 +487,12 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@ -815,7 +804,6 @@ CONFIG_TCPSVD=y
# CONFIG_TRACEROUTE is not set
# CONFIG_TRACEROUTE6 is not set
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
CONFIG_TUNCTL=y
CONFIG_FEATURE_TUNCTL_UG=y
@ -939,9 +927,9 @@ CONFIG_SOFTLIMIT=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set

File diff suppressed because it is too large Load Diff

View File

@ -107,13 +107,11 @@ CONFIG_PREFIX="./_install"
#
# Busybox Library Tuning
#
# CONFIG_FEATURE_SYSTEMD is not set
# CONFIG_FEATURE_RTMINMAX is not set
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
# CONFIG_FEATURE_FAST_TOP is not set
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
# CONFIG_FEATURE_EDITING is not set
CONFIG_FEATURE_EDITING_MAX_LEN=0
# CONFIG_FEATURE_EDITING_VI is not set
@ -155,7 +153,6 @@ CONFIG_FEATURE_CPIO_O=y
CONFIG_FEATURE_CPIO_P=y
CONFIG_DPKG=y
CONFIG_DPKG_DEB=y
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
CONFIG_GUNZIP=y
CONFIG_GZIP=y
# CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
@ -314,11 +311,6 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@ -447,9 +439,9 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
CONFIG_MESG=y
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
@ -519,15 +511,12 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@ -844,7 +833,6 @@ CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
CONFIG_TRACEROUTE=y
# CONFIG_TRACEROUTE6 is not set
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
CONFIG_TUNCTL=y
CONFIG_FEATURE_TUNCTL_UG=y
@ -971,9 +959,9 @@ CONFIG_SOFTLIMIT=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set

View File

@ -96,14 +96,12 @@ CONFIG_PREFIX="./_install"
#
# Busybox Library Tuning
#
# CONFIG_FEATURE_SYSTEMD is not set
# CONFIG_FEATURE_RTMINMAX is not set
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
CONFIG_SHA3_SMALL=1
# CONFIG_FEATURE_FAST_TOP is not set
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
# CONFIG_FEATURE_EDITING is not set
CONFIG_FEATURE_EDITING_MAX_LEN=0
# CONFIG_FEATURE_EDITING_VI is not set
@ -152,7 +150,6 @@ CONFIG_FEATURE_CPIO_O=y
CONFIG_FEATURE_CPIO_P=y
CONFIG_DPKG=y
CONFIG_DPKG_DEB=y
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
CONFIG_GZIP=y
# CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
CONFIG_GZIP_FAST=0
@ -318,11 +315,6 @@ CONFIG_FEATURE_VERBOSE=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@ -457,9 +449,9 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
CONFIG_MESG=y
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
@ -530,15 +522,12 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/system/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@ -870,7 +859,6 @@ CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
CONFIG_TRACEROUTE=y
# CONFIG_TRACEROUTE6 is not set
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
CONFIG_TUNCTL=y
CONFIG_FEATURE_TUNCTL_UG=y
@ -999,9 +987,9 @@ CONFIG_SOFTLIMIT=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_HELP is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set

View File

@ -89,13 +89,11 @@ CONFIG_PREFIX="./_install"
#
# Busybox Library Tuning
#
# CONFIG_FEATURE_SYSTEMD is not set
CONFIG_FEATURE_RTMINMAX=y
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
CONFIG_FEATURE_FAST_TOP=y
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_FEATURE_EDITING=y
CONFIG_FEATURE_EDITING_MAX_LEN=1024
# CONFIG_FEATURE_EDITING_VI is not set
@ -135,7 +133,6 @@ CONFIG_FEATURE_CPIO_O=y
CONFIG_FEATURE_CPIO_P=y
# CONFIG_DPKG is not set
# CONFIG_DPKG_DEB is not set
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
CONFIG_GUNZIP=y
CONFIG_GZIP=y
CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
@ -291,11 +288,6 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@ -424,9 +416,9 @@ CONFIG_TELINIT_PATH=""
CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SCTTY is not set
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_FEATURE_INITRD is not set
# CONFIG_LINUXRC is not set
CONFIG_INIT_TERMINAL_TYPE=""
CONFIG_MESG=y
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
@ -815,7 +807,6 @@ CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
# CONFIG_TRACEROUTE is not set
# CONFIG_TRACEROUTE6 is not set
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
# CONFIG_TUNCTL is not set
# CONFIG_FEATURE_TUNCTL_UG is not set
@ -939,9 +930,9 @@ CONFIG_ASH_BASH_COMPAT=y
CONFIG_ASH_JOB_CONTROL=y
CONFIG_ASH_ALIAS=y
CONFIG_ASH_GETOPTS=y
CONFIG_ASH_BUILTIN_ECHO=y
CONFIG_ASH_BUILTIN_PRINTF=y
CONFIG_ASH_BUILTIN_TEST=y
CONFIG_ASH_ECHO=y
CONFIG_ASH_PRINTF=y
CONFIG_ASH_TEST=y
CONFIG_ASH_CMDCMD=y
# CONFIG_ASH_MAIL is not set
CONFIG_ASH_OPTIMIZE_FOR_SIZE=y

View File

@ -93,7 +93,6 @@ CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
CONFIG_FEATURE_FAST_TOP=y
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_FEATURE_EDITING=y
CONFIG_FEATURE_EDITING_MAX_LEN=1024
# CONFIG_FEATURE_EDITING_VI is not set
@ -132,7 +131,6 @@ CONFIG_CPIO=y
# CONFIG_FEATURE_CPIO_P is not set
# CONFIG_DPKG is not set
# CONFIG_DPKG_DEB is not set
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
CONFIG_GUNZIP=y
CONFIG_GZIP=y
CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
@ -288,11 +286,6 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@ -420,9 +413,9 @@ CONFIG_TELINIT_PATH=""
CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SCTTY is not set
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_FEATURE_INITRD is not set
# CONFIG_LINUXRC is not set
CONFIG_INIT_TERMINAL_TYPE=""
# CONFIG_MESG is not set
@ -795,7 +788,6 @@ CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
# CONFIG_TRACEROUTE is not set
# CONFIG_TRACEROUTE6 is not set
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
# CONFIG_TUNCTL is not set
# CONFIG_FEATURE_TUNCTL_UG is not set
@ -914,9 +906,9 @@ CONFIG_ASH=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set

View File

@ -7,170 +7,4 @@ menu "Console Utilities"
INSERT
config CHVT
bool "chvt"
default y
select PLATFORM_LINUX
help
This program is used to change to another terminal.
Example: chvt 4 (change to terminal /dev/tty4)
config FGCONSOLE
bool "fgconsole"
default y
select PLATFORM_LINUX
help
This program prints active (foreground) console number.
config CLEAR
bool "clear"
default y
help
This program clears the terminal screen.
config DEALLOCVT
bool "deallocvt"
default y
select PLATFORM_LINUX
help
This program deallocates unused virtual consoles.
config DUMPKMAP
bool "dumpkmap"
default y
select PLATFORM_LINUX
help
This program dumps the kernel's keyboard translation table to
stdout, in binary format. You can then use loadkmap to load it.
config KBD_MODE
bool "kbd_mode"
default y
select PLATFORM_LINUX
help
This program reports and sets keyboard mode.
config LOADFONT
bool "loadfont"
default y
select PLATFORM_LINUX
help
This program loads a console font from standard input.
config LOADKMAP
bool "loadkmap"
default y
select PLATFORM_LINUX
help
This program loads a keyboard translation table from
standard input.
config OPENVT
bool "openvt"
default y
select PLATFORM_LINUX
help
This program is used to start a command on an unused
virtual terminal.
config RESET
bool "reset"
default y
help
This program is used to reset the terminal screen, if it
gets messed up.
config RESIZE
bool "resize"
default y
help
This program is used to (re)set the width and height of your current
terminal.
config FEATURE_RESIZE_PRINT
bool "Print environment variables"
default y
depends on RESIZE
help
Prints the newly set size (number of columns and rows) of
the terminal.
E.g.:
COLUMNS=80;LINES=44;export COLUMNS LINES;
config SETCONSOLE
bool "setconsole"
default y
select PLATFORM_LINUX
help
This program redirects the system console to another device,
like the current tty while logged in via telnet.
config FEATURE_SETCONSOLE_LONG_OPTIONS
bool "Enable long options"
default y
depends on SETCONSOLE && LONG_OPTS
help
Support long options for the setconsole applet.
config SETFONT
bool "setfont"
default y
select PLATFORM_LINUX
help
Allows to load console screen map. Useful for i18n.
config FEATURE_SETFONT_TEXTUAL_MAP
bool "Support reading textual screen maps"
default y
depends on SETFONT
help
Support reading textual screen maps.
config DEFAULT_SETFONT_DIR
string "Default directory for console-tools files"
default ""
depends on SETFONT
help
Directory to use if setfont's params are simple filenames
(not /path/to/file or ./file). Default is "" (no default directory).
config SETKEYCODES
bool "setkeycodes"
default y
select PLATFORM_LINUX
help
This program loads entries into the kernel's scancode-to-keycode
map, allowing unusual keyboards to generate usable keycodes.
config SETLOGCONS
bool "setlogcons"
default y
select PLATFORM_LINUX
help
This program redirects the output console of kernel messages.
config SHOWKEY
bool "showkey"
default y
select PLATFORM_LINUX
help
Shows keys pressed.
comment "Common options for loadfont and setfont"
depends on LOADFONT || SETFONT
config FEATURE_LOADFONT_PSF2
bool "Support for PSF2 console fonts"
default y
depends on LOADFONT || SETFONT
help
Support PSF2 console fonts.
config FEATURE_LOADFONT_RAW
bool "Support for old (raw) console fonts"
default y
depends on LOADFONT || SETFONT
help
Support old (raw) console fonts.
endmenu

View File

@ -7,19 +7,3 @@
lib-y:=
INSERT
lib-$(CONFIG_CHVT) += chvt.o
lib-$(CONFIG_FGCONSOLE) += fgconsole.o
lib-$(CONFIG_CLEAR) += clear.o
lib-$(CONFIG_DEALLOCVT) += deallocvt.o
lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
lib-$(CONFIG_SETCONSOLE) += setconsole.o
lib-$(CONFIG_KBD_MODE) += kbd_mode.o
lib-$(CONFIG_LOADFONT) += loadfont.o
lib-$(CONFIG_LOADKMAP) += loadkmap.o
lib-$(CONFIG_OPENVT) += openvt.o
lib-$(CONFIG_RESET) += reset.o
lib-$(CONFIG_RESIZE) += resize.o
lib-$(CONFIG_SETFONT) += loadfont.o
lib-$(CONFIG_SETKEYCODES) += setkeycodes.o
lib-$(CONFIG_SETLOGCONS) += setlogcons.o
lib-$(CONFIG_SHOWKEY) += showkey.o

View File

@ -6,6 +6,17 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHVT
//config: bool "chvt"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program is used to change to another terminal.
//config: Example: chvt 4 (change to terminal /dev/tty4)
//applet:IF_CHVT(APPLET(chvt, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CHVT) += chvt.o
//usage:#define chvt_trivial_usage
//usage: "N"

View File

@ -6,6 +6,15 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CLEAR
//config: bool "clear"
//config: default y
//config: help
//config: This program clears the terminal screen.
//applet:IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CLEAR) += clear.o
//usage:#define clear_trivial_usage
//usage: ""

View File

@ -7,8 +7,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DEALLOCVT
//config: bool "deallocvt"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program deallocates unused virtual consoles.
/* no options, no getopt */
//applet:IF_DEALLOCVT(APPLET(deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DEALLOCVT) += deallocvt.o
//usage:#define deallocvt_trivial_usage
//usage: "[N]"

View File

@ -7,7 +7,17 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*
*/
/* no options, no getopt */
//config:config DUMPKMAP
//config: bool "dumpkmap"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program dumps the kernel's keyboard translation table to
//config: stdout, in binary format. You can then use loadkmap to load it.
//applet:IF_DUMPKMAP(APPLET(dumpkmap, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
//usage:#define dumpkmap_trivial_usage
//usage: "> keymap"
@ -18,6 +28,7 @@
//usage: "$ dumpkmap > keymap\n"
#include "libbb.h"
#include "common_bufsiz.h"
/* From <linux/kd.h> */
struct kbentry {
@ -37,6 +48,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
struct kbentry ke;
int i, j, fd;
#define flags bb_common_bufsiz1
setup_common_bufsiz();
/* When user accidentally runs "dumpkmap FILE"
* instead of "dumpkmap >FILE", we'd dump binary stuff to tty.

View File

@ -6,6 +6,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FGCONSOLE
//config: bool "fgconsole"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program prints active (foreground) console number.
//applet:IF_FGCONSOLE(APPLET(fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_FGCONSOLE) += fgconsole.o
//usage:#define fgconsole_trivial_usage
//usage: ""

View File

@ -8,6 +8,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config KBD_MODE
//config: bool "kbd_mode"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program reports and sets keyboard mode.
//applet:IF_KBD_MODE(APPLET(kbd_mode, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_KBD_MODE) += kbd_mode.o
//usage:#define kbd_mode_trivial_usage
//usage: "[-a|k|s|u] [-C TTY]"

View File

@ -9,6 +9,53 @@
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config LOADFONT
//config: bool "loadfont"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads a console font from standard input.
//config:
//config:config SETFONT
//config: bool "setfont"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Allows to load console screen map. Useful for i18n.
//config:
//config:config FEATURE_SETFONT_TEXTUAL_MAP
//config: bool "Support reading textual screen maps"
//config: default y
//config: depends on SETFONT
//config: help
//config: Support reading textual screen maps.
//config:
//config:config DEFAULT_SETFONT_DIR
//config: string "Default directory for console-tools files"
//config: default ""
//config: depends on SETFONT
//config: help
//config: Directory to use if setfont's params are simple filenames
//config: (not /path/to/file or ./file). Default is "" (no default directory).
//config:
//config:comment "Common options for loadfont and setfont"
//config: depends on LOADFONT || SETFONT
//config:
//config:config FEATURE_LOADFONT_PSF2
//config: bool "Support PSF2 console fonts"
//config: default y
//config: depends on LOADFONT || SETFONT
//config:
//config:config FEATURE_LOADFONT_RAW
//config: bool "Support old (raw) console fonts"
//config: default y
//config: depends on LOADFONT || SETFONT
//applet:IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
//applet:IF_SETFONT(APPLET(setfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_LOADFONT) += loadfont.o
//kbuild:lib-$(CONFIG_SETFONT) += loadfont.o
//usage:#define loadfont_trivial_usage
//usage: "< font"
@ -319,8 +366,10 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
* We used to look at the length of the input file
* with stat(); now that we accept compressed files,
* just read the entire file.
* Len was 32k, but latarcyrheb-sun32.psfu is 34377 bytes
* (it has largish Unicode map).
*/
len = 32*1024; // can't be larger
len = 128*1024;
buffer = xmalloc_read(STDIN_FILENO, &len);
// xmalloc_open_zipped_read_close(filename, &len);
if (!buffer)
@ -405,7 +454,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
}
}
// load font
len = 32*1024; // can't be larger
len = 128*1024;
buffer = xmalloc_open_zipped_read_close(*argv, &len);
if (!buffer)
bb_simple_perror_msg_and_die(*argv);

View File

@ -6,6 +6,17 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config LOADKMAP
//config: bool "loadkmap"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads a keyboard translation table from
//config: standard input.
//applet:IF_LOADKMAP(APPLET(loadkmap, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_LOADKMAP) += loadkmap.o
//usage:#define loadkmap_trivial_usage
//usage: "< keymap"

View File

@ -7,6 +7,17 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config OPENVT
//config: bool "openvt"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program is used to start a command on an unused
//config: virtual terminal.
//applet:IF_OPENVT(APPLET(openvt, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_OPENVT) += openvt.o
//usage:#define openvt_trivial_usage
//usage: "[-c N] [-sw] [PROG ARGS]"

View File

@ -7,9 +7,18 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* "Standard" version of this tool is in ncurses package */
/* BTW, which "standard" package has this utility? It doesn't seem
* to be ncurses, coreutils, console-tools... then what? */
//config:config RESET
//config: bool "reset"
//config: default y
//config: help
//config: This program is used to reset the terminal screen, if it
//config: gets messed up.
//applet:IF_RESET(APPLET(reset, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_RESET) += reset.o
//usage:#define reset_trivial_usage
//usage: ""
@ -47,6 +56,8 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
#if ENABLE_STTY
return stty_main(2, (char**)args);
#else
/* Make sure stdout gets drained before we execvp */
fflush_all();
execvp("stty", (char**)args);
#endif
}

View File

@ -6,7 +6,26 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* no options, no getopt */
//config:config RESIZE
//config: bool "resize"
//config: default y
//config: help
//config: This program is used to (re)set the width and height of your current
//config: terminal.
//config:
//config:config FEATURE_RESIZE_PRINT
//config: bool "Print environment variables"
//config: default y
//config: depends on RESIZE
//config: help
//config: Prints the newly set size (number of columns and rows) of
//config: the terminal.
//config: E.g.:
//config: COLUMNS=80;LINES=44;export COLUMNS LINES;
//applet:IF_RESIZE(APPLET(resize, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_RESIZE) += resize.o
//usage:#define resize_trivial_usage
//usage: ""
@ -14,10 +33,12 @@
//usage: "Resize the screen"
#include "libbb.h"
#include "common_bufsiz.h"
#define ESC "\033"
#define old_termios_p ((struct termios*)&bb_common_bufsiz1)
#define old_termios_p ((struct termios*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
static void
onintr(int sig UNUSED_PARAM)
@ -33,6 +54,8 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
struct winsize w = { 0, 0, 0, 0 };
int ret;
INIT_G();
/* We use _stderr_ in order to make resize usable
* in shell backticks (those redirect stdout away from tty).
* NB: other versions of resize open "/dev/tty"

View File

@ -7,6 +7,22 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETCONSOLE
//config: bool "setconsole"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program redirects the system console to another device,
//config: like the current tty while logged in via telnet.
//config:
//config:config FEATURE_SETCONSOLE_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on SETCONSOLE && LONG_OPTS
//applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SETCONSOLE) += setconsole.o
//usage:#define setconsole_trivial_usage
//usage: "[-r" IF_FEATURE_SETCONSOLE_LONG_OPTIONS("|--reset") "] [DEVICE]"

View File

@ -8,6 +8,17 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETKEYCODES
//config: bool "setkeycodes"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program loads entries into the kernel's scancode-to-keycode
//config: map, allowing unusual keyboards to generate usable keycodes.
//applet:IF_SETKEYCODES(APPLET(setkeycodes, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SETKEYCODES) += setkeycodes.o
//usage:#define setkeycodes_trivial_usage
//usage: "SCANCODE KEYCODE..."

View File

@ -8,6 +8,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config SETLOGCONS
//config: bool "setlogcons"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: This program redirects the output console of kernel messages.
//applet:IF_SETLOGCONS(APPLET(setlogcons, BB_DIR_USR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SETLOGCONS) += setlogcons.o
//usage:#define setlogcons_trivial_usage
//usage: "[N]"

View File

@ -6,6 +6,16 @@
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SHOWKEY
//config: bool "showkey"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: Shows keys pressed.
//applet:IF_SHOWKEY(APPLET(showkey, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SHOWKEY) += showkey.o
//usage:#define showkey_trivial_usage
//usage: "[-a | -k | -s]"

View File

@ -7,702 +7,6 @@ menu "Coreutils"
INSERT
config CAL
bool "cal"
default y
help
cal is used to display a monthly calendar.
config CATV
bool "catv"
default y
help
Display nonprinting characters as escape sequences (like some
implementations' cat -v option).
config CHGRP
bool "chgrp"
default y
help
chgrp is used to change the group ownership of files.
config CHMOD
bool "chmod"
default y
help
chmod is used to change the access permission of files.
config CHOWN
bool "chown"
default y
help
chown is used to change the user and/or group ownership
of files.
config FEATURE_CHOWN_LONG_OPTIONS
bool "Enable long options"
default y
depends on CHOWN && LONG_OPTS
help
Enable use of long options
config CHROOT
bool "chroot"
default y
help
chroot is used to change the root directory and run a command.
The default command is `/bin/sh'.
config CKSUM
bool "cksum"
default y
help
cksum is used to calculate the CRC32 checksum of a file.
config COMM
bool "comm"
default y
help
comm is used to compare two files line by line and return
a three-column output.
config CP
bool "cp"
default y
help
cp is used to copy files and directories.
config FEATURE_CP_LONG_OPTIONS
bool "Enable long options for cp"
default y
depends on CP && LONG_OPTS
help
Enable long options for cp.
Also add support for --parents option.
config CUT
bool "cut"
default y
help
cut is used to print selected parts of lines from
each file to stdout.
config DF
bool "df"
default y
help
df reports the amount of disk space used and available
on filesystems.
config FEATURE_DF_FANCY
bool "Enable -a, -i, -B"
default y
depends on DF
help
This option enables -a, -i and -B.
-a Show all filesystems
-i Inodes
-B <SIZE> Blocksize
config DIRNAME
bool "dirname"
default y
help
dirname is used to strip a non-directory suffix from
a file name.
config DOS2UNIX
bool "dos2unix/unix2dos"
default y
help
dos2unix is used to convert a text file from DOS format to
UNIX format, and vice versa.
config UNIX2DOS
bool
default y
depends on DOS2UNIX
help
unix2dos is used to convert a text file from UNIX format to
DOS format, and vice versa.
config DU
bool "du (default blocksize of 512 bytes)"
default y
help
du is used to report the amount of disk space used
for specified files.
config FEATURE_DU_DEFAULT_BLOCKSIZE_1K
bool "Use a default blocksize of 1024 bytes (1K)"
default y
depends on DU
help
Use a blocksize of (1K) instead of the default 512b.
config ECHO
bool "echo (basic SuSv3 version taking no options)"
default y
help
echo is used to print a specified string to stdout.
# this entry also appears in shell/Config.in, next to the echo builtin
config FEATURE_FANCY_ECHO
bool "Enable echo options (-n and -e)"
default y
depends on ECHO || ASH_BUILTIN_ECHO || HUSH
help
This adds options (-n and -e) to echo.
config ENV
bool "env"
default y
help
env is used to set an environment variable and run
a command; without options it displays the current
environment.
config FEATURE_ENV_LONG_OPTIONS
bool "Enable long options"
default y
depends on ENV && LONG_OPTS
help
Support long options for the env applet.
config EXPAND
bool "expand"
default y
help
By default, convert all tabs to spaces.
config FEATURE_EXPAND_LONG_OPTIONS
bool "Enable long options"
default y
depends on EXPAND && LONG_OPTS
help
Support long options for the expand applet.
config EXPR
bool "expr"
default y
help
expr is used to calculate numbers and print the result
to standard output.
config EXPR_MATH_SUPPORT_64
bool "Extend Posix numbers support to 64 bit"
default y
depends on EXPR
help
Enable 64-bit math support in the expr applet. This will make
the applet slightly larger, but will allow computation with very
large numbers.
config FALSE
bool "false"
default y
help
false returns an exit code of FALSE (1).
config FOLD
bool "fold"
default y
help
Wrap text to fit a specific width.
config FSYNC
bool "fsync"
default y
help
fsync is used to flush file-related cached blocks to disk.
config HEAD
bool "head"
default y
help
head is used to print the first specified number of lines
from files.
config FEATURE_FANCY_HEAD
bool "Enable head options (-c, -q, and -v)"
default y
depends on HEAD
help
This enables the head options (-c, -q, and -v).
config INSTALL
bool "install"
default y
help
Copy files and set attributes.
config FEATURE_INSTALL_LONG_OPTIONS
bool "Enable long options"
default y
depends on INSTALL && LONG_OPTS
help
Support long options for the install applet.
####config LENGTH
#### bool "length"
#### default y
#### help
#### length is used to print out the length of a specified string.
config LN
bool "ln"
default y
help
ln is used to create hard or soft links between files.
config LOGNAME
bool "logname"
default y
help
logname is used to print the current user's login name.
config LS
bool "ls"
default y
help
ls is used to list the contents of directories.
config FEATURE_LS_FILETYPES
bool "Enable filetyping options (-p and -F)"
default y
depends on LS
help
Enable the ls options (-p and -F).
config FEATURE_LS_FOLLOWLINKS
bool "Enable symlinks dereferencing (-L)"
default y
depends on LS
help
Enable the ls option (-L).
config FEATURE_LS_RECURSIVE
bool "Enable recursion (-R)"
default y
depends on LS
help
Enable the ls option (-R).
config FEATURE_LS_SORTFILES
bool "Sort the file names"
default y
depends on LS
help
Allow ls to sort file names alphabetically.
config FEATURE_LS_TIMESTAMPS
bool "Show file timestamps"
default y
depends on LS
help
Allow ls to display timestamps for files.
config FEATURE_LS_USERNAME
bool "Show username/groupnames"
default y
depends on LS
help
Allow ls to display username/groupname for files.
config FEATURE_LS_COLOR
bool "Allow use of color to identify file types"
default y
depends on LS && LONG_OPTS
help
This enables the --color option to ls.
config FEATURE_LS_COLOR_IS_DEFAULT
bool "Produce colored ls output by default"
default y
depends on FEATURE_LS_COLOR
help
Saying yes here will turn coloring on by default,
even if no "--color" option is given to the ls command.
This is not recommended, since the colors are not
configurable, and the output may not be legible on
many output screens.
config MD5SUM
bool "md5sum"
default y
help
md5sum is used to print or check MD5 checksums.
config MKDIR
bool "mkdir"
default y
help
mkdir is used to create directories with the specified names.
config FEATURE_MKDIR_LONG_OPTIONS
bool "Enable long options"
default y
depends on MKDIR && LONG_OPTS
help
Support long options for the mkdir applet.
config MKFIFO
bool "mkfifo"
default y
help
mkfifo is used to create FIFOs (named pipes).
The `mknod' program can also create FIFOs.
config MKNOD
bool "mknod"
default y
help
mknod is used to create FIFOs or block/character special
files with the specified names.
config MV
bool "mv"
default y
help
mv is used to move or rename files or directories.
config FEATURE_MV_LONG_OPTIONS
bool "Enable long options"
default y
depends on MV && LONG_OPTS
help
Support long options for the mv applet.
config NICE
bool "nice"
default y
help
nice runs a program with modified scheduling priority.
config NOHUP
bool "nohup"
default y
help
run a command immune to hangups, with output to a non-tty.
config OD
bool "od"
default y
help
od is used to dump binary files in octal and other formats.
config PRINTENV
bool "printenv"
default y
help
printenv is used to print all or part of environment.
config PRINTF
bool "printf"
default y
help
printf is used to format and print specified strings.
It's similar to `echo' except it has more options.
config PWD
bool "pwd"
default y
help
pwd is used to print the current directory.
config READLINK
bool "readlink"
default y
help
This program reads a symbolic link and returns the name
of the file it points to
config FEATURE_READLINK_FOLLOW
bool "Enable canonicalization by following all symlinks (-f)"
default y
depends on READLINK
help
Enable the readlink option (-f).
config REALPATH
bool "realpath"
default y
help
Return the canonicalized absolute pathname.
This isn't provided by GNU shellutils, but where else does it belong.
config RM
bool "rm"
default y
help
rm is used to remove files or directories.
config RMDIR
bool "rmdir"
default y
help
rmdir is used to remove empty directories.
config FEATURE_RMDIR_LONG_OPTIONS
bool "Enable long options"
default y
depends on RMDIR && LONG_OPTS
help
Support long options for the rmdir applet, including
--ignore-fail-on-non-empty for compatibility with GNU rmdir.
config SEQ
bool "seq"
default y
help
print a sequence of numbers
config SHA1SUM
bool "sha1sum"
default y
help
Compute and check SHA1 message digest
config SHA256SUM
bool "sha256sum"
default y
help
Compute and check SHA256 message digest
config SHA512SUM
bool "sha512sum"
default y
help
Compute and check SHA512 message digest
config SHA3SUM
bool "sha3sum"
default y
help
Compute and check SHA3 (512-bit) message digest
config SLEEP
bool "sleep"
default y
help
sleep is used to pause for a specified number of seconds.
It comes in 3 versions:
- small: takes one integer parameter
- fancy: takes multiple integer arguments with suffixes:
sleep 1d 2h 3m 15s
- fancy with fractional numbers:
sleep 2.3s 4.5h sleeps for 16202.3 seconds
Last one is "the most compatible" with coreutils sleep,
but it adds around 1k of code.
config FEATURE_FANCY_SLEEP
bool "Enable multiple arguments and s/m/h/d suffixes"
default y
depends on SLEEP
help
Allow sleep to pause for specified minutes, hours, and days.
config FEATURE_FLOAT_SLEEP
bool "Enable fractional arguments"
default y
depends on FEATURE_FANCY_SLEEP
help
Allow for fractional numeric parameters.
config SORT
bool "sort"
default y
help
sort is used to sort lines of text in specified files.
config FEATURE_SORT_BIG
bool "Full SuSv3 compliant sort (support -ktcsbdfiozgM)"
default y
depends on SORT
help
Without this, sort only supports -r, -u, and an integer version
of -n. Selecting this adds sort keys, floating point support, and
more. This adds a little over 3k to a nonstatic build on x86.
The SuSv3 sort standard is available at:
http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
config SPLIT
bool "split"
default y
help
split a file into pieces.
config FEATURE_SPLIT_FANCY
bool "Fancy extensions"
default y
depends on SPLIT
help
Add support for features not required by SUSv3.
Supports additional suffixes 'b' for 512 bytes,
'g' for 1GiB for the -b option.
config STAT
bool "stat"
default y
select PLATFORM_LINUX # statfs()
help
display file or filesystem status.
config FEATURE_STAT_FORMAT
bool "Enable custom formats (-c)"
default y
depends on STAT
help
Without this, stat will not support the '-c format' option where
users can pass a custom format string for output. This adds about
7k to a nonstatic build on amd64.
config STTY
bool "stty"
default y
help
stty is used to change and print terminal line settings.
config SUM
bool "sum"
default y
help
checksum and count the blocks in a file
config TAC
bool "tac"
default y
help
tac is used to concatenate and print files in reverse.
config TAIL
bool "tail"
default y
help
tail is used to print the last specified number of lines
from files.
config FEATURE_FANCY_TAIL
bool "Enable extra tail options (-q, -s, -v, and -F)"
default y
depends on TAIL
help
The options (-q, -s, -v and -F) are provided by GNU tail, but
are not specific in the SUSv3 standard.
-q Never output headers giving file names
-s SEC Wait SEC seconds between reads with -f
-v Always output headers giving file names
-F Same as -f, but keep retrying
config TEE
bool "tee"
default y
help
tee is used to read from standard input and write
to standard output and files.
config FEATURE_TEE_USE_BLOCK_IO
bool "Enable block I/O (larger/faster) instead of byte I/O"
default y
depends on TEE
help
Enable this option for a faster tee, at expense of size.
config TRUE
bool "true"
default y
help
true returns an exit code of TRUE (0).
config TTY
bool "tty"
default y
help
tty is used to print the name of the current terminal to
standard output.
config UNAME
bool "uname"
default y
help
uname is used to print system information.
config UNAME_OSNAME
string "Operating system name"
default "GNU/Linux"
depends on UNAME
help
Sets the operating system name reported by uname -o. The
default is "GNU/Linux".
config UNEXPAND
bool "unexpand"
default y
help
By default, convert only leading sequences of blanks to tabs.
config FEATURE_UNEXPAND_LONG_OPTIONS
bool "Enable long options"
default y
depends on UNEXPAND && LONG_OPTS
help
Support long options for the unexpand applet.
config UNIQ
bool "uniq"
default y
help
uniq is used to remove duplicate lines from a sorted file.
config USLEEP
bool "usleep"
default y
help
usleep is used to pause for a specified number of microseconds.
config UUDECODE
bool "uudecode"
default y
help
uudecode is used to decode a uuencoded file.
config UUENCODE
bool "uuencode"
default y
help
uuencode is used to uuencode a file.
config WC
bool "wc"
default y
help
wc is used to print the number of bytes, words, and lines,
in specified files.
config FEATURE_WC_LARGE
bool "Support very large files in wc"
default y
depends on WC
help
Use "unsigned long long" in wc for counter variables.
config WHOAMI
bool "whoami"
default y
help
whoami is used to print the username of the current
user id (same as id -un).
config YES
bool "yes"
default y
help
yes is used to repeatedly output a specific string, or
the default string `y'.
comment "Common options"
config FEATURE_VERBOSE
@ -723,41 +27,14 @@ config FEATURE_PRESERVE_HARDLINKS
help
Allow cp and mv to preserve hard links.
comment "Common options for ls, more and telnet"
depends on LS || MORE || TELNET
config FEATURE_AUTOWIDTH
bool "Calculate terminal & column widths"
default y
depends on LS || MORE || TELNET
help
This option allows utilities such as 'ls', 'more' and 'telnet'
to determine the width of the screen, which can allow them to
display additional text or avoid wrapping text onto the next line.
If you leave this disabled, your utilities will be especially
primitive and will be unable to determine the current screen width.
comment "Common options for df, du, ls"
depends on DF || DU || LS
config FEATURE_HUMAN_READABLE
bool "Support for human readable output (example 13k, 23M, 235G)"
bool "Support human readable output (example 13k, 23M, 235G)"
default y
depends on DF || DU || LS
help
Allow df, du, and ls to have human readable output.
comment "Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum"
depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM
config FEATURE_MD5_SHA1_SUM_CHECK
bool "Enable -c, -s and -w options"
default y
depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM
help
Enabling the -c options allows files to be checked
against pre-calculated hash values.
-s and -w are useful options when verifying checksums.
endmenu

View File

@ -9,75 +9,10 @@ libs-y += libcoreutils/
lib-y:=
INSERT
lib-$(CONFIG_CAL) += cal.o
lib-$(CONFIG_CATV) += catv.o
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
lib-$(CONFIG_CHMOD) += chmod.o
lib-$(CONFIG_CHOWN) += chown.o
lib-$(CONFIG_ADDUSER) += chown.o # used by adduser
lib-$(CONFIG_ADDGROUP) += chown.o # used by adduser
lib-$(CONFIG_CHROOT) += chroot.o
lib-$(CONFIG_CKSUM) += cksum.o
lib-$(CONFIG_COMM) += comm.o
lib-$(CONFIG_CP) += cp.o
lib-$(CONFIG_CUT) += cut.o
lib-$(CONFIG_DD) += dd.o
lib-$(CONFIG_DF) += df.o
lib-$(CONFIG_DIRNAME) += dirname.o
lib-$(CONFIG_DOS2UNIX) += dos2unix.o
lib-$(CONFIG_DU) += du.o
lib-$(CONFIG_ECHO) += echo.o
lib-$(CONFIG_ASH) += echo.o # used by ash
lib-$(CONFIG_HUSH) += echo.o # used by hush
lib-$(CONFIG_ENV) += env.o
lib-$(CONFIG_EXPR) += expr.o
lib-$(CONFIG_EXPAND) += expand.o
lib-$(CONFIG_FALSE) += false.o
lib-$(CONFIG_FOLD) += fold.o
lib-$(CONFIG_FSYNC) += fsync.o
lib-$(CONFIG_INSTALL) += install.o
#lib-$(CONFIG_LENGTH) += length.o
lib-$(CONFIG_LN) += ln.o
lib-$(CONFIG_LOGNAME) += logname.o
lib-$(CONFIG_LS) += ls.o
lib-$(CONFIG_FTPD) += ls.o
lib-$(CONFIG_MD5SUM) += md5_sha1_sum.o
lib-$(CONFIG_MKDIR) += mkdir.o
lib-$(CONFIG_MKFIFO) += mkfifo.o
lib-$(CONFIG_MKNOD) += mknod.o
lib-$(CONFIG_MV) += mv.o
lib-$(CONFIG_NICE) += nice.o
lib-$(CONFIG_NOHUP) += nohup.o
lib-$(CONFIG_OD) += od.o
lib-$(CONFIG_PRINTENV) += printenv.o
lib-$(CONFIG_PRINTF) += printf.o
lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o
lib-$(CONFIG_PWD) += pwd.o
lib-$(CONFIG_READLINK) += readlink.o
lib-$(CONFIG_REALPATH) += realpath.o
lib-$(CONFIG_RM) += rm.o
lib-$(CONFIG_RMDIR) += rmdir.o
lib-$(CONFIG_SEQ) += seq.o
lib-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
lib-$(CONFIG_SHA256SUM) += md5_sha1_sum.o
lib-$(CONFIG_SHA512SUM) += md5_sha1_sum.o
lib-$(CONFIG_SHA3SUM) += md5_sha1_sum.o
lib-$(CONFIG_SLEEP) += sleep.o
lib-$(CONFIG_SPLIT) += split.o
lib-$(CONFIG_SORT) += sort.o
lib-$(CONFIG_STAT) += stat.o
lib-$(CONFIG_STTY) += stty.o
lib-$(CONFIG_SUM) += sum.o
lib-$(CONFIG_TAC) += tac.o
lib-$(CONFIG_TEE) += tee.o
lib-$(CONFIG_TRUE) += true.o
lib-$(CONFIG_TTY) += tty.o
lib-$(CONFIG_UNAME) += uname.o
lib-$(CONFIG_UNEXPAND) += expand.o
lib-$(CONFIG_UNIQ) += uniq.o
lib-$(CONFIG_USLEEP) += usleep.o
lib-$(CONFIG_UUDECODE) += uudecode.o
lib-$(CONFIG_UUENCODE) += uuencode.o
lib-$(CONFIG_WC) += wc.o
lib-$(CONFIG_WHOAMI) += whoami.o
lib-$(CONFIG_YES) += yes.o
lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
lib-$(CONFIG_LESS) += cat.o # less too
lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
lib-$(CONFIG_ADDUSER) += chown.o # used by adduser
lib-$(CONFIG_ADDGROUP) += chown.o # used by addgroup
lib-$(CONFIG_FTPD) += ls.o # used by ftpd

View File

@ -14,12 +14,6 @@
* 2) Don't check for options, as per SUSv3.
* 3) Save some space by using strcmp(). Calling strncmp() here was silly.
*/
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */
//kbuild:lib-$(CONFIG_BASENAME) += basename.o
//config:config BASENAME
//config: bool "basename"
//config: default y
@ -28,6 +22,13 @@
//config: leaving just the filename itself. Enable this option if you wish
//config: to enable the 'basename' utility.
//applet:IF_BASENAME(APPLET_NOFORK(basename, basename, BB_DIR_USR_BIN, BB_SUID_DROP, basename))
//kbuild:lib-$(CONFIG_BASENAME) += basename.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */
//usage:#define basename_trivial_usage
//usage: "FILE [SUFFIX]"
//usage:#define basename_full_usage "\n\n"

View File

@ -6,64 +6,174 @@
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
//kbuild:lib-$(CONFIG_CAT) += cat.o
//kbuild:lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
//kbuild:lib-$(CONFIG_LESS) += cat.o # less too
//kbuild:lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
//config:config CAT
//config: bool "cat"
//config: default y
//config: help
//config: cat is used to concatenate files and print them to the standard
//config: output. Enable this option if you wish to enable the 'cat' utility.
//config:
//config:config FEATURE_CATV
//config: bool "cat -v[etA]"
//config: default y
//config: depends on CAT
//config: help
//config: Display nonprinting characters as escape sequences
//applet:IF_CAT(APPLET(cat, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CAT) += cat.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
//usage:#define cat_trivial_usage
//usage: "[FILE]..."
//usage: "[-nb"IF_FEATURE_CATV("vteA")"] [FILE]..."
//usage:#define cat_full_usage "\n\n"
//usage: "Concatenate FILEs and print them to stdout"
//usage: "Print FILEs to stdout\n"
//usage: "\n -n Number output lines"
//usage: "\n -b Number nonempty lines"
//usage: IF_FEATURE_CATV(
//usage: "\n -v Show nonprinting characters as ^x or M-x"
//usage: "\n -t ...and tabs as ^I"
//usage: "\n -e ...and end lines with $"
//usage: "\n -A Same as -vte"
//usage: )
/*
Longopts not implemented yet:
--number-nonblank number nonempty output lines, overrides -n
--number number all output lines
--show-nonprinting use ^ and M- notation, except for LFD and TAB
--show-all equivalent to -vet
Not implemented yet:
-E, --show-ends display $ at end of each line (-e sans -v)
-T, --show-tabs display TAB characters as ^I (-t sans -v)
-s, --squeeze-blank suppress repeated empty output lines
*/
//usage:
//usage:#define cat_example_usage
//usage: "$ cat /proc/uptime\n"
//usage: "110716.72 17.67"
#include "libbb.h"
#include "common_bufsiz.h"
/* This is a NOFORK applet. Be very careful! */
int bb_cat(char **argv)
#if ENABLE_FEATURE_CATV
/*
* cat -v implementation for busybox
*
* Copyright (C) 2006 Rob Landley <rob@landley.net>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* Rob had "cat -v" implemented as a separate applet, catv.
* See "cat -v considered harmful" at
* http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz
* From USENIX Summer Conference Proceedings, 1983
* """
* The talk reviews reasons for UNIX's popularity and shows, using UCB cat
* as a primary example, how UNIX has grown fat. cat isn't for printing
* files with line numbers, it isn't for compressing multiple blank lines,
* it's not for looking at non-printing ASCII characters, it's for
* concatenating files.
* We are reminded that ls isn't the place for code to break a single column
* into multiple ones, and that mailnews shouldn't have its own more
* processing or joke encryption code.
* """
*
* I agree with the argument. Unfortunately, this ship has sailed (1983...).
* There are dozens of Linux distros and each of them has "cat" which supports -v.
* It's unrealistic for us to "reeducate" them to use our, incompatible way
* to achieve "cat -v" effect. The actuall effect would be "users pissed off
* by gratuitous incompatibility".
*/
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2)
static int catv(unsigned opts, char **argv)
{
int fd;
int retval = EXIT_SUCCESS;
int fd;
if (!*argv)
argv = (char**) &bb_argv_dash;
BUILD_BUG_ON(CATV_OPT_e != VISIBLE_ENDLINE);
BUILD_BUG_ON(CATV_OPT_t != VISIBLE_SHOW_TABS);
#if 0 /* These consts match, we can just pass "opts" to visible() */
if (opts & CATV_OPT_e)
flags |= VISIBLE_ENDLINE;
if (opts & CATV_OPT_t)
flags |= VISIBLE_SHOW_TABS;
#endif
/* Read from stdin if there's nothing else to do. */
if (!argv[0])
*--argv = (char*)"-";
#define read_buf bb_common_bufsiz1
setup_common_bufsiz();
do {
fd = open_or_warn_stdin(*argv);
if (fd >= 0) {
/* This is not a xfunc - never exits */
off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
if (fd != STDIN_FILENO)
close(fd);
if (r >= 0)
continue;
if (fd < 0) {
retval = EXIT_FAILURE;
continue;
}
retval = EXIT_FAILURE;
for (;;) {
int i, res;
res = read(fd, read_buf, COMMON_BUFSIZE);
if (res < 0)
retval = EXIT_FAILURE;
if (res <= 0)
break;
for (i = 0; i < res; i++) {
unsigned char c = read_buf[i];
char buf[sizeof("M-^c")];
visible(c, buf, opts);
fputs(buf, stdout);
}
}
if (ENABLE_FEATURE_CLEAN_UP && fd)
close(fd);
} while (*++argv);
return retval;
fflush_stdout_and_exit(retval);
}
#endif
int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cat_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, "u");
struct number_state ns;
unsigned opts;
IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */)
/* -u is ignored ("unbuffered") */
opts = getopt32(argv, IF_FEATURE_CATV("etvA")"nbu");
argv += optind;
return bb_cat(argv);
#if ENABLE_FEATURE_CATV
if (opts & 7)
return catv(opts, argv);
//BUG: -v,-e,-t,-A ignore -nb
opts >>= 4;
#endif
#define CAT_OPT_n (1<<0)
#define CAT_OPT_b (1<<1)
#define CAT_OPT_u (1<<2)
if (!(opts & (CAT_OPT_n|CAT_OPT_b))) /* no -n or -b */
return bb_cat(argv);
if (!*argv)
*--argv = (char*)"-";
ns.width = 6;
ns.start = 1;
ns.inc = 1;
ns.sep = "\t";
ns.empty_str = "\n";
ns.all = !(opts & CAT_OPT_b); /* -n without -b */
ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */
do {
print_numbered_lines(&ns, *argv);
} while (*++argv);
fflush_stdout_and_exit(EXIT_SUCCESS);
}

View File

@ -1,82 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* cat -v implementation for busybox
*
* Copyright (C) 2006 Rob Landley <rob@landley.net>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* See "Cat -v considered harmful" at
* http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
//usage:#define catv_trivial_usage
//usage: "[-etv] [FILE]..."
//usage:#define catv_full_usage "\n\n"
//usage: "Display nonprinting characters as ^x or M-x\n"
//usage: "\n -e End each line with $"
//usage: "\n -t Show tabs as ^I"
//usage: "\n -v Don't use ^x or M-x escapes"
#include "libbb.h"
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2)
struct BUG_const_mismatch {
char BUG_const_mismatch[
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
? 1 : -1
];
};
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int catv_main(int argc UNUSED_PARAM, char **argv)
{
int retval = EXIT_SUCCESS;
int fd;
unsigned opts;
opts = getopt32(argv, "etv");
argv += optind;
#if 0 /* These consts match, we can just pass "opts" to visible() */
if (opts & CATV_OPT_e)
flags |= VISIBLE_ENDLINE;
if (opts & CATV_OPT_t)
flags |= VISIBLE_SHOW_TABS;
#endif
/* Read from stdin if there's nothing else to do. */
if (!argv[0])
*--argv = (char*)"-";
do {
fd = open_or_warn_stdin(*argv);
if (fd < 0) {
retval = EXIT_FAILURE;
continue;
}
for (;;) {
int i, res;
#define read_buf bb_common_bufsiz1
res = read(fd, read_buf, COMMON_BUFSIZE);
if (res < 0)
retval = EXIT_FAILURE;
if (res <= 0)
break;
for (i = 0; i < res; i++) {
unsigned char c = read_buf[i];
if (opts & CATV_OPT_v) {
putchar(c);
} else {
char buf[sizeof("M-^c")];
visible(c, buf, opts);
fputs(buf, stdout);
}
}
}
if (ENABLE_FEATURE_CLEAN_UP && fd)
close(fd);
} while (*++argv);
fflush_stdout_and_exit(retval);
}

View File

@ -6,6 +6,15 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHGRP
//config: bool "chgrp"
//config: default y
//config: help
//config: chgrp is used to change the group ownership of files.
//applet:IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp))
//kbuild:lib-$(CONFIG_CHGRP) += chgrp.o chown.o
/* BB_AUDIT SUSv3 defects - none? */
/* BB_AUDIT GNU defects - unsupported long options. */

View File

@ -9,6 +9,15 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHMOD
//config: bool "chmod"
//config: default y
//config: help
//config: chmod is used to change the access permission of files.
//applet:IF_CHMOD(APPLET_NOEXEC(chmod, chmod, BB_DIR_BIN, BB_SUID_DROP, chmod))
//kbuild:lib-$(CONFIG_CHMOD) += chmod.o
/* BB_AUDIT SUSv3 compliant */
/* BB_AUDIT GNU defects - unsupported long options. */

View File

@ -6,14 +6,29 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHOWN
//config: bool "chown"
//config: default y
//config: help
//config: chown is used to change the user and/or group ownership
//config: of files.
//config:
//config:config FEATURE_CHOWN_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on CHOWN && LONG_OPTS
//applet:IF_CHOWN(APPLET_NOEXEC(chown, chown, BB_DIR_BIN, BB_SUID_DROP, chown))
//kbuild:lib-$(CONFIG_CHOWN) += chown.o
/* BB_AUDIT SUSv3 defects - none? */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
//usage:#define chown_trivial_usage
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... OWNER[<.|:>[GROUP]] FILE..."
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... USER[:[GRP]] FILE..."
//usage:#define chown_full_usage "\n\n"
//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"
//usage: "Change the owner and/or group of each FILE to USER and/or GRP\n"
//usage: "\n -R Recurse"
//usage: "\n -h Affect symlinks instead of symlink targets"
//usage: IF_DESKTOP(
@ -112,10 +127,6 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
int opt, flags;
struct param_t param;
/* Just -1 might not work: uid_t may be unsigned long */
param.ugid.uid = -1L;
param.ugid.gid = -1L;
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
applet_long_options = chown_longopts;
#endif

View File

@ -6,6 +6,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CHROOT
//config: bool "chroot"
//config: default y
//config: help
//config: chroot is used to change the root directory and run a command.
//config: The default command is `/bin/sh'.
//applet:IF_CHROOT(APPLET(chroot, BB_DIR_USR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CHROOT) += chroot.o
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */

View File

@ -6,13 +6,23 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CKSUM
//config: bool "cksum"
//config: default y
//config: help
//config: cksum is used to calculate the CRC32 checksum of a file.
//applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
//kbuild:lib-$(CONFIG_CKSUM) += cksum.o
//usage:#define cksum_trivial_usage
//usage: "FILES..."
//usage: "FILE..."
//usage:#define cksum_full_usage "\n\n"
//usage: "Calculate the CRC32 checksums of FILES"
//usage: "Calculate the CRC32 checksums of FILEs"
#include "libbb.h"
#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
@ -32,6 +42,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
argv++;
#endif
setup_common_bufsiz();
do {
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
@ -43,7 +54,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
length = 0;
#define read_buf bb_common_bufsiz1
while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) {
while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) {
length += bytes_read;
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
}

View File

@ -6,6 +6,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config COMM
//config: bool "comm"
//config: default y
//config: help
//config: comm is used to compare two files line by line and return
//config: a three-column output.
//applet:IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_COMM) += comm.o
//usage:#define comm_trivial_usage
//usage: "[-123] FILE1 FILE2"

View File

@ -7,13 +7,29 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Size reduction.
*/
//config:config CP
//config: bool "cp"
//config: default y
//config: help
//config: cp is used to copy files and directories.
//config:
//config:config FEATURE_CP_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on CP && LONG_OPTS
//config: help
//config: Enable long options.
//config: Also add support for --parents option.
//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
//kbuild:lib-$(CONFIG_CP) += cp.o
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cp.html */
//usage:#define cp_trivial_usage
//usage: "[OPTIONS] SOURCE... DEST"
@ -31,6 +47,7 @@
//usage: "\n -f Overwrite"
//usage: "\n -i Prompt before overwrite"
//usage: "\n -l,-s Create (sym)links"
//usage: "\n -u Copy only newer files"
#include "libbb.h"
#include "libcoreutils/coreutils.h"
@ -49,12 +66,10 @@ int cp_main(int argc, char **argv)
int flags;
int status;
enum {
OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
FILEUTILS_CP_OPTNUM = sizeof(FILEUTILS_CP_OPTSTR)-1,
#if ENABLE_FEATURE_CP_LONG_OPTIONS
OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
/*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */
OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1),
#endif
};
@ -76,10 +91,12 @@ int cp_main(int argc, char **argv)
"recursive\0" No_argument "R"
"symbolic-link\0" No_argument "s"
"verbose\0" No_argument "v"
"parents\0" No_argument "\xff"
"update\0" No_argument "u"
"remove-destination\0" No_argument "\xff"
"parents\0" No_argument "\xfe"
;
#endif
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
/* Options of cp from GNU coreutils 6.10:
* -a, --archive
* -f, --force
@ -94,6 +111,11 @@ int cp_main(int argc, char **argv)
* -d same as --no-dereference --preserve=links
* -p same as --preserve=mode,ownership,timestamps
* -c same as --preserve=context
* -u, --update
* copy only when the SOURCE file is newer than the destination
* file or when the destination file is missing
* --remove-destination
* remove each existing destination file before attempting to open
* --parents
* use full source file name under DIRECTORY
* NOT SUPPORTED IN BBOX:
@ -106,8 +128,6 @@ int cp_main(int argc, char **argv)
* preserve attributes (default: mode,ownership,timestamps),
* if possible additional attributes: security context,links,all
* --no-preserve=ATTR_LIST
* --remove-destination
* remove each existing destination file before attempting to open
* --sparse=WHEN
* control creation of sparse files
* --strip-trailing-slashes
@ -118,9 +138,6 @@ int cp_main(int argc, char **argv)
* copy all SOURCE arguments into DIRECTORY
* -T, --no-target-directory
* treat DEST as a normal file
* -u, --update
* copy only when the SOURCE file is newer than the destination
* file or when the destination file is missing
* -x, --one-file-system
* stay on this file system
* -Z, --context=CONTEXT
@ -156,11 +173,16 @@ int cp_main(int argc, char **argv)
return EXIT_FAILURE;
#if ENABLE_FEATURE_CP_LONG_OPTIONS
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
// flags, FILEUTILS_RMDEST, OPT_parents);
if (flags & OPT_parents) {
if (!(d_flags & 2)) {
bb_error_msg_and_die("with --parents, the destination must be a directory");
}
}
if (flags & FILEUTILS_RMDEST) {
flags |= FILEUTILS_FORCE;
}
#endif
/* ...if neither is a directory... */

View File

@ -8,6 +8,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config CUT
//config: bool "cut"
//config: default y
//config: help
//config: cut is used to print selected parts of lines from
//config: each file to stdout.
//applet:IF_CUT(APPLET_NOEXEC(cut, cut, BB_DIR_USR_BIN, BB_SUID_DROP, cut))
//kbuild:lib-$(CONFIG_CUT) += cut.o
//usage:#define cut_trivial_usage
//usage: "[OPTIONS] [FILE]..."

View File

@ -8,8 +8,7 @@
* bugfixes and cleanup by Bernhard Reutner-Fischer
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
*/
/* This 'date' command supports only 2 time setting formats,
all the GNU strftime stuff (its in libc, lets use it),
setting time using UTC and displaying it, as well as
@ -19,10 +18,6 @@
/* Input parsing code is always bulky - used heavy duty libc stuff as
much as possible, missed out a lot of bounds checking */
//applet:IF_DATE(APPLET(date, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DATE) += date.o
//config:config DATE
//config: bool "date"
//config: default y
@ -63,6 +58,10 @@
//config: the same format. With it on, 'date DATE' additionally supports
//config: MMDDhhmm[[YY]YY][.ss] format.
//applet:IF_DATE(APPLET(date, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DATE) += date.o
/* GNU coreutils 6.9 man page:
* date [OPTION]... [+FORMAT]
* date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
@ -138,6 +137,7 @@
//usage: "Wed Apr 12 18:52:41 MDT 2000\n"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_DATE_NANO
# include <sys/syscall.h>
#endif
@ -368,6 +368,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
#endif
#define date_buf bb_common_bufsiz1
setup_common_bufsiz();
if (*fmt_dt2str == '\0') {
/* With no format string, just print a blank line */
date_buf[0] = '\0';
@ -377,7 +378,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
}
/* Generate output string */
strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);
strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time);
}
puts(date_buf);

View File

@ -2,12 +2,10 @@
/*
* Mini dd implementation for busybox
*
*
* Copyright (C) 2000,2001 Matt Kraai
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DD
//config: bool "dd"
//config: default y
@ -43,7 +41,7 @@
//config: default y
//config: depends on DD
//config: help
//config: Enables support for writing a certain number of bytes in and out,
//config: Enable support for writing a certain number of bytes in and out,
//config: at a time, and performing conversions on the data stream.
//config:
//config:config FEATURE_DD_STATUS
@ -51,11 +49,15 @@
//config: default y
//config: depends on DD
//config: help
//config: Enables support for status=noxfer/none option.
//config: Enable support for status=noxfer/none option.
//applet:IF_DD(APPLET_NOEXEC(dd, dd, BB_DIR_BIN, BB_SUID_DROP, dd))
//kbuild:lib-$(CONFIG_DD) += dd.o
//usage:#define dd_trivial_usage
//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n"
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync]")
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes]")
//usage:#define dd_full_usage "\n\n"
//usage: "Copy a file with converting and formatting\n"
//usage: "\n if=FILE Read from FILE instead of stdin"
@ -76,6 +78,7 @@
//usage: "\n conv=sync Pad blocks with zeros"
//usage: "\n conv=fsync Physically write data out before finishing"
//usage: "\n conv=swab Swap every pair of bytes"
//usage: "\n iflag=skip_bytes skip=N is in bytes"
//usage: )
//usage: IF_FEATURE_DD_STATUS(
//usage: "\n status=noxfer Suppress rate output"
@ -90,6 +93,7 @@
//usage: "4+0 records out\n"
#include "libbb.h"
#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
@ -107,8 +111,9 @@ struct globals {
#endif
int flags;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
} while (0)
@ -122,11 +127,15 @@ enum {
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of conv flags */
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 6,
FLAG_STATUS = 1 << 7,
FLAG_STATUS_NONE = 1 << 7,
FLAG_STATUS_NOXFER = 1 << 8,
/* start of input flags */
FLAG_IFLAG_SHIFT = 5,
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of input flags */
FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 7,
FLAG_STATUS = 1 << 8,
FLAG_STATUS_NONE = 1 << 9,
FLAG_STATUS_NOXFER = 1 << 10,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@ -203,18 +212,47 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
# define XATOU_SFX xatoul_sfx
#endif
#if ENABLE_FEATURE_DD_IBS_OBS
static int parse_comma_flags(char *val, const char *words, const char *error_in)
{
int flags = 0;
while (1) {
int n;
char *arg;
/* find ',', replace them with NUL so we can use val for
* index_in_strings() without copying.
* We rely on val being non-null, else strchr would fault.
*/
arg = strchr(val, ',');
if (arg)
*arg = '\0';
n = index_in_strings(words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg_to, val, error_in);
flags |= (1 << n);
if (!arg) /* no ',' left, so this was the last specifier */
break;
*arg = ','; /* to preserve ps listing */
val = arg + 1; /* skip this keyword and ',' */
}
return flags;
}
#endif
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dd_main(int argc UNUSED_PARAM, char **argv)
{
static const char keywords[] ALIGN1 =
"bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0")
#if ENABLE_FEATURE_DD_IBS_OBS
"ibs\0""obs\0""conv\0"
"ibs\0""obs\0""conv\0""iflag\0"
#endif
;
#if ENABLE_FEATURE_DD_IBS_OBS
static const char conv_words[] ALIGN1 =
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
static const char iflag_words[] ALIGN1 =
"skip_bytes\0";
#endif
#if ENABLE_FEATURE_DD_STATUS
static const char status_words[] ALIGN1 =
@ -232,6 +270,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
OP_ibs,
OP_obs,
OP_conv,
OP_iflag,
/* Must be in the same order as FLAG_XXX! */
OP_conv_notrunc = 0,
OP_conv_sync,
@ -251,6 +290,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
//ibm from ASCII to alternate EBCDIC
/* Partially implemented: */
//swab swap every pair of input bytes: will abort on non-even reads
OP_iflag_skip_bytes,
#endif
};
smallint exitcode = EXIT_FAILURE;
@ -315,24 +355,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
/*continue;*/
}
if (what == OP_conv) {
while (1) {
int n;
/* find ',', replace them with NUL so we can use val for
* index_in_strings() without copying.
* We rely on val being non-null, else strchr would fault.
*/
arg = strchr(val, ',');
if (arg)
*arg = '\0';
n = index_in_strings(conv_words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
G.flags |= (1 << n);
if (!arg) /* no ',' left, so this was the last specifier */
break;
/* *arg = ','; - to preserve ps listing? */
val = arg + 1; /* skip this keyword and ',' */
}
G.flags |= parse_comma_flags(val, conv_words, "conv");
/*continue;*/
}
if (what == OP_iflag) {
G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT;
/*continue;*/
}
#endif
@ -368,7 +395,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
int n;
n = index_in_strings(status_words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg, val, "status");
bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status");
G.flags |= FLAG_STATUS << n;
/*continue;*/
}
@ -421,9 +448,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
outfile = bb_msg_standard_output;
}
if (skip) {
if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
do {
ssize_t n = safe_read(ifd, ibuf, ibs);
ssize_t n = safe_read(ifd, ibuf, blocksz);
if (n < 0)
goto die_infile;
if (n == 0)
@ -504,11 +532,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (write_and_stats(ibuf, n, obs, outfile))
goto out_status;
}
}
if (G.flags & FLAG_FSYNC) {
if (fsync(ofd) < 0)
goto die_outfile;
}
if (G.flags & FLAG_FSYNC) {
if (fsync(ofd) < 0)
goto die_outfile;
}
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {

View File

@ -7,10 +7,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 _NOT_ compliant -- option -t missing. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/df.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Size reduction. Removed floating point dependency. Added error checking
@ -21,6 +17,28 @@
*
* Implement -P and -B; better coreutils compat; cleanup
*/
//config:config DF
//config: bool "df"
//config: default y
//config: help
//config: df reports the amount of disk space used and available
//config: on filesystems.
//config:
//config:config FEATURE_DF_FANCY
//config: bool "Enable -a, -i, -B"
//config: default y
//config: depends on DF
//config: help
//config: -a Show all filesystems
//config: -i Inodes
//config: -B <SIZE> Blocksize
//applet:IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DF) += df.o
/* BB_AUDIT SUSv3 _NOT_ compliant -- option -t missing. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/df.html */
//usage:#define df_trivial_usage
//usage: "[-Pk"
@ -109,8 +127,19 @@ int df_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_MEGA)
df_disp_hr = 1024*1024;
if (opt & OPT_BSIZE)
df_disp_hr = xatoul_range(chp, 1, ULONG_MAX); /* disallow 0 */
if (opt & OPT_BSIZE) {
/* GNU coreutils 8.25 accepts "-BMiB" form too */
int i;
for (i = 0; kmg_i_suffixes[i].suffix[0]; i++) {
if (strcmp(kmg_i_suffixes[i].suffix, chp) == 0) {
df_disp_hr = kmg_i_suffixes[i].mult;
goto got_it;
}
}
/* Range used to disallow 0 */
df_disp_hr = xatoul_range_sfx(chp, 1, ULONG_MAX, kmg_i_suffixes);
got_it: ;
}
/* From the manpage of df from coreutils-6.10:
* Disk space is shown in 1K blocks by default, unless the environment
@ -183,12 +212,17 @@ int df_main(int argc UNUSED_PARAM, char **argv)
bb_simple_perror_msg(mount_point);
goto set_error;
}
/* Some uclibc versions were seen to lose f_frsize
* (kernel does return it, but then uclibc does not copy it)
*/
if (s.f_frsize == 0)
s.f_frsize = s.f_bsize;
if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
if (opt & OPT_INODE) {
s.f_blocks = s.f_files;
s.f_bavail = s.f_bfree = s.f_ffree;
s.f_bsize = 1;
s.f_frsize = 1;
if (df_disp_hr)
df_disp_hr = 1;
@ -246,26 +280,26 @@ int df_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_HUMAN_READABLE
printf(" %9s ",
/* f_blocks x f_bsize / df_disp_hr, show one fractional,
/* f_blocks x f_frsize / df_disp_hr, show one fractional,
* use suffixes if df_disp_hr == 0 */
make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
make_human_readable_str(s.f_blocks, s.f_frsize, df_disp_hr));
printf(" %9s " + 1,
/* EXPR x f_bsize / df_disp_hr, show one fractional,
/* EXPR x f_frsize / df_disp_hr, show one fractional,
* use suffixes if df_disp_hr == 0 */
make_human_readable_str((s.f_blocks - s.f_bfree),
s.f_bsize, df_disp_hr));
s.f_frsize, df_disp_hr));
printf("%9s %3u%% %s\n",
/* f_bavail x f_bsize / df_disp_hr, show one fractional,
/* f_bavail x f_frsize / df_disp_hr, show one fractional,
* use suffixes if df_disp_hr == 0 */
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
make_human_readable_str(s.f_bavail, s.f_frsize, df_disp_hr),
blocks_percent_used, mount_point);
#else
printf(" %9lu %9lu %9lu %3u%% %s\n",
kscale(s.f_blocks, s.f_bsize),
kscale(s.f_blocks - s.f_bfree, s.f_bsize),
kscale(s.f_bavail, s.f_bsize),
kscale(s.f_blocks, s.f_frsize),
kscale(s.f_blocks - s.f_bfree, s.f_frsize),
kscale(s.f_bavail, s.f_frsize),
blocks_percent_used, mount_point);
#endif
}

View File

@ -6,6 +6,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config DIRNAME
//config: bool "dirname"
//config: default y
//config: help
//config: dirname is used to strip a non-directory suffix from
//config: a file name.
//applet:IF_DIRNAME(APPLET_NOFORK(dirname, dirname, BB_DIR_USR_BIN, BB_SUID_DROP, dirname))
//kbuild:lib-$(CONFIG_DIRNAME) += dirname.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/dirname.html */

View File

@ -2,7 +2,7 @@
/*
* dos2unix for BusyBox
*
* dos2unix '\n' convertor 0.5.0
* dos2unix '\n' converter 0.5.0
* based on Unix2Dos 0.9.0 by Peter Hanecak (made 19.2.1997)
* Copyright 1997,.. by Peter Hanecak <hanecak@megaloman.sk>.
* All rights reserved.
@ -10,7 +10,26 @@
* dos2unix filters reading input from stdin and writing output to stdout.
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
*/
//config:config DOS2UNIX
//config: bool "dos2unix"
//config: default y
//config: help
//config: dos2unix is used to convert a text file from DOS format to
//config: UNIX format, and vice versa.
//config:
//config:config UNIX2DOS
//config: bool "unix2dos"
//config: default y
//config: help
//config: unix2dos is used to convert a text file from UNIX format to
//config: DOS format, and vice versa.
//applet:IF_DOS2UNIX(APPLET_NOEXEC(dos2unix, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, dos2unix))
//applet:IF_UNIX2DOS(APPLET_NOEXEC(unix2dos, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, unix2dos))
//kbuild:lib-$(CONFIG_DOS2UNIX) += dos2unix.o
//kbuild:lib-$(CONFIG_UNIX2DOS) += dos2unix.o
//usage:#define dos2unix_trivial_usage
//usage: "[-ud] [FILE]"
@ -41,7 +60,7 @@ enum {
static void convert(char *fn, int conv_type)
{
FILE *in, *out;
int i;
int ch;
char *temp_fn = temp_fn; /* for compiler */
char *resolved_fn = resolved_fn;
@ -49,28 +68,30 @@ static void convert(char *fn, int conv_type)
out = stdout;
if (fn != NULL) {
struct stat st;
int fd;
resolved_fn = xmalloc_follow_symlinks(fn);
if (resolved_fn == NULL)
bb_simple_perror_msg_and_die(fn);
in = xfopen_for_read(resolved_fn);
fstat(fileno(in), &st);
xfstat(fileno(in), &st, resolved_fn);
temp_fn = xasprintf("%sXXXXXX", resolved_fn);
i = xmkstemp(temp_fn);
if (fchmod(i, st.st_mode) == -1)
fd = xmkstemp(temp_fn);
if (fchmod(fd, st.st_mode) == -1)
bb_simple_perror_msg_and_die(temp_fn);
fchown(fd, st.st_uid, st.st_gid);
out = xfdopen_for_write(i);
out = xfdopen_for_write(fd);
}
while ((i = fgetc(in)) != EOF) {
if (i == '\r')
while ((ch = fgetc(in)) != EOF) {
if (ch == '\r')
continue;
if (i == '\n')
if (ch == '\n')
if (conv_type == CT_UNIX2DOS)
fputc('\r', out);
fputc(i, out);
fputc(ch, out);
}
if (fn != NULL) {
@ -90,9 +111,12 @@ int dos2unix_main(int argc UNUSED_PARAM, char **argv)
int o, conv_type;
/* See if we are supposed to be doing dos2unix or unix2dos */
conv_type = CT_UNIX2DOS;
if (applet_name[0] == 'd') {
if (ENABLE_DOS2UNIX
&& (!ENABLE_UNIX2DOS || applet_name[0] == 'd')
) {
conv_type = CT_DOS2UNIX;
} else {
conv_type = CT_UNIX2DOS;
}
/* -u convert to unix, -d convert to dos */

View File

@ -8,10 +8,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 compliant (unless default blocksize set to 1k) */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/du.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Mostly rewritten for SUSv3 compliance and to fix bugs/defects.
@ -22,6 +18,26 @@
* 3) Added error checking of output.
* 4) Fixed busybox bug #1284 involving long overflow with human_readable.
*/
//config:config DU
//config: bool "du (default blocksize of 512 bytes)"
//config: default y
//config: help
//config: du is used to report the amount of disk space used
//config: for specified files.
//config:
//config:config FEATURE_DU_DEFAULT_BLOCKSIZE_1K
//config: bool "Use a default blocksize of 1024 bytes (1K)"
//config: default y
//config: depends on DU
//config: help
//config: Use a blocksize of (1K) instead of the default 512b.
//applet:IF_DU(APPLET(du, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_DU) += du.o
/* BB_AUDIT SUSv3 compliant (unless default blocksize set to 1k) */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/du.html */
//usage:#define du_trivial_usage
//usage: "[-aHLdclsx" IF_FEATURE_HUMAN_READABLE("hm") "k] [FILE]..."
@ -58,6 +74,7 @@
//usage: "2417 .\n"
#include "libbb.h"
#include "common_bufsiz.h"
enum {
OPT_a_files_too = (1 << 0),
@ -75,7 +92,7 @@ enum {
struct globals {
#if ENABLE_FEATURE_HUMAN_READABLE
unsigned long disp_hr;
unsigned long disp_unit;
#else
unsigned disp_k;
#endif
@ -85,22 +102,31 @@ struct globals {
int du_depth;
dev_t dir_dev;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
/* FIXME? coreutils' du rounds sizes up:
* for example, 1025k file is shown as "2" by du -m.
* We round to nearest.
*/
static void print(unsigned long long size, const char *filename)
{
/* TODO - May not want to defer error checking here. */
#if ENABLE_FEATURE_HUMAN_READABLE
# if ENABLE_DESKTOP
/* ~30 bytes of code for extra comtat:
* coreutils' du rounds sizes up:
* for example, 1025k file is shown as "2" by du -m.
* We round to nearest if human-readable [too hard to fix],
* else (fixed scale such as -m), we round up. To that end,
* add yet another half of the unit before displaying:
*/
if (G.disp_unit)
size += (G.disp_unit-1) / (unsigned)(512 * 2);
# endif
printf("%s\t%s\n",
/* size x 512 / G.disp_hr, show one fractional,
* use suffixes if G.disp_hr == 0 */
make_human_readable_str(size, 512, G.disp_hr),
/* size x 512 / G.disp_unit.
* If G.disp_unit == 0, show one fractional
* and use suffixes
*/
make_human_readable_str(size, 512, G.disp_unit),
filename);
#else
if (G.disp_k) {
@ -199,10 +225,10 @@ int du_main(int argc UNUSED_PARAM, char **argv)
INIT_G();
#if ENABLE_FEATURE_HUMAN_READABLE
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 1024;)
IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 512;)
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
G.disp_hr = 512;
G.disp_unit = 512;
#else
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;)
/* IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
@ -216,21 +242,21 @@ int du_main(int argc UNUSED_PARAM, char **argv)
* ignore -a. This is consistent with -s being equivalent to -d 0.
*/
#if ENABLE_FEATURE_HUMAN_READABLE
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+";
opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth);
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
opt = getopt32(argv, "aHkLsx" "d:+" "lc" "hm", &G.max_print_depth);
argv += optind;
if (opt & OPT_h_for_humans) {
G.disp_hr = 0;
G.disp_unit = 0;
}
if (opt & OPT_m_mbytes) {
G.disp_hr = 1024*1024;
G.disp_unit = 1024*1024;
}
if (opt & OPT_k_kbytes) {
G.disp_hr = 1024;
G.disp_unit = 1024;
}
#else
opt_complementary = "H-L:L-H:s-d:d-s:d+";
opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth);
opt_complementary = "H-L:L-H:s-d:d-s";
opt = getopt32(argv, "aHkLsx" "d:+" "lc", &G.max_print_depth);
argv += optind;
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if (opt & OPT_k_kbytes) {

View File

@ -9,10 +9,6 @@
*
* Original copyright notice is retained at the end of this file.
*/
/* BB_AUDIT SUSv3 compliant -- unless configured as fancy echo. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/echo.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Because of behavioral differences, implemented configurable SUSv3
@ -22,6 +18,27 @@
* 2) SUSv3 specifies that octal escapes are of the form \0{#{#{#}}}.
* The previous version did not allow 4-digit octals.
*/
//config:config ECHO
//config: bool "echo (basic SuSv3 version taking no options)"
//config: default y
//config: help
//config: echo is used to print a specified string to stdout.
//config:
//config:# this entry also appears in shell/Config.in, next to the echo builtin
//config:config FEATURE_FANCY_ECHO
//config: bool "Enable -n and -e options"
//config: default y
//config: depends on ECHO || ASH_ECHO || HUSH_ECHO
//applet:IF_ECHO(APPLET_NOFORK(echo, echo, BB_DIR_BIN, BB_SUID_DROP, echo))
//kbuild:lib-$(CONFIG_ECHO) += echo.o
//kbuild:lib-$(CONFIG_ASH_ECHO) += echo.o
//kbuild:lib-$(CONFIG_HUSH_ECHO) += echo.o
/* BB_AUDIT SUSv3 compliant -- unless configured as fancy echo. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/echo.html */
//usage:#define echo_trivial_usage
//usage: IF_FEATURE_FANCY_ECHO("[-neE] ") "[ARG]..."

View File

@ -11,16 +11,11 @@
*
* Modified for BusyBox by Erik Andersen <andersen@codepoet.org>
*/
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/env.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Fixed bug involving exit return codes if execvp fails. Also added
* output error checking.
*/
/*
* Modified by Vladimir Oleynik <dzo@simtreas.ru> (C) 2003
* - correct "-" option usage
@ -28,8 +23,25 @@
* - GNU long option support
* - use xfunc_error_retval
*/
//config:config ENV
//config: bool "env"
//config: default y
//config: help
//config: env is used to set an environment variable and run
//config: a command; without options it displays the current
//config: environment.
//config:
//config:config FEATURE_ENV_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on ENV && LONG_OPTS
/* This is a NOEXEC applet. Be very careful! */
//applet:IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env))
//kbuild:lib-$(CONFIG_ENV) += env.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/env.html */
//usage:#define env_trivial_usage
//usage: "[-iu] [-] [name=value]... [PROG ARGS]"
@ -54,11 +66,10 @@ int env_main(int argc UNUSED_PARAM, char **argv)
unsigned opts;
llist_t *unset_env = NULL;
opt_complementary = "u::";
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
applet_long_options = env_longopts;
#endif
opts = getopt32(argv, "+iu:", &unset_env);
opts = getopt32(argv, "+iu:+", &unset_env);
argv += optind;
if (argv[0] && LONE_DASH(argv[0])) {
opts |= 1;

View File

@ -8,18 +8,46 @@
* David MacKenzie <djm@gnu.ai.mit.edu>
*
* Options for expand:
* -t num --tabs=NUM Convert tabs to num spaces (default 8 spaces).
* -t num --tabs NUM Convert tabs to num spaces (default 8 spaces).
* -i --initial Only convert initial tabs on each line to spaces.
*
* Options for unexpand:
* -a --all Convert all blanks, instead of just initial blanks.
* -f --first-only Convert only leading sequences of blanks (default).
* -t num --tabs=NUM Have tabs num characters apart instead of 8.
* -t num --tabs NUM Have tabs num characters apart instead of 8.
*
* Busybox version (C) 2007 by Tito Ragusa <farmatito@tiscali.it>
*
* Caveat: this versions of expand and unexpand don't accept tab lists.
*/
//config:config EXPAND
//config: bool "expand"
//config: default y
//config: help
//config: By default, convert all tabs to spaces.
//config:
//config:config FEATURE_EXPAND_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on EXPAND && LONG_OPTS
//config:
//config:config UNEXPAND
//config: bool "unexpand"
//config: default y
//config: help
//config: By default, convert only leading sequences of blanks to tabs.
//config:
//config:config FEATURE_UNEXPAND_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on UNEXPAND && LONG_OPTS
//applet:IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_UNEXPAND(APPLET_ODDNAME(unexpand, expand, BB_DIR_USR_BIN, BB_SUID_DROP, unexpand))
//kbuild:lib-$(CONFIG_EXPAND) += expand.o
//kbuild:lib-$(CONFIG_UNEXPAND) += expand.o
//usage:#define expand_trivial_usage
//usage: "[-i] [-t N] [FILE]..."
@ -27,7 +55,7 @@
//usage: "Convert tabs to spaces, writing to stdout\n"
//usage: IF_FEATURE_EXPAND_LONG_OPTIONS(
//usage: "\n -i,--initial Don't convert tabs after non blanks"
//usage: "\n -t,--tabs=N Tabstops every N chars"
//usage: "\n -t,--tabs N Tabstops every N chars"
//usage: )
//usage: IF_NOT_FEATURE_EXPAND_LONG_OPTIONS(
//usage: "\n -i Don't convert tabs after non blanks"
@ -41,7 +69,7 @@
//usage: IF_FEATURE_UNEXPAND_LONG_OPTIONS(
//usage: "\n -a,--all Convert all blanks"
//usage: "\n -f,--first-only Convert only leading blanks"
//usage: "\n -t,--tabs=N Tabstops every N chars"
//usage: "\n -t,--tabs N Tabstops every N chars"
//usage: )
//usage: IF_NOT_FEATURE_UNEXPAND_LONG_OPTIONS(
//usage: "\n -a Convert all blanks"

View File

@ -13,7 +13,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* This program evaluates expressions. Each token (operator, operand,
* parenthesis) of the expression must be a separate argument. The
* parser used is a reasonably general one, though any incarnation of
@ -21,9 +20,27 @@
*
* No parse tree is needed; a new node is evaluated immediately.
* One function can handle multiple operators all of equal precedence,
* provided they all associate ((x op x) op x). */
* provided they all associate ((x op x) op x).
*/
//config:config EXPR
//config: bool "expr"
//config: default y
//config: help
//config: expr is used to calculate numbers and print the result
//config: to standard output.
//config:
//config:config EXPR_MATH_SUPPORT_64
//config: bool "Extend Posix numbers support to 64 bit"
//config: default y
//config: depends on EXPR
//config: help
//config: Enable 64-bit math support in the expr applet. This will make
//config: the applet slightly larger, but will allow computation with very
//config: large numbers.
/* no getopt needed */
//applet:IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_EXPR) += expr.o
//usage:#define expr_trivial_usage
//usage: "EXPRESSION"
@ -61,6 +78,7 @@
//usage: "of characters matched or 0."
#include "libbb.h"
#include "common_bufsiz.h"
#include "xregex.h"
#if ENABLE_EXPR_MATH_SUPPORT_64
@ -99,8 +117,8 @@ typedef struct valinfo VALUE;
struct globals {
char **args;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
/* forward declarations */
static VALUE *eval(void);
@ -113,7 +131,7 @@ static VALUE *int_value(arith_t i)
VALUE *v;
v = xzalloc(sizeof(VALUE));
if (INTEGER) /* otherwise xzaaloc did it already */
if (INTEGER) /* otherwise xzalloc did it already */
v->type = INTEGER;
v->u.i = i;
return v;
@ -126,7 +144,7 @@ static VALUE *str_value(const char *s)
VALUE *v;
v = xzalloc(sizeof(VALUE));
if (STRING) /* otherwise xzaaloc did it already */
if (STRING) /* otherwise xzalloc did it already */
v->type = STRING;
v->u.s = xstrdup(s);
return v;

219
coreutils/factor.c Normal file
View File

@ -0,0 +1,219 @@
/*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config FACTOR
//config: bool "factor"
//config: default y
//config: help
//config: factor factorizes integers
//applet:IF_FACTOR(APPLET(factor, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_FACTOR) += factor.o
//usage:#define factor_trivial_usage
//usage: "[NUMBER]..."
//usage:#define factor_full_usage "\n\n"
//usage: "Print prime factors"
#include "libbb.h"
#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
#else
# define dbg(...) ((void)0)
#endif
typedef unsigned long long wide_t;
#if ULLONG_MAX == (UINT_MAX * UINT_MAX + 2 * UINT_MAX)
/* "unsigned" is half as wide as ullong */
typedef unsigned half_t;
#define HALF_MAX UINT_MAX
#define HALF_FMT ""
#elif ULLONG_MAX == (ULONG_MAX * ULONG_MAX + 2 * ULONG_MAX)
/* long is half as wide as ullong */
typedef unsigned long half_t;
#define HALF_MAX ULONG_MAX
#define HALF_FMT "l"
#else
#error Cant find an integer type which is half as wide as ullong
#endif
static half_t isqrt_odd(wide_t N)
{
half_t s = isqrt(N);
/* Subtract 1 from even s, odd s won't change: */
/* (doesnt work for zero, but we know that s != 0 here) */
s = (s - 1) | 1;
return s;
}
static NOINLINE void factorize(wide_t N)
{
half_t factor;
half_t max_factor;
// unsigned count3;
// unsigned count5;
// unsigned count7;
// ^^^^^^^^^^^^^^^ commented-out simple sieving code (easier to grasp).
// Faster sieving, using one word for potentially up to 6 counters:
// count upwards in each mask, counter "triggers" when it sets its mask to "100[0]..."
// 10987654321098765432109876543210 - bits 31-0 in 32-bit word
// 17777713333311111777775555333 - bit masks for counters for primes 3,5,7,11,13,17
// 100000100001000010001001 - value for adding 1 to each mask
// 10000010000010000100001000100 - value for checking that any mask reached msb
enum {
SHIFT_3 = 1 << 0,
SHIFT_5 = 1 << 3,
SHIFT_7 = 1 << 7,
INCREMENT_EACH = SHIFT_3 | SHIFT_5 | SHIFT_7,
MULTIPLE_OF_3 = 1 << 2,
MULTIPLE_OF_5 = 1 << 6,
MULTIPLE_OF_7 = 1 << 11,
MULTIPLE_DETECTED = MULTIPLE_OF_3 | MULTIPLE_OF_5 | MULTIPLE_OF_7,
};
unsigned sieve_word;
if (N < 4)
goto end;
while (!(N & 1)) {
printf(" 2");
N >>= 1;
}
/* The code needs to be optimized for the case where
* there are large prime factors. For example,
* this is not hard:
* 8262075252869367027 = 3 7 17 23 47 101 113 127 131 137 823
* (the largest factor to test is only ~sqrt(823) = 28)
* but this is:
* 18446744073709551601 = 53 348051774975651917
* the last factor requires testing up to
* 589959129 - about 100 million iterations.
* The slowest case (largest prime) for N < 2^64 is
* factor 18446744073709551557 (0xffffffffffffffc5).
*/
max_factor = isqrt_odd(N);
// count3 = 3;
// count5 = 6;
// count7 = 9;
sieve_word = 0
/* initial count for SHIFT_n is (n-1)/2*3: */
+ (MULTIPLE_OF_3 - 3 * SHIFT_3)
+ (MULTIPLE_OF_5 - 6 * SHIFT_5)
+ (MULTIPLE_OF_7 - 9 * SHIFT_7)
//+ (MULTIPLE_OF_11 - 15 * SHIFT_11)
//+ (MULTIPLE_OF_13 - 18 * SHIFT_13)
//+ (MULTIPLE_OF_17 - 24 * SHIFT_17)
;
factor = 3;
for (;;) {
/* The division is the most costly part of the loop.
* On 64bit CPUs, takes at best 12 cycles, often ~20.
*/
while ((N % factor) == 0) { /* not likely */
N = N / factor;
printf(" %"HALF_FMT"u", factor);
max_factor = isqrt_odd(N);
}
next_factor:
if (factor >= max_factor)
break;
factor += 2;
/* Rudimentary wheel sieving: skip multiples of 3, 5 and 7:
* Every third odd number is divisible by three and thus isn't a prime:
* 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47...
* ^ ^ ^ ^ ^ ^ ^ _ ^ ^ _ ^ ^ ^ ^
* (^ = primes, _ = would-be-primes-if-not-divisible-by-5)
* The numbers with space under them are excluded by sieve 3.
*/
// count7--;
// count5--;
// count3--;
// if (count3 && count5 && count7)
// continue;
sieve_word += INCREMENT_EACH;
if (!(sieve_word & MULTIPLE_DETECTED))
continue;
/*
* "factor" is multiple of 3 33% of the time (count3 reached 0),
* else, multiple of 5 13% of the time,
* else, multiple of 7 7.6% of the time.
* Cumulatively, with 3,5,7 sieving we are here 54.3% of the time.
*/
// if (count3 == 0)
// count3 = 3;
if (sieve_word & MULTIPLE_OF_3)
sieve_word -= SHIFT_3 * 3;
// if (count5 == 0)
// count5 = 5;
if (sieve_word & MULTIPLE_OF_5)
sieve_word -= SHIFT_5 * 5;
// if (count7 == 0)
// count7 = 7;
if (sieve_word & MULTIPLE_OF_7)
sieve_word -= SHIFT_7 * 7;
goto next_factor;
}
end:
if (N > 1)
printf(" %llu", N);
bb_putchar('\n');
}
static void factorize_numstr(const char *numstr)
{
wide_t N;
/* Leading + is ok (coreutils compat) */
if (*numstr == '+')
numstr++;
N = bb_strtoull(numstr, NULL, 10);
if (errno)
bb_show_usage();
printf("%llu:", N);
factorize(N);
}
int factor_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int factor_main(int argc UNUSED_PARAM, char **argv)
{
//// coreutils has undocumented option ---debug (three dashes)
//getopt32(argv, "");
//argv += optind;
argv++;
if (!*argv) {
/* Read from stdin, several numbers per line are accepted */
for (;;) {
char *numstr, *line;
line = xmalloc_fgetline(stdin);
if (!line)
return EXIT_SUCCESS;
numstr = line;
for (;;) {
char *end;
numstr = skip_whitespace(numstr);
if (!numstr[0])
break;
end = skip_non_whitespace(numstr);
if (*end != '\0')
*end++ = '\0';
factorize_numstr(numstr);
numstr = end;
}
free(line);
}
}
do {
/* Leading spaces are ok (coreutils compat) */
factorize_numstr(skip_whitespace(*argv));
} while (*++argv);
return EXIT_SUCCESS;
}

View File

@ -6,6 +6,15 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FALSE
//config: bool "false"
//config: default y
//config: help
//config: false returns an exit code of FALSE (1).
//applet:IF_FALSE(APPLET_NOFORK(false, false, BB_DIR_BIN, BB_SUID_DROP, false))
//kbuild:lib-$(CONFIG_FALSE) += false.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/000095399/utilities/false.html */

View File

@ -9,6 +9,15 @@
Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FOLD
//config: bool "fold"
//config: default y
//config: help
//config: Wrap text to fit a specific width.
//applet:IF_FOLD(APPLET_NOEXEC(fold, fold, BB_DIR_USR_BIN, BB_SUID_DROP, fold))
//kbuild:lib-$(CONFIG_FOLD) += fold.o
//usage:#define fold_trivial_usage
//usage: "[-bs] [-w WIDTH] [FILE]..."

View File

@ -6,6 +6,15 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FSYNC
//config: bool "fsync"
//config: default y
//config: help
//config: fsync is used to flush file-related cached blocks to disk.
//applet:IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync))
//kbuild:lib-$(CONFIG_FSYNC) += fsync.o
//usage:#define fsync_trivial_usage
//usage: "[-d] FILE..."

View File

@ -6,13 +6,26 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config HEAD
//config: bool "head"
//config: default y
//config: help
//config: head is used to print the first specified number of lines
//config: from files.
//config:
//config:config FEATURE_FANCY_HEAD
//config: bool "Enable -c, -q, and -v"
//config: default y
//config: depends on HEAD
//applet:IF_HEAD(APPLET_NOEXEC(head, head, BB_DIR_USR_BIN, BB_SUID_DROP, head))
//kbuild:lib-$(CONFIG_HEAD) += head.o
/* BB_AUDIT SUSv3 compliant */
/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */
//kbuild:lib-$(CONFIG_HEAD) += head.o
//usage:#define head_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage:#define head_full_usage "\n\n"

View File

@ -6,9 +6,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
//config:config HOSTID
//config: bool "hostid"
//config: default y
@ -20,6 +17,8 @@
//kbuild:lib-$(CONFIG_HOSTID) += hostid.o
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
//usage:#define hostid_trivial_usage
//usage: ""
//usage:#define hostid_full_usage "\n\n"

View File

@ -7,31 +7,30 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 compliant. */
/* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever
* length and to be more similar to GNU id.
* -Z option support: by Yuichi Nakamura <ynakam@hitachisoft.jp>
* Added -G option Tito Ragusa (C) 2008 for SUSv3.
*/
//config:config ID
//config: bool "id"
//config: default y
//config: help
//config: id displays the current user and group ID names.
//config:
//config:config GROUPS
//config: bool "groups"
//config: default y
//config: help
//config: Print the group names associated with current user id.
//applet:IF_GROUPS(APPLET_NOEXEC(groups, id, BB_DIR_USR_BIN, BB_SUID_DROP, groups))
//applet:IF_ID( APPLET_NOEXEC(id, id, BB_DIR_USR_BIN, BB_SUID_DROP, id ))
//kbuild:lib-$(CONFIG_GROUPS) += id.o
//kbuild:lib-$(CONFIG_ID) += id.o
//applet:IF_GROUPS(APPLET_NOEXEC(groups, id, BB_DIR_USR_BIN, BB_SUID_DROP, groups))
//applet:IF_ID( APPLET_NOEXEC(id, id, BB_DIR_USR_BIN, BB_SUID_DROP, id ))
/* BB_AUDIT SUSv3 compliant. */
//usage:#define id_trivial_usage
//usage: "[OPTIONS] [USER]"

View File

@ -5,6 +5,20 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config INSTALL
//config: bool "install"
//config: default y
//config: help
//config: Copy files and set attributes.
//config:
//config:config FEATURE_INSTALL_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on INSTALL && LONG_OPTS
//applet:IF_INSTALL(APPLET(install, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_INSTALL) += install.o
/* -v, -b, -c are ignored */
//usage:#define install_trivial_usage
@ -195,7 +209,8 @@ int install_main(int argc, char **argv)
char *ddir = xstrdup(dest);
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
/* errors are not checked. copy_file
* will fail if dir is not created. */
* will fail if dir is not created.
*/
free(ddir);
}
if (isdir)

View File

@ -1,31 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 N/A -- Apparently a busybox (obsolete?) extension. */
//usage:#define length_trivial_usage
//usage: "STRING"
//usage:#define length_full_usage "\n\n"
//usage: "Print STRING's length"
//usage:
//usage:#define length_example_usage
//usage: "$ length Hello\n"
//usage: "5\n"
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
int length_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int length_main(int argc, char **argv)
{
if ((argc != 2) || (**(++argv) == '-')) {
bb_show_usage();
}
printf("%u\n", (unsigned)strlen(*argv));
return fflush_all();
}

41
coreutils/link.c Normal file
View File

@ -0,0 +1,41 @@
/*
* link implementation for busybox
*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config LINK
//config: bool "link"
//config: default y
//config: help
//config: link creates hard links between files.
//applet:IF_LINK(APPLET_NOFORK(link, link, BB_DIR_BIN, BB_SUID_DROP, link))
//kbuild:lib-$(CONFIG_LINK) += link.o
//usage:#define link_trivial_usage
//usage: "FILE LINK"
//usage:#define link_full_usage "\n\n"
//usage: "Create hard LINK to FILE"
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int link_main(int argc UNUSED_PARAM, char **argv)
{
opt_complementary = "=2"; /* exactly 2 params */
getopt32(argv, "");
argv += optind;
if (link(argv[0], argv[1]) != 0) {
/* shared message */
bb_perror_msg_and_die("can't create %slink "
"%s to %s", "hard",
argv[1], argv[0]
);
}
return EXIT_SUCCESS;
}

View File

@ -6,6 +6,15 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config LN
//config: bool "ln"
//config: default y
//config: help
//config: ln is used to create hard or soft links between files.
//applet:IF_LN(APPLET_NOEXEC(ln, ln, BB_DIR_BIN, BB_SUID_DROP, ln))
//kbuild:lib-$(CONFIG_LN) += ln.o
/* BB_AUDIT SUSv3 compliant */
/* BB_AUDIT GNU options missing: -d, -F, -i, and -v. */

View File

@ -6,10 +6,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/logname.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* SUSv3 specifies the string used is that returned from getlogin().
@ -19,6 +15,18 @@
* correct course of action wrt SUSv3 for a failing getlogin() is
* a diagnostic message and an error return.
*/
//config:config LOGNAME
//config: bool "logname"
//config: default y
//config: help
//config: logname is used to print the current user's login name.
//applet:IF_LOGNAME(APPLET_NOFORK(logname, logname, BB_DIR_USR_BIN, BB_SUID_DROP, logname))
//kbuild:lib-$(CONFIG_LOGNAME) += logname.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/logname.html */
//usage:#define logname_trivial_usage
//usage: ""

View File

@ -4,7 +4,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* [date unknown. Perhaps before year 2000]
* To achieve a small memory footprint, this version of 'ls' doesn't do any
* file sorting, and only has the most essential command line switches
@ -28,24 +27,91 @@
* [2009-03]
* ls sorts listing now, and supports almost all options.
*/
//config:config LS
//config: bool "ls"
//config: default y
//config: help
//config: ls is used to list the contents of directories.
//config:
//config:config FEATURE_LS_FILETYPES
//config: bool "Enable filetyping options (-p and -F)"
//config: default y
//config: depends on LS
//config:
//config:config FEATURE_LS_FOLLOWLINKS
//config: bool "Enable symlinks dereferencing (-L)"
//config: default y
//config: depends on LS
//config:
//config:config FEATURE_LS_RECURSIVE
//config: bool "Enable recursion (-R)"
//config: default y
//config: depends on LS
//config:
//config:config FEATURE_LS_WIDTH
//config: bool "Enable -w WIDTH and window size autodetection"
//config: default y
//config: depends on LS
//config:
//config:config FEATURE_LS_SORTFILES
//config: bool "Sort the file names"
//config: default y
//config: depends on LS
//config: help
//config: Allow ls to sort file names alphabetically.
//config:
//config:config FEATURE_LS_TIMESTAMPS
//config: bool "Show file timestamps"
//config: default y
//config: depends on LS
//config: help
//config: Allow ls to display timestamps for files.
//config:
//config:config FEATURE_LS_USERNAME
//config: bool "Show username/groupnames"
//config: default y
//config: depends on LS
//config: help
//config: Allow ls to display username/groupname for files.
//config:
//config:config FEATURE_LS_COLOR
//config: bool "Allow use of color to identify file types"
//config: default y
//config: depends on LS && LONG_OPTS
//config: help
//config: This enables the --color option to ls.
//config:
//config:config FEATURE_LS_COLOR_IS_DEFAULT
//config: bool "Produce colored ls output by default"
//config: default y
//config: depends on FEATURE_LS_COLOR
//config: help
//config: Saying yes here will turn coloring on by default,
//config: even if no "--color" option is given to the ls command.
//config: This is not recommended, since the colors are not
//config: configurable, and the output may not be legible on
//config: many output screens.
//applet:IF_LS(APPLET_NOEXEC(ls, ls, BB_DIR_BIN, BB_SUID_DROP, ls))
//kbuild:lib-$(CONFIG_LS) += ls.o
//usage:#define ls_trivial_usage
//usage: "[-1AaCxd"
//usage: IF_FEATURE_LS_FOLLOWLINKS("LH")
//usage: IF_FEATURE_LS_RECURSIVE("R")
//usage: IF_FEATURE_LS_FILETYPES("Fp") "lins"
//usage: IF_FEATURE_LS_TIMESTAMPS("e")
//usage: IF_FEATURE_HUMAN_READABLE("h")
//usage: IF_FEATURE_LS_SORTFILES("rSXv")
//usage: IF_FEATURE_LS_TIMESTAMPS("ctu")
//usage: IF_SELINUX("kKZ") "]"
//usage: IF_FEATURE_AUTOWIDTH(" [-w WIDTH]") " [FILE]..."
//usage: IF_SELINUX("kZ") "]"
//usage: IF_FEATURE_LS_WIDTH(" [-w WIDTH]") " [FILE]..."
//usage:#define ls_full_usage "\n\n"
//usage: "List directory contents\n"
//usage: "\n -1 One column output"
//usage: "\n -a Include entries which start with ."
//usage: "\n -A Like -a, but exclude . and .."
//usage: "\n -C List by columns"
////usage: "\n -C List by columns" - don't show, this is a default anyway
//usage: "\n -x List by lines"
//usage: "\n -d List directory entries instead of contents"
//usage: IF_FEATURE_LS_FOLLOWLINKS(
@ -64,35 +130,41 @@
//usage: "\n -n List numeric UIDs and GIDs instead of names"
//usage: "\n -s List allocated blocks"
//usage: IF_FEATURE_LS_TIMESTAMPS(
//usage: "\n -e List full date and time"
//usage: "\n -lc List ctime"
//usage: "\n -lu List atime"
//usage: )
//usage: IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(
//usage: "\n --full-time List full date and time"
//usage: ))
//usage: IF_FEATURE_HUMAN_READABLE(
//usage: "\n -h List sizes in human readable format (1K 243M 2G)"
//usage: "\n -h Human readable sizes (1K 243M 2G)"
//usage: )
//usage: IF_FEATURE_LS_SORTFILES(
//usage: "\n -r Sort in reverse order"
//usage: IF_LONG_OPTS(
//usage: "\n --group-directories-first"
//usage: )
//usage: "\n -S Sort by size"
//usage: "\n -X Sort by extension"
//usage: "\n -v Sort by version"
//usage: )
//usage: IF_FEATURE_LS_TIMESTAMPS(
//usage: "\n -c With -l: sort by ctime"
//usage: "\n -t With -l: sort by mtime"
//usage: "\n -u With -l: sort by atime"
//usage: "\n -t Sort by mtime"
//usage: "\n -tc Sort by ctime"
//usage: "\n -tu Sort by atime"
//usage: )
//usage: "\n -r Reverse sort order"
//usage: IF_SELINUX(
//usage: "\n -k List security context"
//usage: "\n -K List security context in long format"
//usage: "\n -Z List security context and permission"
//usage: )
//usage: IF_FEATURE_AUTOWIDTH(
//usage: "\n -w N Assume the terminal is N columns wide"
//usage: IF_FEATURE_LS_WIDTH(
//usage: "\n -w N Format N columns wide"
//usage: )
//usage: IF_FEATURE_LS_COLOR(
//usage: "\n --color[={always,never,auto}] Control coloring"
//usage: )
#include "libbb.h"
#include "common_bufsiz.h"
#include "unicode.h"
@ -120,187 +192,90 @@ TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */
SPLIT_FILE = 0,
SPLIT_DIR = 1,
SPLIT_SUBDIR = 2,
/* Bits in G.all_fmt: */
/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */
/* what file information will be listed */
LIST_INO = 1 << 0,
LIST_BLOCKS = 1 << 1,
LIST_MODEBITS = 1 << 2,
LIST_NLINKS = 1 << 3,
LIST_ID_NAME = 1 << 4,
LIST_ID_NUMERIC = 1 << 5,
LIST_CONTEXT = 1 << 6,
LIST_SIZE = 1 << 7,
LIST_DATE_TIME = 1 << 8,
LIST_FULLTIME = 1 << 9,
LIST_SYMLINK = 1 << 10,
LIST_FILETYPE = 1 << 11, /* show / suffix for dirs */
LIST_CLASSIFY = 1 << 12, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */
LIST_MASK = (LIST_CLASSIFY << 1) - 1,
/* what files will be displayed */
DISP_DIRNAME = 1 << 13, /* 2 or more items? label directories */
DISP_HIDDEN = 1 << 14, /* show filenames starting with . */
DISP_DOT = 1 << 15, /* show . and .. */
DISP_NOLIST = 1 << 16, /* show directory as itself, not contents */
DISP_RECURSIVE = 1 << 17, /* show directory and everything below it */
DISP_ROWS = 1 << 18, /* print across rows */
DISP_MASK = ((DISP_ROWS << 1) - 1) & ~(DISP_DIRNAME - 1),
/* what is the overall style of the listing */
STYLE_COLUMNAR = 1 << 19, /* many records per line */
STYLE_LONG = 2 << 19, /* one record per line, extended info */
STYLE_SINGLE = 3 << 19, /* one record per line */
STYLE_MASK = STYLE_SINGLE,
/* which of the three times will be used */
TIME_CHANGE = (1 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
TIME_ACCESS = (2 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
TIME_MASK = (3 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
/* how will the files be sorted (CONFIG_FEATURE_LS_SORTFILES) */
SORT_REVERSE = 1 << 23,
SORT_NAME = 0, /* sort by file name */
SORT_SIZE = 1 << 24, /* sort by file size */
SORT_ATIME = 2 << 24, /* sort by last access time */
SORT_CTIME = 3 << 24, /* sort by last change time */
SORT_MTIME = 4 << 24, /* sort by last modification time */
SORT_VERSION = 5 << 24, /* sort by version */
SORT_EXT = 6 << 24, /* sort by file name extension */
SORT_DIR = 7 << 24, /* sort by file or directory */
SORT_MASK = (7 << 24) * ENABLE_FEATURE_LS_SORTFILES,
LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \
LIST_DATE_TIME | LIST_SYMLINK,
};
/* -Cadil1 Std options, busybox always supports */
/* -Cadi1l Std options, busybox always supports */
/* -gnsxA Std options, busybox always supports */
/* -Q GNU option, busybox always supports */
/* -k SELinux option, busybox always supports (ignores if !SELinux) */
/* Std has -k which means "show sizes in kbytes" */
/* -k Std option, busybox always supports (by ignoring) */
/* It means "for -s, show sizes in kbytes" */
/* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */
/* since otherwise -s shows kbytes anyway */
/* -LHRctur Std options, busybox optionally supports */
/* -Fp Std options, busybox optionally supports */
/* -SXvhTw GNU options, busybox optionally supports */
/* -T WIDTH Ignored (we don't use tabs on output) */
/* -KZ SELinux mandated options, busybox optionally supports */
/* (coreutils 8.4 has no -K, remove it?) */
/* -e I think we made this one up (looks similar to GNU --full-time) */
/* We already used up all 32 bits, if we need to add more, candidates for removal: */
/* -K, -T, -e (add --full-time instead) */
/* -Z SELinux mandated option, busybox optionally supports */
static const char ls_options[] ALIGN1 =
"Cadil1gnsxQAk" /* 13 opts, total 13 */
IF_FEATURE_LS_TIMESTAMPS("cetu") /* 4, 17 */
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 21 */
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 23 */
IF_FEATURE_LS_RECURSIVE("R") /* 1, 24 */
IF_SELINUX("KZ") /* 2, 26 */
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 28 */
IF_FEATURE_HUMAN_READABLE("h") /* 1, 29 */
IF_FEATURE_AUTOWIDTH("T:w:") /* 2, 31 */
/* with --color, we use all 32 bits */;
"Cadi1lgnsxAk" /* 12 opts, total 12 */
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */
IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */
IF_SELINUX("Z") /* 1, 16 */
"Q" /* 1, 17 */
IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */
IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */
IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */
;
enum {
//OPT_C = (1 << 0),
//OPT_a = (1 << 1),
//OPT_d = (1 << 2),
//OPT_i = (1 << 3),
//OPT_l = (1 << 4),
//OPT_1 = (1 << 5),
OPT_C = (1 << 0),
OPT_a = (1 << 1),
OPT_d = (1 << 2),
OPT_i = (1 << 3),
OPT_1 = (1 << 4),
OPT_l = (1 << 5),
OPT_g = (1 << 6),
//OPT_n = (1 << 7),
//OPT_s = (1 << 8),
//OPT_x = (1 << 9),
OPT_Q = (1 << 10),
//OPT_A = (1 << 11),
//OPT_k = (1 << 12),
OPT_n = (1 << 7),
OPT_s = (1 << 8),
OPT_x = (1 << 9),
OPT_A = (1 << 10),
//OPT_k = (1 << 11),
OPTBIT_c = 13,
OPTBIT_e,
OPTBIT_t,
OPTBIT_u,
OPTBIT_S = OPTBIT_c + 4 * ENABLE_FEATURE_LS_TIMESTAMPS,
OPTBIT_X, /* 18 */
OPTBIT_r,
OPTBIT_v,
OPTBIT_F = OPTBIT_S + 4 * ENABLE_FEATURE_LS_SORTFILES,
OPTBIT_p, /* 22 */
OPTBIT_F = 12,
OPTBIT_p, /* 13 */
OPTBIT_R = OPTBIT_F + 2 * ENABLE_FEATURE_LS_FILETYPES,
OPTBIT_K = OPTBIT_R + 1 * ENABLE_FEATURE_LS_RECURSIVE,
OPTBIT_Z, /* 25 */
OPTBIT_L = OPTBIT_K + 2 * ENABLE_SELINUX,
OPTBIT_H, /* 27 */
OPTBIT_Z = OPTBIT_R + 1 * ENABLE_FEATURE_LS_RECURSIVE,
OPTBIT_Q = OPTBIT_Z + 1 * ENABLE_SELINUX,
OPTBIT_c, /* 17 */
OPTBIT_t, /* 18 */
OPTBIT_u, /* 19 */
OPTBIT_S = OPTBIT_c + 3 * ENABLE_FEATURE_LS_TIMESTAMPS,
OPTBIT_X, /* 21 */
OPTBIT_r, /* 22 */
OPTBIT_v, /* 23 */
OPTBIT_L = OPTBIT_S + 4 * ENABLE_FEATURE_LS_SORTFILES,
OPTBIT_H, /* 25 */
OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS,
OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE,
OPTBIT_w, /* 30 */
OPTBIT_color = OPTBIT_T + 2 * ENABLE_FEATURE_AUTOWIDTH,
OPTBIT_w, /* 28 */
OPTBIT_full_time = OPTBIT_T + 2 * ENABLE_FEATURE_LS_WIDTH,
OPTBIT_dirs_first,
OPTBIT_color, /* 31 */
/* with long opts, we use all 32 bits */
OPT_F = (1 << OPTBIT_F) * ENABLE_FEATURE_LS_FILETYPES,
OPT_p = (1 << OPTBIT_p) * ENABLE_FEATURE_LS_FILETYPES,
OPT_R = (1 << OPTBIT_R) * ENABLE_FEATURE_LS_RECURSIVE,
OPT_Z = (1 << OPTBIT_Z) * ENABLE_SELINUX,
OPT_Q = (1 << OPTBIT_Q),
OPT_c = (1 << OPTBIT_c) * ENABLE_FEATURE_LS_TIMESTAMPS,
OPT_e = (1 << OPTBIT_e) * ENABLE_FEATURE_LS_TIMESTAMPS,
OPT_t = (1 << OPTBIT_t) * ENABLE_FEATURE_LS_TIMESTAMPS,
OPT_u = (1 << OPTBIT_u) * ENABLE_FEATURE_LS_TIMESTAMPS,
OPT_S = (1 << OPTBIT_S) * ENABLE_FEATURE_LS_SORTFILES,
OPT_X = (1 << OPTBIT_X) * ENABLE_FEATURE_LS_SORTFILES,
OPT_r = (1 << OPTBIT_r) * ENABLE_FEATURE_LS_SORTFILES,
OPT_v = (1 << OPTBIT_v) * ENABLE_FEATURE_LS_SORTFILES,
OPT_F = (1 << OPTBIT_F) * ENABLE_FEATURE_LS_FILETYPES,
OPT_p = (1 << OPTBIT_p) * ENABLE_FEATURE_LS_FILETYPES,
OPT_R = (1 << OPTBIT_R) * ENABLE_FEATURE_LS_RECURSIVE,
OPT_K = (1 << OPTBIT_K) * ENABLE_SELINUX,
OPT_Z = (1 << OPTBIT_Z) * ENABLE_SELINUX,
OPT_L = (1 << OPTBIT_L) * ENABLE_FEATURE_LS_FOLLOWLINKS,
OPT_H = (1 << OPTBIT_H) * ENABLE_FEATURE_LS_FOLLOWLINKS,
OPT_h = (1 << OPTBIT_h) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_T = (1 << OPTBIT_T) * ENABLE_FEATURE_AUTOWIDTH,
OPT_w = (1 << OPTBIT_w) * ENABLE_FEATURE_AUTOWIDTH,
OPT_color = (1 << OPTBIT_color) * ENABLE_FEATURE_LS_COLOR,
OPT_T = (1 << OPTBIT_T) * ENABLE_FEATURE_LS_WIDTH,
OPT_w = (1 << OPTBIT_w) * ENABLE_FEATURE_LS_WIDTH,
OPT_full_time = (1 << OPTBIT_full_time ) * ENABLE_LONG_OPTS,
OPT_dirs_first = (1 << OPTBIT_dirs_first) * ENABLE_LONG_OPTS,
OPT_color = (1 << OPTBIT_color ) * ENABLE_FEATURE_LS_COLOR,
};
/* TODO: simple toggles may be stored as OPT_xxx bits instead */
static const uint32_t opt_flags[] = {
STYLE_COLUMNAR, /* C */
DISP_HIDDEN | DISP_DOT, /* a */
DISP_NOLIST, /* d */
LIST_INO, /* i */
LIST_LONG | STYLE_LONG, /* l */
STYLE_SINGLE, /* 1 */
LIST_LONG | STYLE_LONG, /* g (don't show owner) - handled via OPT_g. assumes l */
LIST_ID_NUMERIC | LIST_LONG | STYLE_LONG, /* n (assumes l) */
LIST_BLOCKS, /* s */
DISP_ROWS | STYLE_COLUMNAR, /* x */
0, /* Q (quote filename) - handled via OPT_Q */
DISP_HIDDEN, /* A */
ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */
#if ENABLE_FEATURE_LS_TIMESTAMPS
TIME_CHANGE | (ENABLE_FEATURE_LS_SORTFILES * SORT_CTIME), /* c */
LIST_FULLTIME, /* e */
ENABLE_FEATURE_LS_SORTFILES * SORT_MTIME, /* t */
TIME_ACCESS | (ENABLE_FEATURE_LS_SORTFILES * SORT_ATIME), /* u */
#endif
#if ENABLE_FEATURE_LS_SORTFILES
SORT_SIZE, /* S */
SORT_EXT, /* X */
SORT_REVERSE, /* r */
SORT_VERSION, /* v */
#endif
#if ENABLE_FEATURE_LS_FILETYPES
LIST_FILETYPE | LIST_CLASSIFY, /* F */
LIST_FILETYPE, /* p */
#endif
#if ENABLE_FEATURE_LS_RECURSIVE
DISP_RECURSIVE, /* R */
#endif
#if ENABLE_SELINUX
LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME|STYLE_SINGLE, /* K */
LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT|STYLE_SINGLE, /* Z */
#endif
(1U << 31)
/* options after Z are not processed through opt_flags */
};
/*
* a directory entry and its stat info
*/
@ -330,9 +305,7 @@ struct dnode {
mode_t dn_mode; /* obtained with lstat OR stat, depending on -L etc */
off_t dn_size;
#if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES
time_t dn_atime;
time_t dn_mtime;
time_t dn_ctime;
time_t dn_time;
#endif
ino_t dn_ino;
blkcnt_t dn_blocks;
@ -353,8 +326,8 @@ struct globals {
# define G_show_color 0
#endif
smallint exit_code;
unsigned all_fmt;
#if ENABLE_FEATURE_AUTOWIDTH
smallint show_dirname;
#if ENABLE_FEATURE_LS_WIDTH
unsigned terminal_width;
# define G_terminal_width (G.terminal_width)
#else
@ -365,11 +338,12 @@ struct globals {
time_t current_time_t;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
IF_FEATURE_AUTOWIDTH(G_terminal_width = TERMINAL_WIDTH;) \
IF_FEATURE_LS_WIDTH(G_terminal_width = TERMINAL_WIDTH;) \
IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
} while (0)
@ -426,11 +400,12 @@ static char bold(mode_t mode)
#if ENABLE_FEATURE_LS_FILETYPES
static char append_char(mode_t mode)
{
if (!(G.all_fmt & LIST_FILETYPE))
if (!(option_mask32 & (OPT_F|OPT_p)))
return '\0';
if (S_ISDIR(mode))
return '/';
if (!(G.all_fmt & LIST_CLASSIFY))
if (!(option_mask32 & OPT_F))
return '\0';
if (S_ISREG(mode) && (mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
return '*';
@ -461,8 +436,8 @@ static unsigned calc_name_len(const char *name)
}
/* Return the number of used columns.
* Note that only STYLE_COLUMNAR uses return value.
* STYLE_SINGLE and STYLE_LONG don't care.
* Note that only columnar output uses return value.
* -l and -1 modes don't care.
* coreutils 7.2 also supports:
* ls -b (--escape) = octal escapes (although it doesn't look like working)
* ls -N (--literal) = not escape at all
@ -495,13 +470,14 @@ static unsigned print_name(const char *name)
}
/* Return the number of used columns.
* Note that only STYLE_COLUMNAR uses return value,
* STYLE_SINGLE and STYLE_LONG don't care.
* Note that only columnar output uses return value,
* -l and -1 modes don't care.
*/
static NOINLINE unsigned display_single(const struct dnode *dn)
{
unsigned column = 0;
char *lpath;
int opt;
#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
struct stat statbuf;
char append;
@ -510,50 +486,61 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
#if ENABLE_FEATURE_LS_FILETYPES
append = append_char(dn->dn_mode);
#endif
opt = option_mask32;
/* Do readlink early, so that if it fails, error message
* does not appear *inside* the "ls -l" line */
lpath = NULL;
if (G.all_fmt & LIST_SYMLINK)
if (opt & OPT_l)
if (S_ISLNK(dn->dn_mode))
lpath = xmalloc_readlink_or_warn(dn->fullname);
if (G.all_fmt & LIST_INO)
if (opt & OPT_i) /* show inode# */
column += printf("%7llu ", (long long) dn->dn_ino);
//TODO: -h should affect -s too:
if (G.all_fmt & LIST_BLOCKS)
if (opt & OPT_s) /* show allocated blocks */
column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
if (G.all_fmt & LIST_MODEBITS)
if (opt & OPT_l) {
/* long listing: show mode */
column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode));
if (G.all_fmt & LIST_NLINKS)
/* long listing: show number of links */
column += printf("%4lu ", (long) dn->dn_nlink);
if (G.all_fmt & LIST_ID_NUMERIC) {
if (option_mask32 & OPT_g)
column += printf("%-8u ", (int) dn->dn_gid);
else
column += printf("%-8u %-8u ",
(int) dn->dn_uid,
(int) dn->dn_gid);
}
#if ENABLE_FEATURE_LS_USERNAME
else if (G.all_fmt & LIST_ID_NAME) {
if (option_mask32 & OPT_g) {
column += printf("%-8.8s ",
get_cached_groupname(dn->dn_gid));
} else {
column += printf("%-8.8s %-8.8s ",
get_cached_username(dn->dn_uid),
get_cached_groupname(dn->dn_gid));
/* long listing: show user/group */
if (opt & OPT_n) {
if (opt & OPT_g)
column += printf("%-8u ", (int) dn->dn_gid);
else
column += printf("%-8u %-8u ",
(int) dn->dn_uid,
(int) dn->dn_gid);
}
#if ENABLE_FEATURE_LS_USERNAME
else {
if (opt & OPT_g) {
column += printf("%-8.8s ",
get_cached_groupname(dn->dn_gid));
} else {
column += printf("%-8.8s %-8.8s ",
get_cached_username(dn->dn_uid),
get_cached_groupname(dn->dn_gid));
}
}
}
#endif
if (G.all_fmt & LIST_SIZE) {
#if ENABLE_SELINUX
}
if (opt & OPT_Z) {
column += printf("%-32s ", dn->sid ? dn->sid : "?");
freecon(dn->sid);
}
if (opt & OPT_l) {
#endif
/* long listing: show size */
if (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) {
column += printf("%4u, %3u ",
dn->dn_rdev_maj,
dn->dn_rdev_min);
} else {
if (option_mask32 & OPT_h) {
if (opt & OPT_h) {
column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ",
/* print size, show one fractional, use suffixes */
make_human_readable_str(dn->dn_size, 1, 0)
@ -562,25 +549,22 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
column += printf("%9"OFF_FMT"u ", dn->dn_size);
}
}
}
#if ENABLE_FEATURE_LS_TIMESTAMPS
if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) {
char *filetime;
const time_t *ttime = &dn->dn_mtime;
if (G.all_fmt & TIME_ACCESS)
ttime = &dn->dn_atime;
if (G.all_fmt & TIME_CHANGE)
ttime = &dn->dn_ctime;
filetime = ctime(ttime);
/* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
if (G.all_fmt & LIST_FULLTIME) { /* -e */
/* Note: coreutils 8.4 ls --full-time prints:
/* long listing: show {m,c,a}time */
if (opt & OPT_full_time) { /* --full-time */
/* coreutils 8.4 ls --full-time prints:
* 2009-07-13 17:49:27.000000000 +0200
* we don't show fractional seconds.
*/
column += printf("%.24s ", filetime);
} else { /* LIST_DATE_TIME */
/* G.current_time_t ~== time(NULL) */
time_t age = G.current_time_t - *ttime;
char buf[sizeof("YYYY-mm-dd HH:MM:SS TIMEZONE")];
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z",
localtime(&dn->dn_time));
column += printf("%s ", buf);
} else { /* ordinary time format */
/* G.current_time_t is ~== time(NULL) */
char *filetime = ctime(&dn->dn_time);
/* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
time_t age = G.current_time_t - dn->dn_time;
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
/* less than 6 months old */
/* "mmm dd hh:mm " */
@ -593,14 +577,8 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
}
column += 13;
}
}
#endif
#if ENABLE_SELINUX
if (G.all_fmt & LIST_CONTEXT) {
column += printf("%-32s ", dn->sid ? dn->sid : "unknown");
freecon(dn->sid);
}
#endif
#if ENABLE_FEATURE_LS_COLOR
if (G_show_color) {
@ -619,7 +597,9 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
if (lpath) {
printf(" -> ");
#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
if ((G.all_fmt & LIST_FILETYPE) || G_show_color) {
if ((opt & (OPT_F|OPT_p))
|| G_show_color
) {
mode_t mode = dn->dn_mode_stat;
if (!mode)
if (stat(dn->fullname, &statbuf) == 0)
@ -641,7 +621,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
}
}
#if ENABLE_FEATURE_LS_FILETYPES
if (G.all_fmt & LIST_FILETYPE) {
if (opt & (OPT_F|OPT_p)) {
if (append) {
putchar(append);
column++;
@ -657,9 +637,9 @@ static void display_files(struct dnode **dn, unsigned nfiles)
unsigned i, ncols, nrows, row, nc;
unsigned column;
unsigned nexttab;
unsigned column_width = 0; /* used only by STYLE_COLUMNAR */
unsigned column_width = 0; /* used only by coulmnal output */
if (G.all_fmt & STYLE_LONG) { /* STYLE_LONG or STYLE_SINGLE */
if (option_mask32 & (OPT_l|OPT_1)) {
ncols = 1;
} else {
/* find the longest file name, use that as the column width */
@ -668,10 +648,11 @@ static void display_files(struct dnode **dn, unsigned nfiles)
if (column_width < len)
column_width = len;
}
column_width += 1 +
IF_SELINUX( ((G.all_fmt & LIST_CONTEXT) ? 33 : 0) + )
((G.all_fmt & LIST_INO) ? 8 : 0) +
((G.all_fmt & LIST_BLOCKS) ? 5 : 0);
column_width += 2
+ ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */
+ ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */
+ ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */
;
ncols = (unsigned)G_terminal_width / column_width;
}
@ -689,15 +670,15 @@ static void display_files(struct dnode **dn, unsigned nfiles)
for (row = 0; row < nrows; row++) {
for (nc = 0; nc < ncols; nc++) {
/* reach into the array based on the column and row */
if (G.all_fmt & DISP_ROWS)
if (option_mask32 & OPT_x)
i = (row * ncols) + nc; /* display across row */
else
i = (nc * nrows) + row; /* display by column */
if (i < nfiles) {
if (column > 0) {
nexttab -= column;
printf("%*s ", nexttab, "");
column += nexttab + 1;
printf("%*s", nexttab, "");
column += nexttab;
}
nexttab = column + column_width;
column += display_single(dn[i]);
@ -722,7 +703,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
if ((option_mask32 & OPT_L) || force_follow) {
#if ENABLE_SELINUX
if (is_selinux_enabled()) {
if (option_mask32 & OPT_Z) {
getfilecon(fullname, &cur->sid);
}
#endif
@ -735,7 +716,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
cur->dn_mode_stat = statbuf.st_mode;
} else {
#if ENABLE_SELINUX
if (is_selinux_enabled()) {
if (option_mask32 & OPT_Z) {
lgetfilecon(fullname, &cur->sid);
}
#endif
@ -752,9 +733,11 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
cur->dn_mode = statbuf.st_mode ;
cur->dn_size = statbuf.st_size ;
#if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES
cur->dn_atime = statbuf.st_atime ;
cur->dn_mtime = statbuf.st_mtime ;
cur->dn_ctime = statbuf.st_ctime ;
cur->dn_time = statbuf.st_mtime ;
if (option_mask32 & OPT_u)
cur->dn_time = statbuf.st_atime;
if (option_mask32 & OPT_c)
cur->dn_time = statbuf.st_ctime;
#endif
cur->dn_ino = statbuf.st_ino ;
cur->dn_blocks = statbuf.st_blocks;
@ -868,33 +851,30 @@ static int sortcmp(const void *a, const void *b)
{
struct dnode *d1 = *(struct dnode **)a;
struct dnode *d2 = *(struct dnode **)b;
unsigned sort_opts = G.all_fmt & SORT_MASK;
unsigned opt = option_mask32;
off_t dif;
dif = 0; /* assume SORT_NAME */
dif = 0; /* assume sort by name */
// TODO: use pre-initialized function pointer
// instead of branch forest
if (sort_opts == SORT_SIZE) {
if (opt & OPT_dirs_first) {
dif = S_ISDIR(d2->dn_mode) - S_ISDIR(d1->dn_mode);
if (dif != 0)
goto maybe_invert_and_ret;
}
if (opt & OPT_S) { /* sort by size */
dif = (d2->dn_size - d1->dn_size);
} else
if (sort_opts == SORT_ATIME) {
dif = (d2->dn_atime - d1->dn_atime);
} else
if (sort_opts == SORT_CTIME) {
dif = (d2->dn_ctime - d1->dn_ctime);
} else
if (sort_opts == SORT_MTIME) {
dif = (d2->dn_mtime - d1->dn_mtime);
} else
if (sort_opts == SORT_DIR) {
dif = S_ISDIR(d2->dn_mode) - S_ISDIR(d1->dn_mode);
if (opt & OPT_t) { /* sort by time */
dif = (d2->dn_time - d1->dn_time);
} else
#if defined(HAVE_STRVERSCMP) && HAVE_STRVERSCMP == 1
if (sort_opts == SORT_VERSION) {
if (opt & OPT_v) { /* sort by version */
dif = strverscmp(d1->name, d2->name);
} else
#endif
if (sort_opts == SORT_EXT) {
if (opt & OPT_X) { /* sort by extension */
dif = strcmp(strchrnul(d1->name, '.'), strchrnul(d2->name, '.'));
}
if (dif == 0) {
@ -903,18 +883,17 @@ static int sortcmp(const void *a, const void *b)
dif = strcoll(d1->name, d2->name);
else
dif = strcmp(d1->name, d2->name);
}
/* Make dif fit into an int */
if (sizeof(dif) > sizeof(int)) {
enum { BITS_TO_SHIFT = 8 * (sizeof(dif) - sizeof(int)) };
/* shift leaving only "int" worth of bits */
if (dif != 0) {
} else {
/* Make dif fit into an int */
if (sizeof(dif) > sizeof(int)) {
enum { BITS_TO_SHIFT = 8 * (sizeof(dif) - sizeof(int)) };
/* shift leaving only "int" worth of bits */
/* (this requires dif != 0, and here it is nonzero) */
dif = 1 | (int)((uoff_t)dif >> BITS_TO_SHIFT);
}
}
return (G.all_fmt & SORT_REVERSE) ? -(int)dif : (int)dif;
maybe_invert_and_ret:
return (opt & OPT_r) ? -(int)dif : (int)dif;
}
static void dnsort(struct dnode **dn, int size)
@ -953,13 +932,13 @@ static struct dnode **scan_one_dir(const char *path, unsigned *nfiles_p)
/* are we going to list the file- it may be . or .. or a hidden file */
if (entry->d_name[0] == '.') {
if ((!entry->d_name[1] || (entry->d_name[1] == '.' && !entry->d_name[2]))
&& !(G.all_fmt & DISP_DOT)
if (!(option_mask32 & (OPT_a|OPT_A)))
continue; /* skip all dotfiles if no -a/-A */
if (!(option_mask32 & OPT_a)
&& (!entry->d_name[1] || (entry->d_name[1] == '.' && !entry->d_name[2]))
) {
continue;
continue; /* if only -A, skip . and .. but show other dotfiles */
}
if (!(G.all_fmt & DISP_HIDDEN))
continue;
}
fullname = concat_path_file(path, entry->d_name);
cur = my_stat(fullname, bb_basename(fullname), 0);
@ -1027,7 +1006,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
struct dnode **subdnp;
for (; *dn; dn++) {
if (G.all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
if (G.show_dirname || (option_mask32 & OPT_R)) {
if (!first)
bb_putchar('\n');
first = 0;
@ -1035,15 +1014,16 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
}
subdnp = scan_one_dir((*dn)->fullname, &nfiles);
#if ENABLE_DESKTOP
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS))
if (option_mask32 & (OPT_s|OPT_l)) {
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
}
#endif
if (nfiles > 0) {
/* list all files at this level */
sort_and_display_files(subdnp, nfiles);
if (ENABLE_FEATURE_LS_RECURSIVE
&& (G.all_fmt & DISP_RECURSIVE)
&& (option_mask32 & OPT_R)
) {
struct dnode **dnd;
unsigned dndirs;
@ -1065,7 +1045,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
int ls_main(int argc UNUSED_PARAM, char **argv)
{
{ /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */
struct dnode **dnd;
struct dnode **dnf;
struct dnode **dnp;
@ -1087,34 +1067,38 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
* 'auto', 'tty', 'if-tty'
* (and substrings: "--color=alwa" work too)
*/
static const char ls_longopts[] ALIGN1 =
"color\0" Optional_argument "\xff"; /* no short equivalent */
static const char color_str[] ALIGN1 =
"always\0""yes\0""force\0"
"auto\0""tty\0""if-tty\0";
/* need to initialize since --color has _an optional_ argument */
const char *color_opt = color_str; /* "always" */
#endif
#if ENABLE_LONG_OPTS
static const char ls_longopts[] ALIGN1 =
"full-time\0" No_argument "\xff"
"group-directories-first\0" No_argument "\xfe"
"color\0" Optional_argument "\xfd"
;
#endif
INIT_G();
init_unicode();
if (ENABLE_FEATURE_LS_SORTFILES)
G.all_fmt = SORT_NAME;
#if ENABLE_FEATURE_AUTOWIDTH
#if ENABLE_FEATURE_LS_WIDTH
/* obtain the terminal width */
get_terminal_width_height(STDIN_FILENO, &G_terminal_width, NULL);
G_terminal_width = get_terminal_width(STDIN_FILENO);
/* go one less... */
G_terminal_width--;
#endif
/* process options */
IF_FEATURE_LS_COLOR(applet_long_options = ls_longopts;)
IF_LONG_OPTS(applet_long_options = ls_longopts;)
opt_complementary =
/* -e implies -l */
IF_FEATURE_LS_TIMESTAMPS("el")
/* -n and -g imply -l */
"nl:gl"
/* --full-time implies -l */
IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l"))
/* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html:
* in some pairs of opts, only last one takes effect:
*/
@ -1126,25 +1110,28 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */
IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */
/* -w NUM: */
IF_FEATURE_AUTOWIDTH(":w+");
IF_FEATURE_LS_WIDTH(":w+");
opt = getopt32(argv, ls_options
IF_FEATURE_AUTOWIDTH(, NULL, &G_terminal_width)
IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width)
IF_FEATURE_LS_COLOR(, &color_opt)
);
for (i = 0; opt_flags[i] != (1U << 31); i++) {
if (opt & (1 << i)) {
uint32_t flags = opt_flags[i];
#if 0 /* option bits debug */
bb_error_msg("opt:0x%08x l:%x H:%x color:%x dirs:%x", opt, OPT_l, OPT_H, OPT_color, OPT_dirs_first);
if (opt & OPT_c ) bb_error_msg("-c");
if (opt & OPT_l ) bb_error_msg("-l");
if (opt & OPT_H ) bb_error_msg("-H");
if (opt & OPT_color ) bb_error_msg("--color");
if (opt & OPT_dirs_first) bb_error_msg("--group-directories-first");
if (opt & OPT_full_time ) bb_error_msg("--full-time");
exit(0);
#endif
if (flags & STYLE_MASK)
G.all_fmt &= ~STYLE_MASK;
if (flags & SORT_MASK)
G.all_fmt &= ~SORT_MASK;
if (flags & TIME_MASK)
G.all_fmt &= ~TIME_MASK;
G.all_fmt |= flags;
}
#if ENABLE_SELINUX
if (opt & OPT_Z) {
if (!is_selinux_enabled())
option_mask32 &= ~OPT_Z;
}
#endif
#if ENABLE_FEATURE_LS_COLOR
/* set G_show_color = 1/0 */
@ -1172,27 +1159,35 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
#endif
/* sort out which command line options take precedence */
if (ENABLE_FEATURE_LS_RECURSIVE && (G.all_fmt & DISP_NOLIST))
G.all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */
if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) {
if (G.all_fmt & TIME_CHANGE)
G.all_fmt = (G.all_fmt & ~SORT_MASK) | SORT_CTIME;
if (G.all_fmt & TIME_ACCESS)
G.all_fmt = (G.all_fmt & ~SORT_MASK) | SORT_ATIME;
if (ENABLE_FEATURE_LS_RECURSIVE && (opt & OPT_d))
option_mask32 &= ~OPT_R; /* no recurse if listing only dir */
if (!(opt & OPT_l)) { /* not -l? */
if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) {
/* when to sort by time? -t[cu] sorts by time even with -l */
/* (this is achieved by opt_flags[] element for -t) */
/* without -l, bare -c or -u enable sort too */
/* (with -l, bare -c or -u just select which time to show) */
if (opt & (OPT_c|OPT_u)) {
option_mask32 |= OPT_t;
}
}
}
if ((G.all_fmt & STYLE_MASK) != STYLE_LONG) /* not -l? */
G.all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME|LIST_FULLTIME);
/* choose a display format if one was not already specified by an option */
if (!(G.all_fmt & STYLE_MASK))
G.all_fmt |= (isatty(STDOUT_FILENO) ? STYLE_COLUMNAR : STYLE_SINGLE);
if (!(option_mask32 & (OPT_l|OPT_1|OPT_x|OPT_C)))
option_mask32 |= (isatty(STDOUT_FILENO) ? OPT_C : OPT_1);
if (ENABLE_FTPD && applet_name[0] == 'f') {
/* ftpd secret backdoor. dirs first are much nicer */
option_mask32 |= OPT_dirs_first;
}
argv += optind;
if (!argv[0])
*--argv = (char*)".";
if (argv[1])
G.all_fmt |= DISP_DIRNAME; /* 2 or more items? label directories */
G.show_dirname = 1; /* 2 or more items? label directories */
/* stuff the command line file names into a dnode array */
dn = NULL;
@ -1200,10 +1195,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
do {
cur = my_stat(*argv, *argv,
/* follow links on command line unless -l, -s or -F: */
!((G.all_fmt & STYLE_MASK) == STYLE_LONG
|| (G.all_fmt & LIST_BLOCKS)
|| (option_mask32 & OPT_F)
)
!(option_mask32 & (OPT_l|OPT_s|OPT_F))
/* ... or if -H: */
|| (option_mask32 & OPT_H)
/* ... or if -L, but my_stat always follows links if -L */
@ -1232,7 +1224,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
break;
}
if (G.all_fmt & DISP_NOLIST) {
if (option_mask32 & OPT_d) {
sort_and_display_files(dnp, nfiles);
} else {
dnd = splitdnarray(dnp, SPLIT_DIR);

View File

@ -5,6 +5,59 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config MD5SUM
//config: bool "md5sum"
//config: default y
//config: help
//config: md5sum is used to print or check MD5 checksums.
//config:
//config:config SHA1SUM
//config: bool "sha1sum"
//config: default y
//config: help
//config: Compute and check SHA1 message digest
//config:
//config:config SHA256SUM
//config: bool "sha256sum"
//config: default y
//config: help
//config: Compute and check SHA256 message digest
//config:
//config:config SHA512SUM
//config: bool "sha512sum"
//config: default y
//config: help
//config: Compute and check SHA512 message digest
//config:
//config:config SHA3SUM
//config: bool "sha3sum"
//config: default y
//config: help
//config: Compute and check SHA3 message digest
//config:
//config:comment "Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum"
//config: depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM
//config:
//config:config FEATURE_MD5_SHA1_SUM_CHECK
//config: bool "Enable -c, -s and -w options"
//config: default y
//config: depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM
//config: help
//config: Enabling the -c options allows files to be checked
//config: against pre-calculated hash values.
//config: -s and -w are useful options when verifying checksums.
//applet:IF_MD5SUM(APPLET_NOEXEC(md5sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, md5sum))
//applet:IF_SHA1SUM(APPLET_NOEXEC(sha1sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha1sum))
//applet:IF_SHA3SUM(APPLET_NOEXEC(sha3sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha3sum))
//applet:IF_SHA256SUM(APPLET_NOEXEC(sha256sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha256sum))
//applet:IF_SHA512SUM(APPLET_NOEXEC(sha512sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha512sum))
//kbuild:lib-$(CONFIG_MD5SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA256SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA512SUM) += md5_sha1_sum.o
//kbuild:lib-$(CONFIG_SHA3SUM) += md5_sha1_sum.o
//usage:#define md5sum_trivial_usage
//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..."
@ -57,15 +110,20 @@
//usage: )
//usage:
//usage:#define sha3sum_trivial_usage
//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[FILE]..."
//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK("[-c[sw]] ")"[-a BITS] [FILE]..."
//usage:#define sha3sum_full_usage "\n\n"
//usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA3-512 checksums"
//usage: "Print" IF_FEATURE_MD5_SHA1_SUM_CHECK(" or check") " SHA3 checksums"
//usage: IF_FEATURE_MD5_SHA1_SUM_CHECK( "\n"
//usage: "\n -c Check sums against list in FILEs"
//usage: "\n -s Don't output anything, status code shows success"
//usage: "\n -w Warn about improperly formatted checksum lines"
//usage: "\n -a BITS 224 (default), 256, 384, 512"
//usage: )
//FIXME: GNU coreutils 8.25 has no -s option, it has only these two long opts:
// --quiet don't print OK for each successfully verified file
// --status don't output anything, status code shows success
#include "libbb.h"
/* This is a NOEXEC applet. Be very careful! */
@ -93,7 +151,10 @@ static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
return (unsigned char *)hex_value;
}
static uint8_t *hash_file(const char *filename)
#if !ENABLE_SHA3SUM
# define hash_file(f,w) hash_file(f)
#endif
static uint8_t *hash_file(const char *filename, unsigned sha3_width)
{
int src_fd, hash_len, count;
union _ctx_ {
@ -105,7 +166,7 @@ static uint8_t *hash_file(const char *filename)
} context;
uint8_t *hash_value;
void FAST_FUNC (*update)(void*, const void*, size_t);
void FAST_FUNC (*final)(void*, void*);
unsigned FAST_FUNC (*final)(void*, void*);
char hash_algo;
src_fd = open_or_warn_stdin(filename);
@ -121,27 +182,47 @@ static uint8_t *hash_file(const char *filename)
update = (void*)md5_hash;
final = (void*)md5_end;
hash_len = 16;
} else if (ENABLE_SHA1SUM && hash_algo == HASH_SHA1) {
}
else if (ENABLE_SHA1SUM && hash_algo == HASH_SHA1) {
sha1_begin(&context.sha1);
update = (void*)sha1_hash;
final = (void*)sha1_end;
hash_len = 20;
} else if (ENABLE_SHA256SUM && hash_algo == HASH_SHA256) {
}
else if (ENABLE_SHA256SUM && hash_algo == HASH_SHA256) {
sha256_begin(&context.sha256);
update = (void*)sha256_hash;
final = (void*)sha256_end;
hash_len = 32;
} else if (ENABLE_SHA512SUM && hash_algo == HASH_SHA512) {
}
else if (ENABLE_SHA512SUM && hash_algo == HASH_SHA512) {
sha512_begin(&context.sha512);
update = (void*)sha512_hash;
final = (void*)sha512_end;
hash_len = 64;
} else if (ENABLE_SHA3SUM && hash_algo == HASH_SHA3) {
}
#if ENABLE_SHA3SUM
else if (ENABLE_SHA3SUM && hash_algo == HASH_SHA3) {
sha3_begin(&context.sha3);
update = (void*)sha3_hash;
final = (void*)sha3_end;
hash_len = 64;
} else {
/*
* Should support 224, 256, 384, 512.
* We allow any value which does not blow the algorithm up.
*/
if (sha3_width >= 1600/2 /* input block can't be <= 0 */
|| sha3_width == 0 /* hash len can't be 0 */
|| (sha3_width & 0x1f) /* should be multiple of 32 */
/* (because input uses up to 8 byte wide word XORs. 32/4=8) */
) {
bb_error_msg_and_die("bad -a%u", sha3_width);
}
sha3_width /= 4;
context.sha3.input_block_bytes = 1600/8 - sha3_width;
hash_len = sha3_width/2;
}
#endif
else {
xfunc_die(); /* can't reach this */
}
@ -172,28 +253,33 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
{
int return_value = EXIT_SUCCESS;
unsigned flags;
#if ENABLE_SHA3SUM
unsigned sha3_width = 224;
#endif
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) {
/* -s and -w require -c */
opt_complementary = "s?c:w?c";
/* -b "binary", -t "text" are ignored (shaNNNsum compat) */
flags = getopt32(argv, "scwbt");
argv += optind;
//argc -= optind;
#if ENABLE_SHA3SUM
if (applet_name[3] == HASH_SHA3)
flags = getopt32(argv, "scwbta:+", &sha3_width);
else
#endif
flags = getopt32(argv, "scwbt");
} else {
argv += 1;
//argc -= 1;
#if ENABLE_SHA3SUM
if (applet_name[3] == HASH_SHA3)
getopt32(argv, "a:+", &sha3_width);
else
#endif
getopt32(argv, "");
}
argv += optind;
//argc -= optind;
if (!*argv)
*--argv = (char*)"-";
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) {
if (flags & FLAG_SILENT) {
bb_error_msg_and_die("-%c is meaningful only with -c", 's');
}
if (flags & FLAG_WARN) {
bb_error_msg_and_die("-%c is meaningful only with -c", 'w');
}
}
do {
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {
FILE *pre_computed_stream;
@ -225,7 +311,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
*filename_ptr = '\0';
filename_ptr += 2;
hash_value = hash_file(filename_ptr);
hash_value = hash_file(filename_ptr, sha3_width);
if (hash_value && (strcmp((char*)hash_value, line) == 0)) {
if (!(flags & FLAG_SILENT))
@ -244,9 +330,17 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
bb_error_msg("WARNING: %d of %d computed checksums did NOT match",
count_failed, count_total);
}
if (count_total == 0) {
return_value = EXIT_FAILURE;
/*
* md5sum from GNU coreutils 8.25 says:
* md5sum: <FILE>: no properly formatted MD5 checksum lines found
*/
bb_error_msg("%s: no checksum lines found", *argv);
}
fclose_if_not_stdin(pre_computed_stream);
} else {
uint8_t *hash_value = hash_file(*argv);
uint8_t *hash_value = hash_file(*argv, sha3_width);
if (hash_value == NULL) {
return_value = EXIT_FAILURE;
} else {

View File

@ -6,18 +6,30 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Fixed broken permission setting when -p was used; especially in
* conjunction with -m.
*/
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
*/
//config:config MKDIR
//config: bool "mkdir"
//config: default y
//config: help
//config: mkdir is used to create directories with the specified names.
//config:
//config:config FEATURE_MKDIR_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on MKDIR && LONG_OPTS
//applet:IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir))
//kbuild:lib-$(CONFIG_MKDIR) += mkdir.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
//usage:#define mkdir_trivial_usage
//usage: "[OPTIONS] DIRECTORY..."

View File

@ -6,6 +6,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config MKFIFO
//config: bool "mkfifo"
//config: default y
//config: help
//config: mkfifo is used to create FIFOs (named pipes).
//config: The 'mknod' program can also create FIFOs.
//applet:IF_MKFIFO(APPLET_NOEXEC(mkfifo, mkfifo, BB_DIR_USR_BIN, BB_SUID_DROP, mkfifo))
//kbuild:lib-$(CONFIG_MKFIFO) += mkfifo.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkfifo.html */

Some files were not shown because too many files have changed in this diff Show More