Compare commits

...
343 Commits
Author SHA1 Message Date
Denys Vlasenko 81e26c4b8e Bump version to 1.27.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-17 12:58:27 +02:00
Denys Vlasenko 0b16a67959 svc: fix a case where with more than option, getopt() state is not reset
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-05 01:40:12 +02:00
Natanael Copa 4989d05174 unzip: fix regression on big-endian machines
This fixes a regression which was introduced with commit 2a0867a5
("unzip: optional support for bzip2 and lzma") and causes unzip to exit
with error when extracting archives:

  unzip: unsupported method 2048

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 14:54:16 +02:00
Denys Vlasenko 21e5d0f841 config: FEDORA_COMPAT option (so far only tweaks uname)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:22:17 +02:00
Denys Vlasenko cf792a58ab NOFORK fixes
"rm -i FILE" and "yes" can now be interrupted by ^C in hush.
This also now works:

$ usleep 19999999
^C
$ echo $?
130

function                                             old     new   delta
run_pipe                                            1668    1711     +43
pseudo_exec_argv                                     312     321      +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 52/0)               Total: 52 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:20:19 +02:00
Denys Vlasenko 0a53eadea5 tls: fix pstm asm constraint problem
function                                             old     new   delta
pstm_sqr_comba                                       551     475     -76

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:18:00 +02:00
Denys Vlasenko 25f07f5898 tls: fix build problem on non-static i386
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:54 +02:00
Denys Vlasenko 6bb89e1622 libbb: safe_write should not return EINTR
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:50 +02:00
Denys Vlasenko 310bcec4dc shuf: fix random line selection. Closes 9971
"""
For example, given input file:

    foo
    bar
    baz

after shuffling the input file, foo will never end up back on the first line.
This came to light when I ran into a use-case where someone was selecting
a random line from a file using shuf | head -n 1, and the results on busybox
were showing a statistical anomaly (as in, the first line would never ever
be picked) vs the same process running on environments that had gnu coreutils
installed.

On line https://git.busybox.net/busybox/tree/coreutils/shuf.c#n56 it uses
r %= i, which will result in 0 <= r < i, while the algorithm specifies
0 <= r <= i.
"""

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-08-04 02:17:42 +02:00
Denys Vlasenko 8fd69c7bdb Bump version to 1.27.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:22:15 +02:00
Denys Vlasenko 56a361bec1 fix more instances of ": $((a++))" in shell scripts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Kang-Che Sung 6f13dd1d65 make_single_applets: fix ": $((fail++))" expansion error
$((fail++)) is not a required expression in POSIX, and in "dash" it
could produce an error like this:

    ./make_single_applets.sh: 61: arithmetic expression: expecting primary: "fail++"

Replace this with something portable: fail=$((fail+1)) would work.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Johannes Schindelin 3df48bdde9 copyfd: guard use of munmap() with #if (windows builds need this)
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Johannes Schindelin 1f684bcde4 ash: protect WIFSTOPPED use with #if JOBS
This change fixes the build in setups where there are
no headers defining WIFSTOPPED and WSTOPSIG (where JOBS has to be
set to 0).

This partially reverts 4700fb5be (ash: make dowait() a bit more
readable. Logic is unchanged, 2015-10-09).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 2cb72bb8de libbb: hide getnetbyaddr() inside "#if ENABLE_FEATURE_ETC_NETWORKS" block
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 87d8ae94a2 uuencode: allow space instead of "`" as padding char. Closes 10046
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko a3de7190a5 dd: fix status=none. Closes 10066
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko f807b8e96e inetd,mount: do not die if uclibc without RPC is detected
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 2f6dc07d8f beep: disallow FEATURE_BEEP_FREQ = 0 in configuration
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 54916641be main: fix the case where user has "halt" as login shell. Closes 9986
halt::0:0::/:/sbin/halt

function                                             old     new   delta
run_applet_and_exit                                  748     751      +3
run_applet_no_and_exit                               467     459      -8

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Peter Korsgaard 80cb8796f8 dpkg: fix CONFIG_FEATURE_CLEAN_UP handling
dpkg moved to away from dynamically allocating the hashtables in commit
c87339d584 (dpkg: trivial code shrinkage, and redo G trick correctly) almost
ten years ago, but the cleanup code was never adjusted to match.

Glibc loudly complains about this:

*** Error in `dpkg': free(): invalid pointer: 0x0000007fac3478c0 ***

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Patrick Steinhardt ee67c9a60a setpriv: do not process remaining args
By default, the 'getopt32' call will continue parsing the command line
even after hitting a non-option string. But in setpriv, this should be
avoided, as all parameters following the initial non-option argument are
in fact arguments to the binary that is to be executed by setpriv.
Otherwise, calling e.g. 'busybox setpriv ls -l' would result in an error
due to the unknown parameter "-l".

Fix the issue by passing "+" as the first character in the options
string. This will cause 'getopt32' to stop processing after hitting the
first non-option.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 8965e5089e tls: use capped SNI len everywhere
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko e916d48e5a bzcat: compile bunzip2_main() if BZCAT.
Currently, BZCAT (and BUNZIP2) selects FEATURE_BZIP2_DECOMPRESS,
thus, "#if ENABLE_FEATURE_BZIP2_DECOMPRESS" around bunzip2_main()
is sufficient. But let's robustify it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
Denys Vlasenko 442d522f0b fixes for bugs found by make_single_applets.sh
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-18 19:20:58 +02:00
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
370 changed files with 16024 additions and 4800 deletions

No files matched your search

+3
View File
@@ -178,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
+31 -16
View File
@@ -22,7 +22,7 @@ config DESKTOP
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.
tools, you can unselect this option for smaller code size.
config EXTRA_COMPAT
bool "Provide compatible behavior for rare corner cases (bigger code)"
@@ -33,6 +33,19 @@ config EXTRA_COMPAT
some GNU extensions in libc. You probably only need this option
if you plan to run busybox on desktop.
config FEDORA_COMPAT
bool "Building for Fedora distribution"
default n
help
This option makes some tools behave like they do on Fedora.
At the time of this writing (2017-08) this only affects uname:
normally, uname -p (processor) and uname -i (platform)
are shown as "unknown", but with this option uname -p
shows the same string as uname -m (machine type),
and so does uname -i unless machine type is i486/i586/i686 -
then uname -i shows "i386".
config INCLUDE_SUSv2
bool "Enable obsolete features removed before SUSv3"
default y
@@ -50,17 +63,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.
config SHOW_USAGE
bool "Show applet usage messages"
default y
@@ -124,14 +126,14 @@ config INSTALL_NO_USR
never to /usr/bin or /usr/sbin.
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 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
@@ -198,7 +200,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
@@ -338,6 +340,17 @@ config FEATURE_HAVE_RPC
# This is automatically selected if any of enabled applets need it.
# You do not need to select it manually.
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.
comment 'Build Options'
config STATIC
@@ -611,6 +624,8 @@ config DEBUG_SANITIZE
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
@@ -625,7 +640,7 @@ config WERROR
bool "Abort compilation on any warning"
default n
help
Selecting this will add -Werror to gcc command line.
This adds -Werror to gcc command line.
Most people should answer N.
+2 -2
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 26
SUBLEVEL = 0
PATCHLEVEL = 27
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
+3
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
-10
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 "Make tar, rpm, modprobe etc understand .Z data"
default n # it is ancient
help
Make tar, rpm, modprobe etc understand .Z data.
INSERT
+1 -1
View File
@@ -31,7 +31,7 @@
//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
+78 -48
View File
@@ -7,21 +7,31 @@
#include "libbb.h"
#include "bb_archive.h"
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
/* 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_BZIP2) += bbunzip.o
/* gzip_main() too: */
//kbuild:lib-$(CONFIG_GZIP) += 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
@@ -123,7 +133,7 @@ int FAST_FUNC bbunpack(char **argv,
if (!(option_mask32 & SEAMLESS_MAGIC)) {
init_transformer_state(&xstate);
xstate.signature_skipped = 0;
/*xstate.signature_skipped = 0; - already is */
/*xstate.src_fd = STDIN_FILENO; - already is */
xstate.dst_fd = STDOUT_FILENO;
status = unpacker(&xstate);
@@ -178,8 +188,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);
@@ -193,7 +206,7 @@ int FAST_FUNC bbunpack(char **argv,
}
#if ENABLE_UNCOMPRESS \
|| ENABLE_BUNZIP2 || ENABLE_BZCAT \
|| ENABLE_FEATURE_BZIP2_DECOMPRESS \
|| ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \
|| ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
static
@@ -236,7 +249,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");
@@ -269,11 +291,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
@@ -291,6 +314,7 @@ 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
@@ -299,6 +323,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
//config:config ZCAT
//config: bool "zcat"
//config: default y
//config: select FEATURE_GZIP_DECOMPRESS
//config: help
//config: Alias to "gunzip -c".
//config:
@@ -306,14 +331,11 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
//config: bool "Enable long options"
//config: default y
//config: depends on (GUNZIP || ZCAT) && LONG_OPTS
//config: help
//config: Enable use of long options.
//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_ZCAT(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
#if ENABLE_GUNZIP || ENABLE_ZCAT
#if ENABLE_FEATURE_GZIP_DECOMPRESS
static
char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
{
@@ -369,7 +391,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
applet_long_options = gunzip_longopts;
#endif
getopt32(argv, "cfvqdtn");
getopt32(argv, "cfkvqdtn");
argv += optind;
/* If called as zcat...
@@ -381,7 +403,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
}
#endif
#endif /* FEATURE_GZIP_DECOMPRESS */
/*
@@ -391,11 +413,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"
@@ -404,6 +427,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
@@ -417,18 +441,18 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//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_ODDNAME:name main location suid_type help
//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
#if ENABLE_BUNZIP2 || ENABLE_BZCAT
#if ENABLE_FEATURE_BZIP2_DECOMPRESS || ENABLE_BUNZIP2 || ENABLE_BZCAT
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 (ENABLE_BZCAT && applet_name[2] == 'c') /* bzcat */
option_mask32 |= OPT_STDOUT;
@@ -447,44 +471,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"
@@ -518,7 +524,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//config: IOW: you'll get lzma applet, but it will always require -d option.
//config:
//config:config FEATURE_LZMA_FAST
//config: bool "Optimize unlzma for speed"
//config: bool "Optimize for speed"
//config: default n
//config: depends on UNLZMA || LZCAT || LZMA
//config: help
@@ -526,8 +532,9 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//config: a 1K bigger binary.
//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
// 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))
//applet:IF_LZMA( APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
//kbuild:lib-$(CONFIG_LZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_LZMA) += bbunzip.o
@@ -535,7 +542,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
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)))
@@ -551,6 +558,28 @@ 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
@@ -571,8 +600,9 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//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_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))
//applet:IF_XZ( APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
//kbuild:lib-$(CONFIG_XZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_XZ) += bbunzip.o
@@ -580,7 +610,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
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)))
+19 -6
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");
}
+2 -2
View File
@@ -29,7 +29,7 @@
//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
@@ -37,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
+14 -18
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;
@@ -1938,10 +1938,6 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
for (i = 0; i < STATUS_HASH_PRIME; i++) {
free(status_hashtable[i]);
}
free(status_hashtable);
free(package_hashtable);
free(name_hashtable);
}
return EXIT_SUCCESS;
+1 -1
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.
+25 -16
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,22 +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: "[-cf" IF_GUNZIP("d") 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_GUNZIP(
//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"
@@ -267,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.
@@ -306,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;
@@ -2154,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"
@@ -2181,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;
@@ -2211,13 +2220,13 @@ 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 */
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
@@ -2226,7 +2235,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
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);
+7 -4
View File
@@ -51,16 +51,19 @@ 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
lib-$(CONFIG_BZCAT) += 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_XZCAT) += open_transformer.o decompress_unxz.o
lib-$(CONFIG_XZ) += open_transformer.o decompress_unxz.o
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
lib-$(CONFIG_ZCAT) += open_transformer.o decompress_gunzip.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
+4 -2
View File
@@ -127,8 +127,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
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",
"%s to %s", "hard",
dst_name,
hard_link);
}
@@ -181,8 +182,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
if (res != 0
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
/* shared message */
bb_perror_msg("can't create %slink "
"from %s to %s", "sym",
"%s to %s", "sym",
dst_name,
file_header->link_target);
}
+4 -4
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;
+26 -5
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...
*/
}
}
+2 -2
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,
+37 -19
View File
@@ -33,13 +33,13 @@
//config:
//config:config UNLZOP
//config: bool "unlzop"
//config: default y
//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 y
//config: default n # INCOMPAT: upstream lzop does not provide such tool
//config: help
//config: Alias to "unlzop -c".
//config:
@@ -53,19 +53,22 @@
//config: and take up 3.2K of code.
//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
//applet:IF_UNLZOP(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"
@@ -77,10 +80,12 @@
//usage: "\n -F Don't verify checksum"
//usage:
//usage:#define unlzop_trivial_usage
//usage: "[-cfvF] [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 verify checksum"
@@ -471,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
};
/**********************************************************************/
@@ -1124,6 +1135,13 @@ 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 (ENABLE_LZOPCAT && applet_name[4] == 'c')
option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS);
+29 -35
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
@@ -540,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;
@@ -1227,21 +1216,26 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
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 */
+396 -304
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
@@ -54,8 +79,8 @@
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,
@@ -80,30 +105,21 @@ 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.method = SWAP_LE16((zip).fmt.method ); \
(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
@@ -115,44 +131,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;
@@ -161,25 +177,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.
@@ -188,30 +222,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 = xlseek(zip_fd, 0, SEEK_END);
end = lseek(zip_fd, 0, SEEK_END);
if (end == (off_t) -1)
return BAD_CDF_OFFSET;
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);
xlseek(zip_fd, end, SEEK_SET);
buf = xzalloc(PEEK_FROM_END);
full_read(zip_fd, buf, PEEK_FROM_END);
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;
@@ -223,19 +258,19 @@ 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 - ??
* This check ignores such CDEs:
*/
if (cde_header.formatted.cdf_offset < end + (p - buf)) {
found = cde_header.formatted.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_header.formatted.cdf_size)));
(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,
@@ -249,33 +284,36 @@ static uint32_t find_cdf_offset(void)
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) {
dbg("Reading CDF at 0x%x", (unsigned)cdf_offset);
xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
FIX_ENDIANNESS_CDF(*cdf_ptr);
dbg(" file_name_length:%u extra_field_length:%u file_comment_length:%u",
(unsigned)cdf_ptr->formatted.file_name_length,
(unsigned)cdf_ptr->formatted.extra_field_length,
(unsigned)cdf_ptr->formatted.file_comment_length
);
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;
dbg("Returning file position to 0x%"OFF_FMT"x", org);
xlseek(zip_fd, org, SEEK_SET);
return cdf_offset;
};
#endif
@@ -297,32 +335,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");
}
}
@@ -339,15 +411,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;
@@ -430,7 +499,7 @@ int unzip_main(int argc, char **argv)
break;
case 'v': /* Verbose list */
IF_DESKTOP(verbose++;)
IF_FEATURE_UNZIP_CDF(verbose++;)
listing = 1;
break;
@@ -545,91 +614,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) {
dbg("got ZIP_CDF_MAGIC");
break;
}
#if ENABLE_DESKTOP
/* 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;
}
#endif
if (magic != ZIP_FILEHEADER_MAGIC)
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
dbg("got ZIP_FILEHEADER_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_header.formatted.cmpsize,
(unsigned)zip_header.formatted.extra_len,
(unsigned)zip_header.formatted.ucmpsize
(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));
@@ -638,129 +730,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 */
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
(zip_header.formatted.moddate >> 5) & 0xf, // mm: 0x01e0
(zip_header.formatted.moddate) & 0x1f, // dd: 0x001f
(zip_header.formatted.moddate >> 9) + 1980, // yy: 0xfe00
(zip_header.formatted.modtime >> 11), // hh: 0xf800
(zip_header.formatted.modtime >> 5) & 0x3f // mm: 0x07e0
// seconds/2 are not shown, encoded in ----------- 0x001f
);
if (!verbose) {
// " Length Date Time Name\n"
// "--------- ---------- ----- ----"
printf( "%9u " "%s " "%s\n",
(unsigned)zip_header.formatted.ucmpsize,
dtbuf,
dst_fn);
} else {
unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize;
if ((int32_t)percents < 0)
percents = 0; /* happens if ucmpsize < cmpsize */
percents = percents * 100;
if (zip_header.formatted.ucmpsize)
percents /= zip_header.formatted.ucmpsize;
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
// "-------- ------ ------- ---- ---------- ----- -------- ----"
printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
(unsigned)zip_header.formatted.ucmpsize,
zip_header.formatted.method == 0 ? "Stored" : "Defl:N", /* Defl is method 8 */
/* TODO: show other methods?
* 1 - Shrunk
* 2 - Reduced with compression factor 1
* 3 - Reduced with compression factor 2
* 4 - Reduced with compression factor 3
* 5 - Reduced with compression factor 4
* 6 - Imploded
* 7 - Reserved for Tokenizing compression algorithm
* 9 - Deflate64
* 10 - PKWARE Data Compression Library Imploding
* 11 - Reserved by PKWARE
* 12 - BZIP2
*/
(unsigned)zip_header.formatted.cmpsize,
(unsigned)percents,
dtbuf,
zip_header.formatted.crc32,
dst_fn);
total_size += zip_header.formatted.cmpsize;
}
total_usize += zip_header.formatted.ucmpsize;
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);
@@ -769,9 +861,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':
@@ -784,7 +876,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;
}
+4 -13
View File
@@ -265,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
#
@@ -387,7 +382,7 @@ 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_LINUXRC=y
CONFIG_HALT=y
@@ -457,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"
@@ -524,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
@@ -879,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
+4 -6
View File
@@ -277,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
@@ -392,7 +391,7 @@ 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_LINUXRC is not set
# CONFIG_HALT is not set
@@ -527,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
@@ -873,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
+4 -13
View File
@@ -276,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
#
@@ -404,7 +399,7 @@ 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_LINUXRC=y
CONFIG_HALT=y
@@ -472,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"
@@ -540,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
@@ -893,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
+4 -13
View File
@@ -94,7 +94,6 @@ 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
@@ -289,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
#
@@ -422,7 +416,7 @@ 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_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
@@ -493,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"
@@ -936,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
+4 -13
View File
@@ -174,7 +174,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=y
CONFIG_FEATURE_EDITING_MAX_LEN=1024
# CONFIG_FEATURE_EDITING_VI is not set
@@ -390,11 +389,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
#
@@ -529,7 +523,7 @@ 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_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
@@ -603,15 +597,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"
@@ -1081,9 +1072,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_HELP=y
CONFIG_ASH_CMDCMD=y
# CONFIG_ASH_MAIL is not set
+4 -13
View File
@@ -112,7 +112,6 @@ 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
@@ -312,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
#
@@ -445,7 +439,7 @@ 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_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
@@ -517,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"
@@ -968,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
+4 -13
View File
@@ -102,7 +102,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
@@ -316,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
#
@@ -455,7 +449,7 @@ 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_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
@@ -528,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"
@@ -996,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
+4 -10
View File
@@ -94,7 +94,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
@@ -289,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
#
@@ -422,7 +416,7 @@ 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_LINUXRC is not set
CONFIG_INIT_TERMINAL_TYPE=""
@@ -936,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
+4 -10
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
@@ -287,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
#
@@ -419,7 +413,7 @@ 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_LINUXRC is not set
CONFIG_INIT_TERMINAL_TYPE=""
@@ -912,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
+2 -6
View File
@@ -42,18 +42,14 @@
//config: depends on LOADFONT || SETFONT
//config:
//config:config FEATURE_LOADFONT_PSF2
//config: bool "Support for PSF2 console fonts"
//config: bool "Support PSF2 console fonts"
//config: default y
//config: depends on LOADFONT || SETFONT
//config: help
//config: Support PSF2 console fonts.
//config:
//config:config FEATURE_LOADFONT_RAW
//config: bool "Support for old (raw) console fonts"
//config: bool "Support old (raw) console fonts"
//config: default y
//config: depends on LOADFONT || SETFONT
//config: help
//config: Support old (raw) console fonts.
//applet:IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
//applet:IF_SETFONT(APPLET(setfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
+2
View File
@@ -56,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
}
-2
View File
@@ -19,8 +19,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on SETCONSOLE && LONG_OPTS
//config: help
//config: Support long options for the setconsole applet.
//applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
+1 -15
View File
@@ -27,25 +27,11 @@ 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
+6 -9
View File
@@ -10,12 +10,9 @@ lib-y:=
INSERT
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 adduser
lib-$(CONFIG_ASH) += echo.o # used by ash
lib-$(CONFIG_HUSH) += echo.o # used by hush
lib-$(CONFIG_FTPD) += ls.o # used by ftpd
lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.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
+134 -22
View File
@@ -12,56 +12,168 @@
//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_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat))
//applet:IF_CAT(APPLET(cat, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CAT) += cat.o
//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);
}
-96
View File
@@ -1,96 +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 */
//config:config CATV
//config: bool "catv"
//config: default y
//config: help
//config: Display nonprinting characters as escape sequences (like some
//config: implementations' cat -v option).
//applet:IF_CATV(APPLET(catv, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CATV) += catv.o
//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"
#include "common_bufsiz.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*)"-";
#define read_buf bb_common_bufsiz1
setup_common_bufsiz();
do {
fd = open_or_warn_stdin(*argv);
if (fd < 0) {
retval = EXIT_FAILURE;
continue;
}
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];
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);
}
-2
View File
@@ -17,8 +17,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on CHOWN && LONG_OPTS
//config: help
//config: Enable use of long options
//applet:IF_CHOWN(APPLET_NOEXEC(chown, chown, BB_DIR_BIN, BB_SUID_DROP, chown))
+2 -2
View File
@@ -17,9 +17,9 @@
//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"
+2 -2
View File
@@ -18,11 +18,11 @@
//config: cp is used to copy files and directories.
//config:
//config:config FEATURE_CP_LONG_OPTIONS
//config: bool "Enable long options for cp"
//config: bool "Enable long options"
//config: default y
//config: depends on CP && LONG_OPTS
//config: help
//config: Enable long options for cp.
//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))
+9 -10
View File
@@ -41,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
@@ -49,7 +49,7 @@
//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))
@@ -133,9 +133,8 @@ enum {
/* 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,
FLAG_STATUS_NONE = 1 << 8,
FLAG_STATUS_NOXFER = 1 << 9,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -396,7 +395,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
n = index_in_strings(status_words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status");
G.flags |= FLAG_STATUS << n;
G.flags |= FLAG_STATUS_NONE << n;
/*continue;*/
}
#endif
@@ -532,11 +531,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) {
+3 -5
View File
@@ -29,11 +29,9 @@
//config: default y
//config: depends on DF
//config: help
//config: This option enables -a, -i and -B.
//config:
//config: -a Show all filesystems
//config: -i Inodes
//config: -B <SIZE> Blocksize
//config: -a Show all filesystems
//config: -i Inodes
//config: -B <SIZE> Blocksize
//applet:IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP))
+1 -1
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.
+5 -4
View File
@@ -26,16 +26,17 @@
//config:
//config:# this entry also appears in shell/Config.in, next to the echo builtin
//config:config FEATURE_FANCY_ECHO
//config: bool "Enable echo options (-n and -e)"
//config: bool "Enable -n and -e options"
//config: default y
//config: depends on ECHO || ASH_BUILTIN_ECHO || HUSH
//config: help
//config: This adds options (-n and -e) to echo.
//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 */
-2
View File
@@ -35,8 +35,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on ENV && LONG_OPTS
//config: help
//config: Support long options for the env applet.
//applet:IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env))
+5 -8
View File
@@ -8,13 +8,13 @@
* 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>
*
@@ -30,8 +30,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on EXPAND && LONG_OPTS
//config: help
//config: Support long options for the expand applet.
//config:
//config:config UNEXPAND
//config: bool "unexpand"
@@ -43,10 +41,9 @@
//config: bool "Enable long options"
//config: default y
//config: depends on UNEXPAND && LONG_OPTS
//config: help
//config: Support long options for the unexpand applet.
//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
@@ -58,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"
@@ -72,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"
+219
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;
}
+1 -3
View File
@@ -14,11 +14,9 @@
//config: from files.
//config:
//config:config FEATURE_FANCY_HEAD
//config: bool "Enable head options (-c, -q, and -v)"
//config: bool "Enable -c, -q, and -v"
//config: default y
//config: depends on HEAD
//config: help
//config: This enables the head options (-c, -q, and -v).
//applet:IF_HEAD(APPLET_NOEXEC(head, head, BB_DIR_USR_BIN, BB_SUID_DROP, head))
-2
View File
@@ -15,8 +15,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on INSTALL && LONG_OPTS
//config: help
//config: Support long options for the install applet.
//applet:IF_INSTALL(APPLET(install, BB_DIR_USR_BIN, BB_SUID_DROP))
+41
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;
}
+241 -319
View File
@@ -37,22 +37,21 @@
//config: bool "Enable filetyping options (-p and -F)"
//config: default y
//config: depends on LS
//config: help
//config: Enable the ls options (-p and -F).
//config:
//config:config FEATURE_LS_FOLLOWLINKS
//config: bool "Enable symlinks dereferencing (-L)"
//config: default y
//config: depends on LS
//config: help
//config: Enable the ls option (-L).
//config:
//config:config FEATURE_LS_RECURSIVE
//config: bool "Enable recursion (-R)"
//config: default y
//config: depends on LS
//config: help
//config: Enable the ls option (-R).
//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"
@@ -102,18 +101,17 @@
//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(
@@ -132,29 +130,34 @@
//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"
@@ -189,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
*/
@@ -399,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;
@@ -422,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
@@ -439,7 +343,7 @@ struct globals {
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)
@@ -496,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 '*';
@@ -531,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
@@ -565,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;
@@ -580,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);
}
/* 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 (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));
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)
@@ -632,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 " */
@@ -663,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) {
@@ -689,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)
@@ -711,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++;
@@ -727,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 */
@@ -738,10 +648,11 @@ static void display_files(struct dnode **dn, unsigned nfiles)
if (column_width < len)
column_width = len;
}
column_width += 2 +
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;
}
@@ -759,7 +670,7 @@ 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 */
@@ -792,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
@@ -805,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
@@ -822,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;
@@ -938,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) {
@@ -973,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)
@@ -1023,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);
@@ -1097,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;
@@ -1105,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;
@@ -1135,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;
@@ -1157,23 +1067,25 @@ 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 */
G_terminal_width = get_terminal_width(STDIN_FILENO);
/* go one less... */
@@ -1181,10 +1093,12 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
#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:
*/
@@ -1196,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 */
@@ -1242,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;
@@ -1270,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 */
@@ -1302,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);
+1 -2
View File
@@ -45,7 +45,6 @@
//config: help
//config: Enabling the -c options allows files to be checked
//config: against pre-calculated hash values.
//config:
//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))
@@ -167,7 +166,7 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
} 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);
-2
View File
@@ -23,8 +23,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on MKDIR && LONG_OPTS
//config: help
//config: Support long options for the mkdir applet.
//applet:IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir))
File renamed without changes.
-2
View File
@@ -21,8 +21,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on MV && LONG_OPTS
//config: help
//config: Support long options for the mv applet.
//applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP))
+101
View File
@@ -0,0 +1,101 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config NL
//config: bool "nl"
//config: default y
//config: help
//config: nl is used to number lines of files.
//applet:IF_NL(APPLET(nl, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_NL) += nl.o
//usage:#define nl_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage:#define nl_full_usage "\n\n"
//usage: "Write FILEs to standard output with line numbers added\n"
//usage: "\n -b STYLE Which lines to number - a: all, t: nonempty, n: none"
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TODO: support "pBRE": number only lines thatmatch regexp BRE"
////usage: "\n -f STYLE footer lines"
////usage: "\n -h STYLE header lines"
////usage: "\n -d CC use CC for separating logical pages"
//usage: "\n -i N Line number increment"
////usage: "\n -l NUMBER group of NUMBER empty lines counted as one"
////usage: "\n -n FORMAT lneft justified, no leading zeros; rn or rz"
////usage: "\n -p do not reset line numbers at logical pages (huh?)"
//usage: "\n -s STRING Use STRING as line number separator"
//usage: "\n -v N Start from N"
//usage: "\n -w N Width of line numbers"
/* By default, selects -v1 -i1 -l1 -sTAB -w6 -nrn -hn -bt -fn */
#include "libbb.h"
void FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename)
{
FILE *fp = fopen_or_warn_stdin(filename);
unsigned N = ns->start;
char *line;
while ((line = xmalloc_fgetline(fp)) != NULL) {
if (ns->all
|| (ns->nonempty && line[0])
) {
printf("%*u%s%s\n", ns->width, N, ns->sep, line);
N += ns->inc;
} else if (ns->empty_str)
fputs(ns->empty_str, stdout);
free(line);
}
fclose(fp);
}
int nl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nl_main(int argc UNUSED_PARAM, char **argv)
{
struct number_state ns;
const char *opt_b = "t";
enum {
OPT_p = (1 << 0),
};
#if ENABLE_LONG_OPTS
static const char nl_longopts[] ALIGN1 =
"body-numbering\0" Required_argument "b"
// "footer-numbering\0" Required_argument "f" - not implemented yet
// "header-numbering\0" Required_argument "h" - not implemented yet
// "section-delimiter\0" Required_argument "d" - not implemented yet
"line-increment\0" Required_argument "i"
// "join-blank-lines\0" Required_argument "l" - not implemented yet
// "number-format\0" Required_argument "n" - not implemented yet
"no-renumber\0" No_argument "p" // no-op so far
"number-separator\0" Required_argument "s"
"starting-line-number\0"Required_argument "v"
"number-width\0" Required_argument "w"
;
applet_long_options = nl_longopts;
#endif
ns.width = 6;
ns.start = 1;
ns.inc = 1;
ns.sep = "\t";
getopt32(argv, "pw:+s:v:+i:+b:", &ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b);
ns.all = (opt_b[0] == 'a');
ns.nonempty = (opt_b[0] == 't');
ns.empty_str = xasprintf("%*s\n", ns.width + (int)strlen(ns.sep), "");
argv += optind;
if (!*argv)
*--argv = (char*)"-";
do {
print_numbered_lines(&ns, *argv);
} while (*++argv);
fflush_stdout_and_exit(EXIT_SUCCESS);
}
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see LICENSE in this source tree
*/
//config:config NPROC
//config: bool "nproc"
//config: default y
//config: help
//config: Print number of CPUs
//applet:IF_NPROC(APPLET(nproc, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_NPROC) += nproc.o
//usage:#define nproc_trivial_usage
//usage: ""
//TODO: "[--all] [--ignore=N]"
//usage:#define nproc_full_usage "\n\n"
//usage: "Print number of CPUs"
#include <sched.h>
#include "libbb.h"
int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
unsigned long mask[1024];
unsigned i, count = 0;
//applet_long_options = ...;
//getopt32(argv, "");
//if --all, count /sys/devices/system/cpu/cpuN dirs, else:
if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) {
for (i = 0; i < ARRAY_SIZE(mask); i++) {
unsigned long m = mask[i];
while (m) {
if (m & 1)
count++;
m >>= 1;
}
}
}
if (count == 0)
count++;
printf("%u\n", count);
return 0;
}
+140
View File
@@ -0,0 +1,140 @@
/* vi: set sw=4 ts=4: */
/*
* paste.c - implementation of the posix paste command
*
* Written by Maxime Coste <mawww@kakoune.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PASTE
//config: bool "paste"
//config: default y
//config: help
//config: paste is used to paste lines of different files together
//config: and write the result to stdout
//applet:IF_PASTE(APPLET_NOEXEC(paste, paste, BB_DIR_USR_BIN, BB_SUID_DROP, paste))
//kbuild:lib-$(CONFIG_PASTE) += paste.o
//usage:#define paste_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage:#define paste_full_usage "\n\n"
//usage: "Paste lines from each input file, separated with tab\n"
//usage: "\n -d LIST Use delimiters from LIST, not tab"
//usage: "\n -s Serial: one file at a time"
//usage:
//usage:#define paste_example_usage
//usage: "# write out directory in four columns\n"
//usage: "$ ls | paste - - - -\n"
//usage: "# combine pairs of lines from a file into single lines\n"
//usage: "$ paste -s -d '\\t\\n' file\n"
#include "libbb.h"
static void paste_files(FILE** files, int file_cnt, char* delims, int del_cnt)
{
char *line;
char delim;
int active_files = file_cnt;
int i;
while (active_files > 0) {
int del_idx = 0;
for (i = 0; i < file_cnt; ++i) {
if (files[i] == NULL)
continue;
line = xmalloc_fgetline(files[i]);
if (!line) {
fclose_if_not_stdin(files[i]);
files[i] = NULL;
--active_files;
continue;
}
fputs(line, stdout);
free(line);
delim = '\n';
if (i != file_cnt - 1) {
delim = delims[del_idx++];
if (del_idx == del_cnt)
del_idx = 0;
}
if (delim != '\0')
fputc(delim, stdout);
}
}
}
static void paste_files_separate(FILE** files, char* delims, int del_cnt)
{
char *line, *next_line;
char delim;
int i;
for (i = 0; files[i]; ++i) {
int del_idx = 0;
line = NULL;
while ((next_line = xmalloc_fgetline(files[i])) != NULL) {
if (line) {
fputs(line, stdout);
free(line);
delim = delims[del_idx++];
if (del_idx == del_cnt)
del_idx = 0;
if (delim != '\0')
fputc(delim, stdout);
}
line = next_line;
}
if (line) {
/* coreutils adds \n even if this is a final line
* of the last file and it was not \n-terminated.
*/
printf("%s\n", line);
free(line);
}
fclose_if_not_stdin(files[i]);
}
}
#define PASTE_OPT_DELIMITERS (1 << 0)
#define PASTE_OPT_SEPARATE (1 << 1)
int paste_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int paste_main(int argc UNUSED_PARAM, char **argv)
{
char *delims = (char*)"\t";
int del_cnt = 1;
unsigned opt;
int i;
opt = getopt32(argv, "d:s", &delims);
argv += optind;
if (opt & PASTE_OPT_DELIMITERS) {
if (!delims[0])
bb_error_msg_and_die("-d '' is not supported");
/* unknown mappings are not changed: "\z" -> '\\' 'z' */
/* trailing backslash, if any, is preserved */
del_cnt = strcpy_and_process_escape_sequences(delims, delims) - delims;
/* note: handle NUL properly (do not stop at it!): try -d'\t\0\t' */
}
if (!argv[0])
(--argv)[0] = (char*) "-";
for (i = 0; argv[i]; ++i) {
argv[i] = (void*) fopen_or_warn_stdin(argv[i]);
if (!argv[i])
xfunc_die();
}
if (opt & PASTE_OPT_SEPARATE)
paste_files_separate((FILE**)argv, delims, del_cnt);
else
paste_files((FILE**)argv, i, delims, del_cnt);
fflush_stdout_and_exit(0);
}
+4 -1
View File
@@ -49,6 +49,9 @@
//kbuild:lib-$(CONFIG_PRINTF) += printf.o
//kbuild:lib-$(CONFIG_ASH_PRINTF) += printf.o
//kbuild:lib-$(CONFIG_HUSH_PRINTF) += printf.o
//usage:#define printf_trivial_usage
//usage: "FORMAT [ARG]..."
//usage:#define printf_full_usage "\n\n"
@@ -417,7 +420,7 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2])
argv++;
if (!argv[1]) {
if (ENABLE_ASH_BUILTIN_PRINTF
if (ENABLE_ASH_PRINTF
&& applet_name[0] != 'p'
) {
bb_error_msg("usage: printf FORMAT [ARGUMENT...]");
+3 -2
View File
@@ -16,7 +16,8 @@
//config: help
//config: rm is used to remove files or directories.
//applet:IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
//applet:IF_RM(APPLET_NOEXEC(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
/* was NOFORK, but then "rm -i FILE" can't be ^C'ed if run by hush */
//kbuild:lib-$(CONFIG_RM) += rm.o
@@ -36,7 +37,7 @@
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
/* This is a NOEXEC applet. Be very careful! */
int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rm_main(int argc UNUSED_PARAM, char **argv)
+3 -2
View File
@@ -12,7 +12,8 @@
//config: help
//config: print a sequence of numbers
//applet:IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
//applet:IF_SEQ(APPLET_NOEXEC(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
/* was NOFORK, but then "seq 1 999999999" can't be ^C'ed if run by hush */
//kbuild:lib-$(CONFIG_SEQ) += seq.o
@@ -26,7 +27,7 @@
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
/* This is a NOEXEC applet. Be very careful! */
int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int seq_main(int argc, char **argv)
+106
View File
@@ -0,0 +1,106 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SHRED
//config: bool "shred"
//config: default y
//config: help
//config: Overwrite a file to hide its contents, and optionally delete it
//applet:IF_SHRED(APPLET(shred, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SHRED) += shred.o
//usage:#define shred_trivial_usage
//usage: "FILE..."
//usage:#define shred_full_usage "\n\n"
//usage: "Overwrite/delete FILEs\n"
//usage: "\n -f Chmod to ensure writability"
//usage: "\n -n N Overwrite N times (default 3)"
//usage: "\n -z Final overwrite with zeros"
//usage: "\n -u Remove file"
//-x and -v are accepted but have no effect
/* shred (GNU coreutils) 8.25:
-f, --force change permissions to allow writing if necessary
-u truncate and remove file after overwriting
-z, --zero add a final overwrite with zeros to hide shredding
-n, --iterations=N overwrite N times instead of the default (3)
-v, --verbose show progress
-x, --exact do not round file sizes up to the next full block; this is the default for non-regular files
--random-source=FILE get random bytes from FILE
-s, --size=N shred this many bytes (suffixes like K, M, G accepted)
--remove[=HOW] like -u but give control on HOW to delete; See below
*/
#include "libbb.h"
int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int shred_main(int argc UNUSED_PARAM, char **argv)
{
int rand_fd = rand_fd; /* for compiler */
int zero_fd;
unsigned num_iter = 3;
unsigned opt;
enum {
OPT_f = (1 << 0),
OPT_u = (1 << 1),
OPT_z = (1 << 2),
OPT_n = (1 << 3),
OPT_v = (1 << 4),
OPT_x = (1 << 5),
};
opt = getopt32(argv, "fuzn:+vx", &num_iter);
argv += optind;
zero_fd = xopen("/dev/zero", O_RDONLY);
if (num_iter != 0)
rand_fd = xopen("/dev/urandom", O_RDONLY);
if (!*argv)
bb_show_usage();
for (;;) {
struct stat sb;
const char *fname;
unsigned i;
int fd;
fname = *argv++;
if (!fname)
break;
fd = -1;
if (opt & OPT_f) {
fd = open(fname, O_WRONLY);
if (fd < 0)
chmod(fname, 0666);
}
if (fd < 0)
fd = xopen(fname, O_WRONLY);
if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
off_t size = sb.st_size;
for (i = 0; i < num_iter; i++) {
bb_copyfd_size(rand_fd, fd, size);
fdatasync(fd);
xlseek(fd, 0, SEEK_SET);
}
if (opt & OPT_z) {
bb_copyfd_size(zero_fd, fd, size);
fdatasync(fd);
}
if (opt & OPT_u) {
ftruncate(fd, 0);
xunlink(fname);
}
xclose(fd);
}
}
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -53,7 +53,7 @@ static void shuffle_lines(char **lines, unsigned numlines)
/* RAND_MAX can be as small as 32767 */
if (i > RAND_MAX)
r ^= rand() << 15;
r %= i;
r %= i + 1;
tmp = lines[i];
lines[i] = lines[r];
lines[r] = tmp;
+1 -1
View File
@@ -9,7 +9,7 @@
//config: bool "split"
//config: default y
//config: help
//config: split a file into pieces.
//config: Split a file into pieces.
//config:
//config:config FEATURE_SPLIT_FANCY
//config: bool "Fancy extensions"
+3 -4
View File
@@ -26,13 +26,12 @@
//config: from files.
//config:
//config:config FEATURE_FANCY_TAIL
//config: bool "Enable extra tail options (-q, -s, -v, and -F)"
//config: bool "Enable -q, -s, -v, and -F options"
//config: default y
//config: depends on TAIL
//config: help
//config: The options (-q, -s, -v and -F) are provided by GNU tail, but
//config: are not specific in the SUSv3 standard.
//config:
//config: These options are provided by GNU tail, but
//config: are not specific in the SUSv3 standard:
//config: -q Never output headers giving file names
//config: -s SEC Wait SEC seconds between reads with -f
//config: -v Always output headers giving file names
+8 -7
View File
@@ -42,19 +42,20 @@
//config:config FEATURE_TEST_64
//config: bool "Extend test to 64 bit"
//config: default y
//config: depends on TEST || TEST1 || TEST2 || ASH_BUILTIN_TEST || HUSH
//config: depends on TEST || TEST1 || TEST2 || ASH_TEST || HUSH_TEST
//config: help
//config: Enable 64-bit support in test.
//applet:IF_TEST(APPLET_NOFORK(test, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST1(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST2(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST1(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST2(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//kbuild:lib-$(CONFIG_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_TEST1) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_TEST2) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_ASH_BUILTIN_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_HUSH) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_ASH_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_HUSH_TEST) += test.o test_ptr_hack.o
/* "test --help" is special-cased to ignore --help */
//usage:#define test_trivial_usage NOUSAGE_STR
@@ -841,7 +842,7 @@ int test_main(int argc, char **argv)
const char *arg0;
arg0 = bb_basename(argv[0]);
if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_BUILTIN_TEST || ENABLE_HUSH)
if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_TEST || ENABLE_HUSH_TEST)
&& (arg0[0] == '[')
) {
--argc;
File renamed without changes.
+1 -1
View File
@@ -157,7 +157,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv)
strcpy(uname_info.processor, unknown_str);
strcpy(uname_info.platform, unknown_str);
strcpy(uname_info.os, CONFIG_UNAME_OSNAME);
#if 0
#if ENABLE_FEDORA_COMPAT
/* Fedora does something like this */
strcpy(uname_info.processor, uname_info.name.machine);
strcpy(uname_info.platform, uname_info.name.machine);
+9 -2
View File
@@ -26,6 +26,7 @@
//usage: "\n -c Prefix lines by the number of occurrences"
//usage: "\n -d Only print duplicate lines"
//usage: "\n -u Only print unique lines"
//usage: "\n -i Ignore case"
//usage: "\n -f N Skip first N fields"
//usage: "\n -s N Skip first N chars (after any skipped fields)"
//usage: "\n -w N Compare N characters in line"
@@ -54,12 +55,13 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
OPT_f = 0x8,
OPT_s = 0x10,
OPT_w = 0x20,
OPT_i = 0x40,
};
skip_fields = skip_chars = 0;
max_chars = INT_MAX;
opt = getopt32(argv, "cduf:+s:+w:+", &skip_fields, &skip_chars, &max_chars);
opt = getopt32(argv, "cduf:+s:+w:+i", &skip_fields, &skip_chars, &max_chars);
argv += optind;
input_filename = argv[0];
@@ -106,7 +108,12 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
++cur_compare;
}
if (!old_line || strncmp(old_compare, cur_compare, max_chars)) {
if (!old_line)
break;
if ((opt & OPT_i)
? strncasecmp(old_compare, cur_compare, max_chars)
: strncmp(old_compare, cur_compare, max_chars)
) {
break;
}
+7
View File
@@ -38,6 +38,13 @@ int usleep_main(int argc UNUSED_PARAM, char **argv)
bb_show_usage();
}
/* Safe wrt NOFORK? (noforks are not allowed to run for
* a long time). Try "usleep 99999999" + ^C + "echo $?"
* in hush with FEATURE_SH_NOFORK=y.
* At least on uclibc, usleep() thanslates to nanosleep()
* which returns early on any signal (even caught one),
* and uclibc does not loop back on EINTR.
*/
usleep(xatou(argv[1]));
return EXIT_SUCCESS;
+9 -3
View File
@@ -47,10 +47,16 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
line = xmalloc_fgets_str_len(src_stream, "\n", &line_len);
if (!line)
break;
/* Handle both Unix and MSDOS text, and stray trailing spaces */
/* Handle both Unix and MSDOS text.
* Note: space should not be trimmed, some encoders use it instead of "`"
* for padding of last incomplete 4-char block.
*/
str_len = line_len;
while (--str_len >= 0 && isspace(line[str_len]))
while (--str_len >= 0
&& (line[str_len] == '\n' || line[str_len] == '\r')
) {
line[str_len] = '\0';
}
if (strcmp(line, "end") == 0) {
return; /* the only non-error exit */
@@ -65,7 +71,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
encoded_len = line[0] * 4 / 3;
/* Check that line is not too short. (we tolerate
* overly _long_ line to accommodate possible extra '`').
* overly _long_ line to accommodate possible extra "`").
* Empty line case is also caught here. */
if (str_len <= encoded_len) {
break; /* go to bb_error_msg_and_die("short file"); */
+2 -2
View File
@@ -40,11 +40,11 @@
//config: in specified files.
//config:
//config:config FEATURE_WC_LARGE
//config: bool "Support very large files in wc"
//config: bool "Support very large counts"
//config: default y
//config: depends on WC
//config: help
//config: Use "unsigned long long" in wc for counter variables.
//config: Use "unsigned long long" for counter variables.
//applet:IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP))
+47 -5
View File
@@ -23,6 +23,14 @@
//config: help
//config: who is used to show who is logged on.
//config:
// procps-ng has this variation of "who":
//config:config W
//config: bool "w"
//config: default y
//config: depends on FEATURE_UTMP
//config: help
//config: w is used to show who is logged on.
//config:
//config:config USERS
//config: bool "users"
//config: default y
@@ -30,11 +38,14 @@
//config: help
//config: Print users currently logged on.
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users))
//applet:IF_WHO(APPLET(who, BB_DIR_USR_BIN, BB_SUID_DROP))
//applet:IF_W( APPLET_ODDNAME(w, who, BB_DIR_USR_BIN, BB_SUID_DROP, w))
//applet:IF_WHO( APPLET( who, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_USERS) += who.o
//kbuild:lib-$(CONFIG_WHO) += who.o
//kbuild:lib-$(CONFIG_W) += who.o
//kbuild:lib-$(CONFIG_WHO) += who.o
/* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */
@@ -43,6 +54,31 @@
//usage:#define users_full_usage "\n\n"
//usage: "Print the users currently logged on"
//usage:#define w_trivial_usage
//usage: ""
//usage:#define w_full_usage "\n\n"
//usage: "Show who is logged on"
//
// procps-ng 3.3.10:
// "\n -h, --no-header"
// "\n -u, --no-current"
// Ignores the username while figuring out the current process
// and cpu times. To demonstrate this, do a "su" and do a "w" and a "w -u".
// "\n -s, --short"
// Short format. Don't print the login time, JCPU or PCPU times.
// "\n -f, --from"
// Toggle printing the from (remote hostname) field.
// The default is for the from field to not be printed
// "\n -i, --ip-addr"
// Display IP address instead of hostname for from field.
// "\n -o, --old-style"
// Old style output. Prints blank space for idle times less than one minute.
// Example output:
// 17:28:00 up 4 days, 22:41, 4 users, load average: 0.84, 0.97, 0.90
// USER TTY LOGIN@ IDLE JCPU PCPU WHAT
// root tty1 Thu18 4days 4:33m 0.07s /bin/sh /etc/xdg/xfce4/xinitrc -- vt
// root pts/1 Mon13 3:24m 1:01 0.01s w
//usage:#define who_trivial_usage
//usage: "[-a]"
//usage:#define who_full_usage "\n\n"
@@ -73,14 +109,17 @@ static void idle_string(char *str6, time_t t)
int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int who_main(int argc UNUSED_PARAM, char **argv)
{
#define CNT_APPLET (ENABLE_USERS + ENABLE_W + ENABLE_WHO)
int do_users = (ENABLE_USERS && (CNT_APPLET == 1 || applet_name[0] == 'u'));
int do_w = (ENABLE_W && (CNT_APPLET == 1 || applet_name[1] == '\0'));
int do_who = (ENABLE_WHO && (CNT_APPLET == 1 || applet_name[1] == 'h'));
struct utmpx *ut;
unsigned opt;
int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
const char *fmt = "%s";
opt_complementary = "=0";
opt = getopt32(argv, do_users ? "" : "aH");
if (opt & 2) // -H
opt = getopt32(argv, do_who ? "aH" : "");
if ((opt & 2) || do_w) /* -H or we are w */
puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
setutxent();
@@ -114,6 +153,9 @@ int who_main(int argc UNUSED_PARAM, char **argv)
(int)sizeof(ut->ut_user), ut->ut_user,
(int)sizeof(ut->ut_line), ut->ut_line,
str6,
// TODO: with LANG=en_US.UTF-8, who from coreutils 8.25 shows
// TIME col as "2017-04-06 18:47" (the default format is "Apr 6 18:47").
// The former format looks saner to me. Switch to it unconditionally?
ctime(&seconds) + 4,
(int)sizeof(ut->ut_host), ut->ut_host
);
+2 -1
View File
@@ -17,7 +17,8 @@
//config: yes is used to repeatedly output a specific string, or
//config: the default string `y'.
//applet:IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
//applet:IF_YES(APPLET_NOEXEC(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
/* was NOFORK, but then yes can't be ^C'ed if run by hush */
//kbuild:lib-$(CONFIG_YES) += yes.o
-2
View File
@@ -41,8 +41,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on RUN_PARTS && LONG_OPTS
//config: help
//config: Support long options for the run-parts applet.
//config:
//config:config FEATURE_RUN_PARTS_FANCY
//config: bool "Support additional arguments"
+5 -8
View File
@@ -64,22 +64,19 @@ Misc options:
//config: termination of system-level processes, usually the ones
//config: started during the startup of the system.
//config:
//config:config FEATURE_START_STOP_DAEMON_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on START_STOP_DAEMON && LONG_OPTS
//config:
//config:config FEATURE_START_STOP_DAEMON_FANCY
//config: bool "Support additional arguments"
//config: default y
//config: depends on START_STOP_DAEMON
//config: help
//config: Support additional arguments.
//config: -o|--oknodo ignored since we exit with 0 anyway
//config: -v|--verbose
//config: -N|--nicelevel N
//config:
//config:config FEATURE_START_STOP_DAEMON_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on START_STOP_DAEMON && LONG_OPTS
//config: help
//config: Support long options for the start-stop-daemon applet.
//applet:IF_START_STOP_DAEMON(APPLET_ODDNAME(start-stop-daemon, start_stop_daemon, BB_DIR_SBIN, BB_SUID_DROP, start_stop_daemon))
+37 -7
View File
@@ -33,6 +33,7 @@ roughly are:
* do not expect shared global variables/buffers to be in their
"initialized" state. Examples: xfunc_error_retval can be != 1,
bb_common_bufsiz1 can be scribbled over, ...
(although usually xfunc_error_retval's state is not a problem).
* do not expect that stdio wasn't used before. Calling set[v]buf()
can be disastrous.
* ...
@@ -51,6 +52,9 @@ xargs, find, shells do it (grep for "spawn_and_wait" and
This poses much more serious limitations on what applet can do:
* all NOEXEC limitations apply.
* do not run for a long time or wait for user input:
hush shell only handles signals (like ^C) after you return
from APPLET_main().
* do not ever exit() or exec().
- xfuncs are okay. They are using special trick to return
to the caller applet instead of dying when they detect "x" condition.
@@ -81,18 +85,44 @@ are probably not worth the effort.
Any NOFORK applet is also a NOEXEC applet.
Calling NOFORK applets
API to call NOFORK applets is two functions:
run_nofork_applet(appno, argv)
spawn_and_wait(argv) // only if FEATURE_PREFER_APPLETS=y
First one is directly used by shells if FEATURE_SH_NOFORK=y.
Second one is used by many applets, but main users are xargs and find.
It itself calls run_nofork_applet(), if argv[0] turned out to be a name
of a NOFORK applet.
run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval,
applet_name. Thus, for example, caller does not need to worry about
option_mask32 getting trashed.
Calling NOEXEC applets
It's the same trusty spawn_and_wait(argv). If FEATURE_PREFER_APPLETS=y,
it does NOEXEC trick. It resets xfunc_error_retval = 1 and
logmode = LOGMODE_STDIO in the child.
Relevant CONFIG options
FEATURE_PREFER_APPLETS
BB_EXECVP(cmd, argv) will try to exec /proc/self/exe
if command's name matches some applet name
applet tables will contain NOFORK/NOEXEC bits
if command's name matches some applet name;
spawn_and_wait(argv) will do NOFORK/NOEXEC tricks
FEATURE_SH_STANDALONE (needs FEATURE_PREFER_APPLETS=y)
shells will try to exec /proc/self/exe if command's name matches
some applet name
shells will do NOEXEC trick on NOEXEC applets
//TODO: the above two things probably should have separate options?
FEATURE_SH_NOFORK (needs FEATURE_PREFER_APPLETS=y)
FEATURE_SH_STANDALONE
shells will try to exec /proc/self/exe if command's name matches
some applet name; shells will do NOEXEC trick on NOEXEC applets
//TODO: split (same as for PREFER_APPLETS)
FEATURE_SH_NOFORK
shells will do NOFORK trick on NOFORK applets
+7 -1
View File
@@ -22,7 +22,7 @@ POSIX Tools supported only as shell built-ins (ash shell):
POSIX Tools not supported:
asa, at, batch, bc, c99, command, compress, csplit, ex, fc, file,
gencat, getconf, iconv, join, link, locale, localedef, lp, m4,
mailx, newgrp, nl, paste, pathchk, pax, pr, qalter, qdel, qhold, qmove,
mailx, newgrp, nl, pathchk, pax, pr, qalter, qdel, qhold, qmove,
qmsg, qrerun, qrls, qselect, qsig, qstat, qsub, tabs, talk, tput,
tsort, unlink, uucp, uustat, uux
@@ -469,6 +469,12 @@ od POSIX options
-x | no | no |
od Busybox specific options: None
paste POSIX options
option | exists | compliant | remarks
-d list | yes | yes |
-s | yes | yes |
paste Busybox specific options: None
patch POSIX options
option | exists | compliant | remarks
-D define | no | no |
+5 -5
View File
@@ -45,7 +45,7 @@ intention.
</td></tr><tr><th valign=top align=left>Required knowledge: </th>
<td valign=top align=left>You have to know what it means to catch SIGINT or SIGQUIT and how
processes are waiting for other processes (childs) they spawned.
processes are waiting for other processes (children) they spawned.
</td></tr></table>
@@ -366,7 +366,7 @@ signal, it has to take care of communicating the signal status
itself.
<p>Some programs don't do this. On SIGINT, they do cleanup and exit
immediatly, but the calling shell isn't told about the non-normal exit
immediately, but the calling shell isn't told about the non-normal exit
and it will call the next program in the script.
<p>As a result, the user hits SIGINT and while one program exits, the
@@ -446,7 +446,7 @@ handlers, so it is portable.
<code>trap</code> command. Here, the same as for C programs apply. If
the intention of SIGINT is to end your program, you have to exit in a
way that the calling programs "sees" that you have been killed. If
you don't catch SIGINT, this happend automatically, but of you catch
you don't catch SIGINT, this happened automatically, but of you catch
SIGINT, i.e. to do cleanup work, you have to end the program by
killing yourself, not by calling exit.
@@ -466,7 +466,7 @@ files (which isn't really portable in C, though).
bourne shell. Every language implementation that lets you catch SIGINT
should also give you the option to reset the signal and kill yourself.
<P>It is always desireable to exit the right way, even if you don't
<P>It is always desirable to exit the right way, even if you don't
expect your usual callers to depend on it, some unusual one will come
along. This proper exit status will be needed for WCE and will not
hurt when the calling shell uses IUE or WUE.
@@ -565,7 +565,7 @@ comments the scripts echo.
<th>What happens when a shellscript called emacs, the user did not use
<code>C-c</code> and the script has additional commands in it?</th>
<th>What happens if a non-interactive child catches SIGINT?</th>
<th>To behave properly, childs must do what?</th>
<th>To behave properly, children must do what?</th>
</tr>
<tr valign=top align=left>
+1 -1
View File
@@ -329,7 +329,7 @@ With "const int" compiler may fail to optimize it out and will reserve
a real storage in rodata for it! (Hopefully, newer gcc will get better
at it...). With "define", you have slight risk of polluting namespace
(#define doesn't allow you to redefine the name in the inner scopes),
and complex "define" are evaluated each time they uesd, not once
and complex "define" are evaluated each time they used, not once
at declarations like enums. Also, the preprocessor does _no_ type checking
whatsoever, making it much more error prone.
+1 -1
View File
@@ -1071,7 +1071,7 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
new_args(); /* G.args[G.num_args - 1] is the last, NULL element */
if (!notitle)
puts("fsck (busybox "BB_VER", "BB_BT")");
puts("fsck (busybox "BB_VER")");
/* Even plain "fsck /dev/hda1" needs fstab to get fs type,
* so we are scanning it anyway */
+1 -1
View File
@@ -12,7 +12,7 @@ config FEATURE_ALLOW_EXEC
default y
depends on VI || AWK
help
Enables vi and awk features which allows user to execute
Enables vi and awk features which allow user to execute
shell commands (using system() C call).
endmenu
+21 -18
View File
@@ -88,8 +88,6 @@
//config: bool "Enable long options"
//config: default y
//config: depends on DIFF && LONG_OPTS
//config: help
//config: Enable use of long options.
//config:
//config:config FEATURE_DIFF_DIR
//config: bool "Enable directory support"
@@ -297,17 +295,6 @@ static int search(const int *c, int k, int y, const struct cand *list)
}
}
static unsigned isqrt(unsigned n)
{
unsigned x = 1;
while (1) {
const unsigned y = x;
x = ((n / x) + x) >> 1;
if (x <= (y + 1) && x >= (y - 1))
return x;
}
}
static void stone(const int *a, int n, const int *b, int *J, int pref)
{
const unsigned isq = isqrt(n);
@@ -728,9 +715,19 @@ static int diffreg(char *file[2])
fp[0] = stdin;
fp[1] = stdin;
for (i = 0; i < 2; i++) {
int fd = open_or_warn_stdin(file[i]);
if (fd == -1)
goto out;
int fd = STDIN_FILENO;
if (!LONE_DASH(file[i])) {
if (!(option_mask32 & FLAG(N))) {
fd = open_or_warn(file[i], O_RDONLY);
if (fd == -1)
goto out;
} else {
/* -N: if some file does not exist compare it like empty */
fd = open(file[i], O_RDONLY);
if (fd == -1)
fd = xopen("/dev/null", O_RDONLY);
}
}
/* Our diff implementation is using seek.
* When we meet non-seekable file, we must make a temp copy.
*/
@@ -991,17 +988,23 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
while (L_arg)
label[!!label[0]] = llist_pop(&L_arg);
/* Compat: "diff file name_which_doesnt_exist" exits with 2 */
xfunc_error_retval = 2;
for (i = 0; i < 2; i++) {
file[i] = argv[i];
/* Compat: "diff file name_which_doesnt_exist" exits with 2 */
if (LONE_DASH(file[i])) {
fstat(STDIN_FILENO, &stb[i]);
gotstdin++;
} else
} else if (option_mask32 & FLAG(N)) {
if (stat(file[i], &stb[i]))
xstat("/dev/null", &stb[i]);
} else {
xstat(file[i], &stb[i]);
}
}
xfunc_error_retval = 1;
if (gotstdin && (S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode)))
bb_error_msg_and_die("can't compare stdin to a directory");
+4 -4
View File
@@ -337,7 +337,7 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
if (isdigit(*my_str)) {
*linenum = strtol(my_str, (char**)&pos, 10);
/* endstr shouldnt ever equal NULL */
/* endstr shouldn't ever equal NULL */
} else if (*my_str == '$') {
*linenum = -1;
pos++;
@@ -444,7 +444,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
free(fname);
break;
}
/* Ignore case (gnu exension) */
/* Ignore case (gnu extension) */
case 'i':
case 'I':
cflags |= REG_ICASE;
@@ -587,7 +587,7 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
free(match);
free(replace);
}
/* if it wasnt a single-letter command that takes no arguments
/* if it wasn't a single-letter command that takes no arguments
* then it must be an invalid command.
*/
else if (idx >= IDX_nul) { /* not d,D,g,G,h,H,l,n,N,p,P,q,x,=,{,} */
@@ -751,7 +751,7 @@ static void do_subst_w_backrefs(char *line, char *replace)
continue;
}
/* I _think_ it is impossible to get '\' to be
* the last char in replace string. Thus we dont check
* the last char in replace string. Thus we don't check
* for replace[i] == NUL. (counterexample anyone?) */
/* if we find a backslash escaped character, print the character */
pipe_putc(replace[i]);
+62 -56
View File
@@ -30,7 +30,7 @@
//config: you may wish to use something else.
//config:
//config:config FEATURE_VI_MAX_LEN
//config: int "Maximum screen width in vi"
//config: int "Maximum screen width"
//config: range 256 16384
//config: default 4096
//config: depends on VI
@@ -39,7 +39,7 @@
//config: Make it smaller than 4k only if you are very limited on memory.
//config:
//config:config FEATURE_VI_8BIT
//config: bool "Allow vi to display 8-bit chars (otherwise shows dots)"
//config: bool "Allow to display 8-bit chars (otherwise shows dots)"
//config: default n
//config: depends on VI
//config: help
@@ -53,7 +53,7 @@
//config: default y
//config: depends on VI
//config: help
//config: Enable a limited set of colon commands for vi. This does not
//config: Enable a limited set of colon commands. This does not
//config: provide an "ex" mode.
//config:
//config:config FEATURE_VI_YANKMARK
@@ -61,16 +61,14 @@
//config: default y
//config: depends on VI
//config: help
//config: This will enable you to use yank and put, as well as mark in
//config: busybox vi.
//config: This will enable you to use yank and put, as well as mark.
//config:
//config:config FEATURE_VI_SEARCH
//config: bool "Enable search and replace cmds"
//config: default y
//config: depends on VI
//config: help
//config: Select this if you wish to be able to do search and replace in
//config: busybox vi.
//config: Select this if you wish to be able to do search and replace.
//config:
//config:config FEATURE_VI_REGEX_SEARCH
//config: bool "Enable regex in search and replace"
@@ -84,16 +82,15 @@
//config: default y
//config: depends on VI
//config: help
//config: Selecting this option will make busybox vi signal aware. This will
//config: make busybox vi support SIGWINCH to deal with Window Changes, catch
//config: Ctrl-Z and Ctrl-C and alarms.
//config: Selecting this option will make vi signal aware. This will support
//config: SIGWINCH to deal with Window Changes, catch ^Z and ^C and alarms.
//config:
//config:config FEATURE_VI_DOT_CMD
//config: bool "Remember previous cmd and \".\" cmd"
//config: default y
//config: depends on VI
//config: help
//config: Make busybox vi remember the last command and be able to repeat it.
//config: Make vi remember the last command and be able to repeat it.
//config:
//config:config FEATURE_VI_READONLY
//config: bool "Enable -R option and \"view\" mode"
@@ -104,25 +101,23 @@
//config: open a file in read-only mode.
//config:
//config:config FEATURE_VI_SETOPTS
//config: bool "Enable set-able options, ai ic showmatch"
//config: bool "Enable settable options, ai ic showmatch"
//config: default y
//config: depends on VI
//config: help
//config: Enable the editor to set some (ai, ic, showmatch) options.
//config:
//config:config FEATURE_VI_SET
//config: bool "Support for :set"
//config: bool "Support :set"
//config: default y
//config: depends on VI
//config: help
//config: Support for ":set".
//config:
//config:config FEATURE_VI_WIN_RESIZE
//config: bool "Handle window resize"
//config: default y
//config: depends on VI
//config: help
//config: Make busybox vi behave nicely with terminals that get resized.
//config: Behave nicely with terminals that get resized.
//config:
//config:config FEATURE_VI_ASK_TERMINAL
//config: bool "Use 'tell me cursor position' ESC sequence to measure window"
@@ -133,15 +128,16 @@
//config: this option makes vi perform a last-ditch effort to find it:
//config: position cursor to 999,999 and ask terminal to report real
//config: cursor position using "ESC [ 6 n" escape sequence, then read stdin.
//config:
//config: This is not clean but helps a lot on serial lines and such.
//config:
//config:config FEATURE_VI_UNDO
//config: bool "Support undo command 'u'"
//config: bool "Support undo command \"u\""
//config: default y
//config: depends on VI
//config: help
//config: Support the 'u' command to undo insertion, deletion, and replacement
//config: of text.
//config:
//config:config FEATURE_VI_UNDO_QUEUE
//config: bool "Enable undo operation queuing"
//config: default y
@@ -152,6 +148,7 @@
//config: reached, the contents of the queue are committed to the undo stack.
//config: This increases the size of the undo code and allows some undo
//config: operations (especially un-typing/backspacing) to be far more useful.
//config:
//config:config FEATURE_VI_UNDO_QUEUE_MAX
//config: int "Maximum undo character queue size"
//config: default 256
@@ -357,7 +354,7 @@ struct globals {
#if ENABLE_FEATURE_VI_USE_SIGNALS
sigjmp_buf restart; // catch_sig()
#endif
struct termios term_orig, term_vi; // remember what the cooked mode was
struct termios term_orig; // remember what the cooked mode was
#if ENABLE_FEATURE_VI_COLON
char *initial_cmds[3]; // currently 2 entries, NULL terminated
#endif
@@ -465,7 +462,6 @@ struct globals {
#define context_end (G.context_end )
#define restart (G.restart )
#define term_orig (G.term_orig )
#define term_vi (G.term_vi )
#define initial_cmds (G.initial_cmds )
#define readbuffer (G.readbuffer )
#define scr_out_buf (G.scr_out_buf )
@@ -719,14 +715,6 @@ static int init_text_buffer(char *fn)
{
int rc;
flush_undo_data();
modified_count = 0;
last_modified_count = -1;
#if ENABLE_FEATURE_VI_YANKMARK
/* init the marks */
memset(mark, 0, sizeof(mark));
#endif
/* allocate/reallocate text buffer */
free(text);
text_size = 10240;
@@ -741,6 +729,14 @@ static int init_text_buffer(char *fn)
// file doesnt exist. Start empty buf with dummy line
char_insert(text, '\n', NO_UNDO);
}
flush_undo_data();
modified_count = 0;
last_modified_count = -1;
#if ENABLE_FEATURE_VI_YANKMARK
/* init the marks */
memset(mark, 0, sizeof(mark));
#endif
return rc;
}
@@ -1038,7 +1034,9 @@ static void colon(char *buf)
|| strncmp(p, "wn", cnt) == 0
|| (p[0] == 'x' && !p[1])
) {
cnt = file_write(current_filename, text, end - 1);
if (modified_count != 0 || p[0] != 'x') {
cnt = file_write(current_filename, text, end - 1);
}
if (cnt < 0) {
if (cnt == -1)
status_line_bold("Write error: %s", strerror(errno));
@@ -1049,8 +1047,9 @@ static void colon(char *buf)
current_filename,
count_lines(text, end - 1), cnt
);
if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n'
|| p[0] == 'X' || p[1] == 'Q' || p[1] == 'N'
if (p[0] == 'x'
|| p[1] == 'q' || p[1] == 'n'
|| p[1] == 'Q' || p[1] == 'N'
) {
editing = 0;
}
@@ -1461,7 +1460,7 @@ static void colon(char *buf)
}
#endif /* FEATURE_VI_SEARCH */
} else if (strncmp(cmd, "version", i) == 0) { // show software version
status_line(BB_VER " " BB_BT);
status_line(BB_VER);
} else if (strncmp(cmd, "write", i) == 0 // write text to file
|| strncmp(cmd, "wq", i) == 0
|| strncmp(cmd, "wn", i) == 0
@@ -1480,16 +1479,19 @@ static void colon(char *buf)
goto ret;
}
#endif
// how many lines in text[]?
li = count_lines(q, r);
size = r - q + 1;
//if (useforce) {
// if "fn" is not write-able, chmod u+w
// sprintf(syscmd, "chmod u+w %s", fn);
// system(syscmd);
// forced = TRUE;
//}
l = file_write(fn, q, r);
if (modified_count != 0 || cmd[0] != 'x') {
size = r - q + 1;
l = file_write(fn, q, r);
} else {
size = 0;
l = 0;
}
//if (useforce && forced) {
// chmod u-w
// sprintf(syscmd, "chmod u-w %s", fn);
@@ -1500,17 +1502,20 @@ static void colon(char *buf)
if (l == -1)
status_line_bold_errno(fn);
} else {
// how many lines written
li = count_lines(q, q + l - 1);
status_line("'%s' %dL, %dC", fn, li, l);
if (q == text && r == end - 1 && l == size) {
modified_count = 0;
last_modified_count = -1;
}
if ((cmd[0] == 'x' || cmd[1] == 'q' || cmd[1] == 'n'
|| cmd[0] == 'X' || cmd[1] == 'Q' || cmd[1] == 'N'
)
&& l == size
) {
editing = 0;
if (l == size) {
if (q == text && q + l == end) {
modified_count = 0;
last_modified_count = -1;
}
if (cmd[0] == 'x'
|| cmd[1] == 'q' || cmd[1] == 'n'
|| cmd[1] == 'Q' || cmd[1] == 'N'
) {
editing = 0;
}
}
}
#if ENABLE_FEATURE_VI_YANKMARK
@@ -2734,15 +2739,9 @@ static char *swap_context(char *p) // goto new context for '' command make this
//----- Set terminal attributes --------------------------------
static void rawmode(void)
{
tcgetattr(0, &term_orig);
term_vi = term_orig;
term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG on - allow intr's
term_vi.c_iflag &= (~IXON & ~ICRNL);
term_vi.c_oflag &= (~ONLCR);
term_vi.c_cc[VMIN] = 1;
term_vi.c_cc[VTIME] = 0;
erase_char = term_vi.c_cc[VERASE];
tcsetattr_stdin_TCSANOW(&term_vi);
// no TERMIOS_CLEAR_ISIG: leave ISIG on - allow signals
set_termios_to_raw(STDIN_FILENO, &term_orig, TERMIOS_RAW_CRNL);
erase_char = term_orig.c_cc[VERASE];
}
static void cookmode(void)
@@ -2817,8 +2816,15 @@ static int readit(void) // read (maybe cursor) key from stdin
int c;
fflush_all();
c = read_key(STDIN_FILENO, readbuffer, /*timeout off:*/ -2);
// Wait for input. TIMEOUT = -1 makes read_key wait even
// on nonblocking stdin.
// Note: read_key sets errno to 0 on success.
again:
c = read_key(STDIN_FILENO, readbuffer, /*timeout:*/ -1);
if (c == -1) { // EOF/error
if (errno == EAGAIN) // paranoia
goto again;
go_bottom_and_clear_to_eol();
cookmode(); // terminal to "cooked"
bb_error_msg_and_die("can't read user input");
+1 -1
View File
@@ -7,7 +7,7 @@
# Licensed under GPLv2, see file LICENSE in this source tree.
#
local BASE="${1:-/usr/lib/modules}"
BASE="${1:-/usr/lib/modules}"
find "$BASE" -name '*.ko.gz' | while read I ; do
N=`basename "$I" '.ko.gz'`
+1 -1
View File
@@ -14,7 +14,7 @@ env | sort
while sleep 1; test $cnt != 0; do
echo "Trying to reread partition table on $DEVNAME ($cnt)"
: $((cnt--))
cnt=$((cnt-1))
# If device node doesn't exist, it means the device was removed.
# Stop trying.
test -e "$DEVNAME" || { echo "$DEVNAME doesn't exist, aborting"; exit 1; }
+8 -1
View File
@@ -18,11 +18,18 @@ then
metric=0
for i in $router
do
if [ "$subnet" = "255.255.255.255" ]; then
# special case for /32 subnets:
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
/sbin/ip route add $i dev $interface
fi
/sbin/route add default gw $i dev $interface metric $((metric++))
done
fi
# Only replace resolv.conf is we have at least one DNS server
# Only replace resolv.conf if we have at least one DNS server
if [ -n "$dns" ]
then
echo -n > $RESOLV_CONF
+9 -2
View File
@@ -1,5 +1,5 @@
#!/bin/sh
# Sample udhcpc bound script
# Sample udhcpc renew script
RESOLV_CONF="/etc/udhcpc/resolv.conf"
@@ -18,11 +18,18 @@ then
metric=0
for i in $router
do
if [ "$subnet" = "255.255.255.255" ]; then
# special case for /32 subnets:
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
/sbin/ip route add $i dev $interface
fi
/sbin/route add default gw $i dev $interface metric $((metric++))
done
fi
# Only replace resolv.conf is we have at least one DNS server
# Only replace resolv.conf if we have at least one DNS server
if [ -n "$dns" ]
then
echo -n > $RESOLV_CONF
+8 -2
View File
@@ -29,8 +29,14 @@ case "$1" in
metric=0
for i in $router ; do
echo "Adding router $i"
route add default gw $i dev $interface metric $metric
: $(( metric += 1 ))
if [ "$subnet" = "255.255.255.255" ]; then
# special case for /32 subnets:
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
ip route add $i dev $interface
fi
route add default gw $i dev $interface metric $((metric++))
done
fi
+25 -18
View File
@@ -48,7 +48,7 @@ ps tells me they did put X, dbus, NM and udev into runsvdir-supervised tree:
654 ? 00:00:00 runsv
659 ? 00:00:00 udevd
Here is a link to Vod Linux's wiki:
Here is a link to Void Linux's wiki:
https://wiki.voidlinux.eu/Runit
@@ -98,10 +98,10 @@ It is not required that a specific clone should be used. Let evolution work.
daemon: any long running background program. Common examples are sshd, getty,
ntpd, dhcp client...
service: same as "daemon"
service: daemon controlled by a service monitor.
service directory: a directory with an executable file (script) named "run"
which (usually) execs daemon (possibly after some preparatory steps).
which (usually) execs some daemon, possibly after some preparatory steps.
It should start it not as a child or daemonized process, but by exec'ing it
(inheriting the same PID and the place in the process tree).
@@ -116,7 +116,7 @@ whose directories disappeared.
supervisor: a tool which monitors one service directory.
It runs "run" script as its child. It restarts it if it dies.
It can be instructed to start/top/signal its child.
It can be instructed to start/stop/signal its child.
In daemontools package, it is called "supervise". In runit, it is called
"runsv". In s6, it is called "s6-supervise".
@@ -150,7 +150,9 @@ The less distros diverge, the easier users' lives are.
System-wide service dirs reside in a distro-specific location.
The recommended location is /var/service. (However, since it is not
a mandatory location, avoid depending on it in your run scripts).
a mandatory location, avoid depending on it in your run scripts.
Void Linux wanted to have it somewhere in /run/*, and they solved this
by making /var/service a symlink).
The install location for service dirs is /etc/rc:
when e.g. ntpd daemon is installed, it creates the /etc/rc/ntpd
@@ -182,10 +184,14 @@ of bad things may happen. This may be worked around by various
heuristics in service monitor which give new service a few seconds
of "grace time" to be fully populated; but this is not yet
implemented in any of three packages.
This also may be worked around by creating a .dotdir (a directory
whose name starts with a dot), populating it, and then renaming;
but packaging tools usually do not have an option to do this
automatically - additional install scripting in packages will be needed.
Daemons' output file descriptors are handled somewhat awkwardly
by various daemontools implementations. For example, for runit tools,
daemons' stdout goes to wherever runsdir's stdout was directied;
daemons' stdout goes to wherever runsvdir's stdout was directed;
stderr goes to runsvdir, which in turn "rotates" it on its command line
(which is visible in ps output).
@@ -236,11 +242,11 @@ there is no guarantee in which order commands are sent to them.
If DIR has no slash and is not "." or "..", it is assumed to be
relative to the system-wide service directory.
The "svok DIR" tool exits 0 if service is running, and nonzero if not.
[Currently, "svc" exists only in daemontools and in busybox.
This proposal asks developers of other daemontools implementations
to add "svc" command to their projects]
The "svstat DIR1 DIR2..." prints one human-readable line for each directory,
saying whether supervise is successfully running in that directory,
and reporting the status information maintained by supervise.
The "svok DIR" tool exits 0 if service is running, and nonzero if not.
Other tools with different names and APIs may exist; however
for portability scripts should use the above tools.
@@ -250,27 +256,28 @@ To this end, first create and populate a new /etc/rc/DIR.
Then "activate" it by running ??????? - this copies (or symlinks,
depending on the distro) its files to the "live" service directory,
whereever it is located on this distro.
wherever it is located on this distro.
Removal of the service should be done as follows:
svc -d DIR [DIR/log], then remove the service directory
(this makes service monitor SIGTERM per-directory supervisors
(if they exist in the implementation))
svc -d DIR [DIR/log], then remove the service directory:
this makes service monitor SIGTERM per-directory supervisors
(if they exist in the implementation).
Implementation details
Top-level service monitor program name is not standardized.
[svscan, runsvdir, s6-svscan ...]
Top-level service monitor program name is not standardized
[svscan, runsvdir, s6-svscan ...] - it does not need to be,
as far as daemon packagers are concerned.
It may run one per-directory supervisor, or two supervisors
(one for DIR/ and one for DIR/log/); for memory-constrained systems
an implementation is possible which itself controls all services, without
intermediate supervisors.
[runsvdir runs one "runsv DIR" per DIR, runsv handles DIR/log/ if that exists]
[svscan runs a pair of "superwise DIR" and "superwise DIR/log"]
[svscan runs a pair of "supervise DIR" and "supervise DIR/log"]
Directores are remembered by device+inode numbers, not names. Renaming a directory
Directories are remembered by device+inode numbers, not names. Renaming a directory
does not affect the running service (unless it is renamed to a .dotdir).
Removal (or .dotdiring) of a directory sends SIGTERM to any running services.
+1 -1
View File
@@ -21,7 +21,7 @@
# ntpsrv=10.34.32.125 10.34.255.7
#
# renew: lease is renewed. Environment is similar to "bound".
# The IP address does not change, however, the other DHCP paramaters,
# The IP address does not change, however, the other DHCP parameters,
# such as the default gateway, subnet mask, and dns server may change.
#
# nak: udhcpc received a NAK message.
+1 -1
View File
@@ -30,7 +30,7 @@ test x"$router" != x"" || exec env - sleep "$ping_time"
failcnt=0
while true; do
ping $ping_opts "$router" && exec env - sleep "$ping_time"
: $((failcnt++))
failcnt=$((failcnt+1))
msg "Failed to ping $router, fail count:$failcnt"
test $failcnt -ge $max_fail && break
env - sleep "$retry_time"
+1 -15
View File
@@ -89,8 +89,6 @@
//config: bool "Enable -perm: permissions matching"
//config: default y
//config: depends on FIND
//config: help
//config: Enable searching based on file permissions.
//config:
//config:config FEATURE_FIND_TYPE
//config: bool "Enable -type: file type matching (file/dir/link/...)"
@@ -104,15 +102,11 @@
//config: bool "Enable -xdev: 'stay in filesystem'"
//config: default y
//config: depends on FIND
//config: help
//config: This option allows find to restrict searches to a single filesystem.
//config:
//config:config FEATURE_FIND_MAXDEPTH
//config: bool "Enable -mindepth N and -maxdepth N"
//config: default y
//config: depends on FIND
//config: help
//config: This option enables -mindepth N and -maxdepth N option.
//config:
//config:config FEATURE_FIND_NEWER
//config: bool "Enable -newer: compare file modification times"
@@ -126,8 +120,6 @@
//config: bool "Enable -inum: inode number matching"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -inum' option for searching by inode number.
//config:
//config:config FEATURE_FIND_EXEC
//config: bool "Enable -exec: execute commands"
@@ -151,15 +143,11 @@
//config: bool "Enable -user: username/uid matching"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -user' option for searching by username or uid.
//config:
//config:config FEATURE_FIND_GROUP
//config: bool "Enable -group: group/gid matching"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -group' option for searching by group name or gid.
//config:
//config:config FEATURE_FIND_NOT
//config: bool "Enable the 'not' (!) operator"
@@ -188,15 +176,13 @@
//config: bool "Enable -size: file size matching"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -size' option for searching by file size.
//config:
//config:config FEATURE_FIND_PRUNE
//config: bool "Enable -prune: exclude subdirectories"
//config: default y
//config: depends on FIND
//config: help
//config: If the file is a directory, dont descend into it. Useful for
//config: If the file is a directory, don't descend into it. Useful for
//config: exclusion .svn and CVS directories.
//config:
//config:config FEATURE_FIND_DELETE
+4 -3
View File
@@ -39,13 +39,14 @@
//config:config FEATURE_GREP_CONTEXT
//config: bool "Enable before and after context flags (-A, -B and -C)"
//config: default y
//config: depends on GREP || EGREP
//config: depends on GREP || EGREP || FGREP
//config: help
//config: Print the specified number of leading (-B) and/or trailing (-A)
//config: context surrounding our matching lines.
//config: Print the specified number of context lines (-C).
//applet:IF_GREP(APPLET(grep, BB_DIR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_EGREP(APPLET_ODDNAME(egrep, grep, BB_DIR_BIN, BB_SUID_DROP, egrep))
//applet:IF_FGREP(APPLET_ODDNAME(fgrep, grep, BB_DIR_BIN, BB_SUID_DROP, fgrep))
@@ -514,7 +515,7 @@ static int grep_file(FILE *file)
if (option_mask32 & OPT_o) {
if (FGREP_FLAG) {
/* -Fo just prints the pattern
* (unless -v: -Fov doesnt print anything at all) */
* (unless -v: -Fov doesn't print anything at all) */
if (found)
print_line(gl->pattern, strlen(gl->pattern), linenum, ':');
} else while (1) {
@@ -822,7 +823,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
grep_done: ;
} while (*argv && *++argv);
/* destroy all the elments in the pattern list */
/* destroy all the elements in the pattern list */
if (ENABLE_FEATURE_CLEAN_UP) {
while (pattern_head) {
llist_t *pattern_head_ptr = pattern_head;
+5 -6
View File
@@ -4,11 +4,7 @@
# enabling it. Run it after applets.h is generated.
# CONFIG_applet names
grep ^IF_ applets.h | grep -v IF_FEATURE_ | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
| grep -v MODPROBE_SMALL \
| sed 's/BB_SYSCTL/SYSCTL/' \
| sed 's/TEST1/[/' \
| sed 's/TEST2/[[/' \
grep ^IF_ applets.h | grep -v ^IF_FEATURE_ | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
| sort | uniq \
>applets_APP1
@@ -17,8 +13,11 @@ grep ^IF_ applets.h | sed -e's/ //g' -e's/.*(\([a-z[][^,]*\),.*/\1/' \
| grep -v '^bash$' \
| grep -v '^sh$' \
| tr a-z A-Z \
| sed 's/^SYSCTL$/BB_SYSCTL/' \
| sed 's/^\[\[$/TEST1/' \
| sed 's/^\[$/TEST2/' \
| sort | uniq \
>applets_APP2
diff -u applets_APP1 applets_APP2 >applets_APP.diff
rm applets_APP1 applets_APP2
#rm applets_APP1 applets_APP2
+142 -35
View File
@@ -342,6 +342,8 @@ extern int *const bb_errno;
uint64_t bb_bswap_64(uint64_t x) FAST_FUNC;
#endif
unsigned long FAST_FUNC isqrt(unsigned long long N);
unsigned long long monotonic_ns(void) FAST_FUNC;
unsigned long long monotonic_us(void) FAST_FUNC;
unsigned long long monotonic_ms(void) FAST_FUNC;
@@ -355,6 +357,27 @@ extern char *skip_dev_pfx(const char *tty_name) FAST_FUNC;
extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC;
/* dmalloc will redefine these to it's own implementation. It is safe
* to have the prototypes here unconditionally. */
void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xrealloc(void *old, size_t size) FAST_FUNC;
/* After v = xrealloc_vector(v, SHIFT, idx) it's ok to use
* at least v[idx] and v[idx+1], for all idx values.
* SHIFT specifies how many new elements are added (1:2, 2:4, ..., 8:256...)
* when all elements are used up. New elements are zeroed out.
* xrealloc_vector(v, SHIFT, idx) *MUST* be called with consecutive IDXs -
* skipping an index is a bad bug - it may miss a realloc!
*/
#define xrealloc_vector(vector, shift, idx) \
xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx))
void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC;
char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
//TODO: supply a pointer to char[11] buffer (avoid statics)?
extern const char *bb_mode_string(mode_t mode) FAST_FUNC;
extern int is_directory(const char *name, int followLinks) FAST_FUNC;
@@ -693,6 +716,56 @@ struct hostent *xgethostbyname(const char *name) FAST_FUNC;
// + inet_common.c has additional IPv4-only stuff
#define TLS_MAX_MAC_SIZE 32
#define TLS_MAX_KEY_SIZE 32
struct tls_handshake_data; /* opaque */
typedef struct tls_state {
int ofd;
int ifd;
unsigned min_encrypted_len_on_read;
uint16_t cipher_id;
uint8_t encrypt_on_write;
unsigned MAC_size;
unsigned key_size;
uint8_t *outbuf;
int outbuf_size;
int inbuf_size;
int ofs_to_buffered;
int buffered_size;
uint8_t *inbuf;
struct tls_handshake_data *hsd;
// RFC 5246
// sequence number
// Each connection state contains a sequence number, which is
// maintained separately for read and write states. The sequence
// number MUST be set to zero whenever a connection state is made the
// active state. Sequence numbers are of type uint64 and may not
// exceed 2^64-1.
/*uint64_t read_seq64_be;*/
uint64_t write_seq64_be;
uint8_t *client_write_key;
uint8_t *server_write_key;
uint8_t client_write_MAC_key[TLS_MAX_MAC_SIZE];
uint8_t server_write_MAC_k__[TLS_MAX_MAC_SIZE];
uint8_t client_write_k__[TLS_MAX_KEY_SIZE];
uint8_t server_write_k__[TLS_MAX_KEY_SIZE];
} tls_state_t;
static inline tls_state_t *new_tls_state(void)
{
tls_state_t *tls = xzalloc(sizeof(*tls));
return tls;
}
void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC;
void tls_run_copy_loop(tls_state_t *tls) FAST_FUNC;
void socket_want_pktinfo(int fd) FAST_FUNC;
ssize_t send_to_from(int fd, void *buf, size_t len, int flags,
const struct sockaddr *to,
@@ -705,9 +778,8 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
/* 0 if argv[0] is NULL: */
unsigned string_array_len(char **argv) FAST_FUNC;
void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
@@ -753,24 +825,6 @@ enum {
};
void visible(unsigned ch, char *buf, int flags) FAST_FUNC;
/* dmalloc will redefine these to it's own implementation. It is safe
* to have the prototypes here unconditionally. */
void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xrealloc(void *old, size_t size) FAST_FUNC;
/* After v = xrealloc_vector(v, SHIFT, idx) it's ok to use
* at least v[idx] and v[idx+1], for all idx values.
* SHIFT specifies how many new elements are added (1:2, 2:4, ..., 8:256...)
* when all elements are used up. New elements are zeroed out.
* xrealloc_vector(v, SHIFT, idx) *MUST* be called with consecutive IDXs -
* skipping an index is a bad bug - it may miss a realloc!
*/
#define xrealloc_vector(vector, shift, idx) \
xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx))
void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC;
extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC;
extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC;
// NB: will return short read on error, not -1,
@@ -1043,10 +1097,19 @@ pid_t wait_any_nohang(int *wstat) FAST_FUNC;
*/
int wait4pid(pid_t pid) FAST_FUNC;
int wait_for_exitstatus(pid_t pid) FAST_FUNC;
/************************************************************************/
/* spawn_and_wait/run_nofork_applet/run_applet_no_and_exit need to work */
/* carefully together to reinit some global state while not disturbing */
/* other. Be careful if you change them. Consult docs/nofork_noexec.txt */
/************************************************************************/
/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
int spawn_and_wait(char **argv) FAST_FUNC;
/* Does NOT check that applet is NOFORK, just blindly runs it */
int run_nofork_applet(int applet_no, char **argv) FAST_FUNC;
#ifndef BUILD_INDIVIDUAL
extern int find_applet_by_name(const char *name) FAST_FUNC;
extern void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC;
#endif
/* Helpers for daemonization.
*
@@ -1115,6 +1178,26 @@ extern const char *applet_long_options;
#endif
extern uint32_t option_mask32;
extern uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC;
/* BSD-derived getopt() functions require that optind be set to 1 in
* order to reset getopt() state. This used to be generally accepted
* way of resetting getopt(). However, glibc's getopt()
* has additional getopt() state beyond optind (specifically, glibc
* extensions such as '+' and '-' at the start of the string), and requires
* that optind be set to zero to reset its state. BSD-derived versions
* of getopt() misbehaved if optind is set to 0 in order to reset getopt(),
* and glibc's getopt() used to coredump if optind is set 1 in order
* to reset getopt().
* Then BSD introduced additional variable "optreset" which should be
* set to 1 in order to reset getopt(). Sigh. Standards, anyone?
*
* By ~2008, OpenBSD 3.4 was changed to survive glibc-like optind = 0
* (to interpret it as if optreset was set).
*/
#ifdef __GLIBC__
#define GETOPT_RESET() (optind = 0)
#else /* BSD style */
#define GETOPT_RESET() (optind = 1)
#endif
/* Having next pointer as a first member allows easy creation
@@ -1186,7 +1269,7 @@ extern void bb_logenv_override(void) FAST_FUNC;
/* Applets which are useful from another applets */
int bb_cat(char** argv);
int bb_cat(char** argv) FAST_FUNC;
/* If shell needs them, they exist even if not enabled as applets */
int echo_main(int argc, char** argv) IF_ECHO(MAIN_EXTERNALLY_VISIBLE);
int printf_main(int argc, char **argv) IF_PRINTF(MAIN_EXTERNALLY_VISIBLE);
@@ -1212,6 +1295,16 @@ int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
void bb_displayroutes(int noresolve, int netstatfmt) FAST_FUNC;
#endif
struct number_state {
unsigned width;
unsigned start;
unsigned inc;
const char *sep;
const char *empty_str;
smallint all, nonempty;
};
void print_numbered_lines(struct number_state *ns, const char *filename) FAST_FUNC;
/* Networking */
/* This structure defines protocol families and their handlers. */
@@ -1253,13 +1346,8 @@ const struct hwtype *get_hwtype(const char *name) FAST_FUNC;
const struct hwtype *get_hwntype(int type) FAST_FUNC;
#ifndef BUILD_INDIVIDUAL
extern int find_applet_by_name(const char *name) FAST_FUNC;
extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
#endif
extern int fstype_matches(const char *fstype, const char *comma_list) FAST_FUNC;
#ifdef HAVE_MNTENT_H
extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC;
extern struct mntent *find_mount_point(const char *name, int subdir_too) FAST_FUNC;
#endif
extern void erase_mtab(const char * name) FAST_FUNC;
@@ -1275,10 +1363,15 @@ extern int get_linux_version_code(void) FAST_FUNC;
extern char *query_loop(const char *device) FAST_FUNC;
extern int del_loop(const char *device) FAST_FUNC;
/* If *devname is not NULL, use that name, otherwise try to find free one,
/*
* If *devname is not NULL, use that name, otherwise try to find free one,
* malloc and return it in *devname.
* return value: 1: read-only loopdev was setup, 0: rw, < 0: error */
extern int set_loop(char **devname, const char *file, unsigned long long offset, int ro) FAST_FUNC;
* return value is the opened fd to the loop device, or < on error
*/
extern int set_loop(char **devname, const char *file, unsigned long long offset, unsigned flags) FAST_FUNC;
/* These constants match linux/loop.h (without BB_ prefix): */
#define BB_LO_FLAGS_READ_ONLY 1
#define BB_LO_FLAGS_AUTOCLEAR 4
/* Like bb_ask below, but asks on stdin with no timeout. */
char *bb_ask_stdin(const char * prompt) FAST_FUNC;
@@ -1390,6 +1483,12 @@ extern void selinux_or_die(void) FAST_FUNC;
#define SETUP_ENV_NO_CHDIR (1 << 4)
void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
void nuke_str(char *str) FAST_FUNC;
#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
int is_tty_secure(const char *short_tty) FAST_FUNC;
#else
static ALWAYS_INLINE int is_tty_secure(const char *short_tty UNUSED_PARAM) { return 1; }
#endif
#define CHECKPASS_PW_HAS_EMPTY_PASSWORD 2
int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC;
int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
@@ -1438,6 +1537,10 @@ int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FU
int get_terminal_width(int fd) FAST_FUNC;
int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC;
#define TERMIOS_CLEAR_ISIG (1 << 0)
#define TERMIOS_RAW_CRNL (1 << 1)
#define TERMIOS_RAW_INPUT (1 << 2)
int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC;
/* NB: "unsigned request" is crucial! "int request" will break some arches! */
int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;
@@ -1749,19 +1852,23 @@ typedef struct sha3_ctx_t {
} sha3_ctx_t;
void md5_begin(md5_ctx_t *ctx) FAST_FUNC;
void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
unsigned md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
#define sha1_hash md5_hash
void sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC;
unsigned sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC;
void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC;
#define sha256_hash md5_hash
#define sha256_end sha1_end
void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC;
void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC;
void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
/* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */
typedef struct md5_ctx_t md5sha_ctx_t;
#define md5sha_hash md5_hash
#define sha_end sha1_end
extern uint32_t *global_crc32_table;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
+10 -5
View File
@@ -108,13 +108,18 @@
* and/or smaller by using modified ABI. It is usually only needed
* on non-static, busybox internal functions. Recent versions of gcc
* optimize statics automatically. FAST_FUNC on static is required
* only if you need to match a function pointer's type */
#if __GNUC_PREREQ(3,0) && defined(i386) /* || defined(__x86_64__)? */
* only if you need to match a function pointer's type.
* FAST_FUNC may not work well with -flto so allow user to disable this.
* (-DFAST_FUNC= )
*/
#ifndef FAST_FUNC
# if __GNUC_PREREQ(3,0) && defined(i386)
/* stdcall makes callee to pop arguments from stack, not caller */
# define FAST_FUNC __attribute__((regparm(3),stdcall))
# define FAST_FUNC __attribute__((regparm(3),stdcall))
/* #elif ... - add your favorite arch today! */
#else
# define FAST_FUNC
# else
# define FAST_FUNC
# endif
#endif
/* Make all declarations hidden (-fvisibility flag only affects definitions) */
+8
View File
@@ -14,6 +14,14 @@
#define NOUSAGE_STR "\b"
#if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA
# define CRYPT_METHODS_HELP_STR "des,md5,sha256/512" \
" (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
#else
# define CRYPT_METHODS_HELP_STR "des,md5" \
" (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
#endif
INSERT
#define busybox_notes_usage \
+2 -1
View File
@@ -46,8 +46,9 @@
//config: locating telinit executable.
//applet:IF_HALT(APPLET(halt, BB_DIR_SBIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_POWEROFF(APPLET_ODDNAME(poweroff, halt, BB_DIR_SBIN, BB_SUID_DROP, poweroff))
//applet:IF_REBOOT(APPLET_ODDNAME(reboot, halt, BB_DIR_SBIN, BB_SUID_DROP, reboot))
//applet:IF_REBOOT( APPLET_ODDNAME(reboot, halt, BB_DIR_SBIN, BB_SUID_DROP, reboot))
//kbuild:lib-$(CONFIG_HALT) += halt.o
//kbuild:lib-$(CONFIG_POWEROFF) += halt.o
+29 -27
View File
@@ -17,7 +17,7 @@
//config: init is the first program run when the system boots.
//config:
//config:config LINUXRC
//config: bool "Support running init from within an initrd (not initramfs)"
//config: bool "linuxrc: support running init from initrd (not initramfs)"
//config: default y
//config: select FEATURE_SYSLOG
//config: help
@@ -73,17 +73,19 @@
//config: bool "Enable init to write to syslog"
//config: default y
//config: depends on INIT || LINUXRC
//config: help
//config: If selected, some init messages are sent to syslog.
//config: Otherwise, they are sent to VT #5 if linux virtual tty is detected
//config: (if not, no separate logging is done).
//config:
//config:config FEATURE_EXTRA_QUIET
//config: bool "Be _extra_ quiet on boot"
//config:config FEATURE_INIT_QUIET
//config: bool "Be quiet on boot (no 'init started:' message)"
//config: default y
//config: depends on INIT || LINUXRC
//config: help
//config: Prevent init from logging some messages to the console during boot.
//config:
//config:config FEATURE_INIT_COREDUMPS
//config: bool "Support dumping core for child processes (debugging only)"
//config: default y
//config: default n # not Y because this is a debug option
//config: depends on INIT || LINUXRC
//config: help
//config: If this option is enabled and the file /.init_enable_core
@@ -104,13 +106,13 @@
//config: sets TERM to "vt102" if one is found.
//config:
//config:config FEATURE_INIT_MODIFY_CMDLINE
//config: bool "Modify the command-line to \"init\""
//config: bool "Clear init's command line"
//config: default y
//config: depends on INIT || LINUXRC
//config: help
//config: When launched as PID 1 and after parsing its arguments, init
//config: wipes all the arguments but argv[0] and rewrites argv[0] to
//config: contain only "init", so that its command-line appears solely as
//config: contain only "init", so that its command line appears solely as
//config: "init" in tools such as ps.
//config: If this option is set to Y, init will keep its original behavior,
//config: otherwise, all the arguments including argv[0] will be preserved,
@@ -214,7 +216,9 @@ struct init_action {
static struct init_action *init_action_list = NULL;
#if !ENABLE_FEATURE_INIT_SYSLOG
static const char *log_console = VC_5;
#endif
enum {
L_LOG = 0x1,
@@ -253,17 +257,16 @@ static void message(int where, const char *fmt, ...)
msg[l++] = '\n';
msg[l] = '\0';
#else
{
static int log_fd = -1;
msg[l++] = '\n';
msg[l] = '\0';
msg[l++] = '\n';
msg[l] = '\0';
if (where & L_LOG) {
/* Take full control of the log tty, and never close it.
* It's mine, all mine! Muhahahaha! */
static int log_fd = -1;
if (log_fd < 0) {
if (!log_console) {
log_fd = STDERR_FILENO;
} else {
log_fd = STDERR_FILENO;
if (log_console) {
log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
if (log_fd < 0) {
bb_error_msg("can't log to %s", log_console);
@@ -273,11 +276,9 @@ static void message(int where, const char *fmt, ...)
}
}
}
if (where & L_LOG) {
full_write(log_fd, msg, l);
if (log_fd == STDERR_FILENO)
return; /* don't print dup messages */
}
full_write(log_fd, msg, l);
if (log_fd == STDERR_FILENO)
return; /* don't print dup messages */
}
#endif
@@ -327,8 +328,9 @@ static void console_init(void)
* if TERM is set to linux (the default) */
if (!s || strcmp(s, "linux") == 0)
putenv((char*)"TERM=vt102");
if (!ENABLE_FEATURE_INIT_SYSLOG)
log_console = NULL;
# if !ENABLE_FEATURE_INIT_SYSLOG
log_console = NULL;
# endif
} else
#endif
if (!s)
@@ -543,8 +545,8 @@ static pid_t run(const struct init_action *a)
}
/* Log the process name and args */
message(L_LOG, "starting pid %d, tty '%s': '%s'",
getpid(), a->terminal, a->command);
message(L_LOG, "starting pid %u, tty '%s': '%s'",
(int)getpid(), a->terminal, a->command);
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
@@ -759,7 +761,7 @@ static void run_shutdown_and_kill_processes(void)
/* Send signals to every process _except_ pid 1 */
kill(-1, SIGTERM);
message(L_CONSOLE | L_LOG, "Sent SIG%s to all processes", "TERM");
message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
sync();
sleep(1);
@@ -1098,7 +1100,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
if (argv[1])
xsetenv("RUNLEVEL", argv[1]);
#if !ENABLE_FEATURE_EXTRA_QUIET
#if !ENABLE_FEATURE_INIT_QUIET
/* Hello world */
message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
#endif
Loaded 100 of 370 files, more files were not shown because too many files have changed in this diff. Show more