Compare commits

..
Author SHA1 Message Date
Denys Vlasenko 1dd2685dcc Bump version to 1.30.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 15:25:41 +01:00
Rostislav Skudnov c199472e3a chcon: Fix typo in ACTION_RECURSE
Signed-off-by: Rostislav Skudnov <rostislav@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko d7a622b572 lineedit: fix SEGV in isk, hexedit, ed, closes 11661
fdisk, hexedit and ed calls read_line_edit in libbb/lineedit.c with NULL
as first argument. On line 2373 of lineedit.c of busybox version 1.29.3,
state->hist_file is referenced without checking the state->flag.

This causes segmentation fault on fdisk, hexedit and ed on ARM Cortex-A9.
It somehow works on x86_64.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Ari Sundholm 256ee62224 grep: fix -x -v with certain pattern orders
We found out that busybox -x -v is a bit broken:

ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -e 'aa.*' -e '.*bb.*'
  aa bb cc
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -v -e 'aa.*' -e '.*bb.*'
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -e '.*aa.*' -e 'bb.*'
  aa bb cc
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -v -e '.*aa.*' -e 'bb.*'
  aa bb cc

Last one is wrong.

This patch fixes the issue by making sure that the variable 'found'
never makes a transition from 1 to 0, as this would mean that
grep previously found a match on this input line.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Niko Vähäsarja <niko@tuxera.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 5c6b9165e7 bc: implement pass-by-reference code from upstream
function                                             old     new   delta
zxc_program_popResultAndCopyToVar                    298     493    +195
bc_vec_pushIndex                                       -      75     +75
zxc_vm_process                                       859     928     +69
xc_program_dereference                                 -      66     +66
bc_vec_npush                                           -      65     +65
zbc_num_s                                            239     249     +10
zxc_program_num                                     1024    1032      +8
zbc_num_divmod                                       150     156      +6
xc_program_search                                    143     146      +3
zxc_program_assign                                   392     389      -3
zdc_program_execStr                                  520     517      -3
xc_program_pushVar                                   198     195      -3
zxc_program_exec                                    4101    4092      -9
zbc_program_call                                     318     308     -10
zbc_func_insert                                      120     104     -16
zbc_parse_stmt_possibly_auto                        1460    1439     -21
bc_vec_push                                           53      12     -41
xc_parse_pushIndex                                    61      18     -43
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 6/9 up/down: 497/-149)          Total: 348 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Bernhard Reutner-Fischer 8296334c1f ip link: Fix vlan proto, closes 8261 and 11638
The proto has to be passed in network byte-order.
While at it allow for
 ip link add link eth0 name eth0.2.24 type vlan proto 802.1ad id 24
 ip link del link eth0 name eth0.2.24 type vlan proto 802.1ad id 24
The del was lacking a dev_str and thus errored out. Fix by using
name/dev counterpart as fallback.

The proto identifier 802.1Q was not recognized, just it's lowercase
variant, fix that too.

function                                             old     new   delta
do_add_or_delete                                    1275    1376    +101
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 101/0)             Total: 101 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 7f8f20714a ip link: fix mismatched enums in vlan_parse_opt(), closes 11631
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Brian Foley b65db51ac1 sed: Fix backslash parsing for 'w' command arg
If there's any whitespace between w and the filename, parse_file_cmd
writes to the wrong offset when trying to fix up backslashes.

This can be seen in the asan build with busybox sed -e 'w 0\\'

Signed-off-by: Brian Foley <bpfoley@google.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Mark Marshall fa86b27e24 capability: fix string comparison in cap_name_to_number
The result of strcasecmp was being used incorrectly.  This function
returns 0 if the strings match.

Signed-off-by: Mark Marshall <mark.marshall@omicronenergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko b570954363 bc: code shrink
function                                             old     new   delta
xc_parse_pushInst_and_Index                            -      16     +16
zbc_parse_expr                                      1818    1816      -2
xc_parse_pushIndex                                    65      61      -4
zbc_parse_pushSTR                                     63      58      -5
zbc_parse_name                                       448     442      -6
xc_parse_pushNUM                                      74      67      -7
zdc_parse_expr                                       479     470      -9
bc_parse_pushJUMP_ZERO                                21      12      -9
bc_parse_pushJUMP                                     21      12      -9
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/8 up/down: 16/-51)            Total: -35 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko c28dc0b58b bc: remove "empty expression" check/message, parsing fails in these cases anyway
function                                             old     new   delta
zbc_parse_expr                                      1848    1818     -30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 60fb586597 bc: zbc_parse_expr_empty_ok() is unused except by zbc_parse_expr(), fold it in
function                                             old     new   delta
zbc_parse_expr                                      1865    1848     -17

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 715273a992 bc: disallow invalid syntax like "{ print 1 print 2 }"
statement parsing must NOT eat the terminator: caller needs to know
what it was, to correctly decide whether it is a valid one.

function                                             old     new   delta
zxc_program_read                                       -     234    +234
zdc_program_printStream                                -     144    +144
zbc_parse_stmt_possibly_auto                        1413    1460     +47
zxc_vm_process                                       869     859     -10
zxc_program_exec                                    4116    4101     -15
zdc_program_asciify                                  368       -    -368
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/2 up/down: 425/-393)           Total: 32 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Martijn Dekker a89ec68a8a ls: make -i compatible with coreutils: don't follow symlink by default
Signed-off-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 5cea086bbf bc: shorten "limits" output
text	   data	    bss	    dec	    hex	filename
 979016	    485	   7296	 986797	  f0ead	busybox_old
 978959	    485	   7296	 986740	  f0e74	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 9c36a02f4d bc: formatting changes, added a FIXME comment, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 5b35d599e8 bc: support void functions (GNU compat)
function                                             old     new   delta
xc_program_print                                       -     689    +689
zxc_vm_process                                       814     869     +55
zxc_program_exec                                    4098    4116     +18
zxc_program_assign                                   385     392      +7
bc_result_free                                        43      46      +3
zxc_program_binOpPrep                                243     245      +2
zdc_program_execStr                                  518     520      +2
zxc_program_print                                    683       -    -683
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 6/0 up/down: 776/-683)           Total: 93 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko c7679c759a dc: fit returning of string
function                                             old     new   delta
zxc_program_exec                                    4087    4098     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko d2651fb775 dc: fix '?'
function                                             old     new   delta
zdc_parse_expr                                       470     479      +9
zxc_vm_process                                       839     814     -25
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 9/-25)             Total: -16 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko fb001145e1 bc: eliminate struct BcInstPtr::results_len_before_call, it is redundant
function                                             old     new   delta
zbc_program_call                                     332     318     -14
zxc_program_exec                                    4147    4087     -60
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-74)             Total: -74 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko ef2e6a8062 bc: add a palceholder comment for "void" return
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko f40467d369 bc: remove extra div/0 test, remove test for string function parameter
function                                             old     new   delta
zbc_program_call                                     354     332     -22
zxc_program_assign                                   426     385     -41
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-63)             Total: -63 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 56e09e93bd bc: fix "...; return}" to work, disallow "return ()"
function                                             old     new   delta
zbc_parse_expr                                        24    1865   +1841
zbc_parse_stmt_possibly_auto                        1425    1413     -12
bc_parse_expr_empty_ok                              1843       -   -1843
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 1841/-1855)        Total: -14 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 18351b4a89 bc: make error line number also size_t, like everything else
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko a8ec556458 bc: generate large bc tests on the fly, -5 mbytes in the git tree
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 7dd6ba12f7 bc: speed up string printing, fix print ""
function                                             old     new   delta
static.esc                                             -       9      +9
zxc_program_print                                    681     683      +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 11/0)               Total: 11 bytes
   text	   data	    bss	    dec	    hex	filename
 979144	    485	   7296	 986925	  f0f2d	busybox_old
 979062	    485	   7296	 986843	  f0edb	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko f23c04af2d bc: upstream fixes
function                                             old     new   delta
bc_parse_expr_empty_ok                              1764    1843     +79
bc_error_at                                            -      62     +62
bc_parse_inst_isLeaf                                   -      30     +30
zbc_func_insert                                      100     120     +20
bc_error_bad_function_definition                       -      10     +10
bc_error_bad_assignment                                -      10     +10
zxc_lex_next                                        1608    1614      +6
ok_in_expr                                            30       -     -30
zxc_vm_process                                       874     839     -35
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 3/1 up/down: 217/-65)           Total: 152 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko c3de036da9 bc: in xc_read_line(), check ^C on NUL input bytes too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 2123ceed18 bc: remove superfluous assigment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 8a7411fcc8 bc: support ibase up to 36 (GNU compat)
function                                             old     new   delta
zxc_program_num                                      995    1018     +23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
Denys Vlasenko 07c8b240d5 bc: fold xc_lex_more_input() into peek_inbuf()
function                                             old     new   delta
peek_inbuf                                            69      56     -13

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-02-14 14:40:57 +01:00
415 changed files with 7113 additions and 10308 deletions

No files matched your search

+3 -26
View File
@@ -12,7 +12,7 @@ config HAVE_DOT_CONFIG
menu "Settings"
config DESKTOP
bool "Enable compatibility for full-blown desktop systems (8kb)"
bool "Enable compatibility for full-blown desktop systems"
default y
help
Enable applet options and features which are not essential.
@@ -156,13 +156,12 @@ config FEATURE_PIDFILE
config PID_FILE_PATH
string "Directory for pidfiles"
default "/var/run"
depends on FEATURE_PIDFILE || FEATURE_CROND_SPECIAL_TIMES
depends on FEATURE_PIDFILE
help
This is the default path where pidfiles are created. Applets which
allow you to set the pidfile path on the command line will override
this value. The option has no effect on applets that require you to
specify a pidfile path. When crond has the 'Support special times'
option enabled, the 'crond.reboot' file is also stored here.
specify a pidfile path.
config BUSYBOX
bool "Include busybox applet"
@@ -340,15 +339,6 @@ config FEATURE_CLEAN_UP
Don't enable this unless you have a really good reason to clean
things up manually.
config FEATURE_SYSLOG_INFO
bool "Support LOG_INFO level syslog messages"
default y
depends on FEATURE_SYSLOG
help
Applets which send their output to syslog use either LOG_INFO or
LOG_ERR log levels, but by disabling this option all messages will
be logged at the LOG_ERR level, saving just under 200 bytes.
# These are auto-selected by other options
config FEATURE_SYSLOG
@@ -662,19 +652,6 @@ config WERROR
Most people should answer N.
config WARN_SIMPLE_MSG
bool "Warn about single parameter bb_xx_msg calls"
default n
help
This will cause warnings to be shown for any instances of
bb_error_msg(), bb_error_msg_and_die(), bb_perror_msg(),
bb_perror_msg_and_die(), bb_herror_msg() or bb_herror_msg_and_die()
being called with a single parameter. In these cases the equivalent
bb_simple_xx_msg function should be used instead.
Note that use of STRERROR_FMT may give false positives.
If you aren't developing busybox, say N here.
choice
prompt "Additional debugging library"
default NO_DEBUG_LIB
+1 -1
View File
@@ -1,5 +1,5 @@
VERSION = 1
PATCHLEVEL = 32
PATCHLEVEL = 30
SUBLEVEL = 1
EXTRAVERSION =
NAME = Unnamed
+6 -29
View File
@@ -15,7 +15,7 @@ CPPFLAGS += \
-include include/autoconf.h \
-D_GNU_SOURCE -DNDEBUG \
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
-DBB_VER=$(squote)$(quote)$(BB_VER)$(quote)$(squote)
-D"BB_VER=KBUILD_STR($(BB_VER))"
CFLAGS += $(call cc-option,-Wall,)
CFLAGS += $(call cc-option,-Wshadow,)
@@ -47,28 +47,12 @@ endif
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
ifneq ($(CC),clang)
# "clang-9: warning: optimization flag '-finline-limit=0' is not supported
CFLAGS += $(call cc-option,-finline-limit=0,)
endif
CFLAGS += $(call cc-option,-fno-builtin-strlen -fomit-frame-pointer -ffunction-sections -fdata-sections,)
CFLAGS += $(call cc-option,-fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
# -fno-guess-branch-probability: prohibit pseudo-random guessing
# of branch probabilities (hopefully makes bloatcheck more stable):
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
CFLAGS += $(call cc-option,-funsigned-char,)
ifneq ($(CC),clang)
# "clang-9: warning: argument unused during compilation: '-static-libgcc'"
CFLAGS += $(call cc-option,-static-libgcc,)
endif
CFLAGS += $(call cc-option,-falign-functions=1,)
ifneq ($(CC),clang)
# "clang-9: warning: optimization flag '-falign-jumps=1' is not supported" (and same for other two)
CFLAGS += $(call cc-option,-falign-jumps=1 -falign-labels=1 -falign-loops=1,)
endif
CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary):
CFLAGS += $(call cc-option,-fno-unwind-tables,)
CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
@@ -76,11 +60,6 @@ CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
# (try disabling this and comparing assembly, it's instructive)
CFLAGS += $(call cc-option,-fno-builtin-printf,)
# clang-9 does not like "str" + N and "if (CONFIG_ITEM && cond)" constructs
ifeq ($(CC),clang)
CFLAGS += $(call cc-option,-Wno-string-plus-int -Wno-constant-logical-operand)
endif
# FIXME: These warnings are at least partially to be concerned about and should
# be fixed..
#CFLAGS += $(call cc-option,-Wconversion,)
@@ -150,12 +129,10 @@ endif
# fall back to using a temp file:
CRYPT_AVAILABLE := $(shell echo 'int main(void){return 0;}' >crypttest.c; $(CC) $(CFLAGS) -lcrypt -o /dev/null crypttest.c >/dev/null 2>&1 && echo "y"; rm crypttest.c)
ifeq ($(CRYPT_AVAILABLE),y)
LDLIBS += m rt crypt
LDLIBS += m crypt
else
LDLIBS += m rt
LDLIBS += m
endif
# libm may be needed for dc, awk, ntpd
# librt may be needed for clock_gettime()
# libpam may use libpthread, libdl and/or libaudit.
# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
-39
View File
@@ -1,39 +0,0 @@
#!/bin/sh
MIMFILE="Mimfile"
if [ $# -ge 2 ] && [ "$1" = "-f" ]
then
MIMFILE="$2"
shift 2
fi
exec <"$MIMFILE" || exit 1
{
INCASE=false
while read -r REPLY
do
case $REPLY in
*:)
if ! $INCASE
then
printf '[ $# -eq 0 ] && set -- "%s"
TARGET="$1"
shift
case "$TARGET" in
' "${REPLY%:}"
else
printf ';;\n'
fi
printf '%s)\n' "${REPLY%:}"
INCASE=true
;;
"") ;;
*) printf '%s\n' "${REPLY##[ ]}";;
esac
done
$INCASE && printf ';;\n'
printf '*)
echo "Unknown command $TARGET"
exit 1
;;
esac
'
} | sh -s "$@"
+2 -4
View File
@@ -114,7 +114,7 @@ int FAST_FUNC bbunpack(char **argv,
/* Check that the input is sane */
if (!(option_mask32 & BBUNPK_OPT_FORCE) && isatty(STDIN_FILENO)) {
bb_simple_error_msg_and_die("compressed data not read from terminal, "
bb_error_msg_and_die("compressed data not read from terminal, "
"use -f to force it");
}
@@ -386,7 +386,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
* Normally, "zcat" is just "gunzip -c".
* But if seamless magic is enabled, then we are much more clever.
*/
if (ENABLE_ZCAT && applet_name[1] == 'c')
if (ENABLE_ZCAT && (!ENABLE_GUNZIP || applet_name[1] == 'c'))
option_mask32 |= BBUNPK_OPT_STDOUT | BBUNPK_SEAMLESS_MAGIC;
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
@@ -536,7 +536,6 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage: "\n -t Test file integrity"
//usage:
//usage:#define xz_trivial_usage
//usage: "-d [-cfk] [FILE]..."
@@ -546,7 +545,6 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage: "\n -t Test file integrity"
//usage:
//usage:#define xzcat_trivial_usage
//usage: "[FILE]..."
+2 -2
View File
@@ -145,7 +145,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
if (n2 != n) {
if (n2 >= 0)
errno = 0; /* prevent bogus error message */
bb_simple_perror_msg(n2 >= 0 ? "short write" : bb_msg_write_error);
bb_perror_msg(n2 >= 0 ? "short write" : bb_msg_write_error);
return -1;
}
}
@@ -187,7 +187,7 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate U
while (1) {
count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
if (count < 0) {
bb_simple_perror_msg(bb_msg_read_error);
bb_perror_msg(bb_msg_read_error);
total = -1;
break;
}
-1
View File
@@ -516,7 +516,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
if (archive_handle->cpio__blocks != (off_t)-1
&& !(opt & OPT_QUIET)
) {
fflush_all();
fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
}
+7 -7
View File
@@ -487,7 +487,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
} else if (strncmp(version, ">=", offset_ch) == 0) {
edge->operator = VER_MORE_EQUAL;
} else {
bb_simple_error_msg_and_die("illegal operator");
bb_error_msg_and_die("illegal operator");
}
}
/* skip to start of version numbers */
@@ -730,7 +730,7 @@ static void set_status(const unsigned status_node_num, const char *new_value, co
status = new_value_num;
break;
default:
bb_simple_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
}
new_status = xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
@@ -944,10 +944,10 @@ static void write_status_file(deb_file_t **deb_file)
/* Create a separate backfile to dpkg */
if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
if (errno != ENOENT)
bb_simple_error_msg_and_die("can't create backup status file");
bb_error_msg_and_die("can't create backup status file");
/* Its ok if renaming the status file fails because status
* file doesn't exist, maybe we are starting from scratch */
bb_simple_error_msg("no status file found, creating new one");
bb_error_msg("no status file found, creating new one");
}
xrename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status");
@@ -1816,7 +1816,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
init_archive_deb_control(archive_handle);
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
if (deb_file[deb_count]->control_file == NULL) {
bb_simple_error_msg_and_die("can't extract control file");
bb_error_msg_and_die("can't extract control file");
}
deb_file[deb_count]->filename = xstrdup(argv[0]);
package_num = fill_package_struct(deb_file[deb_count]->control_file);
@@ -1879,13 +1879,13 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
argv++;
}
if (!deb_count)
bb_simple_error_msg_and_die("no package files specified");
bb_error_msg_and_die("no package files specified");
deb_file[deb_count] = NULL;
/* Check that the deb file arguments are installable */
if (!(opt & OPT_force_ignore_depends)) {
if (!check_deps(deb_file, 0 /*, deb_count*/)) {
bb_simple_error_msg_and_die("dependency check failed");
bb_error_msg_and_die("dependency check failed");
}
}
+61 -71
View File
@@ -52,7 +52,7 @@ aa: 85.1% -- replaced with aa.gz
//config: help
//config: Enable support for compression levels 4-9. The default level
//config: is 6. If levels 1-3 are specified, 4 is used.
//config: If this option is not selected, -N options are ignored and -6
//config: If this option is not selected, -N options are ignored and -9
//config: is used.
//config:
//config:config FEATURE_GZIP_DECOMPRESS
@@ -99,7 +99,7 @@ aa: 85.1% -- replaced with aa.gz
/* Diagnostic functions */
#ifdef DEBUG
static int verbose;
# define Assert(cond,msg) { if (!(cond)) bb_simple_error_msg(msg); }
# define Assert(cond,msg) { if (!(cond)) bb_error_msg(msg); }
# define Trace(x) fprintf x
# define Tracev(x) {if (verbose) fprintf x; }
# define Tracevv(x) {if (verbose > 1) fprintf x; }
@@ -259,13 +259,12 @@ enum {
#if !ENABLE_FEATURE_GZIP_LEVELS
comp_level_minus4 = 6 - 4,
max_chain_length = 128,
max_chain_length = 4096,
/* To speed up deflation, hash chains are never searched beyond this length.
* A higher limit improves compression ratio but degrades the speed.
*/
max_lazy_match = 16,
max_lazy_match = 258,
/* Attempt to find a better match only when the current match is strictly
* smaller than this value. This mechanism is used only for compression
* levels >= 4.
@@ -277,7 +276,7 @@ enum {
* max_insert_length is used only for compression levels <= 3.
*/
good_match = 8,
good_match = 32,
/* Use a faster search when the previous match is longer than this */
/* Values for max_lazy_match, good_match and max_chain_length, depending on
@@ -286,7 +285,7 @@ enum {
* found for specific files.
*/
nice_match = 128, /* Stop searching when current match exceeds this */
nice_match = 258, /* Stop searching when current match exceeds this */
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
* meaning.
@@ -335,16 +334,14 @@ struct globals {
#define head (G1.prev + WSIZE) /* hash head (see deflate.c) */
#if ENABLE_FEATURE_GZIP_LEVELS
unsigned comp_level_minus4; /* can be a byte */
unsigned max_chain_length;
unsigned max_lazy_match;
unsigned good_match;
unsigned nice_match;
#define comp_level_minus4 (G1.comp_level_minus4)
#define max_chain_length (G1.max_chain_length)
#define max_lazy_match (G1.max_lazy_match)
#define good_match (G1.good_match)
#define nice_match (G1.nice_match)
#define max_chain_length (G1.max_chain_length)
#define max_lazy_match (G1.max_lazy_match)
#define good_match (G1.good_match)
#define nice_match (G1.nice_match)
#endif
/* =========================================================================== */
@@ -507,7 +504,7 @@ static ALWAYS_INLINE void flush_outbuf_if_32bit_optimized(void)
* pointer, then initialize the crc shift register contents instead.
* Return the current crc in either case.
*/
static void updcrc(uch *s, unsigned n)
static void updcrc(uch * s, unsigned n)
{
G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/);
}
@@ -610,7 +607,7 @@ static void bi_windup(void)
* Copy a stored block to the zip file, storing first the length and its
* one's complement if requested.
*/
static void copy_block(const char *buf, unsigned len, int header)
static void copy_block(char *buf, unsigned len, int header)
{
bi_windup(); /* align on byte boundary */
@@ -790,7 +787,7 @@ static void check_match(IPos start, IPos match, int length)
/* check that the match is indeed a match */
if (memcmp(G1.window + match, G1.window + start, length) != 0) {
bb_error_msg(" start %d, match %d, length %d", start, match, length);
bb_simple_error_msg("invalid match");
bb_error_msg("invalid match");
}
if (verbose > 1) {
bb_error_msg("\\[%d,%d]", start - match, length);
@@ -1010,8 +1007,7 @@ struct globals2 {
tree_desc d_desc;
tree_desc bl_desc;
/* was "ush", but "unsigned" results in smaller code */
unsigned bl_count[MAX_BITS + 1];
ush bl_count[MAX_BITS + 1];
/* The lengths of the bit length codes are sent in order of decreasing
* probability, to avoid transmitting the lengths for unused bit length codes.
@@ -1122,7 +1118,7 @@ static void init_block(void)
(tree[n].Freq < tree[m].Freq \
|| (tree[n].Freq == tree[m].Freq && G2.depth[n] <= G2.depth[m]))
static void pqdownheap(const ct_data *tree, int k)
static void pqdownheap(ct_data * tree, int k)
{
int v = G2.heap[k];
int j = k << 1; /* left son of k */
@@ -1156,15 +1152,22 @@ static void pqdownheap(const ct_data *tree, int k)
* The length opt_len is updated; static_len is also updated if stree is
* not null.
*/
static void gen_bitlen(const tree_desc *desc)
static void gen_bitlen(tree_desc * desc)
{
#define tree desc->dyn_tree
int h; /* heap index */
int n, m; /* iterate over the tree elements */
int bits; /* bit length */
int overflow; /* number of elements with bit length too large */
ct_data *tree = desc->dyn_tree;
const uint8_t *extra = desc->extra_bits;
int base = desc->extra_base;
int max_code = desc->max_code;
int max_length = desc->max_length;
ct_data *stree = desc->static_tree;
int h; /* heap index */
int n, m; /* iterate over the tree elements */
int bits; /* bit length */
int xbits; /* extra bits */
ush f; /* frequency */
int overflow = 0; /* number of elements with bit length too large */
for (bits = 0; bits < ARRAY_SIZE(G2.bl_count); bits++)
for (bits = 0; bits <= MAX_BITS; bits++)
G2.bl_count[bits] = 0;
/* In a first pass, compute the optimal bit lengths (which may
@@ -1172,32 +1175,28 @@ static void gen_bitlen(const tree_desc *desc)
*/
tree[G2.heap[G2.heap_max]].Len = 0; /* root of the heap */
overflow = 0;
for (h = G2.heap_max + 1; h < HEAP_SIZE; h++) {
ulg f; /* frequency */
int xbits; /* extra bits */
n = G2.heap[h];
bits = tree[tree[n].Dad].Len + 1;
if (bits > desc->max_length) {
bits = desc->max_length;
if (bits > max_length) {
bits = max_length;
overflow++;
}
tree[n].Len = (ush) bits;
/* We overwrite tree[n].Dad which is no longer needed */
if (n > desc->max_code)
if (n > max_code)
continue; /* not a leaf node */
G2.bl_count[bits]++;
xbits = 0;
if (n >= desc->extra_base)
xbits = desc->extra_bits[n - desc->extra_base];
if (n >= base)
xbits = extra[n - base];
f = tree[n].Freq;
G2.opt_len += f * (bits + xbits);
G2.opt_len += (ulg) f *(bits + xbits);
if (desc->static_tree)
G2.static_len += f * (desc->static_tree[n].Len + xbits);
if (stree)
G2.static_len += (ulg) f * (stree[n].Len + xbits);
}
if (overflow == 0)
return;
@@ -1207,14 +1206,14 @@ static void gen_bitlen(const tree_desc *desc)
/* Find the first bit length which could increase: */
do {
bits = desc->max_length - 1;
bits = max_length - 1;
while (G2.bl_count[bits] == 0)
bits--;
G2.bl_count[bits]--; /* move one leaf down the tree */
G2.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
G2.bl_count[desc->max_length]--;
G2.bl_count[max_length]--;
/* The brother of the overflow item also moves one step up,
* but this does not affect bl_count[desc->max_length]
* but this does not affect bl_count[max_length]
*/
overflow -= 2;
} while (overflow > 0);
@@ -1224,11 +1223,11 @@ static void gen_bitlen(const tree_desc *desc)
* lengths instead of fixing only the wrong ones. This idea is taken
* from 'ar' written by Haruhiko Okumura.)
*/
for (bits = desc->max_length; bits != 0; bits--) {
for (bits = max_length; bits != 0; bits--) {
n = G2.bl_count[bits];
while (n != 0) {
m = G2.heap[--h];
if (m > desc->max_code)
if (m > max_code)
continue;
if (tree[m].Len != (unsigned) bits) {
Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len, bits));
@@ -1238,7 +1237,6 @@ static void gen_bitlen(const tree_desc *desc)
n--;
}
}
#undef tree
}
/* ===========================================================================
@@ -1249,13 +1247,12 @@ static void gen_bitlen(const tree_desc *desc)
* OUT assertion: the field code is set for all tree elements of non
* zero code length.
*/
static void gen_codes(ct_data *tree, int max_code)
static void gen_codes(ct_data * tree, int max_code)
{
/* next_code[] and code used to be "ush", but "unsigned" results in smaller code */
unsigned next_code[MAX_BITS + 1]; /* next code value for each bit length */
unsigned code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
ush next_code[MAX_BITS + 1]; /* next code value for each bit length */
ush code = 0; /* running code value */
int bits; /* bit index */
int n; /* code index */
/* The distribution counts are first used to generate the code values
* without bit reversal.
@@ -1307,7 +1304,7 @@ do { \
pqdownheap(tree, SMALLEST); \
} while (0)
static void build_tree(tree_desc *desc)
static void build_tree(tree_desc * desc)
{
ct_data *tree = desc->dyn_tree;
ct_data *stree = desc->static_tree;
@@ -1385,10 +1382,10 @@ static void build_tree(tree_desc *desc)
/* At this point, the fields freq and dad are set. We can now
* generate the bit lengths.
*/
gen_bitlen(desc);
gen_bitlen((tree_desc *) desc);
/* The field len is now set, we can generate the bit codes */
gen_codes(tree, max_code);
gen_codes((ct_data *) tree, max_code);
}
/* ===========================================================================
@@ -1397,7 +1394,7 @@ static void build_tree(tree_desc *desc)
* counts. (The contribution of the bit length codes will be added later
* during the construction of bl_tree.)
*/
static void scan_tree(ct_data *tree, int max_code)
static void scan_tree(ct_data * tree, int max_code)
{
int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */
@@ -1449,7 +1446,7 @@ static void scan_tree(ct_data *tree, int max_code)
* Send a literal or distance tree in compressed form, using the codes in
* bl_tree.
*/
static void send_tree(const ct_data *tree, int max_code)
static void send_tree(ct_data * tree, int max_code)
{
int n; /* iterates over all tree elements */
int prevlen = -1; /* last emitted length */
@@ -1625,7 +1622,7 @@ static int ct_tally(int dist, int lc)
/* ===========================================================================
* Send the block data compressed using the given Huffman trees
*/
static void compress_block(const ct_data *ltree, const ct_data *dtree)
static void compress_block(ct_data * ltree, ct_data * dtree)
{
unsigned dist; /* distance of matched string */
int lc; /* match length or unmatched char (if dist == 0) */
@@ -1675,7 +1672,7 @@ static void compress_block(const ct_data *ltree, const ct_data *dtree)
* trees or store, and output the encoded block to the zip file. This function
* returns the total compressed length for the file so far.
*/
static void flush_block(const char *buf, ulg stored_len, int eof)
static void flush_block(char *buf, ulg stored_len, int eof)
{
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex; /* index of last bit length code of non zero freq */
@@ -1922,7 +1919,7 @@ static void bi_init(void)
/* ===========================================================================
* Initialize the "longest match" routines for a new file
*/
static void lm_init(void)
static void lm_init(unsigned *flags16p)
{
unsigned j;
@@ -1930,6 +1927,8 @@ static void lm_init(void)
memset(head, 0, HASH_SIZE * sizeof(*head));
/* prev will be initialized on the fly */
/* speed options for the general purpose bit flag */
*flags16p |= 2; /* FAST 4, SLOW 2 */
/* ??? reduce max_chain_length for binary files */
//G1.strstart = 0; // globals are zeroed in pack_gzip()
@@ -2077,16 +2076,10 @@ static void zip(void)
bi_init();
ct_init();
lm_init();
deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
lm_init(&deflate_flags);
deflate_flags = 0x300; /* extra flags. OS id = 3 (Unix) */
#if ENABLE_FEATURE_GZIP_LEVELS
/* Note that comp_level < 4 do not exist in this version of gzip */
if (comp_level_minus4 == 9 - 4) {
deflate_flags |= 0x02; /* SLOW flag */
}
#endif
put_16bit(deflate_flags);
put_16bit(deflate_flags | 0x300); /* extra flags. OS id = 3 (Unix) */
/* The above 32-bit misaligns outbuf (10 bytes are stored), flush it */
flush_outbuf_if_32bit_optimized();
@@ -2229,11 +2222,8 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_GZIP_LEVELS
opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */
if (opt == 0)
opt = 1 << 5; /* default: 6 */
opt = 1 << 6; /* default: 6 */
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
comp_level_minus4 = opt;
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;
+2 -2
View File
@@ -103,7 +103,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
struct stat existing_sb;
if (lstat(dst_name, &existing_sb) == -1) {
if (errno != ENOENT) {
bb_simple_perror_msg_and_die("can't stat old file");
bb_perror_msg_and_die("can't stat old file");
}
}
else if (existing_sb.st_mtime >= file_header->mtime) {
@@ -207,7 +207,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
break;
default:
bb_simple_error_msg_and_die("unrecognized file type");
bb_error_msg_and_die("unrecognized file type");
}
if (!S_ISLNK(file_header->mode)) {
+2 -2
View File
@@ -235,9 +235,9 @@ static int get_next_block(bunzip_data *bd)
/* Get next value */
int n = 0;
while (get_bits(bd, 1)) {
n++;
if (n >= groupCount)
return RETVAL_DATA_ERROR;
n++;
}
/* Decode MTF to get the next selector */
tmp_byte = mtfSymbol[n];
@@ -817,7 +817,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
break;
}
if (bd->headerCRC != bd->totalCRC) {
bb_simple_error_msg("CRC error");
bb_error_msg("CRC error");
break;
}
+59 -74
View File
@@ -39,8 +39,7 @@ typedef struct huft_t {
unsigned char e; /* number of extra bits or operation */
unsigned char b; /* number of bits in this code or subcode */
union {
unsigned n; /* literal, length base, or distance base */
/* ^^^^^ was "unsigned short", but that results in larger code */
unsigned short n; /* literal, length base, or distance base */
struct huft_t *t; /* pointer to next level of table */
} v;
} huft_t;
@@ -185,26 +184,29 @@ static const uint16_t mask_bits[] ALIGN2 = {
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
/* Put lengths/offsets and extra bits in a struct of arrays
* to make calls to huft_build() have one fewer parameter.
*/
struct cp_ext {
uint16_t cp[31];
uint8_t ext[31];
/* Copy lengths for literal codes 257..285 */
static const uint16_t cplens[] ALIGN2 = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
};
/* Copy lengths and extra bits for literal codes 257..285 */
/* note: see note #13 above about the 258 in this list. */
static const struct cp_ext lit = {
/*257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 */
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 */
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 } /* 99 == invalid */
/* Extra bits for literal codes 257..285 */
static const uint8_t cplext[] ALIGN1 = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
5, 5, 5, 0, 99, 99
}; /* 99 == invalid */
/* Copy offsets for distance codes 0..29 */
static const uint16_t cpdist[] ALIGN2 = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513,
769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
};
/* Copy offsets and extra bits for distance codes 0..29 */
static const struct cp_ext dist = {
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 */
{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 },
{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }
/* Extra bits for distance codes */
static const uint8_t cpdext[] ALIGN1 = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
11, 11, 12, 12, 13, 13
};
/* Tables for deflate from PKZIP's appnote.txt. */
@@ -220,20 +222,10 @@ static const uint8_t border[] ALIGN1 = {
* each table.
* t: table to free
*/
#define BAD_HUFT(p) ((uintptr_t)(p) & 1)
#define ERR_RET ((huft_t*)(uintptr_t)1)
static void huft_free(huft_t *p)
{
huft_t *q;
/*
* If 'p' has the error bit set we have to clear it, otherwise we might run
* into a segmentation fault or an invalid pointer to free(p)
*/
if (BAD_HUFT(p)) {
p = (huft_t*)((uintptr_t)(p) ^ (uintptr_t)(ERR_RET));
}
/* Go through linked list, freeing from the malloced (t[-1]) address. */
while (p) {
q = (--p)->v.t;
@@ -285,23 +277,22 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
/* Given a list of code lengths and a maximum table size, make a set of
* tables to decode that set of codes.
* tables to decode that set of codes. Return zero on success, one if
* the given code set is incomplete (the tables are still built in this
* case), two if the input is invalid (an oversubscribed set of lengths)
* - in this case stores NULL in *t.
*
* b: code lengths in bits (all assumed <= BMAX)
* n: number of codes (assumed <= N_MAX)
* s: number of simple-valued codes (0..s-1)
* cp_ext->cp,ext: list of base values/extra bits for non-simple codes
* d: list of base values for non-simple codes
* e: list of extra bits for non-simple codes
* t: result: starting table
* m: maximum lookup bits, returns actual
* result: starting table
*
* On error, returns a value with lowest-bit set on error.
* It can be just the value of 0x1,
* or a valid pointer to a Huffman table, ORed with 0x1 if incompete table
* is given: "fixed inflate" decoder feeds us such data.
*/
static huft_t* huft_build(const unsigned *b, const unsigned n,
const unsigned s, const struct cp_ext *cp_ext,
unsigned *m)
static int huft_build(const unsigned *b, const unsigned n,
const unsigned s, const unsigned short *d,
const unsigned char *e, huft_t **t, unsigned *m)
{
unsigned a; /* counter for codes of length k */
unsigned c[BMAX + 1]; /* bit length count table */
@@ -323,12 +314,12 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
unsigned *xp; /* pointer into x */
int y; /* number of dummy codes added */
unsigned z; /* number of entries in current table */
huft_t *result;
huft_t **t;
/* Length of EOB code, if any */
eob_len = n > 256 ? b[256] : BMAX;
*t = NULL;
/* Generate counts for each bit length */
memset(c, 0, sizeof(c));
p = b;
@@ -344,8 +335,9 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
q[1].b = 1;
q[2].e = 99; /* invalid code marker */
q[2].b = 1;
*t = q + 1;
*m = 1;
return q + 1;
return 0;
}
/* Find minimum and maximum length, bound *m by those */
@@ -361,11 +353,11 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
for (y = 1 << j; j < i; j++, y <<= 1) {
y -= c[j];
if (y < 0)
return ERR_RET; /* bad input: more codes than bits */
return 2; /* bad input: more codes than bits */
}
y -= c[i];
if (y < 0)
return ERR_RET;
return 2;
c[i] += y;
/* Generate starting offsets into the value table for each length */
@@ -392,8 +384,6 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
} while (++i < n);
/* Generate the Huffman codes and for each, make the table entries */
result = ERR_RET;
t = &result;
x[0] = i = 0; /* first Huffman code is zero */
p = v; /* grab values in bit order */
htl = -1; /* no tables yet--level -1 */
@@ -459,8 +449,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
r.v.n = (unsigned short) (*p++); /* simple code is just the value */
} else {
r.e = (unsigned char) cp_ext->ext[*p - s]; /* non-simple--look up in lists */
r.v.n = cp_ext->cp[*p++ - s];
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
r.v.n = d[*p++ - s];
}
/* fill code-like entries with r */
@@ -485,11 +475,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
/* return actual size of base table */
*m = ws[1];
if (y != 0 && g != 1) /* we were given an incomplete table */
/* return "result" ORed with 1 */
return (void*)((uintptr_t)result | 1);
return result;
/* Return 1 if we were given an incomplete table */
return y != 0 && g != 1;
}
@@ -790,17 +777,14 @@ static int inflate_block(STATE_PARAM smallint *e)
for (; i < 288; i++) /* make a complete, but wrong code set */
ll[i] = 8;
bl = 7;
inflate_codes_tl = huft_build(ll, 288, 257, &lit, &bl);
/* ^^^ never returns error here - we use known data */
huft_build(ll, 288, 257, cplens, cplext, &inflate_codes_tl, &bl);
/* huft_build() never return nonzero - we use known data */
/* set up distance table */
for (i = 0; i < 30; i++) /* make an incomplete code set */
ll[i] = 5;
bd = 5;
inflate_codes_td = huft_build(ll, 30, 0, &dist, &bd);
/* ^^^ does return error here! (lsb bit is set) - we gave it incomplete code set */
/* clearing error bit: */
inflate_codes_td = (void*)((uintptr_t)inflate_codes_td & ~(uintptr_t)1);
huft_build(ll, 30, 0, cpdist, cpdext, &inflate_codes_td, &bd);
/* set up data for inflate_codes() */
inflate_codes_setup(PASS_STATE bl, bd);
@@ -866,9 +850,9 @@ static int inflate_block(STATE_PARAM smallint *e)
/* build decoding table for trees - single level, 7 bit lookup */
bl = 7;
inflate_codes_tl = huft_build(ll, 19, 19, NULL, &bl);
if (BAD_HUFT(inflate_codes_tl)) {
abort_unzip(PASS_STATE_ONLY); /* incomplete code set */
i = huft_build(ll, 19, 19, NULL, NULL, &inflate_codes_tl, &bl);
if (i != 0) {
abort_unzip(PASS_STATE_ONLY); //return i; /* incomplete code set */
}
/* read in literal and distance code lengths */
@@ -931,13 +915,14 @@ static int inflate_block(STATE_PARAM smallint *e)
/* build the decoding tables for literal/length and distance codes */
bl = lbits;
inflate_codes_tl = huft_build(ll, nl, 257, &lit, &bl);
if (BAD_HUFT(inflate_codes_tl)) {
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
bd = dbits;
inflate_codes_td = huft_build(ll + nl, nd, 0, &dist, &bd);
if (BAD_HUFT(inflate_codes_td)) {
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
if (i != 0) {
abort_unzip(PASS_STATE_ONLY);
}
@@ -1027,7 +1012,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_simple_error_msg(error_msg);
bb_error_msg(error_msg);
n = -1;
goto ret;
}
@@ -1100,7 +1085,7 @@ static int top_up(STATE_PARAM unsigned n)
bytebuffer_offset = 0;
bytebuffer_size = full_read(gunzip_src_fd, &bytebuffer[count], bytebuffer_max - count);
if ((int)bytebuffer_size < 0) {
bb_simple_error_msg(bb_msg_read_error);
bb_error_msg(bb_msg_read_error);
return 0;
}
bytebuffer_size += count;
@@ -1226,7 +1211,7 @@ unpack_gz_stream(transformer_state_t *xstate)
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
bad_magic:
bb_simple_error_msg("invalid magic");
bb_error_msg("invalid magic");
return -1;
}
if (magic2 == COMPRESS_MAGIC) {
@@ -1248,7 +1233,7 @@ unpack_gz_stream(transformer_state_t *xstate)
again:
if (!check_header_gzip(PASS_STATE xstate)) {
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
total = -1;
goto ret;
}
@@ -1261,7 +1246,7 @@ unpack_gz_stream(transformer_state_t *xstate)
total += n;
if (!top_up(PASS_STATE 8)) {
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
total = -1;
goto ret;
}
@@ -1269,7 +1254,7 @@ unpack_gz_stream(transformer_state_t *xstate)
/* Validate decompression - crc */
v32 = buffer_read_le_u32(PASS_STATE_ONLY);
if ((~gunzip_crc) != v32) {
bb_simple_error_msg("crc error");
bb_error_msg("crc error");
total = -1;
goto ret;
}
@@ -1277,7 +1262,7 @@ unpack_gz_stream(transformer_state_t *xstate)
/* Validate decompression - size */
v32 = buffer_read_le_u32(PASS_STATE_ONLY);
if ((uint32_t)gunzip_bytes_out != v32) {
bb_simple_error_msg("incorrect length");
bb_error_msg("incorrect length");
total = -1;
}
+5 -5
View File
@@ -113,7 +113,7 @@ unpack_Z_stream(transformer_state_t *xstate)
/* xread isn't good here, we have to return - caller may want
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
bb_simple_error_msg("short read");
bb_error_msg("short read");
goto err;
}
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_state_t *xstate)
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
if (rsize < 0)
bb_simple_error_msg_and_die(bb_msg_read_error);
bb_error_msg_and_die(bb_msg_read_error);
insize += rsize;
}
@@ -200,7 +200,7 @@ unpack_Z_stream(transformer_state_t *xstate)
if (oldcode == -1) {
if (code >= 256)
bb_simple_error_msg_and_die("corrupted data"); /* %ld", code); */
bb_error_msg_and_die("corrupted data"); /* %ld", code); */
oldcode = code;
finchar = (int) oldcode;
outbuf[outpos++] = (unsigned char) finchar;
@@ -236,7 +236,7 @@ unpack_Z_stream(transformer_state_t *xstate)
insize, posbits, p[-1], p[0], p[1], p[2], p[3],
(posbits & 07));
*/
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
goto err;
}
@@ -247,7 +247,7 @@ unpack_Z_stream(transformer_state_t *xstate)
/* Generate output characters in reverse order */
while (code >= 256) {
if (stackp <= &htabof(0))
bb_simple_error_msg_and_die("corrupted data");
bb_error_msg_and_die("corrupted data");
*--stackp = tab_suffixof(code);
code = tab_prefixof(code);
}
+3 -3
View File
@@ -59,7 +59,7 @@ static void rc_read(rc_t *rc)
//TODO: return -1 instead
//This will make unlzma delete broken unpacked file on unpack errors
if (buffer_size <= 0)
bb_simple_error_msg_and_die("unexpected EOF");
bb_error_msg_and_die("unexpected EOF");
rc->buffer_end = RC_BUFFER + buffer_size;
rc->ptr = RC_BUFFER;
}
@@ -234,7 +234,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|| header.pos >= (9 * 5 * 5)
) {
bb_simple_error_msg("bad lzma header");
bb_error_msg("bad lzma header");
return -1;
}
@@ -513,7 +513,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
* potentially more detailed information).
* Do not fail silently.
*/
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
total_written = -1; /* failure */
}
rc_free(rc);
+3 -21
View File
@@ -74,7 +74,7 @@ unpack_xz_stream(transformer_state_t *xstate)
if (iobuf.in_pos == iobuf.in_size) {
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
if (rd < 0) {
bb_simple_error_msg(bb_msg_read_error);
bb_error_msg(bb_msg_read_error);
total = -1;
break;
}
@@ -96,24 +96,6 @@ unpack_xz_stream(transformer_state_t *xstate)
*/
do {
if (membuf[iobuf.in_pos] != 0) {
/* There is more data, but is it XZ data?
* Example: dpkg-deb -f busybox_1.30.1-4_amd64.deb
* reads control.tar.xz "control" file
* inside the ar archive, but tar.xz
* extraction code reaches end of xz data,
* reached this code and reads the beginning
* of data.tar.xz's ar header, which isn't xz data,
* and prints "corrupted data".
* The correct solution is to not read
* past nested archive (to simulate EOF).
* This is a workaround:
*/
if (membuf[iobuf.in_pos] != 0xfd) {
/* It's definitely not a xz signature
* (which is 0xfd,"7zXZ",0x00).
*/
goto end;
}
xz_dec_reset(state);
goto do_run;
}
@@ -141,12 +123,12 @@ unpack_xz_stream(transformer_state_t *xstate)
continue;
}
if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
bb_simple_error_msg("corrupted data");
bb_error_msg("corrupted data");
total = -1;
break;
}
}
end:
xz_dec_end(state);
free(membuf);
+4 -4
View File
@@ -22,7 +22,7 @@ static unsigned read_num(char *str, int base, int len)
* on misformatted numbers bb_strtou returns all-ones */
err = bb_strtou(str, NULL, base);
if (err == -1)
bb_simple_error_msg_and_die("invalid ar header");
bb_error_msg_and_die("invalid ar header");
return err;
}
@@ -53,7 +53,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
archive_handle->offset += 60;
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
bb_simple_error_msg_and_die("invalid ar header");
bb_error_msg_and_die("invalid ar header");
/*
* Note that the fields MUST be read in reverse order as
@@ -86,7 +86,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
return get_header_ar(archive_handle);
}
#else
bb_simple_error_msg_and_die("long filenames not supported");
bb_error_msg_and_die("long filenames not supported");
#endif
}
/* Only size is always present, the rest may be missing in
@@ -107,7 +107,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
long_offset = read_num(&ar.formatted.name[1], 10,
sizeof(ar.formatted.name) - 1);
if (long_offset >= archive_handle->ar__long_name_size) {
bb_simple_error_msg_and_die("can't resolve long filename");
bb_error_msg_and_die("can't resolve long filename");
}
typed->name = xstrdup(archive_handle->ar__long_names + long_offset);
} else
+3 -3
View File
@@ -33,14 +33,14 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
goto create_hardlinks;
}
if (size != 110) {
bb_simple_error_msg_and_die("short read");
bb_error_msg_and_die("short read");
}
archive_handle->offset += 110;
if (!is_prefixed_with(&cpio_header[0], "07070")
|| (cpio_header[5] != '1' && cpio_header[5] != '2')
) {
bb_simple_error_msg_and_die("unsupported cpio format, use newc or crc");
bb_error_msg_and_die("unsupported cpio format, use newc or crc");
}
if (sscanf(cpio_header + 6,
@@ -50,7 +50,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
&inode, &mode, &uid, &gid,
&nlink, &mtime, &size,
&major, &minor, &namesize) != 10)
bb_simple_error_msg_and_die("damaged cpio file");
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)
+7 -7
View File
@@ -32,7 +32,7 @@ static unsigned long long getOctal(char *str, int len)
if (*end != '\0' && *end != ' ') {
int8_t first = str[0];
if (!(first & 0x80))
bb_simple_error_msg_and_die("corrupted octal value in tar header");
bb_error_msg_and_die("corrupted octal value in tar header");
/*
* GNU tar uses "base-256 encoding" for very large numbers.
* Encoding is binary, with highest bit always set as a marker
@@ -100,7 +100,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|| errno != EINVAL
|| *end != ' '
) {
bb_simple_error_msg("malformed extended header, skipped");
bb_error_msg("malformed extended header, skipped");
// More verbose version:
//bb_error_msg("malformed extended header at %"OFF_FMT"d, skipped",
// archive_handle->offset - (sz + len));
@@ -194,13 +194,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
* the very first read fails. Grrr.
*/
if (archive_handle->offset == 0)
bb_simple_error_msg("short read");
bb_error_msg("short read");
/* this merely signals end of archive, not exit(1): */
return EXIT_FAILURE;
}
if (i != 512) {
IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
bb_simple_error_msg_and_die("short read");
bb_error_msg_and_die("short read");
}
#else
@@ -243,11 +243,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
goto err;
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
err:
bb_simple_error_msg_and_die("invalid tar magic");
bb_error_msg_and_die("invalid tar magic");
archive_handle->offset = 0;
goto again_after_align;
#endif
bb_simple_error_msg_and_die("invalid tar magic");
bb_error_msg_and_die("invalid tar magic");
}
/* Do checksum on headers.
@@ -282,7 +282,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
if (sum_u != sum
IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)
) {
bb_simple_error_msg_and_die("invalid tar header checksum");
bb_error_msg_and_die("invalid tar header checksum");
}
/* GET_OCTAL trashes subsequent field, therefore we call it
+20 -30
View File
@@ -15,7 +15,7 @@ int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
if (!xstate->signature_skipped) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
bb_simple_error_msg("invalid magic");
bb_error_msg("invalid magic");
return -1;
}
xstate->signature_skipped = 2;
@@ -46,7 +46,7 @@ ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf
} else {
nwrote = full_write(xstate->dst_fd, buf, bufsize);
if (nwrote != (ssize_t)bufsize) {
bb_simple_perror_msg("write");
bb_perror_msg("write");
nwrote = -1;
goto ret;
}
@@ -159,44 +159,47 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
*/
static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
{
union {
uint8_t b[4];
uint16_t b16[2];
uint32_t b32[1];
} magic;
transformer_state_t *xstate;
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. */
xstate->signature_skipped = 2;
xread(fd, xstate->magic.b16, 2);
xread(fd, magic.b16, sizeof(magic.b16[0]));
if (ENABLE_FEATURE_SEAMLESS_GZ
&& xstate->magic.b16[0] == GZIP_MAGIC
&& magic.b16[0] == GZIP_MAGIC
) {
xstate->xformer = unpack_gz_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
goto found_magic;
}
if (ENABLE_FEATURE_SEAMLESS_Z
&& xstate->magic.b16[0] == COMPRESS_MAGIC
&& magic.b16[0] == COMPRESS_MAGIC
) {
xstate->xformer = unpack_Z_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "uncompress";)
goto found_magic;
}
if (ENABLE_FEATURE_SEAMLESS_BZ2
&& xstate->magic.b16[0] == BZIP2_MAGIC
&& magic.b16[0] == BZIP2_MAGIC
) {
xstate->xformer = unpack_bz2_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
goto found_magic;
}
if (ENABLE_FEATURE_SEAMLESS_XZ
&& xstate->magic.b16[0] == XZ_MAGIC1
&& magic.b16[0] == XZ_MAGIC1
) {
uint32_t v32;
xstate->signature_skipped = 6;
xread(fd, &xstate->magic.b16[1], 4);
move_from_unaligned32(v32, &xstate->magic.b16[1]);
if (v32 == XZ_MAGIC2) {
xread(fd, magic.b32, sizeof(magic.b32[0]));
if (magic.b32[0] == XZ_MAGIC2) {
xstate->xformer = unpack_xz_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
goto found_magic;
@@ -205,7 +208,7 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
/* No known magic seen */
if (fail_if_not_compressed)
bb_simple_error_msg_and_die("no gzip"
bb_error_msg_and_die("no gzip"
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
IF_FEATURE_SEAMLESS_XZ("/xz")
" magic");
@@ -341,24 +344,11 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
*maxsz_p = xstate->mem_output_size;
}
} else {
/* File is not compressed.
* We already read first few bytes, account for that.
* Example where it happens:
* "modinfo MODULE.ko" (not compressed)
* open("MODULE.ko", O_RDONLY|O_LARGEFILE) = 4
* read(4, "\177E", 2) = 2
* fstat64(4, ...)
* mmap(...)
* read(4, "LF\2\1\1\0\0\0\0"...
* ...and we avoided seeking on the fd! :)
*/
image = xmalloc_read_with_initial_buf(
xstate->src_fd,
maxsz_p,
xmemdup(&xstate->magic, xstate->signature_skipped),
xstate->signature_skipped
);
/* 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);
}
if (!image)
+1 -1
View File
@@ -13,6 +13,6 @@ void FAST_FUNC seek_by_jump(int fd, off_t amount)
if (errno == ESPIPE)
seek_by_read(fd, amount);
else
bb_simple_perror_msg_and_die("seek failure");
bb_perror_msg_and_die("seek failure");
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
if (!is_prefixed_with(magic, AR_MAGIC)) {
bb_simple_error_msg_and_die("invalid ar magic");
bb_error_msg_and_die("invalid ar magic");
}
ar_archive->offset += AR_MAGIC_LEN;
+1 -1
View File
@@ -25,7 +25,7 @@
#define STREAM_HEADER_SIZE 12
#define HEADER_MAGIC "\375""7zXZ"
#define HEADER_MAGIC "\3757zXZ"
#define HEADER_MAGIC_SIZE 6
#define FOOTER_MAGIC "YZ"
+7 -7
View File
@@ -752,7 +752,7 @@ static FAST_FUNC void lzo_check(
*/
uint32_t c = fn(init, buf, len);
if (c != ref)
bb_simple_error_msg_and_die("checksum error");
bb_error_msg_and_die("checksum error");
}
/**********************************************************************/
@@ -785,15 +785,15 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
/* error if split file */
if (dst_len == 0xffffffffL)
/* should not happen - not yet implemented */
bb_simple_error_msg_and_die("this file is a split lzop file");
bb_error_msg_and_die("this file is a split lzop file");
if (dst_len > MAX_BLOCK_SIZE)
bb_simple_error_msg_and_die("corrupted data");
bb_error_msg_and_die("corrupted data");
/* read compressed block size */
src_len = read32();
if (src_len <= 0 || src_len > dst_len)
bb_simple_error_msg_and_die("corrupted data");
bb_error_msg_and_die("corrupted data");
if (dst_len > block_size) {
if (b2) {
@@ -846,7 +846,7 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
r = lzo1x_decompress_safe(b1, src_len, b2, &d /*, NULL*/);
if (r != 0 /*LZO_E_OK*/ || dst_len != d) {
bb_simple_error_msg_and_die("corrupted data");
bb_error_msg_and_die("corrupted data");
}
dst = b2;
} else {
@@ -913,7 +913,7 @@ static void check_magic(void)
unsigned char magic[sizeof(lzop_magic)];
xread(0, magic, sizeof(magic));
if (memcmp(magic, lzop_magic, sizeof(lzop_magic)) != 0)
bb_simple_error_msg_and_die("bad magic number");
bb_error_msg_and_die("bad magic number");
}
/**********************************************************************/
@@ -1049,7 +1049,7 @@ static void lzo_set_method(header_t *h)
else if (option_mask32 & OPT_8)
level = 8;
#else
bb_simple_error_msg_and_die("high compression not compiled in");
bb_error_msg_and_die("high compression not compiled in");
#endif
}
+1 -1
View File
@@ -543,7 +543,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
}
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
bb_simple_error_msg_and_die("error unpacking");
bb_error_msg_and_die("error unpacking");
if (ENABLE_FEATURE_CLEAN_UP) {
close(rpm_fd);
+36 -61
View File
@@ -232,7 +232,7 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf
}
/* Put an octal string into the specified buffer.
* The number is zero padded and possibly NUL terminated.
* The number is zero padded and possibly null terminated.
* Stores low-order bits only if whole value does not fit. */
static void putOctal(char *cp, int len, off_t value)
{
@@ -283,32 +283,31 @@ static void chksum_and_xwrite(int fd, struct tar_header_t* hp)
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static void writeLongname(int fd, int type, const char *name, int dir)
{
struct prefilled {
static const struct {
char mode[8]; /* 100-107 */
char uid[8]; /* 108-115 */
char gid[8]; /* 116-123 */
char size[12]; /* 124-135 */
char mtime[12]; /* 136-147 */
} prefilled = {
"0000000",
"0000000",
"0000000",
"00000000000",
"00000000000",
};
struct tar_header_t header;
int size;
memset(&header, 0, sizeof(header));
header.typeflag = type;
strcpy(header.name, "././@LongLink");
/* This sets mode/uid/gid/mtime to "00...00<NUL>" strings */
memset(header.mode, '0', sizeof(struct prefilled));
header.mode [sizeof(header.mode ) - 1] = '\0';
header.uid [sizeof(header.uid ) - 1] = '\0';
header.gid [sizeof(header.gid ) - 1] = '\0';
/* header.size is filled by '0' now, will be corrected below */
header.mtime[sizeof(header.mtime) - 1] = '\0';
dir = !!dir; /* normalize: 0/1 */
size = strlen(name) + 1 + dir; /* GNU tar uses strlen+1 */
/* + dir: account for possible '/' */
memset(&header, 0, sizeof(header));
strcpy(header.name, "././@LongLink");
memcpy(header.mode, prefilled.mode, sizeof(prefilled));
PUT_OCTAL(header.size, size);
header.typeflag = type;
chksum_and_xwrite(fd, &header);
/* Write filename[/] and pad the block. */
@@ -370,7 +369,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
/* If it is larger than 100 bytes, bail out */
if (header.linkname[sizeof(header.linkname)-1]) {
free(lpath);
bb_simple_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return FALSE;
}
# endif
@@ -543,7 +542,7 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
# if !ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (strlen(header_name) >= NAME_SIZE) {
bb_simple_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
bb_error_msg("names longer than "NAME_SIZE_STR" chars not supported");
return TRUE;
}
# endif
@@ -637,14 +636,8 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
}
xmove_fd(data.rd, 0);
xmove_fd(tfd, 1);
/* exec gzip/bzip2/... program */
//BB_EXECLP(gzip, gzip, "-f", (char *)0); - WRONG for "xz",
// if xz is an enabled applet, it'll be a version which
// can only decompress. We do need to execute external
// program, not applet.
execlp(gzip, gzip, "-f", (char *)0);
/* exec gzip/bzip2 program/applet */
BB_EXECLP(gzip, gzip, "-f", (char *)0);
vfork_exec_errno = errno;
_exit(EXIT_FAILURE);
}
@@ -722,13 +715,13 @@ static NOINLINE int writeTarFile(
freeHardLinkInfo(&tbInfo->hlInfoHead);
if (errorFlag)
bb_simple_error_msg("error exit delayed from previous errors");
bb_error_msg("error exit delayed from previous errors");
# if SEAMLESS_COMPRESSION
if (gzip) {
int status;
if (safe_waitpid(-1, &status, 0) == -1)
bb_simple_perror_msg("waitpid");
bb_perror_msg("waitpid");
else if (!WIFEXITED(status) || WEXITSTATUS(status))
/* gzip was killed or has exited with nonzero! */
errorFlag = TRUE;
@@ -768,7 +761,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_SEAMLESS_GZ("z")
//usage: IF_FEATURE_SEAMLESS_XZ("J")
//usage: IF_FEATURE_SEAMLESS_BZ2("j")
//usage: "a"
//usage: IF_FEATURE_SEAMLESS_LZMA("a")
//usage: IF_FEATURE_TAR_CREATE("h")
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
//usage: "vokO] "
@@ -807,7 +800,9 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: IF_FEATURE_SEAMLESS_BZ2(
//usage: "\n -j (De)compress using bzip2"
//usage: )
//usage: "\n -a (De)compress based on extension"
//usage: IF_FEATURE_SEAMLESS_LZMA(
//usage: "\n -a (De)compress using lzma"
//usage: )
//usage: IF_FEATURE_TAR_CREATE(
//usage: "\n -h Follow symlinks"
//usage: )
@@ -824,7 +819,6 @@ static llist_t *append_file_list_to_list(llist_t *list)
//usage: "$ tar -cf /tmp/tarball.tar /usr/local\n"
// Supported but aren't in --help:
// lzma
// no-recursion
// numeric-owner
// no-same-permissions
@@ -838,16 +832,15 @@ enum {
IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
IF_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
IF_FEATURE_SEAMLESS_BZ2( OPTBIT_BZIP2 ,)
IF_FEATURE_SEAMLESS_LZMA(OPTBIT_LZMA ,)
IF_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
IF_FEATURE_SEAMLESS_XZ( OPTBIT_XZ ,)
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit
OPTBIT_AUTOCOMPRESS_BY_EXT,
IF_FEATURE_SEAMLESS_XZ( OPTBIT_XZ ,) // 16th bit
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
OPTBIT_STRIP_COMPONENTS,
IF_FEATURE_SEAMLESS_LZMA(OPTBIT_LZMA ,)
OPTBIT_NORECURSION,
IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,)
OPTBIT_NUMERIC_OWNER,
@@ -866,15 +859,14 @@ enum {
OPT_CREATE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_CREATE )) + 0, // c
OPT_DEREFERENCE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_DEREFERENCE )) + 0, // h
OPT_BZIP2 = IF_FEATURE_SEAMLESS_BZ2( (1 << OPTBIT_BZIP2 )) + 0, // j
OPT_LZMA = IF_FEATURE_SEAMLESS_LZMA((1 << OPTBIT_LZMA )) + 0, // a
OPT_INCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_INCLUDE_FROM)) + 0, // T
OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
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_AUTOCOMPRESS_BY_EXT = 1 << OPTBIT_AUTOCOMPRESS_BY_EXT, // a
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_LZMA = IF_FEATURE_TAR_LONG_OPTIONS(IF_FEATURE_SEAMLESS_LZMA((1 << OPTBIT_LZMA))) + 0, // lzma
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
@@ -904,6 +896,9 @@ static const char tar_longopts[] ALIGN1 =
# if ENABLE_FEATURE_SEAMLESS_BZ2
"bzip2\0" No_argument "j"
# endif
# if ENABLE_FEATURE_SEAMLESS_LZMA
"lzma\0" No_argument "a"
# endif
# if ENABLE_FEATURE_TAR_FROM
"files-from\0" Required_argument "T"
"exclude-from\0" Required_argument "X"
@@ -917,14 +912,10 @@ static const char tar_longopts[] ALIGN1 =
# if ENABLE_FEATURE_SEAMLESS_Z
"compress\0" No_argument "Z"
# endif
"auto-compress\0" No_argument "a"
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
"touch\0" No_argument "m"
# endif
"strip-components\0" Required_argument "\xf8"
# if ENABLE_FEATURE_SEAMLESS_LZMA
"lzma\0" No_argument "\xf9"
# 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"
@@ -1013,13 +1004,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
"txC:f:Oopvk"
IF_FEATURE_TAR_CREATE( "ch" )
IF_FEATURE_SEAMLESS_BZ2( "j" )
IF_FEATURE_SEAMLESS_LZMA("a" )
IF_FEATURE_TAR_FROM( "T:*X:*")
IF_FEATURE_SEAMLESS_GZ( "z" )
IF_FEATURE_SEAMLESS_XZ( "J" )
IF_FEATURE_SEAMLESS_Z( "Z" )
"a"
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
IF_FEATURE_TAR_LONG_OPTIONS("\xf8:") // --strip-components
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
"\0"
"tt:vv:" // count -t,-v
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
@@ -1029,7 +1020,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
":\xf8+" // --strip-components=NUM
":\xf9+" // --strip-components=NUM
#endif
LONGOPTS
, &base_dir // -C dir
@@ -1048,7 +1039,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
);
#if DBG_OPTION_PARSING
bb_error_msg("opt: 0x%08x", opt);
# define showopt(o) bb_error_msg("opt & %s(%x):\t%x", #o, o, opt & o);
# define showopt(o) bb_error_msg("opt & %s(%x): %x", #o, o, opt & o);
showopt(OPT_TEST );
showopt(OPT_EXTRACT );
showopt(OPT_BASEDIR );
@@ -1061,15 +1052,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
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_AUTOCOMPRESS_BY_EXT);
showopt(OPT_NOPRESERVE_TIME );
showopt(OPT_STRIP_COMPONENTS);
showopt(OPT_LZMA );
showopt(OPT_NORECURSION );
showopt(OPT_2COMMAND );
showopt(OPT_NUMERIC_OWNER );
@@ -1160,7 +1150,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
if (opt & OPT_CREATE) {
/* Make sure there is at least one file to tar up */
if (tar_handle->accept == NULL)
bb_simple_error_msg_and_die("empty archive");
bb_error_msg_and_die("empty archive");
tar_fd = STDOUT_FILENO;
/* Mimicking GNU tar 1.15.1: */
@@ -1188,21 +1178,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
bb_perror_msg_and_die("can't open '%s'", tar_filename);
} else {
tar_handle->src_fd = xopen(tar_filename, flags);
#if ENABLE_FEATURE_TAR_CREATE
if ((OPT_GZIP | OPT_BZIP2 | OPT_XZ | OPT_LZMA) != 0 /* at least one is config-enabled */
&& (opt & OPT_AUTOCOMPRESS_BY_EXT)
&& flags != O_RDONLY
) {
if (OPT_GZIP != 0 && is_suffixed_with(tar_filename, "gz"))
opt |= OPT_GZIP;
if (OPT_BZIP2 != 0 && is_suffixed_with(tar_filename, "bz2"))
opt |= OPT_BZIP2;
if (OPT_XZ != 0 && is_suffixed_with(tar_filename, "xz"))
opt |= OPT_XZ;
if (OPT_LZMA != 0 && is_suffixed_with(tar_filename, "lzma"))
opt |= OPT_LZMA;
}
#endif
}
}
+10 -16
View File
@@ -322,7 +322,7 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
static void die_if_bad_fnamesize(unsigned sz)
{
if (sz > 0xfff) /* more than 4k?! no funny business please */
bb_simple_error_msg_and_die("bad archive");
bb_error_msg_and_die("bad archive");
}
static void unzip_skip(off_t skip)
@@ -359,7 +359,7 @@ static void unzip_extract_symlink(llist_t **symlink_placeholders,
xread(zip_fd, target, zip->fmt.ucmpsize);
} else {
#if 1
bb_simple_error_msg_and_die("compressed symlink is not supported");
bb_error_msg_and_die("compressed symlink is not supported");
#else
transformer_state_t xstate;
init_transformer_state(&xstate);
@@ -399,10 +399,10 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
if (zip->fmt.method == 8) {
/* Method 8 - inflate */
if (inflate_unzip(&xstate) < 0)
bb_simple_error_msg_and_die("inflate error");
bb_error_msg_and_die("inflate error");
/* Validate decompression - crc */
if (zip->fmt.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
bb_simple_error_msg_and_die("crc error");
bb_error_msg_and_die("crc error");
}
}
#if ENABLE_FEATURE_UNZIP_BZIP2
@@ -412,7 +412,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
*/
xstate.bytes_out = unpack_bz2_stream(&xstate);
if (xstate.bytes_out < 0)
bb_simple_error_msg_and_die("inflate error");
bb_error_msg_and_die("inflate error");
}
#endif
#if ENABLE_FEATURE_UNZIP_LZMA
@@ -420,7 +420,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
/* Not tested yet */
xstate.bytes_out = unpack_lzma_stream(&xstate);
if (xstate.bytes_out < 0)
bb_simple_error_msg_and_die("inflate error");
bb_error_msg_and_die("inflate error");
}
#endif
#if ENABLE_FEATURE_UNZIP_XZ
@@ -428,7 +428,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
/* Not tested yet */
xstate.bytes_out = unpack_xz_stream(&xstate);
if (xstate.bytes_out < 0)
bb_simple_error_msg_and_die("inflate error");
bb_error_msg_and_die("inflate error");
}
#endif
else {
@@ -439,7 +439,7 @@ static void unzip_extract(zip_header_t *zip, int dst_fd)
if (zip->fmt.ucmpsize != xstate.bytes_out) {
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_simple_error_msg("bad length");
bb_error_msg("bad length");
}
}
@@ -447,7 +447,7 @@ static void my_fgets80(char *buf80)
{
fflush_all();
if (!fgets(buf80, 80, stdin)) {
bb_simple_perror_msg_and_die("can't read standard input");
bb_perror_msg_and_die("can't read standard input");
}
}
@@ -646,14 +646,8 @@ int unzip_main(int argc, char **argv)
}
/* Change dir if necessary */
if (base_dir) {
/* -p DIR: try to create, errors don't matter.
* UnZip 6.00 does no multi-level mkdir (-p DIR1/DIR2 syntax),
* not using bb_make_directory() here (yet?)
*/
mkdir(base_dir, 0777);
if (base_dir)
xchdir(base_dir);
}
if (quiet <= 1) { /* not -qq */
if (quiet == 0) {
+10 -10
View File
@@ -225,7 +225,7 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize,
if (unicode == PSF2_SEPARATOR) {
break;
} else if (unicode == PSF2_STARTSEQ) {
bb_simple_error_msg_and_die("unicode sequences not implemented");
bb_error_msg_and_die("unicode sequences not implemented");
} else if (unicode >= 0xC0) {
if (unicode >= 0xFC)
unicode &= 0x01, maxct = 5;
@@ -239,12 +239,12 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize,
unicode &= 0x1F, maxct = 1;
do {
if (tailsz <= 0 || *inbuf < 0x80 || *inbuf > 0xBF)
bb_simple_error_msg_and_die("illegal UTF-8 character");
bb_error_msg_and_die("illegal UTF-8 character");
--tailsz;
unicode = (unicode << 6) + (*inbuf++ & 0x3F);
} while (--maxct > 0);
} else if (unicode >= 0x80) {
bb_simple_error_msg_and_die("illegal UTF-8 character");
bb_error_msg_and_die("illegal UTF-8 character");
}
#else
return;
@@ -281,7 +281,7 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
if (len >= sizeof(struct psf1_header) && PSF1_MAGIC_OK(psf1h(buffer))) {
if (psf1h(buffer)->mode > PSF1_MAXMODE)
bb_simple_error_msg_and_die("unsupported psf file mode");
bb_error_msg_and_die("unsupported psf file mode");
if (psf1h(buffer)->mode & PSF1_MODE512)
fontsize = 512;
if (psf1h(buffer)->mode & PSF1_MODEHASTAB)
@@ -292,7 +292,7 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
#if ENABLE_FEATURE_LOADFONT_PSF2
if (len >= sizeof(struct psf2_header) && PSF2_MAGIC_OK(psf2h(buffer))) {
if (psf2h(buffer)->version > PSF2_MAXVERSION)
bb_simple_error_msg_and_die("unsupported psf file version");
bb_error_msg_and_die("unsupported psf file version");
fontsize = psf2h(buffer)->length;
if (psf2h(buffer)->flags & PSF2_HAS_UNICODE_TABLE)
has_table = 2;
@@ -311,19 +311,19 @@ static void do_load(int fd, unsigned char *buffer, size_t len)
} else
#endif
{
bb_simple_error_msg_and_die("input file: bad length or unsupported font type");
bb_error_msg_and_die("input file: bad length or unsupported font type");
}
#if !defined(PIO_FONTX) || defined(__sparc__)
if (fontsize != 256)
bb_simple_error_msg_and_die("only fontsize 256 supported");
bb_error_msg_and_die("only fontsize 256 supported");
#endif
table = font + fontsize * charsize;
buffer += len;
if (table > buffer || (!has_table && table != buffer))
bb_simple_error_msg_and_die("input file: bad length");
bb_error_msg_and_die("input file: bad length");
do_loadfont(fd, font, height, width, charsize, fontsize);
@@ -361,7 +361,7 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
buffer = xmalloc_read(STDIN_FILENO, &len);
// xmalloc_open_zipped_read_close(filename, &len);
if (!buffer)
bb_simple_perror_msg_and_die("error reading input font");
bb_perror_msg_and_die("error reading input font");
do_load(get_console_fd_or_die(), buffer, len);
return EXIT_SUCCESS;
@@ -502,7 +502,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
if (a < 0 || a >= E_TABSZ
|| b < 0 || b > 65535
) {
bb_simple_error_msg_and_die("map format");
bb_error_msg_and_die("map format");
}
// patch map
unicodes[a] = b;
+1 -1
View File
@@ -69,7 +69,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
xread(STDIN_FILENO, flags, 7);
if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
bb_simple_error_msg_and_die("not a valid binary keymap");
bb_error_msg_and_die("not a valid binary keymap");
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
+2 -2
View File
@@ -87,7 +87,7 @@ static int get_vt_fd(void)
fd = open(DEV_CONSOLE, O_RDONLY | O_NONBLOCK);
if (fd >= 0 && !not_vt_fd(fd))
return fd;
bb_simple_error_msg_and_die("can't find open VT");
bb_error_msg_and_die("can't find open VT");
}
static int find_free_vtno(void)
@@ -98,7 +98,7 @@ static int find_free_vtno(void)
errno = 0;
/*xfunc_error_retval = 3; - do we need compat? */
if (ioctl(fd, VT_OPENQRY, &vtno) != 0 || vtno <= 0)
bb_simple_perror_msg_and_die("can't find open VT");
bb_perror_msg_and_die("can't find open VT");
// Not really needed, grep for DAEMON_CLOSE_EXTRA_FDS
// if (fd > 2)
// close(fd);
+1 -1
View File
@@ -56,7 +56,7 @@ static void xset1(struct termios *t)
{
int ret = tcsetattr(STDIN_FILENO, TCSAFLUSH, t);
if (ret) {
bb_simple_perror_msg("can't tcsetattr for stdin");
bb_perror_msg("can't tcsetattr for stdin");
}
}
+2 -2
View File
@@ -21,15 +21,15 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
//usage:#define chgrp_trivial_usage
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... GROUP FILE..."
//usage: "[-RhLHP"IF_DESKTOP("cvf")"]... GROUP FILE..."
//usage:#define chgrp_full_usage "\n\n"
//usage: "Change the group membership of each FILE to GROUP\n"
//usage: "\n -R Recurse"
//usage: "\n -h Affect symlinks instead of symlink targets"
//usage: IF_DESKTOP(
//usage: "\n -L Traverse all symlinks to directories"
//usage: "\n -H Traverse symlinks on command line only"
//usage: "\n -P Don't traverse symlinks (default)"
//usage: IF_DESKTOP(
//usage: "\n -c List changed files"
//usage: "\n -v Verbose"
//usage: "\n -f Hide errors"
+2 -2
View File
@@ -217,7 +217,7 @@ int cp_main(int argc, char **argv)
// flags, FILEUTILS_RMDEST, OPT_parents);
if (flags & OPT_parents) {
if (!(d_flags & 2)) {
bb_simple_error_msg_and_die("with --parents, the destination must be a directory");
bb_error_msg_and_die("with --parents, the destination must be a directory");
}
}
if (flags & FILEUTILS_RMDEST) {
@@ -236,7 +236,7 @@ int cp_main(int argc, char **argv)
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
}
} else if (flags & FILEUTILS_NO_TARGET_DIR) {
bb_simple_error_msg_and_die("too many arguments");
bb_error_msg_and_die("too many arguments");
}
while (1) {
+3 -3
View File
@@ -209,11 +209,11 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
// argc -= optind;
argv += optind;
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields");
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
if (opt & CUT_OPT_DELIM_FLGS) {
if (ltok[0] && ltok[1]) { /* more than 1 char? */
bb_simple_error_msg_and_die("the delimiter must be a single character");
bb_error_msg_and_die("the delimiter must be a single character");
}
delim = ltok[0];
}
@@ -288,7 +288,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
/* make sure we got some cut positions out of all that */
if (nlists == 0)
bb_simple_error_msg_and_die("missing list of positions");
bb_error_msg_and_die("missing list of positions");
/* now that the lists are parsed, we need to sort them to make life
* easier on us when it comes time to print the chars / fields / lines
+9 -10
View File
@@ -33,9 +33,10 @@
//config: Enable option (-I) to output an ISO-8601 compliant
//config: date/time string.
//config:
//config:# defaults to "no": stat's nanosecond field is a bit non-portable
//config:config FEATURE_DATE_NANO
//config: bool "Support %[num]N nanosecond format specifier"
//config: default n # stat's nanosecond field is a bit non-portable
//config: default n # syscall(__NR_clock_gettime)
//config: depends on DATE
//config: select PLATFORM_LINUX
//config: help
@@ -53,7 +54,7 @@
//config: date -s (and other commands like touch -d) use more sensible
//config: formats (for one, ISO format YYYY-MM-DD hh:mm:ss.ssssss).
//config:
//config: With this option off, 'date DATE' and 'date -s DATE' support
//config: With this option off, 'date DATE' is 'date -s DATE' support
//config: the same format. With it on, 'date DATE' additionally supports
//config: MMDDhhmm[[YY]YY][.ss] format.
@@ -120,7 +121,7 @@
//usage: "\n -d,--date TIME Display TIME, not 'now'"
//usage: )
//usage: IF_FEATURE_DATE_ISOFMT(
//usage: "\n -D FMT Use FMT (strptime format) for -d TIME conversion"
//usage: "\n -D FMT Use FMT for -d TIME conversion"
//usage: )
//usage: "\n"
//usage: "\nRecognized TIME formats:"
@@ -271,14 +272,13 @@ int date_main(int argc UNUSED_PARAM, char **argv)
#endif
} else {
#if ENABLE_FEATURE_DATE_NANO
clock_gettime(CLOCK_REALTIME, &ts);
/* libc has incredibly messy way of doing this,
* typically requiring -lrt. We just skip all this mess */
syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
#else
time(&ts.tv_sec);
#endif
}
#if !ENABLE_FEATURE_DATE_NANO
ts.tv_nsec = 0;
#endif
localtime_r(&ts.tv_sec, &tm_time);
/* If date string is given, update tm_time, and maybe set date */
@@ -301,11 +301,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)
if (date_str[0] != '@')
tm_time.tm_isdst = -1;
ts.tv_sec = validate_tm_time(date_str, &tm_time);
ts.tv_nsec = 0;
/* if setting time, set it */
if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
bb_simple_perror_msg("can't set date");
if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
bb_perror_msg("can't set date");
}
}
+19 -23
View File
@@ -59,7 +59,7 @@
//usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]\n"
//usage: IF_FEATURE_DD_IBS_OBS(
//usage: " [conv=notrunc|noerror|sync|fsync]\n"
//usage: " [iflag=skip_bytes|fullblock] [oflag=seek_bytes|append]"
//usage: " [iflag=skip_bytes|fullblock] [oflag=seek_bytes]"
//usage: )
//usage:#define dd_full_usage "\n\n"
//usage: "Copy a file with converting and formatting\n"
@@ -84,7 +84,6 @@
//usage: "\n iflag=skip_bytes skip=N is in bytes"
//usage: "\n iflag=fullblock Read full blocks"
//usage: "\n oflag=seek_bytes seek=N is in bytes"
//usage: "\n oflag=append Open output file in append mode"
//usage: )
//usage: IF_FEATURE_DD_STATUS(
//usage: "\n status=noxfer Suppress rate output"
@@ -141,12 +140,11 @@ enum {
/* start of output flags */
FLAG_OFLAG_SHIFT = 7,
FLAG_SEEK_BYTES = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_APPEND = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
/* end of output flags */
FLAG_TWOBUFS = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 10,
FLAG_STATUS_NONE = 1 << 11,
FLAG_STATUS_NOXFER = 1 << 12,
FLAG_TWOBUFS = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 9,
FLAG_STATUS_NONE = 1 << 10,
FLAG_STATUS_NOXFER = 1 << 11,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -192,15 +190,23 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
#endif
}
static ssize_t full_write_or_warn(const void *buf, size_t len,
const char *const filename)
{
ssize_t n = full_write(ofd, buf, len);
if (n < 0)
bb_perror_msg("writing '%s'", filename);
return n;
}
static bool write_and_stats(const void *buf, size_t len, size_t obs,
const char *filename)
{
ssize_t n;
n = full_write(ofd, buf, len);
ssize_t n = full_write_or_warn(buf, len, filename);
if (n < 0)
return 1;
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
if (n > 0)
G.total_bytes += n;
G.total_bytes += n;
#endif
if ((size_t)n == obs) {
G.out_full++;
@@ -210,14 +216,6 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
G.out_part++;
return 0;
}
/* n is < len (and possibly is -1).
* Even if n >= 0, errno is usually set correctly.
* For example, if writing to block device and getting ENOSPC,
* full_write() first sees a short write, then tries to write
* the remainder and gets errno set to ENOSPC.
* It returns n > 0 (the amount which it did write).
*/
bb_perror_msg("error writing '%s'", filename);
return 1;
}
@@ -269,7 +267,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
static const char iflag_words[] ALIGN1 =
"skip_bytes\0""fullblock\0";
static const char oflag_words[] ALIGN1 =
"seek_bytes\0append\0";
"seek_bytes\0";
#endif
#if ENABLE_FEATURE_DD_STATUS
static const char status_words[] ALIGN1 =
@@ -453,8 +451,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (!seek && !(G.flags & FLAG_NOTRUNC))
oflag |= O_TRUNC;
if (G.flags & FLAG_APPEND)
oflag |= O_APPEND;
xmove_fd(xopen(outfile, oflag), ofd);
+1 -1
View File
@@ -178,7 +178,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
if (!argv[0]) {
mount_table = setmntent(bb_path_mtab_file, "r");
if (!mount_table)
bb_simple_perror_msg_and_die(bb_path_mtab_file);
bb_perror_msg_and_die(bb_path_mtab_file);
}
while (1) {
+2 -2
View File
@@ -290,11 +290,11 @@ int du_main(int argc UNUSED_PARAM, char **argv)
total = 0;
do {
total += du(*argv);
/* otherwise du /dir /dir won't show /dir twice: */
reset_ino_dev_hashtable();
G.slink_depth = slink_depth_save;
} while (*++argv);
if (ENABLE_FEATURE_CLEAN_UP)
reset_ino_dev_hashtable();
if (opt & OPT_c_total)
print(total, "total");
+1 -1
View File
@@ -188,7 +188,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
/*r =*/ full_write(STDOUT_FILENO, buffer, out - buffer);
free(buffer);
if (/*WRONG:r < 0*/ errno) {
bb_simple_perror_msg(bb_msg_write_error);
bb_perror_msg(bb_msg_write_error);
return 1;
}
return 0;
+1 -1
View File
@@ -79,7 +79,7 @@ int env_main(int argc UNUSED_PARAM, char **argv)
while (*argv && (strchr(*argv, '=') != NULL)) {
if (putenv(*argv) < 0) {
bb_simple_perror_msg_and_die("putenv");
bb_perror_msg_and_die("putenv");
}
++argv;
}
+12 -41
View File
@@ -63,62 +63,33 @@ enum {
OPT_ALL = 1 << 2,
};
//FIXME: does not work properly with input containing NULs
//coreutils 8.30 preserves NULs but treats them as chars of width zero:
//AB<nul><tab>C will expand <tab> to 6 spaces, not 5.
#if ENABLE_EXPAND
static void expand(FILE *file, unsigned tab_size, unsigned opt)
{
char *line;
for (;;) {
char *line;
while ((line = xmalloc_fgets(file)) != NULL) {
unsigned char c;
char *ptr;
char *ptr_strbeg;
//commented-out code handles NULs, +90 bytes of code, not tested much
// size_t linelen;
// unsigned len = 0;
// linelen = 1024 * 1024;
// line = xmalloc_fgets_str_len(file, "\n", &linelen);
line = xmalloc_fgets(file); //
if (!line)
break;
ptr = ptr_strbeg = line;
for (;;) {
unsigned char c = *ptr;
if (c == '\0') {
// size_t rem = line + linelen - ptr;
// if (rem > 0) {
//# if ENABLE_UNICODE_SUPPORT
// len += unicode_strwidth(ptr_strbeg);
//# else
// len += ptr - ptr_strbeg;
//# endif
// printf("%s%c", ptr_strbeg, '\0');
// memmove(ptr, ptr + 1, rem + 1);
// ptr_strbeg = ptr;
// linelen--;
// continue;
// }
break;
}
while ((c = *ptr) != '\0') {
if ((opt & OPT_INITIAL) && !isblank(c)) {
/* not space or tab */
break;
}
if (c == '\t') {
unsigned len = 0; //
unsigned len;
*ptr = '\0';
# if ENABLE_UNICODE_SUPPORT
len += unicode_strwidth(ptr_strbeg);
len = unicode_strwidth(ptr_strbeg);
# else
len += ptr - ptr_strbeg;
len = ptr - ptr_strbeg;
# endif
len = tab_size - (len % tab_size);
/*while (ptr[1] == '\t') { ptr++; len += tab_size; } - can handle many tabs at once */
printf("%s%*s", ptr_strbeg, len, "");
// len = 0;
ptr_strbeg = ptr + 1;
}
ptr++;
@@ -160,7 +131,7 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
putchar('\t');
}
if (!(opt & OPT_ALL) && ptr != line) {
if ((opt & OPT_INITIAL) && ptr != line) {
printf("%*s%s", len, "", ptr);
break;
}
@@ -207,13 +178,13 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
"ft:a"
"\0"
"ta" /* -t NUM sets -a */,
"first-only\0" No_argument "f"
"first-only\0" No_argument "i"
"tabs\0" Required_argument "t"
"all\0" No_argument "a"
, &opt_t
);
/* -t implies -a, but an explicit -f overrides */
if (opt & OPT_INITIAL) opt &= ~OPT_ALL;
/* -f --first-only is the default */
if (!(opt & OPT_ALL)) opt |= OPT_INITIAL;
}
tab_size = xatou_range(opt_t, 1, UINT_MAX);
@@ -247,7 +218,7 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
/* Now close stdin also */
/* (if we didn't read from it, it's a no-op) */
if (fclose(stdin))
bb_simple_perror_msg_and_die(bb_msg_standard_input);
bb_perror_msg_and_die(bb_msg_standard_input);
fflush_stdout_and_exit(exit_status);
}
+8 -8
View File
@@ -249,7 +249,7 @@ static arith_t arithmetic_common(VALUE *l, VALUE *r, int op)
arith_t li, ri;
if (!toarith(l) || !toarith(r))
bb_simple_error_msg_and_die("non-numeric argument");
bb_error_msg_and_die("non-numeric argument");
li = l->u.i;
ri = r->u.i;
if (op == '+')
@@ -259,7 +259,7 @@ static arith_t arithmetic_common(VALUE *l, VALUE *r, int op)
if (op == '*')
return li * ri;
if (ri == 0)
bb_simple_error_msg_and_die("division by zero");
bb_error_msg_and_die("division by zero");
if (op == '/')
return li / ri;
return li % ri;
@@ -319,19 +319,19 @@ static VALUE *eval7(void)
VALUE *v;
if (!*G.args)
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
if (nextarg("(")) {
G.args++;
v = eval();
if (!nextarg(")"))
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
G.args++;
return v;
}
if (nextarg(")"))
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
return str_value(*G.args++);
}
@@ -353,7 +353,7 @@ static VALUE *eval6(void)
G.args++; /* We have a valid token, so get the next argument. */
if (key == 1) { /* quote */
if (!*G.args)
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
return str_value(*G.args++);
}
if (key == 2) { /* length */
@@ -546,11 +546,11 @@ int expr_main(int argc UNUSED_PARAM, char **argv)
xfunc_error_retval = 2; /* coreutils compat */
G.args = argv + 1;
if (*G.args == NULL) {
bb_simple_error_msg_and_die("too few arguments");
bb_error_msg_and_die("too few arguments");
}
v = eval();
if (*G.args)
bb_simple_error_msg_and_die("syntax error");
bb_error_msg_and_die("syntax error");
if (v->type == INTEGER)
printf("%" PF_REZ "d\n", PF_REZ_TYPE v->u.i);
else
+60
View File
@@ -0,0 +1,60 @@
/* vi: set sw=4 ts=4: */
/*
* Mini fsync implementation for busybox
*
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FSYNC
//config: bool "fsync (3.6 kb)"
//config: default y
//config: help
//config: fsync is used to flush file-related cached blocks to disk.
//applet:IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync))
//kbuild:lib-$(CONFIG_FSYNC) += fsync.o
//usage:#define fsync_trivial_usage
//usage: "[-d] FILE..."
//usage:#define fsync_full_usage "\n\n"
//usage: "Write files' buffered blocks to disk\n"
//usage: "\n -d Avoid syncing metadata"
#include "libbb.h"
#ifndef O_NOATIME
# define O_NOATIME 0
#endif
/* This is a NOFORK applet. Be very careful! */
int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int fsync_main(int argc UNUSED_PARAM, char **argv)
{
int status;
int opts;
opts = getopt32(argv, "d"); /* fdatasync */
argv += optind;
if (!*argv) {
bb_show_usage();
}
status = EXIT_SUCCESS;
do {
int fd = open_or_warn(*argv, O_NOATIME | O_NOCTTY | O_RDONLY);
if (fd == -1) {
status = EXIT_FAILURE;
continue;
}
if ((opts ? fdatasync(fd) : fsync(fd))) {
//status = EXIT_FAILURE; - do we want this?
bb_simple_perror_msg(*argv);
}
close(fd);
} while (*++argv);
return status;
}
+1 -1
View File
@@ -231,7 +231,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
}
} else if (n < 0) { /* error in get_groups() */
if (ENABLE_DESKTOP)
bb_simple_error_msg_and_die("can't get groups");
bb_error_msg_and_die("can't get groups");
return EXIT_FAILURE;
}
if (ENABLE_FEATURE_CLEAN_UP)
+1 -1
View File
@@ -238,7 +238,7 @@ int install_main(int argc, char **argv)
args[2] = dest;
args[3] = NULL;
if (spawn_and_wait(args)) {
bb_simple_perror_msg("strip");
bb_perror_msg("strip");
ret = EXIT_FAILURE;
}
}
+6 -23
View File
@@ -29,7 +29,7 @@
//usage: "\n -n Don't dereference symlinks - treat like normal file"
//usage: "\n -b Make a backup of the target (if exists) before link operation"
//usage: "\n -S suf Use suffix instead of ~ when making backup files"
//usage: "\n -T Treat LINK as a file, not DIR"
//usage: "\n -T 2nd arg must be a DIR"
//usage: "\n -v Verbose"
//usage:
//usage:#define ln_example_usage
@@ -41,6 +41,7 @@
/* This is a NOEXEC applet. Be very careful! */
#define LN_SYMLINK (1 << 0)
#define LN_FORCE (1 << 1)
#define LN_NODEREFERENCE (1 << 2)
@@ -62,28 +63,13 @@ int ln_main(int argc, char **argv)
int (*link_func)(const char *, const char *);
opts = getopt32(argv, "^" "sfnbS:vT" "\0" "-1", &suffix);
/*
-s, --symbolic make symbolic links instead of hard links
-f, --force remove existing destination files
-n, --no-dereference treat LINK_NAME as a normal file if it is a symbolic link to a directory
-b like --backup but does not accept an argument
--backup[=CONTROL] make a backup of each existing destination file
-S, --suffix=SUFFIX override the usual backup suffix
-v, --verbose
-T, --no-target-directory
-d, -F, --directory allow the superuser to attempt to hard link directories
-i, --interactive prompt whether to remove destinations
-L, --logical dereference TARGETs that are symbolic links
-P, --physical make hard links directly to symbolic links
-r, --relative create symbolic links relative to link location
-t, --target-directory=DIRECTORY specify the DIRECTORY in which to create the links
*/
last = argv[argc - 1];
argv += optind;
argc -= optind;
if ((opts & LN_LINKFILE) && argc > 2) {
bb_simple_error_msg_and_die("-T accepts 2 args max");
bb_error_msg_and_die("-T accepts 2 args max");
}
if (!argv[1]) {
@@ -100,11 +86,8 @@ int ln_main(int argc, char **argv)
src = last;
if (is_directory(src,
/*followlinks:*/ !(opts & (LN_NODEREFERENCE|LN_LINKFILE))
/* Why LN_LINKFILE does not follow links:
* -T/--no-target-directory implies -n/--no-dereference
*/
)
(opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE
)
) {
if (opts & LN_LINKFILE) {
bb_error_msg_and_die("'%s' is a directory", src);
+1 -1
View File
@@ -56,5 +56,5 @@ int logname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
return fflush_all();
}
bb_simple_perror_msg_and_die("getlogin");
bb_perror_msg_and_die("getlogin");
}
+1 -1
View File
@@ -1086,7 +1086,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
static const char ls_longopts[] ALIGN1 =
"full-time\0" No_argument "\xff"
"group-directories-first\0" No_argument "\xfe"
IF_FEATURE_LS_COLOR("color\0" Optional_argument "\xfd")
"color\0" Optional_argument "\xfd"
;
#endif
+1 -1
View File
@@ -300,7 +300,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
}
if (filename_ptr == NULL) {
if (flags & FLAG_WARN) {
bb_simple_error_msg("invalid format");
bb_error_msg("invalid format");
}
count_failed++;
return_value = EXIT_FAILURE;
+6 -6
View File
@@ -536,7 +536,7 @@ check_and_close(void)
}
if (ferror(stdout)) {
bb_simple_error_msg_and_die(bb_msg_write_error);
bb_error_msg_and_die(bb_msg_write_error);
}
}
@@ -841,7 +841,7 @@ skip(off_t n_skip)
}
if (n_skip)
bb_simple_error_msg_and_die("can't skip past end of combined input");
bb_error_msg_and_die("can't skip past end of combined input");
}
@@ -1308,10 +1308,10 @@ int od_main(int argc UNUSED_PARAM, char **argv)
pseudo_start = o2;
argv[1] = NULL;
} else {
bb_simple_error_msg_and_die("the last two arguments must be offsets");
bb_error_msg_and_die("the last two arguments must be offsets");
}
} else { /* >3 args */
bb_simple_error_msg_and_die("too many arguments");
bb_error_msg_and_die("too many arguments");
}
if (pseudo_start >= 0) {
@@ -1332,7 +1332,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
if (option_mask32 & OPT_N) {
end_offset = n_bytes_to_skip + max_bytes_to_format;
if (end_offset < n_bytes_to_skip)
bb_simple_error_msg_and_die("SKIP + SIZE is too large");
bb_error_msg_and_die("SKIP + SIZE is too large");
}
if (G.n_specs == 0) {
@@ -1389,7 +1389,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
dump(n_bytes_to_skip, end_offset);
if (fclose(stdin))
bb_simple_perror_msg_and_die(bb_msg_standard_input);
bb_perror_msg_and_die(bb_msg_standard_input);
return G.exit_code;
}
+1 -1
View File
@@ -116,7 +116,7 @@ int paste_main(int argc UNUSED_PARAM, char **argv)
if (opt & PASTE_OPT_DELIMITERS) {
if (!delims[0])
bb_simple_error_msg_and_die("-d '' is not supported");
bb_error_msg_and_die("-d '' is not supported");
/* unknown mappings are not changed: "\z" -> '\\' 'z' */
/* trailing backslash, if any, is preserved */
del_cnt = strcpy_and_process_escape_sequences(delims, delims) - delims;
+1 -1
View File
@@ -430,7 +430,7 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
if (ENABLE_ASH_PRINTF
&& applet_name[0] != 'p'
) {
bb_simple_error_msg("usage: printf FORMAT [ARGUMENT...]");
bb_error_msg("usage: printf FORMAT [ARGUMENT...]");
return 2; /* bash compat */
}
bb_show_usage();
+1 -1
View File
@@ -62,7 +62,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
const char *base = bb_get_last_path_component_strip(*argv);
if (DOT_OR_DOTDOT(base)) {
bb_simple_error_msg("can't remove '.' or '..'");
bb_error_msg("can't remove '.' or '..'");
} else if (remove_file(*argv, flags) >= 0) {
continue;
}
-5
View File
@@ -68,11 +68,6 @@ int sleep_main(int argc UNUSED_PARAM, char **argv)
if (!*argv)
bb_show_usage();
/* GNU sleep accepts "inf", "INF", "infinity" and "INFINITY" */
if (strncasecmp(argv[0], "inf", 3) == 0)
for (;;)
sleep(INT_MAX);
#if ENABLE_FEATURE_FANCY_SLEEP
# if ENABLE_FLOAT_DURATION
/* undo busybox.c setlocale */
+6 -6
View File
@@ -277,7 +277,7 @@ static int compare_keys(const void *xarg, const void *yarg)
/* Perform actual comparison */
switch (flags & (FLAG_n | FLAG_g | FLAG_M | FLAG_V)) {
default:
bb_simple_error_msg_and_die("unknown sort type");
bb_error_msg_and_die("unknown sort type");
break;
#if defined(HAVE_STRVERSCMP) && HAVE_STRVERSCMP == 1
case FLAG_V:
@@ -398,10 +398,10 @@ static unsigned str2u(char **str)
{
unsigned long lu;
if (!isdigit((*str)[0]))
bb_simple_error_msg_and_die("bad field specification");
bb_error_msg_and_die("bad field specification");
lu = strtoul(*str, str, 10);
if ((sizeof(long) > sizeof(int) && lu > INT_MAX) || !lu)
bb_simple_error_msg_and_die("bad field specification");
bb_error_msg_and_die("bad field specification");
return lu;
}
#endif
@@ -461,7 +461,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_SORT_BIG
if (opts & FLAG_t) {
if (!str_t[0] || str_t[1])
bb_simple_error_msg_and_die("bad -t parameter");
bb_error_msg_and_die("bad -t parameter");
key_separator = str_t[0];
}
/* note: below this point we use option_mask32, not opts,
@@ -504,10 +504,10 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
because comma isn't in OPT_STR */
idx = strchr(OPT_STR, *str_k);
if (!idx)
bb_simple_error_msg_and_die("unknown key option");
bb_error_msg_and_die("unknown key option");
flag = 1 << (idx - OPT_STR);
if (flag & ~FLAG_allowed_for_k)
bb_simple_error_msg_and_die("unknown sort type");
bb_error_msg_and_die("unknown sort type");
/* b after ',' means strip _trailing_ space */
if (i && flag == FLAG_b)
flag = FLAG_bb;
+2 -2
View File
@@ -127,7 +127,7 @@ int split_main(int argc UNUSED_PARAM, char **argv)
}
if (NAME_MAX < strlen(sfx) + suffix_len)
bb_simple_error_msg_and_die("suffix too long");
bb_error_msg_and_die("suffix too long");
{
char *char_p = xzalloc(suffix_len + 1);
@@ -147,7 +147,7 @@ int split_main(int argc UNUSED_PARAM, char **argv)
do {
if (!remaining) {
if (!pfx)
bb_simple_error_msg_and_die("suffixes exhausted");
bb_error_msg_and_die("suffixes exhausted");
xmove_fd(xopen(pfx, O_WRONLY | O_CREAT | O_TRUNC), 1);
pfx = next_file(pfx, suffix_len);
remaining = cnt;
+82 -83
View File
@@ -150,57 +150,25 @@ static const char *file_type(const struct stat *st)
return "weird file";
}
static const char *human_time(struct timespec *ts)
static const char *human_time(time_t t)
{
char fmt[sizeof("%Y-%m-%d %H:%M:%S.123456789 %z") + /*paranoia*/ 8];
/* Old
static char *str;
str = ctime(&t);
str[strlen(str)-1] = '\0';
return str;
*/
/* coreutils 6.3 compat: */
/* coreutils 6.3 compat */
/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
#define buf bb_common_bufsiz1
setup_common_bufsiz();
sprintf(stpcpy(fmt, "%Y-%m-%d %H:%M:%S"), ".%09u %%z", (unsigned)ts->tv_nsec);
strftime(buf, COMMON_BUFSIZE, fmt, localtime(&ts->tv_sec));
strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000");
return buf;
#undef buf
}
#if ENABLE_FEATURE_STAT_FILESYSTEM
#define FS_TYPE_LIST \
FS_TYPE(0xADFF, "affs") \
FS_TYPE(0x1CD1, "devpts") \
FS_TYPE(0x137D, "ext") \
FS_TYPE(0xEF51, "ext2") \
FS_TYPE(0xEF53, "ext2/ext3") \
FS_TYPE(0x3153464a, "jfs") \
FS_TYPE(0x58465342, "xfs") \
FS_TYPE(0xF995E849, "hpfs") \
FS_TYPE(0x9660, "isofs") \
FS_TYPE(0x4000, "isofs") \
FS_TYPE(0x4004, "isofs") \
FS_TYPE(0x137F, "minix") \
FS_TYPE(0x138F, "minix (30 char.)") \
FS_TYPE(0x2468, "minix v2") \
FS_TYPE(0x2478, "minix v2 (30 char.)") \
FS_TYPE(0x4d44, "msdos") \
FS_TYPE(0x4006, "fat") \
FS_TYPE(0x564c, "novell") \
FS_TYPE(0x6969, "nfs") \
FS_TYPE(0x9fa0, "proc") \
FS_TYPE(0x517B, "smb") \
FS_TYPE(0x012FF7B4, "xenix") \
FS_TYPE(0x012FF7B5, "sysv4") \
FS_TYPE(0x012FF7B6, "sysv2") \
FS_TYPE(0x012FF7B7, "coh") \
FS_TYPE(0x00011954, "ufs") \
FS_TYPE(0x012FD16D, "xia") \
FS_TYPE(0x5346544e, "ntfs") \
FS_TYPE(0x1021994, "tmpfs") \
FS_TYPE(0x52654973, "reiserfs") \
FS_TYPE(0x28cd3d45, "cramfs") \
FS_TYPE(0x7275, "romfs") \
FS_TYPE(0x858458f6, "ramfs") \
FS_TYPE(0x73717368, "squashfs") \
FS_TYPE(0x62656572, "sysfs")
/* 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)
@@ -208,22 +176,54 @@ FS_TYPE(0x62656572, "sysfs")
*/
static const char *human_fstype(uint32_t f_type)
{
# define FS_TYPE(type, name) type,
static const uint32_t fstype[] = {
FS_TYPE_LIST
static const struct types {
uint32_t type;
const char *const fs;
} humantypes[] = {
{ 0xADFF, "affs" },
{ 0x1Cd1, "devpts" },
{ 0x137D, "ext" },
{ 0xEF51, "ext2" },
{ 0xEF53, "ext2/ext3" },
{ 0x3153464a, "jfs" },
{ 0x58465342, "xfs" },
{ 0xF995E849, "hpfs" },
{ 0x9660, "isofs" },
{ 0x4000, "isofs" },
{ 0x4004, "isofs" },
{ 0x137F, "minix" },
{ 0x138F, "minix (30 char.)" },
{ 0x2468, "minix v2" },
{ 0x2478, "minix v2 (30 char.)" },
{ 0x4d44, "msdos" },
{ 0x4006, "fat" },
{ 0x564c, "novell" },
{ 0x6969, "nfs" },
{ 0x9fa0, "proc" },
{ 0x517B, "smb" },
{ 0x012FF7B4, "xenix" },
{ 0x012FF7B5, "sysv4" },
{ 0x012FF7B6, "sysv2" },
{ 0x012FF7B7, "coh" },
{ 0x00011954, "ufs" },
{ 0x012FD16D, "xia" },
{ 0x5346544e, "ntfs" },
{ 0x1021994, "tmpfs" },
{ 0x52654973, "reiserfs" },
{ 0x28cd3d45, "cramfs" },
{ 0x7275, "romfs" },
{ 0x858458f6, "ramfs" },
{ 0x73717368, "squashfs" },
{ 0x62656572, "sysfs" },
{ 0, "UNKNOWN" }
};
# undef FS_TYPE
# define FS_TYPE(type, name) name"\0"
static const char humanname[] ALIGN1 =
FS_TYPE_LIST
"UNKNOWN";
# undef FS_TYPE
int i;
for (i = 0; i < ARRAY_SIZE(fstype); ++i)
if (fstype[i] == f_type)
for (i = 0; humantypes[i].type; ++i)
if (humantypes[i].type == f_type)
break;
return nth_string(humanname, i);
return humantypes[i].fs;
}
/* "man statfs" says that statfsbuf->f_fsid is a mess */
@@ -380,19 +380,19 @@ static void FAST_FUNC print_stat(char *pformat, const char m,
strcat(pformat, "lu");
printf(pformat, (unsigned long) statbuf->st_blksize);
} else if (m == 'x') {
printfs(pformat, human_time(&statbuf->st_atim));
printfs(pformat, human_time(statbuf->st_atime));
} else if (m == 'X') {
strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
/* note: (unsigned long) would be wrong:
* imagine (unsigned long64)int32 */
printf(pformat, (long) statbuf->st_atime);
} else if (m == 'y') {
printfs(pformat, human_time(&statbuf->st_mtim));
printfs(pformat, human_time(statbuf->st_mtime));
} else if (m == 'Y') {
strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
printf(pformat, (long) statbuf->st_mtime);
} else if (m == 'z') {
printfs(pformat, human_time(&statbuf->st_ctim));
printfs(pformat, human_time(statbuf->st_ctime));
} else if (m == 'Z') {
strcat(pformat, TYPE_SIGNED(time_t) ? "ld" : "lu");
printf(pformat, (long) statbuf->st_ctime);
@@ -497,7 +497,7 @@ static bool do_statfs(const char *filename, const char *format)
if (format == NULL) {
# if !ENABLE_SELINUX
format = (option_mask32 & OPT_TERSE
? "%n %i %l %t %s %b %f %a %c %d"
? "%n %i %l %t %s %b %f %a %c %d\n"
: " File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
@@ -505,26 +505,25 @@ static bool do_statfs(const char *filename, const char *format)
"Inodes: Total: %-10c Free: %d");
# else
format = (option_mask32 & OPT_TERSE
? (option_mask32 & OPT_SELINUX
? "%n %i %l %t %s %b %f %a %c %d %C"
: "%n %i %l %t %s %b %f %a %c %d")
: (option_mask32 & OPT_SELINUX
? " File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
"Inodes: Total: %-10c Free: %d"
" S_context: %C"
: " File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
"Inodes: Total: %-10c Free: %d")
? (option_mask32 & OPT_SELINUX ? "%n %i %l %t %s %b %f %a %c %d %C\n":
"%n %i %l %t %s %b %f %a %c %d\n")
: (option_mask32 & OPT_SELINUX ?
" File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
"Inodes: Total: %-10c Free: %d"
" S_context: %C\n":
" File: \"%n\"\n"
" ID: %-8i Namelen: %-7l Type: %T\n"
"Block size: %-10s\n"
"Blocks: Total: %-10b Free: %-10f Available: %a\n"
"Inodes: Total: %-10c Free: %d\n")
);
# endif /* SELINUX */
}
print_it(format, filename, print_statfs, &statfsbuf IF_SELINUX(, scontext));
#else /* !FEATURE_STAT_FORMAT */
#else /* FEATURE_STAT_FORMAT */
format = (option_mask32 & OPT_TERSE
? "%s %llx %lu "
: " File: \"%s\"\n"
@@ -621,14 +620,14 @@ static bool do_stat(const char *filename, const char *format)
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
" Device type: %t,%T\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"Access: %x\n" "Modify: %y\n" "Change: %z";
"Access: %x\n" "Modify: %y\n" "Change: %z\n";
} else {
format =
" File: %N\n"
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"Access: %x\n" "Modify: %y\n" "Change: %z";
"Access: %x\n" "Modify: %y\n" "Change: %z\n";
}
}
# else
@@ -647,14 +646,14 @@ static bool do_stat(const char *filename, const char *format)
" Device type: %t,%T\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
" S_Context: %C\n"
"Access: %x\n" "Modify: %y\n" "Change: %z"
"Access: %x\n" "Modify: %y\n" "Change: %z\n"
:
" File: %N\n"
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
"Device: %Dh/%dd\tInode: %-10i Links: %-5h"
" Device type: %t,%T\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"Access: %x\n" "Modify: %y\n" "Change: %z"
"Access: %x\n" "Modify: %y\n" "Change: %z\n"
);
} else {
format = (option_mask32 & OPT_SELINUX ?
@@ -663,13 +662,13 @@ static bool do_stat(const char *filename, const char *format)
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"S_Context: %C\n"
"Access: %x\n" "Modify: %y\n" "Change: %z"
"Access: %x\n" "Modify: %y\n" "Change: %z\n"
:
" File: %N\n"
" Size: %-10s\tBlocks: %-10b IO Block: %-6o %F\n"
"Device: %Dh/%dd\tInode: %-10i Links: %h\n"
"Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n"
"Access: %x\n" "Modify: %y\n" "Change: %z"
"Access: %x\n" "Modify: %y\n" "Change: %z\n"
);
}
}
@@ -746,9 +745,9 @@ static bool do_stat(const char *filename, const char *format)
if (option_mask32 & OPT_SELINUX)
printf(" S_Context: %s\n", scontext);
# endif
printf("Access: %s\n", human_time(&statbuf.st_atim));
printf("Modify: %s\n", human_time(&statbuf.st_mtim));
printf("Change: %s\n", human_time(&statbuf.st_ctim));
printf("Access: %s\n", human_time(statbuf.st_atime));
printf("Modify: %s\n", human_time(statbuf.st_mtime));
printf("Change: %s\n", human_time(statbuf.st_ctime));
}
#endif /* FEATURE_STAT_FORMAT */
return 1;
+15 -9
View File
@@ -5,7 +5,18 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* David MacKenzie <djm@gnu.ai.mit.edu>
/* Usage: stty [-ag] [-F device] [setting...]
*
* Options:
* -a Write all current settings to stdout in human-readable form.
* -g Write all current settings to stdout in stty-readable form.
* -F Open and use the specified device instead of stdin
*
* If no args are given, write to stdout the baud rate and settings that
* have been changed from their defaults. Mode reading and changes
* are done on the specified device, or stdin if none was specified.
*
* David MacKenzie <djm@gnu.ai.mit.edu>
*
* Special for busybox ported by Vladimir Oleynik <dzo@simtreas.ru> 2001
*/
@@ -29,11 +40,6 @@
//usage: "\n -g Print in stty-readable form"
//usage: "\n [SETTING] See manpage"
/* If no args are given, write to stdout the baud rate and settings that
* have been changed from their defaults. Mode reading and changes
* are done on the specified device, or stdin if none was specified.
*/
#include "libbb.h"
#include "common_bufsiz.h"
@@ -1320,7 +1326,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
break;
case 'F':
if (file_name)
bb_simple_error_msg_and_die("only one device may be specified");
bb_error_msg_and_die("only one device may be specified");
file_name = &arg[i+1]; /* "-Fdevice" ? */
if (!file_name[0]) { /* nope, "-F device" */
int p = k+1; /* argv[p] is argnext */
@@ -1405,13 +1411,13 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) ==
(STTY_verbose_output | STTY_recoverable_output)
) {
bb_simple_error_msg_and_die("-a and -g are mutually exclusive");
bb_error_msg_and_die("-a and -g are mutually exclusive");
}
/* Specifying -a or -g with non-options is an error */
if ((stty_state & (STTY_verbose_output | STTY_recoverable_output))
&& !(stty_state & STTY_noargs)
) {
bb_simple_error_msg_and_die("modes may not be set when -a or -g is used");
bb_error_msg_and_die("modes may not be set when -a or -g is used");
}
/* Now it is safe to start doing things */
+32 -70
View File
@@ -20,7 +20,6 @@
//config: sync -d FILE... executes fdatasync() on each FILE.
//config: sync -f FILE... executes syncfs() on each FILE.
// APPLET_NOFORK:name main location suid_type help
//applet:IF_SYNC(APPLET_NOFORK(sync, sync, BB_DIR_BIN, BB_SUID_DROP, sync))
//kbuild:lib-$(CONFIG_SYNC) += sync.o
@@ -43,98 +42,61 @@
/* This is a NOFORK applet. Be very careful! */
#if ENABLE_FEATURE_SYNC_FANCY || ENABLE_FSYNC
static int sync_common(int opts, char **argv)
int sync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
{
int ret;
#if !ENABLE_FEATURE_SYNC_FANCY
/* coreutils-6.9 compat */
bb_warn_ignoring_args(argv[1]);
sync();
return EXIT_SUCCESS;
#else
unsigned opts;
int ret = EXIT_SUCCESS;
enum {
OPT_DATASYNC = (1 << 0),
OPT_SYNCFS = (1 << 1),
};
ret = EXIT_SUCCESS;
do {
/* GNU "sync FILE" uses O_NONBLOCK open */
int fd = open_or_warn(*argv, /*O_NOATIME |*/ O_NOCTTY | O_RDONLY | O_NONBLOCK);
/* open(NOATIME) can only be used by owner or root, don't use NOATIME here */
opts = getopt32(argv, "^" "df" "\0" "d--f:f--d");
argv += optind;
/* Handle the no-argument case. */
if (!argv[0])
sync();
while (*argv) {
int fd = open_or_warn(*argv, O_RDONLY);
if (fd < 0) {
ret = EXIT_FAILURE;
goto next;
}
# if ENABLE_FEATURE_SYNC_FANCY
if (opts & OPT_DATASYNC) {
if (fdatasync(fd))
goto err;
goto do_close;
}
if (opts & OPT_SYNCFS) {
/*
* syncfs is documented to only fail with EBADF,
* which can't happen here. So, no error checks.
*/
syncfs(fd);
} else
# endif
if (((opts & OPT_DATASYNC) ? fdatasync(fd) : fsync(fd)) != 0) {
goto do_close;
}
if (fsync(fd)) {
err:
bb_simple_perror_msg(*argv);
ret = EXIT_FAILURE;
}
do_close:
close(fd);
next:
argv++;
} while (*argv);
++argv;
}
return ret;
}
#endif
#if ENABLE_SYNC
int sync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
{
# if !ENABLE_FEATURE_SYNC_FANCY
/* coreutils-6.9 compat */
bb_warn_ignoring_args(argv[1]);
sync();
return EXIT_SUCCESS;
# else
unsigned opts = getopt32(argv, "^" "df" "\0" "d--f:f--d");
argv += optind;
if (!argv[0]) {
sync();
return EXIT_SUCCESS;
}
return sync_common(opts, argv);
# endif
}
#endif
/*
* Mini fsync implementation for busybox
*
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config FSYNC
//config: bool "fsync (3.6 kb)"
//config: default y
//config: help
//config: fsync is used to flush file-related cached blocks to disk.
// APPLET_NOFORK:name main location suid_type help
//applet:IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync))
//kbuild:lib-$(CONFIG_FSYNC) += sync.o
//usage:#define fsync_trivial_usage
//usage: "[-d] FILE..."
//usage:#define fsync_full_usage "\n\n"
//usage: "Write all buffered blocks in FILEs to disk\n"
//usage: "\n -d Avoid syncing metadata"
#if ENABLE_FSYNC
int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int fsync_main(int argc UNUSED_PARAM, char **argv)
{
int opts = getopt32(argv, "^" "d" "\0" "-1"/*min 1 arg*/);
argv += optind;
return sync_common(opts, argv);
}
#endif
+2 -2
View File
@@ -89,7 +89,7 @@ static ssize_t tail_read(int fd, char *buf, size_t count)
r = full_read(fd, buf, count);
if (r < 0) {
bb_simple_perror_msg(bb_msg_read_error);
bb_perror_msg(bb_msg_read_error);
G.exitcode = EXIT_FAILURE;
}
@@ -186,7 +186,7 @@ int tail_main(int argc, char **argv)
} while (++i < argc);
if (!nfiles)
bb_simple_error_msg_and_die("no files");
bb_error_msg_and_die("no files");
/* prepare the buffer */
tailbufsize = BUFSIZ;
+4 -20
View File
@@ -39,19 +39,6 @@
//usage: "$ cat /tmp/foo\n"
//usage: "Hello\n"
// Bare "tee" with no below options does not install SIGPIPE handler - just dies on it.
// TODO:
// --output-error[=MODE]
// 'warn' diagnose errors writing to any output
// 'warn-nopipe' diagnose errors writing to any output not a pipe
// 'exit' exit on error writing to any output
// 'exit-nopipe' exit on error writing to any output not a pipe
// ^^^ all of these should set SIGPIPE to SIG_IGN.
// Because "exit" mode should print error message and exit1(1) - not die on SIGPIPE.
// "exit-nopipe" does not exit on EPIPE and does not set exitcode to 1 too.
// -p diagnose errors writing to non pipes
// ^^^^ this should set SIGPIPE to SIG_IGN. EPIPE is ignored (same as "warn-nopipe")
#include "libbb.h"
#include "common_bufsiz.h"
@@ -79,12 +66,12 @@ int tee_main(int argc, char **argv)
mode += (retval & 2); /* Since 'a' is the 2nd option... */
if (retval & 1) {
signal(SIGINT, SIG_IGN);
signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */
}
retval = EXIT_SUCCESS;
/* if (opt_p || opt_output_error)
signal(SIGPIPE, SIG_IGN);
*/
/* gnu tee ignores SIGPIPE in case one of the output files is a pipe
* that doesn't consume all its input. Good idea... */
signal(SIGPIPE, SIG_IGN);
/* Allocate an array of FILE *'s, with one extra for a sentinel. */
fp = files = xzalloc(sizeof(FILE *) * (argc + 2));
@@ -92,7 +79,6 @@ int tee_main(int argc, char **argv)
files[0] = stdout;
goto GOT_NEW_FILE;
do {
*fp = stdout;
if (NOT_LONE_DASH(*argv)) {
@@ -116,7 +102,6 @@ int tee_main(int argc, char **argv)
fp = files;
do
fwrite(buf, 1, c, *fp);
/* if (opt_p && fwrite() != c && !EPIPE) bb_error_msg("..."); */
while (*++fp);
}
if (c < 0) { /* Make sure read errors are signaled. */
@@ -128,7 +113,6 @@ int tee_main(int argc, char **argv)
fp = files;
do
putc(c, *fp);
/* if (opt_p && putc() == EOF && !EPIPE) bb_error_msg("..."); */
while (*++fp);
}
#endif
+3 -3
View File
@@ -411,7 +411,7 @@ extern struct test_statics *const test_ptr_to_statics;
#define leaving (S.leaving )
#define INIT_S() do { \
(*(struct test_statics**)not_const_pp(&test_ptr_to_statics)) = xzalloc(sizeof(S)); \
(*(struct test_statics**)&test_ptr_to_statics) = xzalloc(sizeof(S)); \
barrier(); \
} while (0)
#define DEINIT_S() do { \
@@ -832,12 +832,12 @@ int test_main(int argc, char **argv)
--argc;
if (!arg0[1]) { /* "[" ? */
if (NOT_LONE_CHAR(argv[argc], ']')) {
bb_simple_error_msg("missing ]");
bb_error_msg("missing ]");
return 2;
}
} else { /* assuming "[[" */
if (strcmp(argv[argc], "]]") != 0) {
bb_simple_error_msg("missing ]]");
bb_error_msg("missing ]]");
return 2;
}
}
+2 -2
View File
@@ -308,7 +308,7 @@ int tr_main(int argc UNUSED_PARAM, char **argv)
str1_length = complement(str1, str1_length);
if (*argv) {
if (argv[0][0] == '\0')
bb_simple_error_msg_and_die("STRING2 cannot be empty");
bb_error_msg_and_die("STRING2 cannot be empty");
str2_length = expand(*argv, &str2);
map(vector, str1, str1_length,
str2, str2_length);
@@ -333,7 +333,7 @@ int tr_main(int argc UNUSED_PARAM, char **argv)
read_chars = safe_read(STDIN_FILENO, str1, TR_BUFSIZ);
if (read_chars <= 0) {
if (read_chars < 0)
bb_simple_perror_msg_and_die(bb_msg_read_error);
bb_perror_msg_and_die(bb_msg_read_error);
break;
}
in_index = 0;
+4 -4
View File
@@ -82,7 +82,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
continue;
}
if (encoded_len > 60) {
bb_simple_error_msg_and_die("line too long");
bb_error_msg_and_die("line too long");
}
dst = line;
@@ -108,7 +108,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
fwrite(line, 1, dst - line, dst_stream);
free(line);
}
bb_simple_error_msg_and_die("short file");
bb_error_msg_and_die("short file");
}
#endif
@@ -166,7 +166,7 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
/* fclose_if_not_stdin(src_stream); - redundant */
return EXIT_SUCCESS;
}
bb_simple_error_msg_and_die("no 'begin' line");
bb_error_msg_and_die("no 'begin' line");
}
#endif
@@ -216,7 +216,7 @@ int base64_main(int argc UNUSED_PARAM, char **argv)
if (!size)
break;
if ((ssize_t)size < 0)
bb_simple_perror_msg_and_die(bb_msg_read_error);
bb_perror_msg_and_die(bb_msg_read_error);
/* Encode the buffer we just read in */
bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64);
xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3));
+1 -1
View File
@@ -66,7 +66,7 @@ int uuencode_main(int argc UNUSED_PARAM, char **argv)
if (!size)
break;
if ((ssize_t)size < 0)
bb_simple_perror_msg_and_die(bb_msg_read_error);
bb_perror_msg_and_die(bb_msg_read_error);
/* Encode the buffer we just read in */
bb_uuencode(dst_buf, src_buf, size, tbl);
bb_putchar('\n');
+34 -64
View File
@@ -94,7 +94,7 @@ Misc options:
//usage: "\n -n NAME Match processes with NAME"
//usage: "\n in comm field in /proc/PID/stat"
//usage: "\n -x EXECUTABLE Match processes with this command"
//usage: "\n in /proc/PID/cmdline"
//usage: "\n command in /proc/PID/cmdline"
//usage: "\n -p FILE Match a process with PID from FILE"
//usage: "\n All specified conditions must match"
//usage: "\n-S only:"
@@ -317,7 +317,7 @@ static void do_procinit(void)
}
closedir(procdir);
if (!pid)
bb_simple_error_msg_and_die("nothing in /proc - not mounted?");
bb_error_msg_and_die("nothing in /proc - not mounted?");
}
static int do_stop(void)
@@ -337,7 +337,7 @@ static int do_stop(void)
} else if (userspec) {
what = xasprintf("process(es) owned by '%s'", userspec);
} else {
bb_simple_error_msg_and_die("internal error, please report");
bb_error_msg_and_die("internal error, please report");
}
if (!G.found_procs) {
@@ -409,7 +409,7 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
{
unsigned opt;
char *signame;
char *startas = NULL;
char *startas;
char *chuid;
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
// char *retry_arg = NULL;
@@ -425,11 +425,10 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
/* -K or -S is required; they are mutually exclusive */
/* -p is required if -m is given */
/* -xpun (at least one) is required if -K is given */
// /* -xa (at least one) is required if -S is given */
//WRONG: "start-stop-daemon -S -- sleep 5" is a valid invocation
/* -xa (at least one) is required if -S is given */
/* -q turns off -v */
"\0"
"K:S:K--S:S--K:m?p:K?xpun"
"K:S:K--S:S--K:m?p:K?xpun:S?xa"
IF_FEATURE_START_STOP_DAEMON_FANCY("q-v"),
LONGOPTS
&startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile
@@ -443,43 +442,27 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
if (signal_nr < 0) bb_show_usage();
}
//argc -= optind;
argv += optind;
// ARGS contains zeroth arg if -x/-a is not given, else it starts with 1st arg.
// These will try to execute "[/bin/]sleep 5":
// "start-stop-daemon -S -- sleep 5"
// "start-stop-daemon -S -x /bin/sleep -- 5"
// "start-stop-daemon -S -a sleep -- 5"
// NB: -n option does _not_ behave in this way: this will try to execute "5":
// "start-stop-daemon -S -n sleep -- 5"
if (opt & CTX_START) {
if (!execname) { /* -x is not given */
execname = startas;
if (!execname) { /* neither -x nor -a is given */
execname = argv[0];
if (!execname)
bb_show_usage();
argv++;
}
}
if (!startas) /* -a is not given: use -x EXECUTABLE or argv[0] */
startas = execname;
*--argv = startas;
}
if (!(opt & OPT_a))
startas = execname;
if (!execname) /* in case -a is given and -x is not */
execname = startas;
if (execname) {
G.execname_sizeof = strlen(execname) + 1;
G.execname_cmpbuf = xmalloc(G.execname_sizeof + 1);
}
// IF_FEATURE_START_STOP_DAEMON_FANCY(
// if (retry_arg)
// retries = xatoi_positive(retry_arg);
// )
//argc -= optind;
argv += optind;
if (userspec) {
user_id = bb_strtou(userspec, NULL, 10);
if (errno)
user_id = xuname2uid(userspec);
}
/* Both start and stop need to know current processes */
do_procinit();
@@ -488,11 +471,9 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
return (opt & OPT_OKNODO) ? 0 : (i <= 0);
}
/* else: CTX_START (-S). execname can't be NULL. */
if (G.found_procs) {
if (!QUIET)
printf("%s is already running\n", execname);
printf("%s is already running\n%u\n", execname, (unsigned)G.found_procs->pid);
return !(opt & OPT_OKNODO);
}
@@ -501,51 +482,35 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
xstat(execname, &G.execstat);
#endif
*--argv = startas;
if (opt & OPT_BACKGROUND) {
#if BB_MMU
bb_daemonize(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS + DAEMON_DOUBLE_FORK);
/* DAEMON_DEVNULL_STDIO is superfluous -
* it's always done by bb_daemonize() */
#else
/* Daemons usually call bb_daemonize_or_rexec(), but SSD can do
* without: SSD is not itself a daemon, it _execs_ a daemon.
* The usual NOMMU problem of "child can't run indefinitely,
* it must exec" does not bite us: we exec anyway.
*
* bb_daemonize(DAEMON_DEVNULL_STDIO | DAEMON_CLOSE_EXTRA_FDS | DAEMON_DOUBLE_FORK)
* can be used on MMU systems, but use of vfork()
* is preferable since we want to create pidfile
* _before_ parent returns, and vfork() on Linux
* ensures that (by blocking parent until exec in the child).
*/
pid_t pid = xvfork();
if (pid != 0) {
/* Parent */
/* parent */
/* why _exit? the child may have changed the stack,
* so "return 0" may do bad things
*/
* so "return 0" may do bad things */
_exit(EXIT_SUCCESS);
}
/* Child */
setsid(); /* detach from controlling tty */
/* Redirect stdio to /dev/null, close extra FDs */
bb_daemon_helper(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS);
/* On Linux, session leader can acquire ctty
* unknowingly, by opening a tty.
* Prevent this: stop being a session leader.
*/
pid = xvfork();
if (pid != 0)
_exit(EXIT_SUCCESS); /* Parent */
#endif
}
if (opt & OPT_MAKEPID) {
/* User wants _us_ to make the pidfile */
write_pidfile(pidfile);
}
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
if (opt & OPT_NICELEVEL) {
/* Set process priority (must be before OPT_c) */
int prio = getpriority(PRIO_PROCESS, 0) + xatoi_range(opt_N, INT_MIN/2, INT_MAX/2);
if (setpriority(PRIO_PROCESS, 0, prio) < 0) {
bb_perror_msg_and_die("setpriority(%d)", prio);
}
}
#endif
if (opt & OPT_c) {
struct bb_uidgid_t ugid;
parse_chown_usergroup_or_die(&ugid, chuid);
@@ -560,10 +525,15 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv)
setgroups(1, &ugid.gid);
}
}
/* Try:
* strace -oLOG start-stop-daemon -S -x /bin/usleep -a qwerty 500000
* should exec "/bin/usleep", but argv[0] should be "qwerty":
*/
execvp(execname, argv);
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
if (opt & OPT_NICELEVEL) {
/* Set process priority */
int prio = getpriority(PRIO_PROCESS, 0) + xatoi_range(opt_N, INT_MIN/2, INT_MAX/2);
if (setpriority(PRIO_PROCESS, 0, prio) < 0) {
bb_perror_msg_and_die("setpriority(%d)", prio);
}
}
#endif
execvp(startas, argv);
bb_perror_msg_and_die("can't execute '%s'", startas);
}
-1
View File
@@ -183,7 +183,6 @@ dd compatibility options:
iflag=skip_bytes| yes | |
iflag=fullblock | yes | |
oflag=seek_bytes| yes | |
oflag=append | yes | |
df POSIX options
option | exists | compliant | remarks
+3 -3
View File
@@ -196,11 +196,11 @@ int chattr_main(int argc UNUSED_PARAM, char **argv)
/* run sanity checks on all the arguments given us */
if ((g.flags & OPT_SET) && (g.flags & (OPT_ADD|OPT_REM)))
bb_simple_error_msg_and_die("= is incompatible with - and +");
bb_error_msg_and_die("= is incompatible with - and +");
if (g.rf & g.af)
bb_simple_error_msg_and_die("can't set and unset a flag");
bb_error_msg_and_die("can't set and unset a flag");
if (!g.flags)
bb_simple_error_msg_and_die("must use '-v', =, - or +");
bb_error_msg_and_die("must use '-v', =, - or +");
/* now run chattr on all the files passed to us */
do change_attributes(*argv, &g); while (*++argv);
+3 -3
View File
@@ -431,10 +431,10 @@ static int wait_one(int flags)
if (errno == EINTR)
continue;
if (errno == ECHILD) { /* paranoia */
bb_simple_error_msg("wait: no more children");
bb_error_msg("wait: no more children");
return -1;
}
bb_simple_perror_msg("wait");
bb_perror_msg("wait");
continue;
}
prev = NULL;
@@ -919,7 +919,7 @@ static void compile_fs_type(char *fs_type)
if (G.fs_type_negated == -1)
G.fs_type_negated = negate;
if (G.fs_type_negated != negate)
bb_simple_error_msg_and_die(
bb_error_msg_and_die(
"either all or none of the filesystem types passed to -t must be prefixed "
"with 'no' or '!'");
}
+17 -54
View File
@@ -272,25 +272,21 @@ typedef struct tsplitter_s {
/* if previous token class is CONCAT1 and next is CONCAT2, concatenation */
/* operator is inserted between them */
#define TC_CONCAT1 (TC_VARIABLE | TC_ARRTERM | TC_SEQTERM \
| TC_STRING | TC_NUMBER | TC_UOPPOST \
| TC_LENGTH)
| TC_STRING | TC_NUMBER | TC_UOPPOST)
#define TC_CONCAT2 (TC_OPERAND | TC_UOPPRE)
#define OF_RES1 0x010000
#define OF_RES2 0x020000
#define OF_STR1 0x040000
#define OF_STR2 0x080000
#define OF_NUM1 0x100000
#define OF_CHECKED 0x200000
#define OF_REQUIRED 0x400000
#define OF_RES1 0x010000
#define OF_RES2 0x020000
#define OF_STR1 0x040000
#define OF_STR2 0x080000
#define OF_NUM1 0x100000
#define OF_CHECKED 0x200000
/* combined operator flags */
#define xx 0
#define xV OF_RES2
#define xS (OF_RES2 | OF_STR2)
#define Vx OF_RES1
#define Rx (OF_RES1 | OF_NUM1 | OF_REQUIRED)
#define VV (OF_RES1 | OF_RES2)
#define Nx (OF_RES1 | OF_NUM1)
#define NV (OF_RES1 | OF_NUM1 | OF_RES2)
@@ -429,7 +425,7 @@ static const uint32_t tokeninfo[] = {
0,
0, /* \n */
ST_IF, ST_DO, ST_FOR, OC_BREAK,
OC_CONTINUE, OC_DELETE|Rx, OC_PRINT,
OC_CONTINUE, OC_DELETE|Vx, OC_PRINT,
OC_PRINTF, OC_NEXT, OC_NEXTFILE,
OC_RETURN|Vx, OC_EXIT|Nx,
ST_WHILE,
@@ -597,7 +593,7 @@ static const char EMSG_UNEXP_EOS[] ALIGN1 = "Unexpected end of string";
static const char EMSG_UNEXP_TOKEN[] ALIGN1 = "Unexpected token";
static const char EMSG_DIV_BY_ZERO[] ALIGN1 = "Division by zero";
static const char EMSG_INV_FMT[] ALIGN1 = "Invalid format specifier";
static const char EMSG_TOO_FEW_ARGS[] ALIGN1 = "Too few arguments";
static const char EMSG_TOO_FEW_ARGS[] ALIGN1 = "Too few arguments for builtin";
static const char EMSG_NOT_ARRAY[] ALIGN1 = "Not an array";
static const char EMSG_POSSIBLE_ERROR[] ALIGN1 = "Possible syntax error";
static const char EMSG_UNDEF_FUNC[] ALIGN1 = "Call to undefined function";
@@ -1071,10 +1067,8 @@ static uint32_t next_token(uint32_t expected)
const uint32_t *ti;
if (t_rollback) {
debug_printf_parse("%s: using rolled-back token\n", __func__);
t_rollback = FALSE;
} else if (concat_inserted) {
debug_printf_parse("%s: using concat-inserted token\n", __func__);
concat_inserted = FALSE;
t_tclass = save_tclass;
t_info = save_info;
@@ -1203,11 +1197,7 @@ static uint32_t next_token(uint32_t expected)
goto readnext;
/* insert concatenation operator when needed */
debug_printf_parse("%s: %x %x %x concat_inserted?\n", __func__,
(ltclass & TC_CONCAT1), (tc & TC_CONCAT2), (expected & TC_BINOP));
if ((ltclass & TC_CONCAT1) && (tc & TC_CONCAT2) && (expected & TC_BINOP)
&& !(ltclass == TC_LENGTH && tc == TC_SEQSTART) /* but not for "length(..." */
) {
if ((ltclass & TC_CONCAT1) && (tc & TC_CONCAT2) && (expected & TC_BINOP)) {
concat_inserted = TRUE;
save_tclass = tc;
save_info = t_info;
@@ -1215,7 +1205,6 @@ static uint32_t next_token(uint32_t expected)
t_info = OC_CONCAT | SS | P(35);
}
debug_printf_parse("%s: t_tclass=tc=%x\n", __func__, t_tclass);
t_tclass = tc;
}
ltclass = t_tclass;
@@ -1226,7 +1215,6 @@ static uint32_t next_token(uint32_t expected)
EMSG_UNEXP_EOS : EMSG_UNEXP_TOKEN);
}
debug_printf_parse("%s: returning, ltclass:%x t_double:%f\n", __func__, ltclass, t_double);
return ltclass;
#undef concat_inserted
#undef save_tclass
@@ -1277,7 +1265,7 @@ static node *parse_expr(uint32_t iexp)
debug_printf_parse("%s(%x)\n", __func__, iexp);
sn.info = PRIMASK;
sn.r.n = sn.a.n = glptr = NULL;
sn.r.n = glptr = NULL;
xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP | iexp;
while (!((tc = next_token(xtc)) & iexp)) {
@@ -1291,7 +1279,7 @@ static node *parse_expr(uint32_t iexp)
glptr = NULL;
} else if (tc & (TC_BINOP | TC_UOPPOST)) {
debug_printf_parse("%s: TC_BINOP | TC_UOPPOST tc:%x\n", __func__, tc);
debug_printf_parse("%s: TC_BINOP | TC_UOPPOST\n", __func__);
/* for binary and postfix-unary operators, jump back over
* previous operators with higher priority */
vn = cn;
@@ -1299,7 +1287,6 @@ static node *parse_expr(uint32_t iexp)
|| ((t_info == vn->info) && ((t_info & OPCLSMASK) == OC_COLON))
) {
vn = vn->a.n;
if (!vn->a.n) syntax_error(EMSG_UNEXP_TOKEN);
}
if ((t_info & OPCLSMASK) == OC_TERNARY)
t_info += P(6);
@@ -1359,10 +1346,8 @@ static node *parse_expr(uint32_t iexp)
v = cn->l.v = xzalloc(sizeof(var));
if (tc & TC_NUMBER)
setvar_i(v, t_double);
else {
else
setvar_s(v, t_string);
xtc &= ~TC_UOPPOST; /* "str"++ is not allowed */
}
break;
case TC_REGEXP:
@@ -1398,12 +1383,7 @@ static node *parse_expr(uint32_t iexp)
case TC_LENGTH:
debug_printf_parse("%s: TC_LENGTH\n", __func__);
next_token(TC_SEQSTART /* length(...) */
| TC_OPTERM /* length; (or newline)*/
| TC_GRPTERM /* length } */
| TC_BINOPX /* length <op> NUM */
| TC_COMMA /* print length, 1 */
);
next_token(TC_SEQSTART | TC_OPTERM | TC_GRPTERM);
rollback_token();
if (t_tclass & TC_SEQSTART) {
/* It was a "(" token. Handle just like TC_BUILTIN */
@@ -1445,11 +1425,7 @@ static void chain_expr(uint32_t info)
node *n;
n = chain_node(info);
n->l.n = parse_expr(TC_OPTERM | TC_GRPTERM);
if ((info & OF_REQUIRED) && !n->l.n)
syntax_error(EMSG_TOO_FEW_ARGS);
if (t_tclass & TC_GRPTERM)
rollback_token();
}
@@ -1629,25 +1605,12 @@ static void parse_program(char *p)
f = newfunc(t_string);
f->body.first = NULL;
f->nargs = 0;
/* Match func arg list: a comma sep list of >= 0 args, and a close paren */
while (next_token(TC_VARIABLE | TC_SEQTERM | TC_COMMA)) {
/* Either an empty arg list, or trailing comma from prev iter
* must be followed by an arg */
if (f->nargs == 0 && t_tclass == TC_SEQTERM)
break;
/* TC_SEQSTART/TC_COMMA must be followed by TC_VARIABLE */
if (t_tclass != TC_VARIABLE)
syntax_error(EMSG_UNEXP_TOKEN);
while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) {
v = findvar(ahash, t_string);
v->x.aidx = f->nargs++;
/* Arg followed either by end of arg list or 1 comma */
if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM)
break;
if (t_tclass != TC_COMMA)
syntax_error(EMSG_UNEXP_TOKEN);
}
seq = &f->body;
chain_group();
@@ -2649,7 +2612,7 @@ static var *evaluate(node *op, var *res)
if (opn == '|') {
rsm->F = popen(R.s, "w");
if (rsm->F == NULL)
bb_simple_perror_msg_and_die("popen");
bb_perror_msg_and_die("popen");
rsm->is_pipe = 1;
} else {
rsm->F = xfopen(R.s, opn=='w' ? "w" : "a");
@@ -3262,7 +3225,7 @@ int awk_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
//argc -= optind;
if (opt & OPT_W)
bb_simple_error_msg("warning: option -W is ignored");
bb_error_msg("warning: option -W is ignored");
if (opt & OPT_F) {
unescape_string_in_place(opt_F);
setvar_s(intvar[FS], opt_F);
+2 -2
View File
@@ -1006,7 +1006,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
xfunc_error_retval = 1;
if (gotstdin && (S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode)))
bb_simple_error_msg_and_die("can't compare stdin to a directory");
bb_error_msg_and_die("can't compare stdin to a directory");
/* Compare metadata to check if the files are the same physical file.
*
@@ -1037,7 +1037,7 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_DIFF_DIR
diffdir(file, s_start);
#else
bb_simple_error_msg_and_die("no support for directory comparison");
bb_error_msg_and_die("no support for directory comparison");
#endif
} else {
bool dirfile = S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode);
+17 -17
View File
@@ -165,7 +165,7 @@ static NOINLINE int searchLines(const char *str, int num1, int num2)
if (*str == '\0') {
if (searchString[0] == '\0') {
bb_simple_error_msg("no previous search string");
bb_error_msg("no previous search string");
return 0;
}
str = searchString;
@@ -228,7 +228,7 @@ static const char* getNum(const char *cp, smallint *retHaveNum, int *retNum)
case '\'':
cp++;
if ((unsigned)(*cp - 'a') >= 26) {
bb_simple_error_msg("bad mark name");
bb_error_msg("bad mark name");
return NULL;
}
haveNum = TRUE;
@@ -314,7 +314,7 @@ static int insertLine(int num, const char *data, int len)
LINE *newLp, *lp;
if ((num < 1) || (num > lastNum + 1)) {
bb_simple_error_msg("inserting at bad line number");
bb_error_msg("inserting at bad line number");
return FALSE;
}
@@ -384,7 +384,7 @@ static int readLines(const char *file, int num)
char *cp;
if ((num < 1) || (num > lastNum + 1)) {
bb_simple_error_msg("bad line for read");
bb_error_msg("bad line for read");
return FALSE;
}
@@ -629,7 +629,7 @@ static void subCommand(const char *cmd, int num1, int num2)
cp = buf;
if (isblank(*cp) || (*cp == '\0')) {
bb_simple_error_msg("bad delimiter for substitute");
bb_error_msg("bad delimiter for substitute");
return;
}
@@ -638,7 +638,7 @@ static void subCommand(const char *cmd, int num1, int num2)
cp = strchr(cp, delim);
if (cp == NULL) {
bb_simple_error_msg("missing 2nd delimiter for substitute");
bb_error_msg("missing 2nd delimiter for substitute");
return;
}
@@ -660,13 +660,13 @@ static void subCommand(const char *cmd, int num1, int num2)
printFlag = TRUE;
break;
default:
bb_simple_error_msg("unknown option for substitute");
bb_error_msg("unknown option for substitute");
return;
}
if (*oldStr == '\0') {
if (searchString[0] == '\0') {
bb_simple_error_msg("no previous search string");
bb_error_msg("no previous search string");
return;
}
oldStr = searchString;
@@ -846,7 +846,7 @@ static void doCommands(void)
case 'f':
if (*cp != '\0' && *cp != ' ') {
bb_simple_error_msg("bad file command");
bb_error_msg("bad file command");
break;
}
cp = skip_whitespace(cp);
@@ -870,7 +870,7 @@ static void doCommands(void)
case 'k':
cp = skip_whitespace(cp);
if ((unsigned)(*cp - 'a') >= 26 || cp[1]) {
bb_simple_error_msg("bad mark name");
bb_error_msg("bad mark name");
break;
}
marks[(unsigned)(*cp - 'a')] = num2;
@@ -887,7 +887,7 @@ static void doCommands(void)
case 'q':
cp = skip_whitespace(cp);
if (have1 || *cp) {
bb_simple_error_msg("bad quit command");
bb_error_msg("bad quit command");
break;
}
if (!dirty)
@@ -903,12 +903,12 @@ static void doCommands(void)
case 'r':
if (*cp != '\0' && *cp != ' ') {
bb_simple_error_msg("bad read command");
bb_error_msg("bad read command");
break;
}
cp = skip_whitespace(cp);
if (*cp == '\0') {
bb_simple_error_msg("no file name");
bb_error_msg("no file name");
break;
}
if (!have1)
@@ -925,14 +925,14 @@ static void doCommands(void)
case 'w':
if (*cp != '\0' && *cp != ' ') {
bb_simple_error_msg("bad write command");
bb_error_msg("bad write command");
break;
}
cp = skip_whitespace(cp);
if (*cp == '\0') {
cp = fileName;
if (!cp) {
bb_simple_error_msg("no file name specified");
bb_error_msg("no file name specified");
break;
}
}
@@ -960,7 +960,7 @@ static void doCommands(void)
case '.':
if (have1) {
bb_simple_error_msg("no arguments allowed");
bb_error_msg("no arguments allowed");
break;
}
printLines(curNum, curNum, FALSE);
@@ -984,7 +984,7 @@ static void doCommands(void)
break;
default:
bb_simple_error_msg("unimplemented command");
bb_error_msg("unimplemented command");
break;
}
}
+1 -2
View File
@@ -264,7 +264,7 @@ static int apply_one_hunk(void)
if (!plist && matcheof) break;
if (backwarn)
fdprintf(2, "Possibly reversed hunk %d at %ld\n",
fdprintf(2,"Possibly reversed hunk %d at %ld\n",
TT.hunknum, TT.linenum);
// File ended before we found a place for this hunk.
@@ -593,7 +593,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
TT.linenum = 0;
TT.hunknum = 0;
}
fflush_all(); // make "patching file F" visible
}
TT.hunknum++;
+3 -3
View File
@@ -30,7 +30,7 @@ static unsigned copy_lines(FILE *src_stream, FILE *dst_stream, unsigned lines_co
break;
}
if (fputs(line, dst_stream) == EOF) {
bb_simple_perror_msg_and_die("error writing to new file");
bb_perror_msg_and_die("error writing to new file");
}
free(line);
lines_count--;
@@ -148,7 +148,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
new_filename = extract_filename(patch_line, patch_level, "+++ ");
if (!new_filename) {
bb_simple_error_msg_and_die("invalid patch");
bb_error_msg_and_die("invalid patch");
}
/* Get access rights from the file to be patched */
@@ -209,7 +209,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
/* src_beg_line will be 0 if it's a new file */
count = src_beg_line - src_cur_line;
if (copy_lines(src_stream, dst_stream, count)) {
bb_simple_error_msg_and_die("bad src file");
bb_error_msg_and_die("bad src file");
}
src_cur_line += count;
dst_cur_line += count;
+1 -1
View File
@@ -200,7 +200,7 @@ int copy_tempfile(int fdin, char *name, char **tempname)
*tempname = xasprintf("%sXXXXXX", name);
fd = mkstemp(*tempname);
if(-1 == fd) bb_simple_perror_msg_and_die("no temp file");
if(-1 == fd) bb_perror_msg_and_die("no temp file");
// Set permissions of output file
fstat(fdin, &statbuf);
+23 -25
View File
@@ -315,7 +315,7 @@ static int parse_regex_delim(const char *cmdstr, char **match, char **replace)
/* verify that the 's' or 'y' is followed by something. That something
* (typically a 'slash') is now our regexp delimiter... */
if (*cmdstr == '\0')
bb_simple_error_msg_and_die("bad format in substitution expression");
bb_error_msg_and_die("bad format in substitution expression");
delimiter = *cmdstr_ptr++;
/* save the match string */
@@ -360,7 +360,7 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
} else {
*regex = G.previous_regex_ptr;
if (!G.previous_regex_ptr)
bb_simple_error_msg_and_die("no previous regexp");
bb_error_msg_and_die("no previous regexp");
}
/* Move position to next character after last delimiter */
pos += (next+1);
@@ -371,25 +371,25 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
/* Grab a filename. Whitespace at start is skipped, then goes to EOL. */
static int parse_file_cmd(/*sed_cmd_t *sed_cmd,*/ const char *filecmdstr, char **retval)
{
const char *start;
const char *eol;
int start = 0, idx, hack = 0;
/* Skip whitespace, then grab filename to end of line */
start = skip_whitespace(filecmdstr);
eol = strchrnul(start, '\n');
if (eol == start)
bb_simple_error_msg_and_die("empty filename");
while (isspace(filecmdstr[start]))
start++;
idx = start;
while (filecmdstr[idx] && filecmdstr[idx] != '\n')
idx++;
if (*eol) {
/* If lines glued together, put backslash back. */
*retval = xstrndup(start, eol-start + 1);
(*retval)[eol-start] = '\\';
} else {
/* eol is NUL */
*retval = xstrdup(start);
}
/* If lines glued together, put backslash back. */
if (filecmdstr[idx] == '\n')
hack = 1;
if (idx == start)
bb_error_msg_and_die("empty filename");
*retval = xstrndup(filecmdstr+start, idx-start+hack+1);
if (hack)
(*retval)[idx-start] = '\\';
return eol - filecmdstr;
return idx;
}
static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
@@ -468,7 +468,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
goto out;
default:
dbg("s bad flags:'%s'", substr + idx);
bb_simple_error_msg_and_die("bad option in substitution expression");
bb_error_msg_and_die("bad option in substitution expression");
}
}
out:
@@ -688,7 +688,7 @@ static void add_cmd(const char *cmdstr)
idx--; /* if 0, trigger error check below */
}
if (idx < 0)
bb_simple_error_msg_and_die("no address after comma");
bb_error_msg_and_die("no address after comma");
sed_cmd->end_line_orig = sed_cmd->end_line;
}
@@ -706,7 +706,7 @@ static void add_cmd(const char *cmdstr)
/* last part (mandatory) will be a command */
if (!*cmdstr)
bb_simple_error_msg_and_die("missing command");
bb_error_msg_and_die("missing command");
sed_cmd->cmd = *cmdstr++;
cmdstr = parse_cmd_args(sed_cmd, cmdstr);
@@ -791,7 +791,7 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
if (!current_regex) {
current_regex = G.previous_regex_ptr;
if (!current_regex)
bb_simple_error_msg_and_die("no previous regexp");
bb_error_msg_and_die("no previous regexp");
}
G.previous_regex_ptr = current_regex;
@@ -962,7 +962,7 @@ static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char l
if (ferror(file)) {
xfunc_error_retval = 4; /* It's what gnu sed exits with... */
bb_simple_error_msg_and_die(bb_msg_write_error);
bb_error_msg_and_die(bb_msg_write_error);
}
*last_puts_char = lpc;
}
@@ -1097,8 +1097,6 @@ static void process_files(void)
int old_matched, matched;
old_matched = sed_cmd->in_match;
if (!old_matched)
sed_cmd->end_line = sed_cmd->end_line_orig;
/* Determine if this command matches this line: */
@@ -1192,7 +1190,7 @@ static void process_files(void)
}
sed_cmd = sed_cmd->next;
if (!sed_cmd)
bb_simple_error_msg_and_die("unterminated {");
bb_error_msg_and_die("unterminated {");
}
}
continue;
+2241 -2117
View File
File diff suppressed because it is too large. Load diff
+17 -30
View File
@@ -19,43 +19,30 @@
#
# <runlevels>: The runlevels field is completely ignored.
#
# <action>: Valid actions include: sysinit, wait, once, respawn, askfirst,
# shutdown, restart and ctrlaltdel.
# <action>: Valid actions include: sysinit, respawn, askfirst, wait, once,
# restart, ctrlaltdel, and shutdown.
#
# sysinit actions are started first, and init waits for them to complete.
# wait actions are started next, and init waits for them to complete.
# once actions are started next (and not waited for).
# Note: askfirst acts just like respawn, but before running the specified
# process it displays the line "Please press Enter to activate this
# console." and then waits for the user to press enter before starting
# the specified process.
#
# askfirst and respawn are started next.
# For askfirst, before running the specified process, init displays
# the line "Please press Enter to activate this console"
# and then waits for the user to press enter before starting it.
#
# shutdown actions are run on halt/reboot/poweroff, or on SIGQUIT.
# Then the machine is halted/rebooted/powered off, or for SIGQUIT,
# restart action is exec'ed (init process is replaced by that process).
# If no restart action specified, SIGQUIT has no effect.
#
# ctrlaltdel actions are run when SIGINT is received
# (this might be initiated by Ctrl-Alt-Del key combination).
# After they complete, normal processing of askfirst / respawn resumes.
#
# Note: unrecognized actions (like initdefault) will cause init to emit
# an error message, and then go along with its business.
# Note: unrecognized actions (like initdefault) will cause init to emit
# an error message, and then go along with its business.
#
# <process>: Specifies the process to be executed and it's command line.
#
# Note: BusyBox init works just fine without an inittab. If no inittab is
# found, it has the following default behavior:
# ::sysinit:/etc/init.d/rcS
# ::askfirst:/bin/sh
# ::ctrlaltdel:/sbin/reboot
# ::shutdown:/sbin/swapoff -a
# ::shutdown:/bin/umount -a -r
# ::restart:/sbin/init
# tty2::askfirst:/bin/sh
# tty3::askfirst:/bin/sh
# tty4::askfirst:/bin/sh
# ::sysinit:/etc/init.d/rcS
# ::askfirst:/bin/sh
# ::ctrlaltdel:/sbin/reboot
# ::shutdown:/sbin/swapoff -a
# ::shutdown:/bin/umount -a -r
# ::restart:/sbin/init
# tty2::askfirst:/bin/sh
# tty3::askfirst:/bin/sh
# tty4::askfirst:/bin/sh
#
# Boot-time system configuration/initialization script.
# This is run first except when booting in single-user mode.
+1 -1
View File
@@ -4,7 +4,7 @@
# Repeat.
umountcnt=2
writeout=0 # increase if your kernel does not guarantee writes to complete
writeout=0 # increase if your kernel doesn ot guarantee writes to complete
# No /usr - we are expecting all binaries to be accessible
# from root fs alone
+3 -8
View File
@@ -16,10 +16,9 @@ BROADCAST="broadcast +"
case "$1" in
deconfig)
echo "Clearing IP addresses on $interface, upping it"
echo "Setting IP address 0.0.0.0 on $interface"
if command -v ip >/dev/null; then
ip -4 addr flush dev $interface
ip link set dev $interface up
ip addr flush dev $interface
else
ifconfig $interface 0.0.0.0
fi
@@ -53,14 +52,10 @@ case "$1" in
done
fi
echo "Recreating $RESOLV_CONF"
# If the file is a symlink somewhere (like /etc/resolv.conf
# pointing to /run/resolv.conf), make sure things work.
if test -L "$RESOLV_CONF"; then
# If it's a dangling symlink, try to create the target.
test -e "$RESOLV_CONF" || touch "$RESOLV_CONF"
fi
realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
echo "Recreating $realconf"
tmpfile="$realconf-$$"
> "$tmpfile"
[ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
+38 -49
View File
@@ -44,7 +44,7 @@ interface eth0
#notify_file # default: no script
#notify_file dumpleases # useful for debugging
# The following are BOOTP specific options
# The following are bootp specific options
# next server to use in bootstrap
#siaddr 192.168.0.22 # default: 0.0.0.0 (none)
# tftp server name
@@ -52,14 +52,9 @@ interface eth0
# tftp file to download (e.g. kernel image)
#boot_file /var/nfs_root # default: none
# NOTE: "boot_file FILE" and "opt bootfile FILE" are conceptually the same,
# but "boot_file" goes into BOOTP-defined fixed-size field in the packet,
# whereas "opt bootfile" goes into DHCP option 0x43.
# Same for "sname HOST" and "opt tftp HOST".
# Static leases map
#static_lease 00:60:08:11:CE:4E 192.168.0.54
#static_lease 00:60:08:11:CE:3E 192.168.0.44 optional_hostname
#static_lease 00:60:08:11:CE:3E 192.168.0.44
# The remainder of options are DHCP options and can be specified with the
# keyword 'opt' or 'option'. If an option can take multiple items, such
@@ -79,49 +74,43 @@ option staticroutes 10.0.0.0/8 10.127.0.1, 10.11.12.0/24 10.11.12.1
option 0x08 01020304 # option 8: "cookie server IP addr: 1.2.3.4"
option 14 "dumpfile"
# Currently supported options [hex option value] (for more info, see options.c):
#opt lease NUM # [0x33]
#opt subnet IP # [0x01]
#opt broadcast IP # [0x1c]
#opt router IP_LIST # [0x03]
#opt ipttl NUM # [0x17]
#opt mtu NUM # [0x1a]
#opt hostname STRING # [0x0c] client's hostname
#opt domain STRING # [0x0f] client's domain suffix
#opt search STRING_LIST # [0x77] search domains
#opt nisdomain STRING # [0x28]
#opt timezone NUM # [0x02] (localtime - UTC_time) in seconds. signed
#opt tftp STRING # [0x42] tftp server name
#opt bootfile STRING # [0x43] tftp file to download (e.g. kernel image)
#opt bootsize NUM # [0x0d] size of that file
#opt rootpath STRING # [0x11] (NFS) path to mount as root fs
#opt wpad STRING # [0xfc] Web Proxy Auto Discovery Protocol
#opt serverid IP # [0x36] default: server's IP
#opt message STRING # [0x38] error message (udhcpd sends it on success too)
#opt vlanid NUM # [0x84] 802.1P VLAN ID
#opt vlanpriority NUM # [0x85] 802.1Q VLAN priority
# RFC 5071: PXELINUX Options
#opt 0xd0 F100747E # [0xd0] magic
#opt pxeconffile STRING # [0xd1]
#opt pxepathprefix STRING # [0xd2]
#opt reboottime NUM # [0xd3] bootstrap timeout
# Currently supported options (for more info, see options.c):
#opt lease NUM
#opt subnet IP
#opt broadcast IP
#opt router IP_LIST
#opt ipttl NUM
#opt mtu NUM
#opt hostname STRING # client's hostname
#opt domain STRING # client's domain suffix
#opt search STRING_LIST # search domains
#opt nisdomain STRING
#opt timezone NUM # (localtime - UTC_time) in seconds. signed
#opt tftp STRING # tftp server name
#opt bootfile STRING # tftp file to download (e.g. kernel image)
#opt bootsize NUM # size of that file
#opt rootpath STRING # (NFS) path to mount as root fs
#opt wpad STRING
#opt serverid IP # default: server's IP
#opt message STRING # error message (udhcpd sends it on success too)
#opt vlanid NUM # 802.1P VLAN ID
#opt vlanpriority NUM # 802.1Q VLAN priority
# Options specifying server(s)
#opt dns IP_LIST # [0x06]
#opt wins IP_LIST # [0x2c]
#opt nissrv IP_LIST # [0x29]
#opt ntpsrv IP_LIST # [0x2a]
#opt lprsrv IP_LIST # [0x09]
#opt swapsrv IP # [0x10]
#opt dns IP_LIST
#opt wins IP_LIST
#opt nissrv IP_LIST
#opt ntpsrv IP_LIST
#opt lprsrv IP_LIST
#opt swapsrv IP
# Options specifying routes
#opt routes IP_PAIR_LIST # [0x21]
#opt staticroutes STATIC_ROUTES # [0x79] RFC 3442 classless static route option
#opt msstaticroutes STATIC_ROUTES # [0xf9] same, using MS option number
#opt routes IP_PAIR_LIST
#opt staticroutes STATIC_ROUTES # RFC 3442 classless static route option
#opt msstaticroutes STATIC_ROUTES # same, using MS option number
# Obsolete options, no longer supported
#opt logsrv IP_LIST # [0x07] 704/UDP log server (not syslog!)
#opt namesrv IP_LIST # [0x05] IEN 116 name server, obsolete (August 1979!!!)
#opt cookiesrv IP_LIST # [0x08] RFC 865 "quote of the day" server, rarely (never?) used
#opt timesrv IP_LIST # [0x04] RFC 868 time server, rarely (never?) used
#opt logsrv IP_LIST # 704/UDP log server (not syslog!)
#opt namesrv IP_LIST # IEN 116 name server, obsolete (August 1979!!!)
#opt cookiesrv IP_LIST # RFC 865 "quote of the day" server, rarely (never?) used
#opt timesrv IP_LIST # RFC 868 time server, rarely (never?) used
# TODO: in development
#opt userclass STRING # [0x4d] RFC 3004. set of LASCII strings. "I am a printer" etc
#opt sipsrv STRING LIST # [0x78] RFC 3361. flag byte, then: 0: domain names, 1: IP addrs
#opt ip6rd .... # [0xd4] IPv6 rapid deployment
#opt userclass STRING # RFC 3004. set of LASCII strings. "I am a printer" etc
#opt sipserv STRING LIST # RFC 3361. flag byte, then: 0: domain names, 1: IP addrs
@@ -26,30 +26,6 @@ exec 2>&1
test "$interface" || exit 1
test "$ip" || exit 1
# some servers do not return subnet option.
# guess it for standard private networks.
if ! test "$mask"; then
case "$ip" in
10.*)
mask=8;;
192.168.*)
mask=16;;
#172.16-31.x.x
172.1[6789].*)
mask=12;;
172.2[0123456789].*)
mask=12;;
172.3[01].*)
mask=12;;
esac
fi
# some servers do not return router option.
# assume DHCP server is the router.
if ! test "$router"; then
test "$serverid" && router="$serverid"
fi
{
echo "let cfg=cfg+1"
test "$interface" && echo "if[\$cfg]='$interface'"
+2 -2
View File
@@ -8,9 +8,9 @@ pwd="$PWD"
if="${PWD##*/dhcp_}"
echo "* Upping iface $if"
ip link set dev "$if" up || exec sleep 5
ip link set dev "$if" up
echo "* Starting udhcpc on $if [$$]"
echo "* Starting udhcpc"
exec \
env - PATH="$PATH" \
softlimit \
+2 -2
View File
@@ -8,12 +8,12 @@ pwd="$PWD"
if="${PWD##*/dhcpd_}"
echo "* Upping iface $if"
ip link set dev $if up || exec sleep 5
ip link set dev $if up
>>udhcpd.leases
sed 's/^interface.*$/interface '"$if/" -i udhcpd.conf
echo "* Starting udhcpd on $if [$$]"
echo "* Starting udhcpd"
exec \
env - PATH="$PATH" \
softlimit \
+2 -3
View File
@@ -9,14 +9,14 @@ pwd="$PWD"
if="${PWD##*/ifplugd_}"
echo "* Upping iface $if"
ip link set dev "$if" up || exec sleep 5
ip link set dev "$if" up
echo "* Starting ifplugd on $if [$$]"
exec \
env - PATH="$PATH" \
softlimit \
setuidgid root \
ifplugd -aqlMns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler"
ifplugd -aqlns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler"
# We use -t3 to wake ifplugd up less often.
# If after three tests (3*3=9 > 8) link state seen to be different,
@@ -29,7 +29,6 @@ ifplugd -aqlMns -t3 -u8 -d8 -i "$if" -r "$pwd/ifplugd_handler"
# from pointlessly trying to get a lease.
# -q means that stopping monitoring does not stop dhcp/zcip/etc:
# presumably, admin decided to control them manually.
# -M prevents frequent respawning if device does not exist (yet?)
#-a Don't up interface automatically
#-p Don't run "up" script on startup
+2 -3
View File
@@ -8,13 +8,12 @@ pwd="$PWD"
if="${PWD##*/dhcp_}"
echo "* Upping iface $if"
# "or sleep" idiom prevents rapid respawning if iface does not exist
ip link set dev "$if" up || exec sleep 5
ip link set dev "$if" up
##echo "* Powersave disable on $if"
##iw dev "$if" set power_save off
echo "* Starting wpa_supplicant on $if [$$]"
echo "* Starting wpa_supplicant"
exec \
env - PATH="$PATH" \
softlimit \
+2 -2
View File
@@ -8,9 +8,9 @@ pwd="$PWD"
if="${PWD##*/zcip_}"
echo "* Upping iface $if"
ip link set dev "$if" up || exec sleep 5
ip link set dev "$if" up
echo "* Starting zcip on $if [$$]"
echo "* Starting zcip"
exec \
env - PATH="$PATH" \
softlimit \
+2 -52
View File
@@ -203,14 +203,6 @@
//config: WARNING: This option can do much harm if used wrong. Busybox will not
//config: try to protect the user from doing stupid things. Use with care.
//config:
//config:config FEATURE_FIND_EMPTY
//config: bool "Enable -empty: match empty files or directories"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -empty' option to find empty regular files
//config: or directories.
//config:
//config:config FEATURE_FIND_PATH
//config: bool "Enable -path: match pathname with shell pattern"
//config: default y
@@ -323,9 +315,6 @@
//usage: IF_FEATURE_FIND_CONTEXT(
//usage: "\n -context CTX File has specified security context"
//usage: )
//usage: IF_FEATURE_FIND_EMPTY(
//usage: "\n -empty Match empty file/directory"
//usage: )
//usage: IF_FEATURE_FIND_PRUNE(
//usage: "\n -prune If current file is directory, don't descend into it"
//usage: )
@@ -407,7 +396,6 @@ IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
IF_FEATURE_FIND_PRUNE( ACTS(prune))
IF_FEATURE_FIND_QUIT( ACTS(quit))
IF_FEATURE_FIND_DELETE( ACTS(delete))
IF_FEATURE_FIND_EMPTY( ACTS(empty))
IF_FEATURE_FIND_EXEC( ACTS(exec,
char **exec_argv; /* -exec ARGS */
unsigned *subst_count;
@@ -836,30 +824,6 @@ ACTF(delete)
return TRUE;
}
#endif
#if ENABLE_FEATURE_FIND_EMPTY
ACTF(empty)
{
if (S_ISDIR(statbuf->st_mode)) {
DIR *dir;
struct dirent *dent;
dir = opendir(fileName);
if (!dir) {
bb_simple_perror_msg(fileName);
return FALSE;
}
while ((dent = readdir(dir)) != NULL
&& DOT_OR_DOTDOT(dent->d_name)
) {
continue;
}
closedir(dir);
return dent == NULL;
}
return S_ISREG(statbuf->st_mode) && statbuf->st_size == 0;
}
#endif
#if ENABLE_FEATURE_FIND_CONTEXT
ACTF(context)
{
@@ -1025,7 +989,6 @@ static action*** parse_params(char **argv)
IF_FEATURE_FIND_PRUNE( PARM_prune ,)
IF_FEATURE_FIND_QUIT( PARM_quit ,)
IF_FEATURE_FIND_DELETE( PARM_delete ,)
IF_FEATURE_FIND_EMPTY( PARM_empty ,)
IF_FEATURE_FIND_EXEC( PARM_exec ,)
IF_FEATURE_FIND_EXECUTABLE(PARM_executable,)
IF_FEATURE_FIND_PAREN( PARM_char_brace,)
@@ -1071,7 +1034,6 @@ static action*** parse_params(char **argv)
IF_FEATURE_FIND_PRUNE( "-prune\0" )
IF_FEATURE_FIND_QUIT( "-quit\0" )
IF_FEATURE_FIND_DELETE( "-delete\0" )
IF_FEATURE_FIND_EMPTY( "-empty\0" )
IF_FEATURE_FIND_EXEC( "-exec\0" )
IF_FEATURE_FIND_EXECUTABLE("-executable\0")
IF_FEATURE_FIND_PAREN( "(\0" )
@@ -1241,12 +1203,6 @@ static action*** parse_params(char **argv)
(void) ALLOC_ACTION(delete);
}
#endif
#if ENABLE_FEATURE_FIND_EMPTY
else if (parm == PARM_empty) {
dbg("%d", __LINE__);
(void) ALLOC_ACTION(empty);
}
#endif
#if ENABLE_FEATURE_FIND_EXEC
else if (parm == PARM_exec) {
int i;
@@ -1289,7 +1245,7 @@ static action*** parse_params(char **argv)
* coreutils expects {} to appear only once in "-exec +"
*/
if (all_subst != 1 && ap->filelist)
bb_simple_error_msg_and_die("only one '{}' allowed for -exec +");
bb_error_msg_and_die("only one '{}' allowed for -exec +");
# endif
}
#endif
@@ -1303,7 +1259,7 @@ static action*** parse_params(char **argv)
endarg = argv;
while (1) {
if (!*++endarg)
bb_simple_error_msg_and_die("unpaired '('");
bb_error_msg_and_die("unpaired '('");
if (LONE_CHAR(*endarg, '('))
nested++;
else if (LONE_CHAR(*endarg, ')') && !--nested) {
@@ -1511,12 +1467,6 @@ int find_main(int argc UNUSED_PARAM, char **argv)
break;
if (!saved[1])
break; /* it is "-" */
if (saved[1] == '-' && !saved[2]) {
/* it is "--" */
/* Try: find -- /dev/null */
saved = *++past_HLP;
break;
}
if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
break;
}
+16 -37
View File
@@ -60,7 +60,7 @@
/* options */
//usage:#define grep_trivial_usage
//usage: "[-HhnlLoqvsrRiwFE"
//usage: "[-HhnlLoqvsriwFE"
//usage: IF_EXTRA_COMPAT("z")
//usage: "] [-m N] "
//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ")
@@ -78,7 +78,6 @@
//usage: "\n -v Select non-matching lines"
//usage: "\n -s Suppress open and read errors"
//usage: "\n -r Recurse"
//usage: "\n -R Recurse and dereference symlinks"
//usage: "\n -i Ignore case"
//usage: "\n -w Match whole words only"
//usage: "\n -x Match whole lines only"
@@ -109,7 +108,7 @@
/* -e,-f are lists; -m,-A,-B,-C have numeric param */
#define OPTSTR_GREP \
"lnqvscFiHhe:*f:*LorRm:+wx" \
"lnqvscFiHhe:*f:*Lorm:+wx" \
IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
"E" \
IF_EXTRA_COMPAT("z") \
@@ -132,7 +131,6 @@ enum {
OPTBIT_L, /* list unmatched file names only */
OPTBIT_o, /* show only matching parts of lines */
OPTBIT_r, /* recurse dirs */
OPTBIT_R, /* recurse dirs and symlinks to dirs */
OPTBIT_m, /* -m MAX_MATCHES */
OPTBIT_w, /* -w whole word match */
OPTBIT_x, /* -x whole line match */
@@ -156,7 +154,6 @@ enum {
OPT_L = 1 << OPTBIT_L,
OPT_o = 1 << OPTBIT_o,
OPT_r = 1 << OPTBIT_r,
OPT_R = 1 << OPTBIT_R,
OPT_m = 1 << OPTBIT_m,
OPT_w = 1 << OPTBIT_w,
OPT_x = 1 << OPTBIT_x,
@@ -446,23 +443,15 @@ static int grep_file(FILE *file)
}
}
}
/* If it's a non-inverted search, we can stop
* at first match and report it.
* If it's an inverted search, we can move on
* to the next line of input, ignoring the
* rest of the patterns.
*/
if (found) {
//if (invert_search)
// goto do_not_found;
//goto do_found;
break; // this accomplishes both
}
/* If it's non-inverted search, we can stop
* at first match */
if (found && !invert_search)
goto do_found;
pattern_ptr = pattern_ptr->link;
} /* while (pattern_ptr) */
if (found ^ invert_search) {
//do_found:
do_found:
/* keep track of matches */
nmatches++;
@@ -563,7 +552,6 @@ static int grep_file(FILE *file)
}
#if ENABLE_FEATURE_GREP_CONTEXT
else { /* no match */
//do_not_found:
/* if we need to print some context lines after the last match, do so */
if (print_n_lines_after) {
print_line(line, strlen(line), linenum, '-');
@@ -650,13 +638,6 @@ static void load_regexes_from_file(llist_t *fopt)
}
}
static void load_pattern_list(llist_t **lst, char *pattern)
{
char *p;
while ((p = strsep(&pattern, "\n")) != NULL)
llist_add_to(lst, new_grep_list_data(p, 0));
}
static int FAST_FUNC file_action_grep(const char *filename,
struct stat *statbuf,
void* matched,
@@ -697,7 +678,6 @@ static int grep_dir(const char *dir)
int matched = 0;
recursive_action(dir,
/* recurse=yes */ ACTION_RECURSE |
/* followLinks=always */ ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0) |
/* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
/* depthFirst=yes */ ACTION_DEPTHFIRST,
/* fileAction= */ file_action_grep,
@@ -761,19 +741,16 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
#endif
invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
{ /* convert char **argv to pattern_list */
llist_t *cur, *new = NULL;
{ /* convert char **argv to grep_list_data_t */
llist_t *cur;
for (cur = pattern_head; cur; cur = cur->link)
load_pattern_list(&new, cur->data);
llist_free(pattern_head, NULL);
pattern_head = new;
cur->data = new_grep_list_data(cur->data, 0);
}
if (option_mask32 & OPT_f) {
load_regexes_from_file(fopt);
if (!pattern_head) { /* -f EMPTY_FILE? */
/* GNU grep treats it as "nothing matches" except when -x */
const char *data = (option_mask32 & OPT_x) ? ".*" : "";
llist_add_to(&pattern_head, new_grep_list_data((char*)data, 0));
/* GNU grep treats it as "nothing matches" */
llist_add_to(&pattern_head, new_grep_list_data((char*) "", 0));
invert_search ^= 1;
}
}
@@ -815,9 +792,11 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
/* if we didn't get a pattern from -e and no command file was specified,
* first parameter should be the pattern. no pattern, no worky */
if (pattern_head == NULL) {
char *pattern;
if (*argv == NULL)
bb_show_usage();
load_pattern_list(&pattern_head, *argv++);
pattern = new_grep_list_data(*argv++, 0);
llist_add_to(&pattern_head, pattern);
}
/* argv[0..(argc-1)] should be names of file to grep through. If
@@ -839,7 +818,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
if (!cur_file || LONE_DASH(cur_file)) {
cur_file = "(standard input)";
} else {
if (option_mask32 & (OPT_r|OPT_R)) {
if (option_mask32 & OPT_r) {
struct stat st;
if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) {
if (!(option_mask32 & OPT_h))
+19 -28
View File
@@ -114,28 +114,17 @@ struct globals {
int max_procs;
#endif
smalluint xargs_exitcode;
#if ENABLE_FEATURE_XARGS_SUPPORT_QUOTES
#define NORM 0
#define QUOTE 1
#define BACKSLASH 2
#define SPACE 4
smalluint process_stdin__state;
char process_stdin__q;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
setup_common_bufsiz(); \
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \
/* Even zero values are set because we are NOEXEC applet */ \
G.eof_str = NULL; \
G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \
G.idx = 0; \
IF_FEATURE_XARGS_SUPPORT_PARALLEL(G.running_procs = 0;) \
IF_FEATURE_XARGS_SUPPORT_PARALLEL(G.max_procs = 1;) \
G.xargs_exitcode = 0; \
IF_FEATURE_XARGS_SUPPORT_QUOTES(G.process_stdin__state = NORM;) \
IF_FEATURE_XARGS_SUPPORT_QUOTES(G.process_stdin__q = '\0';) \
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \
} while (0)
@@ -268,8 +257,12 @@ static void store_param(char *s)
#if ENABLE_FEATURE_XARGS_SUPPORT_QUOTES
static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
{
#define q G.process_stdin__q
#define state G.process_stdin__state
#define NORM 0
#define QUOTE 1
#define BACKSLASH 2
#define SPACE 4
char q = '\0'; /* quote char */
char state = NORM;
char *s = buf; /* start of the word */
char *p = s + strlen(buf); /* end of the word */
@@ -315,7 +308,6 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
}
}
if (state == SPACE) { /* word's delimiter or EOF detected */
state = NORM;
if (q) {
bb_error_msg_and_die("unmatched %s quote",
q == '\'' ? "single" : "double");
@@ -336,6 +328,7 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
if (n_max_arg == 0) {
goto ret;
}
state = NORM;
}
if (p == buf) {
goto ret;
@@ -346,8 +339,6 @@ static char* FAST_FUNC process_stdin(int n_max_chars, int n_max_arg, char *buf)
/* store_param(NULL) - caller will do it */
dbg_msg("return:'%s'", s);
return s;
#undef q
#undef state
}
#else
/* The variant does not support single quotes, double quotes or backslash */
@@ -525,23 +516,23 @@ static int xargs_ask_confirmation(void)
//usage: "[OPTIONS] [PROG ARGS]"
//usage:#define xargs_full_usage "\n\n"
//usage: "Run PROG on every item given by stdin\n"
//usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(
//usage: "\n -p Ask user whether to run each command"
//usage: )
//usage: "\n -r Don't run command if input is empty"
//usage: IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(
//usage: "\n -0 Input is separated by NULs"
//usage: )
//usage: IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(
//usage: "\n -a FILE Read from FILE instead of stdin"
//usage: )
//usage: "\n -r Don't run command if input is empty"
//usage: "\n -t Print the command on stderr before execution"
//usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(
//usage: "\n -p Ask user whether to run each command"
//usage: )
//usage: "\n -E STR,-e[STR] STR stops input processing"
//usage: "\n -e[STR] STR stops input processing"
//usage: "\n -n N Pass no more than N args to PROG"
//usage: "\n -s N Pass command line of no more than N bytes"
//usage: IF_FEATURE_XARGS_SUPPORT_REPL_STR(
//usage: "\n -I STR Replace STR within PROG ARGS with input line"
//usage: )
//usage: "\n -n N Pass no more than N args to PROG"
//usage: "\n -s N Pass command line of no more than N bytes"
//usage: IF_FEATURE_XARGS_SUPPORT_PARALLEL(
//usage: "\n -P N Run up to N PROGs in parallel"
//usage: )
@@ -674,7 +665,7 @@ int xargs_main(int argc UNUSED_PARAM, char **argv)
}
/* Sanity check */
if (n_max_chars <= 0) {
bb_simple_error_msg_and_die("can't fit single argument within argument list size limit");
bb_error_msg_and_die("can't fit single argument within argument list size limit");
}
buf = xzalloc(n_max_chars + 1);
@@ -725,7 +716,7 @@ int xargs_main(int argc UNUSED_PARAM, char **argv)
if (!G.args[initial_idx]) { /* not even one ARG was added? */
if (*rem != '\0')
bb_simple_error_msg_and_die("argument line too long");
bb_error_msg_and_die("argument line too long");
if (opt & OPT_NO_EMPTY)
break;
}
-6
View File
@@ -235,12 +235,6 @@ typedef struct transformer_state_t {
off_t bytes_in; /* used in unzip code only: needs to know packed size */
uint32_t crc32;
time_t mtime; /* gunzip code may set this on exit */
union { /* if we read magic, it's saved here */
uint8_t b[8];
uint16_t b16[4];
uint32_t b32[2];
} magic;
} transformer_state_t;
void init_transformer_state(transformer_state_t *xstate) FAST_FUNC;
+13 -114
View File
@@ -298,7 +298,6 @@ typedef unsigned long uoff_t;
/* scary. better ideas? (but do *test* them first!) */
#define OFF_T_MAX ((off_t)~((off_t)1 << (sizeof(off_t)*8-1)))
/* Users report bionic to use 32-bit off_t even if LARGEFILE support is requested.
* On musl, !ENABLE_LFS on 32-bit arches thinks that off_t is 32-bit.
* We misdetected that. Don't let it build:
*/
struct BUG_off_t_size_is_misdetected {
@@ -689,7 +688,6 @@ int xsocket_stream(len_and_sockaddr **lsap) FAST_FUNC;
/* NB: these set SO_REUSEADDR before bind */
int create_and_bind_stream_or_die(const char *bindaddr, int port) FAST_FUNC;
int create_and_bind_dgram_or_die(const char *bindaddr, int port) FAST_FUNC;
int create_and_bind_to_netlink(int proto, int grp, unsigned rcvbuf) FAST_FUNC;
/* Create client TCP socket connected to peer:port. Peer cannot be NULL.
* Peer can be numeric IP ("N.N.N.N"), numeric IPv6 address or hostname,
* and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT").
@@ -883,7 +881,6 @@ extern ssize_t open_read_close(const char *filename, void *buf, size_t maxsz) FA
extern char *xmalloc_reads(int fd, size_t *maxsz_p) FAST_FUNC;
/* Reads block up to *maxsz_p (default: INT_MAX - 4095) */
extern void *xmalloc_read(int fd, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
extern void *xmalloc_read_with_initial_buf(int fd, size_t *maxsz_p, char *buf, size_t total) FAST_FUNC;
/* Returns NULL if file can't be opened (default max size: INT_MAX - 4095) */
extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
/* Never returns NULL */
@@ -1043,11 +1040,9 @@ uint16_t xatou16(const char *numstr) FAST_FUNC;
#if ENABLE_FLOAT_DURATION
typedef double duration_t;
void sleep_for_duration(duration_t duration) FAST_FUNC;
#define DURATION_FMT "f"
#else
typedef unsigned duration_t;
#define sleep_for_duration(duration) sleep(duration)
#define DURATION_FMT "u"
#endif
duration_t parse_duration_str(char *str) FAST_FUNC;
@@ -1138,7 +1133,7 @@ void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC;
({ \
pid_t bb__xvfork_pid = vfork(); \
if (bb__xvfork_pid < 0) \
bb_simple_perror_msg_and_die("vfork"); \
bb_perror_msg_and_die("vfork"); \
bb__xvfork_pid; \
})
#if BB_MMU
@@ -1206,11 +1201,11 @@ void set_task_comm(const char *comm) FAST_FUNC;
* to /dev/null if they are not.
*/
enum {
DAEMON_CHDIR_ROOT = 1 << 0,
DAEMON_DEVNULL_STDIO = 1 << 1,
DAEMON_CLOSE_EXTRA_FDS = 1 << 2,
DAEMON_ONLY_SANITIZE = 1 << 3, /* internal use */
//DAEMON_DOUBLE_FORK = 1 << 4, /* double fork to avoid controlling tty */
DAEMON_CHDIR_ROOT = 1,
DAEMON_DEVNULL_STDIO = 2,
DAEMON_CLOSE_EXTRA_FDS = 4,
DAEMON_ONLY_SANITIZE = 8, /* internal use */
DAEMON_DOUBLE_FORK = 16, /* double fork to avoid controlling tty */
};
#if BB_MMU
enum { re_execed = 0 };
@@ -1301,13 +1296,9 @@ llist_t *llist_find_str(llist_t *first, const char *str) FAST_FUNC;
/* True only if we created pidfile which is *file*, not /dev/null etc */
extern smallint wrote_pidfile;
void write_pidfile(const char *path) FAST_FUNC;
void write_pidfile_std_path_and_ext(const char *path) FAST_FUNC;
void remove_pidfile_std_path_and_ext(const char *path) FAST_FUNC;
#define remove_pidfile(path) do { if (wrote_pidfile) unlink(path); } while (0)
#else
enum { wrote_pidfile = 0 };
#define write_pidfile_std_path_and_ext(path) ((void)0)
#define remove_pidfile_std_path_and_ext(path) ((void)0)
#define write_pidfile(path) ((void)0)
#define remove_pidfile(path) ((void)0)
#endif
@@ -1319,78 +1310,26 @@ enum {
LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
};
extern const char *msg_eol;
extern smallint syslog_level;
extern smallint logmode;
extern uint8_t xfunc_error_retval;
extern void (*die_func)(void);
void xfunc_die(void) NORETURN FAST_FUNC;
void bb_show_usage(void) NORETURN FAST_FUNC;
void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
void bb_simple_error_msg(const char *s) FAST_FUNC;
void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
void bb_simple_error_msg_and_die(const char *s) NORETURN FAST_FUNC;
void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
void bb_simple_perror_msg(const char *s) FAST_FUNC;
void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC;
void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
void bb_simple_herror_msg(const char *s) FAST_FUNC;
void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
void bb_simple_herror_msg_and_die(const char *s) NORETURN FAST_FUNC;
void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
void bb_perror_nomsg(void) FAST_FUNC;
void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
void bb_die_memory_exhausted(void) NORETURN FAST_FUNC;
void bb_logenv_override(void) FAST_FUNC;
#if ENABLE_FEATURE_SYSLOG_INFO
void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
void bb_simple_info_msg(const char *s) FAST_FUNC;
void bb_vinfo_msg(const char *s, va_list p) FAST_FUNC;
#else
#define bb_info_msg bb_error_msg
#define bb_simple_info_msg bb_simple_error_msg
#define bb_vinfo_msg(s,p) bb_verror_msg(s,p,NULL)
#endif
#if ENABLE_WARN_SIMPLE_MSG
/* If enabled, cause calls to bb_error_msg() et al that only take a single
* parameter to generate a warning.
*/
static inline void __attribute__ ((deprecated("use bb_simple_error_msg instead")))
bb_not_simple_error_msg(const char *s) { bb_simple_error_msg(s); }
static inline void __attribute__ ((deprecated("use bb_simple_error_msg_and_die instead"))) NORETURN
bb_not_simple_error_msg_and_die(const char *s) { bb_simple_error_msg_and_die(s); }
static inline void __attribute__ ((deprecated("use bb_simple_perror_msg instead")))
bb_not_simple_perror_msg(const char *s) { bb_simple_perror_msg(s); }
static inline void __attribute__ ((deprecated("use bb_simple_perror_msg_and_die instead"))) NORETURN
bb_not_simple_perror_msg_and_die(const char *s) { bb_simple_perror_msg_and_die(s); }
static inline void __attribute__ ((deprecated("use bb_simple_herror_msg instead")))
bb_not_simple_herror_msg(const char *s) { bb_simple_herror_msg(s); }
static inline void __attribute__ ((deprecated("use bb_simple_herror_msg_and_die instead"))) NORETURN
bb_not_simple_herror_msg_and_die(const char *s) { bb_simple_herror_msg_and_die(s); }
static inline void __attribute__ ((deprecated("use bb_simple_info_msg instead")))
bb_not_simple_info_msg(const char *s) { bb_simple_info_msg(s); }
/* Override bb_error_msg() and related functions with macros that will
* substitute them for the equivalent bb_not_simple_error_msg() function when
* they are used with only a single parameter. Macro approach inspired by
* https://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments and
* https://gustedt.wordpress.com/2010/06/03/default-arguments-for-c99
*/
#define _ARG18(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, ...) _17
#define BB_MSG_KIND(...) _ARG18(__VA_ARGS__, , , , , , , , , , , , , , , , , _not_simple)
#define _BB_MSG(name, kind, ...) bb##kind##name(__VA_ARGS__)
#define BB_MSG(name, kind, ...) _BB_MSG(name, kind, __VA_ARGS__)
#define bb_error_msg(...) BB_MSG(_error_msg, BB_MSG_KIND(__VA_ARGS__), __VA_ARGS__)
#define bb_error_msg_and_die(...) BB_MSG(_error_msg_and_die, BB_MSG_KIND(__VA_ARGS__), __VA_ARGS__)
#define bb_perror_msg(...) BB_MSG(_perror_msg, BB_MSG_KIND(__VA_ARGS__), __VA_ARGS__)
#define bb_perror_msg_and_die(...) BB_MSG(_perror_msg_and_die, BB_MSG_KIND(__VA_ARGS__), __VA_ARGS__)
#define bb_herror_msg(...) BB_MSG(_herror_msg, BB_MSG_KIND(__VA_ARGS__), __VA_ARGS__)
#define bb_herror_msg_and_die(...) BB_MSG(_herror_msg_and_die, BB_MSG_KIND(__VA_ARGS__), __VA_ARGS__)
#if ENABLE_FEATURE_SYSLOG_INFO
#define bb_info_msg(...) BB_MSG(_info_msg, BB_MSG_KIND(__VA_ARGS__), __VA_ARGS__)
#endif
#endif
/* We need to export XXX_main from libbusybox
* only if we build "individual" binaries
*/
@@ -1402,7 +1341,7 @@ static inline void __attribute__ ((deprecated("use bb_simple_info_msg instead"))
/* Embedded script support */
char *get_script_content(unsigned n) FAST_FUNC;
int scripted_main(int argc, char** argv) MAIN_EXTERNALLY_VISIBLE;
int scripted_main(int argc, char** argv);
/* Applets which are useful from another applets */
int bb_cat(char** argv) FAST_FUNC;
@@ -1507,19 +1446,17 @@ extern void bb_warn_ignoring_args(char *arg) FAST_FUNC;
extern int get_linux_version_code(void) FAST_FUNC;
char *query_loop(const char *device) FAST_FUNC;
int get_free_loop(void) FAST_FUNC;
int del_loop(const char *device) FAST_FUNC;
extern char *query_loop(const char *device) FAST_FUNC;
extern int del_loop(const char *device) FAST_FUNC;
/*
* If *devname is not NULL, use that name, otherwise try to find free one,
* malloc and return it in *devname.
* return value is the opened fd to the loop device, or < on error
*/
int set_loop(char **devname, const char *file, unsigned long long offset, unsigned flags) FAST_FUNC;
extern int set_loop(char **devname, const char *file, unsigned long long offset, unsigned flags) FAST_FUNC;
/* These constants match linux/loop.h (without BB_ prefix): */
#define BB_LO_FLAGS_READ_ONLY 1
#define BB_LO_FLAGS_AUTOCLEAR 4
#define BB_LO_FLAGS_PARTSCAN 8
/* Returns malloced str */
char *bb_ask_noecho(int fd, int timeout, const char *prompt) FAST_FUNC;
@@ -1821,19 +1758,10 @@ unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC;
# else
# define MAX_HISTORY 0
# endif
typedef const char *get_exe_name_t(int i) FAST_FUNC;
typedef struct line_input_t {
int flags;
int timeout;
const char *path_lookup;
# if ENABLE_FEATURE_TAB_COMPLETION \
&& (ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH \
|| ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH \
)
/* function to fetch additional application-specific names to match */
get_exe_name_t *get_exe_name;
# define EDITING_HAS_get_exe_name 1
# endif
# if MAX_HISTORY
int cnt_history;
int cur_history;
@@ -1880,10 +1808,6 @@ int read_line_input(const char* prompt, char* command, int maxsize) FAST_FUNC;
read_line_input(prompt, command, maxsize)
#endif
#ifndef EDITING_HAS_get_exe_name
# define EDITING_HAS_get_exe_name 0
#endif
#ifndef COMM_LEN
# ifdef TASK_COMM_LEN
@@ -1904,12 +1828,7 @@ struct smaprec {
unsigned long stack;
unsigned long smap_pss, smap_swap;
unsigned long smap_size;
// For mixed 32/64 userspace, 32-bit pmap still needs
// 64-bit field here to correctly show 64-bit processes:
unsigned long long smap_start;
// (strictly speaking, other fields need to be wider too,
// but they are in kbytes, not bytes, and they hold sizes,
// not start addresses, sizes tend to be less than 4 terabytes)
unsigned long smap_start;
char smap_mode[5];
char *smap_name;
};
@@ -2169,32 +2088,12 @@ struct globals;
* Magic prevents ptr_to_globals from going into rodata.
* If you want to assign a value, use SET_PTR_TO_GLOBALS(x) */
extern struct globals *const ptr_to_globals;
#if defined(__clang_major__) && __clang_major__ >= 9
/* Clang/llvm drops assignment to "constant" storage. Silently.
* Needs serious convincing to not eliminate the store.
*/
static ALWAYS_INLINE void* not_const_pp(const void *p)
{
void *pp;
__asm__ __volatile__(
"# forget that p points to const"
: /*outputs*/ "=r" (pp)
: /*inputs*/ "0" (p)
);
return pp;
}
#else
static ALWAYS_INLINE void* not_const_pp(const void *p) { return (void*)p; }
#endif
/* At least gcc 3.4.6 on mipsel system needs optimization barrier */
#define barrier() __asm__ __volatile__("":::"memory")
#define SET_PTR_TO_GLOBALS(x) do { \
(*(struct globals**)not_const_pp(&ptr_to_globals)) = (void*)(x); \
(*(struct globals**)&ptr_to_globals) = (void*)(x); \
barrier(); \
} while (0)
#define FREE_PTR_TO_GLOBALS() do { \
if (ENABLE_FEATURE_CLEAN_UP) { \
free(ptr_to_globals); \
-4
View File
@@ -30,10 +30,6 @@
# endif
#endif
#if !__GNUC_PREREQ(5,0)
# define deprecated(msg) deprecated
#endif
#undef inline
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
/* it's a keyword */
+1 -1
View File
@@ -208,7 +208,7 @@ static char *make_tempdir(void)
bb_perror_msg_and_die("can't %smount tmpfs", "un");
}
#else
bb_simple_perror_msg_and_die("can't create temporary directory");
bb_perror_msg_and_die("can't create temporary directory");
#endif
} else {
xchdir(tempdir);
+169 -128
View File
@@ -145,6 +145,13 @@
# include <sys/ucontext.h>
#endif
/* Used only for sanitizing purposes in set_sane_term() below. On systems where
* the baud rate is stored in a separate field, we can safely disable them. */
#ifndef CBAUD
# define CBAUD 0
# define CBAUDEX 0
#endif
/* Was a CONFIG_xxx option. A lot of people were building
* not fully functional init by switching it on! */
#define DEBUG_INIT 0
@@ -210,8 +217,6 @@ struct globals {
#if !ENABLE_FEATURE_INIT_SYSLOG
const char *log_console;
#endif
sigset_t delayed_sigset;
struct timespec zero_ts;
} FIX_ALIASING;
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
@@ -342,8 +347,7 @@ static void set_sane_term(void)
{
struct termios tty;
if (tcgetattr(STDIN_FILENO, &tty) != 0)
return;
tcgetattr(STDIN_FILENO, &tty);
/* set control chars */
tty.c_cc[VINTR] = 3; /* C-c */
@@ -361,15 +365,10 @@ static void set_sane_term(void)
#endif
/* Make it be sane */
/* On systems where the baud rate is stored in a separate field, we can safely disable these. */
#ifndef CBAUD
# define CBAUD 0
# define CBAUDEX 0
#endif
/* Added CRTSCTS to fix Debian bug 528560 */
#ifndef CRTSCTS
# define CRTSCTS 0
#endif
/* added CRTSCTS to fix Debian bug 528560 */
tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD | CRTSCTS;
tty.c_cflag |= CREAD | HUPCL | CLOCAL;
@@ -413,8 +412,14 @@ static int open_stdio_to_tty(const char* tty_name)
static void reset_sighandlers_and_unblock_sigs(void)
{
bb_signals(0
| (1 << SIGTSTP)
| (1 << SIGSTOP)
+ (1 << SIGUSR1)
+ (1 << SIGUSR2)
+ (1 << SIGTERM)
+ (1 << SIGQUIT)
+ (1 << SIGINT)
+ (1 << SIGHUP)
+ (1 << SIGTSTP)
+ (1 << SIGSTOP)
, SIG_DFL);
sigprocmask_allsigs(SIG_UNBLOCK);
}
@@ -480,13 +485,16 @@ static pid_t run(const struct init_action *a)
{
pid_t pid;
/* Careful: don't be affected by a signal in vforked child */
sigprocmask_allsigs(SIG_BLOCK);
if (BB_MMU && (a->action_type & ASKFIRST))
pid = fork();
else
pid = vfork();
if (pid < 0)
message(L_LOG | L_CONSOLE, "can't fork");
if (pid) {
if (pid < 0)
message(L_LOG | L_CONSOLE, "can't fork");
sigprocmask_allsigs(SIG_UNBLOCK);
return pid; /* Parent or error */
}
@@ -580,11 +588,9 @@ static void waitfor(pid_t pid)
while (1) {
pid_t wpid = wait(NULL);
mark_terminated(wpid);
if (wpid == pid) /* this was the process we waited for */
break;
/* The above is not reliable enough: SIGTSTP handler might have
* wait'ed it already. Double check, exit if process is gone:
*/
/* Unsafe. SIGTSTP handler might have wait'ed it already */
/*if (wpid == pid) break;*/
/* More reliable: */
if (kill(pid, 0))
break;
}
@@ -793,17 +799,23 @@ static void run_shutdown_and_kill_processes(void)
* Delayed handlers just set a flag variable. The variable is checked
* in the main loop and acted upon.
*
* halt/poweroff/reboot and restart have immediate handlers.
* They only traverse linked list of struct action's, never modify it,
* this should be safe to do even in signal handler. Also they
* never return.
*
* SIGSTOP and SIGTSTP have immediate handlers. They just wait
* for SIGCONT to happen.
*
* halt/poweroff/reboot and restart have delayed handlers.
*
* SIGHUP has a delayed handler, because modifying linked list
* of struct action's from a signal handler while it is manipulated
* by the program may be disastrous.
*
* Ctrl-Alt-Del has a delayed handler. Not a must, but allowing
* it to happen even somewhere inside "sysinit" would be a bit awkward.
*
* There is a tiny probability that SIGHUP and Ctrl-Alt-Del will collide
* and only one will be remembered and acted upon.
*/
/* The SIGPWR/SIGUSR[12]/SIGTERM handler */
@@ -887,9 +899,11 @@ static void exec_restart_action(void)
*/
static void stop_handler(int sig UNUSED_PARAM)
{
int saved_errno = errno;
smallint saved_bb_got_signal;
int saved_errno;
bb_got_signal = 0;
saved_bb_got_signal = bb_got_signal;
saved_errno = errno;
signal(SIGCONT, record_signo);
while (1) {
@@ -903,12 +917,12 @@ static void stop_handler(int sig UNUSED_PARAM)
*/
wpid = wait_any_nohang(NULL);
mark_terminated(wpid);
if (wpid <= 0) /* no processes exited? sleep a bit */
sleep(1);
sleep(1);
}
signal(SIGCONT, SIG_DFL);
errno = saved_errno;
bb_got_signal = saved_bb_got_signal;
}
#if ENABLE_FEATURE_USE_INITTAB
@@ -973,39 +987,43 @@ static void reload_inittab(void)
}
#endif
static void check_delayed_sigs(struct timespec *ts)
static int check_delayed_sigs(void)
{
int sig = sigtimedwait(&G.delayed_sigset, /* siginfo_t */ NULL, ts);
if (sig <= 0)
return;
int sigs_seen = 0;
/* The signal "sig" was caught */
while (1) {
smallint sig = bb_got_signal;
if (!sig)
return sigs_seen;
bb_got_signal = 0;
sigs_seen = 1;
#if ENABLE_FEATURE_USE_INITTAB
if (sig == SIGHUP)
reload_inittab();
if (sig == SIGHUP)
reload_inittab();
#endif
if (sig == SIGINT)
run_actions(CTRLALTDEL);
if (sig == SIGQUIT) {
exec_restart_action();
/* returns only if no restart action defined */
}
if ((1 << sig) & (0
if (sig == SIGINT)
run_actions(CTRLALTDEL);
if (sig == SIGQUIT) {
exec_restart_action();
/* returns only if no restart action defined */
}
if ((1 << sig) & (0
#ifdef SIGPWR
| (1 << SIGPWR)
+ (1 << SIGPWR)
#endif
| (1 << SIGUSR1)
| (1 << SIGUSR2)
| (1 << SIGTERM)
)) {
halt_reboot_pwoff(sig);
+ (1 << SIGUSR1)
+ (1 << SIGUSR2)
+ (1 << SIGTERM)
)) {
halt_reboot_pwoff(sig);
}
}
/* if (sig == SIGCHLD) do nothing */
}
#if DEBUG_SEGV_HANDLER
static void handle_sigsegv(int sig, siginfo_t *info, void *ucontext)
static
void handle_sigsegv(int sig, siginfo_t *info, void *ucontext)
{
long ip;
ucontext_t *uc;
@@ -1032,63 +1050,51 @@ static void handle_sigsegv(int sig, siginfo_t *info, void *ucontext)
static void sleep_much(void)
{
sleep(30 * 24*60*60);
sleep(30 * 24*60*60);
}
int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int init_main(int argc UNUSED_PARAM, char **argv)
{
struct sigaction sa;
INIT_G();
/* Some users send poweroff signals to init VERY early.
* To handle this, mask signals early.
*/
/* sigemptyset(&G.delayed_sigset); - done by INIT_G() */
sigaddset(&G.delayed_sigset, SIGINT); /* Ctrl-Alt-Del */
sigaddset(&G.delayed_sigset, SIGQUIT); /* re-exec another init */
#ifdef SIGPWR
sigaddset(&G.delayed_sigset, SIGPWR); /* halt */
#endif
sigaddset(&G.delayed_sigset, SIGUSR1); /* halt */
sigaddset(&G.delayed_sigset, SIGTERM); /* reboot */
sigaddset(&G.delayed_sigset, SIGUSR2); /* poweroff */
#if ENABLE_FEATURE_USE_INITTAB
sigaddset(&G.delayed_sigset, SIGHUP); /* reread /etc/inittab */
#endif
sigaddset(&G.delayed_sigset, SIGCHLD); /* make sigtimedwait() exit on SIGCHLD */
sigprocmask(SIG_BLOCK, &G.delayed_sigset, NULL);
#if DEBUG_SEGV_HANDLER
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = handle_sigsegv;
sa.sa_flags = SA_SIGINFO;
sigaction_set(SIGSEGV, &sa);
sigaction_set(SIGILL, &sa);
sigaction_set(SIGFPE, &sa);
sigaction_set(SIGBUS, &sa);
#endif
if (argv[1] && strcmp(argv[1], "-q") == 0) {
return kill(1, SIGHUP);
}
#if !DEBUG_INIT
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
if (getpid() != 1
&& (!ENABLE_LINUXRC || applet_name[0] != 'l') /* not linuxrc? */
) {
bb_simple_error_msg_and_die("must be run as PID 1");
#if DEBUG_SEGV_HANDLER
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = handle_sigsegv;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGILL, &sa, NULL);
sigaction(SIGFPE, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
# ifdef RB_DISABLE_CAD
/* Turn off rebooting via CTL-ALT-DEL - we get a
* SIGINT on CAD so we can shut things down gracefully... */
reboot(RB_DISABLE_CAD); /* misnomer */
# endif
#endif
if (!DEBUG_INIT) {
/* Some users send poweroff signals to init VERY early.
* To handle this, mask signals early,
* and unmask them only after signal handlers are installed.
*/
sigprocmask_allsigs(SIG_BLOCK);
/* Expect to be invoked as init with PID=1 or be invoked as linuxrc */
if (getpid() != 1
&& (!ENABLE_LINUXRC || applet_name[0] != 'l') /* not linuxrc? */
) {
bb_error_msg_and_die("must be run as PID 1");
}
#ifdef RB_DISABLE_CAD
/* Turn off rebooting via CTL-ALT-DEL - we get a
* SIGINT on CAD so we can shut things down gracefully... */
reboot(RB_DISABLE_CAD); /* misnomer */
#endif
}
/* If, say, xmalloc would ever die, we don't want to oops kernel
* by exiting.
* NB: we set die_func *after* PID 1 check and bb_show_usage.
@@ -1151,65 +1157,106 @@ int init_main(int argc UNUSED_PARAM, char **argv)
}
#endif
#if ENABLE_FEATURE_INIT_MODIFY_CMDLINE
/* Make the command line just say "init" - that's all, nothing else */
strncpy(argv[0], "init", strlen(argv[0]));
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
while (*++argv)
nuke_str(*argv);
#endif
if (ENABLE_FEATURE_INIT_MODIFY_CMDLINE) {
/* Make the command line just say "init" - that's all, nothing else */
strncpy(argv[0], "init", strlen(argv[0]));
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
while (*++argv)
nuke_str(*argv);
}
/* Set up STOP signal handlers */
/* Stop handler must allow only SIGCONT inside itself */
memset(&sa, 0, sizeof(sa));
sigfillset(&sa.sa_mask);
sigdelset(&sa.sa_mask, SIGCONT);
sa.sa_handler = stop_handler;
sa.sa_flags = SA_RESTART;
sigaction_set(SIGTSTP, &sa); /* pause */
/* Does not work as intended, at least in 2.6.20.
* SIGSTOP is simply ignored by init
* (NB: behavior might differ under strace):
*/
sigaction_set(SIGSTOP, &sa); /* pause */
/* Set up signal handlers */
if (!DEBUG_INIT) {
struct sigaction sa;
/* Stop handler must allow only SIGCONT inside itself */
memset(&sa, 0, sizeof(sa));
sigfillset(&sa.sa_mask);
sigdelset(&sa.sa_mask, SIGCONT);
sa.sa_handler = stop_handler;
/* NB: sa_flags doesn't have SA_RESTART.
* It must be able to interrupt wait().
*/
sigaction_set(SIGTSTP, &sa); /* pause */
/* Does not work as intended, at least in 2.6.20.
* SIGSTOP is simply ignored by init:
*/
sigaction_set(SIGSTOP, &sa); /* pause */
/* These signals must interrupt wait(),
* setting handler without SA_RESTART flag.
*/
bb_signals_recursive_norestart(0
+ (1 << SIGINT) /* Ctrl-Alt-Del */
+ (1 << SIGQUIT) /* re-exec another init */
#ifdef SIGPWR
+ (1 << SIGPWR) /* halt */
#endif
+ (1 << SIGUSR1) /* halt */
+ (1 << SIGTERM) /* reboot */
+ (1 << SIGUSR2) /* poweroff */
#if ENABLE_FEATURE_USE_INITTAB
+ (1 << SIGHUP) /* reread /etc/inittab */
#endif
, record_signo);
sigprocmask_allsigs(SIG_UNBLOCK);
}
/* Now run everything that needs to be run */
/* First run the sysinit command */
run_actions(SYSINIT);
check_delayed_sigs(&G.zero_ts);
check_delayed_sigs();
/* Next run anything that wants to block */
run_actions(WAIT);
check_delayed_sigs(&G.zero_ts);
check_delayed_sigs();
/* Next run anything to be run only once */
run_actions(ONCE);
/* Now run the looping stuff for the rest of forever */
/* Now run the looping stuff for the rest of forever.
*/
while (1) {
int maybe_WNOHANG;
maybe_WNOHANG = check_delayed_sigs();
/* (Re)run the respawn/askfirst stuff */
run_actions(RESPAWN | ASKFIRST);
maybe_WNOHANG |= check_delayed_sigs();
/* Wait for any signal (typically it's SIGCHLD) */
check_delayed_sigs(NULL); /* NULL timespec makes it wait */
/* Don't consume all CPU time - sleep a bit */
sleep(1);
maybe_WNOHANG |= check_delayed_sigs();
/* Wait for any child process(es) to exit */
/* Wait for any child process(es) to exit.
*
* If check_delayed_sigs above reported that a signal
* was caught, wait will be nonblocking. This ensures
* that if SIGHUP has reloaded inittab, respawn and askfirst
* actions will not be delayed until next child death.
*/
if (maybe_WNOHANG)
maybe_WNOHANG = WNOHANG;
while (1) {
pid_t wpid;
struct init_action *a;
wpid = waitpid(-1, NULL, WNOHANG);
/* If signals happen _in_ the wait, they interrupt it,
* bb_signals_recursive_norestart set them up that way
*/
wpid = waitpid(-1, NULL, maybe_WNOHANG);
if (wpid <= 0)
break;
a = mark_terminated(wpid);
if (a) {
message(L_LOG, "process '%s' (pid %u) exited. "
message(L_LOG, "process '%s' (pid %d) exited. "
"Scheduling for restart.",
a->command, (unsigned)wpid);
a->command, wpid);
}
/* See if anyone else is waiting to be reaped */
maybe_WNOHANG = WNOHANG;
}
/* Don't consume all CPU time - sleep a bit */
sleep(1);
} /* while (1) */
}
@@ -1222,17 +1269,11 @@ int init_main(int argc UNUSED_PARAM, char **argv)
//usage: "Init is the first process started during boot. It never exits."
//usage: IF_FEATURE_USE_INITTAB(
//usage: "\n""It (re)spawns children according to /etc/inittab."
//usage: "\n""Signals:"
//usage: "\n""HUP: reload /etc/inittab"
//usage: )
//usage: IF_NOT_FEATURE_USE_INITTAB(
//usage: "\n""This version of init doesn't use /etc/inittab,"
//usage: "\n""has fixed set of processed to run."
//usage: "\n""Signals:"
//usage: )
//usage: "\n""TSTP: stop respawning until CONT"
//usage: "\n""QUIT: re-exec another init"
//usage: "\n""USR1/TERM/USR2/INT: run halt/reboot/poweroff/Ctrl-Alt-Del script"
//usage:
//usage:#define init_notes_usage
//usage: "This version of init is designed to be run only by the kernel.\n"
+16 -45
View File
@@ -123,16 +123,16 @@ void FAST_FUNC bb_show_usage(void)
{
if (ENABLE_SHOW_USAGE) {
#ifdef SINGLE_APPLET_STR
/* Imagine that this applet is "true". Dont link in printf! */
/* Imagine that this applet is "true". Dont suck in printf! */
const char *usage_string = unpack_usage_messages();
if (usage_string) {
if (*usage_string == '\b') {
full_write2_str("No help available\n");
full_write2_str("No help available.\n\n");
} else {
full_write2_str("Usage: "SINGLE_APPLET_STR" ");
full_write2_str(usage_string);
full_write2_str("\n");
full_write2_str("\n\n");
}
if (ENABLE_FEATURE_CLEAN_UP)
dealloc_usage_messages((char*)usage_string);
@@ -149,9 +149,9 @@ void FAST_FUNC bb_show_usage(void)
ap--;
}
full_write2_str(bb_banner);
full_write2_str(" multi-call binary.\n"); /* common string */
full_write2_str(" multi-call binary.\n");
if (*p == '\b')
full_write2_str("\nNo help available\n");
full_write2_str("\nNo help available.\n\n");
else {
full_write2_str("\nUsage: ");
full_write2_str(applet_name);
@@ -304,7 +304,7 @@ void lbb_prepare(const char *applet
IF_FEATURE_INDIVIDUAL(, char **argv))
{
#ifdef __GLIBC__
(*(int **)not_const_pp(&bb_errno)) = __errno_location();
(*(int **)&bb_errno) = __errno_location();
barrier();
#endif
applet_name = applet;
@@ -631,7 +631,7 @@ static void check_suid(int applet_no)
/* same group / in group */
m >>= 3;
if (!(m & S_IXOTH)) /* is x bit not set? */
bb_simple_error_msg_and_die("you have no permission to run this applet");
bb_error_msg_and_die("you have no permission to run this applet");
/* We set effective AND saved ids. If saved-id is not set
* like we do below, seteuid(0) can still later succeed! */
@@ -643,7 +643,7 @@ static void check_suid(int applet_no)
rgid = sct->m_ugid.gid;
/* else: we will set egid = rgid, thus dropping sgid effect */
if (setresgid(-1, rgid, rgid))
bb_simple_perror_msg_and_die("setresgid");
bb_perror_msg_and_die("setresgid");
/* Are we directed to change uid
* (APPLET = s** USER.GROUP or APPLET = S** USER.GROUP)?
@@ -653,7 +653,7 @@ static void check_suid(int applet_no)
uid = sct->m_ugid.uid;
/* else: we will set euid = ruid, thus dropping suid effect */
if (setresuid(-1, uid, uid))
bb_simple_perror_msg_and_die("setresuid");
bb_perror_msg_and_die("setresuid");
goto ret;
}
@@ -663,7 +663,7 @@ static void check_suid(int applet_no)
if (!onetime) {
onetime = 1;
bb_simple_error_msg("using fallback suid method");
bb_error_msg("using fallback suid method");
}
}
# endif
@@ -673,7 +673,7 @@ static void check_suid(int applet_no)
/* Real uid is not 0. If euid isn't 0 too, suid bit
* is most probably not set on our executable */
if (geteuid())
bb_simple_error_msg_and_die("must be suid to work properly");
bb_error_msg_and_die("must be suid to work properly");
} else if (APPLET_SUID(applet_no) == BB_SUID_DROP) {
/*
* Drop all privileges.
@@ -754,9 +754,7 @@ static void install_links(const char *busybox UNUSED_PARAM,
}
# endif
# if ENABLE_BUSYBOX || NUM_APPLETS > 0
static void run_applet_and_exit(const char *name, char **argv) NORETURN;
#endif
# if NUM_SCRIPTS > 0
static int find_script_by_name(const char *name)
@@ -772,18 +770,17 @@ static int find_script_by_name(const char *name)
return -1;
}
int scripted_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE;
int scripted_main(int argc UNUSED_PARAM, char **argv)
{
int script = find_script_by_name(applet_name);
if (script >= 0)
# if ENABLE_SHELL_ASH
#if ENABLE_ASH || ENABLE_SH_IS_ASH || ENABLE_BASH_IS_ASH
exit(ash_main(-script - 1, argv));
# elif ENABLE_SHELL_HUSH
#elif ENABLE_HUSH || ENABLE_SH_IS_HUSH || ENABLE_BASH_IS_HUSH
exit(hush_main(-script - 1, argv));
# else
#else
return 1;
# endif
#endif
return 0;
}
@@ -1026,33 +1023,7 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv)
}
# endif
#else /* defined(SINGLE_APPLET_MAIN) */
# if NUM_SCRIPTS > 0
/* if SINGLE_APPLET_MAIN, these two functions are simpler: */
int scripted_main(int argc UNUSED_PARAM, char **argv) MAIN_EXTERNALLY_VISIBLE;
int scripted_main(int argc UNUSED_PARAM, char **argv)
{
# if ENABLE_SHELL_ASH
int script = 0;
exit(ash_main(-script - 1, argv));
# elif ENABLE_SHELL_HUSH
int script = 0;
exit(hush_main(-script - 1, argv));
# else
return 1;
# endif
}
char* FAST_FUNC
get_script_content(unsigned n UNUSED_PARAM)
{
char *t = unpack_bz2_data(packed_scripts, sizeof(packed_scripts),
UNPACKED_SCRIPTS_LENGTH);
return t;
}
# endif /* NUM_SCRIPTS > 0 */
#endif /* defined(SINGLE_APPLET_MAIN) */
#endif /* !defined(SINGLE_APPLET_MAIN) */
#if ENABLE_BUILD_LIBBUSYBOX
+1 -1
View File
@@ -38,7 +38,7 @@ gid_t* FAST_FUNC bb_getgroups(int *ngroups, gid_t *group_array)
continue;
}
/* Some other error (should never happen on Linux) */
bb_simple_perror_msg_and_die("getgroups");
bb_perror_msg_and_die("getgroups");
}
if (ngroups)
+1 -1
View File
@@ -60,6 +60,6 @@ int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
return EXIT_FAILURE;
}
bb_simple_error_msg("All tests passed");
bb_error_msg("All tests passed");
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -119,7 +119,7 @@ void FAST_FUNC getcaps(void *arg)
caps->u32s = _LINUX_CAPABILITY_U32S_3;
break;
default:
bb_simple_error_msg_and_die("unsupported capability version");
bb_error_msg_and_die("unsupported capability version");
}
if (capget(&caps->header, caps->data) != 0)
+1 -1
View File
@@ -51,7 +51,7 @@ void FAST_FUNC change_identity(const struct passwd *pw)
return;
}
bb_simple_perror_msg_and_die("can't set groups");
bb_perror_msg_and_die("can't set groups");
}
xsetgid(pw->pw_gid);
+1 -1
View File
@@ -327,7 +327,7 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
) {
security_context_t con;
if (getfscreatecon(&con) == -1) {
bb_simple_perror_msg("getfscreatecon");
bb_perror_msg("getfscreatecon");
return -1;
}
if (con) {
Loaded 100 of 415 files, more files were not shown because too many files have changed in this diff. Show more