Compare commits

...

261 Commits

Author SHA1 Message Date
Denys Vlasenko
868530ade2 Apply post-1.25.0 patches, bump version to 1.25.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-07 17:11:04 +02:00
Denys Vlasenko
c3b34d8b39 Bump version to 1.25.0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-22 00:58:56 +02:00
Denys Vlasenko
10c0e91786 libarchive: fix xmalloc_open_zipped_read_close()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-21 02:04:16 +02:00
Denys Vlasenko
7cf45ae10e setsid: fix broken -c
This did not work: setsid sh -c 'anything'

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 23:50:26 +02:00
Denys Vlasenko
e24e88697a typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 16:28:53 +02:00
Denys Vlasenko
ea9ebc011b scripts/trylink: libbusybox fix
gcc 6.1.1 can emit empty line with spaces

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 12:23:35 +02:00
Denys Vlasenko
df3ec0e2f7 libarchive: fix open_zipped()
Last commit broke it (on both MMU and NOMMU)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:42:00 +02:00
Denys Vlasenko
984b0a613a libarchive: fix xmalloc_open_zipped_read_close() on NOMMU
The somewhat new "unpack in memory" code was broken
for xmalloc_open_zipped_read_close() on NOMMU: we seek back
over signature, but then expect it to be already consumed.
Stop seeking back in this case.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:06:42 +02:00
Denys Vlasenko
ecf25cb5bc randomconfig fixes 5: false positive for tar; mount emits corrupted message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:04:04 +02:00
Denys Vlasenko
5c3e060604 modprobe-small: fix bogus handling of unpack errors
"modprobe minix; echo $?"

Was:
modprobe: corrupted data
modprobe: read error from 'kernel/fs/minix/minix.ko.xz': No such file or directory
modprobe: corrupted data
modprobe: read error from 'kernel/fs/minix/minix.ko.xz': No such file or directory
modprobe: corrupted data
modprobe: read error from 'kernel/fs/minix/minix.ko.xz'
modprobe: 'kernel/fs/minix/minix.ko.xz': Success
0

Now:
modprobe: corrupted data
modprobe: read error from 'kernel/fs/minix/minix.ko.xz'
1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 11:02:40 +02:00
Denys Vlasenko
0ad872baf3 randomconfig fixes 4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 01:40:19 +02:00
Denys Vlasenko
94046d0495 randomconfig fixes 3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-20 00:36:21 +02:00
Denys Vlasenko
bb0bf287d8 randomconfig fixes 2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-19 21:54:04 +02:00
Denys Vlasenko
015db5800c randomconfig fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-19 18:15:33 +02:00
Ron Yorston
ce824aecf2 libbb: move common code into run_applet_and_exit
Both calls to run_applet_and_exit are followed by the same code
to print an error message and return status 127.  Remove this
duplication and make run_applet_and_exit static.

function                                             old     new   delta
run_applet_and_exit                                  675     667      -8
main                                                 119      92     -27
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-35)             Total: -35 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-19 15:16:27 +02:00
Ron Yorston
ba12081a9e Allow "busybox <applet>" to work when busybox is disabled
A recent commit made it possible to disable BusyBox's --install
and --list options.  However it also stopped "busybox <applet>
<params>" from working.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-18 19:15:20 +02:00
Denys Vlasenko
e4caf1dd9c ntpd: retry initial DNS resolution (forever, no timeout for now).
Some users start ntpd on boot, and don't babysit it. If it dies because
DNS is not yet up and therefore NTP servers can't be found, users are
not happy.

Example behavior with a peer name which can't be resolved:

ntpd: bad address 'qwe.rty.ghj.kl'
...5 sec...
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
ntpd: bad address 'qwe.rty.ghj.kl'
...

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

function                                             old     new   delta
resolve_peer_hostname                                  -      81     +81
ntpd_main                                           1130    1061     -69
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 81/-69)             Total: 12 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-06-06 02:26:49 +02:00
Natanael Copa
b684d1b186 libbb: fix time parsing of [[CC]YY]MMDDhhmm[.SS]. Closes 8951
If SS is not given a value, it is assumed to be zero.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-31 02:50:54 +02:00
Denys Vlasenko
8e95068c7f Make busybox an optional applet
If it's disabled, code shrinks by about 900 bytes:

function                                             old     new   delta
usr_bin                                               10       -     -10
usr_sbin                                              11       -     -11
install_dir                                           20       -     -20
applet_install_loc                                   184       -    -184
run_applet_and_exit                                  686      21    -665
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 0/1 up/down: 0/-890)           Total: -890 bytes
   text    data     bss     dec     hex filename
 911327     493    7336  919156   e0674 busybox_old
 909848     493    7336  917677   e00ad busybox_unstripped

but busybox executable by itself does not say anything useful:

$ busybox
busybox: applet not found

Based on the patch by Ron Yorston <rmy@pobox.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-31 02:44:34 +02:00
Denys Vlasenko
877dedb825 cp: add -u/--update and --remove-destination
Based on the patch by wdlkmpx@gmail.com

function                                             old     new   delta
copy_file                                           1546    1644     +98
add_partition                                       1270    1362     +92
ask_and_unlink                                        95     133     +38
do_iproute                                           132     157     +25
decode_one_format                                    710     715      +5
cp_main                                              369     374      +5
ubirename_main                                       198     202      +4
read_package_field                                   232     230      -2
bb_make_directory                                    421     412      -9
packed_usage                                       30505   30476     -29
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/3 up/down: 267/-40)           Total: 227 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-27 00:46:38 +02:00
Denys Vlasenko
852e8dd734 arping: avoid use of ether_ntoa(). Closes 8926
This is the only non-debug use of ether_ntoa(). By not using it,
we reduce bss:

function                                             old     new   delta
arping_main                                         1568    1665     +97
static.asc                                            18       -     -18
ether_ntoa                                            57       -     -57
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/0 up/down: 97/-75)             Total: 22 bytes
   text    data     bss     dec     hex filename
 911020     493    7352  918865   e0551 busybox_old
 911069     493    7336  918898   e0572 busybox_unstripped

Also, "standard" arping zero-pads MAC. ether_ntoa() does not.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-26 21:35:46 +02:00
Denys Vlasenko
f2559e5c2b sed: fix append command to match GNU sed 4.2.1
This closes one testcase failure

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-05-06 18:25:56 +02:00
Denys Vlasenko
2fbc3123a2 flock: merge spawn_and_wait() code patchs for -c and sans-c uses
function                                             old     new   delta
flock_main                                           334     319     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 18:21:32 +02:00
Denys Vlasenko
e1d426fd65 flock: fix -c; improve error handling of fork+exec
function                                             old     new   delta
flock_main                                           254     334     +80

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 18:19:49 +02:00
Szabolcs Nagy
4ab372d49a ip: fix problem on mips64 n64 big endian musl systems
Use designated initializers for struct msghdr.
The struct layout is non-portable and musl libc does not match what busybox expects.

Signed-off-by: Szabolcs Nagy <nsz@port70.net>
Tested-by: Waldemar Brodkorb <wbx@openadk.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 17:39:02 +02:00
Denys Vlasenko
cbdff15bb7 sed: understand \n,\r and \t in i and a commands. Closes 8871
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 16:18:03 +02:00
Denys Vlasenko
4c8fa34417 generate_BUFSIZ.sh: yet another tweak
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-24 14:13:35 +02:00
Denys Vlasenko
3e134ebf6a *: slap on a few ALIGN1/2s where appropriate
The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map"

   text	   data	    bss	    dec	    hex	filename
 829901	   4086	   1904	 835891	  cc133	busybox_before
 829665	   4086	   1904	 835655	  cc047	busybox

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-22 18:09:21 +02:00
Denys Vlasenko
663d1da1e6 scripts/trylink: document DATA_SEGMENT_ALIGN() hack
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-22 02:00:04 +02:00
Denys Vlasenko
7ff24bd5fb generate_BUFSIZ.sh: catch BUFSIZE < 1024 also on "big" builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-22 00:24:53 +02:00
Denys Vlasenko
d7b502c059 build system: fix generate_BUFSIZ.sh to not alternate 1k and malloc builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 23:52:35 +02:00
Denys Vlasenko
93e1aaa1c7 libbb: constify *bb_common_bufsiz1 (if it is compiled to be a pointer)
This lets gcc optimize much better:

   text	   data	    bss	    dec	    hex	filename
 922846	    910	  13056	 936812	  e4b6c	busybox_unstripped.nonconst
 920255	    910	  13056	 934221	  e414d	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 21:47:45 +02:00
Denys Vlasenko
f56fb5eb11 libbb: make "COMMON_BUFSIZE = 1024 bytes, the buffer will be malloced" work
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 21:03:51 +02:00
Denys Vlasenko
df70a43af2 udhcp: add setup_common_bufsiz() as needed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 18:54:36 +02:00
Denys Vlasenko
9de2e5a222 *: hopefully all setup_common_bufsiz() are in place
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 18:38:51 +02:00
Denys Vlasenko
47cfbf32fd *: add most of the required setup_common_bufsiz() calls
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 18:18:48 +02:00
Denys Vlasenko
e6a2f4cc5a libbb: make bb_common_bufsiz1 1 kbyte, add capability to use bss tail for it
The config item is FEATURE_USE_BSS_TAIL. When it is off (default):

function                                             old     new   delta
read_config                                          210     228     +18
doCommands                                          2279    2294     +15
ipneigh_list_or_flush                                763     772      +9
ipaddr_list_or_flush                                1256    1261      +5
display_process_list                                1301    1306      +5
conspy_main                                         1378    1383      +5
do_lzo_compress                                      352     355      +3
do_lzo_decompress                                    565     567      +2
push                                                  46      44      -2
inetd_main                                          2136    2134      -2
uevent_main                                          421     418      -3
addLines                                              97      92      -5
bb_common_bufsiz1                                   8193    1024   -7169
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/5 up/down: 62/-7181)        Total: -7119 bytes
   text	   data	    bss	    dec	    hex	filename
 829850	   4086	   9080	 843016	  cdd08	busybox_old
 829901	   4086	   1904	 835891	  cc133	busybox_unstripped

FEATURE_USE_BSS_TAIL=y:

read_config                                          210     228     +18
doCommands                                          2279    2294     +15
ipneigh_list_or_flush                                763     772      +9
ipaddr_list_or_flush                                1256    1261      +5
display_process_list                                1301    1306      +5
conspy_main                                         1378    1383      +5
do_lzo_compress                                      352     355      +3
do_lzo_decompress                                    565     567      +2
inetd_main                                          2136    2134      -2
bb_common_bufsiz1                                   8193       -   -8193
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 8/1 up/down: 62/-8195)        Total: -8133 bytes
   text	   data	    bss	    dec	    hex	filename
 829850	   4086	   9080	 843016	  cdd08	busybox_old
 829911	   4086	    880	 834877	  cbd3d	busybox_unstripped

FIXME: setup_common_bufsiz() calls are missing.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-21 17:39:11 +02:00
Denys Vlasenko
5598bdf0d3 unzip: shorter code for date/time generation
function                                             old     new   delta
unzip_main                                          2426    2414     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-18 02:38:32 +02:00
Denys Vlasenko
07bd979921 unzip: better match for "standard" unzip's output; string shrinkage
function                                             old     new   delta
unzip_main                                          2490    2426     -64
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-64)             Total: -64 bytes
   text    data     bss     dec     hex filename
 924008     906   17160  942074   e5ffa busybox_old
 923846     906   17160  941912   e5f58 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-18 01:43:24 +02:00
Denys Vlasenko
bca4deee83 unzip: fix percent overflow; show "stored" files properly
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-18 01:14:05 +02:00
Denys Vlasenko
0ccf52a9fb unzip: fix a case where we find wrong CDE. Closes 8821
function                                             old     new   delta
unzip_main                                          2472    2490     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-17 21:05:34 +02:00
Ron Yorston
84ba50c32f ash: bash-compatible $'...' shouldn't expand in double quotes
Bash doesn't expand its $'...' construct in double quotes:

   $ echo "$'a\tb'"
   $'a\tb'

Change BusyBox ash to do the same.  This also fixes a problem with
here documents where BusyBox ash gave an incorrect result for:

   $ cat <<EOF
   > '$'
   > EOF
   '$'

Reported-by: Timo Teras <timo.teras@iki.fi>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-15 22:16:46 +02:00
Ron Yorston
2b91958dff Rewrite iteration through applet names to save a few bytes
function                                             old     new   delta
run_applet_and_exit                                  758     755      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3)               Total: -3 bytes

In standalone shell mode the saving increases to 17 bytes.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-15 22:13:51 +02:00
Denys Vlasenko
e4d925b889 sed: support "-f -" idiom
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-08 00:20:36 +02:00
Mike Frysinger
d7d4750e1e unrpm: clean up
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-04 01:39:17 -04:00
Mike Frysinger
ee22fe8793 undeb: clean up
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-04 01:35:34 -04:00
Mike Frysinger
ea1b44412a syslogd: minor tweaks to text
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-04 01:28:32 -04:00
Bjørn Forsman
d63d77a7f0 kconfig/lxdialog: get ncurses CFLAGS with pkg-config
This makes "make menuconfig" also work on systems where ncurses is not
installed in a standard location (such as on NixOS).

This patch changes ccflags() so that it tries pkg-config first, and only
if pkg-config fails does it go back to the fallback/manual checks. This
is the same algorithm that ldflags() already uses.

Signed-off-by: Bjørn Forsman <bjorn.forsman@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Michal Marek
935fe68236 kbuild: Make scripts executable
The Makefiles call the respective interpreter explicitly, but this makes
it easier to use the scripts manually.

Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Yann E. MORIN
d35ba8b5ed kconfig/lxdialog: rationalise the include paths where to find {.n}curses{,w}.h
The current code does this:

    if [ -f /usr/include/ncursesw/curses.h ]; then
        echo '-I/usr/include/ncursesw -DCURSES_LOC="<ncursesw/curses.h>"'
    elif [ -f /usr/include/ncurses/ncurses.h ]; then
        echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
    elif [ -f /usr/include/ncurses/curses.h ]; then
        echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"'
    [...]

This is merely inconsistent:
  - adding the full path to the directory in the -I directive,
  - especially since that path is already a sub-path of the system
    include path,
  - and then repeating the sub-path in the #include directive.

Rationalise each include directive:
  - only use the filename in the #include directive,
  - keep the -I directives: they are always searched for before the
    system include path; this ensures the correct header is used.

Using the -I directives and the filename-only in #include is more in
line with how pkg-config behaves, eg.:
    $ pkg-config --cflags ncursesw
    -I/usr/include/ncursesw

This paves the way for using pkg-config for CFLAGS, too, now we use it
to find the libraries.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Justin Lecher
e62c715b3e menuconfig: optionally use pkg-config to detect ncurses libs
When building ncurses with --with-termlib several symbols get moved from
libncurses.so to libtinfo.so. Thus when linking with libncurses.so, one
additionally needs to link with libtinfo.so.

The ncurses pkg-config module will be used to detect the necessary libs for
linking. If not available the old heuristic for detection of the ncurses libs
will be used.

Signed-off-by: Justin Lecher <jlec@gentoo.org>
Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Krzysztof Mazur
f755430d79 menuconfig: fix extended colors ncurses support
The ncurses library allows for extended colors. The support for extended
colors support depends on wide-character support. ncurses headers
enable extended colors (NCURSES_EXT_COLORS) only when wide-character
support is enabled (NCURSES_WIDECHAR).

The "make menuconfig" uses wide-character ncursesw library, which can be
compiled with wide-character support, but does not define NCURSES_WIDECHAR
and it's using headers without wide-character (and extended colors) support.

This fixes problems with colors on systems with enabled extended colors
(like PLD Linux). Without this patch "make menuconfig" is hard to use.

Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Jean Delvare
8c3f943410 kbuild: Fix gcc -x syntax
The correct syntax for gcc -x is "gcc -x assembler", not
"gcc -xassembler". Even though the latter happens to work, the former
is what is documented in the manual page and thus what gcc wrappers
such as icecream do expect.

This isn't a cosmetic change. The missing space prevents icecream from
recognizing compilation tasks it can't handle, leading to silent kernel
miscompilations.

Besides me, credits go to Michael Matz and Dirk Mueller for
investigating the miscompilation issue and tracking it down to this
incorrect -x parameter syntax.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Cc: Bernhard Walle <bernhard@bwalle.de>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Yaakov Selkowitz
74f58ed48c kconfig: fix check-lxdialog for DLL platforms
Import libraries on Cygwin and MinGW/MSYS use the .dll.a suffix, so
checking this suffix is necessary to make sure ncurses will still be
found when built without static libraries.

Signed-off-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Yaakov Selkowitz
a0f24a06df kconfig: check ncursesw headers first in check-lxdialog
Commit 8c41e5e363db55d91aa3b1cdce4ab02ad9821de7 added a check for
ncursesw/curses.h for the case where ncurses and ncursesw are build
separately but only one is installed.  But if both are installed,
the headers ncurses/curses.h and ncursesw/curses.h differ, and since
libncursesw will be found first, so should ncursesw/curses.h.

Signed-off-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Junio C Hamano
f48bd92285 kconfig: fix menuconfig on debian lenny
In 60f33b8 (kconfig: get rid of stray a.o, support ncursesw, 2006-01-15),
support to link menuconfig with ncursesw library was added.  To compute
the linker command option -l, we check "libncursesw.{so,a,dylib}" to allow
ncursesw to be used as a replacement ncurses.  However, when checking what
header file to include, we do not check /usr/include/ncursesw directory.

Add /usr/include/ncursesw to the list of directories that are checked.
With this patch, on my Debian Lenny box with libncursesw5-dev package but
not libncurses5-dev package, I can say "make menuconfig".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:59:15 -04:00
Mike Frysinger
993dab7822 Revert "lxdialog: fix ncursesw include detection"
This reverts commit e91bc53d0c.

Let's get back to a state that matches upstream so we can pull in all of
their fixes from the last few years.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-04-03 23:58:50 -04:00
Ron Yorston
b22061718d find_applet_by_name: loop index should be signed
The loop

   for (j = ARRAY_SIZE(applet_nameofs)-1; j >= 0; j--) {

was intended to terminate when j goes negative, so j needs to be signed.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 22:29:35 +02:00
Denys Vlasenko
6aab9928de whitespace and namespace cleanups
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 22:24:51 +02:00
Sven Eisenberg
b068cf2a7e ubirmvol: Implement -N switch for ubirmvol
function                                             old     new   delta
get_volid_by_name                                      -     125    +125
ubi_devnum_from_devname                                -      43     +43
ubi_tools_main                                      1215    1220      +5
packed_usage                                       30674   30655     -19
ubirename_main                                       394     221    -173
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 1/2 up/down: 173/-192)          Total: -19 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 22:01:43 +02:00
Sven Eisenberg
cb92640998 ubirename: new applet
function                                             old     new   delta
ubirename_main                                         -     394    +394
packed_usage                                       30611   30674     +63
applet_names                                        2530    2540     +10

Signed-off-by: Sven Eisenberg <sven.eisenberg@novero.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 20:12:03 +02:00
Denys Vlasenko
46b494635e libbb: speed up error_msg functions
function                                             old     new   delta
bb_verror_msg                                        386     466     +80

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 16:55:03 +02:00
Denys Vlasenko
bc14f4d13d main(): add a TODO about finding a use for _end[] area
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 16:06:42 +02:00
Denys Vlasenko
056e1f558c trylink: on failure, print a hint about CONFIG_EXTRA_LDLIBS
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-03 15:38:53 +02:00
Denys Vlasenko
1cf68e3033 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 22:57:17 +02:00
Denys Vlasenko
a93e4fd376 find_applet_by_name: add an example of faster linear search code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 22:54:23 +02:00
Denys Vlasenko
8b0f459af7 nsenter,unshare: work around older header
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 19:00:44 +02:00
Denys Vlasenko
b14374a5ba sort: "-o FILE", not "-o", is the syntax
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 18:20:26 +02:00
Denys Vlasenko
8220399173 nsenter,unshare: share common code; fix a bug of not closing all fds
function                                             old     new   delta
xvfork_parent_waits_and_exits                          -      64     +64
exec_prog_or_SHELL                                     -      39     +39
unshare_main                                         873     810     -63
nsenter_main                                         663     596     -67
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 106/-130)          Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 18:06:24 +02:00
Denys Vlasenko
c87e81f944 sort: help text does not need to say that -mST are supported but ignored
Such information is useless for users of "sort --help"

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 17:39:50 +02:00
Denys Vlasenko
dd02a05e08 build system: finer-grained selection of search speedup table.
KNOWN_APPNAME_OFFSETS=8 versus KNOWN_APPNAME_OFFSETS=0:

function                                             old     new   delta
find_applet_by_name                                   55     136     +81
applet_nameofs                                         -      14     +14
run_applet_and_exit                                  757     758      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 15:18:26 +02:00
Denys Vlasenko
9f2f96edfa unshare: remove stale comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-02 04:44:39 +02:00
Bartosz Golaszewski
80c934a251 nsenter: new applet
function                                             old     new   delta
nsenter_main                                           -     663    +663
.rodata                                           155147  155612    +465
packed_usage                                       30536   30708    +172
nsenter_longopts                                       -     116    +116
open_by_path_or_target                                 -      58     +58
applet_names                                        2518    2526      +8
applet_main                                         2920    2928      +8
------------------------------------------------------------------------------
(add/remove: 4/0 grow/shrink: 4/0 up/down: 1490/0)           Total: 1490 bytes
   text	   data	    bss	    dec	    hex	filename
 827956	   4078	   9080	 841114	  cd59a	busybox_old
 829214	   4086	   9080	 842380	  cda8c	busybox_unstripped

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-01 22:19:35 +02:00
Denys Vlasenko
c4199f22d0 libbb: two new functions: wait_for_exitstatus(pid), xfchdir(fd)
Bartosz Golaszewski proposed xfchdir()

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-01 22:12:44 +02:00
Bartosz Golaszewski
29b33b63d4 unshare: new applet
function                                             old     new   delta
unshare_main                                           -     873    +873
.rodata                                           154444  155131    +687
packed_usage                                       30329   30520    +191
unshare_longopts                                       -     106    +106
mount_namespaces                                       -      99     +99
mount_or_die                                           -      51     +51
ns_list                                                -      48     +48
wait_for_exitstatus                                    -      41     +41
opt_str                                                -      17     +17
applet_names                                        2510    2518      +8
applet_main                                         2912    2920      +8
applet_suid                                           91      92      +1
applet_install_loc                                   182     183      +1
------------------------------------------------------------------------------
(add/remove: 8/0 grow/shrink: 6/0 up/down: 2131/0)           Total: 2131 bytes
   text	   data	    bss	    dec	    hex	filename
 826110	   4070	   9080	 839260	  cce5c	busybox_old
 827961	   4078	   9080	 841119	  cd59f	busybox_unstripped

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-01 19:44:39 +02:00
Denys Vlasenko
52977a7d60 Rename FEATURE_INITRD to LINUXRC and make it separate, not an alias to init
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-31 00:42:57 +02:00
Denys Vlasenko
a27dc33f97 make MKPASSWD a separate config option, not an automatic alias to cryptpw
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-31 00:32:39 +02:00
Denys Vlasenko
f75a96d74c udhcp: fix capitalization of two messages
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:49:45 +02:00
Denys Vlasenko
16efe19128 dhcpd: string reuse
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:44:52 +02:00
Denys Vlasenko
8f2e99c813 udhcp: get rid of bb_info_msg()
function                                             old     new   delta
udhcpd_main                                         1501    1531     +30
d6_recv_raw_packet                                   251     264     +13
perform_d6_release                                   188     198     +10
udhcpc6_main                                        2443    2449      +6
udhcp_recv_raw_packet                                582     588      +6
udhcp_recv_kernel_packet                             132     138      +6
send_d6_renew                                        140     146      +6
d6_recv_kernel_packet                                118     124      +6
send_renew                                            77      82      +5
send_discover                                         85      90      +5
send_decline                                          84      89      +5
send_d6_select                                        97     102      +5
send_d6_discover                                     174     179      +5
perform_release                                      167     172      +5
count_lines                                           72      74      +2
udhcpc_main                                         2836    2837      +1
bb_info_msg                                          125       -    -125
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 17/4 up/down: 117/-180)         Total: -63 bytes
   text	   data	    bss	    dec	    hex	filename
 924935	    906	  17160	 943001	  e6399	busybox_old
 924736	    906	  17160	 942802	  e62d2	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:41:23 +02:00
Denys Vlasenko
80f0f1d712 setfiles: switch bb_info_msg to printf
Presumably, bb_info_msg was used here for syslog logging (-l),
but there is no actual code to activate syslog logging.
Added a TODO note on that, so that selinux users would notice
and fix if needed.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 18:17:35 +02:00
Denys Vlasenko
2a17fbe88a sulogin: use bb_error_msg instead of bb_info_msg; better message
Historic "System Maintenance Mode" message is a tiny bit cryptic.
Let's say explicitly what we are doing: we are giving user a shell
(presumably to do some maintenance in single-user mode).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 17:36:20 +02:00
Denys Vlasenko
32c08acba3 sulogin: remove suid paranoia code, explain why it's not necessary
function                                             old     new   delta
sulogin_main                                         325     270     -55

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 17:27:32 +02:00
Denys Vlasenko
8ac6effb02 sulogin: Dorp incorrect comment about suid-ness
Sulogin is not a suid app, should fail if run by non-root.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:50:19 +02:00
Denys Vlasenko
c418f48d8d fsck: use printf for message, not bb_info_msg
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:30:24 +02:00
Denys Vlasenko
3b757f0798 mkfs_vfat: use bb_error_msg for logging, not bb_info_msg
This affects only a commented-out code section which searches for bad blocks

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:23:10 +02:00
Denys Vlasenko
cde1199e01 zcip: use bb_error_msg for logging, not bb_info_msg
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:22:13 +02:00
Denys Vlasenko
066e76befe Replace a few more bb_info_msg's by bb_error_msg or printf
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:20:28 +02:00
Denys Vlasenko
76b680c7a8 Use bb_error_msg instead of bb_info_msg in all commented-out debug printouts
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 16:04:37 +02:00
Ron Yorston
610c4c385b applet_tables: save space by removing applet name offsets
The array applet_nameofs consumes two bytes per applet.  It encodes

   nofork/noexec flags
   suid flags
   the offset of the applet name in the applet_name string

Change the applet_table build tool to store the flags in two separate
arrays (applet_flags and applet_suid).  Replace applet_nameofs[] with a
smaller version that only stores a limited number of offsets.

This requires changes to the macros APPLET_IS_NOFORK, APPLET_IS_NOEXEC
and APPLET_SUID.

   According to Valgrind the original find_applet_by_name required
   353 cycles per call, averaged over all names.  Adjusting the number
   of known offsets allows space to be traded off against execution time:

      KNOWN_OFFSETS     cycles     bytes (wrt KNOWN_OFFSETS = 0)

           0             9057        -
           2             4604       32
           4             2407       75
           8             1342       98
          16              908      130
          32              884      194

   This patch uses KNOWN_OFFSETS = 8.

v2:
   Remove some dead code from the applet_table tool;
   Treat the applet in the middle of the table as a special case.

v3:
   Use the middle applet to adjust the start of the linear search as
   well as the last applet found.

v4:
   Use an augmented linear search in find_applet_by_name.
   Drop the special treatment of the middle name from get_applet_name:
   most of the advantage now derives from the last stored value.

v5:
   Don't store index in applet_nameofs, it can be calculated.

v6:
   Tweaks by Denys

function                                             old     new   delta
find_applet_by_name                                   25     125    +100
applet_suid                                            -      92     +92
run_applet_no_and_exit                               452     460      +8
run_applet_and_exit                                  695     697      +2
applet_name_compare                                   31       -     -31
applet_nameofs                                       734      14    -720
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 3/1 up/down: 202/-751)         Total: -549 bytes
   text       data        bss        dec        hex    filename
 925464        906      17160     943530      e65aa    busybox_old
 924915        906      17160     942981      e6385    busybox_unstripped

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-30 00:44:11 +02:00
Denys Vlasenko
9844d7e830 Revert "networking: properly initialize ipv6 scope id for printing it"
This reverts commit 2fb63292f7.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-29 19:27:00 +02:00
Denys Vlasenko
20dd499341 modprobe: skip non-.conf files only in subdirectories
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-29 19:23:55 +02:00
Denys Vlasenko
31c984dd69 umount: build fix for older glibc
Based on a patch by Veli-Pekka Peltola <veli-pekka.peltola@ray.fi>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-28 22:23:33 +02:00
Timo Teräs
2fb63292f7 networking: properly initialize ipv6 scope id for printing it
Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-28 22:16:48 +02:00
Denys Vlasenko
73dfdda92e grep: make errors other than "not found" result in exit code 2. Closes 8796
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-28 22:12:09 +02:00
Mike Frysinger
b9b7aa1910 ash_test: ignore generated files
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-22 18:15:24 -04:00
Mike Frysinger
787972f60b ash_test: printenv: fix missing includes
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-22 18:15:14 -04:00
Ron Yorston
3e3bfb896e ash: fix corruption of ${#var} if $var contains UTF-8 characters
As reported in bug 8506:

   $ X=abcdÉfghÍjklmnÓpqrstÚvwcyz
   $ echo ${#X}
   abcd26

The result should be 26.

This regression was introduced by:

   <d68d1fb> 2015-05-18 [Ron Yorston]  ash: code shrink around varvalue

The length in characters was being used to discard the contents of
the variable instead of the length in bytes.

URL: https://bugs.busybox.net/8506
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-03-22 18:19:29 -04:00
Denys Vlasenko
6701e91d84 wget: make -T timeout work on header reads too. Closes 8636
function                                             old     new   delta
set_alarm                                              -      27     +27
fgets_and_trim                                        76      92     +16
wget_main                                           2610    2616      +6
open_socket                                           64      54     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-17 21:52:42 +01:00
Denys Vlasenko
0d1b71e8e6 nmeter: reinstate and document -d-1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 17:54:17 +01:00
Denys Vlasenko
41b1e2c392 nmeter: remove undocumented %NNNd specifier
function                                             old     new   delta
nmeter_main                                          707     745     +38
init_functions                                        48      44      -4
init_delay                                            63       -     -63
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 38/-67)            Total: -29 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 16:13:23 +01:00
Denys Vlasenko
a63e2a8cb2 nmeter: simple code shrink here and there
function                                             old     new   delta
nmeter_main                                          709     707      -2
init_cr                                               15      12      -3
collect_time                                         141     131     -10
collect_cpu                                          610     593     -17
init_cpu                                              82      63     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-51)             Total: -51 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 16:06:29 +01:00
Denys Vlasenko
8a26fda98c nmeter: convert field list to bit list
function                                             old     new   delta
rdval                                                 34     157    +123
collect_int                                          123     122      -1
collect_thread_nr                                     65      62      -3
collect_blk                                          559     552      -7
collect_if                                           207     199      -8
collect_fork                                         119     111      -8
collect_ctx                                          119     111      -8
collect_fd                                            81      71     -10
collect_swp                                          120     107     -13
collect_cpu                                          623     610     -13
collect_mem                                          371     339     -32
rdval_loadavg                                         38       -     -38
vrdval                                               170       -    -170
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/10 up/down: 123/-311)        Total: -188 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 15:52:40 +01:00
Denys Vlasenko
99c71c9e80 nmeter: code shrink
function                                             old     new   delta
put                                                   52      43      -9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 15:28:49 +01:00
Denys Vlasenko
e4de8c6316 nmeter: fix a bug with unterminated varargs
function                                             old     new   delta
collect_mem                                          361     371     +10
collect_swp                                          116     120      +4
vrdval                                               168     170      +2
collect_thread_nr                                     63      65      +2
collect_int                                          121     123      +2
collect_if                                           205     207      +2
collect_fork                                         117     119      +2
collect_fd                                            79      81      +2
collect_ctx                                          117     119      +2
collect_cpu                                          621     623      +2
collect_blk                                          557     559      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 11/0 up/down: 32/0)              Total: 32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-15 15:22:42 +01:00
Denys Vlasenko
fd5a2b7b04 New example config: android_502_defconfig
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-14 22:28:53 +01:00
Denys Vlasenko
23961b2fd3 more bionic fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-14 19:34:15 +01:00
Denys Vlasenko
dbb58a3879 fixes for problems found by bionic build
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-14 18:23:33 +01:00
Denys Vlasenko
1b7c17391d udhcpc: fix a warning in debug code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-11 00:26:58 +01:00
Denys Vlasenko
d474ffc682 udhcp: fix a SEGV on malformed RFC1035-encoded domain name
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-10 11:47:58 +01:00
Denys Vlasenko
d2b820b540 renice: tweak help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-07 15:21:54 +01:00
Denys Vlasenko
ea351b9742 ls: fix columnar output. Closes 8731
In coreutils/ls.c, 1.19 introduced commit
2f7d9e8903, removing the variable tabstops and
hard coding the column separation to 2 characters, but was not done correctly.
The column_width assumes a gap of 1 character, so the computed number of
columns exceeds the terminal width when many small files are encountered.

A minor problem but surprisingly annoying.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-06 17:53:11 +01:00
Denys Vlasenko
7849ccb61c inotifyd: swap meaning of 'y' and 'm' events in help text. Closes 8726
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-06 17:35:16 +01:00
Denys Vlasenko
86d9f60f3a udhcpc: do not use -t NUM for counting "select" packets, use 3
Otherwise, "-t 0" usage may end up sending them forever
if server does not respond.

function                                             old     new   delta
udhcpc_main                                         2846    2836     -10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-04 17:00:56 +01:00
Denys Vlasenko
aee7cd82be ntpd: add experimental patch
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-04 07:36:04 +01:00
Denys Vlasenko
c8641962e4 ntpd: if peer does not reply anymore, try re-resolving its hostname
function                                             old     new   delta
ntpd_main                                           1053    1130     +77
add_peers                                            166     195     +29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-04 07:26:08 +01:00
Denys Vlasenko
f37f28199f ntpd: do not use a peer more than once (say, if two peers resolve to the same IP)
function                                             old     new   delta
add_peers                                             98     166     +68

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-04 07:06:53 +01:00
Denys Vlasenko
4c48a64747 ntpd: more informative poll lowering message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-03 22:02:30 +01:00
Denys Vlasenko
35e063e1b9 ifupdowm: fix "warning: unused variable 'iface_list'"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-03 02:19:16 +01:00
Hans Dedecker
abe8f7515a dhcpc: Use client IP address as source address for DHCP renew/rebind messages
RFC2131 paragraph 4.1 states DHCP messages broadcast by a client prior to
that client obtaining its IP address must have the source IP address
field in the header set to 0.
Request messages transmitted in renewing and rebinding state need to use
the obtained IP address as source IP address in the header; this behavior
lines up with other implementations like ISC dhcp client.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-03 02:05:53 +01:00
Christian Lindeberg
ea2b71be66 udhcpd: keep expired leases at startup
Let udhcpd retain the information about expired leases when restarting
so that the leases are reserved until they possibly become the oldest
expired lease.

This reduces the frequency of IP address changes for example when the
DHCP server and a group of clients, who do not store and request their
previously offered IP address across restarts, are collectively restarted
and the startup order of the clients are not guaranteed.

Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-01 19:23:22 +01:00
Nicolas Cavallari
e5aba88712 ifupdown: allow duplicate interface definitions
This patch allow to have multiple interface definitions, much like
Debian's ifupdown.  More specifically, it removes the check for a
duplicate definition, so the impact on binary size should be fairly
minimal.

This configuration:

iface eth0 inet static
        address 192.168.0.15
        netmask 255.255.0.0
        gateway 192.168.0.1

iface eth0 inet static
        address 10.0.0.1
        netmask 255.255.255.0

Will add two addresses to eth0 if ip is used.  If ifconfig is used,
the standards methods will likely not stack, but the administrator may
still use the manual method.  The DHCP method may work depending on the
DHCP client in use.

This is a fairly advanced feature for power users who knows what they
are doing.  There are not many other network configuration systems that
allows multiple addresses on an interface.

Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-03-01 18:59:08 +01:00
Denys Vlasenko
352f79acbd udhcpc: fix OPTION_6RD parsing (could overflow its malloced buffer)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-26 15:54:56 +01:00
Denys Vlasenko
5bec08cebd udhcp: trivial shrink
function                                             old     new   delta
dname_dec                                            337     332      -5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-26 14:56:18 +01:00
Arnout Vandecappelle (Essensium/Mind)
5fa9fefddc taskset: fix non-fancy cpuset printing on big-endian
The non-fancy version of the from_cpuset uses CPU_SETSIZE as if it
represents the number of bytes in the cpuset, while it is actually
the number of bits. This leads to out-of-bounds accesses on the
cpu_set_t in the big-endian case. Basically all uses of CPU_SETSIZE
have to be divided by 8. This is done correctly in the fancy version
of from_cpuset.

In addition, the big-endian case is completely wrong to begin with.
All standard C libraries that I know of implement cpu_set_t as an
unsigned long array, so both for big and little endian, the least
significant bits are in the beginning of the array. Therefore, the
approach taken for the little endian case is equally valid. We only
need special handling for big endian when CPU_SETSIZE is large and
we use an unsigned long long to get more bits out.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-26 14:36:24 +01:00
Denys Vlasenko
03718bb274 ntpd: print packet delay in clock update message
function                                             old     new   delta
update_local_clock                                   820     826      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-24 01:22:45 +01:00
Mike Frysinger
3a5cc98902 modprobe: only parse files that end in .conf
This matches behavior with kmod which has been the standard for a long
time at this point.

URL: https://bugs.busybox.net/8021
Reported-by: Jö <jorrit@jorrit.de>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-02-12 23:26:51 -05:00
Mike Frysinger
43e56639c6 build: add a sanitizer debug option
Building & running with ASAN is super helpful, so add a dedicated config
knob for it.  This way people don't have to guess at the right compiler
settings in order to get a good build.  We can just tell people to enable
this one option.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-02-12 22:12:47 -05:00
Denys Vlasenko
8efcc9589b networking: allow dot at the end of the domain name in dhcp response
Patch based on Balaji Punnuru <balaji.punnuru@gmail.com> work.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-11 17:44:44 +01:00
Nicolas Carrier
29eae728e9 init: make the command-line rewrite optional
When launched as PID 1 and after parsing its arguments, init wipes all
all of them except argv[0] and rewrites argv[0] to contain only "init",
so that its command-line appears solely as "init" in tools such as ps.

This patch adds the FEATURE_INIT_MODIFY_CMDLINE which, if set to n, will
make init preserve all its arguments including argv[0], be they parsed or
ignored.
The original command-line used to launch init can then be retrieved in
/proc/1/cmdline on Linux, for example.

Signed-off-by: Nicolas Carrier <nicolas.carrier@parrot.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-11 14:23:33 +01:00
Denys Vlasenko
383201e725 ntpd: shorter message
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-10 07:06:31 +01:00
Denys Vlasenko
fc47fcefb6 ntpd: step when |offset| > 1 sec, not 0.125 sec
update_local_clock                                   769     820     +51
recv_and_process_peer_pkt                            838     862     +24
reset_peer_stats                                     137     133      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 75/-4)              Total: 71 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-10 06:55:07 +01:00
Felix Fietkau
f2c043acfc busybox: fix uninitialized memory when displaying IPv6 addresses
After commit 8e74adab01
("libbb: make INET[6]_rresolve use sockaddr2{host,dotted}_noport")
INET_sprint6 uses more than just sin6_addr, it also tries to display the
scope id, which is uninitialized when called from ife_print6.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-01 02:20:25 +01:00
Rafał Miłecki
c30a5b1373 dd: support iflag=skip_bytes
It allows specifying amount of bytes directly (not only amount of
blocks) is also supported by GNU's Coreutils.

function                                             old     new   delta
parse_comma_flags                                      -      93     +93
static.iflag_words                                     -      12     +12
dd_main                                             1569    1580     +11
packed_usage                                       30591   30600      +9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/0 up/down: 125/0)             Total: 125 bytes

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-01 02:17:28 +01:00
Kylie McClain
40eea690c7 Fix compiling with musl's utmp stubs
This patch fixes compiling busybox with FEATURE_UTMP and _WTMP enabled.
musl, while not really support utmp/wtmp, provides stub functions, as well
as variables such as _PATH_UTMP, so that programs using utmp or wtmp can
still compile fine.

My reasoning for this patch is that on Exherbo, I'm currently trying to get
us to be able to use the same busybox config file for both glibc and musl
systems, using utmp/wtmp on systems that support it, and using the stubs
on musl without needing two different configs.

As of latest musl git, it provides all utmp functions needed; 1.1.12 doesn't,
but I sent a patch to Rich to add the utmp{,x}name functions expected to
exist, which was merged into musl upstream.

Signed-off-by: Kylie McClain <somasissounds@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-02-01 01:36:05 +01:00
Ron Yorston
4a79224cfc printf: short-circuit output when argument to %b includes \c
printf wasn't correctly handling \c in an argument to the %b format
specifier.

   printf %bXX OK\\c

returned 'OK\cXX' rather than the expected 'OK'.

function                                             old     new   delta
printf_main                                          886     899     +13

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-31 22:23:05 +01:00
Denys Vlasenko
2a4bba3ce2 sed: make 's///w FILE' actually write to FILE. Closes 8251
function                                             old     new   delta
add_cmd                                             1167    1210     +43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-24 15:52:16 +01:00
Denys Vlasenko
eb5091070f patch: correctly handle "patch FILE_TO_PATCH" form. Closes 7736
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-23 05:13:15 +01:00
Denys Vlasenko
c7e47cf627 dos2unix: try to preserve ownership. closes 8311
function                                             old     new   delta
dos2unix_main                                        426     441     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-17 03:50:36 +01:00
Denys Vlasenko
ccf7f0e4d3 setsid: implement -c
function                                             old     new   delta
setsid_main                                           53      96     +43
packed_usage                                       30846   30833     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-17 01:10:53 +01:00
Mike Frysinger
6a70db85cf truncate: use O_WRONLY|O_NONBLOCK
This matches coreutils behavior.  We don't read the fd, and truncation
does not need blocking.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-01-13 13:30:20 -05:00
Ari Sundholm
e111a16404 truncate: always set mode when opening file to avoid fortify errors
Busybox crashes due to no mode being given when opening:
$ ./busybox truncate -s 1M foo
*** invalid open64 call: O_CREAT without mode ***: ./busybox terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7338f)[0x7f66d921338f]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f66d92aac9c]
/lib/x86_64-linux-gnu/libc.so.6(+0xeb6aa)[0x7f66d928b6aa]
./busybox[0x4899f9]
======= Memory map: ========
00400000-004d0000 r-xp 00000000 00:1a 137559                             /home/ari/busybox/busybox
006cf000-006d0000 r--p 000cf000 00:1a 137559                             /home/ari/busybox/busybox
006d0000-006d1000 rw-p 000d0000 00:1a 137559                             /home/ari/busybox/busybox
006d1000-006d4000 rw-p 00000000 00:00 0
014e7000-01508000 rw-p 00000000 00:00 0                                  [heap]
7f66d8f8a000-7f66d8fa0000 r-xp 00000000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d8fa0000-7f66d919f000 ---p 00016000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d919f000-7f66d91a0000 rw-p 00015000 08:07 1579008                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f66d91a0000-7f66d935b000 r-xp 00000000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d935b000-7f66d955a000 ---p 001bb000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955a000-7f66d955e000 r--p 001ba000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d955e000-7f66d9560000 rw-p 001be000 08:07 1578994                    /lib/x86_64-linux-gnu/libc-2.19.so
7f66d9560000-7f66d9565000 rw-p 00000000 00:00 0
7f66d9565000-7f66d966a000 r-xp 00000000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d966a000-7f66d9869000 ---p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d9869000-7f66d986a000 r--p 00104000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986a000-7f66d986b000 rw-p 00105000 08:07 1579020                    /lib/x86_64-linux-gnu/libm-2.19.so
7f66d986b000-7f66d988e000 r-xp 00000000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a64000-7f66d9a67000 rw-p 00000000 00:00 0
7f66d9a8a000-7f66d9a8d000 rw-p 00000000 00:00 0
7f66d9a8d000-7f66d9a8e000 r--p 00022000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8e000-7f66d9a8f000 rw-p 00023000 08:07 1578981                    /lib/x86_64-linux-gnu/ld-2.19.so
7f66d9a8f000-7f66d9a90000 rw-p 00000000 00:00 0
7ffc47761000-7ffc47782000 rw-p 00000000 00:00 0                          [stack]
7ffc477ab000-7ffc477ad000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)
$

Fix this by simply always setting the mode, as it doesn't hurt even
when O_CREAT is not specified.

This bug is a regression introduced in fc3e40e, as xopen(), which
was originally used, would automatically set the mode.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2016-01-13 13:28:01 -05:00
Denys Vlasenko
bae8f98633 login: add commented-out PAM double password avoidance from BZ 4003
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-03 22:43:40 +01:00
Aaro Koskinen
76915bf738 nandwrite: implement -n (read/write without ecc)
Implement -n (read/write without ecc).

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-02 01:33:01 +01:00
Ari Sundholm
dbf5a6da6a blkdiscard: new applet
function                                             old     new   delta
blkdiscard_main                                        -     264    +264

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-02 01:18:32 +01:00
Cristian Ionescu-Idbohrn
c2a2625bcb ash: suppress a compilation warning
Reported by gcc (Debian 5.3.1-4) 5.3.1 20151219

shell/ash.c: In function 'evaltree':
shell/ash.c:8432:19: warning: logical not is only applied to the left hand side of comparison

Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-01-02 00:52:29 +01:00
Denys Vlasenko
911d265faf mount: support "nofail" option. Closes 8551
function                                             old     new   delta
singlemount                                         1045    1060     +15
mount_option_str                                     338     345      +7
mount_it_now                                         355     361      +6
mount_options                                        172     176      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 32/0)               Total: 32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-30 20:11:34 +01:00
Denys Vlasenko
ce4bc1ed04 iproute: support "scope". Closes 8561
function                                             old     new   delta
iproute_modify                                      1051    1120     +69

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-30 17:32:51 +01:00
Denys Vlasenko
6c634f7968 swaponoff: fix compile-time warning
CC      util-linux/swaponoff.o
cc1: warnings being treated as errors
util-linux/swaponoff.c: In function 'swap_enable_disable':
util-linux/swaponoff.c💯 warning: passing argument 1 of 'resolve_mount_spec' from incompatible pointer type
make[1]: *** [util-linux/swaponoff.o] Error 1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-18 19:02:31 +01:00
Pascal Bach
2c0d3f5fd0 chpasswd: support -c argument and respect DEFAULT_PASSWD_ALGO
Signed-off-by: Pascal Bach <pascal.bach@siemens.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-18 19:01:14 +01:00
Ari Sundholm
b505251242 include/platform.h: Remove extra #endif introduced in 6df9612.
It causes the compilation to fail.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-17 15:54:04 -05:00
Chris Renshaw
6df961257d Resolve linker issues with Android API 21 (dprintf, tcdrain)
Signed-off-by: Chris Renshaw <osm0sis@outlook.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-12-17 16:42:41 +01:00
Mike Frysinger
e0942acb9e blkid: add bcache support
URL: https://bugs.gentoo.org/508596
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-16 14:42:25 -05:00
Mike Frysinger
5f11ec3f6a swapon/swapoff: refine the -e (ifexists) option
The -e option should only apply to swapon, and it should swallow all
errors/warnings when the device does not exist.  So delete the flag
from the swapoff patch and unify the check in the swapoff path.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-16 12:59:08 -05:00
Mike Frysinger
77e2bde6a5 trylink: include LDFLAGS when checking linkage
The user might be including options in their LDFLAGS (like -fuse-ld=gold)
that change the behavior of the linker and thus change the results of the
flag tests.  Make sure we include the user's LDFLAGS when running these
tests so we filter out flags that will fail when used later on.

URL: https://bugs.gentoo.org/499712
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2015-12-01 11:25:10 -05:00
Denys Vlasenko
196e400441 modutils: fix build error with !DEPMOD
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-06 15:50:28 +01:00
Timo Teräs
48dc80bbba modutils: merge module_entry and module_info to common
This merges the in-memory module info structures of modprobe
and depmod. This allows sharing hashing by modulename code
improving depmod runtime with almost factor of 2x.

function                                             old     new   delta
get_or_add_modentry                                    -      17     +17
do_modprobe                                          590     601     +11
moddb_get_or_create                                    -      10     +10
load_modules_dep                                     195     205     +10
moddb_get                                              -       7      +7
add_probe                                             81      78      -3
modprobe_main                                        721     714      -7
depmod_main                                          553     543     -10
config_file_action                                   434     421     -13
helper_get_module                                    160     144     -16
parse_module                                         343     320     -23
order_dep_list                                       105      82     -23
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/7 up/down: 55/-95)            Total: -40 bytes

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-05 18:54:55 +01:00
Denys Vlasenko
34adecc2b0 TODO file: remove mpstat, iostat, powertop - we have them now
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 19:39:54 +01:00
Ron Yorston
95ebcf79ff ash: add support for bash 'function' keyword
Where the POSIX shell allows functions to be defined as:

   name () compound-command [ redirections ]

bash adds the alternative syntax:

   function name [()] compound-command [ redirections ]

Implement this in ash's bash compatibility mode.  Most compound
commands work (for/while/until/if/case/[[]]/{}); one exception is:

   function f (echo "no way!")

The other two variants work:

   f() (echo "ok")
   function f() (echo "also ok")

function                                             old     new   delta
parse_command                                       1555    1744    +189
tokname_array                                        232     240      +8
.rodata                                           155612  155566     -46
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 197/-46)           Total: 151 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 19:30:24 +01:00
Denys Vlasenko
bc9bee01f3 hush-misc/func_args1.tests: remove "UNFIXED BUG", it does not fail
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 14:50:19 +01:00
Ron Yorston
85405c80a2 ash: copy function tests from hush testsuite
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 14:48:16 +01:00
Denys Vlasenko
2cf4591413 i2c_tools: suppress "'blen' may be used uninitialized in this function"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:58:03 +01:00
Bartosz Golaszewski
5ed6989d80 i2cdump: display the numeric value for block read ioctl() errors
This makes busybox i2cdump compatible with the upstream version, which
also displays the numeric error value in case of a block read failure.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:10 +01:00
Bartosz Golaszewski
74bb9d5e63 i2cdump: bail-out if block read fails
We should bail-out if i2c_smbus_read_block_data() or
i2c_smbus_read_i2c_block_data() return 0 or less. Add the missing check
for the former and fix the existing for the latter.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Bartosz Golaszewski
1fe75b8ef1 i2cdump: use I2C block mode for the 'i' mode parameter
Currently we're calling i2c_smbus_read_block_data() for both 'i' and 's'
mode parameters. If the bus doesn't support SMBus block mode, then the
i2c access ioctl() fails. Make i2cdump behave compatibly with upstream
version by calling i2c_smbus_read_i2c_block_data() for I2C block.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Bartosz Golaszewski
1cde5f79d4 i2cdump: don't read block data in non-block modes
We currently read data twice in byte mode. Add a check to avoid calling
i2c_smbus_read_i2c_block_data() if we're not in I2C or SMBus block mode.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Bartosz Golaszewski
fc8eb056ea i2cdetect: coding style: add a space after 'for'
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Bartosz Golaszewski
99f025a499 i2cdetect: fix address skipping in auto mode
If the bus doesn't support SMBus Quick Write or Receive Byte commands
and we're running in auto mode all addresses will be skipped resulting
in an empty table being printed.

This is caused by not restoring the auto mode after it's been changed
for certain address ranges - we need an additional variable to hold the
temporary state.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-01 20:55:09 +01:00
Natanael Copa
1062391365 ifupdown: use -x hostname:NAME with udhcpc
The -H NAME is deprecated in udhcpc. See commit
2017d48c0d

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-31 14:19:06 +01:00
Denys Vlasenko
6bd3fff51a [g]unzip: fix recent breakage.
Also, do emit error message we so painstakingly pass from gzip internals

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 23:41:53 +01:00
Ron Yorston
95650a86d1 ash: allow popredir to be called if the stack is empty
If /tmp/test.sh is a script that tries to run a second script which
happens to be non-executable this:

   command . /tmp/test.sh

causes a seg fault.

This is because clearredir is called in the error path to clear the
stack of redirections.  The normal path then calls popredir, but popredir
fails when the stack is empty.

Reported-by: Bastian Bittorf <bittorf@bluebottle.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 22:23:13 +01:00
Ron Yorston
8c55dc79a7 ash: fix EXEXEC status clobbering
evalcommand always clobbers the exit status in case of an EXEXEC
which means that exec always fails with exit status 2 regardless
of what it actually returns.

This patch adds the missing check for EXEXEC so that the correct
exit status is preserved.  It causes the test ash-misc/exec.tests
to succeed.

Based on commit 7f68426 in dash git, by Herbert Xu.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 22:19:48 +01:00
Ron Yorston
e939856c87 ash: add tests for failures of the exec and command builtins
The exec builtin should return an exit status of 127 if the command
can't be found.  It doesn't:  it returns 2.

If the command builtin is used to source a script that runs a second
script that doesn't exist ash should issue an error.  Instead it seg
faults.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 22:19:06 +01:00
Denys Vlasenko
ace833028f stat: make -f optional. This allows to build stat for non-linux systems
function                                             old     new   delta
packed_usage                                       30761   30706     -55

Based on the patch by Ron Yorston.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 22:10:44 +01:00
Denys Vlasenko
fe0dc34746 lineedit: FEATURE_REVERSE_SEARCH should not depend on SAVEHISTORY
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 21:39:19 +01:00
Ron Yorston
f23264b35f lineedit: search applets as well as PATH for tab completion
In standalone shell mode search the applet table as well as PATH
when tab completing a command.

Use a stupid linear search:  we're also about to read all the
directories on PATH so efficiency isn't a big concern.

function                                             old     new   delta
add_match                                              -      53     +53
complete_cmd_dir_file                                687     724     +37
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 90/0)               Total: 90 bytes

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 19:49:33 +01:00
Ron Yorston
ae57af6e78 busybox: alter help message in standalone shell mode
Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-30 19:00:38 +01:00
Denys Vlasenko
112889d706 hush: copy for.tests from ash testsuite
This test passes for hush

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 22:37:25 +01:00
Ron Yorston
c0e007663d ash: simplify EOF/newline handling in list parser
Processing of here documents in ash has had a couple of breakages
which are now the subject of tests.  This commit should fix both.

It is based on the following commit in dash git by Herbert Xu:

   <7c245aa> [PARSER] Simplify EOF/newline handling in list parser

(See git://git.kernel.org/pub/scm/utils/dash/dash.git)

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 21:44:11 +01:00
Ron Yorston
6bd2fabc52 Revert "ash: fix a SEGV case in an invalid heredoc" xxx
This reverts commit 7e66102f76 but
leaves the test in place as it's still valid.

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 21:42:30 +01:00
Ron Yorston
713f07d906 ash: fix error during recursive processing of here document
Save the value of the checkkwd flag to prevent it being clobbered
during recursion.

Based on commit ec2c84d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
readtoken                                            190     203     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 13/0)               Total: 13 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:45:36 +01:00
Denys Vlasenko
7b14ede049 ash tests: make test print test name before it is run
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:34:20 +01:00
Ron Yorston
ef2386b80a ash: only allow local variables in functions
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:33:44 +01:00
Ron Yorston
3f221113a5 ash: respect -p flag when command builtin is run with -v/-V
The command builtin should only check the default path, not $PATH,
when the -p flag is used along with -v/-V.

Based on commits 65ae84b (by Harald van Dijk) and 29ee27d (by Herbert
Xu) from git://git.kernel.org/pub/scm/utils/dash/dash.git).

function                                             old     new   delta
commandcmd                                            72      87     +15
describe_command                                     437     450     +13
typecmd                                               84      86      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 30/0)               Total: 30 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 20:05:32 +01:00
Denys Vlasenko
e2f32c02b1 ash: fix command -- crash
busybox sh -c 'command --' segfaults because parse_command_args
returns a pointer to a null pointer.

Based on commit 18071c7 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Gerrit Pape.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:46:40 +01:00
Ron Yorston
383b885ff7 ash: save a few bytes in code to parse case statements
Based on commit 49b82fc from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
parse_command                                       1563    1555      -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-8)               Total: -8 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:36:08 +01:00
Ron Yorston
ab80e01cd9 ash: allow newline after variable name in for loop
Newline is a valid delimiter between the variable name and `in`
keyword in for loops.

Based on commit 22e8fb4 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
parse_command                                       1568    1563      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5)               Total: -5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:30:55 +01:00
Ron Yorston
9121510dc6 ash: add test for issue with here document
This used to work but doesn't now:

foo () {
cat <<EOF && { echo "$1" ; }
$1
EOF
}

foo "bar"

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 19:12:03 +01:00
Denys Vlasenko
4c8576fea1 modinfo: fix "-F firmware", add "intree" field display
function                                             old     new   delta
shortcuts                                              -      52     +52
modinfo                                              317     330     +13
display                                               77      87     +10
packed_usage                                       30752   30761      +9
modinfo_main                                         351     345      -6
static.shortcuts                                      48       -     -48
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 3/1 up/down: 84/-54)             Total: 30 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-28 18:07:46 +01:00
Denys Vlasenko
4840325351 lzop: eliminate variable, use "int" as return type
Based on patch by Maxin B. John <maxin.john@intel.com>

function                                             old     new   delta
pack_lzop                                            870     859     -11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-28 15:33:19 +01:00
Timo Teräs
82c2fad26c fbsplash: use virtual y size in mmap size calculations
The virtual y can be larger - and we can be even writing there since
we are taking into account the y offset. Avoids possible crash.
But use it only if set, seems it is not set if virtual area is not
allocated (though, often fbcon allocates some scrollback area).

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-27 21:32:00 +01:00
Aaro Koskinen
cddc98eab7 gzip: add support for --no-name long option
Add support for --no-name long option. Just silently ignore it
like the short -n option.

This allows to use busybox gzip with Lynx browser.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-27 21:30:43 +01:00
Aaro Koskinen
fbe50cf6bc gunzip: add support for long options
Add support for long options.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-27 21:28:50 +01:00
Denys Vlasenko
1de25a6e87 unzip: test for bad archive SEGVing
function                                             old     new   delta
huft_build                                          1296    1300      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-26 19:33:05 +01:00
Richard Genoud
d683c5c2f1 tr: support octal ranges
now, we can do printf "a\tb\tcdef\n" | ./busybox tr -d "\1-\14b-e"
af

and bonus, we save some bytes.

function                                             old     new   delta
expand                                               718     699     -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-19)             Total: -19
bytes

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-26 17:18:07 +01:00
Timo Teräs
028524317d ifupdown: pass interface device name for ipv6 route commands
IPv6 routes need the device argument for link-local routes, or they
cannot be used at all. E.g. "gateway fe80::def" seems to be used in
some places, but kernel refuses to insert the route unless device
name is explicitly specified in the route addition.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-26 17:06:12 +01:00
Denys Vlasenko
db700330d8 tweak defconfig
MONOTONIC_SYSCALL=y by default

FEATURE_LAST_SMALL is gone: now FEATURE_LAST_FANCY is a "bool", not a "choice".

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-25 20:36:03 +01:00
Denys Vlasenko
0269789537 inetd: make FEATURE_INETD_RPC off by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-25 20:10:46 +01:00
Ron Yorston
8814431aca libiproute: use if_nametoindex
Saves 87 bytes.  Assuming, of course, all platforms have it.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 22:04:36 +02:00
Aaro Koskinen
6d777b75ed xargs: make -I imply -r
Make -I imply -r (GNU findutils seems to do the same).

Fixes the following bug:

        $ echo -n | xargs -I% echo %
        Segmentation fault

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 22:01:29 +02:00
Denys Vlasenko
f98705a00c dumpleases: string reuse
text	   data	    bss	    dec	    hex	filename
 926254	    906	  17160	 944320	  e68c0	busybox_old
 926242	    906	  17160	 944308	  e68b4	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 20:45:10 +02:00
Isaac Dunham
d320a1e7a5 dumpleases: new option -d to show time in seconds
function                                             old     new   delta
dumpleases_main                                      493     534     +41
static.dumpleases_longopts                            31      41     +10
packed_usage                                       30777   30752     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 51/-25)             Total: 26 bytes

Signed-off-by: Isaac Dunham <ibid.ag@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 20:28:04 +02:00
Denys Vlasenko
334e12ac6a zcip: ...ad suppress the warning
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 19:15:44 +02:00
Denys Vlasenko
49d51598ac zcip: do not query current time if we won't use the result
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 19:14:04 +02:00
Denys Vlasenko
bf1866c183 tweak zcip service example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 18:57:32 +02:00
Denys Vlasenko
1a1cfedbef Tweak README
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 14:58:58 +02:00
Denys Vlasenko
4f8ecf273c update network service examples
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 14:55:33 +02:00
Denys Vlasenko
d32a1a4054 New example of a service: examples/var_service/zcip_if
Zeroconf for IPv4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 05:30:58 +02:00
Denys Vlasenko
9a51217668 dumpleases: make host names sanitized to shell-friendly condition
function                                             old     new   delta
add_lease                                            271     298     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 04:45:22 +02:00
Denys Vlasenko
941e7a4919 reuse a string
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 04:19:56 +02:00
Denys Vlasenko
cd13974b20 rmmod: fix bad error message
Before:

    ># busybox_old rmmod gtrhfhdfghdf
    rmmod: can't unload 'gtrhfhdfghdf': unknown symbol in module, or unknown parameter

    After:

    ># busybox rmmod gtrhfhdfghdf
    rmmod: can't unload module 'gtrhfhdfghdf': No such file or directory

function                                             old     new   delta
modprobe_main                                        726     721      -5
do_modprobe                                          599     590      -9
rmmod_main                                           187     169     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-32)             Total: -32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 04:17:04 +02:00
Denys Vlasenko
2e9a0662bc MODPROBE_SMALL is not experimental anymore
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 04:13:16 +02:00
Denys Vlasenko
049b007865 pmap: fix bogus {no such process} comm field text
function                                             old     new   delta
read_cmdline                                         246     266     +20
procps_get_maps                                      196     193      -3
packed_usage                                       30413   30404      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 20/-12)              Total: 8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-24 03:45:57 +02:00
Denys Vlasenko
00da72bee0 tidy up strtok use
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23 18:43:16 +02:00
Denys Vlasenko
59f8475924 httpd: fix heap buffer overflow. Closes 8426
function                                             old     new   delta
send_headers                                         654     677     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23 11:49:04 +02:00
Denys Vlasenko
d3d6534b2a wget: if stderr is not a tty, progress bar shouldn't use tty-tricks
function                                             old     new   delta
bb_progress_update                                   706     768     +62

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23 02:01:38 +02:00
Denys Vlasenko
641caaec3d libbb: factor out code which queries screen width
function                                             old     new   delta
get_terminal_width                                     -      17     +17
stty_main                                           1196    1197      +1
pstree_main                                          321     319      -2
ls_main                                              735     731      -4
watch_main                                           232     225      -7
bb_progress_update                                   714     706      -8
ps_main                                              555     543     -12
run_applet_and_exit                                  708     695     -13
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/6 up/down: 18/-46)            Total: -28 byte

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-23 01:44:22 +02:00
Denys Vlasenko
a960748748 tar: add a test that we don't write into symlinks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 16:37:01 +02:00
Denys Vlasenko
accd9eeb71 remove systemd support
systemd people are not willing to play nice with the rest of the world.
Therefore there is no reason for the rest of the world to cooperate with them.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 16:01:57 +02:00
Denys Vlasenko
537389cedd tar: fix files skipped with --strip_components not resetting selinux context
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 13:38:09 +02:00
Denys Vlasenko
f167e4503d tar: shrink hardlink name handling code
function                                             old     new   delta
data_extract_all                                    1069    1040     -29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 13:30:34 +02:00
Denys Vlasenko
62ae323df0 tar: implement --version for buildroot
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 13:22:26 +02:00
Denys Vlasenko
6c563e370d tar: add support for --strip-components=N
function                                             old     new   delta
data_extract_all                                     882     995    +113
tar_longopts                                         290     309     +19
tar_main                                             938     942      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 136/0)             Total: 136 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-22 01:07:13 +02:00
Denys Vlasenko
c47917865d login: explain -h HOST option better
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-21 16:06:40 +02:00
Denys Vlasenko
92e1b0826d wget: make Bartosz's "wget --passive-ftp -nd -t 3" work
function                                             old     new   delta
static.wget_longopts                                 166     234     +68
wget_main                                           2608    2610      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 21:51:52 +02:00
Denys Vlasenko
edcd5dcc9b typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 18:15:01 +02:00
Denys Vlasenko
58d0e20ad0 scripts/trylink: remove $CPPFLAGS
We don't use it in final link, should not use it in check_FOO then.
This uncovered a logic bug in glibc check...

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 16:40:43 +02:00
Denys Vlasenko
5134010d88 scripts/trylink: fix bit-rotted linker option verification
To that end, *make it complain* when check_cc fails on options
we usually want to succeed.

   text	   data	    bss	    dec	    hex	filename
 929697	    932	  17692	 948321	  e7861	busybox-1.23.2/busybox
 915361	    911	  17484	 933756	  e3f7c	busybox-1.23.2.fixed/busybox

 927725	    932	  17448	 946105	  e6fb9	busybox-1.24.0/busybox
 913630	    911	  17240	 931781	  e37c5	busybox-1.24.0.fixed/busybox

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 16:16:16 +02:00
Denys Vlasenko
76efb3ed33 qemu_multiarch_testing/README: add a list of qemu's needed
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-20 12:58:37 +02:00
Denys Vlasenko
f2ccefb946 setarch: add support for '-R' (disable randomization)
This commit adds support for the -R flag of setarch, which disables
randomization of the virtual address space.

function                                             old     new   delta
setarch_main                                         115     150     +35
packed_usage                                       30664   30651     -13

Signed-off-by: Jan Heylen <heyleke@gmail.com>
Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 23:26:50 +02:00
Denys Vlasenko
0506e292b5 sort: fix ENDCHAR handling in "-kSTART,N.ENDCHAR"
function                                             old     new   delta
get_key                                              505     503      -2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 19:27:26 +02:00
Denys Vlasenko
d1ed3e68b8 sort: code shrink
function                                             old     new   delta
compare_keys                                         738     695     -43

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 19:13:06 +02:00
Denys Vlasenko
fd19faf705 remove extra debug printout
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 14:48:24 +02:00
Denys Vlasenko
2e86a5c98d sort: fix key with delimiters breakage
function                                             old     new   delta
get_key                                              509     505      -4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 14:44:51 +02:00
Denys Vlasenko
3d0805e9e7 libbb: make parse_chown_usergroup_or_die() set unspecified uid/gid to -1
function                                             old     new   delta
parse_chown_usergroup_or_die                         102     115     +13
chown_main                                           190     175     -15
start_stop_daemon_main                              1043    1027     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 13/-31)            Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 04:37:19 +02:00
Denys Vlasenko
526d85831e libbb: get_uidgid() always called with allow_numeric=1
function                                             old     new   delta
xget_uidgid                                           30      25      -5
make_device                                         2188    2183      -5
main                                                 797     792      -5
get_uidgid                                           240     225     -15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 04:27:17 +02:00
Denys Vlasenko
f3d58a29be od: get rid of (almost all) statics
function                                             old     new   delta
od_main                                             2565    2600     +35
check_and_close                                      113     115      +2
static.prev_pair_equal                                 1       -      -1
static.first                                           1       -      -1
exit_code                                              1       -      -1
string_min                                             4       -      -4
n_specs                                                4       -      -4
in_stream                                              4       -      -4
format_address                                         4       -      -4
file_list                                              4       -      -4
bytes_per_block                                        4       -      -4
get_lcm                                              120     115      -5
pseudo_offset                                          8       -      -8
------------------------------------------------------------------------------
(add/remove: 0/10 grow/shrink: 2/1 up/down: 37/-40)            Total: -3 bytes
   text	   data	    bss	    dec	    hex	filename
 938487	    932	  17392	 956811	  e998b	busybox_old
 938519	    924	  17360	 956803	  e9983	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 02:51:56 +02:00
Denys Vlasenko
c4fb8c6ad5 fsck: do not use statics
function                                             old     new   delta
fsck_main                                           1794    1812     +18
packed_usage                                       30662   30664      +2
kill_all_if_got_signal                                60      62      +2
create_fs_device                                     158     160      +2
static.kill_sent                                       1       -      -1
skip_root                                              1       -      -1
serialize                                              1       -      -1
parallel_root                                          1       -      -1
noexecute                                              1       -      -1
fs_type_negated                                        1       -      -1
force_all_parallel                                     1       -      -1
verbose                                                4       -      -4
num_running                                            4       -      -4
num_args                                               4       -      -4
max_running                                            4       -      -4
instance_list                                          4       -      -4
fstype                                                 4       -      -4
fs_type_list                                           4       -      -4
fs_type_flag                                           4       -      -4
filesys_last                                           4       -      -4
filesys_info                                           4       -      -4
args                                                   4       -      -4
wait_one                                             309     300      -9
ignore                                               196     174     -22
------------------------------------------------------------------------------
(add/remove: 0/18 grow/shrink: 4/2 up/down: 24/-82)           Total: -58 bytes
   text    data     bss     dec     hex filename
 938527     932   17448  956907   e99eb busybox_old
 938487     932   17392  956811   e998b busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 02:24:14 +02:00
Denys Vlasenko
36647abcc3 chattr,lsattr: shorten help message
function                                             old     new   delta
packed_usage                                       30662   30645     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 01:29:20 +02:00
Denys Vlasenko
95dee81a46 loginutils/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 01:20:36 +02:00
Denys Vlasenko
28826ac8c0 debianutils/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 00:52:26 +02:00
Denys Vlasenko
854bb6879d printutils/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 00:45:46 +02:00
Denys Vlasenko
0863e1a576 runit/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-19 00:41:28 +02:00
Denys Vlasenko
000eda41c0 e2fsprogs/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-18 22:40:23 +02:00
Denys Vlasenko
d34f300db6 sysklogd/*: convert to new-style "one file" applets
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-18 22:40:09 +02:00
Aaro Koskinen
2735bc00e3 cpio: implement -R/--owner
Implement -R/--owner to force ownership of files.

function                                             old     new   delta
cpio_main                                            532     586     +54
get_header_cpio                                      909     939     +30
print                                                 36      65     +29
cpio_o                                               804     832     +28
cpio_TRAILER                                           -      11     +11
packed_usage                                       30667   30662      -5
static.trailer                                        11       -     -11
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 4/1 up/down: 152/-16)           Total: 136 bytes

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-16 17:24:46 +02:00
Denys Vlasenko
93dd9fd90a du: extra compat: with -k and -m, round sizes up
function                                             old     new   delta
print                                                 36      65     +29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-15 21:33:34 +02:00
Denys Vlasenko
5251135bc1 better pinger service example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-15 02:10:11 +02:00
Denys Vlasenko
4ad702c0a7 top: make sort field for 's' mode less confusing
function                                             old     new   delta
display_topmem_process_list                          542     565     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-14 22:30:47 +02:00
Denys Vlasenko
926d801fa5 libiproute: make rt_addr_n2a() and format_host() return auto strings
function                                             old     new   delta
rt_addr_n2a                                           56      53      -3
print_addrinfo                                      1227    1178     -49
print_neigh                                          933     881     -52
print_rule                                           689     617     -72
print_tunnel                                         640     560     -80
print_route                                         1727    1588    -139
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-395)           Total: -395 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-14 13:56:42 +02:00
Denys Vlasenko
0f296a3a56 libiproute: rename invarg(a,b) to invarg_1_to_2(a,b)
invarg(a,b) - "invalid argument", but how a and b enter the message?

invarg_1_to_2(a,b) is somewhat easier to read: "invalid argument 'a' to 'b'"

Audit of usage revealed a number of bad uses, with too long messages.

   text	   data	    bss	    dec	    hex	filename
 938848	    932	  17448	 957228	  e9b2c	busybox_old
 938788	    932	  17448	 957168	  e9af0	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-14 13:21:01 +02:00
Curt Brune
69934701fd networking: add 'ip neigh' command
This patch ports the 'ip neigh' command, originally written by Alexey
Kuznetsov, <kuznet@ms2.inr.ac.ru>, to busybox.

The base of the port is the version of iproute that shipped with
Debian Squeeze, taken from:

  http://http.debian.net/debian/pool/main/i/iproute/iproute_20100519.orig.tar.gz

This patch has actively been used by the Open Network Install
Environment (ONIE) project for over 3 years without incident.

function                                             old     new   delta
print_neigh                                            -     933    +933
ipneigh_list_or_flush                                  -     742    +742
get_hz                                                 -     109    +109
do_ipneigh                                             -      62     +62
do_iproute                                          2112    2153     +41
packed_usage                                       30647   30667     +20
ipneigh_main                                           -      14     +14
static.ip_neigh_commands                               -      12     +12
static.nuds                                            -       9      +9
static.ip_func_ptrs                                   32      36      +4
print_route                                         1858    1727    -131
------------------------------------------------------------------------------
(add/remove: 8/0 grow/shrink: 3/1 up/down: 1946/-131)        Total: 1815 bytes

Signed-off-by: Curt Brune <curt@cumulusnetworks.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-14 12:53:47 +02:00
Denys Vlasenko
7b85ec30b5 *: more BUILD_BUG_ON conversions
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 17:17:34 +02:00
Ron Yorston
4d0c1ea478 wget: shrink code if https isn't supported
If FEATURE_WGET_OPENSSL and FEATURE_WGET_SSL_HELPER are both disabled
there's no point in checking for https URLs.

function                                             old     new   delta
P_HTTPS                                                6       -      -6
.rodata                                           155501  155469     -32
parse_url                                            476     423     -53
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-91)             Total: -91 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 14:56:22 +02:00
Denys Vlasenko
ab3964db4e libbb: introduce kernel-style BUILD_BUG_ON()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 14:50:20 +02:00
Denys Vlasenko
f7ad927c20 ftpd: make DIR parameter work for non-root too: chdir to it instead of chroot
Unfortunately, chroot() works only for root user, because of attacks
on setuid binaries (make DIR/lib/ld-linux.so a shell, hardlink to
a setuid binary, chroot to DIR, execute it and get root shell).

function                                             old     new   delta
ftpd_main                                           2160    2180     +20

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 13:49:53 +02:00
Denys Vlasenko
bf74fb4497 typo fix in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 12:34:35 +02:00
Denys Vlasenko
6390a3a4e5 whitespace fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 01:51:37 +02:00
Denys Vlasenko
450a367a11 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 01:49:06 +02:00
Denys Vlasenko
b5dabd9078 libpwdgrp: fix comment discrepancies
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 00:31:02 +02:00
Denys Vlasenko
966423d403 Start 1.25.0 development cycle
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-12 14:36:39 +02:00
364 changed files with 7779 additions and 3242 deletions

View File

@ -116,9 +116,21 @@ config FEATURE_COMPRESS_USAGE
and have very little memory, this might not be a win. Otherwise,
you probably want this.
config BUSYBOX
bool "Include busybox applet"
default y
help
The busybox applet provides general help regarding busybox and
allows the included applets to be listed. It's also required
if applet links are to be installed at runtime.
If you can live without these features disabling this will save
some space.
config FEATURE_INSTALLER
bool "Support --install [-s] to install applet links at runtime"
default y
depends on BUSYBOX
help
Enable 'busybox --install [-s]' support. This will allow you to use
busybox at runtime to create hard links or symlinks for all the
@ -688,6 +700,16 @@ config DEBUG_PESSIMIZE
in a much bigger executable that more closely matches the source
code.
config DEBUG_SANITIZE
bool "Enable runtime sanitizers (ASAN/LSAN/USAN/etc...)"
default n
help
Say Y here if you want to enable runtime sanitizers. These help
catch bad memory accesses (e.g. buffer overflows), but will make
the executable larger and slow down runtime a bit.
If you aren't developing/testing busybox, say N here.
config UNIT_TEST
bool "Build unit tests"
default n

View File

@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 24
SUBLEVEL = 0
PATCHLEVEL = 25
SUBLEVEL = 1
EXTRAVERSION =
NAME = Unnamed
@ -610,7 +610,8 @@ quiet_cmd_busybox__ ?= LINK $@
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
"$(core-y)" \
"$(libs-y)" \
"$(LDLIBS)"
"$(LDLIBS)" \
&& $(srctree)/scripts/generate_BUFSIZ.sh --post include/common_bufsiz.h
# Generate System.map
quiet_cmd_sysmap = SYSMAP
@ -844,12 +845,15 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
# Split autoconf.h into include/linux/config/*
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h
quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h
cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
#bbox# piggybacked generation of few .h files
include/config/MARKER: scripts/basic/split-include include/autoconf.h
$(call cmd,split_autoconf)
$(call cmd,gen_bbconfigopts)
$(call cmd,gen_common_bufsiz)
@touch $@
# Generate some files
@ -965,6 +969,7 @@ CLEAN_FILES += busybox busybox_unstripped* busybox.links \
MRPROPER_DIRS += include/config include2
MRPROPER_FILES += .config .config.old include/asm .version .old_version \
include/NUM_APPLETS.h \
include/common_bufsiz.h \
include/autoconf.h \
include/bbconfigopts.h \
include/bbconfigopts_bz2.h \

View File

@ -75,6 +75,11 @@ else
CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
endif
endif
ifeq ($(CONFIG_DEBUG_SANITIZE),y)
CFLAGS += $(call cc-option,-fsanitize=address,)
CFLAGS += $(call cc-option,-fsanitize=leak,)
CFLAGS += $(call cc-option,-fsanitize=undefined,)
endif
# If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
ARCH_FPIC ?= -fpic

2
TODO
View File

@ -258,5 +258,3 @@ vdprintf() -> similar sized functionality
* more support for advanced linux 2.6.x features, see: iotop
most likely there is more
* even more support for statistics: mpstat, iostat, powertop....

View File

@ -41,8 +41,6 @@ struct bb_applet {
enum { NUM_APPLETS = ARRAY_SIZE(applets) };
static int offset[NUM_APPLETS];
static int cmp_name(const void *a, const void *b)
{
const struct bb_applet *aa = a;
@ -62,24 +60,30 @@ static int str_isalnum_(const char *s)
int main(int argc, char **argv)
{
int i;
int ofs;
// unsigned MAX_APPLET_NAME_LEN = 1;
int i, j;
// In find_applet_by_name(), before linear search, narrow it down
// by looking at N "equidistant" names. With ~350 applets:
// KNOWN_APPNAME_OFFSETS cycles
// 0 9057
// 2 4604 + ~100 bytes of code
// 4 2407 + 4 bytes
// 8 1342 + 8 bytes
// 16 908 + 16 bytes
// 32 884 + 32 bytes
// With 8, int16_t applet_nameofs[] table has 7 elements.
int KNOWN_APPNAME_OFFSETS = 8;
// With 128 applets we do two linear searches, with 1..7 strcmp's in the first one
// and 1..16 strcmp's in the second. With 256 apps, second search does 1..32 strcmp's.
if (NUM_APPLETS < 128)
KNOWN_APPNAME_OFFSETS = 4;
if (NUM_APPLETS < 32)
KNOWN_APPNAME_OFFSETS = 0;
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
ofs = 0;
for (i = 0; i < NUM_APPLETS; i++) {
offset[i] = ofs;
ofs += strlen(applets[i].name) + 1;
}
/* We reuse 4 high-order bits of offset array for other purposes,
* so if they are indeed needed, refuse to proceed */
if (ofs > 0xfff)
return 1;
if (!argv[1])
return 1;
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (i < 0)
return 1;
@ -94,7 +98,27 @@ int main(int argc, char **argv)
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main);
}
printf("\n");
printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS);
if (KNOWN_APPNAME_OFFSETS > 0) {
int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS];
for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++)
index[i] = i * NUM_APPLETS / KNOWN_APPNAME_OFFSETS;
ofs = 0;
for (i = 0; i < NUM_APPLETS; i++) {
for (j = 0; j < KNOWN_APPNAME_OFFSETS; j++)
if (i == index[j])
offset[j] = ofs;
ofs += strlen(applets[i].name) + 1;
}
/* If the list of names is too long refuse to proceed */
if (ofs > 0xffff)
return 1;
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
for (i = 1; i < KNOWN_APPNAME_OFFSETS; i++)
printf("%d,\n", offset[i]);
printf("};\n\n");
}
//printf("#ifndef SKIP_definitions\n");
printf("const char applet_names[] ALIGN1 = \"\"\n");
@ -119,20 +143,39 @@ int main(int argc, char **argv)
printf("};\n");
printf("#endif\n\n");
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
for (i = 0; i < NUM_APPLETS; i++) {
printf("0x%04x,\n",
offset[i]
#if ENABLE_FEATURE_PREFER_APPLETS
+ (applets[i].nofork << 12)
+ (applets[i].noexec << 13)
#endif
#if ENABLE_FEATURE_SUID
+ (applets[i].need_suid << 14) /* 2 bits */
#endif
);
printf("const uint8_t applet_flags[] ALIGN1 = {\n");
i = 0;
while (i < NUM_APPLETS) {
int v = applets[i].nofork + (applets[i].noexec << 1);
if (++i < NUM_APPLETS)
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 2;
if (++i < NUM_APPLETS)
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 4;
if (++i < NUM_APPLETS)
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 6;
printf("0x%02x,\n", v);
i++;
}
printf("};\n\n");
#endif
#if ENABLE_FEATURE_SUID
printf("const uint8_t applet_suid[] ALIGN1 = {\n");
i = 0;
while (i < NUM_APPLETS) {
int v = applets[i].need_suid; /* 2 bits */
if (++i < NUM_APPLETS)
v |= applets[i].need_suid << 2;
if (++i < NUM_APPLETS)
v |= applets[i].need_suid << 4;
if (++i < NUM_APPLETS)
v |= applets[i].need_suid << 6;
printf("0x%02x,\n", v);
i++;
}
printf("};\n\n");
#endif
#if ENABLE_FEATURE_INSTALLER
printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");

View File

@ -31,7 +31,7 @@ config FEATURE_SEAMLESS_GZ
config FEATURE_SEAMLESS_Z
bool "tar, rpm, modprobe etc understand .Z data"
default n
default n # it is ancient
help
Make tar, rpm, modprobe etc understand .Z data.

View File

@ -4,7 +4,7 @@
#
# Licensed under GPLv2, see file LICENSE in this source tree.
libs-y += libarchive/
libs-y += libarchive/
lib-y:=

View File

@ -22,23 +22,13 @@
//config: default n # needs to be improved to be able to replace binutils ar
//config: help
//config: ar is an archival utility program used to create, modify, and
//config: extract contents from archives. An archive is a single file holding
//config: a collection of other files in a structure that makes it possible to
//config: retrieve the original individual files (called archive members).
//config: The original files' contents, mode (permissions), timestamp, owner,
//config: and group are preserved in the archive, and can be restored on
//config: extraction.
//config: extract contents from archives. In practice, it is used exclusively
//config: for object module archives used by compilers.
//config:
//config: The stored filename is limited to 15 characters. (for more information
//config: see long filename support).
//config: ar has 60 bytes of overheads for every stored file.
//config:
//config: This implementation of ar can extract archives, it cannot create or
//config: modify them.
//config: On an x86 system, the ar applet adds about 1K.
//config:
//config: Unless you have a specific application which requires ar, you should
//config: probably say N here.
//config: probably say N here: most compilers come with their own ar utility.
//config:
//config:config FEATURE_AR_LONG_FILENAMES
//config: bool "Support for long filenames (not needed for debs)"

View File

@ -121,7 +121,7 @@ int FAST_FUNC bbunpack(char **argv,
if (!(option_mask32 & SEAMLESS_MAGIC)) {
init_transformer_state(&xstate);
xstate.check_signature = 1;
xstate.signature_skipped = 0;
/*xstate.src_fd = STDIN_FILENO; - already is */
xstate.dst_fd = STDOUT_FILENO;
status = unpacker(&xstate);
@ -220,7 +220,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
//config:config UNCOMPRESS
//config: bool "uncompress"
//config: default n
//config: default n # ancient
//config: help
//config: uncompress is used to decompress archives created by compress.
//config: Not much used anymore, replaced by gzip/gunzip.
@ -290,6 +290,13 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
//config: gunzip is used to decompress archives created by gzip.
//config: You can use the `-t' option to test the integrity of
//config: an archive, without decompressing it.
//config:
//config:config FEATURE_GUNZIP_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on GUNZIP && LONG_OPTS
//config: help
//config: Enable use of long options.
//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
//applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
@ -321,6 +328,17 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
}
return filename;
}
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
static const char gunzip_longopts[] ALIGN1 =
"stdout\0" No_argument "c"
"to-stdout\0" No_argument "c"
"force\0" No_argument "f"
"test\0" No_argument "t"
"no-name\0" No_argument "n"
;
#endif
/*
* Linux kernel build uses gzip -d -n. We accept and ignore it.
* Man page says:
@ -337,6 +355,9 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int gunzip_main(int argc UNUSED_PARAM, char **argv)
{
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
applet_long_options = gunzip_longopts;
#endif
getopt32(argv, "cfvqdtn");
argv += optind;

View File

@ -11,6 +11,7 @@
* Only supports new ASCII and CRC formats
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
//config:config CPIO
@ -46,7 +47,7 @@
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
//usage:#define cpio_trivial_usage
//usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
//usage: "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]")
//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
//usage: " [EXTR_FILE]..."
//usage:#define cpio_full_usage "\n\n"
@ -71,6 +72,7 @@
//usage: "\n -v Verbose"
//usage: "\n -u Overwrite"
//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
//usage: "\n -R USER[:GRP] Set owner of created files"
//usage: IF_FEATURE_CPIO_O(
//usage: "\n -H newc Archive format"
//usage: )
@ -130,7 +132,7 @@
-I FILE File to use instead of standard input
-L, --dereference Dereference symbolic links (copy the files
that they point to instead of copying the links)
-R, --owner=[USER][:.][GROUP] Set owner of created files
-R, --owner=[USER][:.][GRP] Set owner of created files
Options valid in --extract and --pass-through modes:
-d, --make-directories Create leading directories where needed
@ -150,7 +152,8 @@ enum {
OPT_PRESERVE_MTIME = (1 << 6),
OPT_DEREF = (1 << 7),
OPT_FILE = (1 << 8),
OPTBIT_FILE = 8,
OPT_OWNER = (1 << 9),
OPTBIT_OWNER = 9,
IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
@ -163,7 +166,18 @@ enum {
OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
};
#define OPTION_STR "it0uvdmLF:"
#define OPTION_STR "it0uvdmLF:R:"
struct globals {
struct bb_uidgid_t owner_ugid;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
void BUG_cpio_globals_too_big(void);
#define INIT_G() do { \
setup_common_bufsiz(); \
G.owner_ugid.uid = -1L; \
G.owner_ugid.gid = -1L; \
} while (0)
#if ENABLE_FEATURE_CPIO_O
static off_t cpio_pad4(off_t size)
@ -181,7 +195,6 @@ static off_t cpio_pad4(off_t size)
* It's ok to exit instead of return. */
static NOINLINE int cpio_o(void)
{
static const char trailer[] ALIGN1 = "TRAILER!!!";
struct name_s {
struct name_s *next;
char name[1];
@ -223,6 +236,11 @@ static NOINLINE int cpio_o(void)
bb_simple_perror_msg_and_die(name);
}
if (G.owner_ugid.uid != (uid_t)-1L)
st.st_uid = G.owner_ugid.uid;
if (G.owner_ugid.gid != (gid_t)-1L)
st.st_gid = G.owner_ugid.gid;
if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
st.st_size = 0; /* paranoia */
@ -275,7 +293,7 @@ static NOINLINE int cpio_o(void)
} else {
/* If no (more) hardlinks to output,
* output "trailer" entry */
name = trailer;
name = cpio_TRAILER;
/* st.st_size == 0 is a must, but for uniformity
* in the output, we zero out everything */
memset(&st, 0, sizeof(st));
@ -323,7 +341,7 @@ static NOINLINE int cpio_o(void)
}
if (!line) {
if (name != trailer)
if (name != cpio_TRAILER)
goto next_link;
/* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
return EXIT_SUCCESS;
@ -339,6 +357,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
{
archive_handle_t *archive_handle;
char *cpio_filename;
char *cpio_owner;
IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
unsigned opt;
@ -353,12 +372,14 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
"pass-through\0" No_argument "p"
#endif
#endif
"owner\0" Required_argument "R"
"verbose\0" No_argument "v"
"quiet\0" No_argument "\xff"
"to-stdout\0" No_argument "\xfe"
;
#endif
INIT_G();
archive_handle = init_handle();
/* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
@ -369,14 +390,21 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
/* -L makes sense only with -o or -p */
#if !ENABLE_FEATURE_CPIO_O
opt = getopt32(argv, OPTION_STR, &cpio_filename);
opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner);
#else
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"),
&cpio_filename, &cpio_owner, &cpio_fmt);
#endif
argv += optind;
if (opt & OPT_OWNER) { /* -R */
parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner);
archive_handle->cpio__owner = G.owner_ugid;
}
#if !ENABLE_FEATURE_CPIO_O
if (opt & OPT_FILE) { /* -F */
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
}
#else
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
argv += optind;
if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
}

View File

@ -77,13 +77,15 @@ aa: 85.1% -- replaced with aa.gz
//kbuild:lib-$(CONFIG_GZIP) += gzip.o
//usage:#define gzip_trivial_usage
//usage: "[-cfd" IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
//usage: "[-cf" IF_GUNZIP("d") 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: "\n -d Decompress"
//usage: )
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage:
@ -2160,6 +2162,7 @@ static const char gzip_longopts[] ALIGN1 =
"quiet\0" No_argument "q"
"fast\0" No_argument "1"
"best\0" No_argument "9"
"no-name\0" No_argument "n"
;
#endif
@ -2217,10 +2220,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */
if (opt == 0)
opt = 1 << 6; /* default: 6 */
/* Map 1..3 to 4 */
if (opt & 0x7)
opt |= 1 << 4;
opt = ffs(opt >> 3);
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
max_chain_length = 1 << gzip_level_config[opt].chain_shift;
good_match = gzip_level_config[opt].good;
max_lazy_match = gzip_level_config[opt].lazy2 * 2;

View File

@ -4,7 +4,7 @@
#
# Licensed under GPLv2 or later, see file LICENSE in this source tree.
lib-y:=
lib-y:= common.o
COMMON_FILES:= \
\

View File

@ -0,0 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#include "bb_archive.h"
const char cpio_TRAILER[] ALIGN1 = "TRAILER!!!";

View File

@ -11,6 +11,12 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
file_header_t *file_header = archive_handle->file_header;
int dst_fd;
int res;
char *hard_link;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
char *dst_name;
#else
# define dst_name (file_header->name)
#endif
#if ENABLE_FEATURE_TAR_SELINUX
char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
@ -23,11 +29,49 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
#endif
/* Hard links are encoded as regular files of size 0
* with a nonempty link field */
hard_link = NULL;
if (S_ISREG(file_header->mode) && file_header->size == 0)
hard_link = file_header->link_target;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
dst_name = file_header->name;
if (archive_handle->tar__strip_components) {
unsigned n = archive_handle->tar__strip_components;
do {
dst_name = strchr(dst_name, '/');
if (!dst_name || dst_name[1] == '\0') {
data_skip(archive_handle);
goto ret;
}
dst_name++;
/*
* Link target is shortened only for hardlinks:
* softlinks restored unchanged.
*/
if (hard_link) {
// GNU tar 1.26 does not check that we reached end of link name:
// if "dir/hardlink" is hardlinked to "file",
// tar xvf a.tar --strip-components=1 says:
// tar: hardlink: Cannot hard link to '': No such file or directory
// and continues processing. We silently skip such entries.
hard_link = strchr(hard_link, '/');
if (!hard_link || hard_link[1] == '\0') {
data_skip(archive_handle);
goto ret;
}
hard_link++;
}
} while (--n != 0);
}
#endif
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
char *slash = strrchr(file_header->name, '/');
char *slash = strrchr(dst_name, '/');
if (slash) {
*slash = '\0';
bb_make_directory(file_header->name, -1, FILEUTILS_RECUR);
bb_make_directory(dst_name, -1, FILEUTILS_RECUR);
*slash = '/';
}
}
@ -35,12 +79,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) {
/* Remove the entry if it exists */
if (!S_ISDIR(file_header->mode)) {
/* Is it hardlink?
* We encode hard links as regular files of size 0 with a symlink */
if (S_ISREG(file_header->mode)
&& file_header->link_target
&& file_header->size == 0
) {
if (hard_link) {
/* Ugly special case:
* tar cf t.tar hardlink1 hardlink2 hardlink1
* results in this tarball structure:
@ -48,22 +87,22 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
* hardlink2 -> hardlink1
* hardlink1 -> hardlink1 <== !!!
*/
if (strcmp(file_header->link_target, file_header->name) == 0)
if (strcmp(hard_link, dst_name) == 0)
goto ret;
}
/* Proceed with deleting */
if (unlink(file_header->name) == -1
if (unlink(dst_name) == -1
&& errno != ENOENT
) {
bb_perror_msg_and_die("can't remove old file %s",
file_header->name);
dst_name);
}
}
}
else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
/* Remove the existing entry if its older than the extracted entry */
struct stat existing_sb;
if (lstat(file_header->name, &existing_sb) == -1) {
if (lstat(dst_name, &existing_sb) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat old file");
}
@ -73,30 +112,25 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
&& !S_ISDIR(file_header->mode)
) {
bb_error_msg("%s not created: newer or "
"same age file exists", file_header->name);
"same age file exists", dst_name);
}
data_skip(archive_handle);
goto ret;
}
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
else if ((unlink(dst_name) == -1) && (errno != EISDIR)) {
bb_perror_msg_and_die("can't remove old file %s",
file_header->name);
dst_name);
}
}
/* Handle hard links separately
* We encode hard links as regular files of size 0 with a symlink */
if (S_ISREG(file_header->mode)
&& file_header->link_target
&& file_header->size == 0
) {
/* hard link */
res = link(file_header->link_target, file_header->name);
if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
/* Handle hard links separately */
if (hard_link) {
res = link(hard_link, dst_name);
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("can't create %slink "
"from %s to %s", "hard",
file_header->name,
file_header->link_target);
dst_name,
hard_link);
}
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
goto ret;
@ -106,17 +140,17 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
switch (file_header->mode & S_IFMT) {
case S_IFREG: {
/* Regular file */
char *dst_name;
char *dst_nameN;
int flags = O_WRONLY | O_CREAT | O_EXCL;
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
flags = O_WRONLY | O_CREAT | O_TRUNC;
dst_name = file_header->name;
dst_nameN = dst_name;
#ifdef ARCHIVE_REPLACE_VIA_RENAME
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME)
/* rpm-style temp file name */
dst_name = xasprintf("%s;%x", dst_name, (int)getpid());
dst_nameN = xasprintf("%s;%x", dst_name, (int)getpid());
#endif
dst_fd = xopen3(dst_name,
dst_fd = xopen3(dst_nameN,
flags,
file_header->mode
);
@ -124,32 +158,32 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
close(dst_fd);
#ifdef ARCHIVE_REPLACE_VIA_RENAME
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) {
xrename(dst_name, file_header->name);
free(dst_name);
xrename(dst_nameN, dst_name);
free(dst_nameN);
}
#endif
break;
}
case S_IFDIR:
res = mkdir(file_header->name, file_header->mode);
res = mkdir(dst_name, file_header->mode);
if ((res == -1)
&& (errno != EISDIR) /* btw, Linux doesn't return this */
&& (errno != EEXIST)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't make dir %s", file_header->name);
bb_perror_msg("can't make dir %s", dst_name);
}
break;
case S_IFLNK:
/* Symlink */
//TODO: what if file_header->link_target == NULL (say, corrupted tarball?)
res = symlink(file_header->link_target, file_header->name);
if ((res == -1)
res = symlink(file_header->link_target, dst_name);
if (res != 0
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't create %slink "
"from %s to %s", "sym",
file_header->name,
dst_name,
file_header->link_target);
}
break;
@ -157,11 +191,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
case S_IFBLK:
case S_IFCHR:
case S_IFIFO:
res = mknod(file_header->name, file_header->mode, file_header->device);
res = mknod(dst_name, file_header->mode, file_header->device);
if ((res == -1)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("can't create node %s", file_header->name);
bb_perror_msg("can't create node %s", dst_name);
}
break;
default:
@ -186,20 +220,20 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
#endif
/* GNU tar 1.15.1 uses chown, not lchown */
chown(file_header->name, uid, gid);
chown(dst_name, uid, gid);
}
/* uclibc has no lchmod, glibc is even stranger -
* it has lchmod which seems to do nothing!
* so we use chmod... */
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) {
chmod(file_header->name, file_header->mode);
chmod(dst_name, file_header->mode);
}
if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
struct timeval t[2];
t[1].tv_sec = t[0].tv_sec = file_header->mtime;
t[1].tv_usec = t[0].tv_usec = 0;
utimes(file_header->name, t);
utimes(dst_name, t);
}
}

View File

@ -112,8 +112,7 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
bb_copyfd_exact_size(archive_handle->src_fd, p[1], -file_header->size);
close(p[1]);
if (safe_waitpid(pid, &status, 0) == -1)
bb_perror_msg_and_die("waitpid");
status = wait_for_exitstatus(pid);
if (WIFEXITED(status) && WEXITSTATUS(status))
bb_error_msg_and_die("'%s' returned status %d",
archive_handle->tar__to_command, WEXITSTATUS(status));

View File

@ -305,11 +305,11 @@ static int huft_build(const unsigned *b, const unsigned n,
unsigned i; /* counter, current code */
unsigned j; /* counter */
int k; /* number of bits in current code */
unsigned *p; /* pointer into c[], b[], or v[] */
const unsigned *p; /* pointer into c[], b[], or v[] */
huft_t *q; /* points to current table */
huft_t r; /* table entry for structure assignment */
huft_t *u[BMAX]; /* table stack */
unsigned v[N_MAX]; /* values in order of bit length */
unsigned v[N_MAX + 1]; /* values in order of bit length. last v[] is never used */
int ws[BMAX + 1]; /* bits decoded stack */
int w; /* bits decoded */
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
@ -324,7 +324,7 @@ static int huft_build(const unsigned *b, const unsigned n,
/* Generate counts for each bit length */
memset(c, 0, sizeof(c));
p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */
p = b;
i = n;
do {
c[*p]++; /* assume all entries <= BMAX */
@ -364,8 +364,12 @@ static int huft_build(const unsigned *b, const unsigned n,
*xp++ = j;
}
/* Make a table of values in order of bit lengths */
p = (unsigned *) b;
/* Make a table of values in order of bit lengths.
* To detect bad input, unused v[i]'s are set to invalid value UINT_MAX.
* In particular, last v[i] is never filled and must not be accessed.
*/
memset(v, 0xff, sizeof(v));
p = b;
i = 0;
do {
j = *p++;
@ -432,7 +436,9 @@ static int huft_build(const unsigned *b, const unsigned n,
/* set up table entry in r */
r.b = (unsigned char) (k - w);
if (p >= v + n) {
if (/*p >= v + n || -- redundant, caught by the second check: */
*p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/
) {
r.e = 99; /* out of values--invalid code */
} else if (*p < s) {
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
@ -517,8 +523,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
e = t->e;
if (e > 16)
do {
if (e == 99)
abort_unzip(PASS_STATE_ONLY);;
if (e == 99) {
abort_unzip(PASS_STATE_ONLY);
}
bb >>= t->b;
k -= t->b;
e -= 16;
@ -554,8 +561,9 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
e = t->e;
if (e > 16)
do {
if (e == 99)
if (e == 99) {
abort_unzip(PASS_STATE_ONLY);
}
bb >>= t->b;
k -= t->b;
e -= 16;
@ -821,8 +829,9 @@ static int inflate_block(STATE_PARAM smallint *e)
b_dynamic >>= 4;
k_dynamic -= 4;
if (nl > 286 || nd > 30)
if (nl > 286 || nd > 30) {
abort_unzip(PASS_STATE_ONLY); /* bad lengths */
}
/* read in bit-length-code lengths */
for (j = 0; j < nb; j++) {
@ -903,12 +912,14 @@ static int inflate_block(STATE_PARAM smallint *e)
bl = lbits;
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
if (i != 0)
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
bd = dbits;
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
if (i != 0)
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
/* set up data for inflate_codes() */
inflate_codes_setup(PASS_STATE bl, bd);
@ -996,6 +1007,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
error_msg = "corrupted data";
if (setjmp(error_jmp)) {
/* Error from deep inside zip machinery */
bb_error_msg(error_msg);
n = -1;
goto ret;
}
@ -1118,9 +1130,8 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
uint8_t os_flags_UNUSED;
} PACKED formatted;
} header;
struct BUG_header {
char BUG_header[sizeof(header) == 8 ? 1 : -1];
};
BUILD_BUG_ON(sizeof(header) != 8);
/*
* Rewind bytebuffer. We use the beginning because the header has 8
@ -1190,7 +1201,7 @@ unpack_gz_stream(transformer_state_t *xstate)
if (check_signature16(xstate, GZIP_MAGIC))
return -1;
#else
if (xstate->check_signature) {
if (!xstate->signature_skipped) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
@ -1199,7 +1210,7 @@ unpack_gz_stream(transformer_state_t *xstate)
return -1;
}
if (magic2 == COMPRESS_MAGIC) {
xstate->check_signature = 0;
xstate->signature_skipped = 2;
return unpack_Z_stream(xstate);
}
if (magic2 != GZIP_MAGIC)

View File

@ -55,7 +55,7 @@ unpack_xz_stream(transformer_state_t *xstate)
iobuf.out = membuf + BUFSIZ;
iobuf.out_size = BUFSIZ;
if (!xstate || xstate->check_signature == 0) {
if (!xstate || xstate->signature_skipped) {
/* Preload XZ file signature */
strcpy((char*)membuf, HEADER_MAGIC);
iobuf.in_size = HEADER_MAGIC_SIZE;

View File

@ -52,6 +52,11 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
&major, &minor, &namesize) != 10)
bb_error_msg_and_die("damaged cpio file");
file_header->mode = mode;
/* "cpio -R USER:GRP" support: */
if (archive_handle->cpio__owner.uid != (uid_t)-1L)
uid = archive_handle->cpio__owner.uid;
if (archive_handle->cpio__owner.gid != (gid_t)-1L)
gid = archive_handle->cpio__owner.gid;
file_header->uid = uid;
file_header->gid = gid;
file_header->mtime = mtime;
@ -75,7 +80,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
/* Update offset amount and skip padding before file contents */
data_align(archive_handle, 4);
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
if (strcmp(file_header->name, cpio_TRAILER) == 0) {
/* Always round up. ">> 9" divides by 512 */
archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9;
goto create_hardlinks;

View File

@ -60,13 +60,21 @@ static unsigned long long getOctal(char *str, int len)
}
#define GET_OCTAL(a) getOctal((a), sizeof(a))
#define TAR_EXTD (ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX)
#if !TAR_EXTD
#define process_pax_hdr(archive_handle, sz, global) \
process_pax_hdr(archive_handle, sz)
#endif
/* "global" is 0 or 1 */
static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global)
{
#if !TAR_EXTD
unsigned blk_sz = (sz + 511) & (~511);
seek_by_read(archive_handle->src_fd, blk_sz);
#else
unsigned blk_sz = (sz + 511) & (~511);
char *buf, *p;
unsigned blk_sz;
blk_sz = (sz + 511) & (~511);
p = buf = xmalloc(blk_sz + 1);
xread(archive_handle->src_fd, buf, blk_sz);
archive_handle->offset += blk_sz;
@ -104,30 +112,31 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
p[-1] = '\0';
value = end + 1;
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (!global && is_prefixed_with(value, "path=")) {
value += sizeof("path=") - 1;
free(archive_handle->tar__longname);
archive_handle->tar__longname = xstrdup(value);
continue;
}
#endif
# endif
#if ENABLE_FEATURE_TAR_SELINUX
# if ENABLE_FEATURE_TAR_SELINUX
/* Scan for SELinux contexts, via "RHT.security.selinux" keyword.
* This is what Red Hat's patched version of tar uses.
*/
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
free(archive_handle->tar__sctx[global]);
archive_handle->tar__sctx[global] = xstrdup(value);
continue;
}
#endif
# endif
}
free(buf);
#endif
}
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
@ -418,6 +427,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* Everything up to and including last ".." component is stripped */
overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
//TODO: do the same for file_header->link_target?
/* Strip trailing '/' in directories */
/* Must be done after mode is set as '/' is used to check if it's a directory */

View File

@ -13,16 +13,13 @@ void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
{
if (xstate->check_signature) {
if (!xstate->signature_skipped) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
bb_error_msg("invalid magic");
#if 0 /* possible future extension */
if (xstate->check_signature > 1)
xfunc_die();
#endif
return -1;
}
xstate->signature_skipped = 2;
}
return 0;
}
@ -102,7 +99,7 @@ void check_errors_in_children(int signo)
/* transformer(), more than meets the eye */
#if BB_MMU
void FAST_FUNC fork_transformer(int fd,
int check_signature,
int signature_skipped,
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
)
#else
@ -123,7 +120,7 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
IF_DESKTOP(long long) int r;
transformer_state_t xstate;
init_transformer_state(&xstate);
xstate.check_signature = check_signature;
xstate.signature_skipped = signature_skipped;
xstate.src_fd = fd;
xstate.dst_fd = fd_pipe.wr;
r = transformer(&xstate);
@ -168,12 +165,11 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
uint16_t b16[2];
uint32_t b32[1];
} magic;
int offset;
transformer_state_t *xstate;
offset = -2;
xstate = xzalloc(sizeof(*xstate));
xstate->src_fd = fd;
xstate->signature_skipped = 2;
/* .gz and .bz2 both have 2-byte signature, and their
* unpack_XXX_stream wants this header skipped. */
@ -202,7 +198,7 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
if (ENABLE_FEATURE_SEAMLESS_XZ
&& magic.b16[0] == XZ_MAGIC1
) {
offset = -6;
xstate->signature_skipped = 6;
xread(fd, magic.b32, sizeof(magic.b32[0]));
if (magic.b32[0] == XZ_MAGIC2) {
xstate->xformer = unpack_xz_stream;
@ -224,18 +220,8 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
*/
// USE_FOR_MMU(xstate->xformer = copy_stream;)
// USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
/* fall through to seeking bck over bytes we read earlier */
USE_FOR_NOMMU(found_magic:)
/* NOMMU version of fork_transformer execs
* an external unzipper that wants
* file position at the start of the file.
*/
xlseek(fd, offset, SEEK_CUR);
USE_FOR_MMU(found_magic:)
/* In MMU case, if magic was found, seeking back is not necessary */
found_magic:
return xstate;
}
@ -254,6 +240,12 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
# else
/* NOMMU version of fork_transformer execs
* an external unzipper that wants
* file position at the start of the file.
*/
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
# endif
free(xstate);
@ -296,14 +288,22 @@ int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
return -1;
fd = xstate->src_fd;
if (xstate->xformer) {
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
# else
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
# endif
if (xstate->xformer) {
fork_transformer_with_no_sig(fd, xstate->xformer);
} else {
/* the file is not compressed */
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
}
/* else: the file is not compressed */
# else
/* NOMMU can't avoid the seek :( */
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
if (xstate->xformer) {
fork_transformer_with_sig(fd, xstate->xformer, xstate->xformer_prog);
} /* else: the file is not compressed */
# endif
free(xstate);
return fd;
@ -331,6 +331,9 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
}
} else {
/* File is not compressed */
//FIXME: avoid seek
xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
xstate->signature_skipped = 0;
image = xmalloc_read(xstate->src_fd, maxsz_p);
}

View File

@ -71,6 +71,7 @@
//usage: "\n -F Don't store or verify checksum"
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
#include "liblzo_interface.h"
@ -443,8 +444,8 @@ struct globals {
chksum_t chksum_in;
chksum_t chksum_out;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
//#define G (*ptr_to_globals)
//#define INIT_G() do {
// SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
@ -640,7 +641,7 @@ static int lzo_get_method(header_t *h)
/**********************************************************************/
// compress a file
/**********************************************************************/
static NOINLINE smallint lzo_compress(const header_t *h)
static NOINLINE int lzo_compress(const header_t *h)
{
unsigned block_size = LZO_BLOCK_SIZE;
int r = 0; /* LZO_E_OK */
@ -650,7 +651,6 @@ static NOINLINE smallint lzo_compress(const header_t *h)
uint32_t d_adler32 = ADLER32_INIT_VALUE;
uint32_t d_crc32 = CRC32_INIT_VALUE;
int l;
smallint ok = 1;
uint8_t *wrk_mem = NULL;
if (h->method == M_LZO1X_1)
@ -732,7 +732,7 @@ static NOINLINE smallint lzo_compress(const header_t *h)
free(wrk_mem);
free(b1);
free(b2);
return ok;
return 1;
}
static FAST_FUNC void lzo_check(
@ -753,7 +753,7 @@ static FAST_FUNC void lzo_check(
/**********************************************************************/
// decompress a file
/**********************************************************************/
static NOINLINE smallint lzo_decompress(const header_t *h)
static NOINLINE int lzo_decompress(const header_t *h)
{
unsigned block_size = LZO_BLOCK_SIZE;
int r;
@ -761,7 +761,6 @@ static NOINLINE smallint lzo_decompress(const header_t *h)
uint32_t c_adler32 = ADLER32_INIT_VALUE;
uint32_t d_adler32 = ADLER32_INIT_VALUE;
uint32_t c_crc32 = CRC32_INIT_VALUE, d_crc32 = CRC32_INIT_VALUE;
smallint ok = 1;
uint8_t *b1;
uint32_t mcs_block_size = MAX_COMPRESSED_SIZE(block_size);
uint8_t *b2 = NULL;
@ -865,7 +864,7 @@ static NOINLINE smallint lzo_decompress(const header_t *h)
}
free(b2);
return ok;
return 1;
}
/**********************************************************************/
@ -897,7 +896,7 @@ static NOINLINE smallint lzo_decompress(const header_t *h)
* chksum_out
* The rest is identical.
*/
static const unsigned char lzop_magic[9] = {
static const unsigned char lzop_magic[9] ALIGN1 = {
0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
};
@ -1050,7 +1049,7 @@ static void lzo_set_method(header_t *h)
h->level = level;
}
static smallint do_lzo_compress(void)
static int do_lzo_compress(void)
{
header_t header;
@ -1078,7 +1077,7 @@ static smallint do_lzo_compress(void)
/**********************************************************************/
// decompress
/**********************************************************************/
static smallint do_lzo_decompress(void)
static int do_lzo_decompress(void)
{
header_t header;

View File

@ -29,6 +29,7 @@
//usage: "\n -qpc List config files"
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
#include "rpm.h"
@ -93,8 +94,8 @@ struct globals {
rpm_index **mytags;
int tagcount;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
static void extract_cpio(int fd, const char *source_rpm)
{

View File

@ -146,18 +146,23 @@
#include <fnmatch.h>
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
/* FIXME: Stop using this non-standard feature */
#ifndef FNM_LEADING_DIR
# define FNM_LEADING_DIR 0
#endif
//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
#define DBG(...) ((void)0)
#if 0
# define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
#else
# define DBG(...) ((void)0)
#endif
#define DBG_OPTION_PARSING 0
#define block_buf bb_common_bufsiz1
#define INIT_G() do { setup_common_bufsiz(); } while (0)
#if ENABLE_FEATURE_TAR_CREATE
@ -855,6 +860,7 @@ enum {
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
OPTBIT_STRIP_COMPONENTS,
OPTBIT_NORECURSION,
IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,)
OPTBIT_NUMERIC_OWNER,
@ -879,12 +885,13 @@ enum {
OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J
OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
OPT_STRIP_COMPONENTS = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_STRIP_COMPONENTS)) + 0, // strip-components
OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS),
};
@ -928,6 +935,7 @@ static const char tar_longopts[] ALIGN1 =
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
"touch\0" No_argument "m"
# endif
"strip-components\0" Required_argument "\xf9"
"no-recursion\0" No_argument "\xfa"
# if ENABLE_FEATURE_TAR_TO_COMMAND
"to-command\0" Required_argument "\xfb"
@ -957,6 +965,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
llist_t *excludes = NULL;
#endif
INIT_G();
/* Initialise default values */
tar_handle = init_handle();
@ -973,15 +982,28 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
"tt:vv:" // count -t,-v
IF_FEATURE_TAR_FROM("X::T::") // cumulative lists
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
"\xff::" // cumulative lists for --exclude
"\xff::" // --exclude=PATTERN is a list
#endif
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
":\xf9+" // --strip-components=NUM
#endif
;
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
applet_long_options = tar_longopts;
#endif
#if ENABLE_DESKTOP
/* Lie to buildroot when it starts asking stupid questions. */
if (argv[1] && strcmp(argv[1], "--version") == 0) {
// Output of 'tar --version' examples:
// tar (GNU tar) 1.15.1
// tar (GNU tar) 1.25
// bsdtar 2.8.3 - libarchive 2.8.3
puts("tar (busybox) " BB_VER);
return 0;
}
if (argv[1] && argv[1][0] != '-') {
/* Compat:
* 1st argument without dash handles options with parameters
@ -1018,10 +1040,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_SEAMLESS_XZ( "J" )
IF_FEATURE_SEAMLESS_Z( "Z" )
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
, &base_dir // -C dir
, &tar_filename // -f filename
IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
, &tar_handle->tar__strip_components // --strip-components
#endif
IF_FEATURE_TAR_TO_COMMAND(, &(tar_handle->tar__to_command)) // --to-command
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
, &excludes // --exclude
@ -1029,11 +1055,49 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
, &verboseFlag // combined count for -t and -v
, &verboseFlag // combined count for -t and -v
);
//bb_error_msg("opt:%08x", opt);
#if DBG_OPTION_PARSING
bb_error_msg("opt: 0x%08x", opt);
# define showopt(o) bb_error_msg("opt & %s(%x): %x", #o, o, opt & o);
showopt(OPT_TEST );
showopt(OPT_EXTRACT );
showopt(OPT_BASEDIR );
showopt(OPT_TARNAME );
showopt(OPT_2STDOUT );
showopt(OPT_NOPRESERVE_OWNER);
showopt(OPT_P );
showopt(OPT_VERBOSE );
showopt(OPT_KEEP_OLD );
showopt(OPT_CREATE );
showopt(OPT_DEREFERENCE );
showopt(OPT_BZIP2 );
showopt(OPT_LZMA );
showopt(OPT_INCLUDE_FROM );
showopt(OPT_EXCLUDE_FROM );
showopt(OPT_GZIP );
showopt(OPT_XZ );
showopt(OPT_COMPRESS );
showopt(OPT_NOPRESERVE_TIME );
showopt(OPT_STRIP_COMPONENTS);
showopt(OPT_NORECURSION );
showopt(OPT_2COMMAND );
showopt(OPT_NUMERIC_OWNER );
showopt(OPT_NOPRESERVE_PERM );
showopt(OPT_OVERWRITE );
showopt(OPT_ANY_COMPRESS );
bb_error_msg("base_dir:'%s'", base_dir);
bb_error_msg("tar_filename:'%s'", tar_filename);
bb_error_msg("verboseFlag:%d", verboseFlag);
bb_error_msg("tar_handle->tar__to_command:'%s'", tar_handle->tar__to_command);
bb_error_msg("tar_handle->tar__strip_components:%u", tar_handle->tar__strip_components);
return 0;
# undef showopt
#endif
argv += optind;
if (verboseFlag) tar_handle->action_header = header_verbose_list;
if (verboseFlag == 1) tar_handle->action_header = header_list;
if (verboseFlag)
tar_handle->action_header = header_verbose_list;
if (verboseFlag == 1)
tar_handle->action_header = header_list;
if (opt & OPT_EXTRACT)
tar_handle->action_data = data_extract_all;
@ -1135,9 +1199,10 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
// signal(SIGCHLD, check_errors_in_children);
#if ENABLE_FEATURE_TAR_CREATE
/* Create an archive */
if (opt & OPT_CREATE) {
#if SEAMLESS_COMPRESSION
# if SEAMLESS_COMPRESSION
const char *zipMode = NULL;
if (opt & OPT_COMPRESS)
zipMode = "compress";
@ -1149,7 +1214,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
zipMode = "lzma";
if (opt & OPT_XZ)
zipMode = "xz";
#endif
# endif
/* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tar_handle->src_fd, verboseFlag,
(opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
@ -1157,6 +1222,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
tar_handle->accept,
tar_handle->reject, zipMode);
}
#endif
if (opt & OPT_ANY_COMPRESS) {
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)

View File

@ -45,6 +45,12 @@
#include "libbb.h"
#include "bb_archive.h"
#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
#else
# define dbg(...) ((void)0)
#endif
enum {
#if BB_BIG_ENDIAN
ZIP_FILEHEADER_MAGIC = 0x504b0304,
@ -193,15 +199,17 @@ static uint32_t find_cdf_offset(void)
unsigned char *p;
off_t end;
unsigned char *buf = xzalloc(PEEK_FROM_END);
uint32_t found;
end = xlseek(zip_fd, 0, SEEK_END);
end -= PEEK_FROM_END;
if (end < 0)
end = 0;
xlseek(zip_fd, end, SEEK_SET);
dbg("Looking for cdf_offset starting from 0x%"OFF_FMT"x", end);
xlseek(zip_fd, end, SEEK_SET);
full_read(zip_fd, buf, PEEK_FROM_END);
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
found = BAD_CDF_OFFSET;
p = buf;
while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) {
if (*p != 'P') {
@ -220,14 +228,25 @@ static uint32_t find_cdf_offset(void)
/*
* I've seen .ZIP files with seemingly valid CDEs
* where cdf_offset points past EOF - ??
* Ignore such CDEs:
* This check ignores such CDEs:
*/
if (cde_header.formatted.cdf_offset < end + (p - buf))
break;
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
if (cde_header.formatted.cdf_offset < end + (p - buf)) {
found = cde_header.formatted.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)));
/*
* We do not "break" here because only the last CDE is valid.
* I've seen a .zip archive which contained a .zip file,
* uncompressed, and taking the first CDE was using
* the CDE inside that file!
*/
}
}
free(buf);
return cde_header.formatted.cdf_offset;
dbg("Found cdf_offset:0x%x", (unsigned)found);
return found;
};
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
@ -240,15 +259,22 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
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("Returning file position to 0x%"OFF_FMT"x", org);
xlseek(zip_fd, org, SEEK_SET);
return cdf_offset;
};
@ -461,7 +487,7 @@ int unzip_main(int argc, char **argv)
if (overwrite == O_PROMPT)
overwrite = O_NEVER;
} else {
static const char extn[][5] = { ".zip", ".ZIP" };
static const char extn[][5] ALIGN1 = { ".zip", ".ZIP" };
char *ext = src_fn + strlen(src_fn);
int src_fd;
@ -488,11 +514,11 @@ int unzip_main(int argc, char **argv)
printf("Archive: %s\n", src_fn);
if (listing) {
puts(verbose ?
" Length Method Size Ratio Date Time CRC-32 Name\n"
"-------- ------ ------- ----- ---- ---- ------ ----"
" Length Method Size Cmpr Date Time CRC-32 Name\n"
"-------- ------ ------- ---- ---------- ----- -------- ----"
:
" Length Date Time Name\n"
" -------- ---- ---- ----"
" Length Date Time Name\n"
"--------- ---------- ----- ----"
);
}
}
@ -532,11 +558,14 @@ int unzip_main(int argc, char **argv)
/* Check magic number */
xread(zip_fd, &magic, 4);
/* Central directory? It's at the end, so exit */
if (magic == ZIP_CDF_MAGIC)
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;
@ -544,6 +573,7 @@ int unzip_main(int argc, char **argv)
#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);
@ -587,6 +617,11 @@ int unzip_main(int argc, char **argv)
bb_error_msg_and_die("can't find file table");
}
#endif
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
);
/* Read filename */
free(dst_fn);
@ -607,40 +642,55 @@ int unzip_main(int argc, char **argv)
} else {
if (listing) {
/* List entry */
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
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 %02u-%02u-%02u %02u:%02u %s\n",
// " Length Date Time Name\n"
// "--------- ---------- ----- ----"
printf( "%9u " "%s " "%s\n",
(unsigned)zip_header.formatted.ucmpsize,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
dtbuf,
dst_fn);
total_usize += zip_header.formatted.ucmpsize;
} 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 Ratio Date Time CRC-32 Name\n"
// "-------- ------ ------- ----- ---- ---- ------ ----"
printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n",
// " 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,
(dostime & 0x01e00000) >> 21,
(dostime & 0x001f0000) >> 16,
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
(dostime & 0x0000f800) >> 11,
(dostime & 0x000007e0) >> 5,
dtbuf,
zip_header.formatted.crc32,
dst_fn);
total_usize += zip_header.formatted.ucmpsize;
total_size += zip_header.formatted.cmpsize;
}
total_usize += zip_header.formatted.ucmpsize;
i = 'n';
} else if (dst_fd == STDOUT_FILENO) {
/* Extracting to STDOUT */
@ -743,21 +793,25 @@ int unzip_main(int argc, char **argv)
if (listing && quiet <= 1) {
if (!verbose) {
// " Length Date Time Name\n"
// " -------- ---- ---- ----"
printf( " -------- -------\n"
"%9lu" " %u files\n",
total_usize, total_entries);
// " Length Date Time Name\n"
// "--------- ---------- ----- ----"
printf( " --------%21s" "-------\n"
"%9lu%21s" "%u files\n",
"",
total_usize, "", total_entries);
} else {
unsigned long percents = total_usize - total_size;
if ((long)percents < 0)
percents = 0; /* happens if usize < size */
percents = percents * 100;
if (total_usize)
percents /= total_usize;
// " Length Method Size Ratio Date Time CRC-32 Name\n"
// "-------- ------ ------- ----- ---- ---- ------ ----"
printf( "-------- ------- --- -------\n"
"%8lu" "%17lu%4u%% %u files\n",
total_usize, total_size, (unsigned)percents,
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
// "-------- ------ ------- ---- ---------- ----- -------- ----"
printf( "-------- ------- ----%28s" "----\n"
"%8lu" "%17lu%4u%%%28s" "%u files\n",
"",
total_usize, total_size, (unsigned)percents, "",
total_entries);
}
}

View File

@ -390,7 +390,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_HALT=y
# CONFIG_FEATURE_CALL_TELINIT is not set
CONFIG_TELINIT_PATH=""

View File

@ -395,7 +395,7 @@ CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_FEATURE_INITRD is not set
# CONFIG_LINUXRC is not set
# CONFIG_HALT is not set
# CONFIG_FEATURE_CALL_TELINIT is not set
CONFIG_TELINIT_PATH=""

View File

@ -407,7 +407,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_HALT=y
# CONFIG_FEATURE_CALL_TELINIT is not set
CONFIG_TELINIT_PATH=""

View File

@ -89,7 +89,6 @@ CONFIG_PREFIX="./_install"
#
# Busybox Library Tuning
#
# CONFIG_FEATURE_SYSTEMD is not set
# CONFIG_FEATURE_RTMINMAX is not set
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
@ -426,7 +425,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
CONFIG_MESG=y
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y

File diff suppressed because it is too large Load Diff

View File

@ -107,7 +107,6 @@ CONFIG_PREFIX="./_install"
#
# Busybox Library Tuning
#
# CONFIG_FEATURE_SYSTEMD is not set
# CONFIG_FEATURE_RTMINMAX is not set
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
@ -449,7 +448,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
CONFIG_MESG=y
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y

View File

@ -96,7 +96,6 @@ CONFIG_PREFIX="./_install"
#
# Busybox Library Tuning
#
# CONFIG_FEATURE_SYSTEMD is not set
# CONFIG_FEATURE_RTMINMAX is not set
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
@ -459,7 +458,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_FEATURE_INITRD=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
CONFIG_MESG=y
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y

View File

@ -89,7 +89,6 @@ CONFIG_PREFIX="./_install"
#
# Busybox Library Tuning
#
# CONFIG_FEATURE_SYSTEMD is not set
CONFIG_FEATURE_RTMINMAX=y
CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
@ -426,7 +425,7 @@ CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_FEATURE_INITRD is not set
# CONFIG_LINUXRC is not set
CONFIG_INIT_TERMINAL_TYPE=""
CONFIG_MESG=y
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y

View File

@ -422,7 +422,7 @@ CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_FEATURE_INITRD is not set
# CONFIG_LINUXRC is not set
CONFIG_INIT_TERMINAL_TYPE=""
# CONFIG_MESG is not set

View File

@ -18,6 +18,7 @@
//usage: "$ dumpkmap > keymap\n"
#include "libbb.h"
#include "common_bufsiz.h"
/* From <linux/kd.h> */
struct kbentry {
@ -37,6 +38,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
struct kbentry ke;
int i, j, fd;
#define flags bb_common_bufsiz1
setup_common_bufsiz();
/* When user accidentally runs "dumpkmap FILE"
* instead of "dumpkmap >FILE", we'd dump binary stuff to tty.

View File

@ -14,10 +14,12 @@
//usage: "Resize the screen"
#include "libbb.h"
#include "common_bufsiz.h"
#define ESC "\033"
#define old_termios_p ((struct termios*)&bb_common_bufsiz1)
#define old_termios_p ((struct termios*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
static void
onintr(int sig UNUSED_PARAM)
@ -33,6 +35,8 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
struct winsize w = { 0, 0, 0, 0 };
int ret;
INIT_G();
/* We use _stderr_ in order to make resize usable
* in shell backticks (those redirect stdout away from tty).
* NB: other versions of resize open "/dev/tty"

View File

@ -543,22 +543,6 @@ config FEATURE_SPLIT_FANCY
Supports additional suffixes 'b' for 512 bytes,
'g' for 1GiB for the -b option.
config STAT
bool "stat"
default y
select PLATFORM_LINUX # statfs()
help
display file or filesystem status.
config FEATURE_STAT_FORMAT
bool "Enable custom formats (-c)"
default y
depends on STAT
help
Without this, stat will not support the '-c format' option where
users can pass a custom format string for output. This adds about
7k to a nonstatic build on amd64.
config STTY
bool "stty"
default y

View File

@ -19,6 +19,7 @@
//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)
@ -48,6 +49,9 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
/* 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) {
@ -57,7 +61,6 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
for (;;) {
int i, res;
#define read_buf bb_common_bufsiz1
res = read(fd, read_buf, COMMON_BUFSIZE);
if (res < 0)
retval = EXIT_FAILURE;

View File

@ -11,9 +11,9 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
//usage:#define chown_trivial_usage
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... OWNER[<.|:>[GROUP]] FILE..."
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... USER[:[GRP]] FILE..."
//usage:#define chown_full_usage "\n\n"
//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"
//usage: "Change the owner and/or group of each FILE to USER and/or GRP\n"
//usage: "\n -R Recurse"
//usage: "\n -h Affect symlinks instead of symlink targets"
//usage: IF_DESKTOP(
@ -112,10 +112,6 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
int opt, flags;
struct param_t param;
/* Just -1 might not work: uid_t may be unsigned long */
param.ugid.uid = -1L;
param.ugid.gid = -1L;
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
applet_long_options = chown_longopts;
#endif

View File

@ -13,6 +13,7 @@
//usage: "Calculate the CRC32 checksums of FILES"
#include "libbb.h"
#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
@ -32,6 +33,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
argv++;
#endif
setup_common_bufsiz();
do {
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
@ -43,7 +45,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
length = 0;
#define read_buf bb_common_bufsiz1
while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) {
while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) {
length += bytes_read;
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
}

View File

@ -31,6 +31,7 @@
//usage: "\n -f Overwrite"
//usage: "\n -i Prompt before overwrite"
//usage: "\n -l,-s Create (sym)links"
//usage: "\n -u Copy only newer files"
#include "libbb.h"
#include "libcoreutils/coreutils.h"
@ -49,12 +50,10 @@ int cp_main(int argc, char **argv)
int flags;
int status;
enum {
OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
FILEUTILS_CP_OPTNUM = sizeof(FILEUTILS_CP_OPTSTR)-1,
#if ENABLE_FEATURE_CP_LONG_OPTIONS
OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
/*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */
OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1),
#endif
};
@ -76,10 +75,12 @@ int cp_main(int argc, char **argv)
"recursive\0" No_argument "R"
"symbolic-link\0" No_argument "s"
"verbose\0" No_argument "v"
"parents\0" No_argument "\xff"
"update\0" No_argument "u"
"remove-destination\0" No_argument "\xff"
"parents\0" No_argument "\xfe"
;
#endif
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
/* Options of cp from GNU coreutils 6.10:
* -a, --archive
* -f, --force
@ -94,6 +95,11 @@ int cp_main(int argc, char **argv)
* -d same as --no-dereference --preserve=links
* -p same as --preserve=mode,ownership,timestamps
* -c same as --preserve=context
* -u, --update
* copy only when the SOURCE file is newer than the destination
* file or when the destination file is missing
* --remove-destination
* remove each existing destination file before attempting to open
* --parents
* use full source file name under DIRECTORY
* NOT SUPPORTED IN BBOX:
@ -106,8 +112,6 @@ int cp_main(int argc, char **argv)
* preserve attributes (default: mode,ownership,timestamps),
* if possible additional attributes: security context,links,all
* --no-preserve=ATTR_LIST
* --remove-destination
* remove each existing destination file before attempting to open
* --sparse=WHEN
* control creation of sparse files
* --strip-trailing-slashes
@ -118,9 +122,6 @@ int cp_main(int argc, char **argv)
* copy all SOURCE arguments into DIRECTORY
* -T, --no-target-directory
* treat DEST as a normal file
* -u, --update
* copy only when the SOURCE file is newer than the destination
* file or when the destination file is missing
* -x, --one-file-system
* stay on this file system
* -Z, --context=CONTEXT
@ -156,11 +157,16 @@ int cp_main(int argc, char **argv)
return EXIT_FAILURE;
#if ENABLE_FEATURE_CP_LONG_OPTIONS
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
// flags, FILEUTILS_RMDEST, OPT_parents);
if (flags & OPT_parents) {
if (!(d_flags & 2)) {
bb_error_msg_and_die("with --parents, the destination must be a directory");
}
}
if (flags & FILEUTILS_RMDEST) {
flags |= FILEUTILS_FORCE;
}
#endif
/* ...if neither is a directory... */

View File

@ -138,6 +138,7 @@
//usage: "Wed Apr 12 18:52:41 MDT 2000\n"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_DATE_NANO
# include <sys/syscall.h>
#endif
@ -368,6 +369,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
#endif
#define date_buf bb_common_bufsiz1
setup_common_bufsiz();
if (*fmt_dt2str == '\0') {
/* With no format string, just print a blank line */
date_buf[0] = '\0';
@ -377,7 +379,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
}
/* Generate output string */
strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);
strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time);
}
puts(date_buf);

View File

@ -55,7 +55,7 @@
//usage:#define dd_trivial_usage
//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n"
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync]")
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes]")
//usage:#define dd_full_usage "\n\n"
//usage: "Copy a file with converting and formatting\n"
//usage: "\n if=FILE Read from FILE instead of stdin"
@ -76,6 +76,7 @@
//usage: "\n conv=sync Pad blocks with zeros"
//usage: "\n conv=fsync Physically write data out before finishing"
//usage: "\n conv=swab Swap every pair of bytes"
//usage: "\n iflag=skip_bytes skip=N is in bytes"
//usage: )
//usage: IF_FEATURE_DD_STATUS(
//usage: "\n status=noxfer Suppress rate output"
@ -90,6 +91,7 @@
//usage: "4+0 records out\n"
#include "libbb.h"
#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
@ -107,8 +109,9 @@ struct globals {
#endif
int flags;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
} while (0)
@ -122,11 +125,15 @@ enum {
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of conv flags */
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 6,
FLAG_STATUS = 1 << 7,
FLAG_STATUS_NONE = 1 << 7,
FLAG_STATUS_NOXFER = 1 << 8,
/* start of input flags */
FLAG_IFLAG_SHIFT = 5,
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of input flags */
FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 7,
FLAG_STATUS = 1 << 8,
FLAG_STATUS_NONE = 1 << 9,
FLAG_STATUS_NOXFER = 1 << 10,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@ -203,18 +210,47 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
# define XATOU_SFX xatoul_sfx
#endif
#if ENABLE_FEATURE_DD_IBS_OBS
static int parse_comma_flags(char *val, const char *words, const char *error_in)
{
int flags = 0;
while (1) {
int n;
char *arg;
/* find ',', replace them with NUL so we can use val for
* index_in_strings() without copying.
* We rely on val being non-null, else strchr would fault.
*/
arg = strchr(val, ',');
if (arg)
*arg = '\0';
n = index_in_strings(words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg_to, val, error_in);
flags |= (1 << n);
if (!arg) /* no ',' left, so this was the last specifier */
break;
*arg = ','; /* to preserve ps listing */
val = arg + 1; /* skip this keyword and ',' */
}
return flags;
}
#endif
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dd_main(int argc UNUSED_PARAM, char **argv)
{
static const char keywords[] ALIGN1 =
"bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0")
#if ENABLE_FEATURE_DD_IBS_OBS
"ibs\0""obs\0""conv\0"
"ibs\0""obs\0""conv\0""iflag\0"
#endif
;
#if ENABLE_FEATURE_DD_IBS_OBS
static const char conv_words[] ALIGN1 =
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
static const char iflag_words[] ALIGN1 =
"skip_bytes\0";
#endif
#if ENABLE_FEATURE_DD_STATUS
static const char status_words[] ALIGN1 =
@ -232,6 +268,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
OP_ibs,
OP_obs,
OP_conv,
OP_iflag,
/* Must be in the same order as FLAG_XXX! */
OP_conv_notrunc = 0,
OP_conv_sync,
@ -251,6 +288,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
//ibm from ASCII to alternate EBCDIC
/* Partially implemented: */
//swab swap every pair of input bytes: will abort on non-even reads
OP_iflag_skip_bytes,
#endif
};
smallint exitcode = EXIT_FAILURE;
@ -315,24 +353,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
/*continue;*/
}
if (what == OP_conv) {
while (1) {
int n;
/* find ',', replace them with NUL so we can use val for
* index_in_strings() without copying.
* We rely on val being non-null, else strchr would fault.
*/
arg = strchr(val, ',');
if (arg)
*arg = '\0';
n = index_in_strings(conv_words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
G.flags |= (1 << n);
if (!arg) /* no ',' left, so this was the last specifier */
break;
/* *arg = ','; - to preserve ps listing? */
val = arg + 1; /* skip this keyword and ',' */
}
G.flags |= parse_comma_flags(val, conv_words, "conv");
/*continue;*/
}
if (what == OP_iflag) {
G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT;
/*continue;*/
}
#endif
@ -368,7 +393,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
int n;
n = index_in_strings(status_words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg, val, "status");
bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status");
G.flags |= FLAG_STATUS << n;
/*continue;*/
}
@ -421,9 +446,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
outfile = bb_msg_standard_output;
}
if (skip) {
if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
do {
ssize_t n = safe_read(ifd, ibuf, ibs);
ssize_t n = safe_read(ifd, ibuf, blocksz);
if (n < 0)
goto die_infile;
if (n == 0)

View File

@ -41,7 +41,7 @@ enum {
static void convert(char *fn, int conv_type)
{
FILE *in, *out;
int i;
int ch;
char *temp_fn = temp_fn; /* for compiler */
char *resolved_fn = resolved_fn;
@ -49,28 +49,30 @@ static void convert(char *fn, int conv_type)
out = stdout;
if (fn != NULL) {
struct stat st;
int fd;
resolved_fn = xmalloc_follow_symlinks(fn);
if (resolved_fn == NULL)
bb_simple_perror_msg_and_die(fn);
in = xfopen_for_read(resolved_fn);
fstat(fileno(in), &st);
xfstat(fileno(in), &st, resolved_fn);
temp_fn = xasprintf("%sXXXXXX", resolved_fn);
i = xmkstemp(temp_fn);
if (fchmod(i, st.st_mode) == -1)
fd = xmkstemp(temp_fn);
if (fchmod(fd, st.st_mode) == -1)
bb_simple_perror_msg_and_die(temp_fn);
fchown(fd, st.st_uid, st.st_gid);
out = xfdopen_for_write(i);
out = xfdopen_for_write(fd);
}
while ((i = fgetc(in)) != EOF) {
if (i == '\r')
while ((ch = fgetc(in)) != EOF) {
if (ch == '\r')
continue;
if (i == '\n')
if (ch == '\n')
if (conv_type == CT_UNIX2DOS)
fputc('\r', out);
fputc(i, out);
fputc(ch, out);
}
if (fn != NULL) {

View File

@ -58,6 +58,7 @@
//usage: "2417 .\n"
#include "libbb.h"
#include "common_bufsiz.h"
enum {
OPT_a_files_too = (1 << 0),
@ -75,7 +76,7 @@ enum {
struct globals {
#if ENABLE_FEATURE_HUMAN_READABLE
unsigned long disp_hr;
unsigned long disp_unit;
#else
unsigned disp_k;
#endif
@ -85,22 +86,31 @@ struct globals {
int du_depth;
dev_t dir_dev;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
/* FIXME? coreutils' du rounds sizes up:
* for example, 1025k file is shown as "2" by du -m.
* We round to nearest.
*/
static void print(unsigned long long size, const char *filename)
{
/* TODO - May not want to defer error checking here. */
#if ENABLE_FEATURE_HUMAN_READABLE
# if ENABLE_DESKTOP
/* ~30 bytes of code for extra comtat:
* coreutils' du rounds sizes up:
* for example, 1025k file is shown as "2" by du -m.
* We round to nearest if human-readable [too hard to fix],
* else (fixed scale such as -m), we round up. To that end,
* add yet another half of the unit before displaying:
*/
if (G.disp_unit)
size += (G.disp_unit-1) / (unsigned)(512 * 2);
# endif
printf("%s\t%s\n",
/* size x 512 / G.disp_hr, show one fractional,
* use suffixes if G.disp_hr == 0 */
make_human_readable_str(size, 512, G.disp_hr),
/* size x 512 / G.disp_unit.
* If G.disp_unit == 0, show one fractional
* and use suffixes
*/
make_human_readable_str(size, 512, G.disp_unit),
filename);
#else
if (G.disp_k) {
@ -199,10 +209,10 @@ int du_main(int argc UNUSED_PARAM, char **argv)
INIT_G();
#if ENABLE_FEATURE_HUMAN_READABLE
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 1024;)
IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 512;)
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
G.disp_hr = 512;
G.disp_unit = 512;
#else
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;)
/* IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
@ -220,13 +230,13 @@ int du_main(int argc UNUSED_PARAM, char **argv)
opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth);
argv += optind;
if (opt & OPT_h_for_humans) {
G.disp_hr = 0;
G.disp_unit = 0;
}
if (opt & OPT_m_mbytes) {
G.disp_hr = 1024*1024;
G.disp_unit = 1024*1024;
}
if (opt & OPT_k_kbytes) {
G.disp_hr = 1024;
G.disp_unit = 1024;
}
#else
opt_complementary = "H-L:L-H:s-d:d-s:d+";

View File

@ -61,6 +61,7 @@
//usage: "of characters matched or 0."
#include "libbb.h"
#include "common_bufsiz.h"
#include "xregex.h"
#if ENABLE_EXPR_MATH_SUPPORT_64
@ -99,8 +100,8 @@ typedef struct valinfo VALUE;
struct globals {
char **args;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
/* forward declarations */
static VALUE *eval(void);

View File

@ -93,6 +93,7 @@
//usage: )
#include "libbb.h"
#include "common_bufsiz.h"
#include "unicode.h"
@ -365,8 +366,9 @@ struct globals {
time_t current_time_t;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
IF_FEATURE_AUTOWIDTH(G_terminal_width = TERMINAL_WIDTH;) \
@ -668,7 +670,7 @@ static void display_files(struct dnode **dn, unsigned nfiles)
if (column_width < len)
column_width = len;
}
column_width += 1 +
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);
@ -696,8 +698,8 @@ static void display_files(struct dnode **dn, unsigned nfiles)
if (i < nfiles) {
if (column > 0) {
nexttab -= column;
printf("%*s ", nexttab, "");
column += nexttab + 1;
printf("%*s", nexttab, "");
column += nexttab;
}
nexttab = column + column_width;
column += display_single(dn[i]);
@ -1105,7 +1107,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_AUTOWIDTH
/* obtain the terminal width */
get_terminal_width_height(STDIN_FILENO, &G_terminal_width, NULL);
G_terminal_width = get_terminal_width(STDIN_FILENO);
/* go one less... */
G_terminal_width--;
#endif

View File

@ -20,6 +20,7 @@
/* #include "libbb.h" - done in od.c */
#include "common_bufsiz.h"
#define assert(a) ((void)0)
@ -66,7 +67,7 @@ enum {
/* -S was -s and also had optional parameter */ \
/* but in coreutils 6.3 it was renamed and now has */ \
/* _mandatory_ parameter */ \
&str_A, &str_N, &str_j, &lst_t, &str_S, &bytes_per_block)
&str_A, &str_N, &str_j, &lst_t, &str_S, &G.bytes_per_block)
/* Check for 0x7f is a coreutils 6.3 addition */
@ -174,38 +175,53 @@ struct ERR_width_bytes_has_bad_size {
char ERR_width_bytes_has_bad_size[ARRAY_SIZE(width_bytes) == N_SIZE_SPECS ? 1 : -1];
};
static smallint exit_code;
struct globals {
smallint exit_code;
static unsigned string_min;
unsigned string_min;
/* An array of specs describing how to format each input block. */
static size_t n_specs;
static struct tspec *spec;
/* An array of specs describing how to format each input block. */
unsigned n_specs;
struct tspec *spec;
/* Function that accepts an address and an optional following char,
and prints the address and char to stdout. */
static void (*format_address)(off_t, char);
/* The difference between the old-style pseudo starting address and
the number of bytes to skip. */
/* Function that accepts an address and an optional following char,
and prints the address and char to stdout. */
void (*format_address)(off_t, char);
/* The difference between the old-style pseudo starting address and
the number of bytes to skip. */
#if ENABLE_LONG_OPTS
static off_t pseudo_offset;
#else
enum { pseudo_offset = 0 };
off_t pseudo_offset;
# define G_pseudo_offset G.pseudo_offset
#endif
/* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all
input is formatted. */
/* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all
input is formatted. */
/* The number of input bytes formatted per output line. It must be
a multiple of the least common multiple of the sizes associated with
the specified output types. It should be as large as possible, but
no larger than 16 -- unless specified with the -w option. */
static unsigned bytes_per_block = 32; /* have to use unsigned, not size_t */
/* The number of input bytes formatted per output line. It must be
a multiple of the least common multiple of the sizes associated with
the specified output types. It should be as large as possible, but
no larger than 16 -- unless specified with the -w option. */
unsigned bytes_per_block; /* have to use unsigned, not size_t */
/* A NULL-terminated list of the file-arguments from the command line. */
static const char *const *file_list;
/* A NULL-terminated list of the file-arguments from the command line. */
const char *const *file_list;
/* The input stream associated with the current file. */
FILE *in_stream;
bool not_first;
bool prev_pair_equal;
} FIX_ALIASING;
#if !ENABLE_LONG_OPTS
enum { G_pseudo_offset = 0 };
#endif
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
G.bytes_per_block = 32; \
} while (0)
/* The input stream associated with the current file. */
static FILE *in_stream;
#define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t)
static const unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = {
@ -476,17 +492,17 @@ static void
open_next_file(void)
{
while (1) {
if (!*file_list)
if (!*G.file_list)
return;
in_stream = fopen_or_warn_stdin(*file_list++);
if (in_stream) {
G.in_stream = fopen_or_warn_stdin(*G.file_list++);
if (G.in_stream) {
break;
}
exit_code = 1;
G.exit_code = 1;
}
if ((option_mask32 & (OPT_N|OPT_S)) == OPT_N)
setbuf(in_stream, NULL);
setbuf(G.in_stream, NULL);
}
/* Test whether there have been errors on in_stream, and close it if
@ -499,16 +515,16 @@ open_next_file(void)
static void
check_and_close(void)
{
if (in_stream) {
if (ferror(in_stream)) {
bb_error_msg("%s: read error", (in_stream == stdin)
if (G.in_stream) {
if (ferror(G.in_stream)) {
bb_error_msg("%s: read error", (G.in_stream == stdin)
? bb_msg_standard_input
: file_list[-1]
: G.file_list[-1]
);
exit_code = 1;
G.exit_code = 1;
}
fclose_if_not_stdin(in_stream);
in_stream = NULL;
fclose_if_not_stdin(G.in_stream);
G.in_stream = NULL;
}
if (ferror(stdout)) {
@ -744,9 +760,9 @@ decode_format_string(const char *s)
assert(s != next);
s = next;
spec = xrealloc_vector(spec, 4, n_specs);
memcpy(&spec[n_specs], &tspec, sizeof(spec[0]));
n_specs++;
G.spec = xrealloc_vector(G.spec, 4, G.n_specs);
memcpy(&G.spec[G.n_specs], &tspec, sizeof(G.spec[0]));
G.n_specs++;
}
}
@ -763,7 +779,7 @@ skip(off_t n_skip)
if (n_skip == 0)
return;
while (in_stream) { /* !EOF */
while (G.in_stream) { /* !EOF */
struct stat file_stats;
/* First try seeking. For large offsets, this extra work is
@ -781,15 +797,15 @@ skip(off_t n_skip)
If the number of bytes left to skip is at least
as large as the size of the current file, we can
decrement n_skip and go on to the next file. */
if (fstat(fileno(in_stream), &file_stats) == 0
if (fstat(fileno(G.in_stream), &file_stats) == 0
&& S_ISREG(file_stats.st_mode) && file_stats.st_size > 0
) {
if (file_stats.st_size < n_skip) {
n_skip -= file_stats.st_size;
/* take "check & close / open_next" route */
} else {
if (fseeko(in_stream, n_skip, SEEK_CUR) != 0)
exit_code = 1;
if (fseeko(G.in_stream, n_skip, SEEK_CUR) != 0)
G.exit_code = 1;
return;
}
} else {
@ -802,7 +818,7 @@ skip(off_t n_skip)
while (n_skip > 0) {
if (n_skip < n_bytes_to_read)
n_bytes_to_read = n_skip;
n_bytes_read = fread(buf, 1, n_bytes_to_read, in_stream);
n_bytes_read = fread(buf, 1, n_bytes_to_read, G.in_stream);
n_skip -= n_bytes_read;
if (n_bytes_read != n_bytes_to_read)
break; /* EOF on this file or error */
@ -855,7 +871,7 @@ static void
format_address_label(off_t address, char c)
{
format_address_std(address, ' ');
format_address_paren(address + pseudo_offset, c);
format_address_paren(address + G_pseudo_offset, c);
}
#endif
@ -886,36 +902,34 @@ static void
write_block(off_t current_offset, size_t n_bytes,
const char *prev_block, const char *curr_block)
{
static char first = 1;
static char prev_pair_equal = 0;
size_t i;
unsigned i;
if (!(option_mask32 & OPT_v)
&& !first
&& n_bytes == bytes_per_block
&& memcmp(prev_block, curr_block, bytes_per_block) == 0
&& G.not_first
&& n_bytes == G.bytes_per_block
&& memcmp(prev_block, curr_block, G.bytes_per_block) == 0
) {
if (prev_pair_equal) {
if (G.prev_pair_equal) {
/* The two preceding blocks were equal, and the current
block is the same as the last one, so print nothing. */
} else {
puts("*");
prev_pair_equal = 1;
G.prev_pair_equal = 1;
}
} else {
first = 0;
prev_pair_equal = 0;
for (i = 0; i < n_specs; i++) {
G.not_first = 1;
G.prev_pair_equal = 0;
for (i = 0; i < G.n_specs; i++) {
if (i == 0)
format_address(current_offset, '\0');
G.format_address(current_offset, '\0');
else
printf("%*s", address_pad_len_char - '0', "");
(*spec[i].print_function) (n_bytes, curr_block, spec[i].fmt_string);
if (spec[i].hexl_mode_trailer) {
(*G.spec[i].print_function) (n_bytes, curr_block, G.spec[i].fmt_string);
if (G.spec[i].hexl_mode_trailer) {
/* space-pad out to full line width, then dump the trailer */
unsigned datum_width = width_bytes[spec[i].size];
unsigned blank_fields = (bytes_per_block - n_bytes) / datum_width;
unsigned field_width = spec[i].field_width + 1;
unsigned datum_width = width_bytes[G.spec[i].size];
unsigned blank_fields = (G.bytes_per_block - n_bytes) / datum_width;
unsigned field_width = G.spec[i].field_width + 1;
printf("%*s", blank_fields * field_width, "");
dump_hexl_mode_trailer(n_bytes, curr_block);
}
@ -927,19 +941,19 @@ write_block(off_t current_offset, size_t n_bytes,
static void
read_block(size_t n, char *block, size_t *n_bytes_in_buffer)
{
assert(0 < n && n <= bytes_per_block);
assert(0 < n && n <= G.bytes_per_block);
*n_bytes_in_buffer = 0;
if (n == 0)
return;
while (in_stream != NULL) { /* EOF. */
while (G.in_stream != NULL) { /* EOF. */
size_t n_needed;
size_t n_read;
n_needed = n - *n_bytes_in_buffer;
n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, in_stream);
n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, G.in_stream);
*n_bytes_in_buffer += n_read;
if (n_read == n_needed)
break;
@ -958,8 +972,8 @@ get_lcm(void)
size_t i;
int l_c_m = 1;
for (i = 0; i < n_specs; i++)
l_c_m = lcm(l_c_m, width_bytes[(int) spec[i].size]);
for (i = 0; i < G.n_specs; i++)
l_c_m = lcm(l_c_m, width_bytes[(int) G.spec[i].size]);
return l_c_m;
}
@ -980,8 +994,8 @@ dump(off_t current_offset, off_t end_offset)
int idx;
size_t n_bytes_read;
block[0] = xmalloc(2 * bytes_per_block);
block[1] = block[0] + bytes_per_block;
block[0] = xmalloc(2 * G.bytes_per_block);
block[1] = block[0] + G.bytes_per_block;
idx = 0;
if (option_mask32 & OPT_N) {
@ -991,21 +1005,21 @@ dump(off_t current_offset, off_t end_offset)
n_bytes_read = 0;
break;
}
n_needed = MIN(end_offset - current_offset, (off_t) bytes_per_block);
n_needed = MIN(end_offset - current_offset, (off_t) G.bytes_per_block);
read_block(n_needed, block[idx], &n_bytes_read);
if (n_bytes_read < bytes_per_block)
if (n_bytes_read < G.bytes_per_block)
break;
assert(n_bytes_read == bytes_per_block);
assert(n_bytes_read == G.bytes_per_block);
write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]);
current_offset += n_bytes_read;
idx ^= 1;
}
} else {
while (1) {
read_block(bytes_per_block, block[idx], &n_bytes_read);
if (n_bytes_read < bytes_per_block)
read_block(G.bytes_per_block, block[idx], &n_bytes_read);
if (n_bytes_read < G.bytes_per_block)
break;
assert(n_bytes_read == bytes_per_block);
assert(n_bytes_read == G.bytes_per_block);
write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]);
current_offset += n_bytes_read;
idx ^= 1;
@ -1028,7 +1042,7 @@ dump(off_t current_offset, off_t end_offset)
current_offset += n_bytes_read;
}
format_address(current_offset, '\n');
G.format_address(current_offset, '\n');
if ((option_mask32 & OPT_N) && current_offset >= end_offset)
check_and_close();
@ -1059,16 +1073,16 @@ dump(off_t current_offset, off_t end_offset)
static void
dump_strings(off_t address, off_t end_offset)
{
unsigned bufsize = MAX(100, string_min);
unsigned bufsize = MAX(100, G.string_min);
unsigned char *buf = xmalloc(bufsize);
while (1) {
size_t i;
int c;
/* See if the next 'string_min' chars are all printing chars. */
/* See if the next 'G.string_min' chars are all printing chars. */
tryline:
if ((option_mask32 & OPT_N) && (end_offset - string_min <= address))
if ((option_mask32 & OPT_N) && (end_offset - G.string_min <= address))
break;
i = 0;
while (!(option_mask32 & OPT_N) || address < end_offset) {
@ -1077,8 +1091,8 @@ dump_strings(off_t address, off_t end_offset)
buf = xrealloc(buf, bufsize);
}
while (in_stream) { /* !EOF */
c = fgetc(in_stream);
while (G.in_stream) { /* !EOF */
c = fgetc(G.in_stream);
if (c != EOF)
goto got_char;
check_and_close();
@ -1095,12 +1109,12 @@ dump_strings(off_t address, off_t end_offset)
buf[i++] = c; /* String continues; store it all. */
}
if (i < string_min) /* Too short! */
if (i < G.string_min) /* Too short! */
goto tryline;
/* If we get here, the string is all printable and NUL-terminated */
buf[i] = 0;
format_address(address - i - 1, ' ');
G.format_address(address - i - 1, ' ');
for (i = 0; (c = buf[i]); i++) {
switch (c) {
@ -1118,7 +1132,7 @@ dump_strings(off_t address, off_t end_offset)
}
/* We reach this point only if we search through
(max_bytes_to_format - string_min) bytes before reaching EOF. */
(max_bytes_to_format - G.string_min) bytes before reaching EOF. */
check_and_close();
ret:
free(buf);
@ -1190,8 +1204,10 @@ int od_main(int argc UNUSED_PARAM, char **argv)
/* The maximum number of bytes that will be formatted. */
off_t max_bytes_to_format = 0;
spec = NULL;
format_address = format_address_std;
INIT_G();
/*G.spec = NULL; - already is */
G.format_address = format_address_std;
address_base_char = 'o';
address_pad_len_char = '7';
@ -1217,7 +1233,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
bb_error_msg_and_die("bad output address radix "
"'%c' (must be [doxn])", str_A[0]);
pos = p - doxn;
if (pos == 3) format_address = format_address_none;
if (pos == 3) G.format_address = format_address_none;
address_base_char = doxn_address_base_char[pos];
address_pad_len_char = doxn_address_pad_len_char[pos];
}
@ -1240,11 +1256,11 @@ int od_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_x) decode_format_string("x2");
if (opt & OPT_s) decode_format_string("d2");
if (opt & OPT_S) {
string_min = xstrtou_sfx(str_S, 0, bkm_suffixes);
G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes);
}
// Bloat:
//if ((option_mask32 & OPT_S) && n_specs > 0)
//if ((option_mask32 & OPT_S) && G.n_specs > 0)
// bb_error_msg_and_die("no type may be specified when dumping strings");
/* If the --traditional option is used, there may be from
@ -1300,14 +1316,14 @@ int od_main(int argc UNUSED_PARAM, char **argv)
}
if (pseudo_start >= 0) {
if (format_address == format_address_none) {
if (G.format_address == format_address_none) {
address_base_char = 'o';
address_pad_len_char = '7';
format_address = format_address_paren;
G.format_address = format_address_paren;
} else {
format_address = format_address_label;
G.format_address = format_address_label;
}
pseudo_offset = pseudo_start - n_bytes_to_skip;
G_pseudo_offset = pseudo_start - n_bytes_to_skip;
}
}
/* else: od --traditional (without args) */
@ -1320,45 +1336,45 @@ int od_main(int argc UNUSED_PARAM, char **argv)
bb_error_msg_and_die("SKIP + SIZE is too large");
}
if (n_specs == 0) {
if (G.n_specs == 0) {
decode_format_string("o2");
/*n_specs = 1; - done by decode_format_string */
/*G.n_specs = 1; - done by decode_format_string */
}
/* If no files were listed on the command line,
set the global pointer FILE_LIST so that it
references the null-terminated list of one name: "-". */
file_list = bb_argv_dash;
G.file_list = bb_argv_dash;
if (argv[0]) {
/* Set the global pointer FILE_LIST so that it
references the first file-argument on the command-line. */
file_list = (char const *const *) argv;
G.file_list = (char const *const *) argv;
}
/* Open the first input file */
open_next_file();
/* Skip over any unwanted header bytes */
skip(n_bytes_to_skip);
if (!in_stream)
if (!G.in_stream)
return EXIT_FAILURE;
/* Compute output block length */
l_c_m = get_lcm();
if (opt & OPT_w) { /* -w: width */
if (!bytes_per_block || bytes_per_block % l_c_m != 0) {
if (!G.bytes_per_block || G.bytes_per_block % l_c_m != 0) {
bb_error_msg("warning: invalid width %u; using %d instead",
(unsigned)bytes_per_block, l_c_m);
bytes_per_block = l_c_m;
(unsigned)G.bytes_per_block, l_c_m);
G.bytes_per_block = l_c_m;
}
} else {
bytes_per_block = l_c_m;
G.bytes_per_block = l_c_m;
if (l_c_m < DEFAULT_BYTES_PER_BLOCK)
bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m;
G.bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m;
}
#ifdef DEBUG
for (i = 0; i < n_specs; i++) {
for (i = 0; i < G.n_specs; i++) {
printf("%d: fmt=\"%s\" width=%d\n",
i, spec[i].fmt_string, width_bytes[spec[i].size]);
}
@ -1372,5 +1388,5 @@ int od_main(int argc UNUSED_PARAM, char **argv)
if (fclose(stdin))
bb_perror_msg_and_die(bb_msg_standard_input);
return exit_code;
return G.exit_code;
}

View File

@ -131,8 +131,8 @@ static double my_xstrtod(const char *arg)
return result;
}
/* Handles %b */
static void print_esc_string(const char *str)
/* Handles %b; return 1 if output is to be short-circuited by \c */
static int print_esc_string(const char *str)
{
char c;
while ((c = *str) != '\0') {
@ -145,6 +145,9 @@ static void print_esc_string(const char *str)
str++;
}
}
else if (*str == 'c') {
return 1;
}
{
/* optimization: don't force arg to be on-stack,
* use another variable for that. */
@ -155,6 +158,8 @@ static void print_esc_string(const char *str)
}
putchar(c);
}
return 0;
}
static void print_direc(char *format, unsigned fmt_length,
@ -280,7 +285,8 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
}
if (*f == 'b') {
if (*argv) {
print_esc_string(*argv);
if (print_esc_string(*argv))
return saved_argv; /* causes main() to exit */
++argv;
}
break;

View File

@ -14,23 +14,23 @@
//usage:#define sort_trivial_usage
//usage: "[-nru"
//usage: IF_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR")
//usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR")
//usage: "] [FILE]..."
//usage:#define sort_full_usage "\n\n"
//usage: "Sort lines of text\n"
//usage: IF_FEATURE_SORT_BIG(
//usage: "\n -b Ignore leading blanks"
//usage: "\n -o FILE Output to FILE"
//usage: "\n -c Check whether input is sorted"
//usage: "\n -d Dictionary order (blank or alphanumeric only)"
//usage: "\n -b Ignore leading blanks"
//usage: "\n -f Ignore case"
//usage: "\n -g General numerical sort"
//usage: "\n -i Ignore unprintable characters"
//usage: "\n -d Dictionary order (blank or alphanumeric only)"
//usage: "\n -g General numerical sort"
//usage: "\n -M Sort month"
//usage: )
//-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G)
//usage: "\n -n Sort numbers"
//usage: IF_FEATURE_SORT_BIG(
//usage: "\n -o Output to file"
//usage: "\n -t CHAR Field separator"
//usage: "\n -k N[,M] Sort by Nth field"
//usage: )
@ -41,7 +41,10 @@
//usage: "\n -u Suppress duplicate lines"
//usage: IF_FEATURE_SORT_BIG(
//usage: "\n -z Lines are terminated by NUL, not newline"
//usage: "\n -mST Ignored for GNU compatibility")
////usage: "\n -m Ignored for GNU compatibility"
////usage: "\n -S BUFSZ Ignored for GNU compatibility"
////usage: "\n -T TMPDIR Ignored for GNU compatibility"
//usage: )
//usage:
//usage:#define sort_example_usage
//usage: "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n"
@ -106,7 +109,9 @@ static struct sort_key {
static char *get_key(char *str, struct sort_key *key, int flags)
{
int start = 0, end = 0, len, j;
int start = start; /* for compiler */
int end;
int len, j;
unsigned i;
/* Special case whole string, so we don't have to make a copy */
@ -123,12 +128,15 @@ static char *get_key(char *str, struct sort_key *key, int flags)
end = len;
/* Loop through fields */
else {
unsigned char ch = 0;
end = 0;
for (i = 1; i < key->range[2*j] + j; i++) {
if (key_separator) {
/* Skip body of key and separator */
while (str[end]) {
if (str[end++] == key_separator)
while ((ch = str[end]) != '\0') {
end++;
if (ch == key_separator)
break;
}
} else {
@ -136,7 +144,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
while (isspace(str[end]))
end++;
/* Skip body of key */
while (str[end]) {
while (str[end] != '\0') {
if (isspace(str[end]))
break;
end++;
@ -144,23 +152,29 @@ static char *get_key(char *str, struct sort_key *key, int flags)
}
}
/* Remove last delim: "abc:def:" => "abc:def" */
if (key_separator && j && end != 0)
if (j && ch) {
//if (str[end-1] != key_separator)
// bb_error_msg(_and_die("BUG! "
// "str[start:%d,end:%d]:'%.*s'",
// start, end, (int)(end-start), &str[start]);
end--;
}
}
if (!j) start = end;
}
/* Strip leading whitespace if necessary */
//XXX: skip_whitespace()
if (flags & FLAG_b)
/* not using skip_whitespace() for speed */
while (isspace(str[start])) start++;
/* Strip trailing whitespace if necessary */
if (flags & FLAG_bb)
while (end > start && isspace(str[end-1])) end--;
/* Handle offsets on start and end */
/* -kSTART,N.ENDCHAR: honor ENDCHAR (1-based) */
if (key->range[3]) {
end += key->range[3] - 1;
end = key->range[3];
if (end > len) end = len;
}
/* -kN.STARTCHAR[,...]: honor STARTCHAR (1-based) */
if (key->range[1]) {
start += key->range[1] - 1;
if (start > len) start = len;
@ -281,7 +295,7 @@ static int compare_keys(const void *xarg, const void *yarg)
else if (!yy)
retval = 1;
else
retval = (dx == thyme.tm_mon) ? 0 : dx - thyme.tm_mon;
retval = dx - thyme.tm_mon;
break;
}
/* Full floating point version of -n */
@ -307,8 +321,8 @@ static int compare_keys(const void *xarg, const void *yarg)
/* Perform fallback sort if necessary */
if (!retval && !(option_mask32 & FLAG_s)) {
retval = strcmp(*(char **)xarg, *(char **)yarg);
flags = option_mask32;
retval = strcmp(*(char **)xarg, *(char **)yarg);
}
if (flags & FLAG_r)
@ -336,7 +350,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
char *line, **lines;
char *str_ignored, *str_o, *str_t;
llist_t *lst_k = NULL;
int i, flag;
int i;
int linecount;
unsigned opts;
@ -359,7 +373,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
/* note: below this point we use option_mask32, not opts,
* since that reduces register pressure and makes code smaller */
/* parse sort key */
/* Parse sort key */
while (lst_k) {
enum {
FLAG_allowed_for_k =
@ -386,17 +400,18 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
key->range[2*i+1] = str2u(&str_k);
}
while (*str_k) {
const char *temp2;
int flag;
const char *idx;
if (*str_k == ',' && !i++) {
str_k++;
break;
} /* no else needed: fall through to syntax error
because comma isn't in OPT_STR */
temp2 = strchr(OPT_STR, *str_k);
if (!temp2)
idx = strchr(OPT_STR, *str_k);
if (!idx)
bb_error_msg_and_die("unknown key option");
flag = 1 << (temp2 - OPT_STR);
flag = 1 << (idx - OPT_STR);
if (flag & ~FLAG_allowed_for_k)
bb_error_msg_and_die("unknown sort type");
/* b after ',' means strip _trailing_ space */
@ -430,10 +445,10 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
} while (*++argv);
#if ENABLE_FEATURE_SORT_BIG
/* if no key, perform alphabetic sort */
/* If no key, perform alphabetic sort */
if (!key_list)
add_key()->range[0] = 1;
/* handle -c */
/* Handle -c */
if (option_mask32 & FLAG_c) {
int j = (option_mask32 & FLAG_u) ? -1 : 0;
for (i = 1; i < linecount; i++) {
@ -447,20 +462,21 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
#endif
/* Perform the actual sort */
qsort(lines, linecount, sizeof(lines[0]), compare_keys);
/* handle -u */
/* Handle -u */
if (option_mask32 & FLAG_u) {
flag = 0;
int j = 0;
/* coreutils 6.3 drop lines for which only key is the same */
/* -- disabling last-resort compare... */
option_mask32 |= FLAG_s;
for (i = 1; i < linecount; i++) {
if (compare_keys(&lines[flag], &lines[i]) == 0)
if (compare_keys(&lines[j], &lines[i]) == 0)
free(lines[i]);
else
lines[++flag] = lines[i];
lines[++j] = lines[i];
}
if (linecount)
linecount = flag+1;
linecount = j+1;
}
/* Print it */
@ -469,9 +485,11 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
if (option_mask32 & FLAG_o)
xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
#endif
flag = (option_mask32 & FLAG_z) ? '\0' : '\n';
for (i = 0; i < linecount; i++)
printf("%s%c", lines[i], flag);
{
int ch = (option_mask32 & FLAG_z) ? '\0' : '\n';
for (i = 0; i < linecount; i++)
printf("%s%c", lines[i], ch);
}
fflush_stdout_and_exit(EXIT_SUCCESS);
}

View File

@ -22,6 +22,7 @@
//usage: "$ cat TODO | split -a 2 -l 2 TODO_\n"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_SPLIT_FANCY
static const struct suffix_mult split_suffixes[] = {
@ -78,6 +79,8 @@ int split_main(int argc UNUSED_PARAM, char **argv)
ssize_t bytes_read, to_write;
char *src;
setup_common_bufsiz();
opt_complementary = "?2:a+"; /* max 2 args; -a N */
opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len);

View File

@ -12,54 +12,83 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config STAT
//config: bool "stat"
//config: default y
//config: help
//config: display file or filesystem status.
//config:
//config:config FEATURE_STAT_FORMAT
//config: bool "Enable custom formats (-c)"
//config: default y
//config: depends on STAT
//config: help
//config: Without this, stat will not support the '-c format' option where
//config: users can pass a custom format string for output. This adds about
//config: 7k to a nonstatic build on amd64.
//config:
//config:config FEATURE_STAT_FILESYSTEM
//config: bool "Enable display of filesystem status (-f)"
//config: default y
//config: depends on STAT
//config: select PLATFORM_LINUX # statfs()
//config: help
//config: Without this, stat will not support the '-f' option to display
//config: information about filesystem status.
//usage:#define stat_trivial_usage
//usage: "[OPTIONS] FILE..."
//usage:#define stat_full_usage "\n\n"
//usage: "Display file (default) or filesystem status\n"
//usage: "Display file"
//usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem")
//usage: " status\n"
//usage: IF_FEATURE_STAT_FORMAT(
//usage: "\n -c fmt Use the specified format"
//usage: "\n -c FMT Use the specified format"
//usage: )
//usage: IF_FEATURE_STAT_FILESYSTEM(
//usage: "\n -f Display filesystem status"
//usage: )
//usage: "\n -L Follow links"
//usage: "\n -t Display info in terse form"
//usage: "\n -t Terse display"
//usage: IF_SELINUX(
//usage: "\n -Z Print security context"
//usage: )
//usage: IF_FEATURE_STAT_FORMAT(
//usage: "\n\nValid format sequences for files:\n"
//usage: "\n\nFMT sequences"IF_FEATURE_STAT_FILESYSTEM(" for files")":\n"
//usage: " %a Access rights in octal\n"
//usage: " %A Access rights in human readable form\n"
//usage: " %b Number of blocks allocated (see %B)\n"
//usage: " %B The size in bytes of each block reported by %b\n"
//usage: " %B Size in bytes of each block reported by %b\n"
//usage: " %d Device number in decimal\n"
//usage: " %D Device number in hex\n"
//usage: " %f Raw mode in hex\n"
//usage: " %F File type\n"
//usage: " %g Group ID of owner\n"
//usage: " %G Group name of owner\n"
//usage: " %g Group ID\n"
//usage: " %G Group name\n"
//usage: " %h Number of hard links\n"
//usage: " %i Inode number\n"
//usage: " %n File name\n"
//usage: " %N File name, with -> TARGET if symlink\n"
//usage: " %o I/O block size\n"
//usage: " %s Total size, in bytes\n"
//usage: " %s Total size in bytes\n"
//usage: " %t Major device type in hex\n"
//usage: " %T Minor device type in hex\n"
//usage: " %u User ID of owner\n"
//usage: " %U User name of owner\n"
//usage: " %u User ID\n"
//usage: " %U User name\n"
//usage: " %x Time of last access\n"
//usage: " %X Time of last access as seconds since Epoch\n"
//usage: " %y Time of last modification\n"
//usage: " %Y Time of last modification as seconds since Epoch\n"
//usage: " %z Time of last change\n"
//usage: " %Z Time of last change as seconds since Epoch\n"
//usage: "\nValid format sequences for file systems:\n"
//usage: IF_FEATURE_STAT_FILESYSTEM(
//usage: "\nFMT sequences for file systems:\n"
//usage: " %a Free blocks available to non-superuser\n"
//usage: " %b Total data blocks in file system\n"
//usage: " %c Total file nodes in file system\n"
//usage: " %d Free file nodes in file system\n"
//usage: " %f Free blocks in file system\n"
//usage: " %b Total data blocks\n"
//usage: " %c Total file nodes\n"
//usage: " %d Free file nodes\n"
//usage: " %f Free blocks\n"
//usage: IF_SELINUX(
//usage: " %C Security context in selinux\n"
//usage: )
@ -71,13 +100,17 @@
//usage: " %t Type in hex\n"
//usage: " %T Type in human readable form"
//usage: )
//usage: )
#include "libbb.h"
#include "common_bufsiz.h"
#define OPT_FILESYS (1 << 0)
#define OPT_TERSE (1 << 1)
#define OPT_DEREFERENCE (1 << 2)
#define OPT_SELINUX (1 << 3)
enum {
OPT_TERSE = (1 << 0),
OPT_DEREFERENCE = (1 << 1),
OPT_FILESYS = (1 << 2) * ENABLE_FEATURE_STAT_FILESYSTEM,
OPT_SELINUX = (1 << (2+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX,
};
#if ENABLE_FEATURE_STAT_FORMAT
typedef bool (*statfunc_ptr)(const char *, const char *);
@ -126,12 +159,13 @@ static const char *human_time(time_t t)
/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
#define buf bb_common_bufsiz1
strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000");
setup_common_bufsiz();
strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000");
return buf;
#undef buf
}
#if ENABLE_FEATURE_STAT_FILESYSTEM
/* Return the type of the specified file system.
* Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris)
* Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2)
@ -202,6 +236,7 @@ static unsigned long long get_f_fsid(const struct statfs *statfsbuf)
while (--sz > 0);
return r;
}
#endif /* FEATURE_STAT_FILESYSTEM */
#if ENABLE_FEATURE_STAT_FORMAT
static void strcatc(char *str, char c)
@ -217,6 +252,7 @@ static void printfs(char *pformat, const char *msg)
printf(pformat, msg);
}
#if ENABLE_FEATURE_STAT_FILESYSTEM
/* print statfs info */
static void FAST_FUNC print_statfs(char *pformat, const char m,
const char *const filename, const void *data
@ -263,6 +299,7 @@ static void FAST_FUNC print_statfs(char *pformat, const char m,
printf(pformat, m);
}
}
#endif
/* print stat info */
static void FAST_FUNC print_stat(char *pformat, const char m,
@ -423,6 +460,7 @@ static void print_it(const char *masterformat,
}
#endif /* FEATURE_STAT_FORMAT */
#if ENABLE_FEATURE_STAT_FILESYSTEM
/* Stat the file system and print what we find. */
#if !ENABLE_FEATURE_STAT_FORMAT
#define do_statfs(filename, format) do_statfs(filename)
@ -538,6 +576,7 @@ static bool do_statfs(const char *filename, const char *format)
#endif /* FEATURE_STAT_FORMAT */
return 1;
}
#endif /* FEATURE_STAT_FILESYSTEM */
/* stat the file and print what we find */
#if !ENABLE_FEATURE_STAT_FORMAT
@ -721,12 +760,15 @@ int stat_main(int argc UNUSED_PARAM, char **argv)
statfunc_ptr statfunc = do_stat;
opt_complementary = "-1"; /* min one arg */
opts = getopt32(argv, "ftL"
opts = getopt32(argv, "tL"
IF_FEATURE_STAT_FILESYSTEM("f")
IF_SELINUX("Z")
IF_FEATURE_STAT_FORMAT("c:", &format)
);
#if ENABLE_FEATURE_STAT_FILESYSTEM
if (opts & OPT_FILESYS) /* -f */
statfunc = do_statfs;
#endif
#if ENABLE_SELINUX
if (opts & OPT_SELINUX) {
selinux_or_die();

View File

@ -32,6 +32,7 @@
//usage: "\n [SETTING] See manpage"
#include "libbb.h"
#include "common_bufsiz.h"
#ifndef _POSIX_VDISABLE
# define _POSIX_VDISABLE ((unsigned char) 0)
@ -317,7 +318,7 @@ enum {
#define MI_ENTRY(N,T,F,B,M) N "\0"
/* Mode names given on command line */
static const char mode_name[] =
static const char mode_name[] ALIGN1 =
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 )
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 )
MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 )
@ -680,7 +681,7 @@ enum {
#define CI_ENTRY(n,s,o) n "\0"
/* Name given on command line */
static const char control_name[] =
static const char control_name[] ALIGN1 =
CI_ENTRY("intr", CINTR, VINTR )
CI_ENTRY("quit", CQUIT, VQUIT )
CI_ENTRY("erase", CERASE, VERASE )
@ -722,7 +723,7 @@ static const char control_name[] =
#undef CI_ENTRY
#define CI_ENTRY(n,s,o) { s, o },
static const struct control_info control_info[] = {
static const struct control_info control_info[] ALIGN2 = {
/* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */
CI_ENTRY("intr", CINTR, VINTR )
CI_ENTRY("quit", CQUIT, VQUIT )
@ -775,7 +776,7 @@ struct globals {
unsigned current_col;
char buf[10];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.device_name = bb_msg_standard_input; \
G.max_col = 80; \
@ -1403,7 +1404,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
perror_on_device_and_die("%s");
if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) {
get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL);
G.max_col = get_terminal_width(STDOUT_FILENO);
output_func(&mode, display_all);
return EXIT_SUCCESS;
}

View File

@ -21,6 +21,7 @@
//usage: "\n -s Use System V sum algorithm (512byte blocks)"
#include "libbb.h"
#include "common_bufsiz.h"
enum { SUM_BSD, PRINT_NAME, SUM_SYSV };
@ -30,18 +31,20 @@ enum { SUM_BSD, PRINT_NAME, SUM_SYSV };
/* Return 1 if successful. */
static unsigned sum_file(const char *file, unsigned type)
{
#define buf bb_common_bufsiz1
unsigned long long total_bytes = 0;
int fd, r;
/* The sum of all the input bytes, modulo (UINT_MAX + 1). */
unsigned s = 0;
#define buf bb_common_bufsiz1
setup_common_bufsiz();
fd = open_or_warn_stdin(file);
if (fd == -1)
return 0;
while (1) {
size_t bytes_read = safe_read(fd, buf, BUFSIZ);
size_t bytes_read = safe_read(fd, buf, COMMON_BUFSIZE);
if ((ssize_t)bytes_read <= 0) {
r = (fd && close(fd) != 0);

View File

@ -49,13 +49,14 @@
//usage: "nameserver 10.0.0.1\n"
#include "libbb.h"
#include "common_bufsiz.h"
struct globals {
bool from_top;
bool exitcode;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { } while (0)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
static void tail_xprint_header(const char *fmt, const char *filename)
{

View File

@ -23,6 +23,7 @@
//usage: "Hello\n"
#include "libbb.h"
#include "common_bufsiz.h"
int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int tee_main(int argc, char **argv)
@ -37,6 +38,7 @@ int tee_main(int argc, char **argv)
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
ssize_t c;
# define buf bb_common_bufsiz1
setup_common_bufsiz();
#else
int c;
#endif
@ -79,7 +81,7 @@ int tee_main(int argc, char **argv)
/* names[0] will be filled later */
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
while ((c = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE)) > 0) {
fp = files;
do
fwrite(buf, 1, c, *fp);

View File

@ -91,7 +91,6 @@ static void map(char *pvector,
* Character classes, e.g. [:upper:] ==> A...Z
* Equiv classess, e.g. [=A=] ==> A (hmmmmmmm?)
* not supported:
* \ooo-\ooo - octal ranges
* [x*N] - repeat char x N times
* [x*] - repeat char x until it fills STRING2:
* # echo qwe123 | /usr/bin/tr 123456789 '[d]'
@ -99,7 +98,7 @@ static void map(char *pvector,
* # echo qwe123 | /usr/bin/tr 123456789 '[d*]'
* qweddd
*/
static unsigned expand(const char *arg, char **buffer_p)
static unsigned expand(char *arg, char **buffer_p)
{
char *buffer = *buffer_p;
unsigned pos = 0;
@ -113,9 +112,17 @@ static unsigned expand(const char *arg, char **buffer_p)
*buffer_p = buffer = xrealloc(buffer, size);
}
if (*arg == '\\') {
const char *z;
arg++;
buffer[pos++] = bb_process_escape_sequence(&arg);
continue;
z = arg;
ac = bb_process_escape_sequence(&z);
arg = (char *)z;
arg--;
*arg = ac;
/*
* fall through, there may be a range.
* If not, current char will be treated anyway.
*/
}
if (arg[1] == '-') { /* "0-9..." */
ac = arg[2];
@ -124,9 +131,15 @@ static unsigned expand(const char *arg, char **buffer_p)
continue; /* next iter will copy '-' and stop */
}
i = (unsigned char) *arg;
arg += 3; /* skip 0-9 or 0-\ */
if (ac == '\\') {
const char *z;
z = arg;
ac = bb_process_escape_sequence(&z);
arg = (char *)z;
}
while (i <= ac) /* ok: i is unsigned _int_ */
buffer[pos++] = i++;
arg += 3; /* skip 0-9 */
continue;
}
if ((ENABLE_FEATURE_TR_CLASSES || ENABLE_FEATURE_TR_EQUIV)

View File

@ -40,7 +40,7 @@ int truncate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int truncate_main(int argc UNUSED_PARAM, char **argv)
{
unsigned opts;
int flags = O_RDWR;
int flags = O_WRONLY | O_NONBLOCK;
int ret = EXIT_SUCCESS;
char *size_str;
off_t size;
@ -64,7 +64,7 @@ int truncate_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
while (*argv) {
int fd = open(*argv, flags);
int fd = open(*argv, flags, 0666);
if (fd < 0) {
if (errno != ENOENT || !(opts & OPT_NOCREATE)) {
bb_perror_msg("%s: open", *argv);

View File

@ -7,79 +7,4 @@ menu "Debian Utilities"
INSERT
config MKTEMP
bool "mktemp"
default y
help
mktemp is used to create unique temporary files
config PIPE_PROGRESS
bool "pipe_progress"
default y
help
Display a dot to indicate pipe activity.
config RUN_PARTS
bool "run-parts"
default y
help
run-parts is a utility designed to run all the scripts in a directory.
It is useful to set up a directory like cron.daily, where you need to
execute all the scripts in that directory.
In this implementation of run-parts some features (such as report
mode) are not implemented.
Unless you know that run-parts is used in some of your scripts
you can safely say N here.
config FEATURE_RUN_PARTS_LONG_OPTIONS
bool "Enable long options"
default y
depends on RUN_PARTS && LONG_OPTS
help
Support long options for the run-parts applet.
config FEATURE_RUN_PARTS_FANCY
bool "Support additional arguments"
default y
depends on RUN_PARTS
help
Support additional options:
-l --list print the names of the all matching files (not
limited to executables), but don't actually run them.
config START_STOP_DAEMON
bool "start-stop-daemon"
default y
help
start-stop-daemon is used to control the creation and
termination of system-level processes, usually the ones
started during the startup of the system.
config FEATURE_START_STOP_DAEMON_FANCY
bool "Support additional arguments"
default y
depends on START_STOP_DAEMON
help
Support additional arguments.
-o|--oknodo ignored since we exit with 0 anyway
-v|--verbose
-N|--nicelevel N
config FEATURE_START_STOP_DAEMON_LONG_OPTIONS
bool "Enable long options"
default y
depends on START_STOP_DAEMON && LONG_OPTS
help
Support long options for the start-stop-daemon applet.
config WHICH
bool "which"
default y
help
which is used to find programs in your PATH and
print out their pathnames.
endmenu

View File

@ -7,8 +7,3 @@
lib-y:=
INSERT
lib-$(CONFIG_MKTEMP) += mktemp.o
lib-$(CONFIG_PIPE_PROGRESS) += pipe_progress.o
lib-$(CONFIG_RUN_PARTS) += run_parts.o
lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o
lib-$(CONFIG_WHICH) += which.o

View File

@ -30,6 +30,15 @@
* a directory: $TMPDIR, if set; else the directory specified via
* -p; else /tmp [deprecated]
*/
//config:config MKTEMP
//config: bool "mktemp"
//config: default y
//config: help
//config: mktemp is used to create unique temporary files
//applet:IF_MKTEMP(APPLET(mktemp, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_MKTEMP) += mktemp.o
//usage:#define mktemp_trivial_usage
//usage: "[-dt] [-p DIR] [TEMPLATE]"

View File

@ -6,6 +6,15 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PIPE_PROGRESS
//config: bool "pipe_progress"
//config: default y
//config: help
//config: Display a dot to indicate pipe activity.
//applet:IF_PIPE_PROGRESS(APPLET(pipe_progress, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_PIPE_PROGRESS) += pipe_progress.o
//usage:#define pipe_progress_trivial_usage NOUSAGE_STR
//usage:#define pipe_progress_full_usage ""

View File

@ -22,6 +22,40 @@
* report mode. As the original run-parts support only long options, I've
* broken compatibility because the BusyBox policy doesn't allow them.
*/
//config:config RUN_PARTS
//config: bool "run-parts"
//config: default y
//config: help
//config: run-parts is a utility designed to run all the scripts in a directory.
//config:
//config: It is useful to set up a directory like cron.daily, where you need to
//config: execute all the scripts in that directory.
//config:
//config: In this implementation of run-parts some features (such as report
//config: mode) are not implemented.
//config:
//config: Unless you know that run-parts is used in some of your scripts
//config: you can safely say N here.
//config:
//config:config FEATURE_RUN_PARTS_LONG_OPTIONS
//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"
//config: default y
//config: depends on RUN_PARTS
//config: help
//config: Support additional options:
//config: -l --list print the names of the all matching files (not
//config: limited to executables), but don't actually run them.
//applet:IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts))
//kbuild:lib-$(CONFIG_RUN_PARTS) += run_parts.o
//usage:#define run_parts_trivial_usage
//usage: "[-a ARG]... [-u UMASK] "
@ -55,17 +89,18 @@
//usage: "+ shutdown -h +4m"
#include "libbb.h"
#include "common_bufsiz.h"
struct globals {
char **names;
int cur;
char *cmd[2 /* using 1 provokes compiler warning */];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define names (G.names)
#define cur (G.cur )
#define cmd (G.cmd )
#define INIT_G() do { } while (0)
#define INIT_G() do { setup_common_bufsiz(); } while (0)
enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 };

View File

@ -56,6 +56,34 @@ Misc options:
-q,--quiet Quiet
-v,--verbose Verbose
*/
//config:config START_STOP_DAEMON
//config: bool "start-stop-daemon"
//config: default y
//config: help
//config: start-stop-daemon is used to control the creation and
//config: termination of system-level processes, usually the ones
//config: started during the startup of the system.
//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))
//kbuild:lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o
//usage:#define start_stop_daemon_trivial_usage
//usage: "[OPTIONS] [-S|-K] ... [-- ARGS...]"
@ -125,6 +153,7 @@ Misc options:
/* Override ENABLE_FEATURE_PIDFILE */
#define WANT_PIDFILE 1
#include "libbb.h"
#include "common_bufsiz.h"
struct pid_list {
struct pid_list *next;
@ -163,7 +192,7 @@ struct globals {
int user_id;
smallint signal_nr;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define userspec (G.userspec )
#define cmdname (G.cmdname )
#define execname (G.execname )
@ -171,6 +200,7 @@ struct globals {
#define user_id (G.user_id )
#define signal_nr (G.signal_nr )
#define INIT_G() do { \
setup_common_bufsiz(); \
user_id = -1; \
signal_nr = 15; \
} while (0)
@ -511,15 +541,15 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
write_pidfile(pidfile);
}
if (opt & OPT_c) {
struct bb_uidgid_t ugid = { -1, -1 };
struct bb_uidgid_t ugid;
parse_chown_usergroup_or_die(&ugid, chuid);
if (ugid.uid != (uid_t) -1) {
if (ugid.uid != (uid_t) -1L) {
struct passwd *pw = xgetpwuid(ugid.uid);
if (ugid.gid != (gid_t) -1)
if (ugid.gid != (gid_t) -1L)
pw->pw_gid = ugid.gid;
/* initgroups, setgid, setuid: */
change_identity(pw);
} else if (ugid.gid != (gid_t) -1) {
} else if (ugid.gid != (gid_t) -1L) {
xsetgid(ugid.gid);
setgroups(1, &ugid.gid);
}

View File

@ -5,6 +5,16 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config WHICH
//config: bool "which"
//config: default y
//config: help
//config: which is used to find programs in your PATH and
//config: print out their pathnames.
//applet:IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_WHICH) += which.o
//usage:#define which_trivial_usage
//usage: "[COMMAND]..."

View File

@ -178,6 +178,7 @@ dd POSIX options:
conv=noerror | yes | |
conv=notrunc | yes | |
conv=sync | yes | |
iflag=skip_bytes| yes | |
dd Busybox specific options:
conv=fsync

View File

@ -7,12 +7,6 @@ menu "Linux Ext2 FS Progs"
INSERT
config CHATTR
bool "chattr"
default y
help
chattr changes the file attributes on a second extended file system.
### config E2FSCK
### bool "e2fsck"
### default y
@ -22,21 +16,6 @@ config CHATTR
### The normal compat symlinks 'fsck.ext2' and 'fsck.ext3' are also
### provided.
config FSCK
bool "fsck"
default y
help
fsck is used to check and optionally repair one or more filesystems.
In actuality, fsck is simply a front-end for the various file system
checkers (fsck.fstype) available under Linux.
config LSATTR
bool "lsattr"
default y
select PLATFORM_LINUX
help
lsattr lists the file attributes on a second extended file system.
### config MKE2FS
### bool "mke2fs"
### default y
@ -44,13 +23,6 @@ config LSATTR
### mke2fs is used to create an ext2/ext3 filesystem. The normal compat
### symlinks 'mkfs.ext2' and 'mkfs.ext3' are also provided.
config TUNE2FS
bool "tune2fs"
default n # off: it is too limited compared to upstream version
help
tune2fs allows the system administrator to adjust various tunable
filesystem parameters on Linux ext2/ext3 filesystems.
### config E2LABEL
### bool "e2label"
### default y

View File

@ -7,9 +7,3 @@
lib-y:=
INSERT
lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o
lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o
lib-$(CONFIG_FSCK) += fsck.o
lib-$(CONFIG_TUNE2FS) += tune2fs.o

View File

@ -9,24 +9,22 @@
* This file can be redistributed under the terms of the GNU General
* Public License
*/
//config:config CHATTR
//config: bool "chattr"
//config: default y
//config: help
//config: chattr changes the file attributes on a second extended file system.
/*
* History:
* 93/10/30 - Creation
* 93/11/13 - Replace stat() calls by lstat() to avoid loops
* 94/02/27 - Integrated in Ted's distribution
* 98/12/29 - Ignore symlinks when working recursively (G M Sipe)
* 98/12/29 - Display version info only when -V specified (G M Sipe)
*/
//applet:IF_CHATTR(APPLET(chattr, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o
//usage:#define chattr_trivial_usage
//usage: "[-R] [-+=AacDdijsStTu] [-v VERSION] [FILE]..."
//usage:#define chattr_full_usage "\n\n"
//usage: "Change file attributes on an ext2 fs\n"
//usage: "Change ext2 file attributes\n"
//usage: "\nModifiers:"
//usage: "\n - Remove attributes"
//usage: "\n + Add attributes"
//usage: "\n = Set attributes"
//usage: "\n -,+,= Remove/add/set attributes"
//usage: "\nAttributes:"
//usage: "\n A Don't track atime"
//usage: "\n a Append mode only"
@ -36,11 +34,11 @@
//usage: "\n i Cannot be modified (immutable)"
//usage: "\n j Write all data to journal first"
//usage: "\n s Zero disk storage when deleted"
//usage: "\n S Write file contents synchronously"
//usage: "\n S Write synchronously"
//usage: "\n t Disable tail-merging of partial blocks with other files"
//usage: "\n u Allow file to be undeleted"
//usage: "\n -R Recurse"
//usage: "\n -v Set the file's version/generation number"
//usage: "\n -v VER Set version/generation number"
#include "libbb.h"
#include "e2fs_lib.h"

View File

@ -149,14 +149,14 @@ const uint32_t e2attr_flags_value[] = {
EXT2_TOPDIR_FL
};
const char e2attr_flags_sname[] =
const char e2attr_flags_sname[] ALIGN1 =
#ifdef ENABLE_COMPRESSION
"BZXE"
#endif
"I"
"suSDiadAcjtT";
static const char e2attr_flags_lname[] =
static const char e2attr_flags_lname[] ALIGN1 =
#ifdef ENABLE_COMPRESSION
"Compressed_File" "\0"
"Compressed_Dirty_File" "\0"

View File

@ -33,9 +33,20 @@
* spawns actual fsck.something for each filesystem to check.
* It doesn't guess filesystem types from on-disk format.
*/
//config:config FSCK
//config: bool "fsck"
//config: default y
//config: help
//config: fsck is used to check and optionally repair one or more filesystems.
//config: In actuality, fsck is simply a front-end for the various file system
//config: checkers (fsck.fstype) available under Linux.
//applet:IF_FSCK(APPLET(fsck, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_FSCK) += fsck.o
//usage:#define fsck_trivial_usage
//usage: "[-ANPRTV] [-C FD] [-t FSTYPE] [FS_OPTS] [BLOCKDEV]..."
//usage: "[-ANPRTV] [-t FSTYPE] [FS_OPTS] [BLOCKDEV]..."
//usage:#define fsck_full_usage "\n\n"
//usage: "Check and repair filesystems\n"
//usage: "\n -A Walk /etc/fstab and check all filesystems"
@ -44,10 +55,12 @@
//usage: "\n -R With -A, skip the root filesystem"
//usage: "\n -T Don't show title on startup"
//usage: "\n -V Verbose"
//usage: "\n -C n Write status information to specified filedescriptor"
//DO_PROGRESS_INDICATOR is off:
////usage: "\n -C FD Write status information to specified file descriptor"
//usage: "\n -t TYPE List of filesystem types to check"
#include "libbb.h"
#include "common_bufsiz.h"
/* "progress indicator" code is somewhat buggy and ext[23] specific.
* We should be filesystem agnostic. IOW: there should be a well-defined
@ -125,35 +138,43 @@ static const char really_wanted[] ALIGN1 =
#define BASE_MD "/dev/md"
static char **args;
static int num_args;
static int verbose;
struct globals {
char **args;
int num_args;
int verbose;
#define FS_TYPE_FLAG_NORMAL 0
#define FS_TYPE_FLAG_OPT 1
#define FS_TYPE_FLAG_NEGOPT 2
static char **fs_type_list;
static uint8_t *fs_type_flag;
static smallint fs_type_negated;
char **fs_type_list;
uint8_t *fs_type_flag;
smallint fs_type_negated;
static smallint noexecute;
static smallint serialize;
static smallint skip_root;
/* static smallint like_mount; */
static smallint parallel_root;
static smallint force_all_parallel;
smallint noexecute;
smallint serialize;
smallint skip_root;
/* smallint like_mount; */
smallint parallel_root;
smallint force_all_parallel;
smallint kill_sent;
#if DO_PROGRESS_INDICATOR
static smallint progress;
static int progress_fd;
smallint progress;
int progress_fd;
#endif
static int num_running;
static int max_running;
static char *fstype;
static struct fs_info *filesys_info;
static struct fs_info *filesys_last;
static struct fsck_instance *instance_list;
int num_running;
int max_running;
char *fstype;
struct fs_info *filesys_info;
struct fs_info *filesys_last;
struct fsck_instance *instance_list;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
/*
* Return the "base device" given a particular device; this is used to
@ -302,11 +323,11 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt,
/*fs->flags = 0; */
/*fs->next = NULL; */
if (!filesys_info)
filesys_info = fs;
if (!G.filesys_info)
G.filesys_info = fs;
else
filesys_last->next = fs;
filesys_last = fs;
G.filesys_last->next = fs;
G.filesys_last = fs;
return fs;
}
@ -316,6 +337,7 @@ static void load_fs_info(const char *filename)
{
FILE *fstab;
struct mntent mte;
char buf[1024];
fstab = setmntent(filename, "r");
if (!fstab) {
@ -324,8 +346,8 @@ static void load_fs_info(const char *filename)
}
// Loop through entries
while (getmntent_r(fstab, &mte, bb_common_bufsiz1, COMMON_BUFSIZE)) {
//bb_info_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir,
while (getmntent_r(fstab, &mte, buf, sizeof(buf))) {
//bb_error_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir,
// mte.mnt_type, mte.mnt_opts,
// mte.mnt_passno);
create_fs_device(mte.mnt_fsname, mte.mnt_dir,
@ -340,7 +362,7 @@ static struct fs_info *lookup(char *filesys)
{
struct fs_info *fs;
for (fs = filesys_info; fs; fs = fs->next) {
for (fs = G.filesys_info; fs; fs = fs->next) {
if (strcmp(filesys, fs->device) == 0
|| (fs->mountpt && strcmp(filesys, fs->mountpt) == 0)
)
@ -355,7 +377,7 @@ static int progress_active(void)
{
struct fsck_instance *inst;
for (inst = instance_list; inst; inst = inst->next) {
for (inst = G.instance_list; inst; inst = inst->next) {
if (inst->flags & FLAG_DONE)
continue;
if (inst->flags & FLAG_PROGRESS)
@ -371,19 +393,17 @@ static int progress_active(void)
*/
static void kill_all_if_got_signal(void)
{
static smallint kill_sent;
struct fsck_instance *inst;
if (!bb_got_signal || kill_sent)
if (!bb_got_signal || G.kill_sent)
return;
for (inst = instance_list; inst; inst = inst->next) {
for (inst = G.instance_list; inst; inst = inst->next) {
if (inst->flags & FLAG_DONE)
continue;
kill(inst->pid, SIGTERM);
}
kill_sent = 1;
G.kill_sent = 1;
}
/*
@ -398,9 +418,9 @@ static int wait_one(int flags)
struct fsck_instance *inst, *prev;
pid_t pid;
if (!instance_list)
if (!G.instance_list)
return -1;
/* if (noexecute) { already returned -1; } */
/* if (G.noexecute) { already returned -1; } */
while (1) {
pid = waitpid(-1, &status, flags);
@ -418,7 +438,7 @@ static int wait_one(int flags)
continue;
}
prev = NULL;
inst = instance_list;
inst = G.instance_list;
do {
if (inst->pid == pid)
goto child_died;
@ -428,9 +448,8 @@ static int wait_one(int flags)
}
child_died:
if (WIFEXITED(status))
status = WEXITSTATUS(status);
else if (WIFSIGNALED(status)) {
status = WEXITSTATUS(status);
if (WIFSIGNALED(status)) {
sig = WTERMSIG(status);
status = EXIT_UNCORRECTED;
if (sig != SIGINT) {
@ -439,16 +458,12 @@ static int wait_one(int flags)
inst->prog, inst->device, sig);
status = EXIT_ERROR;
}
} else {
printf("%s %s: status is %x, should never happen\n",
inst->prog, inst->device, status);
status = EXIT_ERROR;
}
#if DO_PROGRESS_INDICATOR
if (progress && (inst->flags & FLAG_PROGRESS) && !progress_active()) {
struct fsck_instance *inst2;
for (inst2 = instance_list; inst2; inst2 = inst2->next) {
for (inst2 = G.instance_list; inst2; inst2 = inst2->next) {
if (inst2->flags & FLAG_DONE)
continue;
if (strcmp(inst2->type, "ext2") != 0
@ -475,11 +490,11 @@ static int wait_one(int flags)
if (prev)
prev->next = inst->next;
else
instance_list = inst->next;
if (verbose > 1)
G.instance_list = inst->next;
if (G.verbose > 1)
printf("Finished with %s (exit status %d)\n",
inst->device, status);
num_running--;
G.num_running--;
free_instance(inst);
return status;
@ -515,51 +530,51 @@ static void execute(const char *type, const char *device,
struct fsck_instance *inst;
pid_t pid;
args[0] = xasprintf("fsck.%s", type);
G.args[0] = xasprintf("fsck.%s", type);
#if DO_PROGRESS_INDICATOR
if (progress && !progress_active()) {
if (strcmp(type, "ext2") == 0
|| strcmp(type, "ext3") == 0
) {
args[XXX] = xasprintf("-C%d", progress_fd); /* 1 */
G.args[XXX] = xasprintf("-C%d", progress_fd); /* 1 */
inst->flags |= FLAG_PROGRESS;
}
}
#endif
args[num_args - 2] = (char*)device;
/* args[num_args - 1] = NULL; - already is */
G.args[G.num_args - 2] = (char*)device;
/* G.args[G.num_args - 1] = NULL; - already is */
if (verbose || noexecute) {
printf("[%s (%d) -- %s]", args[0], num_running,
if (G.verbose || G.noexecute) {
printf("[%s (%d) -- %s]", G.args[0], G.num_running,
mntpt ? mntpt : device);
for (i = 0; args[i]; i++)
printf(" %s", args[i]);
for (i = 0; G.args[i]; i++)
printf(" %s", G.args[i]);
bb_putchar('\n');
}
/* Fork and execute the correct program. */
pid = -1;
if (!noexecute) {
pid = spawn(args);
if (!G.noexecute) {
pid = spawn(G.args);
if (pid < 0)
bb_simple_perror_msg(args[0]);
bb_simple_perror_msg(G.args[0]);
}
#if DO_PROGRESS_INDICATOR
free(args[XXX]);
free(G.args[XXX]);
#endif
/* No child, so don't record an instance */
if (pid <= 0) {
free(args[0]);
free(G.args[0]);
return;
}
inst = xzalloc(sizeof(*inst));
inst->pid = pid;
inst->prog = args[0];
inst->prog = G.args[0];
inst->device = xstrdup(device);
inst->base_device = base_device(device);
#if DO_PROGRESS_INDICATOR
@ -568,8 +583,8 @@ static void execute(const char *type, const char *device,
/* Add to the list of running fsck's.
* (was adding to the end, but adding to the front is simpler...) */
inst->next = instance_list;
instance_list = inst;
inst->next = G.instance_list;
G.instance_list = inst;
}
/*
@ -588,27 +603,27 @@ static void fsck_device(struct fs_info *fs /*, int interactive */)
if (strcmp(fs->type, "auto") != 0) {
type = fs->type;
if (verbose > 2)
bb_info_msg("using filesystem type '%s' %s",
if (G.verbose > 2)
printf("using filesystem type '%s' %s\n",
type, "from fstab");
} else if (fstype
&& (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */
&& !is_prefixed_with(fstype, "opts=")
&& !is_prefixed_with(fstype, "loop")
&& !strchr(fstype, ',')
} else if (G.fstype
&& (G.fstype[0] != 'n' || G.fstype[1] != 'o') /* != "no" */
&& !is_prefixed_with(G.fstype, "opts=")
&& !is_prefixed_with(G.fstype, "loop")
&& !strchr(G.fstype, ',')
) {
type = fstype;
if (verbose > 2)
bb_info_msg("using filesystem type '%s' %s",
type = G.fstype;
if (G.verbose > 2)
printf("using filesystem type '%s' %s\n",
type, "from -t");
} else {
type = "auto";
if (verbose > 2)
bb_info_msg("using filesystem type '%s' %s",
if (G.verbose > 2)
printf("using filesystem type '%s' %s\n",
type, "(default)");
}
num_running++;
G.num_running++;
execute(type, fs->device, fs->mountpt /*, interactive */);
}
@ -621,13 +636,13 @@ static int device_already_active(char *device)
struct fsck_instance *inst;
char *base;
if (force_all_parallel)
if (G.force_all_parallel)
return 0;
#ifdef BASE_MD
/* Don't check a soft raid disk with any other disk */
if (instance_list
&& (is_prefixed_with(instance_list->device, BASE_MD)
if (G.instance_list
&& (is_prefixed_with(G.instance_list->device, BASE_MD)
|| is_prefixed_with(device, BASE_MD))
) {
return 1;
@ -640,9 +655,9 @@ static int device_already_active(char *device)
* already active if there are any fsck instances running.
*/
if (!base)
return (instance_list != NULL);
return (G.instance_list != NULL);
for (inst = instance_list; inst; inst = inst->next) {
for (inst = G.instance_list; inst; inst = inst->next) {
if (!inst->base_device || !strcmp(base, inst->base_device)) {
free(base);
return 1;
@ -687,17 +702,17 @@ static int fs_match(struct fs_info *fs)
int n, ret, checked_type;
char *cp;
if (!fs_type_list)
if (!G.fs_type_list)
return 1;
ret = 0;
checked_type = 0;
n = 0;
while (1) {
cp = fs_type_list[n];
cp = G.fs_type_list[n];
if (!cp)
break;
switch (fs_type_flag[n]) {
switch (G.fs_type_flag[n]) {
case FS_TYPE_FLAG_NORMAL:
checked_type++;
if (strcmp(cp, fs->type) == 0)
@ -717,7 +732,7 @@ static int fs_match(struct fs_info *fs)
if (checked_type == 0)
return 1;
return (fs_type_negated ? !ret : ret);
return (G.fs_type_negated ? !ret : ret);
}
/* Check if we should ignore this filesystem. */
@ -753,7 +768,7 @@ static int check_all(void)
smallint pass_done;
int passno;
if (verbose)
if (G.verbose)
puts("Checking all filesystems");
/*
@ -761,17 +776,17 @@ static int check_all(void)
* which should be ignored as done, and resolve any "auto"
* filesystem types (done as a side-effect of calling ignore()).
*/
for (fs = filesys_info; fs; fs = fs->next)
for (fs = G.filesys_info; fs; fs = fs->next)
if (ignore(fs))
fs->flags |= FLAG_DONE;
/*
* Find and check the root filesystem.
*/
if (!parallel_root) {
for (fs = filesys_info; fs; fs = fs->next) {
if (!G.parallel_root) {
for (fs = G.filesys_info; fs; fs = fs->next) {
if (LONE_CHAR(fs->mountpt, '/')) {
if (!skip_root && !ignore(fs)) {
if (!G.skip_root && !ignore(fs)) {
fsck_device(fs /*, 1*/);
status |= wait_many(FLAG_WAIT_ALL);
if (status > EXIT_NONDESTRUCT)
@ -787,8 +802,8 @@ static int check_all(void)
* filesystem listed twice.
* "Skip root" will skip _all_ root entries.
*/
if (skip_root)
for (fs = filesys_info; fs; fs = fs->next)
if (G.skip_root)
for (fs = G.filesys_info; fs; fs = fs->next)
if (LONE_CHAR(fs->mountpt, '/'))
fs->flags |= FLAG_DONE;
@ -798,7 +813,7 @@ static int check_all(void)
not_done_yet = 0;
pass_done = 1;
for (fs = filesys_info; fs; fs = fs->next) {
for (fs = G.filesys_info; fs; fs = fs->next) {
if (bb_got_signal)
break;
if (fs->flags & FLAG_DONE)
@ -824,7 +839,7 @@ static int check_all(void)
/*
* Spawn off the fsck process
*/
fsck_device(fs /*, serialize*/);
fsck_device(fs /*, G.serialize*/);
fs->flags |= FLAG_DONE;
/*
@ -832,8 +847,8 @@ static int check_all(void)
* have a limit on the number of fsck's extant
* at one time, apply that limit.
*/
if (serialize
|| (max_running && (num_running >= max_running))
if (G.serialize
|| (G.num_running >= G.max_running)
) {
pass_done = 0;
break;
@ -841,12 +856,12 @@ static int check_all(void)
}
if (bb_got_signal)
break;
if (verbose > 1)
if (G.verbose > 1)
printf("--waiting-- (pass %d)\n", passno);
status |= wait_many(pass_done ? FLAG_WAIT_ALL :
FLAG_WAIT_ATLEAST_ONE);
if (pass_done) {
if (verbose > 1)
if (G.verbose > 1)
puts("----------------------------------");
passno++;
} else
@ -874,9 +889,9 @@ static void compile_fs_type(char *fs_type)
s++;
}
fs_type_list = xzalloc(num * sizeof(fs_type_list[0]));
fs_type_flag = xzalloc(num * sizeof(fs_type_flag[0]));
fs_type_negated = -1; /* not yet known is it negated or not */
G.fs_type_list = xzalloc(num * sizeof(G.fs_type_list[0]));
G.fs_type_flag = xzalloc(num * sizeof(G.fs_type_flag[0]));
G.fs_type_negated = -1; /* not yet known is it negated or not */
num = 0;
s = fs_type;
@ -898,18 +913,18 @@ static void compile_fs_type(char *fs_type)
if (is_prefixed_with(s, "opts=")) {
s += 5;
loop_special_case:
fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT;
G.fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT;
} else {
if (fs_type_negated == -1)
fs_type_negated = negate;
if (fs_type_negated != negate)
if (G.fs_type_negated == -1)
G.fs_type_negated = negate;
if (G.fs_type_negated != negate)
bb_error_msg_and_die(
"either all or none of the filesystem types passed to -t must be prefixed "
"with 'no' or '!'");
}
comma = strchr(s, ',');
fs_type_list[num++] = comma ? xstrndup(s, comma-s) : xstrdup(s);
if (!comma)
comma = strchrnul(s, ',');
G.fs_type_list[num++] = xstrndup(s, comma-s);
if (*comma == '\0')
break;
s = comma + 1;
}
@ -917,8 +932,8 @@ static void compile_fs_type(char *fs_type)
static char **new_args(void)
{
args = xrealloc_vector(args, 2, num_args);
return &args[num_args++];
G.args = xrealloc_vector(G.args, 2, G.num_args);
return &G.args[G.num_args++];
}
int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@ -935,6 +950,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
smallint doall;
smallint notitle;
INIT_G();
/* we want wait() to be interruptible */
signal_no_SA_RESTART_empty_mask(SIGINT, record_signo);
signal_no_SA_RESTART_empty_mask(SIGTERM, record_signo);
@ -944,8 +961,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
opts_for_fsck = doall = notitle = 0;
devices = NULL;
num_devices = 0;
new_args(); /* args[0] = NULL, will be replaced by fsck.<type> */
/* instance_list = NULL; - in bss, so already zeroed */
new_args(); /* G.args[0] = NULL, will be replaced by fsck.<type> */
/* G.instance_list = NULL; - in bss, so already zeroed */
while (*++argv) {
int j;
@ -994,13 +1011,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
goto next_arg;
#endif
case 'V':
verbose++;
G.verbose++;
break;
case 'N':
noexecute = 1;
G.noexecute = 1;
break;
case 'R':
skip_root = 1;
G.skip_root = 1;
break;
case 'T':
notitle = 1;
@ -1009,13 +1026,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
like_mount = 1;
break; */
case 'P':
parallel_root = 1;
G.parallel_root = 1;
break;
case 's':
serialize = 1;
G.serialize = 1;
break;
case 't':
if (fstype)
if (G.fstype)
bb_show_usage();
if (arg[++j])
tmp = &arg[j];
@ -1023,8 +1040,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
tmp = *argv;
else
bb_show_usage();
fstype = xstrdup(tmp);
compile_fs_type(fstype);
G.fstype = xstrdup(tmp);
compile_fs_type(G.fstype);
goto next_arg;
case '?':
bb_show_usage();
@ -1045,12 +1062,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
}
}
if (getenv("FSCK_FORCE_ALL_PARALLEL"))
force_all_parallel = 1;
G.force_all_parallel = 1;
tmp = getenv("FSCK_MAX_INST");
G.max_running = INT_MAX;
if (tmp)
max_running = xatoi(tmp);
new_args(); /* args[num_args - 2] will be replaced by <device> */
new_args(); /* args[num_args - 1] is the last, NULL element */
G.max_running = xatoi(tmp);
new_args(); /* G.args[G.num_args - 2] will be replaced by <device> */
new_args(); /* G.args[G.num_args - 1] is the last, NULL element */
if (!notitle)
puts("fsck (busybox "BB_VER", "BB_BT")");
@ -1062,10 +1080,10 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
fstab = "/etc/fstab";
load_fs_info(fstab);
/*interactive = (num_devices == 1) | serialize;*/
/*interactive = (num_devices == 1) | G.serialize;*/
if (num_devices == 0)
/*interactive =*/ serialize = doall = 1;
/*interactive =*/ G.serialize = doall = 1;
if (doall)
return check_all();
@ -1081,13 +1099,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
fs = create_fs_device(devices[i], "", "auto", NULL, -1);
fsck_device(fs /*, interactive */);
if (serialize
|| (max_running && (num_running >= max_running))
if (G.serialize
|| (G.num_running >= G.max_running)
) {
int exit_status = wait_one(0);
if (exit_status >= 0)
status |= exit_status;
if (verbose > 1)
if (G.verbose > 1)
puts("----------------------------------");
}
}

View File

@ -9,24 +9,26 @@
* This file can be redistributed under the terms of the GNU General
* Public License
*/
//config:config LSATTR
//config: bool "lsattr"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: lsattr lists the file attributes on a second extended file system.
/*
* History:
* 93/10/30 - Creation
* 93/11/13 - Replace stat() calls by lstat() to avoid loops
* 94/02/27 - Integrated in Ted's distribution
* 98/12/29 - Display version info only when -V specified (G M Sipe)
*/
//applet:IF_LSATTR(APPLET(lsattr, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o
//usage:#define lsattr_trivial_usage
//usage: "[-Radlv] [FILE]..."
//usage:#define lsattr_full_usage "\n\n"
//usage: "List file attributes on an ext2 fs\n"
//usage: "List ext2 file attributes\n"
//usage: "\n -R Recurse"
//usage: "\n -a Don't hide entries starting with ."
//usage: "\n -d List directory entries instead of contents"
//usage: "\n -l List long flag names"
//usage: "\n -v List the file's version/generation number"
//usage: "\n -v List version/generation number"
#include "libbb.h"
#include "e2fs_lib.h"

View File

@ -6,6 +6,33 @@
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config TUNE2FS
//config: bool "tune2fs"
//config: default n # off: it is too limited compared to upstream version
//config: help
//config: tune2fs allows the system administrator to adjust various tunable
//config: filesystem parameters on Linux ext2/ext3 filesystems.
//applet:IF_TUNE2FS(APPLET(tune2fs, BB_DIR_SBIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_TUNE2FS) += tune2fs.o
//usage:#define tune2fs_trivial_usage
//usage: "[-c MAX_MOUNT_COUNT] "
////usage: "[-e errors-behavior] [-g group] "
//usage: "[-i DAYS] "
////usage: "[-j] [-J journal-options] [-l] [-s sparse-flag] "
////usage: "[-m reserved-blocks-percent] [-o [^]mount-options[,...]] "
////usage: "[-r reserved-blocks-count] [-u user] "
//usage: "[-C MOUNT_COUNT] "
//usage: "[-L LABEL] "
////usage: "[-M last-mounted-dir] [-O [^]feature[,...]] "
////usage: "[-T last-check-time] [-U UUID] "
//usage: "BLOCKDEV"
//usage:
//usage:#define tune2fs_full_usage "\n\n"
//usage: "Adjust filesystem options on ext[23] filesystems"
#include "libbb.h"
#include <linux/fs.h>
#include "bb_e2fs_defs.h"
@ -27,22 +54,6 @@ do { \
#define FETCH_LE32(field) \
(sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size())
//usage:#define tune2fs_trivial_usage
//usage: "[-c MAX_MOUNT_COUNT] "
////usage: "[-e errors-behavior] [-g group] "
//usage: "[-i DAYS] "
////usage: "[-j] [-J journal-options] [-l] [-s sparse-flag] "
////usage: "[-m reserved-blocks-percent] [-o [^]mount-options[,...]] "
////usage: "[-r reserved-blocks-count] [-u user] "
//usage: "[-C MOUNT_COUNT] "
//usage: "[-L LABEL] "
////usage: "[-M last-mounted-dir] [-O [^]feature[,...]] "
////usage: "[-T last-check-time] [-U UUID] "
//usage: "BLOCKDEV"
//usage:
//usage:#define tune2fs_full_usage "\n\n"
//usage: "Adjust filesystem options on ext[23] filesystems"
enum {
OPT_L = 1 << 0, // label
OPT_c = 1 << 1, // max mount count

View File

@ -125,6 +125,7 @@
//usage: "\n -w Ignore all whitespace"
#include "libbb.h"
#include "common_bufsiz.h"
#if 0
# define dbg_error_msg(...) bb_error_msg(__VA_ARGS__)
@ -748,6 +749,7 @@ static int diffreg(char *file[2])
fp[i] = fdopen(fd, "r");
}
setup_common_bufsiz();
while (1) {
const size_t sz = COMMON_BUFSIZE / 2;
char *const buf0 = bb_common_bufsiz1;

View File

@ -23,6 +23,7 @@
//usage:#define ed_full_usage ""
#include "libbb.h"
#include "common_bufsiz.h"
typedef struct LINE {
struct LINE *next;
@ -35,8 +36,8 @@ typedef struct LINE {
#define searchString bb_common_bufsiz1
enum {
USERSIZE = sizeof(searchString) > 1024 ? 1024
: sizeof(searchString) - 1, /* max line length typed in by user */
USERSIZE = COMMON_BUFSIZE > 1024 ? 1024
: COMMON_BUFSIZE - 1, /* max line length typed in by user */
INITBUF_SIZE = 1024, /* initial buffer size */
};
@ -66,6 +67,7 @@ struct globals {
#define lines (G.lines )
#define marks (G.marks )
#define INIT_G() do { \
setup_common_bufsiz(); \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
} while (0)

View File

@ -372,10 +372,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
xmove_fd(xopen_stdin(argv[1]), STDIN_FILENO);
}
}
if (argv[0]) {
oldname = xstrdup(argv[0]);
newname = xstrdup(argv[0]);
}
// Loop through the lines in the patch
for(;;) {
@ -486,10 +482,10 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
// or if new hunk is empty (zero context) after patching
if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) {
name = reverse ? newname : oldname;
empty++;
empty = 1;
}
// handle -p path truncation.
// Handle -p path truncation.
for (i = 0, s = name; *s;) {
if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i)
break;
@ -500,6 +496,9 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
i++;
name = s;
}
// If "patch FILE_TO_PATCH", completely ignore name from patch
if (argv[0])
name = argv[0];
if (empty) {
// File is empty after the patches have been applied

View File

@ -86,6 +86,7 @@
//usage: "bar\n"
#include "libbb.h"
#include "common_bufsiz.h"
#include "xregex.h"
#if 0
@ -113,7 +114,7 @@ typedef struct sed_cmd_s {
int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($). -2-N = +N */
int end_line_orig;
FILE *sw_file; /* File (sw) command writes to, -1 for none. */
FILE *sw_file; /* File (sw) command writes to, NULL for none. */
char *string; /* Data string for (saicytb) commands. */
unsigned which_match; /* (s) Which match to replace (0 for all) */
@ -161,11 +162,10 @@ struct globals {
int len; /* Space allocated */
} pipeline;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
struct BUG_G_too_big {
char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
};
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
G.sed_cmd_tail = &G.sed_cmd_head; \
} while (0)
@ -181,7 +181,7 @@ static void sed_free_and_close_stuff(void)
sed_cmd_t *sed_cmd_next = sed_cmd->next;
if (sed_cmd->sw_file)
xprint_and_close_file(sed_cmd->sw_file);
fclose(sed_cmd->sw_file);
if (sed_cmd->beg_match) {
regfree(sed_cmd->beg_match);
@ -218,23 +218,33 @@ static void cleanup_outname(void)
/* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */
static void parse_escapes(char *dest, const char *string, int len, char from, char to)
static unsigned parse_escapes(char *dest, const char *string, int len, char from, char to)
{
char *d = dest;
int i = 0;
if (len == -1)
len = strlen(string);
while (i < len) {
if (string[i] == '\\') {
if (!to || string[i+1] == from) {
*dest++ = to ? to : string[i+1];
if ((*d = to ? to : string[i+1]) == '\0')
return d - dest;
i += 2;
d++;
continue;
}
*dest++ = string[i++];
i++; /* skip backslash in string[] */
*d++ = '\\';
/* fall through: copy next char verbatim */
}
/* TODO: is it safe wrt a string with trailing '\\' ? */
*dest++ = string[i++];
if ((*d = string[i++]) == '\0')
return d - dest;
d++;
}
*dest = '\0';
*d = '\0';
return d - dest;
}
static char *copy_parsing_escapes(const char *string, int len)
@ -245,9 +255,8 @@ static char *copy_parsing_escapes(const char *string, int len)
/* sed recognizes \n */
/* GNU sed also recognizes \t and \r */
for (s = "\nn\tt\rr"; *s; s += 2) {
parse_escapes(dest, string, len, s[1], s[0]);
len = parse_escapes(dest, string, len, s[1], s[0]);
string = dest;
len = strlen(dest);
}
return dest;
}
@ -428,8 +437,11 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
/* Write to file */
case 'w':
{
char *temp;
idx += parse_file_cmd(/*sed_cmd,*/ substr+idx, &temp);
char *fname;
idx += parse_file_cmd(/*sed_cmd,*/ substr+idx+1, &fname);
sed_cmd->sw_file = xfopen_for_write(fname);
sed_cmd->sw_last_char = '\n';
free(fname);
break;
}
/* Ignore case (gnu exension) */
@ -470,7 +482,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
*/
static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
{
static const char cmd_letters[] = "saicrw:btTydDgGhHlnNpPqx={}";
static const char cmd_letters[] ALIGN1 = "saicrw:btTydDgGhHlnNpPqx={}";
enum {
IDX_s = 0,
IDX_a,
@ -501,9 +513,11 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
IDX_rbrace,
IDX_nul
};
struct chk { char chk[sizeof(cmd_letters)-1 == IDX_nul ? 1 : -1]; };
unsigned idx;
unsigned idx = strchrnul(cmd_letters, sed_cmd->cmd) - cmd_letters;
BUILD_BUG_ON(sizeof(cmd_letters)-1 != IDX_nul);
idx = strchrnul(cmd_letters, sed_cmd->cmd) - cmd_letters;
/* handle (s)ubstitution command */
if (idx == IDX_s) {
@ -511,6 +525,8 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
}
/* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */
else if (idx <= IDX_c) { /* a,i,c */
unsigned len;
if (idx < IDX_c) { /* a,i */
if (sed_cmd->end_line || sed_cmd->end_match)
bb_error_msg_and_die("command '%c' uses only one address", sed_cmd->cmd);
@ -524,10 +540,11 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
break;
cmdstr++;
}
sed_cmd->string = xstrdup(cmdstr);
len = strlen(cmdstr);
sed_cmd->string = copy_parsing_escapes(cmdstr, len);
cmdstr += len;
/* "\anychar" -> "anychar" */
parse_escapes(sed_cmd->string, sed_cmd->string, strlen(cmdstr), '\0', '\0');
cmdstr += strlen(cmdstr);
parse_escapes(sed_cmd->string, sed_cmd->string, -1, '\0', '\0');
}
/* handle file cmds: (r)ead */
else if (idx <= IDX_w) { /* r,w */
@ -559,8 +576,8 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
cmdstr += parse_regex_delim(cmdstr, &match, &replace)+1;
/* \n already parsed, but \delimiter needs unescaping. */
parse_escapes(match, match, strlen(match), i, i);
parse_escapes(replace, replace, strlen(replace), i, i);
parse_escapes(match, match, -1, i, i);
parse_escapes(replace, replace, -1, i, i);
sed_cmd->string = xzalloc((strlen(match) + 1) * 2);
for (i = 0; match[i] && replace[i]; i++) {
@ -939,13 +956,22 @@ static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char l
*last_puts_char = lpc;
}
static void flush_append(char *last_puts_char, char last_gets_char)
static void flush_append(char *last_puts_char)
{
char *data;
/* Output appended lines. */
while ((data = (char *)llist_pop(&G.append_head))) {
puts_maybe_newline(data, G.nonstdout, last_puts_char, last_gets_char);
while ((data = (char *)llist_pop(&G.append_head)) != NULL) {
/* Append command does not respect "nonterminated-ness"
* of last line. Try this:
* $ echo -n "woot" | sed -e '/woot/a woo' -
* woot
* woo
* (both lines are terminated with \n)
* Therefore we do not propagate "last_gets_char" here,
* pass '\n' instead:
*/
puts_maybe_newline(data, G.nonstdout, last_puts_char, '\n');
free(data);
}
}
@ -953,13 +979,13 @@ static void flush_append(char *last_puts_char, char last_gets_char)
/* Get next line of input from G.input_file_list, flushing append buffer and
* noting if we ran out of files without a newline on the last line we read.
*/
static char *get_next_line(char *gets_char, char *last_puts_char, char last_gets_char)
static char *get_next_line(char *gets_char, char *last_puts_char)
{
char *temp = NULL;
int len;
char gc;
flush_append(last_puts_char, last_gets_char);
flush_append(last_puts_char);
/* will be returned if last line in the file
* doesn't end with either '\n' or '\0' */
@ -1037,7 +1063,7 @@ static void process_files(void)
int substituted;
/* Prime the pump */
next_line = get_next_line(&next_gets_char, &last_puts_char, '\n' /*last_gets_char*/);
next_line = get_next_line(&next_gets_char, &last_puts_char);
/* Go through every line in each file */
again:
@ -1051,7 +1077,7 @@ static void process_files(void)
/* Read one line in advance so we can act on the last line,
* the '$' address */
next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
next_line = get_next_line(&next_gets_char, &last_puts_char);
linenum++;
/* For every line, go through all the commands */
@ -1278,7 +1304,7 @@ static void process_files(void)
free(pattern_space);
pattern_space = next_line;
last_gets_char = next_gets_char;
next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
next_line = get_next_line(&next_gets_char, &last_puts_char);
substituted = 0;
linenum++;
break;
@ -1314,7 +1340,7 @@ static void process_files(void)
pattern_space[len] = '\n';
strcpy(pattern_space + len+1, next_line);
last_gets_char = next_gets_char;
next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char);
next_line = get_next_line(&next_gets_char, &last_puts_char);
linenum++;
break;
}
@ -1418,7 +1444,7 @@ static void process_files(void)
/* Delete and such jump here. */
discard_line:
flush_append(&last_puts_char, last_gets_char);
flush_append(&last_puts_char /*,last_gets_char*/);
free(pattern_space);
goto again;
@ -1504,12 +1530,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
while (opt_f) { // -f
char *line;
FILE *cmdfile;
cmdfile = xfopen_for_read(llist_pop(&opt_f));
cmdfile = xfopen_stdin(llist_pop(&opt_f));
while ((line = xmalloc_fgetline(cmdfile)) != NULL) {
add_cmd(line);
free(line);
}
fclose(cmdfile);
fclose_if_not_stdin(cmdfile);
}
/* if we didn't get a pattern from -e or -f, use argv[0] */
if (!(opt & 0x30)) {

View File

@ -251,7 +251,7 @@ enum {
// cmds modifying text[]
// vda: removed "aAiIs" as they switch us into insert mode
// and remembering input for replay after them makes no sense
static const char modifying_cmds[] = "cCdDJoOpPrRxX<>~";
static const char modifying_cmds[] ALIGN1 = "cCdDJoOpPrRxX<>~";
#endif
enum {

View File

@ -5,49 +5,55 @@
# Requires the programs (ar, tar, gzip, and the pager more or less).
#
usage() {
echo "Usage: undeb -c package.deb <Print control file info>"
echo " undeb -l package.deb <List contents of deb package>"
echo " undeb -x package.deb /foo/boo <Extract deb package to this directory,"
echo " put . for current directory>"
exit
cat <<EOF
Usage: undeb -c package.deb <Print control file info>
undeb -l package.deb <List contents of deb package>
undeb -x package.deb /foo/boo <Extract deb package to this directory,
put . for current directory>
EOF
exit
}
deb=$2
exist() {
if [ "$deb" = "" ]; then
usage
elif [ ! -s "$deb" ]; then
echo "Can't find $deb!"
exit
fi
if [ -z "${deb}" ]; then
usage
elif [ ! -s "${deb}" ]; then
echo "Can't find ${deb}!"
exit 1
fi
}
if [ "$1" = "" ]; then
usage
if [ -z "$1" ]; then
usage
elif [ "$1" = "-l" ]; then
exist
type more >/dev/null 2>&1 && pager=more
type less >/dev/null 2>&1 && pager=less
[ "$pager" = "" ] && echo "No pager found!" && exit
(ar -p $deb control.tar.gz | tar -xzO *control ; echo -e "\nPress enter to scroll, q to Quit!\n" ; ar -p $deb data.tar.gz | tar -tzv) | $pager
exit
exist
type more >/dev/null 2>&1 && pager=more
type less >/dev/null 2>&1 && pager=less
[ -z "${pager}" ] && echo "No pager found!" && exit 1
(
ar -p "${deb}" control.tar.gz | tar -xzO *control
printf "\nPress enter to scroll, q to Quit!\n\n"
ar -p "${deb}" data.tar.gz | tar -tzv
) | ${pager}
exit
elif [ "$1" = "-c" ]; then
exist
ar -p $deb control.tar.gz | tar -xzO *control
exit
exist
ar -p "${deb}" control.tar.gz | tar -xzO *control
exit
elif [ "$1" = "-x" ]; then
exist
if [ "$3" = "" ]; then
usage
elif [ ! -d "$3" ]; then
echo "No such directory $3!"
exit
fi
ar -p $deb data.tar.gz | tar -xzvpf - -C $3 || exit
echo
echo "Extracted $deb to $3!"
exit
exist
if [ -z "$3" ]; then
usage
elif [ ! -d "$3" ]; then
echo "No such directory $3!"
exit 1
fi
ar -p "${deb}" data.tar.gz | tar -xzvpf - -C "$3" || exit
echo
echo "Extracted ${deb} to $3!"
exit
else
usage
usage
fi

View File

@ -5,44 +5,49 @@
# Requires the programs (cpio, gzip, and the pager more or less).
#
usage() {
echo "Usage: unrpm -l package.rpm <List contents of rpm package>"
echo " unrpm -x package.rpm /foo/boo <Extract rpm package to this directory,"
echo " put . for current directory>"
exit
cat <<EOF
Usage: unrpm -l package.rpm <List contents of rpm package>
unrpm -x package.rpm /foo/boo <Extract rpm package to this directory,
put . for current directory>
EOF
exit
}
rpm=$2
exist() {
if [ "$rpm" = "" ]; then
usage
elif [ ! -s "$rpm" ]; then
echo "Can't find $rpm!"
exit
fi
if [ -z "${rpm}" ]; then
usage
elif [ ! -s "${rpm}" ]; then
echo "Can't find ${rpm}!"
exit 1
fi
}
if [ "$1" = "" ]; then
usage
if [ -z "$1" ]; then
usage
elif [ "$1" = "-l" ]; then
exist
type more >/dev/null 2>&1 && pager=more
type less >/dev/null 2>&1 && pager=less
[ "$pager" = "" ] && echo "No pager found!" && exit
(echo -e "\nPress enter to scroll, q to Quit!\n" ; rpm2cpio $rpm | cpio -tv --quiet) | $pager
exit
exist
type more >/dev/null 2>&1 && pager=more
type less >/dev/null 2>&1 && pager=less
[ "$pager" = "" ] && echo "No pager found!" && exit
(
printf "\nPress enter to scroll, q to Quit!\n\n"
rpm2cpio "${rpm}" | cpio -tv --quiet
) | ${pager}
exit
elif [ "$1" = "-x" ]; then
exist
if [ "$3" = "" ]; then
usage
elif [ ! -d "$3" ]; then
echo "No such directory $3!"
exit
fi
rpm2cpio $rpm | (umask 0 ; cd $3 ; cpio -idmuv) || exit
echo
echo "Extracted $rpm to $3!"
exit
exist
if [ -z "$3" ]; then
usage
elif [ ! -d "$3" ]; then
echo "No such directory $3!"
exit 1
fi
rpm2cpio "${rpm}" | (umask 0 ; cd "$3" ; cpio -idmuv) || exit
echo
echo "Extracted ${rpm} to $3!"
exit
else
usage
usage
fi

View File

@ -36,10 +36,10 @@ service accordingly. In effect, it allows you to unplug/plug-to-different-networ
and have your IP properly re-negotiated at once.
var_service/dhcp_if_pinger -
Uses var_service/dhcp_if's data (/var/service/dhcp_if/dhcp_if.out file)
to determine router IP. Pings it. If ping fails, restarts /var/service/dhcp_if
service. Basically, an example of watchdog service for networks
which are not reliable and need babysitting.
Uses var_service/dhcp_if's data to determine router IP. Pings it.
If ping fails, restarts /var/service/dhcp_if service.
Basically, an example of watchdog service for networks which are not reliable
and need babysitting.
var_service/fw -
A *one-shot* service which reconfigures network based on current known state

View File

@ -29,6 +29,6 @@ test "$ip" || exit 1
{
for n in $ntpsrv; do
echo "let cfg=cfg+1"
echo "ntpip[\$cfg]='$n'";
echo "ntpip[\$cfg]='$n'"
done
} >"$1"

View File

@ -36,7 +36,7 @@ service=${PWD##*/}
file_ipconf="$service.ipconf"
file_ntpconf="$service.ntpconf"
dir_ipconf="/var/run/service/fw"
dir_ntpconf="/var/run/service/ntp"
dir_ntpconf="/var/run/service/ntpd"
exec >/dev/null
#exec >>"$0.out" #debug
@ -47,7 +47,7 @@ echo "`date`: Params: $*"
if test x"$1" != x"bound" && test x"$1" != x"renew" ; then
# Reconfigure network with this interface disabled
echo "Deconfiguring"
rm "$service.out"
rm "env.out"
rm "$file_ipconf"
rm "$file_ntpconf"
rm "$dir_ipconf/$file_ipconf"
@ -57,7 +57,8 @@ if test x"$1" != x"bound" && test x"$1" != x"renew" ; then
fi
# Bound: we've got the lease
#env >"$service.out" # debug
# Record information for e.g. dhcp_$IF_pinger service
env >"env.out"
./convert2ipconf "$file_ipconf"
# Reconfigure routing and firewall if needed
@ -69,7 +70,7 @@ if test $? != 0; then
sv u /var/service/fw
fi
if test -d /var/service/ntp; then
if test -d /var/service/ntpd; then
./convert2ntpconf "$file_ntpconf"
# Reconfigure ntp server addresses if needed
diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1
@ -77,7 +78,7 @@ if test -d /var/service/ntp; then
echo "Reconfiguring ntp"
mkdir -p "$dir_ntpconf" 2>/dev/null
cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf"
sv t /var/service/ntp
sv u /var/service/ntp
sv t /var/service/ntpd
sv u /var/service/ntpd
fi
fi

View File

@ -0,0 +1,17 @@
#!/bin/sh
# executed when service is taken down ("sv d .")
service=${PWD##*/}
file_ipconf="$service.ipconf"
file_ntpconf="$service.ntpconf"
dir_ipconf="/var/run/service/fw"
dir_ntpconf="/var/run/service/ntpd"
# Reconfigure network with this interface disabled
echo "Finish: deconfiguring"
rm "env.out"
rm "$file_ipconf"
rm "$file_ntpconf"
rm "$dir_ipconf/$file_ipconf"
rm "$dir_ntpconf/$file_ntpconf"
sv u /var/service/fw

View File

@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm logdir
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger

View File

@ -1,23 +1,47 @@
#!/bin/sh
delay=67
# How often to test, seconds
ping_time=67
# "One ping, must have reply in 1 sec"
ping_opts="-c1 -W1 -w1"
# If ping failed, how soon to retry
retry_time=5
# Reinit after this many consecutive ping error
max_fail=5
# Interface whose DHCP data to use
if=${PWD##*/dhcp_}
if=${if%%_pinger}
msg() {
echo "`date '+%Y-%m-%d %H:%M:%S'` $*" >>"$0.log"
}
if test -f "$0.log"; then
tail -999 "$0.log" >"$0.log.new"
mv "$0.log.new" "$0.log"
fi
test -f "/var/service/dhcp_$if/dhcp_$if.out" || exec env - sleep "$delay"
. "/var/service/dhcp_$if/dhcp_$if.out"
test x"$router" != x"" || exec env - sleep "$delay"
test -f "/var/service/dhcp_$if/env.out" || exec env - sleep "$ping_time"
#echo "`date '+%Y-%m-%d %H:%M:%S'` Testing ping -c3 $router" >>"$0.log"
ping -c3 "$router" && exec env - sleep "$delay"
. "/var/service/dhcp_$if/env.out"
test x"$router" != x"" || exec env - sleep "$ping_time"
echo "`date '+%Y-%m-%d %H:%M:%S'` Restarting /var/service/dhcp_$if" >>"$0.log"
sv t "/var/service/dhcp_$if"
#msg "Pinging $router"
failcnt=0
while true; do
ping $ping_opts "$router" && exec env - sleep "$ping_time"
: $((failcnt++))
msg "Failed to ping $router, fail count:$failcnt"
test $failcnt -ge $max_fail && break
env - sleep "$retry_time"
done
exec env - sleep "$delay"
test -d "/var/service/dhcp_$if" && {
msg "Restarting /var/service/dhcp_$if"
sv t "/var/service/dhcp_$if"
}
test -d "/var/service/supplicant_$if" && {
msg "Restarting /var/service/supplicant_$if"
sv t "/var/service/supplicant_$if"
}
exec env - sleep "$ping_time"

View File

@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm logdir
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger

View File

@ -62,7 +62,7 @@ umask 077
# Make sure rundir/ exists
mkdir -p "$rundir" 2>/dev/null
chown -R "$user:" "$rundir"
chown -R "$user": "$rundir"
chmod -R a=rX "$rundir"
rm -rf rundir 2>/dev/null
ln -s "$rundir" rundir

View File

@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm logdir
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger

View File

@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm logdir
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger

View File

@ -8,6 +8,9 @@ pwd="$PWD"
if="${PWD##*/ifplugd_}"
echo "* Upping iface $if"
ip link set dev "$if" up
echo "* Starting ifplugd on $if [$$]"
exec \
env - PATH="$PATH" \

View File

@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm logdir
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger

View File

@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm logdir
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger

View File

@ -15,7 +15,7 @@ default_p_opt="-p 0.$pool -p 1.$pool -p 2.$pool -p 3.$pool"
# Make sure rundir/ exists
mkdir -p "$rundir" 2>/dev/null
chown -R "$user:" "$rundir"
chown -R "$user": "$rundir"
chmod -R a=rX "$rundir"
rm -rf rundir 2>/dev/null
ln -s "$rundir" rundir

View File

@ -6,7 +6,7 @@ logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm logdir
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger

View File

@ -0,0 +1,5 @@
The real README file is one directory up.
This directory's run script can have useful comments.
If it doesn't but you feel it should, please send a patch
to busybox's mailing list.

View File

@ -0,0 +1,24 @@
#!/bin/sh
# convert:
#interface=eth1
#ip=169.254.x.y
# into:
#let cfg=cfg+1
#if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=...
exec >/dev/null
#exec >"$0.out" # debug
exec 2>&1
test "$interface" || exit 1
test "$ip" || exit 1
{
echo "let cfg=cfg+1"
test "$interface" && echo "if[\$cfg]='$interface'"
test "$ip" && echo "ip[\$cfg]='$ip'"
test "$ip" && echo "ipmask[\$cfg]='$ip/16'"
} >"$1"

View File

@ -0,0 +1,13 @@
#!/bin/sh
# executed when service is taken down ("sv d .")
service=${PWD##*/}
file_ipconf="$service.ipconf"
dir_ipconf="/var/run/service/fw"
# Reconfigure network with this interface disabled
echo "Finish: deconfiguring"
rm "env.out"
rm "$file_ipconf"
rm "$dir_ipconf/$file_ipconf"
sv u /var/service/fw

View File

@ -0,0 +1,21 @@
#!/bin/sh
user=logger
logdir="/var/log/service/`(cd ..;basename $PWD)`"
mkdir -p "$logdir" 2>/dev/null
chown -R "$user": "$logdir"
chmod -R go-rwxst,u+rwX "$logdir"
rm -rf logdir
ln -s "$logdir" logdir
# make this dir accessible to logger
chmod a+rX .
exec >/dev/null
exec 2>&1
exec \
env - PATH="$PATH" \
softlimit \
setuidgid "$user" \
svlogd -tt "$logdir"

View File

@ -0,0 +1,4 @@
#!/bin/sh
cd log/logdir || exit 1
cat @* current | $PAGER

View File

@ -0,0 +1,20 @@
#!/bin/sh
exec 2>&1
exec </dev/null
pwd="$PWD"
if="${PWD##*/zcip_}"
echo "* Upping iface $if"
ip link set dev "$if" up
echo "* Starting zcip"
exec \
env - PATH="$PATH" \
softlimit \
setuidgid root \
zcip -fvv \
"$if" \
"$pwd/zcip_handler"

Some files were not shown because too many files have changed in this diff Show More