Compare commits

..
Author SHA1 Message Date
Denys Vlasenko 28dd64a0e1 libarchive: open_zipped() does not need to check extensions for e.g. gzip
We only need to check for signature-less extensions,
currently only .lzma. The rest can be happily autodetected.

This fixes "zcat FILE_WITHOUT_GZ_EXT" case, among others.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 7c47b560a8)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2014-10-21 15:11:54 -04:00
Denys Vlasenko 5698ff9323 lzop: add overflow check
See CVE-2014-4607
http://www.openwall.com/lists/oss-security/2014/06/26/20

function                                             old     new   delta
lzo1x_decompress_safe                               1010    1031     +21

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
(cherry picked from commit a9dc7c2f59)
2014-10-21 08:41:37 -04:00
Denys Vlasenko d9e0c438e1 Apply post-1.22.0 patches, bump version to 1.22.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2014-01-20 03:41:48 +01:00
193 changed files with 2336 additions and 6375 deletions

No files matched your search

-7
View File
@@ -35,10 +35,3 @@ Config.in
core
.gdb_history
.gdbinit
#
# testing output
#
/busybox.links
/runtest-tempdir-links
/testsuite/echo-ne
+4 -29
View File
@@ -257,26 +257,6 @@ 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
@@ -436,7 +416,10 @@ config SELINUX
the option of compiling in SELinux applets.
If you do not have a complete SELinux userland installed, this stuff
will not compile. Specifially, libselinux 1.28 or better is
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
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> \
@@ -688,14 +671,6 @@ 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
+2 -2
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 23
SUBLEVEL = 2
PATCHLEVEL = 22
SUBLEVEL = 1
EXTRAVERSION =
NAME = Unnamed
-4
View File
@@ -55,11 +55,7 @@ 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)"
+4
View File
@@ -21,6 +21,10 @@ 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));) \
-17
View File
@@ -14,7 +14,6 @@
#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])))
@@ -50,16 +49,6 @@ 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;
@@ -105,12 +94,6 @@ 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++) {
+39 -17
View File
@@ -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_state_t *xstate),
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
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_state_t xstate;
transformer_aux_data_t aux;
do {
/* NB: new_name is *maybe* malloc'ed! */
@@ -72,8 +72,7 @@ int FAST_FUNC bbunpack(char **argv,
goto err;
} else {
/* "clever zcat" with FILE */
/* fail_if_not_compressed because zcat refuses uncompressed input */
int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
int fd = open_zipped(filename);
if (fd < 0)
goto err_name;
xmove_fd(fd, STDIN_FILENO);
@@ -81,7 +80,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_compressed*/ 1))
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0))
goto err;
}
@@ -120,11 +119,9 @@ int FAST_FUNC bbunpack(char **argv,
}
if (!(option_mask32 & SEAMLESS_MAGIC)) {
init_transformer_state(&xstate);
xstate.check_signature = 1;
/*xstate.src_fd = STDIN_FILENO; - already is */
xstate.dst_fd = STDOUT_FILENO;
status = unpacker(&xstate);
init_transformer_aux_data(&aux);
aux.check_signature = 1;
status = unpacker(&aux);
if (status < 0)
exitcode = 1;
} else {
@@ -143,10 +140,10 @@ int FAST_FUNC bbunpack(char **argv,
unsigned new_name_len;
/* TODO: restore other things? */
if (xstate.mtime != 0) {
if (aux.mtime != 0) {
struct timeval times[2];
times[1].tv_sec = times[0].tv_sec = xstate.mtime;
times[1].tv_sec = times[0].tv_sec = aux.mtime;
times[1].tv_usec = times[0].tv_usec = 0;
/* Note: we closed it first.
* On some systems calling utimes
@@ -228,13 +225,18 @@ 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_Z_stream, make_new_name_generic, "Z");
return bbunpack(argv, unpack_uncompress, make_new_name_generic, "Z");
}
#endif
@@ -321,6 +323,11 @@ 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:
@@ -347,7 +354,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_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
}
#endif
@@ -387,6 +394,11 @@ 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)
{
@@ -395,7 +407,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
if (applet_name[2] == 'c') /* bzcat */
option_mask32 |= OPT_STDOUT;
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
return bbunpack(argv, unpack_bunzip2, make_new_name_generic, "bz2");
}
#endif
@@ -481,6 +493,11 @@ 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)
{
@@ -495,7 +512,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
option_mask32 |= OPT_STDOUT;
argv += optind;
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma");
}
#endif
@@ -519,6 +536,11 @@ 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)
{
@@ -533,6 +555,6 @@ int unxz_main(int argc UNUSED_PARAM, char **argv)
option_mask32 |= OPT_STDOUT;
argv += optind;
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
return bbunpack(argv, unpack_unxz, make_new_name_generic, "xz");
}
#endif
+1 -1
View File
@@ -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_state_t *xstate UNUSED_PARAM)
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_aux_data_t *aux UNUSED_PARAM)
{
IF_DESKTOP(long long) int total;
ssize_t count;
-1
View File
@@ -65,7 +65,6 @@
//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
View File
@@ -2042,7 +2042,7 @@ static void zip(ulg time_stamp)
/* ======================================================================== */
static
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM)
{
struct stat s;
+6 -5
View File
@@ -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_state_t *xstate)
unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
{
IF_DESKTOP(long long total_written = 0;)
bunzip_data *bd;
@@ -739,14 +739,14 @@ unpack_bz2_stream(transformer_state_t *xstate)
int i;
unsigned len;
if (check_signature16(xstate, BZIP2_MAGIC))
if (check_signature16(aux, src_fd, BZIP2_MAGIC))
return -1;
outbuf = xmalloc(IOBUF_SIZE);
len = 0;
while (1) { /* "Process one BZ... stream" loop */
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
i = start_bunzip(&bd, src_fd, outbuf + 2, len);
if (i == 0) {
while (1) { /* "Produce some output bytes" loop */
@@ -756,7 +756,8 @@ unpack_bz2_stream(transformer_state_t *xstate)
i = IOBUF_SIZE - i; /* number of bytes produced */
if (i == 0) /* EOF? */
break;
if (i != transformer_write(xstate, outbuf, i)) {
if (i != full_write(dst_fd, outbuf, i)) {
bb_error_msg("short write");
i = RETVAL_SHORT_WRITE;
goto release_mem;
}
@@ -789,7 +790,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
len = bd->inbufCount - bd->inbufPos;
memcpy(outbuf, &bd->inbuf[bd->inbufPos], len);
if (len < 2) {
if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len)
if (safe_read(src_fd, outbuf + len, 2 - len) != 2 - len)
break;
len = 2;
}
+22 -20
View File
@@ -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 transformer_state_t *xstate)
inflate_unzip_internal(STATE_PARAM int in, int out)
{
IF_DESKTOP(long long) int n = 0;
ssize_t nwrote;
@@ -980,7 +980,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
gunzip_window = xmalloc(GUNZIP_WSIZE);
gunzip_outbuf_count = 0;
gunzip_bytes_out = 0;
gunzip_src_fd = xstate->src_fd;
gunzip_src_fd = in;
/* (re) initialize state */
method = -1;
@@ -1002,8 +1002,9 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
while (1) {
int r = inflate_get_next_window(PASS_STATE_ONLY);
nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count);
if (nwrote == (ssize_t)-1) {
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
if (nwrote != (ssize_t)gunzip_outbuf_count) {
bb_perror_msg("write");
n = -1;
goto ret;
}
@@ -1033,22 +1034,22 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
/* For unzip */
IF_DESKTOP(long long) int FAST_FUNC
inflate_unzip(transformer_state_t *xstate)
inflate_unzip(transformer_aux_data_t *aux, int in, int out)
{
IF_DESKTOP(long long) int n;
DECLARE_STATE;
ALLOC_STATE;
to_read = xstate->bytes_in;
to_read = aux->bytes_in;
// bytebuffer_max = 0x8000;
bytebuffer_offset = 4;
bytebuffer = xmalloc(bytebuffer_max);
n = inflate_unzip_internal(PASS_STATE xstate);
n = inflate_unzip_internal(PASS_STATE in, out);
free(bytebuffer);
xstate->crc32 = gunzip_crc;
xstate->bytes_out = gunzip_bytes_out;
aux->crc32 = gunzip_crc;
aux->bytes_out = gunzip_bytes_out;
DEALLOC_STATE;
return n;
}
@@ -1106,7 +1107,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
return res;
}
static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
{
union {
unsigned char raw[8];
@@ -1168,7 +1169,8 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
}
}
xstate->mtime = SWAP_LE32(header.formatted.mtime);
if (aux)
aux->mtime = SWAP_LE32(header.formatted.mtime);
/* Read the header checksum */
if (header.formatted.flags & 0x02) {
@@ -1180,27 +1182,27 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
}
IF_DESKTOP(long long) int FAST_FUNC
unpack_gz_stream(transformer_state_t *xstate)
unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
{
uint32_t v32;
IF_DESKTOP(long long) int total, n;
DECLARE_STATE;
#if !ENABLE_FEATURE_SEAMLESS_Z
if (check_signature16(xstate, GZIP_MAGIC))
if (check_signature16(aux, src_fd, GZIP_MAGIC))
return -1;
#else
if (xstate->check_signature) {
if (aux && aux->check_signature) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
if (full_read(src_fd, &magic2, 2) != 2) {
bad_magic:
bb_error_msg("invalid magic");
return -1;
}
if (magic2 == COMPRESS_MAGIC) {
xstate->check_signature = 0;
return unpack_Z_stream(xstate);
aux->check_signature = 0;
return unpack_Z_stream(aux, src_fd, dst_fd);
}
if (magic2 != GZIP_MAGIC)
goto bad_magic;
@@ -1213,16 +1215,16 @@ unpack_gz_stream(transformer_state_t *xstate)
to_read = -1;
// bytebuffer_max = 0x8000;
bytebuffer = xmalloc(bytebuffer_max);
gunzip_src_fd = xstate->src_fd;
gunzip_src_fd = src_fd;
again:
if (!check_header_gzip(PASS_STATE xstate)) {
if (!check_header_gzip(PASS_STATE aux)) {
bb_error_msg("corrupted data");
total = -1;
goto ret;
}
n = inflate_unzip_internal(PASS_STATE xstate);
n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);
if (n < 0) {
total = -1;
goto ret;
+6 -6
View File
@@ -73,7 +73,7 @@
*/
IF_DESKTOP(long long) int FAST_FUNC
unpack_Z_stream(transformer_state_t *xstate)
unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
{
IF_DESKTOP(long long total_written = 0;)
IF_DESKTOP(long long) int retval = -1;
@@ -102,7 +102,7 @@ unpack_Z_stream(transformer_state_t *xstate)
/* block compress mode -C compatible with 2.0 */
int block_mode; /* = BLOCK_MODE; */
if (check_signature16(xstate, COMPRESS_MAGIC))
if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
return -1;
inbuf = xzalloc(IBUFSIZ + 64);
@@ -114,7 +114,7 @@ unpack_Z_stream(transformer_state_t *xstate)
/* xread isn't good here, we have to return - caller may want
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
if (full_read(src_fd, inbuf, 1) != 1) {
bb_error_msg("short read");
goto err;
}
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_state_t *xstate)
}
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
rsize = safe_read(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_state_t *xstate)
}
if (outpos >= OBUFSIZ) {
xtransformer_write(xstate, outbuf, outpos);
xwrite(dst_fd, outbuf, outpos);
IF_DESKTOP(total_written += outpos;)
outpos = 0;
}
@@ -301,7 +301,7 @@ unpack_Z_stream(transformer_state_t *xstate)
} while (rsize > 0);
if (outpos > 0) {
xtransformer_write(xstate, outbuf, outpos);
xwrite(dst_fd, outbuf, outpos);
IF_DESKTOP(total_written += outpos;)
}
+13 -22
View File
@@ -206,7 +206,7 @@ enum {
IF_DESKTOP(long long) int FAST_FUNC
unpack_lzma_stream(transformer_state_t *xstate)
unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
{
IF_DESKTOP(long long total_written = 0;)
lzma_header_t header;
@@ -214,6 +214,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
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;
@@ -223,7 +225,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
int state = 0;
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
|| header.pos >= (9 * 5 * 5)
) {
bb_error_msg("bad lzma header");
@@ -237,9 +239,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
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);
@@ -248,17 +247,13 @@ unpack_lzma_stream(transformer_state_t *xstate)
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
{
int num_probs;
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;
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); */
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
while (global_pos + buffer_pos < header.dst_size) {
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
@@ -306,7 +301,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
goto bad;
IF_DESKTOP(total_written += header.dict_size;)
}
@@ -315,7 +310,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
goto one_byte2;
#endif
} else {
int num_bits;
int offset;
uint16_t *prob2;
#define prob_len prob2
@@ -440,22 +434,19 @@ unpack_lzma_stream(transformer_state_t *xstate)
if (buffer_pos == header.dict_size) {
buffer_pos = 0;
global_pos += header.dict_size;
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
if (full_write(dst_fd, 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 (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
bad:
total_written = -1; /* failure */
}
+4 -4
View File
@@ -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_state_t *xstate)
unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
{
enum xz_ret xz_result;
struct xz_buf iobuf;
@@ -55,7 +55,7 @@ unpack_xz_stream(transformer_state_t *xstate)
iobuf.out = membuf + BUFSIZ;
iobuf.out_size = BUFSIZ;
if (!xstate || xstate->check_signature == 0) {
if (!aux || aux->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_state_t *xstate)
xz_result = X_OK;
while (1) {
if (iobuf.in_pos == iobuf.in_size) {
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
int rd = safe_read(src_fd, membuf, BUFSIZ);
if (rd < 0) {
bb_error_msg(bb_msg_read_error);
total = -1;
@@ -104,7 +104,7 @@ unpack_xz_stream(transformer_state_t *xstate)
// 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) {
xtransformer_write(xstate, iobuf.out, iobuf.out_pos);
xwrite(dst_fd, iobuf.out, iobuf.out_pos);
IF_DESKTOP(total += iobuf.out_pos;)
iobuf.out_pos = 0;
}
+2 -4
View File
@@ -115,9 +115,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
*/
p += len;
sz -= len;
if (
/** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */
(int)(sz|len) < 0 /* this works */
if ((int)sz < 0
|| len == 0
|| errno != EINVAL
|| *end != ' '
@@ -243,7 +241,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_compressed:*/ 0) != 0)
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
err:
bb_error_msg_and_die("invalid tar magic");
archive_handle->offset = 0;
+1 -1
View File
@@ -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;
fork_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+1 -1
View File
@@ -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;
fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+1 -1
View File
@@ -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;
fork_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+46 -172
View File
@@ -6,19 +6,19 @@
#include "libbb.h"
#include "bb_archive.h"
void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
{
memset(xstate, 0, sizeof(*xstate));
memset(aux, 0, sizeof(*aux));
}
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
{
if (xstate->check_signature) {
if (aux && aux->check_signature) {
uint16_t magic2;
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
bb_error_msg("invalid magic");
#if 0 /* possible future extension */
if (xstate->check_signature > 1)
if (aux->check_signature > 1)
xfunc_die();
#endif
return -1;
@@ -27,47 +27,6 @@ int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
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;
@@ -101,12 +60,12 @@ void check_errors_in_children(int signo)
/* transformer(), more than meets the eye */
#if BB_MMU
void FAST_FUNC fork_transformer(int fd,
void FAST_FUNC open_transformer(int fd,
int check_signature,
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
)
#else
void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
void FAST_FUNC open_transformer(int fd, const char *transform_prog)
#endif
{
struct fd_pair fd_pipe;
@@ -121,12 +80,10 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
#if BB_MMU
{
IF_DESKTOP(long long) int r;
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);
transformer_aux_data_t aux;
init_transformer_aux_data(&aux);
aux.check_signature = check_signature;
r = transformer(&aux, fd, fd_pipe.wr);
if (ENABLE_FEATURE_CLEAN_UP) {
close(fd_pipe.wr); /* send EOF */
close(fd);
@@ -161,19 +118,16 @@ void FAST_FUNC fork_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.
*/
static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
{
union {
uint8_t b[4];
uint16_t b16[2];
uint32_t b32[1];
} magic;
int offset;
transformer_state_t *xstate;
offset = -2;
xstate = xzalloc(sizeof(*xstate));
xstate->src_fd = fd;
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;)
/* .gz and .bz2 both have 2-byte signature, and their
* unpack_XXX_stream wants this header skipped. */
@@ -181,15 +135,15 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
if (ENABLE_FEATURE_SEAMLESS_GZ
&& magic.b16[0] == GZIP_MAGIC
) {
xstate->xformer = unpack_gz_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
USE_FOR_MMU(xformer = unpack_gz_stream;)
USE_FOR_NOMMU(xformer_prog = "gunzip";)
goto found_magic;
}
if (ENABLE_FEATURE_SEAMLESS_BZ2
&& magic.b16[0] == BZIP2_MAGIC
) {
xstate->xformer = unpack_bz2_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
USE_FOR_MMU(xformer = unpack_bz2_stream;)
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
goto found_magic;
}
if (ENABLE_FEATURE_SEAMLESS_XZ
@@ -198,146 +152,68 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
offset = -6;
xread(fd, magic.b32, sizeof(magic.b32[0]));
if (magic.b32[0] == XZ_MAGIC2) {
xstate->xformer = unpack_xz_stream;
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
USE_FOR_MMU(xformer = unpack_xz_stream;)
USE_FOR_NOMMU(xformer_prog = "unxz";)
goto found_magic;
}
}
/* No known magic seen */
if (fail_if_not_compressed)
if (fail_if_not_detected)
bb_error_msg_and_die("no gzip"
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
IF_FEATURE_SEAMLESS_XZ("/xz")
" magic");
/* 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.
*/
xlseek(fd, offset, SEEK_CUR);
return 1;
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;
}
found_magic:
# if BB_MMU
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
open_transformer_with_no_sig(fd, xformer);
# else
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
/* NOMMU version of open_transformer execs
* an external unzipper that wants
* file position at the start of the file */
xlseek(fd, offset, SEEK_CUR);
open_transformer_with_sig(fd, xformer, xformer_prog);
# endif
free(xstate);
return 0;
}
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
int FAST_FUNC open_zipped(const char *fname)
{
transformer_state_t *xstate;
int fd;
fd = open(fname, O_RDONLY);
if (fd < 0)
return NULL;
return fd;
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;
open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
return fd;
}
}
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
if ((ENABLE_FEATURE_SEAMLESS_GZ)
|| (ENABLE_FEATURE_SEAMLESS_BZ2)
|| (ENABLE_FEATURE_SEAMLESS_XZ)
) {
setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
}
/* 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, /*fail_if_not_compressed:*/ 0);
fd = open_zipped(fname);
if (fd < 0)
return NULL;
@@ -345,8 +221,6 @@ 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 */
return image;
}
+1 -1
View File
@@ -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_state_t *xstate UNUSED_PARAM)
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
{
if (option_mask32 & OPT_DECOMPRESS)
return do_lzo_decompress();
+1 -1
View File
@@ -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_compressed:*/ 1);
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1);
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
}
+1 -1
View File
@@ -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_compressed:*/ 1);
setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
bb_error_msg_and_die("error unpacking");
+45 -33
View File
@@ -160,6 +160,13 @@
#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
/*
@@ -614,12 +621,21 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
return TRUE;
}
#if SEAMLESS_COMPRESSION
#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
/* Don't inline: vfork scares gcc and pessimizes code */
static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
static void NOINLINE vfork_compressor(int tar_fd, int 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
@@ -633,6 +649,11 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *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) {
@@ -648,7 +669,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
xmove_fd(gzipDataPipe.rd, 0);
xmove_fd(tar_fd, 1);
/* exec gzip/bzip2 program/applet */
BB_EXECLP(gzip, gzip, "-f", (char *)0);
BB_EXECLP(zip_exec, zip_exec, "-f", (char *)0);
vfork_exec_errno = errno;
_exit(EXIT_FAILURE);
}
@@ -671,21 +692,16 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
# endif
if (vfork_exec_errno) {
errno = vfork_exec_errno;
bb_perror_msg_and_die("can't execute '%s'", gzip);
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
}
}
#endif /* SEAMLESS_COMPRESSION */
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
#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, const char *gzip)
const llist_t *exclude, int gzip)
{
int errorFlag = FALSE;
struct TarBallInfo tbInfo;
@@ -698,7 +714,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 SEAMLESS_COMPRESSION
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
if (gzip)
vfork_compressor(tbInfo.tarFd, gzip);
#endif
@@ -733,7 +749,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
if (errorFlag)
bb_error_msg("error exit delayed from previous errors");
#if SEAMLESS_COMPRESSION
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
if (gzip) {
int status;
if (safe_waitpid(-1, &status, 0) == -1)
@@ -745,9 +761,11 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
#endif
return errorFlag;
}
#else /* !FEATURE_TAR_CREATE */
# define writeTarFile(...) 0
#endif
#else
int writeTarFile(int tar_fd, int verboseFlag,
int recurseFlags, const llist_t *include,
const llist_t *exclude, int gzip);
#endif /* FEATURE_TAR_CREATE */
#if ENABLE_FEATURE_TAR_FROM
static llist_t *append_file_list_to_list(llist_t *list)
@@ -1119,7 +1137,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, /*fail_if_not_compressed:*/ 0);
tar_handle->src_fd = open_zipped(tar_filename);
if (tar_handle->src_fd < 0)
bb_perror_msg_and_die("can't open '%s'", tar_filename);
} else {
@@ -1131,24 +1149,18 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
if (base_dir)
xchdir(base_dir);
//if (SEAMLESS_COMPRESSION)
//if (SEAMLESS_COMPRESSION || OPT_COMPRESS)
// /* 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 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";
#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;
#endif
/* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tar_handle->src_fd, verboseFlag,
@@ -1159,7 +1171,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_state_t *xstate);)
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;)
if (opt & OPT_COMPRESS)
@@ -1178,7 +1190,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
USE_FOR_MMU(xformer = unpack_xz_stream;)
USE_FOR_NOMMU(xformer_prog = "unxz";)
fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
open_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 */
+6 -8
View File
@@ -280,19 +280,17 @@ 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_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)
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)
bb_error_msg_and_die("inflate error");
/* Validate decompression - crc */
if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
if (zip_header->formatted.crc32 != (aux.crc32 ^ 0xffffffffL)) {
bb_error_msg_and_die("crc error");
}
/* Validate decompression - size */
if (zip_header->formatted.ucmpsize != xstate.bytes_out) {
if (zip_header->formatted.ucmpsize != aux.bytes_out) {
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_error_msg("bad length");
+2 -2
View File
@@ -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. Default:0 (current console)"
//usage: "Redirect the kernel output to console N (0 for current)"
#include "libbb.h"
+1 -12
View File
@@ -633,13 +633,12 @@ config FEATURE_FANCY_TAIL
default y
depends on TAIL
help
The options (-q, -s, -v and -F) are provided by GNU tail, but
The options (-q, -s, and -v) 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"
@@ -739,16 +738,6 @@ 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
+8 -10
View File
@@ -20,22 +20,20 @@
#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
View File
@@ -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"
+1
View File
@@ -79,6 +79,7 @@ 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
+8 -28
View File
@@ -25,7 +25,6 @@
//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"
@@ -36,7 +35,6 @@
//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"
@@ -85,12 +83,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
enum {
OPT_KILO = (1 << 0),
OPT_POSIX = (1 << 1),
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,
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,
};
const char *disp_units_hdr = NULL;
char *chp;
@@ -102,7 +99,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, "kPT"
opt = getopt32(argv, "kP"
IF_FEATURE_DF_FANCY("aiB:")
IF_FEATURE_HUMAN_READABLE("hm")
IF_FEATURE_DF_FANCY(, &chp));
@@ -137,11 +134,8 @@ int df_main(int argc UNUSED_PARAM, char **argv)
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
#endif
}
printf("Filesystem %s%-15sUsed Available %s Mounted on\n",
(opt & OPT_FSTYPE) ? "Type " : "",
disp_units_hdr,
(opt & OPT_POSIX) ? "Capacity" : "Use%");
printf("Filesystem %-15sUsed Available %s Mounted on\n",
disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%");
mount_table = NULL;
argv += optind;
@@ -154,7 +148,6 @@ 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);
@@ -177,7 +170,6 @@ 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);
@@ -226,22 +218,10 @@ 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
+18 -33
View File
@@ -8,7 +8,7 @@
/* -v, -b, -c are ignored */
//usage:#define install_trivial_usage
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST"
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST"
//usage:#define install_full_usage "\n\n"
//usage: "Copy files and set attributes\n"
//usage: "\n -c Just copy (default)"
@@ -19,7 +19,6 @@
//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: )
@@ -29,16 +28,12 @@
#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
@@ -94,11 +89,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;
int isdir = 0;
#if ENABLE_SELINUX
security_context_t scontext;
bool use_default_selinux_context = 1;
@@ -114,22 +109,21 @@ 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 << 11,
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
OPT_SET_SECURITY_CONTEXT = 1 << 10,
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
#endif
};
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
applet_long_options = install_longopts;
#endif
opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
opt_complementary = "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:t:" IF_SELINUX("Z:"),
&gid_str, &mode_str, &uid_str, &last
IF_SELINUX(, &scontext));
opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
&gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
argc -= optind;
argv += optind;
@@ -147,11 +141,6 @@ 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) {
@@ -163,37 +152,33 @@ 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();
/* 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;
last = argv[argc - 1];
if (!(opts & OPT_DIRECTORY)) {
argv[argc - 1] = NULL;
min_args++;
/* coreutils install resolves link in this case, don't use lstat */
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
}
if (argc < 1)
if (argc < min_args)
bb_show_usage();
while ((arg = *argv++) != NULL) {
char *dest;
char *dest = last;
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, mkdir_flags)) {
if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
ret = EXIT_FAILURE;
goto next;
}
} else {
dest = last;
if (opts & OPT_MKDIR_LEADING) {
char *ddir = xstrdup(dest);
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
/* errors are not checked. copy_file
* will fail if dir is not created. */
free(ddir);
+1 -1
View File
@@ -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 || (G.all_fmt & LIST_BLOCKS))
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG)
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
#endif
if (nfiles > 0) {
+2 -6
View File
@@ -48,9 +48,7 @@ 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
@@ -69,7 +67,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:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext));
if (opt & 1) {
mode_t mmode = 0777;
if (!bb_parse_mode(smode, &mmode)) {
@@ -79,10 +77,8 @@ 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 & 8) {
if (opt & 4) {
selinux_or_die();
setfscreatecon_or_die(scontext);
}
+1 -7
View File
@@ -33,17 +33,13 @@ 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)
@@ -62,6 +58,7 @@ 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");
@@ -151,9 +148,6 @@ 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);
}
+1 -2
View File
@@ -38,6 +38,7 @@ 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)
@@ -46,8 +47,6 @@ 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 {
+2 -8
View File
@@ -31,7 +31,7 @@
#define PARENTS (1 << 0)
#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE)
//efine VERBOSE (1 << 1) //accepted but ignored
#define IGNORE_NON_EMPTY (1 << 2)
int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -44,12 +44,10 @@ 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
@@ -64,10 +62,6 @@ 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)
-153
View File
@@ -1,153 +0,0 @@
/* 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);
}
+3 -7
View File
@@ -225,7 +225,7 @@ static int compare_keys(const void *xarg, const void *yarg)
y = *(char **)yarg;
#endif
/* Perform actual comparison */
switch (flags & (FLAG_n | FLAG_M | FLAG_g)) {
switch (flags & 7) {
default:
bb_error_msg_and_die("unknown sort type");
break;
@@ -302,14 +302,10 @@ 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;
}
+2 -3
View File
@@ -655,7 +655,7 @@ static bool do_stat(const char *filename, const char *format)
);
# if ENABLE_SELINUX
if (option_mask32 & OPT_SELINUX)
printf(" %s\n", scontext);
printf(" %lc\n", *scontext);
else
bb_putchar('\n');
# endif
@@ -700,8 +700,7 @@ 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
if (option_mask32 & OPT_SELINUX)
printf(" S_Context: %s\n", scontext);
printf(" S_Context: %lc\n", *scontext);
# endif
printf("Access: %s\n", human_time(statbuf.st_atime));
printf("Modify: %s\n", human_time(statbuf.st_mtime));
+4 -3
View File
@@ -32,14 +32,15 @@
//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: "\n -c [+]N[kbm] Print last N bytes"
//usage: IF_FEATURE_FANCY_TAIL(
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
//usage: )
//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: )
+34 -35
View File
@@ -826,6 +826,7 @@ int test_main(int argc, char **argv)
{
int res;
const char *arg0;
// bool negate = 0;
arg0 = bb_basename(argv[0]);
if (arg0[0] == '[') {
@@ -843,7 +844,6 @@ 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,45 +862,43 @@ 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.
* 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;
/* 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;
}
}
/* Some complex expression. Undo '!' removal */
if (negate) {
negate = 0;
//argc++;
argv--;
}
#endif
args = argv;
res = !oexpr(check_operator(*args));
if (*args != NULL && *++args != NULL) {
@@ -913,5 +911,6 @@ int test_main(int argc, char **argv)
}
ret:
DEINIT_S();
// return negate ? !res : res;
return res;
}
+4 -6
View File
@@ -49,18 +49,16 @@
*/
//usage:#define uname_trivial_usage
//usage: "[-amnrspvio]"
//usage: "[-amnrspv]"
//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 Kernel release"
//usage: "\n -s Kernel name (default)"
//usage: "\n -r OS release"
//usage: "\n -s OS name (default)"
//usage: "\n -p Processor type"
//usage: "\n -v Kernel version"
//usage: "\n -i The hardware platform"
//usage: "\n -o OS name"
//usage: "\n -v OS version"
//usage:
//usage:#define uname_example_usage
//usage: "$ uname -a\n"
-34
View File
@@ -1,34 +0,0 @@
/* 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;
}
+61 -24
View File
@@ -1,9 +1,13 @@
/* 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
@@ -20,43 +24,76 @@
int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int which_main(int argc UNUSED_PARAM, char **argv)
{
const char *env_path;
int status = 0;
env_path = getenv("PATH");
if (!env_path)
env_path = bb_default_root_path;
IF_DESKTOP(int opt;)
int status = EXIT_SUCCESS;
char *path;
char *p;
opt_complementary = "-1"; /* at least one argument */
getopt32(argv, "a");
IF_DESKTOP(opt =) 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 {
int missing = 1;
/* If file contains a slash don't use PATH */
#if ENABLE_DESKTOP
/* Much bloat just to support -a */
if (strchr(*argv, '/')) {
if (file_is_executable(*argv)) {
missing = 0;
if (execable_file(*argv)) {
puts(*argv);
continue;
}
status = EXIT_FAILURE;
} else {
char *path;
char *tmp;
char *p;
char *path2 = xstrdup(path);
char *tmp = path2;
path = tmp = xstrdup(env_path);
while ((p = find_executable(*argv, &tmp)) != NULL) {
missing = 0;
p = find_execable(*argv, &tmp);
if (!p)
status = EXIT_FAILURE;
else {
print:
puts(p);
free(p);
if (!option_mask32) /* -a not set */
break;
if (opt) {
/* -a: show matches in all PATH components */
if (tmp) {
p = find_execable(*argv, &tmp);
if (p)
goto print;
}
}
}
free(path);
free(path2);
}
status |= missing;
} while (*++argv);
#else
/* Just ignoring -a */
if (strchr(*argv, '/')) {
if (execable_file(*argv)) {
puts(*argv);
continue;
}
} else {
char *path2 = xstrdup(path);
char *tmp = path2;
p = find_execable(*argv, &tmp);
free(path2);
if (p) {
puts(p);
free(p);
continue;
}
}
status = EXIT_FAILURE;
#endif
} while (*(++argv) != NULL);
return status;
fflush_stdout_and_exit(status);
}
+1 -1
View File
@@ -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 (executable_exists(ext_dhcp_clients[i].name))
if (exists_execable(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");
+1 -9
View File
@@ -103,15 +103,7 @@ 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(). Another variation is
to use stack:
int <applet>_main(...)
{
#undef G
struct globals G;
memset(&G, 0, sizeof(G));
SET_PTR_TO_GLOBALS(&G);
Typically it is done in <applet>_main().
Now you can reference "globals" by G.a, G.buf and so on, in any function.
-2
View File
@@ -45,8 +45,6 @@ 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),
+40 -64
View File
@@ -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 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.
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.
For a new applet mu, here is the code that would go in mu.c:
(libbb.h already includes most usual header files. You do not need
(busybox.h already includes most usual header files. You do not need
#include <stdio.h> etc...)
@@ -41,22 +41,6 @@ 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)
{
@@ -106,8 +90,6 @@ 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;
@@ -115,7 +97,9 @@ int function(char *a)
----end example code------
Remember about the kbuild snippet.
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.
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
@@ -125,68 +109,60 @@ 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.
Add the kbuild snippet to the .c file:
Make sure you find the appropriate places in the files, the applets are
sorted alphabetically.
//kbuild:lib-$(CONFIG_MU) += mu.o
Add the applet to Kbuild.src in the chosen directory:
Add the config snippet to the .c file:
lib-$(CONFIG_MU) += mu.o
//config:config MU
//config: bool "MU"
//config: default y
//config: help
//config: Returns an indeterminate value.
Add the applet to Config.src in the chosen directory:
config MU
bool "MU"
default n
help
Returns an indeterminate value.
Usage String(s)
---------------
Next, add usage information for your applet to the .c file.
Next, add usage information for you applet to include/usage.src.h.
This should look like the following:
//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: ...
#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" \
...
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.
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.)
Header Files
------------
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.
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:
//applet:IF_MU(APPLET(mu, BB_DIR_USR_BIN, BB_SUID_DROP))
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' */
The Grand Announcement
-50
View File
@@ -1,50 +0,0 @@
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.
-2
View File
@@ -1540,14 +1540,12 @@ 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 */
+3 -10
View File
@@ -395,9 +395,7 @@ 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] != '^') {
@@ -405,7 +403,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 - 1;
idx = pos - substr;
}
continue;
}
@@ -445,7 +443,6 @@ 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");
}
}
@@ -1522,16 +1519,12 @@ 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);
+241 -649
View File
File diff suppressed because it is too large. Load diff
+7 -11
View File
@@ -22,14 +22,10 @@ then
done
fi
# 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
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
+7 -11
View File
@@ -22,14 +22,10 @@ then
done
fi
# 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
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
+2 -11
View File
@@ -9,15 +9,6 @@ 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 -
@@ -56,8 +47,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
-5
View File
@@ -1,5 +0,0 @@
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.
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
-5
View File
@@ -1,5 +0,0 @@
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.
+50 -149
View File
@@ -137,16 +137,6 @@
//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
@@ -329,9 +319,6 @@
//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: )
@@ -350,12 +337,8 @@
# define FNM_CASEFOLD 0
#endif
#if 1
# define dbg(...) ((void)0)
#else
# define dbg(...) bb_error_msg(__VA_ARGS__)
#endif
#define dbg(...) ((void)0)
/* #define dbg(...) bb_error_msg(__VA_ARGS__) */
/* This is a NOEXEC applet. Be very careful! */
@@ -392,20 +375,7 @@ 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; /* -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_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
IF_FEATURE_FIND_LINKS( ACTS(links, char links_char; int links_count;))
@@ -419,7 +389,6 @@ 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 { \
@@ -429,11 +398,40 @@ 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)
@@ -484,6 +482,7 @@ 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)
{
@@ -558,8 +557,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 == '+' || ap->perm_char == '/')
/* -perm +mode: at least one of perm_mask bits are set */
if (ap->perm_char == '+')
return (statbuf->st_mode & ap->perm_mask) != 0;
/* -perm -mode: all of perm_mask are set */
if (ap->perm_char == '-')
@@ -607,57 +606,17 @@ ACTF(inum)
}
#endif
#if ENABLE_FEATURE_FIND_EXEC
static int do_exec(action_exec *ap, const char *fileName)
ACTF(exec)
{
int i, rc;
# 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
#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 */
rc = spawn_and_wait(argv);
if (rc < 0)
@@ -668,48 +627,6 @@ static int do_exec(action_exec *ap, const char *fileName)
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)
@@ -1150,7 +1067,6 @@ 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);
@@ -1163,13 +1079,10 @@ 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++;
@@ -1179,17 +1092,8 @@ 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_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
while (i--)
ap->subst_count[i] = count_subst(ap->exec_argv[i]);
}
#endif
#if ENABLE_FEATURE_FIND_PAREN
@@ -1252,14 +1156,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 = (arg1[0] == '/' ? arg1+1 : plus_minus_num(arg1));
arg1 = 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);
@@ -1461,11 +1365,8 @@ 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;
}
+15 -20
View File
@@ -375,8 +375,6 @@ static int grep_file(FILE *file)
} else {
#if ENABLE_EXTRA_COMPAT
unsigned start_pos;
#else
int match_flg;
#endif
char *match_at;
@@ -394,7 +392,6 @@ 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
@@ -403,7 +400,7 @@ static int grep_file(FILE *file)
//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, match_flg) == 0
regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
#else
re_search(&gl->compiled_regex, match_at, line_len,
start_pos, /*range:*/ line_len,
@@ -418,15 +415,13 @@ static int grep_file(FILE *file)
found = 1;
} else {
char c = ' ';
if (match_at > line || gl->matched_range.rm_so != 0) {
if (gl->matched_range.rm_so)
c = match_at[gl->matched_range.rm_so - 1];
}
if (!isalnum(c) && c != '_') {
c = match_at[gl->matched_range.rm_eo];
}
if (!isalnum(c) && c != '_') {
found = 1;
} else {
if (!c || (!isalnum(c) && c != '_')) {
found = 1;
} else {
/*
* Why check gl->matched_range.rm_eo?
* Zero-length match makes -w skip the line:
@@ -435,17 +430,17 @@ static int grep_file(FILE *file)
* 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;
}
if (gl->matched_range.rm_eo != 0) {
match_at += gl->matched_range.rm_eo;
goto opt_w_again;
}
#else
if (gl->matched_range.rm_eo > start_pos) {
start_pos = gl->matched_range.rm_eo;
goto opt_w_again;
}
if (gl->matched_range.rm_eo > start_pos) {
start_pos = gl->matched_range.rm_eo;
goto opt_w_again;
}
#endif
}
}
}
}
@@ -668,7 +663,7 @@ static int grep_dir(const char *dir)
int matched = 0;
recursive_action(dir,
/* recurse=yes */ ACTION_RECURSE |
/* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
/* followLinks=no */
/* depthFirst=yes */ ACTION_DEPTHFIRST,
/* fileAction= */ file_action_grep,
/* dirAction= */ NULL,
+42 -137
View File
@@ -53,13 +53,6 @@
//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))
@@ -92,22 +85,19 @@
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;
@@ -311,7 +301,7 @@ static char* FAST_FUNC process0_stdin(int n_max_chars, int n_max_arg, char *buf)
c = '\0';
}
*p++ = c;
if (c == '\0') { /* NUL or EOF detected */
if (c == '\0') { /* word's delimiter or EOF detected */
/* A full word is loaded */
store_param(s);
dbg_msg("args[]:'%s'", s);
@@ -333,71 +323,10 @@ 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 user responds affirmatively, return true;
* otherwise, return false. Uses "/dev/tty", not stdin.
*/
if the user responds affirmatively, return true;
otherwise, return false. Uses "/dev/tty", not stdin. */
static int xargs_ask_confirmation(void)
{
FILE *tty_stream;
@@ -431,9 +360,6 @@ 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: )
@@ -452,8 +378,6 @@ 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 ,
@@ -464,14 +388,11 @@ 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_REPL_STR( "I:i::")
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0")
int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int xargs_main(int argc, char **argv)
@@ -484,8 +405,7 @@ int xargs_main(int argc, char **argv)
unsigned opt;
int n_max_chars;
int n_max_arg;
#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM \
|| ENABLE_FEATURE_XARGS_SUPPORT_REPL_STR
#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
char* FAST_FUNC (*read_args)(int, int, char*) = process_stdin;
#else
#define read_args process_stdin
@@ -499,10 +419,7 @@ 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
IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str)
);
opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &G.eof_str, &G.eof_str);
/* -E ""? You may wonder why not just omit -E?
* This is used for portability:
@@ -510,10 +427,8 @@ 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_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\0';)
}
if (opt & OPT_ZEROTERM)
IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin);
argv += optind;
argc -= optind;
@@ -523,7 +438,12 @@ 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
@@ -531,15 +451,16 @@ 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".
*/
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;
{
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;
}
if (opt & OPT_UPTO_SIZE) {
n_max_chars = xatou_range(max_chars, 1, INT_MAX);
}
@@ -565,36 +486,20 @@ int xargs_main(int argc, char **argv)
/* if (n_max_arg > n_max_chars) n_max_arg = n_max_chars */
}
#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];
}
/* 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;
+27 -25
View File
@@ -8,7 +8,7 @@
/*
name - applet name as it is typed on command line
help - applet name, converted to C (ether-wake: help = ether_wake)
name2 - applet name, converted to C (ether-wake: name2 = 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,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;
# 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;
#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(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(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,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)
# 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)
#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,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)
# 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)
#elif defined(MAKE_LINKS)
# define APPLET(name,l,c) 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
# 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
#elif defined(MAKE_SUID)
# define APPLET(name,l,s) 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
# 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
#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,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 },
# 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 },
#endif
#if ENABLE_INSTALL_NO_USR
@@ -104,6 +104,7 @@ 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))
@@ -342,6 +343,7 @@ 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))
@@ -389,7 +391,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) && !defined(MAKE_USAGE) \
#if !defined(PROTOTYPES) && !defined(NAME_MAIN_CNAME) && !defined(MAKE_USAGE) \
&& !defined(MAKE_LINKS) && !defined(MAKE_SUID)
};
#endif
+18 -32
View File
@@ -203,57 +203,43 @@ 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_state_t {
typedef struct transformer_aux_data_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_state_t;
} transformer_aux_data_t;
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;
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;
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;
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;
char* append_ext(char *filename, const char *expected_ext) FAST_FUNC;
int bbunpack(char **argv,
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
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 fork_transformer(int fd,
void open_transformer(int fd,
int check_signature,
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
) FAST_FUNC;
#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))
#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))
#else
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 */
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 */
#endif
+9 -166
View File
@@ -334,8 +334,6 @@ 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;
@@ -390,8 +388,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;
int ndelay_on(int fd) FAST_FUNC;
int ndelay_off(int fd) FAST_FUNC;
void ndelay_on(int fd) FAST_FUNC;
void 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;
@@ -652,8 +650,6 @@ 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;
@@ -731,18 +727,6 @@ 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 \
@@ -752,15 +736,14 @@ unsigned bb_clk_tck(void) FAST_FUNC;
#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_compressed) FAST_FUNC;
extern int setup_unzip_on_fd(int fd, int fail_if_not_detected) FAST_FUNC;
/* Autodetects .gz etc */
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;
extern int open_zipped(const char *fname) FAST_FUNC;
#else
# define setup_unzip_on_fd(...) (0)
# 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))
# define open_zipped(fname) open((fname), O_RDONLY);
#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,
@@ -927,9 +910,9 @@ void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const
#endif
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;
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;
/* BB_EXECxx always execs (it's not doing NOFORK/NOEXEC stuff),
* but it may exec busybox and call applet instead of searching PATH.
@@ -1089,7 +1072,6 @@ 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;
@@ -1108,7 +1090,6 @@ 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
@@ -1271,9 +1252,7 @@ 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;
@@ -1323,7 +1302,6 @@ 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 */
@@ -1949,141 +1927,6 @@ 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
+8 -39
View File
@@ -76,9 +76,6 @@
# 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)
@@ -376,7 +373,6 @@ 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
@@ -385,15 +381,12 @@ typedef unsigned smalluint;
#define HAVE_NET_ETHERNET_H 1
#define HAVE_SYS_STATFS_H 1
#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
#if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
# undef HAVE_STRVERSCMP
#endif
#if defined(__dietlibc__)
# undef HAVE_STRCHRNUL
#endif
#if defined(__WATCOMC__)
@@ -426,7 +419,7 @@ typedef unsigned smalluint;
/* These BSD-derived OSes share many similarities */
#if (defined __digital__ && defined __unix__) \
|| defined __APPLE__ \
|| defined __OpenBSD__ || defined __NetBSD__
|| defined __FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
# undef HAVE_CLEARENV
# undef HAVE_FDATASYNC
# undef HAVE_GETLINE
@@ -441,30 +434,10 @@ typedef unsigned smalluint;
# undef HAVE_UNLOCKED_LINE_OPS
#endif
#if defined(__dietlibc__)
#if defined(__FreeBSD__) || defined(__APPLE__)
# 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
@@ -530,10 +503,6 @@ 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
+18 -30
View File
@@ -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 exec_restart_action(void)
static void restart_handler(int sig UNUSED_PARAM)
{
struct init_action *a;
@@ -975,20 +975,6 @@ 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);
}
}
}
@@ -1084,7 +1070,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 sysinit actions then! */
/* If you do, consider adding swapon to sysinot actions then! */
/* struct sysinfo is linux-specific */
# ifdef __linux__
/* Make sure there is enough memory to do something useful. */
@@ -1148,6 +1134,14 @@ 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);
@@ -1162,24 +1156,18 @@ int init_main(int argc UNUSED_PARAM, char **argv)
*/
sigaction_set(SIGSTOP, &sa); /* pause */
/* These signals must interrupt wait(),
/* SIGINT (Ctrl-Alt-Del) must interrupt wait(),
* setting handler without SA_RESTART flag.
*/
bb_signals_recursive_norestart(0
+ (1 << SIGINT) /* Ctrl-Alt-Del */
+ (1 << SIGQUIT) /* re-exec another init */
#ifdef SIGPWR
+ (1 << SIGPWR) /* halt */
#endif
+ (1 << SIGUSR1) /* halt */
+ (1 << SIGTERM) /* reboot */
+ (1 << SIGUSR2) /* poweroff */
#if ENABLE_FEATURE_USE_INITTAB
+ (1 << SIGHUP) /* reread /etc/inittab */
#endif
, record_signo);
bb_signals_recursive_norestart((1 << SIGINT), 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);
+1 -7
View File
@@ -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 += executable.o
lib-y += execable.o
lib-y += fclose_nonstdin.o
lib-y += fflush_stdout_and_exit.o
lib-y += fgets_str.o
@@ -92,7 +92,6 @@ 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
@@ -142,7 +141,6 @@ 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
@@ -151,7 +149,6 @@ 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
@@ -188,6 +185,3 @@ 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
+13 -28
View File
@@ -184,7 +184,8 @@ void lbb_prepare(const char *applet
#endif
applet_name = applet;
if (ENABLE_LOCALE_SUPPORT)
/* Set locale for everybody except 'init' */
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
setlocale(LC_ALL, "");
#if ENABLE_FEATURE_INDIVIDUAL
@@ -605,11 +606,7 @@ static void install_links(const char *busybox, int use_symbolic_links,
}
}
# else
static void install_links(const char *busybox UNUSED_PARAM,
int use_symbolic_links UNUSED_PARAM,
char *custom_install_dir UNUSED_PARAM)
{
}
# define install_links(x,y,z) ((void)0)
# endif
/* If we were called as "busybox..." */
@@ -733,8 +730,7 @@ 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");
/* POSIX: "If a command is not found, the exit status shall be 127" */
exit(127);
xfunc_die();
}
void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
@@ -746,25 +742,15 @@ 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 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;
}
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;
bb_show_usage();
}
}
@@ -839,7 +825,6 @@ 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");
/* POSIX: "If a command is not found, the exit status shall be 127" */
exit(127);
xfunc_die();
#endif
}
+1 -4
View File
@@ -30,12 +30,9 @@ 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;
-90
View File
@@ -1,90 +0,0 @@
/* 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;
}
-4
View File
@@ -389,9 +389,5 @@ 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;
}
+32 -57
View File
@@ -8,20 +8,6 @@
*/
#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
@@ -32,13 +18,12 @@ 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;
ssize_t sendfile_sz;
#if CONFIG_FEATURE_COPYBUF_KB > 4
char *buffer = buffer; /* for compiler */
int buffer_size = 0;
#else
#if CONFIG_FEATURE_COPYBUF_KB <= 4
char buffer[CONFIG_FEATURE_COPYBUF_KB * 1024];
enum { buffer_size = sizeof(buffer) };
#else
char *buffer;
int buffer_size;
#endif
if (size < 0) {
@@ -46,58 +31,46 @@ 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 = SENDFILE_BIGBUF;
size = buffer_size;
status = 1; /* copy until eof */
}
while (1) {
ssize_t rd;
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:
rd = safe_read(src_fd, buffer, size > buffer_size ? buffer_size : size);
if (!rd) { /* eof - all done */
status = 0;
break;
}
if (rd < 0) {
bb_perror_msg(bb_msg_read_error);
break;
}
/* dst_fd == -1 is a fake, else... */
if (dst_fd >= 0 && !sendfile_sz) {
if (dst_fd >= 0) {
ssize_t wr = full_write(dst_fd, buffer, rd);
if (wr < rd) {
if (!continue_on_write_error) {
@@ -119,8 +92,10 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
}
out:
if (buffer_size > 4 * 1024)
#if CONFIG_FEATURE_COPYBUF_KB > 4
if (buffer_size != 4 * 1024)
munmap(buffer, buffer_size);
#endif
return status ? -1 : total;
}
+29 -67
View File
@@ -30,63 +30,6 @@
#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.
@@ -98,23 +41,42 @@ int FAST_FUNC check_password(const struct passwd *pw, const char *plaintext)
int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw,
int timeout, const char *prompt)
{
IF_FEATURE_SHADOWPASSWDS(char buffer[SHADOW_BUFSIZE];)
char *plaintext;
const char *pw_pass;
char *unencrypted, *encrypted;
const char *correct;
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
pw_pass = get_passwd(pw, buffer);
if (!pw_pass[0]) /* empty password field? */
if (!correct[0]) /* empty password field? */
return 1;
plaintext = bb_ask(STDIN_FILENO, timeout, prompt);
if (!plaintext) {
fake_it:
unencrypted = bb_ask(STDIN_FILENO, timeout, prompt);
if (!unencrypted) {
/* EOF (such as ^D) or error (such as ^C) or timeout */
return -1;
}
r = check_password(pw, plaintext);
nuke_str(plaintext);
encrypted = pw_encrypt(unencrypted, correct, 1);
r = (strcmp(encrypted, correct) == 0);
free(encrypted);
nuke_str(unencrypted);
return r;
}
+17 -23
View File
@@ -13,7 +13,7 @@
* return 1 if found;
* return 0 otherwise;
*/
int FAST_FUNC file_is_executable(const char *name)
int FAST_FUNC execable_file(const char *name)
{
struct stat s;
return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode));
@@ -23,21 +23,13 @@ int FAST_FUNC file_is_executable(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_executable again with this PATHp to continue
* you may call find_execable 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_executable(const char *filename, char **PATHp)
char* FAST_FUNC find_execable(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;
@@ -45,15 +37,14 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp)
n = strchr(p, ':');
if (n)
*n++ = '\0';
p = concat_path_file(
p[0] ? p : ".", /* handle "::" case */
filename
);
if (file_is_executable(p)) {
*PATHp = n;
return p;
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);
}
free(p);
p = n;
} /* on loop exit p == NULL */
return p;
@@ -63,14 +54,17 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp)
* return 1 if found;
* return 0 otherwise;
*/
int FAST_FUNC executable_exists(const char *filename)
int FAST_FUNC exists_execable(const char *filename)
{
char *path = xstrdup(getenv("PATH"));
char *tmp = path;
char *ret = find_executable(filename, &tmp);
char *ret = find_execable(filename, &tmp);
free(path);
free(ret);
return ret != NULL;
if (ret) {
free(ret);
return 1;
}
return 0;
}
#if ENABLE_FEATURE_PREFER_APPLETS
+1 -1
View File
@@ -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
+19 -298
View File
@@ -926,81 +926,10 @@ 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().
*/
@@ -1008,179 +937,12 @@ static void sha3_process_block72(uint64_t *state)
{
enum { NROUNDS = 24 };
#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 */
/* 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.
*/
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,
@@ -1221,7 +983,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;
unsigned x, y;
unsigned round;
if (BB_BIG_ENDIAN) {
@@ -1283,62 +1045,22 @@ static void sha3_process_block72(uint64_t *state)
RhoPi_twice(20); RhoPi_twice(22);
#undef RhoPi_twice
}
/* Chi */
# if LONG_MAX > 0x7fffffff
for (x = 0; x <= 20; x += 5) {
for (y = 0; y <= 20; y += 5) {
uint64_t BC0, BC1, BC2, BC3, BC4;
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);
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);
}
# 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)
@@ -1350,7 +1072,6 @@ static void sha3_process_block72(uint64_t *state)
state[x] = SWAP_LE64(state[x]);
}
}
#endif
}
void FAST_FUNC sha3_begin(sha3_ctx_t *ctx)
+10 -26
View File
@@ -11,23 +11,14 @@
#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 311u /* Should be prime */
#define hash_inode(i) ((unsigned)(i) % HASH_SIZE)
#define HASH_SIZE 311 /* Should be prime */
#define hash_inode(i) ((i) % HASH_SIZE)
/* array of [HASH_SIZE] elements */
static ino_dev_hashtable_bucket_t **ino_dev_hashtable;
@@ -47,7 +38,6 @@ 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;
}
@@ -62,18 +52,17 @@ 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;
}
@@ -83,18 +72,13 @@ 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, *next;
ino_dev_hashtable_bucket_t *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;
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;
}
}
free(ino_dev_hashtable);
+3 -7
View File
@@ -2256,13 +2256,9 @@ 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|ICANON)) == ICANON
|| !(initial_settings.c_lflag & ECHO)
) {
/* 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").
*/
/* Happens when e.g. stty -echo was run before */
parse_and_put_prompt(prompt);
/* fflush_all(); - done by parse_and_put_prompt */
if (fgets(command, maxsize, stdin) == NULL)
@@ -2611,7 +2607,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, 50);
ic = lineedit_read_key(read_key_buffer, timeout);
switch (ic) {
//case KEYCODE_LEFT: - bash doesn't do this
case 'b':
-24
View File
@@ -1,24 +0,0 @@
/* 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
}
+6 -12
View File
@@ -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;
goto open_ffd;
ffd = open(file, mode);
}
return -errno;
if (ffd < 0)
return -errno;
}
/* Find a loop device. */
try = *device ? *device : dev;
/* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */
/* 1048575 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 = -1;
rc = -ENOENT;
break;
}
try_to_open:
@@ -131,14 +131,8 @@ 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 (errno == ENXIO) {
/* Happens if loop module is not loaded */
rc = -1;
break;
}
if (dfd < 0)
goto try_again;
}
rc = ioctl(dfd, BB_LOOP_GET_STATUS, &loopinfo);
-4
View File
@@ -99,10 +99,6 @@ 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) {
+1 -39
View File
@@ -76,7 +76,7 @@ static int string_checker(const char *p1, const char *p2)
ret |= string_checker_helper(p, p2);
/* clean up */
nuke_str(p);
memset(p, 0, size);
free(p);
return ret;
@@ -182,41 +182,3 @@ 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 */
-18
View File
@@ -17,24 +17,6 @@ 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)
{
+1 -8
View File
@@ -142,14 +142,7 @@ 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)
{
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 : "");
return xstrdup(crypt(clear, salt));
}
#endif
-8
View File
@@ -78,10 +78,6 @@ int FAST_FUNC remove_file(const char *path, int flags)
return -1;
}
if (flags & FILEUTILS_VERBOSE) {
printf("removed directory: '%s'\n", path);
}
return status;
}
@@ -102,9 +98,5 @@ int FAST_FUNC remove_file(const char *path, int flags)
return -1;
}
if (flags & FILEUTILS_VERBOSE) {
printf("removed '%s'\n", path);
}
return 0;
}
-45
View File
@@ -1,45 +0,0 @@
/* 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;
}
+10 -42
View File
@@ -33,55 +33,23 @@ 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)
goto try_name;
name = ""; /*else: we have rtc name, don't try other names */
for (;;) {
rtc = open_loop_on_busy(*default_rtc, flags);
if (!*default_rtc) {
*default_rtc = "/dev/rtc";
rtc = open(*default_rtc, flags);
if (rtc >= 0)
return rtc;
if (!name[0])
return xopen(*default_rtc, flags);
try_name:
*default_rtc = name;
name += strlen(name) + 1;
*default_rtc = "/dev/rtc0";
rtc = open(*default_rtc, flags);
if (rtc >= 0)
return rtc;
*default_rtc = "/dev/misc/rtc";
}
return xopen(*default_rtc, flags);
}
void FAST_FUNC rtc_read_tm(struct tm *ptm, int fd)
-5
View File
@@ -10,12 +10,7 @@
#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;
};
+12 -7
View File
@@ -7,7 +7,13 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#ifdef __DO_STRRSTR_TEST
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#else
#include "libbb.h"
#endif
/*
* The strrstr() function finds the last occurrence of the substring needle
@@ -28,9 +34,8 @@ char* FAST_FUNC strrstr(const char *haystack, const char *needle)
}
}
#if ENABLE_UNIT_TEST
BBUNIT_DEFINE_TEST(strrstr)
#ifdef __DO_STRRSTR_TEST
int main(int argc, char **argv)
{
static const struct {
const char *h, *n;
@@ -54,13 +59,13 @@ BBUNIT_DEFINE_TEST(strrstr)
i = 0;
while (i < sizeof(test_array) / sizeof(test_array[0])) {
const char *r = strrstr(test_array[i].h, test_array[i].n);
printf("'%s' vs. '%s': '%s' - ", test_array[i].h, test_array[i].n, r);
if (r == NULL)
r = test_array[i].h - 1;
BBUNIT_ASSERT_EQ(r, test_array[i].h + test_array[i].pos);
printf("%s\n", r == test_array[i].h + test_array[i].pos ? "PASSED" : "FAILED");
i++;
}
BBUNIT_ENDTEST;
return 0;
}
#endif /* ENABLE_UNIT_TEST */
#endif
-30
View File
@@ -1,30 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Various system configuration helpers.
*
* Copyright (C) 2014 Bartosz Golaszewski <bartekgola@gmail.com>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
#include "libbb.h"
#if !defined(bb_arg_max)
unsigned FAST_FUNC bb_arg_max(void)
{
long r = sysconf(_SC_ARG_MAX);
/* I've seen a version of uclibc which returned -1.
* Guard about it, and also avoid insanely large values
*/
if ((unsigned long)r > 64*1024*1024)
r = 64*1024*1024;
return r;
}
#endif
/* Return the number of clock ticks per second. */
unsigned FAST_FUNC bb_clk_tck(void)
{
return sysconf(_SC_CLK_TCK);
}
Loaded 100 of 193 files, more files were not shown because too many files have changed in this diff. Show more