Compare commits
245
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be947c4d97 | ||
|
|
1ecfe811fe | ||
|
|
6968e08123 | ||
|
|
ca9c4653a9 | ||
|
|
11775edbfc | ||
|
|
a6588fa102 | ||
|
|
28634924f0 | ||
|
|
ad0d009e0c | ||
|
|
e835afadfe | ||
|
|
20cd31a2d7 | ||
|
|
acb8be7217 | ||
|
|
d598a8d4e6 | ||
|
|
202d9a6464 | ||
|
|
bd7c1f2d13 | ||
|
|
cfcd2399b2 | ||
|
|
b4c11c1397 | ||
|
|
e7800f351a | ||
|
|
476654cdbe | ||
|
|
8d75d794ea | ||
|
|
ee41094b80 | ||
|
|
04c1417602 | ||
|
|
2835a224cd | ||
|
|
eff58f15b0 | ||
|
|
298fabaefc | ||
|
|
2bba9ad67a | ||
|
|
4e314faa0a | ||
|
|
f5add44981 | ||
|
|
8a475def9e | ||
|
|
08a5dab181 | ||
|
|
1a1143907c | ||
|
|
628f134fe7 | ||
|
|
d3fabf89d7 | ||
|
|
fdd957bdc9 | ||
|
|
9f41271f3c | ||
|
|
760d035699 | ||
|
|
cd73871178 | ||
|
|
b434ce7069 | ||
|
|
cf76b5ce12 | ||
|
|
d3fe960271 | ||
|
|
186b98a86f | ||
|
|
054f5a5b0d | ||
|
|
590a22cf8d | ||
|
|
fb143f783d | ||
|
|
0f78d616cb | ||
|
|
307d26c0eb | ||
|
|
865814a617 | ||
|
|
d6e7672545 | ||
|
|
15943c886d | ||
|
|
fbdc167f27 | ||
|
|
cd7a38a87d | ||
|
|
d0cdacafa9 | ||
|
|
9caea2448e | ||
|
|
7666fa1d02 | ||
|
|
05399fc53d | ||
|
|
26a8b9f196 | ||
|
|
07f7ea70ed | ||
|
|
2ec34969e7 | ||
|
|
3e9b13e4c5 | ||
|
|
4eb1e425fe | ||
|
|
67e01fecce | ||
|
|
f02c52bcde | ||
|
|
34cc6c91a2 | ||
|
|
6ff0551157 | ||
|
|
962c4e8220 | ||
|
|
fb8d1ef2d0 | ||
|
|
e9ab07c211 | ||
|
|
841f8331d7 | ||
|
|
c538d5bcc3 | ||
|
|
45b4ecc868 | ||
|
|
feac9b607d | ||
|
|
09a0e2223f | ||
|
|
4ff933c0e7 | ||
|
|
6c6d37ee45 | ||
|
|
7df1f1dda1 | ||
|
|
2a563ea49a | ||
|
|
a4d564ad7c | ||
|
|
b8ffd11e65 | ||
|
|
278842dd72 | ||
|
|
7d16964c3e | ||
|
|
03e17bfa8d | ||
|
|
6e17766c33 | ||
|
|
ae57fcad5d | ||
|
|
e46047aa87 | ||
|
|
a28c1b21e1 | ||
|
|
98654b995b | ||
|
|
d32fc647d7 | ||
|
|
184b266917 | ||
|
|
bf0f2c7aa6 | ||
|
|
d3633b7e9c | ||
|
|
a9dc7c2f59 | ||
|
|
1b487ea8a6 | ||
|
|
9d7cbdeee3 | ||
|
|
27c290f7f2 | ||
|
|
a6ae999b3b | ||
|
|
5f8daefb83 | ||
|
|
0b0ccd4570 | ||
|
|
2a870d091e | ||
|
|
8feb25956f | ||
|
|
f17fbe1d36 | ||
|
|
cbf3bfa57a | ||
|
|
de3cae1348 | ||
|
|
5aeae36e2b | ||
|
|
ea23c25e96 | ||
|
|
3ed81cf052 | ||
|
|
5d2e409ef8 | ||
|
|
f92f1d0181 | ||
|
|
6be3a5242c | ||
|
|
14158b4127 | ||
|
|
85090c162b | ||
|
|
9aa6ffb22b | ||
|
|
b905d6c2ea | ||
|
|
1b90e031c3 | ||
|
|
fd0640e5a1 | ||
|
|
17f8418ea7 | ||
|
|
539e2802eb | ||
|
|
62a40a0448 | ||
|
|
d257608a84 | ||
|
|
a875d59d24 | ||
|
|
e3366d696c | ||
|
|
1e3cce6814 | ||
|
|
e765b5ac34 | ||
|
|
15a357e596 | ||
|
|
a4476eb654 | ||
|
|
d8290c2ef0 | ||
|
|
528808fa7b | ||
|
|
fe33683c8b | ||
|
|
43b8a1cc38 | ||
|
|
d5929d602e | ||
|
|
3dfe0ae5a8 | ||
|
|
01a1a967c9 | ||
|
|
07e5555a8f | ||
|
|
5a21c8550e | ||
|
|
d531f93f64 | ||
|
|
6116cb23cc | ||
|
|
5fd3ddfb24 | ||
|
|
e152cb8189 | ||
|
|
eb9f485b07 | ||
|
|
3fa97af7cc | ||
|
|
ad16741ccd | ||
|
|
69b114fb8a | ||
|
|
32afd3aa60 | ||
|
|
e7430867a8 | ||
|
|
2c51202aec | ||
|
|
a8d6f9bee4 | ||
|
|
7537406edd | ||
|
|
c9a67133d6 | ||
|
|
a3f326cd66 | ||
|
|
faa9e94db6 | ||
|
|
0a53b203f9 | ||
|
|
b9bbd4ddf6 | ||
|
|
c3a27b0bfd | ||
|
|
504fe45f35 | ||
|
|
f332617fbd | ||
|
|
c50493854a | ||
|
|
9dbe4d0547 | ||
|
|
109ee5d336 | ||
|
|
438b4ac286 | ||
|
|
29f3526048 | ||
|
|
0e3334c8d8 | ||
|
|
ac03a40cba | ||
|
|
2bba591991 | ||
|
|
f93187512d | ||
|
|
fb183076a3 | ||
|
|
69f9567de2 | ||
|
|
102f0d0d07 | ||
|
|
190693ced1 | ||
|
|
58adbb5505 | ||
|
|
0ed5f7aacd | ||
|
|
2cdcb1082c | ||
|
|
30f17e9556 | ||
|
|
ecd8c3affc | ||
|
|
81071e6872 | ||
|
|
2108a6f0b5 | ||
|
|
e2318bbad7 | ||
|
|
fca0ee5959 | ||
|
|
3795266841 | ||
|
|
83e49ade57 | ||
|
|
6f068904dc | ||
|
|
6885e49ba5 | ||
|
|
c472898eaa | ||
|
|
589051b565 | ||
|
|
18b699c30f | ||
|
|
83bc4332e7 | ||
|
|
12916b9220 | ||
|
|
6554d03735 | ||
|
|
a2796223cb | ||
|
|
53315570bb | ||
|
|
d82046f59f | ||
|
|
8b7e8ae224 | ||
|
|
192c14bd87 | ||
|
|
265a74b983 | ||
|
|
ffc3a93d0d | ||
|
|
50e4cc29f5 | ||
|
|
3e78f6f955 | ||
|
|
8ed9672660 | ||
|
|
4e03d41342 | ||
|
|
744ee5db1c | ||
|
|
3ba2df874c | ||
|
|
07f417b6ab | ||
|
|
e4785ca653 | ||
|
|
fe8390e0fe | ||
|
|
d353bfff46 | ||
|
|
69a12fa790 | ||
|
|
640ce3de07 | ||
|
|
f1999b5a9d | ||
|
|
29ed580668 | ||
|
|
922fdf6527 | ||
|
|
b664f740d9 | ||
|
|
bf2f2229bb | ||
|
|
821e64316a | ||
|
|
ff65061311 | ||
|
|
731f596175 | ||
|
|
fa6ab56353 | ||
|
|
3b394781b5 | ||
|
|
2de232da53 | ||
|
|
c009d35f00 | ||
|
|
76ad7481b1 | ||
|
|
5c13ab41bb | ||
|
|
1a4d9f6521 | ||
|
|
49111cdc4f | ||
|
|
891b98c9bc | ||
|
|
2e66daca65 | ||
|
|
d74f8435ea | ||
|
|
0f592d7fb9 | ||
|
|
604b7b6cc0 | ||
|
|
1bdbf26454 | ||
|
|
79df481dc4 | ||
|
|
7c47b560a8 | ||
|
|
9b76f895bc | ||
|
|
3deabea893 | ||
|
|
abaf9109bd | ||
|
|
3ea93e853e | ||
|
|
89deb22f97 | ||
|
|
16ca379b55 | ||
|
|
6eb0cbe07e | ||
|
|
f0058b1b1f | ||
|
|
e4569be244 | ||
|
|
f2743a5b00 | ||
|
|
cb7611385c | ||
|
|
96f92a1afa | ||
|
|
8e0ad2647a | ||
|
|
5680e98451 | ||
|
|
cd55f2d933 | ||
|
|
432fbd7a1a | ||
|
|
57434022ce |
No files matched your search
@@ -35,3 +35,10 @@ Config.in
|
||||
core
|
||||
.gdb_history
|
||||
.gdbinit
|
||||
|
||||
#
|
||||
# testing output
|
||||
#
|
||||
/busybox.links
|
||||
/runtest-tempdir-links
|
||||
/testsuite/echo-ne
|
||||
@@ -257,6 +257,26 @@ config UNICODE_PRESERVE_BROKEN
|
||||
at shell prompt will list file named 0xff (single char name
|
||||
with char value 255), not file named '?'.
|
||||
|
||||
config PAM
|
||||
bool "Support for PAM (Pluggable Authentication Modules)"
|
||||
default n
|
||||
help
|
||||
Use PAM in some busybox applets (currently login and httpd) instead
|
||||
of direct access to password database.
|
||||
|
||||
config FEATURE_USE_SENDFILE
|
||||
bool "Use sendfile system call"
|
||||
default y
|
||||
select PLATFORM_LINUX
|
||||
help
|
||||
When enabled, busybox will use the kernel sendfile() function
|
||||
instead of read/write loops to copy data between file descriptors
|
||||
(for example, cp command does this a lot).
|
||||
If sendfile() doesn't work, copying code falls back to read/write
|
||||
loop. sendfile() was originally implemented for faster I/O
|
||||
from files to sockets, but since Linux 2.6.33 it was extended
|
||||
to work for many more file types.
|
||||
|
||||
config LONG_OPTS
|
||||
bool "Support for --long-options"
|
||||
default y
|
||||
@@ -416,10 +436,7 @@ config SELINUX
|
||||
the option of compiling in SELinux applets.
|
||||
|
||||
If you do not have a complete SELinux userland installed, this stuff
|
||||
will not compile. Go visit
|
||||
http://www.nsa.gov/selinux/index.html
|
||||
to download the necessary stuff to allow busybox to compile with
|
||||
this option enabled. Specifially, libselinux 1.28 or better is
|
||||
will not compile. Specifially, libselinux 1.28 or better is
|
||||
directly required by busybox. If the installation is located in a
|
||||
non-standard directory, provide it by invoking make as follows:
|
||||
CFLAGS=-I<libselinux-include-path> \
|
||||
@@ -671,6 +688,14 @@ config DEBUG_PESSIMIZE
|
||||
in a much bigger executable that more closely matches the source
|
||||
code.
|
||||
|
||||
config UNIT_TEST
|
||||
bool "Build unit tests"
|
||||
default n
|
||||
help
|
||||
Say Y here if you want to build unit tests (both the framework and
|
||||
test cases) as a Busybox applet. This results in bigger code, so you
|
||||
probably don't want this option in production builds.
|
||||
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
default n
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 22
|
||||
SUBLEVEL = 0
|
||||
PATCHLEVEL = 23
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
@@ -55,7 +55,11 @@ endif
|
||||
# (cp -pPR is POSIX-compliant (cp -dpR or cp -a would not be))
|
||||
.PHONY: check
|
||||
.PHONY: test
|
||||
ifeq ($(CONFIG_UNIT_TEST),y)
|
||||
UNIT_CMD = ./busybox unit
|
||||
endif
|
||||
check test: busybox busybox.links
|
||||
$(UNIT_CMD)
|
||||
test -d $(objtree)/testsuite || cp -pPR $(srctree)/testsuite $(objtree)
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite \
|
||||
$(SHELL) -c "cd $(objtree)/testsuite && $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)"
|
||||
|
||||
@@ -21,10 +21,6 @@ help:
|
||||
@echo ' defconfig - set .config to largest generic configuration'
|
||||
@echo ' menuconfig - interactive curses-based configurator'
|
||||
@echo ' oldconfig - resolve any unresolved symbols in .config'
|
||||
@echo ' hosttools - build sed for the host.'
|
||||
@echo ' You can use these commands if the commands on the host'
|
||||
@echo ' is unusable. Afterwards use it like:'
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@$(if $(boards), \
|
||||
$(foreach b, $(boards), \
|
||||
printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#undef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
|
||||
@@ -49,6 +50,16 @@ static int cmp_name(const void *a, const void *b)
|
||||
return strcmp(aa->name, bb->name);
|
||||
}
|
||||
|
||||
static int str_isalnum_(const char *s)
|
||||
{
|
||||
while (*s) {
|
||||
if (!isalnum(*s) && *s != '_')
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
@@ -94,6 +105,12 @@ int main(int argc, char **argv)
|
||||
}
|
||||
printf(";\n\n");
|
||||
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
if (str_isalnum_(applets[i].name))
|
||||
printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("#ifndef SKIP_applet_main\n");
|
||||
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
|
||||
+17
-39
@@ -39,7 +39,7 @@ char* FAST_FUNC append_ext(char *filename, const char *expected_ext)
|
||||
}
|
||||
|
||||
int FAST_FUNC bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
|
||||
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
|
||||
const char *expected_ext
|
||||
)
|
||||
@@ -48,7 +48,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int status = 0;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
transformer_aux_data_t aux;
|
||||
transformer_state_t xstate;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
@@ -72,7 +72,8 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
goto err;
|
||||
} else {
|
||||
/* "clever zcat" with FILE */
|
||||
int fd = open_zipped(filename);
|
||||
/* fail_if_not_compressed because zcat refuses uncompressed input */
|
||||
int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
|
||||
if (fd < 0)
|
||||
goto err_name;
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
@@ -80,7 +81,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
} else
|
||||
if (option_mask32 & SEAMLESS_MAGIC) {
|
||||
/* "clever zcat" on stdin */
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0))
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -119,9 +120,11 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = 1;
|
||||
status = unpacker(&aux);
|
||||
init_transformer_state(&xstate);
|
||||
xstate.check_signature = 1;
|
||||
/*xstate.src_fd = STDIN_FILENO; - already is */
|
||||
xstate.dst_fd = STDOUT_FILENO;
|
||||
status = unpacker(&xstate);
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
} else {
|
||||
@@ -140,10 +143,10 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
unsigned new_name_len;
|
||||
|
||||
/* TODO: restore other things? */
|
||||
if (aux.mtime != 0) {
|
||||
if (xstate.mtime != 0) {
|
||||
struct timeval times[2];
|
||||
|
||||
times[1].tv_sec = times[0].tv_sec = aux.mtime;
|
||||
times[1].tv_sec = times[0].tv_sec = xstate.mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* Note: we closed it first.
|
||||
* On some systems calling utimes
|
||||
@@ -225,18 +228,13 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
#if ENABLE_UNCOMPRESS
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, unpack_uncompress, make_new_name_generic, "Z");
|
||||
return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -323,11 +321,6 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
@@ -354,7 +347,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
|
||||
|
||||
return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -394,11 +387,6 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
#if ENABLE_BUNZIP2
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -407,7 +395,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (applet_name[2] == 'c') /* bzcat */
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, unpack_bunzip2, make_new_name_generic, "bz2");
|
||||
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -493,11 +481,6 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
|
||||
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
#if ENABLE_UNLZMA
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -512,7 +495,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma");
|
||||
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -536,11 +519,6 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
|
||||
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
|
||||
#if ENABLE_UNXZ
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -555,6 +533,6 @@ int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_unxz, make_new_name_generic, "xz");
|
||||
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
|
||||
}
|
||||
#endif
|
||||
+1
-1
@@ -127,7 +127,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
|
||||
{
|
||||
IF_DESKTOP(long long) int total;
|
||||
ssize_t count;
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
//usage: IF_FEATURE_CPIO_P(
|
||||
//usage: "\n -p DIR Copy files to DIR"
|
||||
//usage: )
|
||||
//usage: "\nOptions:"
|
||||
//usage: "\n -d Make leading directories"
|
||||
//usage: "\n -m Preserve mtime"
|
||||
//usage: "\n -v Verbose"
|
||||
|
||||
+1
-1
@@ -2042,7 +2042,7 @@ static void zip(ulg time_stamp)
|
||||
|
||||
/* ======================================================================== */
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
|
||||
@@ -731,7 +731,7 @@ void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
|
||||
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
unpack_bz2_stream(transformer_state_t *xstate)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
bunzip_data *bd;
|
||||
@@ -739,14 +739,14 @@ unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
int i;
|
||||
unsigned len;
|
||||
|
||||
if (check_signature16(aux, src_fd, BZIP2_MAGIC))
|
||||
if (check_signature16(xstate, BZIP2_MAGIC))
|
||||
return -1;
|
||||
|
||||
outbuf = xmalloc(IOBUF_SIZE);
|
||||
len = 0;
|
||||
while (1) { /* "Process one BZ... stream" loop */
|
||||
|
||||
i = start_bunzip(&bd, src_fd, outbuf + 2, len);
|
||||
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
|
||||
|
||||
if (i == 0) {
|
||||
while (1) { /* "Produce some output bytes" loop */
|
||||
@@ -756,8 +756,7 @@ unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
i = IOBUF_SIZE - i; /* number of bytes produced */
|
||||
if (i == 0) /* EOF? */
|
||||
break;
|
||||
if (i != full_write(dst_fd, outbuf, i)) {
|
||||
bb_error_msg("short write");
|
||||
if (i != transformer_write(xstate, outbuf, i)) {
|
||||
i = RETVAL_SHORT_WRITE;
|
||||
goto release_mem;
|
||||
}
|
||||
@@ -790,7 +789,7 @@ unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
len = bd->inbufCount - bd->inbufPos;
|
||||
memcpy(outbuf, &bd->inbuf[bd->inbufPos], len);
|
||||
if (len < 2) {
|
||||
if (safe_read(src_fd, outbuf + len, 2 - len) != 2 - len)
|
||||
if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len)
|
||||
break;
|
||||
len = 2;
|
||||
}
|
||||
|
||||
@@ -971,7 +971,7 @@ static int inflate_get_next_window(STATE_PARAM_ONLY)
|
||||
|
||||
/* Called from unpack_gz_stream() and inflate_unzip() */
|
||||
static IF_DESKTOP(long long) int
|
||||
inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
{
|
||||
IF_DESKTOP(long long) int n = 0;
|
||||
ssize_t nwrote;
|
||||
@@ -980,7 +980,7 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
gunzip_window = xmalloc(GUNZIP_WSIZE);
|
||||
gunzip_outbuf_count = 0;
|
||||
gunzip_bytes_out = 0;
|
||||
gunzip_src_fd = in;
|
||||
gunzip_src_fd = xstate->src_fd;
|
||||
|
||||
/* (re) initialize state */
|
||||
method = -1;
|
||||
@@ -1002,9 +1002,8 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
|
||||
while (1) {
|
||||
int r = inflate_get_next_window(PASS_STATE_ONLY);
|
||||
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote != (ssize_t)gunzip_outbuf_count) {
|
||||
bb_perror_msg("write");
|
||||
nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote == (ssize_t)-1) {
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -1034,22 +1033,22 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
/* For unzip */
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
inflate_unzip(transformer_aux_data_t *aux, int in, int out)
|
||||
inflate_unzip(transformer_state_t *xstate)
|
||||
{
|
||||
IF_DESKTOP(long long) int n;
|
||||
DECLARE_STATE;
|
||||
|
||||
ALLOC_STATE;
|
||||
|
||||
to_read = aux->bytes_in;
|
||||
to_read = xstate->bytes_in;
|
||||
// bytebuffer_max = 0x8000;
|
||||
bytebuffer_offset = 4;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
n = inflate_unzip_internal(PASS_STATE in, out);
|
||||
n = inflate_unzip_internal(PASS_STATE xstate);
|
||||
free(bytebuffer);
|
||||
|
||||
aux->crc32 = gunzip_crc;
|
||||
aux->bytes_out = gunzip_bytes_out;
|
||||
xstate->crc32 = gunzip_crc;
|
||||
xstate->bytes_out = gunzip_bytes_out;
|
||||
DEALLOC_STATE;
|
||||
return n;
|
||||
}
|
||||
@@ -1107,7 +1106,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
|
||||
static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
@@ -1169,8 +1168,7 @@ static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
|
||||
}
|
||||
}
|
||||
|
||||
if (aux)
|
||||
aux->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
xstate->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formatted.flags & 0x02) {
|
||||
@@ -1182,27 +1180,27 @@ static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
|
||||
}
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
unpack_gz_stream(transformer_state_t *xstate)
|
||||
{
|
||||
uint32_t v32;
|
||||
IF_DESKTOP(long long) int total, n;
|
||||
DECLARE_STATE;
|
||||
|
||||
#if !ENABLE_FEATURE_SEAMLESS_Z
|
||||
if (check_signature16(aux, src_fd, GZIP_MAGIC))
|
||||
if (check_signature16(xstate, GZIP_MAGIC))
|
||||
return -1;
|
||||
#else
|
||||
if (aux && aux->check_signature) {
|
||||
if (xstate->check_signature) {
|
||||
uint16_t magic2;
|
||||
|
||||
if (full_read(src_fd, &magic2, 2) != 2) {
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
|
||||
bad_magic:
|
||||
bb_error_msg("invalid magic");
|
||||
return -1;
|
||||
}
|
||||
if (magic2 == COMPRESS_MAGIC) {
|
||||
aux->check_signature = 0;
|
||||
return unpack_Z_stream(aux, src_fd, dst_fd);
|
||||
xstate->check_signature = 0;
|
||||
return unpack_Z_stream(xstate);
|
||||
}
|
||||
if (magic2 != GZIP_MAGIC)
|
||||
goto bad_magic;
|
||||
@@ -1215,16 +1213,16 @@ unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
to_read = -1;
|
||||
// bytebuffer_max = 0x8000;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
gunzip_src_fd = src_fd;
|
||||
gunzip_src_fd = xstate->src_fd;
|
||||
|
||||
again:
|
||||
if (!check_header_gzip(PASS_STATE aux)) {
|
||||
if (!check_header_gzip(PASS_STATE xstate)) {
|
||||
bb_error_msg("corrupted data");
|
||||
total = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);
|
||||
n = inflate_unzip_internal(PASS_STATE xstate);
|
||||
if (n < 0) {
|
||||
total = -1;
|
||||
goto ret;
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
*/
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
unpack_Z_stream(transformer_state_t *xstate)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
IF_DESKTOP(long long) int retval = -1;
|
||||
@@ -102,7 +102,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
/* block compress mode -C compatible with 2.0 */
|
||||
int block_mode; /* = BLOCK_MODE; */
|
||||
|
||||
if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
|
||||
if (check_signature16(xstate, COMPRESS_MAGIC))
|
||||
return -1;
|
||||
|
||||
inbuf = xzalloc(IBUFSIZ + 64);
|
||||
@@ -114,7 +114,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
|
||||
/* 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(src_fd, inbuf, 1) != 1) {
|
||||
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
|
||||
bb_error_msg("short read");
|
||||
goto err;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
}
|
||||
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
rsize = safe_read(src_fd, inbuf + insize, IBUFSIZ);
|
||||
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
|
||||
if (rsize < 0)
|
||||
bb_error_msg_and_die(bb_msg_read_error);
|
||||
insize += rsize;
|
||||
@@ -274,7 +274,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
xwrite(dst_fd, outbuf, outpos);
|
||||
xtransformer_write(xstate, outbuf, outpos);
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
outpos = 0;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
xwrite(dst_fd, outbuf, outpos);
|
||||
xtransformer_write(xstate, outbuf, outpos);
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ enum {
|
||||
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
|
||||
unpack_lzma_stream(transformer_state_t *xstate)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
lzma_header_t header;
|
||||
@@ -214,8 +214,6 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
|
||||
uint32_t pos_state_mask;
|
||||
uint32_t literal_pos_mask;
|
||||
uint16_t *p;
|
||||
int num_bits;
|
||||
int num_probs;
|
||||
rc_t *rc;
|
||||
int i;
|
||||
uint8_t *buffer;
|
||||
@@ -225,7 +223,7 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
|| header.pos >= (9 * 5 * 5)
|
||||
) {
|
||||
bb_error_msg("bad lzma header");
|
||||
@@ -239,6 +237,9 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
|
||||
pos_state_mask = (1 << pb) - 1;
|
||||
literal_pos_mask = (1 << lp) - 1;
|
||||
|
||||
/* Example values from linux-3.3.4.tar.lzma:
|
||||
* dict_size: 64M, dst_size: 2^64-1
|
||||
*/
|
||||
header.dict_size = SWAP_LE32(header.dict_size);
|
||||
header.dst_size = SWAP_LE64(header.dst_size);
|
||||
|
||||
@@ -247,13 +248,17 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
|
||||
|
||||
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
|
||||
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
{
|
||||
int num_probs;
|
||||
|
||||
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
}
|
||||
|
||||
rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
@@ -301,7 +306,7 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
@@ -310,6 +315,7 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
|
||||
goto one_byte2;
|
||||
#endif
|
||||
} else {
|
||||
int num_bits;
|
||||
int offset;
|
||||
uint16_t *prob2;
|
||||
#define prob_len prob2
|
||||
@@ -434,19 +440,22 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
len--;
|
||||
} while (len != 0 && buffer_pos < header.dst_size);
|
||||
/* FIXME: ...........^^^^^
|
||||
* shouldn't it be "global_pos + buffer_pos < header.dst_size"?
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
IF_NOT_DESKTOP(int total_written = 0; /* success */)
|
||||
IF_DESKTOP(total_written += buffer_pos;)
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
bad:
|
||||
total_written = -1; /* failure */
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
#include "unxz/xz_dec_stream.c"
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
unpack_xz_stream(transformer_state_t *xstate)
|
||||
{
|
||||
enum xz_ret xz_result;
|
||||
struct xz_buf iobuf;
|
||||
@@ -55,7 +55,7 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
iobuf.out = membuf + BUFSIZ;
|
||||
iobuf.out_size = BUFSIZ;
|
||||
|
||||
if (!aux || aux->check_signature == 0) {
|
||||
if (!xstate || xstate->check_signature == 0) {
|
||||
/* Preload XZ file signature */
|
||||
strcpy((char*)membuf, HEADER_MAGIC);
|
||||
iobuf.in_size = HEADER_MAGIC_SIZE;
|
||||
@@ -67,7 +67,7 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
xz_result = X_OK;
|
||||
while (1) {
|
||||
if (iobuf.in_pos == iobuf.in_size) {
|
||||
int rd = safe_read(src_fd, membuf, BUFSIZ);
|
||||
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
|
||||
if (rd < 0) {
|
||||
bb_error_msg(bb_msg_read_error);
|
||||
total = -1;
|
||||
@@ -104,7 +104,7 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
// bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
|
||||
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
|
||||
if (iobuf.out_pos) {
|
||||
xwrite(dst_fd, iobuf.out, iobuf.out_pos);
|
||||
xtransformer_write(xstate, iobuf.out, iobuf.out_pos);
|
||||
IF_DESKTOP(total += iobuf.out_pos;)
|
||||
iobuf.out_pos = 0;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,9 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
*/
|
||||
p += len;
|
||||
sz -= len;
|
||||
if ((int)sz < 0
|
||||
if (
|
||||
/** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */
|
||||
(int)(sz|len) < 0 /* this works */
|
||||
|| len == 0
|
||||
|| errno != EINVAL
|
||||
|| *end != ' '
|
||||
@@ -241,7 +243,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* or not first block (false positive, it's not .gz/.bz2!) */
|
||||
if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
|
||||
goto err;
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
|
||||
err:
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
archive_handle->offset = 0;
|
||||
|
||||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -14,7 +14,7 @@ char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -76,11 +76,13 @@
|
||||
# define TEST_IP (ip < ip_end)
|
||||
# define NEED_IP(x) \
|
||||
if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun
|
||||
# define TEST_IV(x) if ((x) > (unsigned)0 - (511)) goto input_overrun
|
||||
|
||||
# undef TEST_OP /* don't need both of the tests here */
|
||||
# define TEST_OP 1
|
||||
# define NEED_OP(x) \
|
||||
if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun
|
||||
# define TEST_OV(x) if ((x) > (unsigned)0 - (511)) goto output_overrun
|
||||
|
||||
#define HAVE_ANY_OP 1
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 15 + *ip++;
|
||||
}
|
||||
/* copy literals */
|
||||
@@ -224,6 +225,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 31 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
@@ -265,6 +267,7 @@ int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
TEST_IV(t);
|
||||
t += 7 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
|
||||
@@ -6,19 +6,19 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
|
||||
void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
|
||||
{
|
||||
memset(aux, 0, sizeof(*aux));
|
||||
memset(xstate, 0, sizeof(*xstate));
|
||||
}
|
||||
|
||||
int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
|
||||
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
|
||||
{
|
||||
if (aux && aux->check_signature) {
|
||||
if (xstate->check_signature) {
|
||||
uint16_t magic2;
|
||||
if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
bb_error_msg("invalid magic");
|
||||
#if 0 /* possible future extension */
|
||||
if (aux->check_signature > 1)
|
||||
if (xstate->check_signature > 1)
|
||||
xfunc_die();
|
||||
#endif
|
||||
return -1;
|
||||
@@ -27,6 +27,47 @@ int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigne
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
|
||||
{
|
||||
ssize_t nwrote;
|
||||
|
||||
if (xstate->mem_output_size_max != 0) {
|
||||
size_t pos = xstate->mem_output_size;
|
||||
size_t size;
|
||||
|
||||
size = (xstate->mem_output_size += bufsize);
|
||||
if (size > xstate->mem_output_size_max) {
|
||||
free(xstate->mem_output_buf);
|
||||
xstate->mem_output_buf = NULL;
|
||||
bb_perror_msg("buffer %u too small", (unsigned)xstate->mem_output_size_max);
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
xstate->mem_output_buf = xrealloc(xstate->mem_output_buf, size + 1);
|
||||
memcpy(xstate->mem_output_buf + pos, buf, bufsize);
|
||||
xstate->mem_output_buf[size] = '\0';
|
||||
nwrote = bufsize;
|
||||
} else {
|
||||
nwrote = full_write(xstate->dst_fd, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
bb_perror_msg("write");
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
ret:
|
||||
return nwrote;
|
||||
}
|
||||
|
||||
ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
|
||||
{
|
||||
ssize_t nwrote = transformer_write(xstate, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
xfunc_die();
|
||||
}
|
||||
return nwrote;
|
||||
}
|
||||
|
||||
void check_errors_in_children(int signo)
|
||||
{
|
||||
int status;
|
||||
@@ -60,12 +101,12 @@ void check_errors_in_children(int signo)
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
#if BB_MMU
|
||||
void FAST_FUNC open_transformer(int fd,
|
||||
void FAST_FUNC fork_transformer(int fd,
|
||||
int check_signature,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
|
||||
)
|
||||
#else
|
||||
void FAST_FUNC open_transformer(int fd, const char *transform_prog)
|
||||
void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
#endif
|
||||
{
|
||||
struct fd_pair fd_pipe;
|
||||
@@ -80,10 +121,12 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog)
|
||||
#if BB_MMU
|
||||
{
|
||||
IF_DESKTOP(long long) int r;
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = check_signature;
|
||||
r = transformer(&aux, fd, fd_pipe.wr);
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.check_signature = check_signature;
|
||||
xstate.src_fd = fd;
|
||||
xstate.dst_fd = fd_pipe.wr;
|
||||
r = transformer(&xstate);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd_pipe.wr); /* send EOF */
|
||||
close(fd);
|
||||
@@ -118,16 +161,19 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog)
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
|
||||
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;
|
||||
int offset = -2;
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
int offset;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
offset = -2;
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
|
||||
/* .gz and .bz2 both have 2-byte signature, and their
|
||||
* unpack_XXX_stream wants this header skipped. */
|
||||
@@ -135,15 +181,15 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& magic.b16[0] == GZIP_MAGIC
|
||||
) {
|
||||
USE_FOR_MMU(xformer = unpack_gz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "gunzip";)
|
||||
xstate->xformer = unpack_gz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& magic.b16[0] == BZIP2_MAGIC
|
||||
) {
|
||||
USE_FOR_MMU(xformer = unpack_bz2_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
|
||||
xstate->xformer = unpack_bz2_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
@@ -152,69 +198,146 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
|
||||
offset = -6;
|
||||
xread(fd, magic.b32, sizeof(magic.b32[0]));
|
||||
if (magic.b32[0] == XZ_MAGIC2) {
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "unxz";)
|
||||
xstate->xformer = unpack_xz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
|
||||
goto found_magic;
|
||||
}
|
||||
}
|
||||
|
||||
/* No known magic seen */
|
||||
if (fail_if_not_detected)
|
||||
if (fail_if_not_compressed)
|
||||
bb_error_msg_and_die("no gzip"
|
||||
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
IF_FEATURE_SEAMLESS_XZ("/xz")
|
||||
" magic");
|
||||
xlseek(fd, offset, SEEK_CUR);
|
||||
return 1;
|
||||
|
||||
found_magic:
|
||||
# if BB_MMU
|
||||
open_transformer_with_no_sig(fd, xformer);
|
||||
# else
|
||||
/* NOMMU version of open_transformer execs
|
||||
/* Some callers expect this function to "consume" fd
|
||||
* even if data is not compressed. In this case,
|
||||
* we return a state with trivial transformer.
|
||||
*/
|
||||
// USE_FOR_MMU(xstate->xformer = copy_stream;)
|
||||
// USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
|
||||
/* fall through to seeking bck over bytes we read earlier */
|
||||
|
||||
USE_FOR_NOMMU(found_magic:)
|
||||
/* NOMMU version of fork_transformer execs
|
||||
* an external unzipper that wants
|
||||
* file position at the start of the file */
|
||||
* file position at the start of the file.
|
||||
*/
|
||||
xlseek(fd, offset, SEEK_CUR);
|
||||
open_transformer_with_sig(fd, xformer, xformer_prog);
|
||||
|
||||
USE_FOR_MMU(found_magic:)
|
||||
/* In MMU case, if magic was found, seeking back is not necessary */
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
if (!xstate || !xstate->xformer) {
|
||||
free(xstate);
|
||||
return 1;
|
||||
}
|
||||
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
# else
|
||||
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
|
||||
# endif
|
||||
free(xstate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FAST_FUNC open_zipped(const char *fname)
|
||||
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
|
||||
{
|
||||
char *sfx;
|
||||
transformer_state_t *xstate;
|
||||
int fd;
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
return NULL;
|
||||
|
||||
sfx = strrchr(fname, '.');
|
||||
if (sfx) {
|
||||
sfx++;
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0)
|
||||
/* .lzma has no header/signature, just trust it */
|
||||
open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
|
||||
else
|
||||
if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0)
|
||||
) {
|
||||
setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
|
||||
/* .lzma has no header/signature, can only detect it by extension */
|
||||
char *sfx = strrchr(fname, '.');
|
||||
if (sfx && strcmp(sfx+1, "lzma") == 0) {
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->xformer = unpack_lzma_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
|
||||
return xstate;
|
||||
}
|
||||
}
|
||||
|
||||
xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
|
||||
{
|
||||
int fd;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = open_transformer(fname, fail_if_not_compressed);
|
||||
if (!xstate)
|
||||
return -1;
|
||||
|
||||
fd = xstate->src_fd;
|
||||
if (xstate->xformer) {
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
# else
|
||||
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
|
||||
# endif
|
||||
}
|
||||
/* else: the file is not compressed */
|
||||
|
||||
free(xstate);
|
||||
return fd;
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
|
||||
void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p)
|
||||
{
|
||||
# if 1
|
||||
transformer_state_t *xstate;
|
||||
char *image;
|
||||
|
||||
xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0);
|
||||
if (!xstate) /* file open error */
|
||||
return NULL;
|
||||
|
||||
image = NULL;
|
||||
if (xstate->xformer) {
|
||||
/* In-memory decompression */
|
||||
xstate->mem_output_size_max = maxsz_p ? *maxsz_p : (size_t)(INT_MAX - 4095);
|
||||
xstate->xformer(xstate);
|
||||
if (xstate->mem_output_buf) {
|
||||
image = xstate->mem_output_buf;
|
||||
if (maxsz_p)
|
||||
*maxsz_p = xstate->mem_output_size;
|
||||
}
|
||||
} else {
|
||||
/* File is not compressed */
|
||||
image = xmalloc_read(xstate->src_fd, maxsz_p);
|
||||
}
|
||||
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(xstate->src_fd);
|
||||
free(xstate);
|
||||
return image;
|
||||
# else
|
||||
/* This version forks a subprocess - much more expensive */
|
||||
int fd;
|
||||
char *image;
|
||||
|
||||
fd = open_zipped(fname);
|
||||
fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
@@ -222,6 +345,8 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(fd);
|
||||
|
||||
return image;
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
+1
-1
@@ -1099,7 +1099,7 @@ static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_e
|
||||
return xasprintf("%s.lzo", filename);
|
||||
}
|
||||
|
||||
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate UNUSED_PARAM)
|
||||
{
|
||||
if (option_mask32 & OPT_DECOMPRESS)
|
||||
return do_lzo_decompress();
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ static void extract_cpio(int fd, const char *source_rpm)
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1);
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
/* This works, but doesn't report uncompress errors (they happen in child) */
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
|
||||
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
|
||||
bb_error_msg_and_die("error unpacking");
|
||||
|
||||
|
||||
+33
-45
@@ -160,13 +160,6 @@
|
||||
#define block_buf bb_common_bufsiz1
|
||||
|
||||
|
||||
#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
|
||||
/*
|
||||
@@ -621,21 +614,12 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
# endif
|
||||
#if SEAMLESS_COMPRESSION
|
||||
/* Don't inline: vfork scares gcc and pessimizes code */
|
||||
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
{
|
||||
pid_t gzipPid;
|
||||
# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
# elif ENABLE_FEATURE_SEAMLESS_GZ
|
||||
const char *zip_exec = "gzip";
|
||||
# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
const char *zip_exec = "bzip2";
|
||||
# endif
|
||||
|
||||
// On Linux, vfork never unpauses parent early, although standard
|
||||
// allows for that. Do we want to waste bytes checking for it?
|
||||
# define WAIT_FOR_CHILD 0
|
||||
@@ -649,11 +633,6 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
# if defined(__GNUC__) && __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &zip_exec;
|
||||
# endif
|
||||
|
||||
gzipPid = xvfork();
|
||||
|
||||
if (gzipPid == 0) {
|
||||
@@ -669,7 +648,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", (char *)0);
|
||||
BB_EXECLP(gzip, gzip, "-f", (char *)0);
|
||||
vfork_exec_errno = errno;
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -692,16 +671,21 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
# endif
|
||||
if (vfork_exec_errno) {
|
||||
errno = vfork_exec_errno;
|
||||
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
|
||||
bb_perror_msg_and_die("can't execute '%s'", gzip);
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
|
||||
|
||||
#if !SEAMLESS_COMPRESSION
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#endif
|
||||
/* gcc 4.2.1 inlines it, making code bigger */
|
||||
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int recurseFlags, const llist_t *include,
|
||||
const llist_t *exclude, int gzip)
|
||||
const llist_t *exclude, const char *gzip)
|
||||
{
|
||||
int errorFlag = FALSE;
|
||||
struct TarBallInfo tbInfo;
|
||||
@@ -714,7 +698,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
* can avoid including the tarball into itself.... */
|
||||
xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
#if SEAMLESS_COMPRESSION
|
||||
if (gzip)
|
||||
vfork_compressor(tbInfo.tarFd, gzip);
|
||||
#endif
|
||||
@@ -749,7 +733,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
#if SEAMLESS_COMPRESSION
|
||||
if (gzip) {
|
||||
int status;
|
||||
if (safe_waitpid(-1, &status, 0) == -1)
|
||||
@@ -761,11 +745,9 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
#endif
|
||||
return errorFlag;
|
||||
}
|
||||
#else
|
||||
int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int recurseFlags, const llist_t *include,
|
||||
const llist_t *exclude, int gzip);
|
||||
#endif /* FEATURE_TAR_CREATE */
|
||||
#else /* !FEATURE_TAR_CREATE */
|
||||
# define writeTarFile(...) 0
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
@@ -1137,7 +1119,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
&& flags == O_RDONLY
|
||||
&& !(opt & OPT_ANY_COMPRESS)
|
||||
) {
|
||||
tar_handle->src_fd = open_zipped(tar_filename);
|
||||
tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
|
||||
if (tar_handle->src_fd < 0)
|
||||
bb_perror_msg_and_die("can't open '%s'", tar_filename);
|
||||
} else {
|
||||
@@ -1149,18 +1131,24 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
//if (SEAMLESS_COMPRESSION || OPT_COMPRESS)
|
||||
//if (SEAMLESS_COMPRESSION)
|
||||
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
/* Create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
int zipMode = 0;
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP))
|
||||
zipMode = 1;
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2))
|
||||
zipMode = 2;
|
||||
#if SEAMLESS_COMPRESSION
|
||||
const char *zipMode = NULL;
|
||||
if (opt & OPT_COMPRESS)
|
||||
zipMode = "compress";
|
||||
if (opt & OPT_GZIP)
|
||||
zipMode = "gzip";
|
||||
if (opt & OPT_BZIP2)
|
||||
zipMode = "bzip2";
|
||||
if (opt & OPT_LZMA)
|
||||
zipMode = "lzma";
|
||||
if (opt & OPT_XZ)
|
||||
zipMode = "xz";
|
||||
#endif
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag,
|
||||
@@ -1171,7 +1159,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
if (opt & OPT_ANY_COMPRESS) {
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
|
||||
if (opt & OPT_COMPRESS)
|
||||
@@ -1190,7 +1178,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "unxz";)
|
||||
|
||||
open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
|
||||
fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
|
||||
/* Can't lseek over pipes */
|
||||
tar_handle->seek = seek_by_read;
|
||||
/*tar_handle->offset = 0; - already is */
|
||||
|
||||
+8
-6
@@ -280,17 +280,19 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
bb_copyfd_exact_size(zip_fd, dst_fd, size);
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.bytes_in = zip_header->formatted.cmpsize;
|
||||
if (inflate_unzip(&aux, zip_fd, dst_fd) < 0)
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.bytes_in = zip_header->formatted.cmpsize;
|
||||
xstate.src_fd = zip_fd;
|
||||
xstate.dst_fd = dst_fd;
|
||||
if (inflate_unzip(&xstate) < 0)
|
||||
bb_error_msg_and_die("inflate error");
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (aux.crc32 ^ 0xffffffffL)) {
|
||||
if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != aux.bytes_out) {
|
||||
if (zip_header->formatted.ucmpsize != xstate.bytes_out) {
|
||||
/* Don't die. Who knows, maybe len calculation
|
||||
* was botched somewhere. After all, crc matched! */
|
||||
bb_error_msg("bad length");
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
*/
|
||||
|
||||
//usage:#define setlogcons_trivial_usage
|
||||
//usage: "N"
|
||||
//usage: "[N]"
|
||||
//usage:#define setlogcons_full_usage "\n\n"
|
||||
//usage: "Redirect the kernel output to console N (0 for current)"
|
||||
//usage: "Redirect the kernel output to console N. Default:0 (current console)"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
|
||||
+12
-1
@@ -633,12 +633,13 @@ config FEATURE_FANCY_TAIL
|
||||
default y
|
||||
depends on TAIL
|
||||
help
|
||||
The options (-q, -s, and -v) are provided by GNU tail, but
|
||||
The options (-q, -s, -v and -F) are provided by GNU tail, but
|
||||
are not specific in the SUSv3 standard.
|
||||
|
||||
-q Never output headers giving file names
|
||||
-s SEC Wait SEC seconds between reads with -f
|
||||
-v Always output headers giving file names
|
||||
-F Same as -f, but keep retrying
|
||||
|
||||
config TEE
|
||||
bool "tee"
|
||||
@@ -738,6 +739,16 @@ config YES
|
||||
yes is used to repeatedly output a specific string, or
|
||||
the default string `y'.
|
||||
|
||||
comment "Common options"
|
||||
|
||||
config FEATURE_VERBOSE
|
||||
bool "Support verbose options (usually -v) for various applets"
|
||||
default y
|
||||
help
|
||||
Enable cp -v, rm -v and similar messages.
|
||||
Also enables long option (--verbose) if it exists.
|
||||
Without this option, -v is accepted but ignored.
|
||||
|
||||
comment "Common options for cp and mv"
|
||||
depends on CP || MV
|
||||
|
||||
|
||||
+10
-8
@@ -20,20 +20,22 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
struct BUG_const_mismatch {
|
||||
char BUG_const_mismatch[
|
||||
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
|
||||
? 1 : -1
|
||||
];
|
||||
};
|
||||
|
||||
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
unsigned opts;
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
typedef char BUG_const_mismatch[
|
||||
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
|
||||
? 1 : -1
|
||||
];
|
||||
|
||||
opts = getopt32(argv, "etv");
|
||||
argv += optind;
|
||||
#if 0 /* These consts match, we can just pass "opts" to visible() */
|
||||
|
||||
+1
-1
@@ -16,10 +16,10 @@
|
||||
//usage: "Change the owner and/or group of each FILE to OWNER and/or 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 List all files"
|
||||
//usage: "\n -f Hide errors"
|
||||
|
||||
@@ -79,7 +79,6 @@ int cp_main(int argc, char **argv)
|
||||
"parents\0" No_argument "\xff"
|
||||
;
|
||||
#endif
|
||||
// -v (--verbose) is ignored
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
|
||||
/* Options of cp from GNU coreutils 6.10:
|
||||
* -a, --archive
|
||||
|
||||
+28
-8
@@ -25,6 +25,7 @@
|
||||
//usage:#define df_trivial_usage
|
||||
//usage: "[-Pk"
|
||||
//usage: IF_FEATURE_HUMAN_READABLE("mh")
|
||||
//usage: "T"
|
||||
//usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE")
|
||||
//usage: "] [FILESYSTEM]..."
|
||||
//usage:#define df_full_usage "\n\n"
|
||||
@@ -35,6 +36,7 @@
|
||||
//usage: "\n -m 1M-byte blocks"
|
||||
//usage: "\n -h Human readable (e.g. 1K 243M 2G)"
|
||||
//usage: )
|
||||
//usage: "\n -T Print filesystem type"
|
||||
//usage: IF_FEATURE_DF_FANCY(
|
||||
//usage: "\n -a Show all filesystems"
|
||||
//usage: "\n -i Inodes"
|
||||
@@ -83,11 +85,12 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
enum {
|
||||
OPT_KILO = (1 << 0),
|
||||
OPT_POSIX = (1 << 1),
|
||||
OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_FSTYPE = (1 << 2),
|
||||
OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
};
|
||||
const char *disp_units_hdr = NULL;
|
||||
char *chp;
|
||||
@@ -99,7 +102,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "k-m:m-k";
|
||||
#endif
|
||||
opt = getopt32(argv, "kP"
|
||||
opt = getopt32(argv, "kPT"
|
||||
IF_FEATURE_DF_FANCY("aiB:")
|
||||
IF_FEATURE_HUMAN_READABLE("hm")
|
||||
IF_FEATURE_DF_FANCY(, &chp));
|
||||
@@ -134,8 +137,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
|
||||
#endif
|
||||
}
|
||||
printf("Filesystem %-15sUsed Available %s Mounted on\n",
|
||||
disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
|
||||
printf("Filesystem %s%-15sUsed Available %s Mounted on\n",
|
||||
(opt & OPT_FSTYPE) ? "Type " : "",
|
||||
disp_units_hdr,
|
||||
(opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
|
||||
mount_table = NULL;
|
||||
argv += optind;
|
||||
@@ -148,6 +154,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (1) {
|
||||
const char *device;
|
||||
const char *mount_point;
|
||||
const char *fs_type;
|
||||
|
||||
if (mount_table) {
|
||||
mount_entry = getmntent(mount_table);
|
||||
@@ -170,6 +177,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
device = mount_entry->mnt_fsname;
|
||||
mount_point = mount_entry->mnt_dir;
|
||||
fs_type = mount_entry->mnt_type;
|
||||
|
||||
if (statfs(mount_point, &s) != 0) {
|
||||
bb_simple_perror_msg(mount_point);
|
||||
@@ -218,10 +226,22 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, "");
|
||||
}
|
||||
free(uni_dev);
|
||||
if (opt & OPT_FSTYPE) {
|
||||
char *uni_type = unicode_conv_to_printable(&uni_stat, fs_type);
|
||||
if (uni_stat.unicode_width > 10 && !(opt & OPT_POSIX))
|
||||
printf(" %s\n%31s", uni_type, "");
|
||||
else
|
||||
printf(" %s%*s", uni_type, 10 - (int)uni_stat.unicode_width, "");
|
||||
free(uni_type);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX))
|
||||
printf("\n%-20s", "");
|
||||
if (opt & OPT_FSTYPE) {
|
||||
if (printf(" %-10s", fs_type) > 11 && !(opt & OPT_POSIX))
|
||||
printf("\n%-30s", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
|
||||
+33
-18
@@ -8,7 +8,7 @@
|
||||
|
||||
/* -v, -b, -c are ignored */
|
||||
//usage:#define install_trivial_usage
|
||||
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST"
|
||||
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST"
|
||||
//usage:#define install_full_usage "\n\n"
|
||||
//usage: "Copy files and set attributes\n"
|
||||
//usage: "\n -c Just copy (default)"
|
||||
@@ -19,6 +19,7 @@
|
||||
//usage: "\n -o USER Set ownership"
|
||||
//usage: "\n -g GRP Set group ownership"
|
||||
//usage: "\n -m MODE Set permissions"
|
||||
//usage: "\n -t DIR Install to DIR"
|
||||
//usage: IF_SELINUX(
|
||||
//usage: "\n -Z Set security context"
|
||||
//usage: )
|
||||
@@ -28,12 +29,16 @@
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
static const char install_longopts[] ALIGN1 =
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
"directory\0" No_argument "d"
|
||||
"preserve-timestamps\0" No_argument "p"
|
||||
"strip\0" No_argument "s"
|
||||
"group\0" Required_argument "g"
|
||||
"mode\0" Required_argument "m"
|
||||
"owner\0" Required_argument "o"
|
||||
"target-directory\0" Required_argument "t"
|
||||
/* autofs build insists of using -b --suffix=.orig */
|
||||
/* TODO? (short option for --suffix is -S) */
|
||||
#if ENABLE_SELINUX
|
||||
@@ -89,11 +94,11 @@ int install_main(int argc, char **argv)
|
||||
const char *gid_str;
|
||||
const char *uid_str;
|
||||
const char *mode_str;
|
||||
int mkdir_flags = FILEUTILS_RECUR;
|
||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||
int opts;
|
||||
int min_args = 1;
|
||||
int ret = EXIT_SUCCESS;
|
||||
int isdir = 0;
|
||||
int isdir;
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext;
|
||||
bool use_default_selinux_context = 1;
|
||||
@@ -109,21 +114,22 @@ int install_main(int argc, char **argv)
|
||||
OPT_GROUP = 1 << 7,
|
||||
OPT_MODE = 1 << 8,
|
||||
OPT_OWNER = 1 << 9,
|
||||
OPT_TARGET = 1 << 10,
|
||||
#if ENABLE_SELINUX
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 10,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 11,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
applet_long_options = install_longopts;
|
||||
#endif
|
||||
opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
/* -c exists for backwards compatibility, it's needed */
|
||||
/* -v is ignored ("print name of each created directory") */
|
||||
/* -b is ignored ("make a backup of each existing destination file") */
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str, &last
|
||||
IF_SELINUX(, &scontext));
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
@@ -141,6 +147,11 @@ int install_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((opts & OPT_v) && FILEUTILS_VERBOSE) {
|
||||
mkdir_flags |= FILEUTILS_VERBOSE;
|
||||
copy_flags |= FILEUTILS_VERBOSE;
|
||||
}
|
||||
|
||||
/* preserve access and modification time, this is GNU behaviour,
|
||||
* BSD only preserves modification time */
|
||||
if (opts & OPT_PRESERVE_TIME) {
|
||||
@@ -152,33 +163,37 @@ int install_main(int argc, char **argv)
|
||||
uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
|
||||
gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
|
||||
|
||||
last = argv[argc - 1];
|
||||
if (!(opts & OPT_DIRECTORY)) {
|
||||
argv[argc - 1] = NULL;
|
||||
min_args++;
|
||||
|
||||
/* If -t DIR is in use, then isdir=true, last="DIR" */
|
||||
isdir = (opts & OPT_TARGET);
|
||||
if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) {
|
||||
/* Neither -t DIR nor -d is in use */
|
||||
argc--;
|
||||
last = argv[argc];
|
||||
argv[argc] = NULL;
|
||||
/* coreutils install resolves link in this case, don't use lstat */
|
||||
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
|
||||
}
|
||||
|
||||
if (argc < min_args)
|
||||
if (argc < 1)
|
||||
bb_show_usage();
|
||||
|
||||
while ((arg = *argv++) != NULL) {
|
||||
char *dest = last;
|
||||
char *dest;
|
||||
|
||||
if (opts & OPT_DIRECTORY) {
|
||||
dest = arg;
|
||||
/* GNU coreutils 6.9 does not set uid:gid
|
||||
* on intermediate created directories
|
||||
* (only on last one) */
|
||||
if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
|
||||
if (bb_make_directory(dest, 0755, mkdir_flags)) {
|
||||
ret = EXIT_FAILURE;
|
||||
goto next;
|
||||
}
|
||||
} else {
|
||||
dest = last;
|
||||
if (opts & OPT_MKDIR_LEADING) {
|
||||
char *ddir = xstrdup(dest);
|
||||
bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
|
||||
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
|
||||
/* errors are not checked. copy_file
|
||||
* will fail if dir is not created. */
|
||||
free(ddir);
|
||||
|
||||
+1
-1
@@ -1032,7 +1032,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
|
||||
}
|
||||
subdnp = scan_one_dir((*dn)->fullname, &nfiles);
|
||||
#if ENABLE_DESKTOP
|
||||
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG)
|
||||
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS))
|
||||
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
|
||||
#endif
|
||||
if (nfiles > 0) {
|
||||
|
||||
+6
-2
@@ -48,7 +48,9 @@ static const char mkdir_longopts[] ALIGN1 =
|
||||
#if ENABLE_SELINUX
|
||||
"context\0" Required_argument "Z"
|
||||
#endif
|
||||
#if ENABLE_FEATURE_VERBOSE
|
||||
"verbose\0" No_argument "v"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
|
||||
@@ -67,7 +69,7 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
|
||||
applet_long_options = mkdir_longopts;
|
||||
#endif
|
||||
opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext));
|
||||
opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
mode_t mmode = 0777;
|
||||
if (!bb_parse_mode(smode, &mmode)) {
|
||||
@@ -77,8 +79,10 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
if (opt & 2)
|
||||
flags |= FILEUTILS_RECUR;
|
||||
if ((opt & 4) && FILEUTILS_VERBOSE)
|
||||
flags |= FILEUTILS_VERBOSE;
|
||||
#if ENABLE_SELINUX
|
||||
if (opt & 4) {
|
||||
if (opt & 8) {
|
||||
selinux_or_die();
|
||||
setfscreatecon_or_die(scontext);
|
||||
}
|
||||
|
||||
+7
-1
@@ -33,13 +33,17 @@ static const char mv_longopts[] ALIGN1 =
|
||||
"interactive\0" No_argument "i"
|
||||
"force\0" No_argument "f"
|
||||
"no-clobber\0" No_argument "n"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
;
|
||||
#endif
|
||||
|
||||
#define OPT_FORCE (1 << 0)
|
||||
#define OPT_INTERACTIVE (1 << 1)
|
||||
#define OPT_NOCLOBBER (1 << 2)
|
||||
#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
|
||||
|
||||
|
||||
int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mv_main(int argc, char **argv)
|
||||
@@ -58,7 +62,6 @@ int mv_main(int argc, char **argv)
|
||||
/* Need at least two arguments.
|
||||
* If more than one of -f, -i, -n is specified , only the final one
|
||||
* takes effect (it unsets previous options).
|
||||
* -v is accepted but ignored.
|
||||
*/
|
||||
opt_complementary = "-2:f-in:i-fn:n-fi";
|
||||
flags = getopt32(argv, "finv");
|
||||
@@ -148,6 +151,9 @@ int mv_main(int argc, char **argv)
|
||||
status = 1;
|
||||
}
|
||||
RET_0:
|
||||
if (flags & OPT_VERBOSE) {
|
||||
printf("'%s' -> '%s'\n", *argv, dest);
|
||||
}
|
||||
if (dest != last) {
|
||||
free((void *) dest);
|
||||
}
|
||||
|
||||
+2
-1
@@ -38,7 +38,6 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opt;
|
||||
|
||||
opt_complementary = "f-i:i-f";
|
||||
/* -v (verbose) is ignored */
|
||||
opt = getopt32(argv, "fiRrv");
|
||||
argv += optind;
|
||||
if (opt & 1)
|
||||
@@ -47,6 +46,8 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
flags |= FILEUTILS_INTERACTIVE;
|
||||
if (opt & (8|4))
|
||||
flags |= FILEUTILS_RECUR;
|
||||
if ((opt & 16) && FILEUTILS_VERBOSE)
|
||||
flags |= FILEUTILS_VERBOSE;
|
||||
|
||||
if (*argv != NULL) {
|
||||
do {
|
||||
|
||||
+8
-2
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#define PARENTS (1 << 0)
|
||||
//efine VERBOSE (1 << 1) //accepted but ignored
|
||||
#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE)
|
||||
#define IGNORE_NON_EMPTY (1 << 2)
|
||||
|
||||
int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -44,10 +44,12 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
|
||||
static const char rmdir_longopts[] ALIGN1 =
|
||||
"parents\0" No_argument "p"
|
||||
"verbose\0" No_argument "v"
|
||||
/* Debian etch: many packages fail to be purged or installed
|
||||
* because they desperately want this option: */
|
||||
"ignore-fail-on-non-empty\0" No_argument "\xff"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
;
|
||||
applet_long_options = rmdir_longopts;
|
||||
#endif
|
||||
@@ -62,6 +64,10 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
path = *argv;
|
||||
|
||||
while (1) {
|
||||
if (flags & VERBOSE) {
|
||||
printf("rmdir: removing directory, '%s'\n", path);
|
||||
}
|
||||
|
||||
if (rmdir(path) < 0) {
|
||||
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
|
||||
if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* shuf: Write a random permutation of the input lines to standard output.
|
||||
*
|
||||
* Copyright (C) 2014 by Bartosz Golaszewski <bartekgola@gmail.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config SHUF
|
||||
//config: bool "shuf"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Generate random permutations
|
||||
|
||||
//kbuild:lib-$(CONFIG_SHUF) += shuf.o
|
||||
//applet:IF_SHUF(APPLET_NOEXEC(shuf, shuf, BB_DIR_USR_BIN, BB_SUID_DROP, shuf))
|
||||
|
||||
//usage:#define shuf_trivial_usage
|
||||
//usage: "[-e|-i L-H] [-n NUM] [-o FILE] [-z] [FILE|ARG...]"
|
||||
//usage:#define shuf_full_usage "\n\n"
|
||||
//usage: "Randomly permute lines\n"
|
||||
//usage: "\n -e Treat ARGs as lines"
|
||||
//usage: "\n -i L-H Treat numbers L-H as lines"
|
||||
//usage: "\n -n NUM Output at most NUM lines"
|
||||
//usage: "\n -o FILE Write to FILE, not standard output"
|
||||
//usage: "\n -z End lines with zero byte, not newline"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#define OPT_e (1 << 0)
|
||||
#define OPT_i (1 << 1)
|
||||
#define OPT_n (1 << 2)
|
||||
#define OPT_o (1 << 3)
|
||||
#define OPT_z (1 << 4)
|
||||
#define OPT_STR "ei:n:o:z"
|
||||
|
||||
/*
|
||||
* Use the Fisher-Yates shuffle algorithm on an array of lines.
|
||||
*/
|
||||
static void shuffle_lines(char **lines, unsigned numlines)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned r;
|
||||
char *tmp;
|
||||
|
||||
srand(monotonic_us());
|
||||
|
||||
for (i = numlines-1; i > 0; i--) {
|
||||
r = rand();
|
||||
/* RAND_MAX can be as small as 32767 */
|
||||
if (i > RAND_MAX)
|
||||
r ^= rand() << 15;
|
||||
r %= i;
|
||||
tmp = lines[i];
|
||||
lines[i] = lines[r];
|
||||
lines[r] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int shuf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int shuf_main(int argc, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
char *opt_i_str, *opt_n_str, *opt_o_str;
|
||||
unsigned i;
|
||||
char **lines;
|
||||
unsigned numlines;
|
||||
char eol;
|
||||
|
||||
opt_complementary = "e--i:i--e"; /* mutually exclusive */
|
||||
opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str);
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/* Prepare lines for shuffling - either: */
|
||||
if (opts & OPT_e) {
|
||||
/* make lines from command-line arguments */
|
||||
numlines = argc;
|
||||
lines = argv;
|
||||
} else
|
||||
if (opts & OPT_i) {
|
||||
/* create a range of numbers */
|
||||
char *dash;
|
||||
unsigned lo, hi;
|
||||
|
||||
dash = strchr(opt_i_str, '-');
|
||||
if (!dash) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
*dash = '\0';
|
||||
lo = xatou(opt_i_str);
|
||||
hi = xatou(dash + 1);
|
||||
*dash = '-';
|
||||
if (hi < lo) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
|
||||
numlines = (hi+1) - lo;
|
||||
lines = xmalloc(numlines * sizeof(lines[0]));
|
||||
for (i = 0; i < numlines; i++) {
|
||||
lines[i] = (char*)(uintptr_t)lo;
|
||||
lo++;
|
||||
}
|
||||
} else {
|
||||
/* default - read lines from stdin or the input file */
|
||||
FILE *fp;
|
||||
|
||||
if (argc > 1)
|
||||
bb_show_usage();
|
||||
|
||||
fp = xfopen_stdin(argv[0] ? argv[0] : "-");
|
||||
lines = NULL;
|
||||
numlines = 0;
|
||||
for (;;) {
|
||||
char *line = xmalloc_fgetline(fp);
|
||||
if (!line)
|
||||
break;
|
||||
lines = xrealloc_vector(lines, 6, numlines);
|
||||
lines[numlines++] = line;
|
||||
}
|
||||
fclose_if_not_stdin(fp);
|
||||
}
|
||||
|
||||
if (numlines != 0)
|
||||
shuffle_lines(lines, numlines);
|
||||
|
||||
if (opts & OPT_o)
|
||||
xmove_fd(xopen(opt_o_str, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
|
||||
|
||||
if (opts & OPT_n) {
|
||||
unsigned maxlines;
|
||||
maxlines = xatou(opt_n_str);
|
||||
if (numlines > maxlines)
|
||||
numlines = maxlines;
|
||||
}
|
||||
|
||||
eol = '\n';
|
||||
if (opts & OPT_z)
|
||||
eol = '\0';
|
||||
|
||||
for (i = 0; i < numlines; i++) {
|
||||
if (opts & OPT_i)
|
||||
printf("%u%c", (unsigned)(uintptr_t)lines[i], eol);
|
||||
else
|
||||
printf("%s%c", lines[i], eol);
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+7
-3
@@ -225,7 +225,7 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
y = *(char **)yarg;
|
||||
#endif
|
||||
/* Perform actual comparison */
|
||||
switch (flags & 7) {
|
||||
switch (flags & (FLAG_n | FLAG_M | FLAG_g)) {
|
||||
default:
|
||||
bb_error_msg_and_die("unknown sort type");
|
||||
break;
|
||||
@@ -302,10 +302,14 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
} /* for */
|
||||
|
||||
/* Perform fallback sort if necessary */
|
||||
if (!retval && !(option_mask32 & FLAG_s))
|
||||
if (!retval && !(option_mask32 & FLAG_s)) {
|
||||
retval = strcmp(*(char **)xarg, *(char **)yarg);
|
||||
flags = option_mask32;
|
||||
}
|
||||
|
||||
if (flags & FLAG_r)
|
||||
return -retval;
|
||||
|
||||
if (flags & FLAG_r) return -retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -655,7 +655,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
);
|
||||
# if ENABLE_SELINUX
|
||||
if (option_mask32 & OPT_SELINUX)
|
||||
printf(" %lc\n", *scontext);
|
||||
printf(" %s\n", scontext);
|
||||
else
|
||||
bb_putchar('\n');
|
||||
# endif
|
||||
@@ -700,7 +700,8 @@ static bool do_stat(const char *filename, const char *format)
|
||||
(unsigned long) statbuf.st_gid,
|
||||
(gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
|
||||
# if ENABLE_SELINUX
|
||||
printf(" S_Context: %lc\n", *scontext);
|
||||
if (option_mask32 & OPT_SELINUX)
|
||||
printf(" S_Context: %s\n", scontext);
|
||||
# endif
|
||||
printf("Access: %s\n", human_time(statbuf.st_atime));
|
||||
printf("Modify: %s\n", human_time(statbuf.st_mtime));
|
||||
|
||||
+3
-4
@@ -32,15 +32,14 @@
|
||||
//usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n"
|
||||
//usage: "With more than one FILE, precede each with a filename header.\n"
|
||||
//usage: "\n -f Print data as file grows"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: )
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: "\n -n N[kbm] Print last N lines"
|
||||
//usage: "\n -n +N[kbm] Start on Nth line and print the rest"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: "\n -F Same as -f, but keep retrying"
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
|
||||
//usage: )
|
||||
|
||||
+35
-34
@@ -826,7 +826,6 @@ int test_main(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
const char *arg0;
|
||||
// bool negate = 0;
|
||||
|
||||
arg0 = bb_basename(argv[0]);
|
||||
if (arg0[0] == '[') {
|
||||
@@ -844,6 +843,7 @@ int test_main(int argc, char **argv)
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
/* argc is unused after this point */
|
||||
|
||||
/* We must do DEINIT_S() prior to returning */
|
||||
INIT_S();
|
||||
@@ -862,43 +862,45 @@ int test_main(int argc, char **argv)
|
||||
*/
|
||||
/*ngroups = 0; - done by INIT_S() */
|
||||
|
||||
//argc--;
|
||||
argv++;
|
||||
args = argv;
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
if (!argv[0]) { /* "test" */
|
||||
res = 1;
|
||||
goto ret;
|
||||
}
|
||||
#if 0
|
||||
// Now it's fixed in the parser and should not be needed
|
||||
if (LONE_CHAR(argv[0], '!') && argv[1]) {
|
||||
negate = 1;
|
||||
//argc--;
|
||||
argv++;
|
||||
}
|
||||
if (!argv[1]) { /* "test [!] arg" */
|
||||
res = (*argv[0] == '\0');
|
||||
goto ret;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
check_operator(argv[1]);
|
||||
if (last_operator->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
args = argv;
|
||||
res = (binop() == 0);
|
||||
goto ret;
|
||||
/* Implement special cases from POSIX.2, section 4.62.4.
|
||||
* Testcase: "test '(' = '('"
|
||||
* The general parser would misinterpret '(' as group start.
|
||||
*/
|
||||
if (1) {
|
||||
int negate = 0;
|
||||
again:
|
||||
if (!argv[0]) {
|
||||
/* "test" */
|
||||
res = 1;
|
||||
goto ret_special;
|
||||
}
|
||||
if (!argv[1]) {
|
||||
/* "test [!] arg" */
|
||||
res = (argv[0][0] == '\0');
|
||||
goto ret_special;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
check_operator(argv[1]);
|
||||
if (last_operator->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
args = argv;
|
||||
res = (binop() == 0);
|
||||
ret_special:
|
||||
/* If there was leading "!" op... */
|
||||
res ^= negate;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
if (LONE_CHAR(argv[0], '!')) {
|
||||
argv++;
|
||||
negate ^= 1;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
|
||||
/* Some complex expression. Undo '!' removal */
|
||||
if (negate) {
|
||||
negate = 0;
|
||||
//argc++;
|
||||
argv--;
|
||||
}
|
||||
#endif
|
||||
args = argv;
|
||||
res = !oexpr(check_operator(*args));
|
||||
|
||||
if (*args != NULL && *++args != NULL) {
|
||||
@@ -911,6 +913,5 @@ int test_main(int argc, char **argv)
|
||||
}
|
||||
ret:
|
||||
DEINIT_S();
|
||||
// return negate ? !res : res;
|
||||
return res;
|
||||
}
|
||||
+6
-4
@@ -49,16 +49,18 @@
|
||||
*/
|
||||
|
||||
//usage:#define uname_trivial_usage
|
||||
//usage: "[-amnrspv]"
|
||||
//usage: "[-amnrspvio]"
|
||||
//usage:#define uname_full_usage "\n\n"
|
||||
//usage: "Print system information\n"
|
||||
//usage: "\n -a Print all"
|
||||
//usage: "\n -m The machine (hardware) type"
|
||||
//usage: "\n -n Hostname"
|
||||
//usage: "\n -r OS release"
|
||||
//usage: "\n -s OS name (default)"
|
||||
//usage: "\n -r Kernel release"
|
||||
//usage: "\n -s Kernel name (default)"
|
||||
//usage: "\n -p Processor type"
|
||||
//usage: "\n -v OS version"
|
||||
//usage: "\n -v Kernel version"
|
||||
//usage: "\n -i The hardware platform"
|
||||
//usage: "\n -o OS name"
|
||||
//usage:
|
||||
//usage:#define uname_example_usage
|
||||
//usage: "$ uname -a\n"
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* unlink for busybox
|
||||
*
|
||||
* Copyright (C) 2014 Isaac Dunham <ibid.ag@gmail.com>
|
||||
*
|
||||
* Licensed under GPLv2, see LICENSE in this source tree
|
||||
*/
|
||||
|
||||
//config:config UNLINK
|
||||
//config: bool "unlink"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unlink deletes a file by calling unlink()
|
||||
|
||||
//kbuild:lib-$(CONFIG_UNLINK) += unlink.o
|
||||
|
||||
//applet:IF_UNLINK(APPLET(unlink, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define unlink_trivial_usage
|
||||
//usage: "FILE"
|
||||
//usage:#define unlink_full_usage "\n\n"
|
||||
//usage: "Delete FILE by calling unlink()"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlink_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
opt_complementary = "=1"; /* must have exactly 1 param */
|
||||
getopt32(argv, "");
|
||||
argv += optind;
|
||||
xunlink(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
+24
-61
@@ -1,13 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Which implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
* Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*
|
||||
* Based on which from debianutils
|
||||
*/
|
||||
|
||||
//usage:#define which_trivial_usage
|
||||
@@ -24,76 +20,43 @@
|
||||
int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int which_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_DESKTOP(int opt;)
|
||||
int status = EXIT_SUCCESS;
|
||||
char *path;
|
||||
char *p;
|
||||
const char *env_path;
|
||||
int status = 0;
|
||||
|
||||
env_path = getenv("PATH");
|
||||
if (!env_path)
|
||||
env_path = bb_default_root_path;
|
||||
|
||||
opt_complementary = "-1"; /* at least one argument */
|
||||
IF_DESKTOP(opt =) getopt32(argv, "a");
|
||||
getopt32(argv, "a");
|
||||
argv += optind;
|
||||
|
||||
/* This matches what is seen on e.g. ubuntu.
|
||||
* "which" there is a shell script. */
|
||||
path = getenv("PATH");
|
||||
if (!path) {
|
||||
path = (char*)bb_PATH_root_path;
|
||||
putenv(path);
|
||||
path += 5; /* skip "PATH=" */
|
||||
}
|
||||
|
||||
do {
|
||||
#if ENABLE_DESKTOP
|
||||
/* Much bloat just to support -a */
|
||||
if (strchr(*argv, '/')) {
|
||||
if (execable_file(*argv)) {
|
||||
puts(*argv);
|
||||
continue;
|
||||
}
|
||||
status = EXIT_FAILURE;
|
||||
} else {
|
||||
char *path2 = xstrdup(path);
|
||||
char *tmp = path2;
|
||||
int missing = 1;
|
||||
|
||||
p = find_execable(*argv, &tmp);
|
||||
if (!p)
|
||||
status = EXIT_FAILURE;
|
||||
else {
|
||||
print:
|
||||
puts(p);
|
||||
free(p);
|
||||
if (opt) {
|
||||
/* -a: show matches in all PATH components */
|
||||
if (tmp) {
|
||||
p = find_execable(*argv, &tmp);
|
||||
if (p)
|
||||
goto print;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(path2);
|
||||
}
|
||||
#else
|
||||
/* Just ignoring -a */
|
||||
/* If file contains a slash don't use PATH */
|
||||
if (strchr(*argv, '/')) {
|
||||
if (execable_file(*argv)) {
|
||||
if (file_is_executable(*argv)) {
|
||||
missing = 0;
|
||||
puts(*argv);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
char *path2 = xstrdup(path);
|
||||
char *tmp = path2;
|
||||
p = find_execable(*argv, &tmp);
|
||||
free(path2);
|
||||
if (p) {
|
||||
char *path;
|
||||
char *tmp;
|
||||
char *p;
|
||||
|
||||
path = tmp = xstrdup(env_path);
|
||||
while ((p = find_executable(*argv, &tmp)) != NULL) {
|
||||
missing = 0;
|
||||
puts(p);
|
||||
free(p);
|
||||
continue;
|
||||
if (!option_mask32) /* -a not set */
|
||||
break;
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
status = EXIT_FAILURE;
|
||||
#endif
|
||||
} while (*(++argv) != NULL);
|
||||
status |= missing;
|
||||
} while (*++argv);
|
||||
|
||||
fflush_stdout_and_exit(status);
|
||||
return status;
|
||||
}
|
||||
@@ -21,7 +21,7 @@ static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
|
||||
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
|
||||
int i ;
|
||||
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
|
||||
if (exists_execable(ext_dhcp_clients[i].name))
|
||||
if (executable_exists(ext_dhcp_clients[i].name))
|
||||
return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
|
||||
}
|
||||
bb_error_msg("no dhcp clients found, using static interface shutdown");
|
||||
|
||||
@@ -103,7 +103,15 @@ smaller code. In order to assign it, use SET_PTR_TO_GLOBALS macro:
|
||||
|
||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
|
||||
|
||||
Typically it is done in <applet>_main().
|
||||
Typically it is done in <applet>_main(). Another variation is
|
||||
to use stack:
|
||||
|
||||
int <applet>_main(...)
|
||||
{
|
||||
#undef G
|
||||
struct globals G;
|
||||
memset(&G, 0, sizeof(G));
|
||||
SET_PTR_TO_GLOBALS(&G);
|
||||
|
||||
Now you can reference "globals" by G.a, G.buf and so on, in any function.
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ udhcpc - auto-backgrounds unless -f after lease is obtained,
|
||||
udhcpd - auto-backgrounds and do not log to stderr unless -f,
|
||||
otherwise logs to stderr, but option -S makes it log *also* to syslog
|
||||
zcip - auto-backgrounds and logs *also* to syslog unless -f
|
||||
behaviour can be overridden with experimental LOGGING env.var
|
||||
(can be set to either "none" or "syslog")
|
||||
|
||||
Total: 13 applets (+1 obsolete),
|
||||
4 log to syslog by default (crond fakeidentd inetd zcip),
|
||||
|
||||
+64
-40
@@ -6,7 +6,7 @@ This document details the steps you must take to add a new applet to BusyBox.
|
||||
Credits:
|
||||
Matt Kraai - initial writeup
|
||||
Mark Whitley - the remix
|
||||
Thomas Lundquist - Trying to keep it updated.
|
||||
Thomas Lundquist - trying to keep it updated
|
||||
|
||||
When doing this you should consider using the latest git HEAD.
|
||||
This is a good thing if you plan to getting it committed into mainline.
|
||||
@@ -16,14 +16,14 @@ Initial Write
|
||||
|
||||
First, write your applet. Be sure to include copyright information at the top,
|
||||
such as who you stole the code from and so forth. Also include the mini-GPL
|
||||
boilerplate. Be sure to name the main function <applet>_main instead of main.
|
||||
And be sure to put it in <applet>.c. Usage does not have to be taken care of by
|
||||
your applet.
|
||||
Make sure to #include "libbb.h" as the first include file in your applet.
|
||||
boilerplate and Config.in/Kbuild/usage/applet.h snippets (more on that below
|
||||
in this document). Be sure to name the main function <applet>_main instead
|
||||
of main. And be sure to put it in <applet>.c. Make sure to #include "libbb.h"
|
||||
as the first include file in your applet.
|
||||
|
||||
For a new applet mu, here is the code that would go in mu.c:
|
||||
|
||||
(busybox.h already includes most usual header files. You do not need
|
||||
(libbb.h already includes most usual header files. You do not need
|
||||
#include <stdio.h> etc...)
|
||||
|
||||
|
||||
@@ -41,6 +41,22 @@ For a new applet mu, here is the code that would go in mu.c:
|
||||
#include "libbb.h"
|
||||
#include "other.h"
|
||||
|
||||
//config:config MU
|
||||
//config: bool "MU"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Returns an indeterminate value.
|
||||
|
||||
//kbuild:lib-$(CONFIG_MU) += mu.o
|
||||
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define mu_trivial_usage
|
||||
//usage: "[-abcde] FILE..."
|
||||
//usage:#define mu_full_usage
|
||||
//usage: "Returns an indeterminate value\n"
|
||||
//usage: "\n -a First function"
|
||||
//usage: "\n -b Second function"
|
||||
|
||||
int mu_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mu_main(int argc, char **argv)
|
||||
{
|
||||
@@ -90,6 +106,8 @@ Make a new file named <function_name>.c
|
||||
#include "libbb.h"
|
||||
#include "other.h"
|
||||
|
||||
//kbuild:lib-y += function.o
|
||||
|
||||
int function(char *a)
|
||||
{
|
||||
return *a;
|
||||
@@ -97,9 +115,7 @@ int function(char *a)
|
||||
|
||||
----end example code------
|
||||
|
||||
Add <function_name>.o in the right alphabetically sorted place
|
||||
in libbb/Kbuild.src. You should look at the conditional part of
|
||||
libbb/Kbuild.src as well.
|
||||
Remember about the kbuild snippet.
|
||||
|
||||
You should also try to find a suitable place in include/libbb.h for
|
||||
the function declaration. If not, add it somewhere anyway, with or without
|
||||
@@ -109,60 +125,68 @@ You can look at libbb/Config.src and try to find out if the function is
|
||||
tunable and add it there if it is.
|
||||
|
||||
|
||||
Kbuild/Config.in/usage/applets.h snippets in .c files
|
||||
-----------------------------------------------------
|
||||
|
||||
The old way of adding new applets was to put all the information needed by the
|
||||
configuration and build system into appropriate files (namely: Kbuild.src and
|
||||
Config.src in new applet's directory) and to add the applet declaration and
|
||||
usage info text to include/applets.src.h and include/usage.src.h respectively.
|
||||
|
||||
Since the scripts/gen_build_files.sh script had been introduced, the preferred
|
||||
way is to have all these declarations contained within the applet .c files.
|
||||
|
||||
Every line intended to be processed by gen_build_files.sh should start as a
|
||||
comment without any preceding whitespaces and be followed by an appropriate
|
||||
keyword - kbuild, config, usage or applet - and a colon, just like shown in the
|
||||
first example above.
|
||||
|
||||
|
||||
Placement / Directory
|
||||
---------------------
|
||||
|
||||
Find the appropriate directory for your new applet.
|
||||
|
||||
Make sure you find the appropriate places in the files, the applets are
|
||||
sorted alphabetically.
|
||||
Add the kbuild snippet to the .c file:
|
||||
|
||||
Add the applet to Kbuild.src in the chosen directory:
|
||||
//kbuild:lib-$(CONFIG_MU) += mu.o
|
||||
|
||||
lib-$(CONFIG_MU) += mu.o
|
||||
Add the config snippet to the .c file:
|
||||
|
||||
Add the applet to Config.src in the chosen directory:
|
||||
|
||||
config MU
|
||||
bool "MU"
|
||||
default n
|
||||
help
|
||||
Returns an indeterminate value.
|
||||
//config:config MU
|
||||
//config: bool "MU"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Returns an indeterminate value.
|
||||
|
||||
|
||||
Usage String(s)
|
||||
---------------
|
||||
|
||||
Next, add usage information for you applet to include/usage.src.h.
|
||||
Next, add usage information for your applet to the .c file.
|
||||
This should look like the following:
|
||||
|
||||
#define mu_trivial_usage \
|
||||
"-[abcde] FILES"
|
||||
#define mu_full_usage \
|
||||
"Returns an indeterminate value.\n\n" \
|
||||
"Options:\n" \
|
||||
"\t-a\t\tfirst function\n" \
|
||||
"\t-b\t\tsecond function\n" \
|
||||
...
|
||||
//usage:#define mu_trivial_usage
|
||||
//usage: "[-abcde] FILE..."
|
||||
//usage:#define mu_full_usage
|
||||
//usage: "Returns an indeterminate value\n"
|
||||
//usage: "\n -a First function"
|
||||
//usage: "\n -b Second function"
|
||||
//usage: ...
|
||||
|
||||
If your program supports flags, the flags should be mentioned on the first
|
||||
line (-[abcde]) and a detailed description of each flag should go in the
|
||||
mu_full_usage section, one flag per line. (Numerous examples of this
|
||||
currently exist in usage.src.h.)
|
||||
line ([-abcde]) and a detailed description of each flag should go in the
|
||||
mu_full_usage section, one flag per line.
|
||||
|
||||
|
||||
Header Files
|
||||
------------
|
||||
|
||||
Next, add an entry to include/applets.src.h. Be *sure* to keep the list
|
||||
in alphabetical order, or else it will break the binary-search lookup
|
||||
algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
|
||||
Finally add the applet declaration snippet. Be sure to read the top of
|
||||
applets.src.h before adding your applet - it contains important info
|
||||
on applet macros and conventions.
|
||||
|
||||
Be sure to read the top of applets.src.h before adding your applet.
|
||||
|
||||
/* all programs above here are alphabetically "less than" 'mu' */
|
||||
IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
/* all programs below here are alphabetically "greater than" 'mu' */
|
||||
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
|
||||
The Grand Announcement
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
Busybox unit test framework
|
||||
===========================
|
||||
|
||||
This document describes what you need to do to write test cases using the
|
||||
Busybox unit test framework.
|
||||
|
||||
|
||||
Building unit tests
|
||||
-------------------
|
||||
|
||||
The framework and all tests are built as a regular Busybox applet if option
|
||||
CONFIG_UNIT_TEST (found in General Configuration -> Debugging Options) is set.
|
||||
|
||||
|
||||
Writing test cases
|
||||
------------------
|
||||
|
||||
Unit testing interface can be found in include/bbunit.h.
|
||||
|
||||
Tests can be placed in any .c file in Busybox tree - preferably right next to
|
||||
the functions they test. Test cases should be enclosed within an #if, and
|
||||
should start with BBUNIT_DEFINE_TEST macro and end with BBUNIT_ENDTEST within
|
||||
the test curly brackets. If an assertion fails the test ends immediately, ie.
|
||||
the following assertions will not be reached. Any code placed after
|
||||
BBUNIT_ENDTEST is executed regardless of the test result. Here's an example:
|
||||
|
||||
#if ENABLE_UNIT_TEST
|
||||
|
||||
BBUNIT_DEFINE_TEST(test_name)
|
||||
{
|
||||
int *i;
|
||||
|
||||
i = malloc(sizeof(int));
|
||||
BBUNIT_ASSERT_NOTNULL(i);
|
||||
*i = 2;
|
||||
BBUNIT_ASSERT_EQ((*i)*(*i), 4);
|
||||
|
||||
BBUNIT_ENDTEST;
|
||||
|
||||
free(i);
|
||||
}
|
||||
|
||||
#endif /* ENABLE_UNIT_TEST */
|
||||
|
||||
|
||||
Running the unit test suite
|
||||
---------------------------
|
||||
|
||||
To run the tests you can either directly run 'busybox unit' or use 'make test'
|
||||
to run both the unit tests (if compiled) and regular test suite.
|
||||
@@ -1540,12 +1540,14 @@ static void chain_group(void)
|
||||
debug_printf_parse("%s: OC_BREAK\n", __func__);
|
||||
n = chain_node(OC_EXEC);
|
||||
n->a.n = break_ptr;
|
||||
chain_expr(t_info);
|
||||
break;
|
||||
|
||||
case OC_CONTINUE:
|
||||
debug_printf_parse("%s: OC_CONTINUE\n", __func__);
|
||||
n = chain_node(OC_EXEC);
|
||||
n->a.n = continue_ptr;
|
||||
chain_expr(t_info);
|
||||
break;
|
||||
|
||||
/* delete, next, nextfile, return, exit */
|
||||
|
||||
+10
-3
@@ -395,7 +395,9 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
|
||||
/* process the flags */
|
||||
|
||||
sed_cmd->which_match = 1;
|
||||
dbg("s flags:'%s'", substr + idx + 1);
|
||||
while (substr[++idx]) {
|
||||
dbg("s flag:'%c'", substr[idx]);
|
||||
/* Parse match number */
|
||||
if (isdigit(substr[idx])) {
|
||||
if (match[0] != '^') {
|
||||
@@ -403,7 +405,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
|
||||
const char *pos = substr + idx;
|
||||
/* FIXME: error check? */
|
||||
sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10);
|
||||
idx = pos - substr;
|
||||
idx = pos - substr - 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -443,6 +445,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
|
||||
case '}':
|
||||
goto out;
|
||||
default:
|
||||
dbg("s bad flags:'%s'", substr + idx);
|
||||
bb_error_msg_and_die("bad option in substitution expression");
|
||||
}
|
||||
}
|
||||
@@ -1519,12 +1522,16 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* -i: process each FILE separately: */
|
||||
|
||||
if (stat(*argv, &statbuf) != 0) {
|
||||
bb_simple_perror_msg(*argv);
|
||||
G.exitcode = EXIT_FAILURE;
|
||||
G.current_input_file++;
|
||||
continue;
|
||||
}
|
||||
G.outname = xasprintf("%sXXXXXX", *argv);
|
||||
nonstdoutfd = xmkstemp(G.outname);
|
||||
G.nonstdout = xfdopen_for_write(nonstdoutfd);
|
||||
|
||||
/* Set permissions/owner of output file */
|
||||
stat(*argv, &statbuf);
|
||||
/* chmod'ing AFTER chown would preserve suid/sgid bits,
|
||||
* but GNU sed 4.2.1 does not preserve them either */
|
||||
fchmod(nonstdoutfd, statbuf.st_mode);
|
||||
|
||||
+645
-237
File diff suppressed because it is too large.
Load diff
@@ -22,10 +22,14 @@ then
|
||||
done
|
||||
fi
|
||||
|
||||
echo -n > $RESOLV_CONF
|
||||
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
|
||||
for i in $dns
|
||||
do
|
||||
echo adding dns $i
|
||||
echo nameserver $i >> $RESOLV_CONF
|
||||
done
|
||||
# Only replace resolv.conf is we have at least one DNS server
|
||||
if [ -n "$dns" ]
|
||||
then
|
||||
echo -n > $RESOLV_CONF
|
||||
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
|
||||
for i in $dns
|
||||
do
|
||||
echo adding dns $i
|
||||
echo nameserver $i >> $RESOLV_CONF
|
||||
done
|
||||
fi
|
||||
@@ -22,10 +22,14 @@ then
|
||||
done
|
||||
fi
|
||||
|
||||
echo -n > $RESOLV_CONF
|
||||
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
|
||||
for i in $dns
|
||||
do
|
||||
echo adding dns $i
|
||||
echo nameserver $i >> $RESOLV_CONF
|
||||
done
|
||||
# Only replace resolv.conf is we have at least one DNS server
|
||||
if [ -n "$dns" ]
|
||||
then
|
||||
echo -n > $RESOLV_CONF
|
||||
[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF
|
||||
for i in $dns
|
||||
do
|
||||
echo adding dns $i
|
||||
echo nameserver $i >> $RESOLV_CONF
|
||||
done
|
||||
fi
|
||||
@@ -9,6 +9,15 @@ env - PATH=... <other vars=...> runsvdir /var/service &
|
||||
from one of system startup scripts. (Google "man runsvdir" and "man runsv"
|
||||
for more info about these tools).
|
||||
|
||||
You can try or debug an individual service by running its SERVICE_DIR/run script.
|
||||
In this case, its stdout and stderr go to your terminal.
|
||||
|
||||
You can also run "runsv SERVICE_DIR", which runs both the service
|
||||
and its logger service (SERVICE_DIR/log/run) if logger service exists.
|
||||
If logger service exists, the output will go to it instead of the terminal.
|
||||
|
||||
"runsvdir DIR" merely runs "runsv SERVICE_DIR" for every subdirectory in DIR.
|
||||
|
||||
Some existing examples:
|
||||
|
||||
var_service/dhcp_if -
|
||||
@@ -47,8 +56,8 @@ This even works while fw service runs: if dhcp signals fw to (re)start
|
||||
while fw runs, fw will not stop after its execution, but will re-execute once,
|
||||
picking up dhcp's new configuration.
|
||||
This is achieved very simply by having
|
||||
# Make ourself one-shot
|
||||
sv o .
|
||||
# Make ourself one-shot
|
||||
sv o .
|
||||
at the very beginning of fw/run script, not at the end.
|
||||
Therefore, any "sv u /var/run/service/fw" command by any other
|
||||
script "undoes" o(ne-shot) command if fw still runs, thus
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
@@ -0,0 +1,5 @@
|
||||
The real README file is one directory up.
|
||||
|
||||
This directory's run script can have useful comments.
|
||||
If it doesn't but you feel it should, please send a patch
|
||||
to busybox's mailing list.
|
||||
+169
-51
@@ -137,6 +137,16 @@
|
||||
//config: Support the 'find -exec' option for executing commands based upon
|
||||
//config: the files matched.
|
||||
//config:
|
||||
//config:config FEATURE_FIND_EXEC_PLUS
|
||||
//config: bool "Enable -exec ... {} +"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_FIND_EXEC
|
||||
//config: help
|
||||
//config: Support the 'find -exec ... {} +' option for executing commands
|
||||
//config: for all matched files at once.
|
||||
//config: Without this option, -exec + is a synonym for -exec ;
|
||||
//config: (IOW: it works correctly, but without expected speedup)
|
||||
//config:
|
||||
//config:config FEATURE_FIND_USER
|
||||
//config: bool "Enable -user: username/uid matching"
|
||||
//config: default y
|
||||
@@ -319,6 +329,9 @@
|
||||
//usage: "\n -exec CMD ARG ; Run CMD with all instances of {} replaced by"
|
||||
//usage: "\n file name. Fails if CMD exits with nonzero"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_FIND_EXEC_PLUS(
|
||||
//usage: "\n -exec CMD ARG + Run CMD with {} replaced by list of file names"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_FIND_DELETE(
|
||||
//usage: "\n -delete Delete current file/directory. Turns on -depth option"
|
||||
//usage: )
|
||||
@@ -337,8 +350,12 @@
|
||||
# define FNM_CASEFOLD 0
|
||||
#endif
|
||||
|
||||
#define dbg(...) ((void)0)
|
||||
/* #define dbg(...) bb_error_msg(__VA_ARGS__) */
|
||||
#if 1
|
||||
# define dbg(...) ((void)0)
|
||||
#else
|
||||
# define dbg(...) bb_error_msg(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
@@ -375,7 +392,20 @@ IF_FEATURE_FIND_CONTEXT(ACTS(context, security_context_t context;))
|
||||
IF_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;))
|
||||
IF_FEATURE_FIND_PRUNE( ACTS(prune))
|
||||
IF_FEATURE_FIND_DELETE( ACTS(delete))
|
||||
IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
|
||||
IF_FEATURE_FIND_EXEC( ACTS(exec,
|
||||
char **exec_argv; /* -exec ARGS */
|
||||
unsigned *subst_count;
|
||||
int exec_argc; /* count of ARGS */
|
||||
IF_FEATURE_FIND_EXEC_PLUS(
|
||||
/*
|
||||
* filelist is NULL if "exec ;"
|
||||
* non-NULL if "exec +"
|
||||
*/
|
||||
char **filelist;
|
||||
int filelist_idx;
|
||||
int file_len;
|
||||
)
|
||||
))
|
||||
IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
|
||||
IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;))
|
||||
|
||||
@@ -389,6 +419,7 @@ struct globals {
|
||||
smallint need_print;
|
||||
smallint xdev_on;
|
||||
recurse_flags_t recurse_flags;
|
||||
IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;)
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
@@ -398,40 +429,11 @@ struct globals {
|
||||
/* we have to zero it out because of NOEXEC */ \
|
||||
memset(&G, 0, sizeof(G)); \
|
||||
IF_FEATURE_FIND_MAXDEPTH(G.minmaxdepth[1] = INT_MAX;) \
|
||||
IF_FEATURE_FIND_EXEC_PLUS(G.max_argv_len = bb_arg_max() - 2048;) \
|
||||
G.need_print = 1; \
|
||||
G.recurse_flags = ACTION_RECURSE; \
|
||||
} while (0)
|
||||
|
||||
#if ENABLE_FEATURE_FIND_EXEC
|
||||
static unsigned count_subst(const char *str)
|
||||
{
|
||||
unsigned count = 0;
|
||||
while ((str = strstr(str, "{}")) != NULL) {
|
||||
count++;
|
||||
str++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
static char* subst(const char *src, unsigned count, const char* filename)
|
||||
{
|
||||
char *buf, *dst, *end;
|
||||
size_t flen = strlen(filename);
|
||||
/* we replace each '{}' with filename: growth by strlen-2 */
|
||||
buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
|
||||
while ((end = strstr(src, "{}"))) {
|
||||
memcpy(dst, src, end - src);
|
||||
dst += end - src;
|
||||
src = end + 2;
|
||||
memcpy(dst, filename, flen);
|
||||
dst += flen;
|
||||
}
|
||||
strcpy(dst, src);
|
||||
return buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return values of ACTFs ('action functions') are a bit mask:
|
||||
* bit 1=1: prune (use SKIP constant for setting it)
|
||||
* bit 0=1: matched successfully (TRUE)
|
||||
@@ -482,7 +484,6 @@ static int exec_actions(action ***appp, const char *fileName, const struct stat
|
||||
return rc ^ TRUE; /* restore TRUE bit */
|
||||
}
|
||||
|
||||
|
||||
#if !FNM_CASEFOLD
|
||||
static char *strcpy_upcase(char *dst, const char *src)
|
||||
{
|
||||
@@ -557,8 +558,8 @@ ACTF(type)
|
||||
#if ENABLE_FEATURE_FIND_PERM
|
||||
ACTF(perm)
|
||||
{
|
||||
/* -perm +mode: at least one of perm_mask bits are set */
|
||||
if (ap->perm_char == '+')
|
||||
/* -perm [+/]mode: at least one of perm_mask bits are set */
|
||||
if (ap->perm_char == '+' || ap->perm_char == '/')
|
||||
return (statbuf->st_mode & ap->perm_mask) != 0;
|
||||
/* -perm -mode: all of perm_mask are set */
|
||||
if (ap->perm_char == '-')
|
||||
@@ -606,17 +607,57 @@ ACTF(inum)
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_FIND_EXEC
|
||||
ACTF(exec)
|
||||
static int do_exec(action_exec *ap, const char *fileName)
|
||||
{
|
||||
int i, rc;
|
||||
#if ENABLE_USE_PORTABLE_CODE
|
||||
char **argv = alloca(sizeof(char*) * (ap->exec_argc + 1));
|
||||
#else /* gcc 4.3.1 generates smaller code: */
|
||||
char *argv[ap->exec_argc + 1];
|
||||
#endif
|
||||
for (i = 0; i < ap->exec_argc; i++)
|
||||
argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName);
|
||||
argv[i] = NULL; /* terminate the list */
|
||||
# if ENABLE_FEATURE_FIND_EXEC_PLUS
|
||||
int size = ap->exec_argc + ap->filelist_idx + 1;
|
||||
# else
|
||||
int size = ap->exec_argc + 1;
|
||||
# endif
|
||||
# if ENABLE_USE_PORTABLE_CODE
|
||||
char **argv = alloca(sizeof(char*) * size);
|
||||
# else /* gcc 4.3.1 generates smaller code: */
|
||||
char *argv[size];
|
||||
# endif
|
||||
char **pp = argv;
|
||||
|
||||
for (i = 0; i < ap->exec_argc; i++) {
|
||||
const char *arg = ap->exec_argv[i];
|
||||
|
||||
# if ENABLE_FEATURE_FIND_EXEC_PLUS
|
||||
if (ap->filelist) {
|
||||
/* Handling "-exec +"
|
||||
* Only one exec_argv[i] has substitution in it.
|
||||
* Expand that one exec_argv[i] into file list.
|
||||
*/
|
||||
if (ap->subst_count[i] == 0) {
|
||||
*pp++ = xstrdup(arg);
|
||||
} else {
|
||||
int j = 0;
|
||||
while (ap->filelist[j]) {
|
||||
/* 2nd arg here should be ap->subst_count[i], but it is always 1: */
|
||||
*pp++ = xmalloc_substitute_string(arg, 1, "{}", ap->filelist[j]);
|
||||
free(ap->filelist[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
} else
|
||||
# endif
|
||||
{
|
||||
/* Handling "-exec ;" */
|
||||
*pp++ = xmalloc_substitute_string(arg, ap->subst_count[i], "{}", fileName);
|
||||
}
|
||||
}
|
||||
*pp = NULL; /* terminate the list */
|
||||
|
||||
# if ENABLE_FEATURE_FIND_EXEC_PLUS
|
||||
if (ap->filelist) {
|
||||
ap->filelist[0] = NULL;
|
||||
ap->filelist_idx = 0;
|
||||
ap->file_len = 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
rc = spawn_and_wait(argv);
|
||||
if (rc < 0)
|
||||
@@ -627,6 +668,48 @@ ACTF(exec)
|
||||
free(argv[i++]);
|
||||
return rc == 0; /* return 1 if exitcode 0 */
|
||||
}
|
||||
ACTF(exec)
|
||||
{
|
||||
# if ENABLE_FEATURE_FIND_EXEC_PLUS
|
||||
if (ap->filelist) {
|
||||
int rc;
|
||||
|
||||
ap->filelist = xrealloc_vector(ap->filelist, 8, ap->filelist_idx);
|
||||
ap->filelist[ap->filelist_idx++] = xstrdup(fileName);
|
||||
ap->file_len += strlen(fileName) + sizeof(char*) + 1;
|
||||
/* If we have lots of files already, exec the command */
|
||||
rc = 1;
|
||||
if (ap->file_len >= G.max_argv_len)
|
||||
rc = do_exec(ap, NULL);
|
||||
return rc;
|
||||
}
|
||||
# endif
|
||||
return do_exec(ap, fileName);
|
||||
}
|
||||
# if ENABLE_FEATURE_FIND_EXEC_PLUS
|
||||
static int flush_exec_plus(void)
|
||||
{
|
||||
action *ap;
|
||||
action **app;
|
||||
action ***appp = G.actions;
|
||||
while ((app = *appp++) != NULL) {
|
||||
while ((ap = *app++) != NULL) {
|
||||
if (ap->f == (action_fp)func_exec) {
|
||||
action_exec *ae = (void*)ap;
|
||||
if (ae->filelist_idx != 0) {
|
||||
int rc = do_exec(ae, NULL);
|
||||
# if ENABLE_FEATURE_FIND_NOT
|
||||
if (ap->invert) rc = !rc;
|
||||
# endif
|
||||
if (rc == 0)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
#if ENABLE_FEATURE_FIND_USER
|
||||
ACTF(user)
|
||||
@@ -1067,6 +1150,7 @@ static action*** parse_params(char **argv)
|
||||
else if (parm == PARM_exec) {
|
||||
int i;
|
||||
action_exec *ap;
|
||||
IF_FEATURE_FIND_EXEC_PLUS(int all_subst = 0;)
|
||||
dbg("%d", __LINE__);
|
||||
G.need_print = 0;
|
||||
ap = ALLOC_ACTION(exec);
|
||||
@@ -1079,10 +1163,13 @@ static action*** parse_params(char **argv)
|
||||
// executes "echo Foo >FILENAME<",
|
||||
// find -exec echo Foo ">{}<" "+"
|
||||
// executes "echo Foo FILENAME1 FILENAME2 FILENAME3...".
|
||||
// TODO (so far we treat "+" just like ";")
|
||||
if ((argv[0][0] == ';' || argv[0][0] == '+')
|
||||
&& argv[0][1] == '\0'
|
||||
) {
|
||||
# if ENABLE_FEATURE_FIND_EXEC_PLUS
|
||||
if (argv[0][0] == '+')
|
||||
ap->filelist = xzalloc(sizeof(ap->filelist[0]));
|
||||
# endif
|
||||
break;
|
||||
}
|
||||
argv++;
|
||||
@@ -1092,8 +1179,17 @@ static action*** parse_params(char **argv)
|
||||
bb_error_msg_and_die(bb_msg_requires_arg, arg);
|
||||
ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
|
||||
i = ap->exec_argc;
|
||||
while (i--)
|
||||
ap->subst_count[i] = count_subst(ap->exec_argv[i]);
|
||||
while (i--) {
|
||||
ap->subst_count[i] = count_strstr(ap->exec_argv[i], "{}");
|
||||
IF_FEATURE_FIND_EXEC_PLUS(all_subst += ap->subst_count[i];)
|
||||
}
|
||||
# if ENABLE_FEATURE_FIND_EXEC_PLUS
|
||||
/*
|
||||
* coreutils expects {} to appear only once in "-exec +"
|
||||
*/
|
||||
if (all_subst != 1 && ap->filelist)
|
||||
bb_error_msg_and_die("only one '{}' allowed for -exec +");
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_FIND_PAREN
|
||||
@@ -1156,14 +1252,14 @@ static action*** parse_params(char **argv)
|
||||
/* -perm BITS File's mode bits are exactly BITS (octal or symbolic).
|
||||
* Symbolic modes use mode 0 as a point of departure.
|
||||
* -perm -BITS All of the BITS are set in file's mode.
|
||||
* -perm +BITS At least one of the BITS is set in file's mode.
|
||||
* -perm [+/]BITS At least one of the BITS is set in file's mode.
|
||||
*/
|
||||
else if (parm == PARM_perm) {
|
||||
action_perm *ap;
|
||||
dbg("%d", __LINE__);
|
||||
ap = ALLOC_ACTION(perm);
|
||||
ap->perm_char = arg1[0];
|
||||
arg1 = plus_minus_num(arg1);
|
||||
arg1 = (arg1[0] == '/' ? arg1+1 : plus_minus_num(arg1));
|
||||
/*ap->perm_mask = 0; - ALLOC_ACTION did it */
|
||||
if (!bb_parse_mode(arg1, &ap->perm_mask))
|
||||
bb_error_msg_and_die("invalid mode '%s'", arg1);
|
||||
@@ -1291,9 +1387,27 @@ int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int find_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int i, firstopt, status = EXIT_SUCCESS;
|
||||
char **past_HLP, *saved;
|
||||
|
||||
INIT_G();
|
||||
|
||||
/* "find -type f" + getopt("+HLP") => disaster.
|
||||
* Need to avoid getopt running into a non-HLP option.
|
||||
* Do this by temporarily storing NULL there:
|
||||
*/
|
||||
past_HLP = argv;
|
||||
for (;;) {
|
||||
saved = *++past_HLP;
|
||||
if (!saved)
|
||||
break;
|
||||
if (saved[0] != '-')
|
||||
break;
|
||||
if (!saved[1])
|
||||
break; /* it is "-" */
|
||||
if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
|
||||
break;
|
||||
}
|
||||
*past_HLP = NULL;
|
||||
/* "+": stop on first non-option */
|
||||
i = getopt32(argv, "+HLP");
|
||||
if (i & (1<<0))
|
||||
@@ -1301,7 +1415,8 @@ int find_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (i & (1<<1))
|
||||
G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
|
||||
/* -P is default and is ignored */
|
||||
argv += optind;
|
||||
argv = past_HLP; /* same result as "argv += optind;" */
|
||||
*past_HLP = saved;
|
||||
|
||||
for (firstopt = 0; argv[firstopt]; firstopt++) {
|
||||
if (argv[firstopt][0] == '-')
|
||||
@@ -1346,8 +1461,11 @@ int find_main(int argc UNUSED_PARAM, char **argv)
|
||||
0) /* depth */
|
||||
) {
|
||||
status = EXIT_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
IF_FEATURE_FIND_EXEC_PLUS(status = flush_exec_plus();)
|
||||
out:
|
||||
return status;
|
||||
}
|
||||
+34
-7
@@ -373,6 +373,11 @@ static int grep_file(FILE *file)
|
||||
opt_f_not_found: ;
|
||||
}
|
||||
} else {
|
||||
#if ENABLE_EXTRA_COMPAT
|
||||
unsigned start_pos;
|
||||
#else
|
||||
int match_flg;
|
||||
#endif
|
||||
char *match_at;
|
||||
|
||||
if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
|
||||
@@ -389,15 +394,19 @@ static int grep_file(FILE *file)
|
||||
#if !ENABLE_EXTRA_COMPAT
|
||||
gl->matched_range.rm_so = 0;
|
||||
gl->matched_range.rm_eo = 0;
|
||||
match_flg = 0;
|
||||
#else
|
||||
start_pos = 0;
|
||||
#endif
|
||||
match_at = line;
|
||||
opt_w_again:
|
||||
//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
|
||||
if (
|
||||
#if !ENABLE_EXTRA_COMPAT
|
||||
regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
|
||||
regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, match_flg) == 0
|
||||
#else
|
||||
re_search(&gl->compiled_regex, match_at, line_len,
|
||||
/*start:*/ 0, /*range:*/ line_len,
|
||||
start_pos, /*range:*/ line_len,
|
||||
&gl->matched_range) >= 0
|
||||
#endif
|
||||
) {
|
||||
@@ -409,16 +418,34 @@ static int grep_file(FILE *file)
|
||||
found = 1;
|
||||
} else {
|
||||
char c = ' ';
|
||||
if (gl->matched_range.rm_so)
|
||||
if (match_at > line || gl->matched_range.rm_so != 0) {
|
||||
c = match_at[gl->matched_range.rm_so - 1];
|
||||
}
|
||||
if (!isalnum(c) && c != '_') {
|
||||
c = match_at[gl->matched_range.rm_eo];
|
||||
if (!c || (!isalnum(c) && c != '_')) {
|
||||
found = 1;
|
||||
} else {
|
||||
}
|
||||
if (!isalnum(c) && c != '_') {
|
||||
found = 1;
|
||||
} else {
|
||||
/*
|
||||
* Why check gl->matched_range.rm_eo?
|
||||
* Zero-length match makes -w skip the line:
|
||||
* "echo foo | grep ^" prints "foo",
|
||||
* "echo foo | grep -w ^" prints nothing.
|
||||
* Without such check, we can loop forever.
|
||||
*/
|
||||
#if !ENABLE_EXTRA_COMPAT
|
||||
if (gl->matched_range.rm_eo != 0) {
|
||||
match_at += gl->matched_range.rm_eo;
|
||||
match_flg |= REG_NOTBOL;
|
||||
goto opt_w_again;
|
||||
}
|
||||
#else
|
||||
if (gl->matched_range.rm_eo > start_pos) {
|
||||
start_pos = gl->matched_range.rm_eo;
|
||||
goto opt_w_again;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -641,7 +668,7 @@ static int grep_dir(const char *dir)
|
||||
int matched = 0;
|
||||
recursive_action(dir,
|
||||
/* recurse=yes */ ACTION_RECURSE |
|
||||
/* followLinks=no */
|
||||
/* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
|
||||
/* depthFirst=yes */ ACTION_DEPTHFIRST,
|
||||
/* fileAction= */ file_action_grep,
|
||||
/* dirAction= */ NULL,
|
||||
|
||||
+137
-42
@@ -53,6 +53,13 @@
|
||||
//config: Support -0: input items are terminated by a NUL character
|
||||
//config: instead of whitespace, and the quotes and backslash
|
||||
//config: are not special.
|
||||
//config:
|
||||
//config:config FEATURE_XARGS_SUPPORT_REPL_STR
|
||||
//config: bool "Enable -I STR: string to replace"
|
||||
//config: default y
|
||||
//config: depends on XARGS
|
||||
//config: help
|
||||
//config: Support -I STR and -i[STR] options.
|
||||
|
||||
//applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, BB_DIR_USR_BIN, BB_SUID_DROP, xargs))
|
||||
|
||||
@@ -85,19 +92,22 @@
|
||||
|
||||
struct globals {
|
||||
char **args;
|
||||
#if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
|
||||
char **argv;
|
||||
const char *repl_str;
|
||||
char eol_ch;
|
||||
#endif
|
||||
const char *eof_str;
|
||||
int idx;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \
|
||||
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \
|
||||
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
* This function has special algorithm.
|
||||
* Don't use fork and include to main!
|
||||
*/
|
||||
static int xargs_exec(void)
|
||||
{
|
||||
int status;
|
||||
@@ -301,7 +311,7 @@ static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf)
|
||||
c = '\0';
|
||||
}
|
||||
*p++ = c;
|
||||
if (c == '\0') { /* word's delimiter or EOF detected */
|
||||
if (c == '\0') { /* NUL or EOF detected */
|
||||
/* A full word is loaded */
|
||||
store_param(s);
|
||||
dbg_msg("args[]:'%s'", s);
|
||||
@@ -323,10 +333,71 @@ static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf)
|
||||
}
|
||||
#endif /* FEATURE_XARGS_SUPPORT_ZERO_TERM */
|
||||
|
||||
#if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
|
||||
/*
|
||||
* Used if -I<repl> was specified.
|
||||
* In this mode, words aren't appended to PROG ARGS.
|
||||
* Instead, entire input line is read, then <repl> string
|
||||
* in every PROG and ARG is replaced with the line:
|
||||
* echo -e "ho ho\nhi" | xargs -I_ cmd __ _
|
||||
* results in "cmd 'ho hoho ho' 'ho ho'"; "cmd 'hihi' 'hi'".
|
||||
* -n MAX_ARGS seems to be ignored.
|
||||
* Tested with GNU findutils 4.5.10.
|
||||
*/
|
||||
//FIXME: n_max_chars is not handled the same way as in GNU findutils.
|
||||
//FIXME: quoting is not implemented.
|
||||
static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg UNUSED_PARAM, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *end, *p;
|
||||
|
||||
/* Free strings from last invocation, if any */
|
||||
for (i = 0; G.args && G.args[i]; i++)
|
||||
if (G.args[i] != G.argv[i])
|
||||
free(G.args[i]);
|
||||
|
||||
end = buf + n_max_chars;
|
||||
p = buf;
|
||||
|
||||
while (1) {
|
||||
int c = getchar();
|
||||
if (c == EOF || c == G.eol_ch) {
|
||||
if (p == buf)
|
||||
goto ret; /* empty line */
|
||||
c = '\0';
|
||||
}
|
||||
*p++ = c;
|
||||
if (c == '\0') { /* EOL or EOF detected */
|
||||
i = 0;
|
||||
while (G.argv[i]) {
|
||||
char *arg = G.argv[i];
|
||||
int count = count_strstr(arg, G.repl_str);
|
||||
if (count != 0)
|
||||
arg = xmalloc_substitute_string(arg, count, G.repl_str, buf);
|
||||
store_param(arg);
|
||||
dbg_msg("args[]:'%s'", arg);
|
||||
i++;
|
||||
}
|
||||
p = buf;
|
||||
goto ret;
|
||||
}
|
||||
if (p == end) {
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
ret:
|
||||
*p = '\0';
|
||||
/* store_param(NULL) - caller will do it */
|
||||
dbg_msg("return:'%s'", buf);
|
||||
return buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION
|
||||
/* Prompt the user for a response, and
|
||||
if the user responds affirmatively, return true;
|
||||
otherwise, return false. Uses "/dev/tty", not stdin. */
|
||||
* if user responds affirmatively, return true;
|
||||
* otherwise, return false. Uses "/dev/tty", not stdin.
|
||||
*/
|
||||
static int xargs_ask_confirmation(void)
|
||||
{
|
||||
FILE *tty_stream;
|
||||
@@ -360,6 +431,9 @@ static int xargs_ask_confirmation(void)
|
||||
//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: IF_FEATURE_XARGS_SUPPORT_TERMOPT(
|
||||
//usage: "\n -x Exit if size is exceeded"
|
||||
//usage: )
|
||||
@@ -378,6 +452,8 @@ enum {
|
||||
IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(OPTBIT_INTERACTIVE,)
|
||||
IF_FEATURE_XARGS_SUPPORT_TERMOPT( OPTBIT_TERMINATE ,)
|
||||
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( OPTBIT_ZEROTERM ,)
|
||||
IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR ,)
|
||||
IF_FEATURE_XARGS_SUPPORT_REPL_STR( OPTBIT_REPLSTR1 ,)
|
||||
|
||||
OPT_VERBOSE = 1 << OPTBIT_VERBOSE ,
|
||||
OPT_NO_EMPTY = 1 << OPTBIT_NO_EMPTY ,
|
||||
@@ -388,11 +464,14 @@ enum {
|
||||
OPT_INTERACTIVE = IF_FEATURE_XARGS_SUPPORT_CONFIRMATION((1 << OPTBIT_INTERACTIVE)) + 0,
|
||||
OPT_TERMINATE = IF_FEATURE_XARGS_SUPPORT_TERMOPT( (1 << OPTBIT_TERMINATE )) + 0,
|
||||
OPT_ZEROTERM = IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( (1 << OPTBIT_ZEROTERM )) + 0,
|
||||
OPT_REPLSTR = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR )) + 0,
|
||||
OPT_REPLSTR1 = IF_FEATURE_XARGS_SUPPORT_REPL_STR( (1 << OPTBIT_REPLSTR1 )) + 0,
|
||||
};
|
||||
#define OPTION_STR "+trn:s:e::E:" \
|
||||
IF_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \
|
||||
IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \
|
||||
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0")
|
||||
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") \
|
||||
IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::")
|
||||
|
||||
int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int xargs_main(int argc, char **argv)
|
||||
@@ -405,7 +484,8 @@ int xargs_main(int argc, char **argv)
|
||||
unsigned opt;
|
||||
int n_max_chars;
|
||||
int n_max_arg;
|
||||
#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
|
||||
#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM \
|
||||
|| ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
|
||||
char* FAST_FUNC (*read_args)(int, int, char*) = process_stdin;
|
||||
#else
|
||||
#define read_args process_stdin
|
||||
@@ -419,7 +499,10 @@ int xargs_main(int argc, char **argv)
|
||||
"no-run-if-empty\0" No_argument "r"
|
||||
;
|
||||
#endif
|
||||
opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &G.eof_str, &G.eof_str);
|
||||
opt = getopt32(argv, OPTION_STR,
|
||||
&max_args, &max_chars, &G.eof_str, &G.eof_str
|
||||
IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str)
|
||||
);
|
||||
|
||||
/* -E ""? You may wonder why not just omit -E?
|
||||
* This is used for portability:
|
||||
@@ -427,8 +510,10 @@ int xargs_main(int argc, char **argv)
|
||||
if ((opt & OPT_EOF_STRING1) && G.eof_str[0] == '\0')
|
||||
G.eof_str = NULL;
|
||||
|
||||
if (opt & OPT_ZEROTERM)
|
||||
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin);
|
||||
if (opt & OPT_ZEROTERM) {
|
||||
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin;)
|
||||
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\0';)
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
@@ -438,12 +523,7 @@ int xargs_main(int argc, char **argv)
|
||||
argc++;
|
||||
}
|
||||
|
||||
/* -s NUM default. fileutils-4.4.2 uses 128k, but I heasitate
|
||||
* to use such a big value - first need to change code to use
|
||||
* growable buffer instead of fixed one.
|
||||
*/
|
||||
n_max_chars = 32 * 1024;
|
||||
/* Make smaller if system does not allow our default value.
|
||||
/*
|
||||
* The Open Group Base Specifications Issue 6:
|
||||
* "The xargs utility shall limit the command line length such that
|
||||
* when the command line is invoked, the combined argument
|
||||
@@ -451,16 +531,15 @@ int xargs_main(int argc, char **argv)
|
||||
* in the System Interfaces volume of IEEE Std 1003.1-2001)
|
||||
* shall not exceed {ARG_MAX}-2048 bytes".
|
||||
*/
|
||||
{
|
||||
long arg_max = 0;
|
||||
#if defined _SC_ARG_MAX
|
||||
arg_max = sysconf(_SC_ARG_MAX) - 2048;
|
||||
#elif defined ARG_MAX
|
||||
arg_max = ARG_MAX - 2048;
|
||||
#endif
|
||||
if (arg_max > 0 && n_max_chars > arg_max)
|
||||
n_max_chars = arg_max;
|
||||
}
|
||||
n_max_chars = bb_arg_max();
|
||||
if (n_max_chars > 32 * 1024)
|
||||
n_max_chars = 32 * 1024;
|
||||
/*
|
||||
* POSIX suggests substracting 2048 bytes from sysconf(_SC_ARG_MAX)
|
||||
* so that the process may safely modify its environment.
|
||||
*/
|
||||
n_max_chars -= 2048;
|
||||
|
||||
if (opt & OPT_UPTO_SIZE) {
|
||||
n_max_chars = xatou_range(max_chars, 1, INT_MAX);
|
||||
}
|
||||
@@ -486,20 +565,36 @@ int xargs_main(int argc, char **argv)
|
||||
/* if (n_max_arg > n_max_chars) n_max_arg = n_max_chars */
|
||||
}
|
||||
|
||||
/* Allocate pointers for execvp */
|
||||
/* We can statically allocate (argc + n_max_arg + 1) elements
|
||||
* and do not bother with resizing args[], but on 64-bit machines
|
||||
* this results in args[] vector which is ~8 times bigger
|
||||
* than n_max_chars! That is, with n_max_chars == 20k,
|
||||
* args[] will take 160k (!), which will most likely be
|
||||
* almost entirely unused.
|
||||
*/
|
||||
/* See store_param() for matching 256-step growth logic */
|
||||
G.args = xmalloc(sizeof(G.args[0]) * ((argc + 0xff) & ~0xff));
|
||||
|
||||
/* Store the command to be executed, part 1 */
|
||||
for (i = 0; argv[i]; i++)
|
||||
G.args[i] = argv[i];
|
||||
#if ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
|
||||
if (opt & (OPT_REPLSTR | OPT_REPLSTR1)) {
|
||||
/*
|
||||
* -I<str>:
|
||||
* Unmodified args are kept in G.argv[i],
|
||||
* G.args[i] receives malloced G.argv[i] with <str> replaced
|
||||
* with input line. Setting this up:
|
||||
*/
|
||||
G.args = NULL;
|
||||
G.argv = argv;
|
||||
argc = 0;
|
||||
read_args = process_stdin_with_replace;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* Allocate pointers for execvp.
|
||||
* We can statically allocate (argc + n_max_arg + 1) elements
|
||||
* and do not bother with resizing args[], but on 64-bit machines
|
||||
* this results in args[] vector which is ~8 times bigger
|
||||
* than n_max_chars! That is, with n_max_chars == 20k,
|
||||
* args[] will take 160k (!), which will most likely be
|
||||
* almost entirely unused.
|
||||
*
|
||||
* See store_param() for matching 256-step growth logic
|
||||
*/
|
||||
G.args = xmalloc(sizeof(G.args[0]) * ((argc + 0xff) & ~0xff));
|
||||
/* Store the command to be executed, part 1 */
|
||||
for (i = 0; argv[i]; i++)
|
||||
G.args[i] = argv[i];
|
||||
}
|
||||
|
||||
while (1) {
|
||||
char *rem;
|
||||
|
||||
+25
-27
@@ -8,7 +8,7 @@
|
||||
|
||||
/*
|
||||
name - applet name as it is typed on command line
|
||||
name2 - applet name, converted to C (ether-wake: name2 = ether_wake)
|
||||
help - applet name, converted to C (ether-wake: help = ether_wake)
|
||||
main - corresponding <applet>_main to call (bzcat: main = bunzip2)
|
||||
l - location to install link to: [/usr]/[s]bin
|
||||
s - suid type:
|
||||
@@ -24,46 +24,46 @@ s - suid type:
|
||||
|
||||
#if defined(PROTOTYPES)
|
||||
# define APPLET(name,l,s) int name##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
# define APPLET_ODDNAME(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
# define APPLET_NOEXEC(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
# define APPLET_NOFORK(name,main,l,s,help) int main##_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
|
||||
#elif defined(NAME_MAIN_CNAME)
|
||||
# define APPLET(name,l,s) name name##_main name
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) name main##_main name2
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) name main##_main name2
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) name main##_main name2
|
||||
#elif defined(NAME_MAIN)
|
||||
# define APPLET(name,l,s) name name##_main
|
||||
# define APPLET_ODDNAME(name,main,l,s,help) name main##_main
|
||||
# define APPLET_NOEXEC(name,main,l,s,help) name main##_main
|
||||
# define APPLET_NOFORK(name,main,l,s,help) name main##_main
|
||||
|
||||
#elif defined(MAKE_USAGE) && ENABLE_FEATURE_VERBOSE_USAGE
|
||||
# define APPLET(name,l,s) MAKE_USAGE(#name, name##_trivial_usage name##_full_usage)
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage)
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage)
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage name2##_full_usage)
|
||||
# define APPLET_ODDNAME(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
|
||||
# define APPLET_NOEXEC(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
|
||||
# define APPLET_NOFORK(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage help##_full_usage)
|
||||
|
||||
#elif defined(MAKE_USAGE) && !ENABLE_FEATURE_VERBOSE_USAGE
|
||||
# define APPLET(name,l,s) MAKE_USAGE(#name, name##_trivial_usage)
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage)
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage)
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) MAKE_USAGE(#name, name2##_trivial_usage)
|
||||
# define APPLET_ODDNAME(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
|
||||
# define APPLET_NOEXEC(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
|
||||
# define APPLET_NOFORK(name,main,l,s,help) MAKE_USAGE(#name, help##_trivial_usage)
|
||||
|
||||
#elif defined(MAKE_LINKS)
|
||||
# define APPLET(name,l,c) LINK l name
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) LINK l name
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) LINK l name
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) LINK l name
|
||||
# define APPLET_ODDNAME(name,main,l,s,help) LINK l name
|
||||
# define APPLET_NOEXEC(name,main,l,s,help) LINK l name
|
||||
# define APPLET_NOFORK(name,main,l,s,help) LINK l name
|
||||
|
||||
#elif defined(MAKE_SUID)
|
||||
# define APPLET(name,l,s) SUID s l name
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) SUID s l name
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) SUID s l name
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) SUID s l name
|
||||
# define APPLET_ODDNAME(name,main,l,s,help) SUID s l name
|
||||
# define APPLET_NOEXEC(name,main,l,s,help) SUID s l name
|
||||
# define APPLET_NOFORK(name,main,l,s,help) SUID s l name
|
||||
|
||||
#else
|
||||
static struct bb_applet applets[] = { /* name, main, location, need_suid */
|
||||
# define APPLET(name,l,s) { #name, #name, l, s },
|
||||
# define APPLET_ODDNAME(name,main,l,s,name2) { #name, #main, l, s },
|
||||
# define APPLET_NOEXEC(name,main,l,s,name2) { #name, #main, l, s, 1 },
|
||||
# define APPLET_NOFORK(name,main,l,s,name2) { #name, #main, l, s, 1, 1 },
|
||||
# define APPLET_ODDNAME(name,main,l,s,help) { #name, #main, l, s },
|
||||
# define APPLET_NOEXEC(name,main,l,s,help) { #name, #main, l, s, 1 },
|
||||
# define APPLET_NOFORK(name,main,l,s,help) { #name, #main, l, s, 1, 1 },
|
||||
#endif
|
||||
|
||||
#if ENABLE_INSTALL_NO_USR
|
||||
@@ -104,7 +104,6 @@ IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
|
||||
IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
|
||||
IF_CROND(APPLET(crond, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
/* Needs to be run by root or be suid root - needs to change /var/spool/cron* files: */
|
||||
IF_CRONTAB(APPLET(crontab, BB_DIR_USR_BIN, BB_SUID_REQUIRE))
|
||||
IF_CRYPTPW(APPLET(cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
@@ -343,7 +342,6 @@ IF_BB_SYSCTL(APPLET(sysctl, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
IF_TAC(APPLET_NOEXEC(tac, tac, BB_DIR_USR_BIN, BB_SUID_DROP, tac))
|
||||
IF_TAIL(APPLET(tail, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
IF_TASKSET(APPLET(taskset, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
/* IF_TC(APPLET(tc, BB_DIR_SBIN, BB_SUID_DROP)) */
|
||||
IF_TCPSVD(APPLET_ODDNAME(tcpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, tcpsvd))
|
||||
IF_TEE(APPLET(tee, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
@@ -391,7 +389,7 @@ IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami))
|
||||
IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
|
||||
IF_ZCIP(APPLET(zcip, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
|
||||
#if !defined(PROTOTYPES) && !defined(NAME_MAIN_CNAME) && !defined(MAKE_USAGE) \
|
||||
#if !defined(PROTOTYPES) && !defined(NAME_MAIN) && !defined(MAKE_USAGE) \
|
||||
&& !defined(MAKE_LINKS) && !defined(MAKE_SUID)
|
||||
};
|
||||
#endif
|
||||
|
||||
+32
-18
@@ -203,43 +203,57 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len) FAST_FUNC;
|
||||
void dealloc_bunzip(bunzip_data *bd) FAST_FUNC;
|
||||
|
||||
/* Meaning and direction (input/output) of the fields are transformer-specific */
|
||||
typedef struct transformer_aux_data_t {
|
||||
typedef struct transformer_state_t {
|
||||
smallint check_signature; /* most often referenced member */
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*xformer)(struct transformer_state_t *xstate);
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
|
||||
/* Source */
|
||||
int src_fd;
|
||||
/* Output */
|
||||
int dst_fd;
|
||||
size_t mem_output_size_max; /* if non-zero, decompress to RAM instead of fd */
|
||||
size_t mem_output_size;
|
||||
char *mem_output_buf;
|
||||
|
||||
off_t bytes_out;
|
||||
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 */
|
||||
} transformer_aux_data_t;
|
||||
} transformer_state_t;
|
||||
|
||||
void init_transformer_aux_data(transformer_aux_data_t *aux) FAST_FUNC;
|
||||
int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16) FAST_FUNC;
|
||||
void init_transformer_state(transformer_state_t *xstate) FAST_FUNC;
|
||||
ssize_t transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize) FAST_FUNC;
|
||||
ssize_t xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize) FAST_FUNC;
|
||||
int check_signature16(transformer_state_t *xstate, unsigned magic16) FAST_FUNC;
|
||||
|
||||
IF_DESKTOP(long long) int inflate_unzip(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_lzma_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int inflate_unzip(transformer_state_t *xstate) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_Z_stream(transformer_state_t *xstate) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_gz_stream(transformer_state_t *xstate) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_bz2_stream(transformer_state_t *xstate) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_lzma_stream(transformer_state_t *xstate) FAST_FUNC;
|
||||
IF_DESKTOP(long long) int unpack_xz_stream(transformer_state_t *xstate) FAST_FUNC;
|
||||
|
||||
char* append_ext(char *filename, const char *expected_ext) FAST_FUNC;
|
||||
int bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
|
||||
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
|
||||
const char *expected_ext
|
||||
) FAST_FUNC;
|
||||
|
||||
void check_errors_in_children(int signo);
|
||||
#if BB_MMU
|
||||
void open_transformer(int fd,
|
||||
void fork_transformer(int fd,
|
||||
int check_signature,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
|
||||
) FAST_FUNC;
|
||||
#define open_transformer_with_sig(fd, transformer, transform_prog) open_transformer((fd), 1, (transformer))
|
||||
#define open_transformer_with_no_sig(fd, transformer) open_transformer((fd), 0, (transformer))
|
||||
#define fork_transformer_with_sig(fd, transformer, transform_prog) fork_transformer((fd), 1, (transformer))
|
||||
#define fork_transformer_with_no_sig(fd, transformer) fork_transformer((fd), 0, (transformer))
|
||||
#else
|
||||
void open_transformer(int fd, const char *transform_prog) FAST_FUNC;
|
||||
#define open_transformer_with_sig(fd, transformer, transform_prog) open_transformer((fd), (transform_prog))
|
||||
/* open_transformer_with_no_sig() does not exist on NOMMU */
|
||||
void fork_transformer(int fd, const char *transform_prog) FAST_FUNC;
|
||||
#define fork_transformer_with_sig(fd, transformer, transform_prog) fork_transformer((fd), (transform_prog))
|
||||
/* fork_transformer_with_no_sig() does not exist on NOMMU */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
+166
-9
@@ -334,6 +334,8 @@ enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */
|
||||
FILEUTILS_SET_SECURITY_CONTEXT = 1 << 10,
|
||||
#endif
|
||||
FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
|
||||
/* -v */
|
||||
FILEUTILS_VERBOSE = (1 << 12) * ENABLE_FEATURE_VERBOSE,
|
||||
};
|
||||
#define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
|
||||
extern int remove_file(const char *path, int flags) FAST_FUNC;
|
||||
@@ -388,8 +390,8 @@ const char *bb_basename(const char *name) FAST_FUNC;
|
||||
char *last_char_is(const char *s, int c) FAST_FUNC;
|
||||
const char* endofname(const char *name) FAST_FUNC;
|
||||
|
||||
void ndelay_on(int fd) FAST_FUNC;
|
||||
void ndelay_off(int fd) FAST_FUNC;
|
||||
int ndelay_on(int fd) FAST_FUNC;
|
||||
int ndelay_off(int fd) FAST_FUNC;
|
||||
void close_on_exec_on(int fd) FAST_FUNC;
|
||||
void xdup2(int, int) FAST_FUNC;
|
||||
void xmove_fd(int, int) FAST_FUNC;
|
||||
@@ -650,6 +652,8 @@ char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
|
||||
void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
|
||||
char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
|
||||
char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
|
||||
unsigned count_strstr(const char *str, const char *sub) FAST_FUNC;
|
||||
char *xmalloc_substitute_string(const char *src, int count, const char *sub, const char *repl) FAST_FUNC;
|
||||
/* Guaranteed to NOT be a macro (smallest code). Saves nearly 2k on uclibc.
|
||||
* But potentially slow, don't use in one-billion-times loops */
|
||||
int bb_putchar(int ch) FAST_FUNC;
|
||||
@@ -727,6 +731,18 @@ extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST
|
||||
/* Never returns NULL */
|
||||
extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
|
||||
|
||||
#if defined(ARG_MAX) && (ARG_MAX >= 60*1024 || !defined(_SC_ARG_MAX))
|
||||
/* Use _constant_ maximum if: defined && (big enough || no variable one exists) */
|
||||
# define bb_arg_max() ((unsigned)ARG_MAX)
|
||||
#elif defined(_SC_ARG_MAX)
|
||||
/* Else use variable one (a bit more expensive) */
|
||||
unsigned bb_arg_max(void) FAST_FUNC;
|
||||
#else
|
||||
/* If all else fails */
|
||||
# define bb_arg_max() ((unsigned)(32 * 1024))
|
||||
#endif
|
||||
unsigned bb_clk_tck(void) FAST_FUNC;
|
||||
|
||||
#define SEAMLESS_COMPRESSION (0 \
|
||||
|| ENABLE_FEATURE_SEAMLESS_XZ \
|
||||
|| ENABLE_FEATURE_SEAMLESS_LZMA \
|
||||
@@ -736,14 +752,15 @@ extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAS
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
/* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */
|
||||
extern int setup_unzip_on_fd(int fd, int fail_if_not_detected) FAST_FUNC;
|
||||
extern int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC;
|
||||
/* Autodetects .gz etc */
|
||||
extern int open_zipped(const char *fname) FAST_FUNC;
|
||||
extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC;
|
||||
extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
|
||||
#else
|
||||
# define setup_unzip_on_fd(...) (0)
|
||||
# define open_zipped(fname) open((fname), O_RDONLY);
|
||||
# define open_zipped(fname, fail_if_not_compressed) open((fname), O_RDONLY);
|
||||
# define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p))
|
||||
#endif
|
||||
extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
|
||||
|
||||
extern ssize_t safe_write(int fd, const void *buf, size_t count) FAST_FUNC;
|
||||
// NB: will return short write on error, not -1,
|
||||
@@ -910,9 +927,9 @@ void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const
|
||||
#endif
|
||||
|
||||
|
||||
int execable_file(const char *name) FAST_FUNC;
|
||||
char *find_execable(const char *filename, char **PATHp) FAST_FUNC;
|
||||
int exists_execable(const char *filename) FAST_FUNC;
|
||||
int file_is_executable(const char *name) FAST_FUNC;
|
||||
char *find_executable(const char *filename, char **PATHp) FAST_FUNC;
|
||||
int executable_exists(const char *filename) FAST_FUNC;
|
||||
|
||||
/* BB_EXECxx always execs (it's not doing NOFORK/NOEXEC stuff),
|
||||
* but it may exec busybox and call applet instead of searching PATH.
|
||||
@@ -1072,6 +1089,7 @@ enum {
|
||||
LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
|
||||
};
|
||||
extern const char *msg_eol;
|
||||
extern smallint syslog_level;
|
||||
extern smallint logmode;
|
||||
extern int die_sleep;
|
||||
extern uint8_t xfunc_error_retval;
|
||||
@@ -1090,6 +1108,7 @@ extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
|
||||
extern void bb_perror_nomsg(void) FAST_FUNC;
|
||||
extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
|
||||
extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
|
||||
extern void bb_logenv_override(void) FAST_FUNC;
|
||||
|
||||
/* We need to export XXX_main from libbusybox
|
||||
* only if we build "individual" binaries
|
||||
@@ -1252,7 +1271,9 @@ char *bb_simplify_path(const char *path) FAST_FUNC;
|
||||
/* Returns ptr to NUL */
|
||||
char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
|
||||
|
||||
#ifndef LOGIN_FAIL_DELAY
|
||||
#define LOGIN_FAIL_DELAY 3
|
||||
#endif
|
||||
extern void bb_do_delay(int seconds) FAST_FUNC;
|
||||
extern void change_identity(const struct passwd *pw) FAST_FUNC;
|
||||
extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) NORETURN FAST_FUNC;
|
||||
@@ -1302,6 +1323,7 @@ int sd_listen_fds(void);
|
||||
#define SETUP_ENV_NO_CHDIR (1 << 4)
|
||||
void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
|
||||
void nuke_str(char *str) FAST_FUNC;
|
||||
int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC;
|
||||
int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
|
||||
int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
|
||||
/* Returns a malloced string */
|
||||
@@ -1927,6 +1949,141 @@ static ALWAYS_INLINE unsigned char bb_ascii_tolower(unsigned char a)
|
||||
#define isprint_asciionly(a) ((unsigned)((a) - 0x20) <= 0x7e - 0x20)
|
||||
|
||||
|
||||
/* Simple unit-testing framework */
|
||||
|
||||
typedef void (*bbunit_testfunc)(void);
|
||||
|
||||
struct bbunit_listelem {
|
||||
struct bbunit_listelem* next;
|
||||
const char* name;
|
||||
bbunit_testfunc testfunc;
|
||||
};
|
||||
|
||||
void bbunit_registertest(struct bbunit_listelem* test);
|
||||
void bbunit_settestfailed(void);
|
||||
|
||||
#define BBUNIT_DEFINE_TEST(NAME) \
|
||||
static void bbunit_##NAME##_test(void); \
|
||||
static struct bbunit_listelem bbunit_##NAME##_elem = { \
|
||||
.name = #NAME, \
|
||||
.testfunc = bbunit_##NAME##_test, \
|
||||
}; \
|
||||
static void INIT_FUNC bbunit_##NAME##_register(void) \
|
||||
{ \
|
||||
bbunit_registertest(&bbunit_##NAME##_elem); \
|
||||
} \
|
||||
static void bbunit_##NAME##_test(void)
|
||||
|
||||
/*
|
||||
* Both 'goto bbunit_end' and 'break' are here only to get rid
|
||||
* of compiler warnings.
|
||||
*/
|
||||
#define BBUNIT_ENDTEST \
|
||||
do { \
|
||||
goto bbunit_end; \
|
||||
bbunit_end: \
|
||||
break; \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_PRINTASSERTFAIL \
|
||||
do { \
|
||||
bb_error_msg( \
|
||||
"[ERROR] Assertion failed in file %s, line %d", \
|
||||
__FILE__, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_ASSERTION_FAILED \
|
||||
do { \
|
||||
bbunit_settestfailed(); \
|
||||
goto bbunit_end; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Assertions.
|
||||
* For now we only offer assertions which cause tests to fail
|
||||
* immediately. In the future 'expects' might be added too -
|
||||
* similar to those offered by the gtest framework.
|
||||
*/
|
||||
#define BBUNIT_ASSERT_EQ(EXPECTED, ACTUAL) \
|
||||
do { \
|
||||
if ((EXPECTED) != (ACTUAL)) { \
|
||||
BBUNIT_PRINTASSERTFAIL; \
|
||||
bb_error_msg("[ERROR] '%s' isn't equal to '%s'", \
|
||||
#EXPECTED, #ACTUAL); \
|
||||
BBUNIT_ASSERTION_FAILED; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_ASSERT_NOTEQ(EXPECTED, ACTUAL) \
|
||||
do { \
|
||||
if ((EXPECTED) == (ACTUAL)) { \
|
||||
BBUNIT_PRINTASSERTFAIL; \
|
||||
bb_error_msg("[ERROR] '%s' is equal to '%s'", \
|
||||
#EXPECTED, #ACTUAL); \
|
||||
BBUNIT_ASSERTION_FAILED; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_ASSERT_NOTNULL(PTR) \
|
||||
do { \
|
||||
if ((PTR) == NULL) { \
|
||||
BBUNIT_PRINTASSERTFAIL; \
|
||||
bb_error_msg("[ERROR] '%s' is NULL!", #PTR); \
|
||||
BBUNIT_ASSERTION_FAILED; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_ASSERT_NULL(PTR) \
|
||||
do { \
|
||||
if ((PTR) != NULL) { \
|
||||
BBUNIT_PRINTASSERTFAIL; \
|
||||
bb_error_msg("[ERROR] '%s' is not NULL!", #PTR); \
|
||||
BBUNIT_ASSERTION_FAILED; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_ASSERT_FALSE(STATEMENT) \
|
||||
do { \
|
||||
if ((STATEMENT)) { \
|
||||
BBUNIT_PRINTASSERTFAIL; \
|
||||
bb_error_msg("[ERROR] Statement '%s' evaluated to true!", \
|
||||
#STATEMENT); \
|
||||
BBUNIT_ASSERTION_FAILED; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_ASSERT_TRUE(STATEMENT) \
|
||||
do { \
|
||||
if (!(STATEMENT)) { \
|
||||
BBUNIT_PRINTASSERTFAIL; \
|
||||
bb_error_msg("[ERROR] Statement '%s' evaluated to false!", \
|
||||
#STATEMENT); \
|
||||
BBUNIT_ASSERTION_FAILED; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_ASSERT_STREQ(STR1, STR2) \
|
||||
do { \
|
||||
if (strcmp(STR1, STR2) != 0) { \
|
||||
BBUNIT_PRINTASSERTFAIL; \
|
||||
bb_error_msg("[ERROR] Strings '%s' and '%s' " \
|
||||
"are not the same", STR1, STR2); \
|
||||
BBUNIT_ASSERTION_FAILED; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BBUNIT_ASSERT_STRNOTEQ(STR1, STR2) \
|
||||
do { \
|
||||
if (strcmp(STR1, STR2) == 0) { \
|
||||
BBUNIT_PRINTASSERTFAIL; \
|
||||
bb_error_msg("[ERROR] Strings '%s' and '%s' " \
|
||||
"are the same, but were " \
|
||||
"expected to differ", STR1, STR2); \
|
||||
BBUNIT_ASSERTION_FAILED; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
POP_SAVED_FUNCTION_VISIBILITY
|
||||
|
||||
#endif
|
||||
+39
-8
@@ -76,6 +76,9 @@
|
||||
# define UNUSED_PARAM_RESULT
|
||||
#endif
|
||||
|
||||
/* used by unit test machinery to run registration functions before calling main() */
|
||||
#define INIT_FUNC __attribute__ ((constructor))
|
||||
|
||||
/* -fwhole-program makes all symbols local. The attribute externally_visible
|
||||
* forces a symbol global. */
|
||||
#if __GNUC_PREREQ(4,1)
|
||||
@@ -373,6 +376,7 @@ typedef unsigned smalluint;
|
||||
#define HAVE_STRSIGNAL 1
|
||||
#define HAVE_STRVERSCMP 1
|
||||
#define HAVE_VASPRINTF 1
|
||||
#define HAVE_USLEEP 1
|
||||
#define HAVE_UNLOCKED_STDIO 1
|
||||
#define HAVE_UNLOCKED_LINE_OPS 1
|
||||
#define HAVE_GETLINE 1
|
||||
@@ -381,12 +385,15 @@ typedef unsigned smalluint;
|
||||
#define HAVE_NET_ETHERNET_H 1
|
||||
#define HAVE_SYS_STATFS_H 1
|
||||
|
||||
#if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
|
||||
# undef HAVE_STRVERSCMP
|
||||
#endif
|
||||
|
||||
#if defined(__dietlibc__)
|
||||
# undef HAVE_STRCHRNUL
|
||||
#if defined(__UCLIBC__)
|
||||
# if UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
|
||||
# undef HAVE_STRVERSCMP
|
||||
# endif
|
||||
# if UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
|
||||
# ifndef __UCLIBC_SUSV3_LEGACY__
|
||||
# undef HAVE_USLEEP
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__WATCOMC__)
|
||||
@@ -419,7 +426,7 @@ typedef unsigned smalluint;
|
||||
/* These BSD-derived OSes share many similarities */
|
||||
#if (defined __digital__ && defined __unix__) \
|
||||
|| defined __APPLE__ \
|
||||
|| defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
|
||||
|| defined __OpenBSD__ || defined __NetBSD__
|
||||
# undef HAVE_CLEARENV
|
||||
# undef HAVE_FDATASYNC
|
||||
# undef HAVE_GETLINE
|
||||
@@ -434,10 +441,30 @@ typedef unsigned smalluint;
|
||||
# undef HAVE_UNLOCKED_LINE_OPS
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__APPLE__)
|
||||
#if defined(__dietlibc__)
|
||||
# undef HAVE_STRCHRNUL
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# undef HAVE_STRCHRNUL
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
# undef HAVE_CLEARENV
|
||||
# undef HAVE_FDATASYNC
|
||||
# undef HAVE_MNTENT_H
|
||||
# undef HAVE_PTSNAME_R
|
||||
# undef HAVE_SYS_STATFS_H
|
||||
# undef HAVE_SIGHANDLER_T
|
||||
# undef HAVE_STRVERSCMP
|
||||
# undef HAVE_XTABS
|
||||
# undef HAVE_UNLOCKED_LINE_OPS
|
||||
# include <osreldate.h>
|
||||
# if __FreeBSD_version < 1000029
|
||||
# undef HAVE_STRCHRNUL /* FreeBSD added strchrnul() between 1000028 and 1000029 */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
# define HAVE_GETLINE 1 /* Recent NetBSD versions have getline() */
|
||||
#endif
|
||||
@@ -503,6 +530,10 @@ extern char *strsep(char **stringp, const char *delim) FAST_FUNC;
|
||||
# define strsignal(sig) get_signame(sig)
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_USLEEP
|
||||
extern int usleep(unsigned) FAST_FUNC;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VASPRINTF
|
||||
extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
|
||||
#endif
|
||||
|
||||
+30
-18
@@ -822,7 +822,7 @@ static void halt_reboot_pwoff(int sig)
|
||||
|
||||
/* Handler for QUIT - exec "restart" action,
|
||||
* else (no such action defined) do nothing */
|
||||
static void restart_handler(int sig UNUSED_PARAM)
|
||||
static void exec_restart_action(void)
|
||||
{
|
||||
struct init_action *a;
|
||||
|
||||
@@ -975,6 +975,20 @@ static int check_delayed_sigs(void)
|
||||
#endif
|
||||
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)
|
||||
#endif
|
||||
+ (1 << SIGUSR1)
|
||||
+ (1 << SIGUSR2)
|
||||
+ (1 << SIGTERM)
|
||||
)) {
|
||||
halt_reboot_pwoff(sig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1070,7 +1084,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
#if 0
|
||||
/* It's 2013, does anyone really still depend on this? */
|
||||
/* If you do, consider adding swapon to sysinot actions then! */
|
||||
/* If you do, consider adding swapon to sysinit actions then! */
|
||||
/* struct sysinfo is linux-specific */
|
||||
# ifdef __linux__
|
||||
/* Make sure there is enough memory to do something useful. */
|
||||
@@ -1134,14 +1148,6 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!DEBUG_INIT) {
|
||||
struct sigaction sa;
|
||||
|
||||
bb_signals(0
|
||||
+ (1 << SIGPWR) /* halt */
|
||||
+ (1 << SIGUSR1) /* halt */
|
||||
+ (1 << SIGTERM) /* reboot */
|
||||
+ (1 << SIGUSR2) /* poweroff */
|
||||
, halt_reboot_pwoff);
|
||||
signal(SIGQUIT, restart_handler); /* re-exec another init */
|
||||
|
||||
/* Stop handler must allow only SIGCONT inside itself */
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sigfillset(&sa.sa_mask);
|
||||
@@ -1156,18 +1162,24 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
*/
|
||||
sigaction_set(SIGSTOP, &sa); /* pause */
|
||||
|
||||
/* SIGINT (Ctrl-Alt-Del) must interrupt wait(),
|
||||
/* These signals must interrupt wait(),
|
||||
* setting handler without SA_RESTART flag.
|
||||
*/
|
||||
bb_signals_recursive_norestart((1 << SIGINT), record_signo);
|
||||
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);
|
||||
}
|
||||
|
||||
/* Set up "reread /etc/inittab" handler.
|
||||
* Handler is set up without SA_RESTART, it will interrupt syscalls.
|
||||
*/
|
||||
if (!DEBUG_INIT && ENABLE_FEATURE_USE_INITTAB)
|
||||
bb_signals_recursive_norestart((1 << SIGHUP), record_signo);
|
||||
|
||||
/* Now run everything that needs to be run */
|
||||
/* First run the sysinit command */
|
||||
run_actions(SYSINIT);
|
||||
|
||||
+7
-1
@@ -30,7 +30,7 @@ lib-y += crc32.o
|
||||
lib-y += default_error_retval.o
|
||||
lib-y += device_open.o
|
||||
lib-y += dump.o
|
||||
lib-y += execable.o
|
||||
lib-y += executable.o
|
||||
lib-y += fclose_nonstdin.o
|
||||
lib-y += fflush_stdout_and_exit.o
|
||||
lib-y += fgets_str.o
|
||||
@@ -92,6 +92,7 @@ lib-y += skip_whitespace.o
|
||||
lib-y += speed_table.o
|
||||
lib-y += str_tolower.o
|
||||
lib-y += strrstr.o
|
||||
lib-y += sysconf.o
|
||||
lib-y += time.o
|
||||
lib-y += trim.o
|
||||
lib-y += u_signal_names.o
|
||||
@@ -141,6 +142,7 @@ lib-$(CONFIG_ADDUSER) += update_passwd.o
|
||||
lib-$(CONFIG_DELGROUP) += update_passwd.o
|
||||
lib-$(CONFIG_DELUSER) += update_passwd.o
|
||||
|
||||
lib-$(CONFIG_FTPD) += correct_password.o
|
||||
lib-$(CONFIG_PASSWD) += pw_encrypt.o update_passwd.o obscure.o
|
||||
lib-$(CONFIG_CHPASSWD) += pw_encrypt.o update_passwd.o
|
||||
lib-$(CONFIG_CRYPTPW) += pw_encrypt.o
|
||||
@@ -149,6 +151,7 @@ lib-$(CONFIG_VLOCK) += pw_encrypt.o correct_password.o
|
||||
lib-$(CONFIG_SU) += pw_encrypt.o correct_password.o
|
||||
lib-$(CONFIG_LOGIN) += pw_encrypt.o correct_password.o
|
||||
lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o
|
||||
lib-$(CONFIG_FEATURE_FTP_AUTHENTICATION) += pw_encrypt.o
|
||||
|
||||
lib-$(CONFIG_DF) += find_mount_point.o
|
||||
lib-$(CONFIG_MKFS_MINIX) += find_mount_point.o
|
||||
@@ -185,3 +188,6 @@ lib-$(CONFIG_PGREP) += xregcomp.o
|
||||
lib-$(CONFIG_PKILL) += xregcomp.o
|
||||
lib-$(CONFIG_DEVFSD) += xregcomp.o
|
||||
lib-$(CONFIG_FEATURE_FIND_REGEX) += xregcomp.o
|
||||
|
||||
# Add the experimental logging functionality, only used by zcip
|
||||
lib-$(CONFIG_ZCIP) += logenv.o
|
||||
+28
-13
@@ -184,8 +184,7 @@ void lbb_prepare(const char *applet
|
||||
#endif
|
||||
applet_name = applet;
|
||||
|
||||
/* Set locale for everybody except 'init' */
|
||||
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
|
||||
if (ENABLE_LOCALE_SUPPORT)
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
#if ENABLE_FEATURE_INDIVIDUAL
|
||||
@@ -606,7 +605,11 @@ static void install_links(const char *busybox, int use_symbolic_links,
|
||||
}
|
||||
}
|
||||
# else
|
||||
# define install_links(x,y,z) ((void)0)
|
||||
static void install_links(const char *busybox UNUSED_PARAM,
|
||||
int use_symbolic_links UNUSED_PARAM,
|
||||
char *custom_install_dir UNUSED_PARAM)
|
||||
{
|
||||
}
|
||||
# endif
|
||||
|
||||
/* If we were called as "busybox..." */
|
||||
@@ -730,7 +733,8 @@ static int busybox_main(char **argv)
|
||||
/*bb_error_msg_and_die("applet not found"); - sucks in printf */
|
||||
full_write2_str(applet_name);
|
||||
full_write2_str(": applet not found\n");
|
||||
xfunc_die();
|
||||
/* POSIX: "If a command is not found, the exit status shall be 127" */
|
||||
exit(127);
|
||||
}
|
||||
|
||||
void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
|
||||
@@ -742,15 +746,25 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
|
||||
|
||||
/* Reinit some shared global data */
|
||||
xfunc_error_retval = EXIT_FAILURE;
|
||||
|
||||
applet_name = APPLET_NAME(applet_no);
|
||||
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
|
||||
/* Special case. POSIX says "test --help"
|
||||
* should be no different from e.g. "test --foo". */
|
||||
//TODO: just compare applet_no with APPLET_NO_test
|
||||
if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) {
|
||||
/* If you want "foo --help" to return 0: */
|
||||
xfunc_error_retval = 0;
|
||||
|
||||
#if defined APPLET_NO_test
|
||||
/* Special case. POSIX says "test --help"
|
||||
* should be no different from e.g. "test --foo".
|
||||
* Thus for "test", we skip --help check.
|
||||
*/
|
||||
if (applet_no != APPLET_NO_test)
|
||||
#endif
|
||||
{
|
||||
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
|
||||
#if defined APPLET_NO_false
|
||||
/* Someone insisted that "false --help" must exit 1. Sigh */
|
||||
if (applet_no != APPLET_NO_false)
|
||||
#endif
|
||||
{
|
||||
/* Make "foo --help" exit with 0: */
|
||||
xfunc_error_retval = 0;
|
||||
}
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
@@ -825,6 +839,7 @@ int main(int argc UNUSED_PARAM, char **argv)
|
||||
/*bb_error_msg_and_die("applet not found"); - sucks in printf */
|
||||
full_write2_str(applet_name);
|
||||
full_write2_str(": applet not found\n");
|
||||
xfunc_die();
|
||||
/* POSIX: "If a command is not found, the exit status shall be 127" */
|
||||
exit(127);
|
||||
#endif
|
||||
}
|
||||
+4
-1
@@ -30,9 +30,12 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
|
||||
struct sigaction sa, oldsa;
|
||||
struct termios tio, oldtio;
|
||||
|
||||
tcflush(fd, TCIFLUSH);
|
||||
/* Was buggy: was printing prompt *before* flushing input,
|
||||
* which was upsetting "expect" based scripts of some users.
|
||||
*/
|
||||
fputs(prompt, stdout);
|
||||
fflush_all();
|
||||
tcflush(fd, TCIFLUSH);
|
||||
|
||||
tcgetattr(fd, &oldtio);
|
||||
tio = oldtio;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* bbunit: Simple unit-testing framework for Busybox.
|
||||
*
|
||||
* Copyright (C) 2014 by Bartosz Golaszewski <bartekgola@gmail.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//kbuild:lib-$(CONFIG_UNIT_TEST) += bbunit.o
|
||||
//applet:IF_UNIT_TEST(APPLET(unit, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
//usage:#define unit_trivial_usage
|
||||
//usage: ""
|
||||
//usage:#define unit_full_usage "\n\n"
|
||||
//usage: "Run the unit-test suite"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define WANT_TIMING 0
|
||||
|
||||
static llist_t *tests = NULL;
|
||||
static unsigned tests_registered = 0;
|
||||
static int test_retval;
|
||||
|
||||
void bbunit_registertest(struct bbunit_listelem *test)
|
||||
{
|
||||
llist_add_to_end(&tests, test);
|
||||
tests_registered++;
|
||||
}
|
||||
|
||||
void bbunit_settestfailed(void)
|
||||
{
|
||||
test_retval = -1;
|
||||
}
|
||||
|
||||
#if WANT_TIMING
|
||||
static void timeval_diff(struct timeval* res,
|
||||
const struct timeval* x,
|
||||
const struct timeval* y)
|
||||
{
|
||||
long udiff = x->tv_usec - y->tv_usec;
|
||||
|
||||
res->tv_sec = x->tv_sec - y->tv_sec - (udiff < 0);
|
||||
res->tv_usec = (udiff >= 0 ? udiff : udiff + 1000000);
|
||||
}
|
||||
#endif
|
||||
|
||||
int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
{
|
||||
unsigned tests_run = 0;
|
||||
unsigned tests_failed = 0;
|
||||
#if WANT_TIMING
|
||||
struct timeval begin;
|
||||
struct timeval end;
|
||||
struct timeval time_spent;
|
||||
gettimeofday(&begin, NULL);
|
||||
#endif
|
||||
|
||||
bb_error_msg("Running %d test(s)...", tests_registered);
|
||||
for (;;) {
|
||||
struct bbunit_listelem* el = llist_pop(&tests);
|
||||
if (!el)
|
||||
break;
|
||||
bb_error_msg("Case: [%s]", el->name);
|
||||
test_retval = 0;
|
||||
el->testfunc();
|
||||
if (test_retval < 0) {
|
||||
bb_error_msg("[ERROR] [%s]: TEST FAILED", el->name);
|
||||
tests_failed++;
|
||||
}
|
||||
tests_run++;
|
||||
el = el->next;
|
||||
}
|
||||
|
||||
#if WANT_TIMING
|
||||
gettimeofday(&end, NULL);
|
||||
timeval_diff(&time_spent, &end, &begin);
|
||||
bb_error_msg("Elapsed time %u.%06u seconds",
|
||||
(int)time_spent.tv_sec,
|
||||
(int)time_spent.tv_usec);
|
||||
#endif
|
||||
if (tests_failed > 0) {
|
||||
bb_error_msg("[ERROR] %u test(s) FAILED", tests_failed);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
bb_error_msg("All tests passed");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -389,5 +389,9 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
|
||||
bb_perror_msg("can't preserve %s of '%s'", "permissions", dest);
|
||||
}
|
||||
|
||||
if (flags & FILEUTILS_VERBOSE) {
|
||||
printf("'%s' -> '%s'\n", source, dest);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
+56
-31
@@ -8,6 +8,20 @@
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#if ENABLE_FEATURE_USE_SENDFILE
|
||||
# include <sys/sendfile.h>
|
||||
#else
|
||||
# define sendfile(a,b,c,d) (-1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We were using 0x7fff0000 as sendfile chunk size, but it
|
||||
* was seen to cause largish delays when user tries to ^C a file copy.
|
||||
* Let's use a saner size.
|
||||
* Note: needs to be >= max(CONFIG_FEATURE_COPYBUF_KB),
|
||||
* or else "copy to eof" code will use neddlesly short reads.
|
||||
*/
|
||||
#define SENDFILE_BIGBUF (16*1024*1024)
|
||||
|
||||
/* Used by NOFORK applets (e.g. cat) - must not use xmalloc.
|
||||
* size < 0 means "ignore write errors", used by tar --to-command
|
||||
@@ -18,12 +32,13 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
|
||||
int status = -1;
|
||||
off_t total = 0;
|
||||
bool continue_on_write_error = 0;
|
||||
#if CONFIG_FEATURE_COPYBUF_KB <= 4
|
||||
ssize_t sendfile_sz;
|
||||
#if CONFIG_FEATURE_COPYBUF_KB > 4
|
||||
char *buffer = buffer; /* for compiler */
|
||||
int buffer_size = 0;
|
||||
#else
|
||||
char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024];
|
||||
enum { buffer_size = sizeof(buffer) };
|
||||
#else
|
||||
char *buffer;
|
||||
int buffer_size;
|
||||
#endif
|
||||
|
||||
if (size < 0) {
|
||||
@@ -31,46 +46,58 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
|
||||
continue_on_write_error = 1;
|
||||
}
|
||||
|
||||
#if CONFIG_FEATURE_COPYBUF_KB > 4
|
||||
if (size > 0 && size <= 4 * 1024)
|
||||
goto use_small_buf;
|
||||
/* We want page-aligned buffer, just in case kernel is clever
|
||||
* and can do page-aligned io more efficiently */
|
||||
buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON,
|
||||
/* ignored: */ -1, 0);
|
||||
buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
|
||||
if (buffer == MAP_FAILED) {
|
||||
use_small_buf:
|
||||
buffer = alloca(4 * 1024);
|
||||
buffer_size = 4 * 1024;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (src_fd < 0)
|
||||
goto out;
|
||||
|
||||
sendfile_sz = !ENABLE_FEATURE_USE_SENDFILE
|
||||
? 0
|
||||
: SENDFILE_BIGBUF;
|
||||
if (!size) {
|
||||
size = buffer_size;
|
||||
size = SENDFILE_BIGBUF;
|
||||
status = 1; /* copy until eof */
|
||||
}
|
||||
|
||||
while (1) {
|
||||
ssize_t rd;
|
||||
|
||||
rd = safe_read(src_fd, buffer, size > buffer_size ? buffer_size : size);
|
||||
|
||||
if (!rd) { /* eof - all done */
|
||||
status = 0;
|
||||
break;
|
||||
if (sendfile_sz) {
|
||||
rd = sendfile(dst_fd, src_fd, NULL,
|
||||
size > sendfile_sz ? sendfile_sz : size);
|
||||
if (rd >= 0)
|
||||
goto read_ok;
|
||||
sendfile_sz = 0; /* do not try sendfile anymore */
|
||||
}
|
||||
#if CONFIG_FEATURE_COPYBUF_KB > 4
|
||||
if (buffer_size == 0) {
|
||||
if (size > 0 && size <= 4 * 1024)
|
||||
goto use_small_buf;
|
||||
/* We want page-aligned buffer, just in case kernel is clever
|
||||
* and can do page-aligned io more efficiently */
|
||||
buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON,
|
||||
/* ignored: */ -1, 0);
|
||||
buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
|
||||
if (buffer == MAP_FAILED) {
|
||||
use_small_buf:
|
||||
buffer = alloca(4 * 1024);
|
||||
buffer_size = 4 * 1024;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
rd = safe_read(src_fd, buffer,
|
||||
size > buffer_size ? buffer_size : size);
|
||||
if (rd < 0) {
|
||||
bb_perror_msg(bb_msg_read_error);
|
||||
break;
|
||||
}
|
||||
read_ok:
|
||||
if (!rd) { /* eof - all done */
|
||||
status = 0;
|
||||
break;
|
||||
}
|
||||
/* dst_fd == -1 is a fake, else... */
|
||||
if (dst_fd >= 0) {
|
||||
if (dst_fd >= 0 && !sendfile_sz) {
|
||||
ssize_t wr = full_write(dst_fd, buffer, rd);
|
||||
if (wr < rd) {
|
||||
if (!continue_on_write_error) {
|
||||
@@ -92,10 +119,8 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
|
||||
}
|
||||
out:
|
||||
|
||||
#if CONFIG_FEATURE_COPYBUF_KB > 4
|
||||
if (buffer_size != 4 * 1024)
|
||||
if (buffer_size > 4 * 1024)
|
||||
munmap(buffer, buffer_size);
|
||||
#endif
|
||||
return status ? -1 : total;
|
||||
}
|
||||
|
||||
|
||||
+67
-29
@@ -30,6 +30,63 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define SHADOW_BUFSIZE 256
|
||||
|
||||
/* Retrieve encrypted password string for pw.
|
||||
* If pw == NULL, return a string which fails password check against any
|
||||
* password.
|
||||
*/
|
||||
#if !ENABLE_FEATURE_SHADOWPASSWDS
|
||||
#define get_passwd(pw, buffer) get_passwd(pw)
|
||||
#endif
|
||||
static const char *get_passwd(const struct passwd *pw, char buffer[SHADOW_BUFSIZE])
|
||||
{
|
||||
const char *pass;
|
||||
|
||||
if (!pw)
|
||||
return "aa"; /* "aa" will never match */
|
||||
|
||||
pass = pw->pw_passwd;
|
||||
#if ENABLE_FEATURE_SHADOWPASSWDS
|
||||
/* Using _r function to avoid pulling in static buffers */
|
||||
if ((pass[0] == 'x' || pass[0] == '*') && !pass[1]) {
|
||||
struct spwd spw;
|
||||
int r;
|
||||
/* getspnam_r may return 0 yet set result to NULL.
|
||||
* At least glibc 2.4 does this. Be extra paranoid here. */
|
||||
struct spwd *result = NULL;
|
||||
r = getspnam_r(pw->pw_name, &spw, buffer, SHADOW_BUFSIZE, &result);
|
||||
pass = (r || !result) ? "aa" : result->sp_pwdp;
|
||||
}
|
||||
#endif
|
||||
return pass;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return 1 if PW has an empty password.
|
||||
* Return 1 if the user gives the correct password for entry PW,
|
||||
* 0 if not.
|
||||
* NULL pw means "just fake it for login with bad username"
|
||||
*/
|
||||
int FAST_FUNC check_password(const struct passwd *pw, const char *plaintext)
|
||||
{
|
||||
IF_FEATURE_SHADOWPASSWDS(char buffer[SHADOW_BUFSIZE];)
|
||||
char *encrypted;
|
||||
const char *pw_pass;
|
||||
int r;
|
||||
|
||||
pw_pass = get_passwd(pw, buffer);
|
||||
if (!pw_pass[0]) { /* empty password field? */
|
||||
return 1;
|
||||
}
|
||||
|
||||
encrypted = pw_encrypt(plaintext, /*salt:*/ pw_pass, 1);
|
||||
r = (strcmp(encrypted, pw_pass) == 0);
|
||||
free(encrypted);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/* Ask the user for a password.
|
||||
* Return 1 without asking if PW has an empty password.
|
||||
* Return -1 on EOF, error while reading input, or timeout.
|
||||
@@ -41,42 +98,23 @@
|
||||
int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw,
|
||||
int timeout, const char *prompt)
|
||||
{
|
||||
char *unencrypted, *encrypted;
|
||||
const char *correct;
|
||||
IF_FEATURE_SHADOWPASSWDS(char buffer[SHADOW_BUFSIZE];)
|
||||
char *plaintext;
|
||||
const char *pw_pass;
|
||||
int r;
|
||||
/* fake salt. crypt() can choke otherwise. */
|
||||
correct = "aa";
|
||||
if (!pw) {
|
||||
/* "aa" will never match */
|
||||
goto fake_it;
|
||||
}
|
||||
correct = pw->pw_passwd;
|
||||
#if ENABLE_FEATURE_SHADOWPASSWDS
|
||||
/* Using _r function to avoid pulling in static buffers */
|
||||
if ((correct[0] == 'x' || correct[0] == '*') && !correct[1]) {
|
||||
struct spwd spw;
|
||||
char buffer[256];
|
||||
/* getspnam_r may return 0 yet set result to NULL.
|
||||
* At least glibc 2.4 does this. Be extra paranoid here. */
|
||||
struct spwd *result = NULL;
|
||||
r = getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result);
|
||||
correct = (r || !result) ? "aa" : result->sp_pwdp;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!correct[0]) /* empty password field? */
|
||||
pw_pass = get_passwd(pw, buffer);
|
||||
if (!pw_pass[0]) /* empty password field? */
|
||||
return 1;
|
||||
|
||||
fake_it:
|
||||
unencrypted = bb_ask(STDIN_FILENO, timeout, prompt);
|
||||
if (!unencrypted) {
|
||||
plaintext = bb_ask(STDIN_FILENO, timeout, prompt);
|
||||
if (!plaintext) {
|
||||
/* EOF (such as ^D) or error (such as ^C) or timeout */
|
||||
return -1;
|
||||
}
|
||||
encrypted = pw_encrypt(unencrypted, correct, 1);
|
||||
r = (strcmp(encrypted, correct) == 0);
|
||||
free(encrypted);
|
||||
nuke_str(unencrypted);
|
||||
|
||||
r = check_password(pw, plaintext);
|
||||
nuke_str(plaintext);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* return 1 if found;
|
||||
* return 0 otherwise;
|
||||
*/
|
||||
int FAST_FUNC execable_file(const char *name)
|
||||
int FAST_FUNC file_is_executable(const char *name)
|
||||
{
|
||||
struct stat s;
|
||||
return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode));
|
||||
@@ -23,13 +23,21 @@ int FAST_FUNC execable_file(const char *name)
|
||||
* return allocated string containing full path if found;
|
||||
* PATHp points to the component after the one where it was found
|
||||
* (or NULL),
|
||||
* you may call find_execable again with this PATHp to continue
|
||||
* you may call find_executable again with this PATHp to continue
|
||||
* (if it's not NULL).
|
||||
* return NULL otherwise; (PATHp is undefined)
|
||||
* in all cases (*PATHp) contents will be trashed (s/:/NUL/).
|
||||
*/
|
||||
char* FAST_FUNC find_execable(const char *filename, char **PATHp)
|
||||
char* FAST_FUNC find_executable(const char *filename, char **PATHp)
|
||||
{
|
||||
/* About empty components in $PATH:
|
||||
* http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
|
||||
* 8.3 Other Environment Variables - PATH
|
||||
* A zero-length prefix is a legacy feature that indicates the current
|
||||
* working directory. It appears as two adjacent colons ( "::" ), as an
|
||||
* initial colon preceding the rest of the list, or as a trailing colon
|
||||
* following the rest of the list.
|
||||
*/
|
||||
char *p, *n;
|
||||
|
||||
p = *PATHp;
|
||||
@@ -37,14 +45,15 @@ char* FAST_FUNC find_execable(const char *filename, char **PATHp)
|
||||
n = strchr(p, ':');
|
||||
if (n)
|
||||
*n++ = '\0';
|
||||
if (*p != '\0') { /* it's not a PATH="foo::bar" situation */
|
||||
p = concat_path_file(p, filename);
|
||||
if (execable_file(p)) {
|
||||
*PATHp = n;
|
||||
return p;
|
||||
}
|
||||
free(p);
|
||||
p = concat_path_file(
|
||||
p[0] ? p : ".", /* handle "::" case */
|
||||
filename
|
||||
);
|
||||
if (file_is_executable(p)) {
|
||||
*PATHp = n;
|
||||
return p;
|
||||
}
|
||||
free(p);
|
||||
p = n;
|
||||
} /* on loop exit p == NULL */
|
||||
return p;
|
||||
@@ -54,17 +63,14 @@ char* FAST_FUNC find_execable(const char *filename, char **PATHp)
|
||||
* return 1 if found;
|
||||
* return 0 otherwise;
|
||||
*/
|
||||
int FAST_FUNC exists_execable(const char *filename)
|
||||
int FAST_FUNC executable_exists(const char *filename)
|
||||
{
|
||||
char *path = xstrdup(getenv("PATH"));
|
||||
char *tmp = path;
|
||||
char *ret = find_execable(filename, &tmp);
|
||||
char *ret = find_executable(filename, &tmp);
|
||||
free(path);
|
||||
if (ret) {
|
||||
free(ret);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
free(ret);
|
||||
return ret != NULL;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_PREFER_APPLETS
|
||||
+1
-1
@@ -16,7 +16,7 @@ int FAST_FUNC xgetpty(char *line)
|
||||
|
||||
#if ENABLE_FEATURE_DEVPTS
|
||||
p = open("/dev/ptmx", O_RDWR);
|
||||
if (p > 0) {
|
||||
if (p >= 0) {
|
||||
grantpt(p); /* chmod+chown corresponding slave pty */
|
||||
unlockpt(p); /* (what does this do?) */
|
||||
# ifndef HAVE_PTSNAME_R
|
||||
|
||||
+298
-19
@@ -926,10 +926,81 @@ void FAST_FUNC sha512_end(sha512_ctx_t *ctx, void *resbuf)
|
||||
# define SHA3_SMALL CONFIG_SHA3_SMALL
|
||||
#endif
|
||||
|
||||
#define OPTIMIZE_SHA3_FOR_32 0
|
||||
/*
|
||||
* SHA3 can be optimized for 32-bit CPUs with bit-slicing:
|
||||
* every 64-bit word of state[] can be split into two 32-bit words
|
||||
* by even/odd bits. In this form, all rotations of sha3 round
|
||||
* are 32-bit - and there are lots of them.
|
||||
* However, it requires either splitting/combining state words
|
||||
* before/after sha3 round (code does this now)
|
||||
* or shuffling bits before xor'ing them into state and in sha3_end.
|
||||
* Without shuffling, bit-slicing results in -130 bytes of code
|
||||
* and marginal speedup (but of course it gives wrong result).
|
||||
* With shuffling it works, but +260 code bytes, and slower.
|
||||
* Disabled for now:
|
||||
*/
|
||||
#if 0 /* LONG_MAX == 0x7fffffff */
|
||||
# undef OPTIMIZE_SHA3_FOR_32
|
||||
# define OPTIMIZE_SHA3_FOR_32 1
|
||||
#endif
|
||||
|
||||
enum {
|
||||
SHA3_IBLK_BYTES = 72, /* 576 bits / 8 */
|
||||
};
|
||||
|
||||
#if OPTIMIZE_SHA3_FOR_32
|
||||
/* This splits every 64-bit word into a pair of 32-bit words,
|
||||
* even bits go into first word, odd bits go to second one.
|
||||
* The conversion is done in-place.
|
||||
*/
|
||||
static void split_halves(uint64_t *state)
|
||||
{
|
||||
/* Credit: Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002 */
|
||||
uint32_t *s32 = (uint32_t*)state;
|
||||
uint32_t t, x0, x1;
|
||||
int i;
|
||||
for (i = 24; i >= 0; --i) {
|
||||
x0 = s32[0];
|
||||
t = (x0 ^ (x0 >> 1)) & 0x22222222; x0 = x0 ^ t ^ (t << 1);
|
||||
t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0C; x0 = x0 ^ t ^ (t << 2);
|
||||
t = (x0 ^ (x0 >> 4)) & 0x00F000F0; x0 = x0 ^ t ^ (t << 4);
|
||||
t = (x0 ^ (x0 >> 8)) & 0x0000FF00; x0 = x0 ^ t ^ (t << 8);
|
||||
x1 = s32[1];
|
||||
t = (x1 ^ (x1 >> 1)) & 0x22222222; x1 = x1 ^ t ^ (t << 1);
|
||||
t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0C; x1 = x1 ^ t ^ (t << 2);
|
||||
t = (x1 ^ (x1 >> 4)) & 0x00F000F0; x1 = x1 ^ t ^ (t << 4);
|
||||
t = (x1 ^ (x1 >> 8)) & 0x0000FF00; x1 = x1 ^ t ^ (t << 8);
|
||||
*s32++ = (x0 & 0x0000FFFF) | (x1 << 16);
|
||||
*s32++ = (x0 >> 16) | (x1 & 0xFFFF0000);
|
||||
}
|
||||
}
|
||||
/* The reverse operation */
|
||||
static void combine_halves(uint64_t *state)
|
||||
{
|
||||
uint32_t *s32 = (uint32_t*)state;
|
||||
uint32_t t, x0, x1;
|
||||
int i;
|
||||
for (i = 24; i >= 0; --i) {
|
||||
x0 = s32[0];
|
||||
x1 = s32[1];
|
||||
t = (x0 & 0x0000FFFF) | (x1 << 16);
|
||||
x1 = (x0 >> 16) | (x1 & 0xFFFF0000);
|
||||
x0 = t;
|
||||
t = (x0 ^ (x0 >> 8)) & 0x0000FF00; x0 = x0 ^ t ^ (t << 8);
|
||||
t = (x0 ^ (x0 >> 4)) & 0x00F000F0; x0 = x0 ^ t ^ (t << 4);
|
||||
t = (x0 ^ (x0 >> 2)) & 0x0C0C0C0C; x0 = x0 ^ t ^ (t << 2);
|
||||
t = (x0 ^ (x0 >> 1)) & 0x22222222; x0 = x0 ^ t ^ (t << 1);
|
||||
*s32++ = x0;
|
||||
t = (x1 ^ (x1 >> 8)) & 0x0000FF00; x1 = x1 ^ t ^ (t << 8);
|
||||
t = (x1 ^ (x1 >> 4)) & 0x00F000F0; x1 = x1 ^ t ^ (t << 4);
|
||||
t = (x1 ^ (x1 >> 2)) & 0x0C0C0C0C; x1 = x1 ^ t ^ (t << 2);
|
||||
t = (x1 ^ (x1 >> 1)) & 0x22222222; x1 = x1 ^ t ^ (t << 1);
|
||||
*s32++ = x1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* In the crypto literature this function is usually called Keccak-f().
|
||||
*/
|
||||
@@ -937,12 +1008,179 @@ static void sha3_process_block72(uint64_t *state)
|
||||
{
|
||||
enum { NROUNDS = 24 };
|
||||
|
||||
/* Elements should be 64-bit, but top half is always zero or 0x80000000.
|
||||
* We encode 63rd bits in a separate word below.
|
||||
* Same is true for 31th bits, which lets us use 16-bit table instead of 64-bit.
|
||||
* The speed penalty is lost in the noise.
|
||||
*/
|
||||
#if OPTIMIZE_SHA3_FOR_32
|
||||
/*
|
||||
static const uint32_t IOTA_CONST_0[NROUNDS] = {
|
||||
0x00000001UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000001UL,
|
||||
0x00000001UL,
|
||||
0x00000001UL,
|
||||
0x00000001UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000001UL,
|
||||
0x00000000UL,
|
||||
0x00000001UL,
|
||||
0x00000001UL,
|
||||
0x00000001UL,
|
||||
0x00000001UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000000UL,
|
||||
0x00000001UL,
|
||||
0x00000000UL,
|
||||
0x00000001UL,
|
||||
0x00000000UL,
|
||||
};
|
||||
** bits are in lsb: 0101 0000 1111 0100 1111 0001
|
||||
*/
|
||||
uint32_t IOTA_CONST_0bits = (uint32_t)(0x0050f4f1);
|
||||
static const uint32_t IOTA_CONST_1[NROUNDS] = {
|
||||
0x00000000UL,
|
||||
0x00000089UL,
|
||||
0x8000008bUL,
|
||||
0x80008080UL,
|
||||
0x0000008bUL,
|
||||
0x00008000UL,
|
||||
0x80008088UL,
|
||||
0x80000082UL,
|
||||
0x0000000bUL,
|
||||
0x0000000aUL,
|
||||
0x00008082UL,
|
||||
0x00008003UL,
|
||||
0x0000808bUL,
|
||||
0x8000000bUL,
|
||||
0x8000008aUL,
|
||||
0x80000081UL,
|
||||
0x80000081UL,
|
||||
0x80000008UL,
|
||||
0x00000083UL,
|
||||
0x80008003UL,
|
||||
0x80008088UL,
|
||||
0x80000088UL,
|
||||
0x00008000UL,
|
||||
0x80008082UL,
|
||||
};
|
||||
|
||||
uint32_t *const s32 = (uint32_t*)state;
|
||||
unsigned round;
|
||||
|
||||
split_halves(state);
|
||||
|
||||
for (round = 0; round < NROUNDS; round++) {
|
||||
unsigned x;
|
||||
|
||||
/* Theta */
|
||||
{
|
||||
uint32_t BC[20];
|
||||
for (x = 0; x < 10; ++x) {
|
||||
BC[x+10] = BC[x] = s32[x]^s32[x+10]^s32[x+20]^s32[x+30]^s32[x+40];
|
||||
}
|
||||
for (x = 0; x < 10; x += 2) {
|
||||
uint32_t ta, tb;
|
||||
ta = BC[x+8] ^ rotl32(BC[x+3], 1);
|
||||
tb = BC[x+9] ^ BC[x+2];
|
||||
s32[x+0] ^= ta;
|
||||
s32[x+1] ^= tb;
|
||||
s32[x+10] ^= ta;
|
||||
s32[x+11] ^= tb;
|
||||
s32[x+20] ^= ta;
|
||||
s32[x+21] ^= tb;
|
||||
s32[x+30] ^= ta;
|
||||
s32[x+31] ^= tb;
|
||||
s32[x+40] ^= ta;
|
||||
s32[x+41] ^= tb;
|
||||
}
|
||||
}
|
||||
/* RhoPi */
|
||||
{
|
||||
uint32_t t0a,t0b, t1a,t1b;
|
||||
t1a = s32[1*2+0];
|
||||
t1b = s32[1*2+1];
|
||||
|
||||
#define RhoPi(PI_LANE, ROT_CONST) \
|
||||
t0a = s32[PI_LANE*2+0];\
|
||||
t0b = s32[PI_LANE*2+1];\
|
||||
if (ROT_CONST & 1) {\
|
||||
s32[PI_LANE*2+0] = rotl32(t1b, ROT_CONST/2+1);\
|
||||
s32[PI_LANE*2+1] = ROT_CONST == 1 ? t1a : rotl32(t1a, ROT_CONST/2+0);\
|
||||
} else {\
|
||||
s32[PI_LANE*2+0] = rotl32(t1a, ROT_CONST/2);\
|
||||
s32[PI_LANE*2+1] = rotl32(t1b, ROT_CONST/2);\
|
||||
}\
|
||||
t1a = t0a; t1b = t0b;
|
||||
|
||||
RhoPi(10, 1)
|
||||
RhoPi( 7, 3)
|
||||
RhoPi(11, 6)
|
||||
RhoPi(17,10)
|
||||
RhoPi(18,15)
|
||||
RhoPi( 3,21)
|
||||
RhoPi( 5,28)
|
||||
RhoPi(16,36)
|
||||
RhoPi( 8,45)
|
||||
RhoPi(21,55)
|
||||
RhoPi(24, 2)
|
||||
RhoPi( 4,14)
|
||||
RhoPi(15,27)
|
||||
RhoPi(23,41)
|
||||
RhoPi(19,56)
|
||||
RhoPi(13, 8)
|
||||
RhoPi(12,25)
|
||||
RhoPi( 2,43)
|
||||
RhoPi(20,62)
|
||||
RhoPi(14,18)
|
||||
RhoPi(22,39)
|
||||
RhoPi( 9,61)
|
||||
RhoPi( 6,20)
|
||||
RhoPi( 1,44)
|
||||
#undef RhoPi
|
||||
}
|
||||
/* Chi */
|
||||
for (x = 0; x <= 40;) {
|
||||
uint32_t BC0, BC1, BC2, BC3, BC4;
|
||||
BC0 = s32[x + 0*2];
|
||||
BC1 = s32[x + 1*2];
|
||||
BC2 = s32[x + 2*2];
|
||||
s32[x + 0*2] = BC0 ^ ((~BC1) & BC2);
|
||||
BC3 = s32[x + 3*2];
|
||||
s32[x + 1*2] = BC1 ^ ((~BC2) & BC3);
|
||||
BC4 = s32[x + 4*2];
|
||||
s32[x + 2*2] = BC2 ^ ((~BC3) & BC4);
|
||||
s32[x + 3*2] = BC3 ^ ((~BC4) & BC0);
|
||||
s32[x + 4*2] = BC4 ^ ((~BC0) & BC1);
|
||||
x++;
|
||||
BC0 = s32[x + 0*2];
|
||||
BC1 = s32[x + 1*2];
|
||||
BC2 = s32[x + 2*2];
|
||||
s32[x + 0*2] = BC0 ^ ((~BC1) & BC2);
|
||||
BC3 = s32[x + 3*2];
|
||||
s32[x + 1*2] = BC1 ^ ((~BC2) & BC3);
|
||||
BC4 = s32[x + 4*2];
|
||||
s32[x + 2*2] = BC2 ^ ((~BC3) & BC4);
|
||||
s32[x + 3*2] = BC3 ^ ((~BC4) & BC0);
|
||||
s32[x + 4*2] = BC4 ^ ((~BC0) & BC1);
|
||||
x += 9;
|
||||
}
|
||||
/* Iota */
|
||||
s32[0] ^= IOTA_CONST_0bits & 1;
|
||||
IOTA_CONST_0bits >>= 1;
|
||||
s32[1] ^= IOTA_CONST_1[round];
|
||||
}
|
||||
|
||||
combine_halves(state);
|
||||
#else
|
||||
/* Native 64-bit algorithm */
|
||||
static const uint16_t IOTA_CONST[NROUNDS] = {
|
||||
/* Elements should be 64-bit, but top half is always zero
|
||||
* or 0x80000000. We encode 63rd bits in a separate word below.
|
||||
* Same is true for 31th bits, which lets us use 16-bit table
|
||||
* instead of 64-bit. The speed penalty is lost in the noise.
|
||||
*/
|
||||
0x0001,
|
||||
0x8082,
|
||||
0x808a,
|
||||
@@ -983,7 +1221,7 @@ static void sha3_process_block72(uint64_t *state)
|
||||
};
|
||||
/*static const uint8_t MOD5[10] = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, };*/
|
||||
|
||||
unsigned x, y;
|
||||
unsigned x;
|
||||
unsigned round;
|
||||
|
||||
if (BB_BIG_ENDIAN) {
|
||||
@@ -1045,22 +1283,62 @@ static void sha3_process_block72(uint64_t *state)
|
||||
RhoPi_twice(20); RhoPi_twice(22);
|
||||
#undef RhoPi_twice
|
||||
}
|
||||
|
||||
/* Chi */
|
||||
for (y = 0; y <= 20; y += 5) {
|
||||
# if LONG_MAX > 0x7fffffff
|
||||
for (x = 0; x <= 20; x += 5) {
|
||||
uint64_t BC0, BC1, BC2, BC3, BC4;
|
||||
BC0 = state[y + 0];
|
||||
BC1 = state[y + 1];
|
||||
BC2 = state[y + 2];
|
||||
state[y + 0] = BC0 ^ ((~BC1) & BC2);
|
||||
BC3 = state[y + 3];
|
||||
state[y + 1] = BC1 ^ ((~BC2) & BC3);
|
||||
BC4 = state[y + 4];
|
||||
state[y + 2] = BC2 ^ ((~BC3) & BC4);
|
||||
state[y + 3] = BC3 ^ ((~BC4) & BC0);
|
||||
state[y + 4] = BC4 ^ ((~BC0) & BC1);
|
||||
BC0 = state[x + 0];
|
||||
BC1 = state[x + 1];
|
||||
BC2 = state[x + 2];
|
||||
state[x + 0] = BC0 ^ ((~BC1) & BC2);
|
||||
BC3 = state[x + 3];
|
||||
state[x + 1] = BC1 ^ ((~BC2) & BC3);
|
||||
BC4 = state[x + 4];
|
||||
state[x + 2] = BC2 ^ ((~BC3) & BC4);
|
||||
state[x + 3] = BC3 ^ ((~BC4) & BC0);
|
||||
state[x + 4] = BC4 ^ ((~BC0) & BC1);
|
||||
}
|
||||
|
||||
# else
|
||||
/* Reduced register pressure version
|
||||
* for register-starved 32-bit arches
|
||||
* (i386: -95 bytes, and it is _faster_)
|
||||
*/
|
||||
for (x = 0; x <= 40;) {
|
||||
uint32_t BC0, BC1, BC2, BC3, BC4;
|
||||
uint32_t *const s32 = (uint32_t*)state;
|
||||
# if SHA3_SMALL
|
||||
do_half:
|
||||
# endif
|
||||
BC0 = s32[x + 0*2];
|
||||
BC1 = s32[x + 1*2];
|
||||
BC2 = s32[x + 2*2];
|
||||
s32[x + 0*2] = BC0 ^ ((~BC1) & BC2);
|
||||
BC3 = s32[x + 3*2];
|
||||
s32[x + 1*2] = BC1 ^ ((~BC2) & BC3);
|
||||
BC4 = s32[x + 4*2];
|
||||
s32[x + 2*2] = BC2 ^ ((~BC3) & BC4);
|
||||
s32[x + 3*2] = BC3 ^ ((~BC4) & BC0);
|
||||
s32[x + 4*2] = BC4 ^ ((~BC0) & BC1);
|
||||
x++;
|
||||
# if SHA3_SMALL
|
||||
if (x & 1)
|
||||
goto do_half;
|
||||
x += 8;
|
||||
# else
|
||||
BC0 = s32[x + 0*2];
|
||||
BC1 = s32[x + 1*2];
|
||||
BC2 = s32[x + 2*2];
|
||||
s32[x + 0*2] = BC0 ^ ((~BC1) & BC2);
|
||||
BC3 = s32[x + 3*2];
|
||||
s32[x + 1*2] = BC1 ^ ((~BC2) & BC3);
|
||||
BC4 = s32[x + 4*2];
|
||||
s32[x + 2*2] = BC2 ^ ((~BC3) & BC4);
|
||||
s32[x + 3*2] = BC3 ^ ((~BC4) & BC0);
|
||||
s32[x + 4*2] = BC4 ^ ((~BC0) & BC1);
|
||||
x += 9;
|
||||
# endif
|
||||
}
|
||||
# endif /* long is 32-bit */
|
||||
/* Iota */
|
||||
state[0] ^= IOTA_CONST[round]
|
||||
| (uint32_t)((IOTA_CONST_bit31 << round) & 0x80000000)
|
||||
@@ -1072,6 +1350,7 @@ static void sha3_process_block72(uint64_t *state)
|
||||
state[x] = SWAP_LE64(state[x]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void FAST_FUNC sha3_begin(sha3_ctx_t *ctx)
|
||||
|
||||
+26
-10
@@ -11,14 +11,23 @@
|
||||
#include "libbb.h"
|
||||
|
||||
typedef struct ino_dev_hash_bucket_struct {
|
||||
struct ino_dev_hash_bucket_struct *next;
|
||||
ino_t ino;
|
||||
dev_t dev;
|
||||
/*
|
||||
* Above fields can be 64-bit, while pointer may be 32-bit.
|
||||
* Putting "next" field here may reduce size of this struct:
|
||||
*/
|
||||
struct ino_dev_hash_bucket_struct *next;
|
||||
/*
|
||||
* Reportedly, on cramfs a file and a dir can have same ino.
|
||||
* Need to also remember "file/dir" bit:
|
||||
*/
|
||||
char isdir; /* bool */
|
||||
char name[1];
|
||||
} ino_dev_hashtable_bucket_t;
|
||||
|
||||
#define HASH_SIZE 311 /* Should be prime */
|
||||
#define hash_inode(i) ((i) % HASH_SIZE)
|
||||
#define HASH_SIZE 311u /* Should be prime */
|
||||
#define hash_inode(i) ((unsigned)(i) % HASH_SIZE)
|
||||
|
||||
/* array of [HASH_SIZE] elements */
|
||||
static ino_dev_hashtable_bucket_t **ino_dev_hashtable;
|
||||
@@ -38,6 +47,7 @@ char* FAST_FUNC is_in_ino_dev_hashtable(const struct stat *statbuf)
|
||||
while (bucket != NULL) {
|
||||
if ((bucket->ino == statbuf->st_ino)
|
||||
&& (bucket->dev == statbuf->st_dev)
|
||||
&& (bucket->isdir == !!S_ISDIR(statbuf->st_mode))
|
||||
) {
|
||||
return bucket->name;
|
||||
}
|
||||
@@ -52,17 +62,18 @@ void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *
|
||||
int i;
|
||||
ino_dev_hashtable_bucket_t *bucket;
|
||||
|
||||
i = hash_inode(statbuf->st_ino);
|
||||
if (!name)
|
||||
name = "";
|
||||
bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name));
|
||||
bucket->ino = statbuf->st_ino;
|
||||
bucket->dev = statbuf->st_dev;
|
||||
bucket->isdir = !!S_ISDIR(statbuf->st_mode);
|
||||
strcpy(bucket->name, name);
|
||||
|
||||
if (!ino_dev_hashtable)
|
||||
ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable));
|
||||
|
||||
i = hash_inode(statbuf->st_ino);
|
||||
bucket->next = ino_dev_hashtable[i];
|
||||
ino_dev_hashtable[i] = bucket;
|
||||
}
|
||||
@@ -72,13 +83,18 @@ void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *
|
||||
void FAST_FUNC reset_ino_dev_hashtable(void)
|
||||
{
|
||||
int i;
|
||||
ino_dev_hashtable_bucket_t *bucket;
|
||||
ino_dev_hashtable_bucket_t *bucket, *next;
|
||||
|
||||
for (i = 0; ino_dev_hashtable && i < HASH_SIZE; i++) {
|
||||
while (ino_dev_hashtable[i] != NULL) {
|
||||
bucket = ino_dev_hashtable[i]->next;
|
||||
free(ino_dev_hashtable[i]);
|
||||
ino_dev_hashtable[i] = bucket;
|
||||
if (!ino_dev_hashtable)
|
||||
return;
|
||||
|
||||
for (i = 0; i < HASH_SIZE; i++) {
|
||||
bucket = ino_dev_hashtable[i];
|
||||
|
||||
while (bucket != NULL) {
|
||||
next = bucket->next;
|
||||
free(bucket);
|
||||
bucket = next;
|
||||
}
|
||||
}
|
||||
free(ino_dev_hashtable);
|
||||
|
||||
+9
-3
@@ -1255,7 +1255,9 @@ line_input_t* FAST_FUNC new_line_input_t(int flags)
|
||||
{
|
||||
line_input_t *n = xzalloc(sizeof(*n));
|
||||
n->flags = flags;
|
||||
#if MAX_HISTORY > 0
|
||||
n->max_history = MAX_HISTORY;
|
||||
#endif
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -2254,9 +2256,13 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
|
||||
INIT_S();
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &initial_settings) < 0
|
||||
|| !(initial_settings.c_lflag & ECHO)
|
||||
|| (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON
|
||||
) {
|
||||
/* Happens when e.g. stty -echo was run before */
|
||||
/* Happens when e.g. stty -echo was run before.
|
||||
* But if ICANON is not set, we don't come here.
|
||||
* (example: interactive python ^Z-backgrounded,
|
||||
* tty is still in "raw mode").
|
||||
*/
|
||||
parse_and_put_prompt(prompt);
|
||||
/* fflush_all(); - done by parse_and_put_prompt */
|
||||
if (fgets(command, maxsize, stdin) == NULL)
|
||||
@@ -2605,7 +2611,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
|
||||
* standard readline bindings (IOW: bash) do.
|
||||
* Often, Alt-<key> generates ESC-<key>.
|
||||
*/
|
||||
ic = lineedit_read_key(read_key_buffer, timeout);
|
||||
ic = lineedit_read_key(read_key_buffer, 50);
|
||||
switch (ic) {
|
||||
//case KEYCODE_LEFT: - bash doesn't do this
|
||||
case 'b':
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Utility routines.
|
||||
*
|
||||
* Copyright (C) 2014 by Fugro Intersite B.V. <m.stam@fugro.nl>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
|
||||
void FAST_FUNC bb_logenv_override(void)
|
||||
{
|
||||
const char* mode = getenv("LOGGING");
|
||||
|
||||
if (!mode)
|
||||
return;
|
||||
|
||||
if (strcmp(mode, "none") == 0)
|
||||
logmode = LOGMODE_NONE;
|
||||
#if ENABLE_FEATURE_SYSLOG
|
||||
else if (strcmp(mode, "syslog") == 0)
|
||||
logmode = LOGMODE_SYSLOG;
|
||||
#endif
|
||||
}
|
||||
+12
-6
@@ -94,19 +94,19 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
|
||||
|
||||
/* Open the file. Barf if this doesn't work. */
|
||||
mode = ro ? O_RDONLY : O_RDWR;
|
||||
open_ffd:
|
||||
ffd = open(file, mode);
|
||||
if (ffd < 0) {
|
||||
if (mode != O_RDONLY) {
|
||||
mode = O_RDONLY;
|
||||
ffd = open(file, mode);
|
||||
goto open_ffd;
|
||||
}
|
||||
if (ffd < 0)
|
||||
return -errno;
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* Find a loop device. */
|
||||
try = *device ? *device : dev;
|
||||
/* 1048575 is a max possible minor number in Linux circa 2010 */
|
||||
/* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */
|
||||
for (i = 0; rc && i < 1048576; i++) {
|
||||
sprintf(dev, LOOP_FORMAT, i);
|
||||
|
||||
@@ -121,7 +121,7 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
|
||||
goto try_to_open;
|
||||
}
|
||||
/* Ran out of block devices, return failure. */
|
||||
rc = -ENOENT;
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
try_to_open:
|
||||
@@ -131,8 +131,14 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse
|
||||
mode = O_RDONLY;
|
||||
dfd = open(try, mode);
|
||||
}
|
||||
if (dfd < 0)
|
||||
if (dfd < 0) {
|
||||
if (errno == ENXIO) {
|
||||
/* Happens if loop module is not loaded */
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
goto try_again;
|
||||
}
|
||||
|
||||
rc = ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo);
|
||||
|
||||
|
||||
@@ -99,6 +99,10 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
|
||||
if (!c) {
|
||||
goto ret0;
|
||||
}
|
||||
} else {
|
||||
if (flags & FILEUTILS_VERBOSE) {
|
||||
printf("created directory: '%s'\n", path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!c) {
|
||||
|
||||
+39
-1
@@ -76,7 +76,7 @@ static int string_checker(const char *p1, const char *p2)
|
||||
ret |= string_checker_helper(p, p2);
|
||||
|
||||
/* clean up */
|
||||
memset(p, 0, size);
|
||||
nuke_str(p);
|
||||
free(p);
|
||||
|
||||
return ret;
|
||||
@@ -182,3 +182,41 @@ int FAST_FUNC obscure(const char *old, const char *newval, const struct passwd *
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_UNIT_TEST
|
||||
|
||||
/* Test obscure_msg() instead of obscure() in order not to print anything. */
|
||||
|
||||
static const struct passwd pw = {
|
||||
.pw_name = (char *)"johndoe",
|
||||
.pw_gecos = (char *)"John Doe",
|
||||
};
|
||||
|
||||
BBUNIT_DEFINE_TEST(obscure_weak_pass)
|
||||
{
|
||||
/* Empty password */
|
||||
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "", &pw));
|
||||
/* Pure numbers */
|
||||
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "23577315", &pw));
|
||||
/* Similar to pw_name */
|
||||
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "johndoe123%", &pw));
|
||||
/* Similar to pw_gecos, reversed */
|
||||
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "eoD nhoJ^44@", &pw));
|
||||
/* Similar to the old password */
|
||||
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "d4#21?'S", &pw));
|
||||
/* adjacent letters */
|
||||
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "qwerty123", &pw));
|
||||
/* Many similar chars */
|
||||
BBUNIT_ASSERT_NOTNULL(obscure_msg("Ad4#21?'S|", "^33Daaaaaa1", &pw));
|
||||
|
||||
BBUNIT_ENDTEST;
|
||||
}
|
||||
|
||||
BBUNIT_DEFINE_TEST(obscure_strong_pass)
|
||||
{
|
||||
BBUNIT_ASSERT_NULL(obscure_msg("Rt4##2&:'|", "}(^#rrSX3S*22", &pw));
|
||||
|
||||
BBUNIT_ENDTEST;
|
||||
}
|
||||
|
||||
#endif /* ENABLE_UNIT_TEST */
|
||||
@@ -17,6 +17,24 @@ char* FAST_FUNC strchrnul(const char *s, int c)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_USLEEP
|
||||
int FAST_FUNC usleep(unsigned usec)
|
||||
{
|
||||
struct timespec ts;
|
||||
ts.tv_sec = usec / 1000000u;
|
||||
ts.tv_nsec = (usec % 1000000u) * 1000u;
|
||||
/*
|
||||
* If a signal has non-default handler, nanosleep returns early.
|
||||
* Our version of usleep doesn't return early
|
||||
* if interrupted by such signals:
|
||||
*
|
||||
*/
|
||||
while (nanosleep(&ts, &ts) != 0)
|
||||
continue;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_VASPRINTF
|
||||
int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
|
||||
{
|
||||
|
||||
+8
-1
@@ -142,7 +142,14 @@ char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
|
||||
|
||||
char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
|
||||
{
|
||||
return xstrdup(crypt(clear, salt));
|
||||
char *s;
|
||||
|
||||
s = crypt(clear, salt);
|
||||
/*
|
||||
* glibc used to return "" on malformed salts (for example, ""),
|
||||
* but since 2.17 it returns NULL.
|
||||
*/
|
||||
return xstrdup(s ? s : "");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -78,6 +78,10 @@ int FAST_FUNC remove_file(const char *path, int flags)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags & FILEUTILS_VERBOSE) {
|
||||
printf("removed directory: '%s'\n", path);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -98,5 +102,9 @@ int FAST_FUNC remove_file(const char *path, int flags)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags & FILEUTILS_VERBOSE) {
|
||||
printf("removed '%s'\n", path);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Utility routines.
|
||||
*
|
||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//kbuild:lib-y += replace.o
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
unsigned FAST_FUNC count_strstr(const char *str, const char *sub)
|
||||
{
|
||||
size_t sub_len = strlen(sub);
|
||||
unsigned count = 0;
|
||||
|
||||
while ((str = strstr(str, sub)) != NULL) {
|
||||
count++;
|
||||
str += sub_len;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
char* FAST_FUNC xmalloc_substitute_string(const char *src, int count, const char *sub, const char *repl)
|
||||
{
|
||||
char *buf, *dst, *end;
|
||||
size_t sub_len = strlen(sub);
|
||||
size_t repl_len = strlen(repl);
|
||||
|
||||
//dbg_msg("subst(s:'%s',count:%d,sub:'%s',repl:'%s'", src, count, sub, repl);
|
||||
|
||||
buf = dst = xmalloc(strlen(src) + count * ((int)repl_len - (int)sub_len) + 1);
|
||||
/* we replace each sub with repl */
|
||||
while ((end = strstr(src, sub)) != NULL) {
|
||||
dst = mempcpy(dst, src, end - src);
|
||||
dst = mempcpy(dst, repl, repl_len);
|
||||
/*src = end + 1; - GNU findutils 4.5.10 doesn't do this... */
|
||||
src = end + sub_len; /* but this. Try "xargs -Iaa echo aaa" */
|
||||
}
|
||||
strcpy(dst, src);
|
||||
//dbg_msg("subst9:'%s'", buf);
|
||||
return buf;
|
||||
}
|
||||
+42
-10
@@ -33,23 +33,55 @@ int FAST_FUNC rtc_adjtime_is_utc(void)
|
||||
return utc;
|
||||
}
|
||||
|
||||
/* rtc opens are exclusive.
|
||||
* Try to run two "hwclock -w" at the same time to see it.
|
||||
* Users wouldn't expect that to fail merely because /dev/rtc
|
||||
* was momentarily busy, let's try a bit harder on errno == EBUSY.
|
||||
*/
|
||||
static int open_loop_on_busy(const char *name, int flags)
|
||||
{
|
||||
int rtc;
|
||||
/*
|
||||
* Tested with two parallel "hwclock -w" loops.
|
||||
* With try = 10, no failures with 2x1000000 loop iterations.
|
||||
*/
|
||||
int try = 1000 / 20;
|
||||
again:
|
||||
errno = 0;
|
||||
rtc = open(name, flags);
|
||||
if (errno == EBUSY) {
|
||||
usleep(20 * 1000);
|
||||
if (--try != 0)
|
||||
goto again;
|
||||
/* EBUSY. Last try, exit on error instead of returning -1 */
|
||||
return xopen(name, flags);
|
||||
}
|
||||
return rtc;
|
||||
}
|
||||
|
||||
/* Never fails */
|
||||
int FAST_FUNC rtc_xopen(const char **default_rtc, int flags)
|
||||
{
|
||||
int rtc;
|
||||
const char *name =
|
||||
"/dev/rtc""\0"
|
||||
"/dev/rtc0""\0"
|
||||
"/dev/misc/rtc""\0";
|
||||
|
||||
if (!*default_rtc) {
|
||||
*default_rtc = "/dev/rtc";
|
||||
rtc = open(*default_rtc, flags);
|
||||
if (!*default_rtc)
|
||||
goto try_name;
|
||||
name = ""; /*else: we have rtc name, don't try other names */
|
||||
|
||||
for (;;) {
|
||||
rtc = open_loop_on_busy(*default_rtc, flags);
|
||||
if (rtc >= 0)
|
||||
return rtc;
|
||||
*default_rtc = "/dev/rtc0";
|
||||
rtc = open(*default_rtc, flags);
|
||||
if (rtc >= 0)
|
||||
return rtc;
|
||||
*default_rtc = "/dev/misc/rtc";
|
||||
if (!name[0])
|
||||
return xopen(*default_rtc, flags);
|
||||
try_name:
|
||||
*default_rtc = name;
|
||||
name += strlen(name) + 1;
|
||||
}
|
||||
|
||||
return xopen(*default_rtc, flags);
|
||||
}
|
||||
|
||||
void FAST_FUNC rtc_read_tm(struct tm *ptm, int fd)
|
||||
|
||||
@@ -10,7 +10,12 @@
|
||||
#include "libbb.h"
|
||||
|
||||
struct speed_map {
|
||||
#if defined __FreeBSD__
|
||||
/* On FreeBSD, B<num> constants don't fit into a short */
|
||||
unsigned speed;
|
||||
#else
|
||||
unsigned short speed;
|
||||
#endif
|
||||
unsigned short value;
|
||||
};
|
||||
|
||||
|
||||
Loaded 100 of 195 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user