Compare commits

...
7 Commits
Author SHA1 Message Date
Denys Vlasenko e58eac3373 bump version to 1.15.3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-12-12 22:18:18 +01:00
Denys Vlasenko 3e97eeb408 apply post-1.15.2 fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-12-12 22:17:44 +01:00
Denys Vlasenko 8cbc300d08 ash: fix compile breakage
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-10-08 03:18:51 +02:00
Denys Vlasenko 6f01ccffc2 bump version to 1.15.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-10-08 03:06:39 +02:00
Denys Vlasenko 4ac9819263 apply post-1.15.1 fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-10-08 03:06:04 +02:00
Denys Vlasenko 5b807cd5ac test: use index_in_strings
function                                             old     new   delta
ops_texts                                              -     124    +124
ops_table                                              -      80     +80
display_process_list                                1447    1448      +1
binop                                                525     523      -2
static.no_op                                           6       2      -4
check_operator                                        71      63      -8
ops                                                  240       -    -240
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 1/3 up/down: 205/-254)          Total: -49 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-09-12 22:38:26 +02:00
Denys Vlasenko d7686c8c2c Apply post-1.15.0 fixes; bump version to 1.15.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2009-09-12 17:57:19 +02:00
41 changed files with 1446 additions and 936 deletions

No files matched your search

+11 -2
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 15
SUBLEVEL = 0
SUBLEVEL = 3
EXTRAVERSION =
NAME = Unnamed
@@ -358,6 +358,15 @@ scripts_basic:
# To avoid any implicit rule to kick in, define an empty command.
scripts/basic/%: scripts_basic ;
# bbox: we have helpers in applets/
# we depend on scripts_basic, since scripts/basic/fixdep
# must be built before any other host prog
PHONY += applets_dir
applets_dir: scripts_basic
$(Q)$(MAKE) $(build)=applets
applets/%: applets_dir ;
PHONY += outputmakefile
# outputmakefile generates a Makefile in the output directory, if using a
# separate output directory. This allows convenient use of make in the
@@ -797,7 +806,7 @@ ifneq ($(KBUILD_MODULES),)
$(Q)rm -f $(MODVERDIR)/*
endif
archprepare: prepare1 scripts_basic
archprepare: prepare1 scripts_basic applets_dir
prepare0: archprepare FORCE
$(Q)$(MAKE) $(build)=.
+2 -2
View File
@@ -298,8 +298,8 @@ config FEATURE_LZMA_FAST
default n
depends on UNLZMA
help
This option reduces decompression time by about 25% at the cost of
a 1K bigger binary.
This option reduces decompression time by about 33% at the cost of
a 2K bigger binary.
config UNZIP
bool "unzip"
+1 -1
View File
@@ -132,7 +132,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
#endif
lchown(file_header->name, file_header->uid, file_header->gid);
}
if (S_ISLNK(file_header->mode)) {
if (!S_ISLNK(file_header->mode)) {
/* uclibc has no lchmod, glibc is even stranger -
* it has lchmod which seems to do nothing!
* so we use chmod... */
+96 -58
View File
@@ -8,15 +8,14 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include "unarchive.h"
#if ENABLE_FEATURE_LZMA_FAST
# define speed_inline ALWAYS_INLINE
# define size_inline
#else
# define speed_inline
# define size_inline ALWAYS_INLINE
#endif
@@ -45,8 +44,8 @@ typedef struct {
#define RC_MODEL_TOTAL_BITS 11
/* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
static size_inline void rc_read(rc_t *rc)
/* Called twice: once at startup and once in rc_normalize() */
static void rc_read(rc_t *rc)
{
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
if (buffer_size <= 0)
@@ -55,17 +54,8 @@ static size_inline void rc_read(rc_t *rc)
rc->buffer_end = RC_BUFFER + buffer_size;
}
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_1() */
static void rc_do_normalize(rc_t *rc)
{
if (rc->ptr >= rc->buffer_end)
rc_read(rc);
rc->range <<= 8;
rc->code = (rc->code << 8) | *rc->ptr++;
}
/* Called once */
static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
static rc_t* rc_init(int fd) /*, int buffer_size) */
{
int i;
rc_t *rc;
@@ -73,18 +63,17 @@ static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
rc = xmalloc(sizeof(*rc) + RC_BUFFER_SIZE);
rc->fd = fd;
/* rc->buffer_size = buffer_size; */
rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE;
rc->ptr = rc->buffer_end;
rc->code = 0;
rc->range = 0xFFFFFFFF;
for (i = 0; i < 5; i++) {
#if ENABLE_FEATURE_LZMA_FAST
if (rc->ptr >= rc->buffer_end)
rc_read(rc);
rc->code = (rc->code << 8) | *rc->ptr++;
#else
rc_do_normalize(rc);
#endif
}
rc->range = 0xFFFFFFFF;
return rc;
}
@@ -94,6 +83,14 @@ static ALWAYS_INLINE void rc_free(rc_t *rc)
free(rc);
}
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
static void rc_do_normalize(rc_t *rc)
{
if (rc->ptr >= rc->buffer_end)
rc_read(rc);
rc->range <<= 8;
rc->code = (rc->code << 8) | *rc->ptr++;
}
static ALWAYS_INLINE void rc_normalize(rc_t *rc)
{
if (rc->range < (1 << RC_TOP_BITS)) {
@@ -101,28 +98,49 @@ static ALWAYS_INLINE void rc_normalize(rc_t *rc)
}
}
/* rc_is_bit_1 is called 9 times */
static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
/* rc_is_bit_0 is called 9 times */
/* Why rc_is_bit_0_helper exists?
* Because we want to always expose (rc->code < rc->bound) to optimizer.
* Thus rc_is_bit_0 is always inlined, and rc_is_bit_0_helper is inlined
* only if we compile for speed.
*/
static speed_inline uint32_t rc_is_bit_0_helper(rc_t *rc, uint16_t *p)
{
rc_normalize(rc);
rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
if (rc->code < rc->bound) {
rc->range = rc->bound;
*p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
return 0;
}
return rc->bound;
}
static ALWAYS_INLINE int rc_is_bit_0(rc_t *rc, uint16_t *p)
{
uint32_t t = rc_is_bit_0_helper(rc, p);
return rc->code < t;
}
/* Called ~10 times, but very small, thus inlined */
static speed_inline void rc_update_bit_0(rc_t *rc, uint16_t *p)
{
rc->range = rc->bound;
*p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
}
static speed_inline void rc_update_bit_1(rc_t *rc, uint16_t *p)
{
rc->range -= rc->bound;
rc->code -= rc->bound;
*p -= *p >> RC_MOVE_BITS;
return 1;
}
/* Called 4 times in unlzma loop */
static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
static int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
{
int ret = rc_is_bit_1(rc, p);
*symbol = *symbol * 2 + ret;
return ret;
if (rc_is_bit_0(rc, p)) {
rc_update_bit_0(rc, p);
*symbol *= 2;
return 0;
} else {
rc_update_bit_1(rc, p);
*symbol = *symbol * 2 + 1;
return 1;
}
}
/* Called once */
@@ -248,13 +266,13 @@ unpack_lzma_stream(int src_fd, int dst_fd)
header.dst_size = SWAP_LE64(header.dst_size);
if (header.dict_size == 0)
header.dict_size++;
header.dict_size = 1;
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
p = xmalloc(num_probs * sizeof(*p));
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
for (i = 0; i < num_probs; i++)
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
@@ -264,8 +282,9 @@ unpack_lzma_stream(int src_fd, int dst_fd)
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
if (!rc_is_bit_1(rc, prob)) {
if (rc_is_bit_0(rc, prob)) {
mi = 1;
rc_update_bit_0(rc, prob);
prob = (p + LZMA_LITERAL
+ (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
+ (previous_byte >> (8 - lc))
@@ -321,21 +340,27 @@ unpack_lzma_stream(int src_fd, int dst_fd)
int offset;
uint16_t *prob_len;
rc_update_bit_1(rc, prob);
prob = p + LZMA_IS_REP + state;
if (!rc_is_bit_1(rc, prob)) {
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
rep3 = rep2;
rep2 = rep1;
rep1 = rep0;
state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
prob = p + LZMA_LEN_CODER;
} else {
prob += LZMA_IS_REP_G0 - LZMA_IS_REP;
if (!rc_is_bit_1(rc, prob)) {
rc_update_bit_1(rc, prob);
prob = p + LZMA_IS_REP_G0 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
prob = (p + LZMA_IS_REP_0_LONG
+ (state << LZMA_NUM_POS_BITS_MAX)
+ pos_state
);
if (!rc_is_bit_1(rc, prob)) {
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
#if ENABLE_FEATURE_LZMA_FAST
pos = buffer_pos - rep0;
@@ -347,16 +372,25 @@ unpack_lzma_stream(int src_fd, int dst_fd)
len = 1;
goto string;
#endif
} else {
rc_update_bit_1(rc, prob);
}
} else {
uint32_t distance;
prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
distance = rep1;
if (rc_is_bit_1(rc, prob)) {
prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
distance = rep2;
if (rc_is_bit_1(rc, prob)) {
rc_update_bit_1(rc, prob);
prob = p + LZMA_IS_REP_G1 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
distance = rep1;
} else {
rc_update_bit_1(rc, prob);
prob = p + LZMA_IS_REP_G2 + state;
if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob);
distance = rep2;
} else {
rc_update_bit_1(rc, prob);
distance = rep3;
rep3 = rep2;
}
@@ -370,20 +404,24 @@ unpack_lzma_stream(int src_fd, int dst_fd)
}
prob_len = prob + LZMA_LEN_CHOICE;
if (!rc_is_bit_1(rc, prob_len)) {
prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
+ (pos_state << LZMA_LEN_NUM_LOW_BITS);
if (rc_is_bit_0(rc, prob_len)) {
rc_update_bit_0(rc, prob_len);
prob_len = (prob + LZMA_LEN_LOW
+ (pos_state << LZMA_LEN_NUM_LOW_BITS));
offset = 0;
num_bits = LZMA_LEN_NUM_LOW_BITS;
} else {
prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
if (!rc_is_bit_1(rc, prob_len)) {
prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
+ (pos_state << LZMA_LEN_NUM_MID_BITS);
rc_update_bit_1(rc, prob_len);
prob_len = prob + LZMA_LEN_CHOICE_2;
if (rc_is_bit_0(rc, prob_len)) {
rc_update_bit_0(rc, prob_len);
prob_len = (prob + LZMA_LEN_MID
+ (pos_state << LZMA_LEN_NUM_MID_BITS));
offset = 1 << LZMA_LEN_NUM_LOW_BITS;
num_bits = LZMA_LEN_NUM_MID_BITS;
} else {
prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
rc_update_bit_1(rc, prob_len);
prob_len = prob + LZMA_LEN_HIGH;
offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
+ (1 << LZMA_LEN_NUM_MID_BITS));
num_bits = LZMA_LEN_NUM_HIGH_BITS;
@@ -400,20 +438,19 @@ unpack_lzma_stream(int src_fd, int dst_fd)
((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
LZMA_NUM_LEN_TO_POS_STATES - 1)
<< LZMA_NUM_POS_SLOT_BITS);
rc_bit_tree_decode(rc, prob,
LZMA_NUM_POS_SLOT_BITS, &pos_slot);
rep0 = pos_slot;
rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
&pos_slot);
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
num_bits = (pos_slot >> 1) - 1;
rep0 = 2 | (pos_slot & 1);
prob = p + LZMA_ALIGN;
if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
rep0 <<= num_bits;
prob += LZMA_SPEC_POS - LZMA_ALIGN - 1 + rep0 - pos_slot;
prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
} else {
num_bits -= LZMA_NUM_ALIGN_BITS;
while (num_bits--)
rep0 = (rep0 << 1) | rc_direct_bit(rc);
prob = p + LZMA_ALIGN;
rep0 <<= LZMA_NUM_ALIGN_BITS;
num_bits = LZMA_NUM_ALIGN_BITS;
}
@@ -424,7 +461,8 @@ unpack_lzma_stream(int src_fd, int dst_fd)
rep0 |= i;
i <<= 1;
}
}
} else
rep0 = pos_slot;
if (++rep0 == 0)
break;
}
+6 -5
View File
@@ -286,25 +286,26 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
}
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
if (flags & FLAG_NOERROR) /* Pre-zero the buffer if conv=noerror */
memset(ibuf, 0, ibs);
n = safe_read(ifd, ibuf, ibs);
if (n == 0)
break;
if (n < 0) {
/* "Bad block" */
if (!(flags & FLAG_NOERROR))
goto die_infile;
n = ibs;
bb_simple_perror_msg(infile);
/* GNU dd with conv=noerror skips over "bad blocks" */
/* GNU dd with conv=noerror skips over bad blocks */
xlseek(ifd, ibs, SEEK_CUR);
/* conv=noerror,sync writes NULs,
* conv=noerror just ignores input bad blocks */
n = 0;
}
if ((size_t)n == ibs)
G.in_full++;
else {
G.in_part++;
if (flags & FLAG_SYNC) {
memset(ibuf + n, '\0', ibs - n);
memset(ibuf + n, 0, ibs - n);
n = ibs;
}
}
+5 -1
View File
@@ -79,9 +79,13 @@ int split_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
if (argv[0]) {
int fd;
if (argv[1])
sfx = argv[1];
xmove_fd(xopen(argv[0], O_RDONLY), 0);
fd = open_or_warn_stdin(argv[0]);
if (fd == -1)
return EXIT_FAILURE;
xmove_fd(fd, STDIN_FILENO);
} else {
argv[0] = (char *) bb_msg_standard_input;
}
+95 -59
View File
@@ -222,7 +222,7 @@ static const char *const TOKSTR[] = {
#define unnest_msg_and_return(expr, ...) return expr
#endif
enum token_types {
enum {
UNOP,
BINOP,
BUNOP,
@@ -231,53 +231,96 @@ enum token_types {
};
struct operator_t {
char op_text[4];
unsigned char op_num, op_type;
};
static const struct operator_t ops[] = {
{ "-r", FILRD , UNOP },
{ "-w", FILWR , UNOP },
{ "-x", FILEX , UNOP },
{ "-e", FILEXIST, UNOP },
{ "-f", FILREG , UNOP },
{ "-d", FILDIR , UNOP },
{ "-c", FILCDEV , UNOP },
{ "-b", FILBDEV , UNOP },
{ "-p", FILFIFO , UNOP },
{ "-u", FILSUID , UNOP },
{ "-g", FILSGID , UNOP },
{ "-k", FILSTCK , UNOP },
{ "-s", FILGZ , UNOP },
{ "-t", FILTT , UNOP },
{ "-z", STREZ , UNOP },
{ "-n", STRNZ , UNOP },
{ "-h", FILSYM , UNOP }, /* for backwards compat */
static const struct operator_t ops_table[] = {
{ /* "-r" */ FILRD , UNOP },
{ /* "-w" */ FILWR , UNOP },
{ /* "-x" */ FILEX , UNOP },
{ /* "-e" */ FILEXIST, UNOP },
{ /* "-f" */ FILREG , UNOP },
{ /* "-d" */ FILDIR , UNOP },
{ /* "-c" */ FILCDEV , UNOP },
{ /* "-b" */ FILBDEV , UNOP },
{ /* "-p" */ FILFIFO , UNOP },
{ /* "-u" */ FILSUID , UNOP },
{ /* "-g" */ FILSGID , UNOP },
{ /* "-k" */ FILSTCK , UNOP },
{ /* "-s" */ FILGZ , UNOP },
{ /* "-t" */ FILTT , UNOP },
{ /* "-z" */ STREZ , UNOP },
{ /* "-n" */ STRNZ , UNOP },
{ /* "-h" */ FILSYM , UNOP }, /* for backwards compat */
{ "-O" , FILUID , UNOP },
{ "-G" , FILGID , UNOP },
{ "-L" , FILSYM , UNOP },
{ "-S" , FILSOCK, UNOP },
{ "=" , STREQ , BINOP },
{ "==" , STREQ , BINOP },
{ "!=" , STRNE , BINOP },
{ "<" , STRLT , BINOP },
{ ">" , STRGT , BINOP },
{ "-eq", INTEQ , BINOP },
{ "-ne", INTNE , BINOP },
{ "-ge", INTGE , BINOP },
{ "-gt", INTGT , BINOP },
{ "-le", INTLE , BINOP },
{ "-lt", INTLT , BINOP },
{ "-nt", FILNT , BINOP },
{ "-ot", FILOT , BINOP },
{ "-ef", FILEQ , BINOP },
{ "!" , UNOT , BUNOP },
{ "-a" , BAND , BBINOP },
{ "-o" , BOR , BBINOP },
{ "(" , LPAREN , PAREN },
{ ")" , RPAREN , PAREN },
{ /* "-O" */ FILUID , UNOP },
{ /* "-G" */ FILGID , UNOP },
{ /* "-L" */ FILSYM , UNOP },
{ /* "-S" */ FILSOCK , UNOP },
{ /* "=" */ STREQ , BINOP },
{ /* "==" */ STREQ , BINOP },
{ /* "!=" */ STRNE , BINOP },
{ /* "<" */ STRLT , BINOP },
{ /* ">" */ STRGT , BINOP },
{ /* "-eq"*/ INTEQ , BINOP },
{ /* "-ne"*/ INTNE , BINOP },
{ /* "-ge"*/ INTGE , BINOP },
{ /* "-gt"*/ INTGT , BINOP },
{ /* "-le"*/ INTLE , BINOP },
{ /* "-lt"*/ INTLT , BINOP },
{ /* "-nt"*/ FILNT , BINOP },
{ /* "-ot"*/ FILOT , BINOP },
{ /* "-ef"*/ FILEQ , BINOP },
{ /* "!" */ UNOT , BUNOP },
{ /* "-a" */ BAND , BBINOP },
{ /* "-o" */ BOR , BBINOP },
{ /* "(" */ LPAREN , PAREN },
{ /* ")" */ RPAREN , PAREN },
};
/* Please keep these two tables in sync */
static const char ops_texts[] ALIGN1 =
"-r" "\0"
"-w" "\0"
"-x" "\0"
"-e" "\0"
"-f" "\0"
"-d" "\0"
"-c" "\0"
"-b" "\0"
"-p" "\0"
"-u" "\0"
"-g" "\0"
"-k" "\0"
"-s" "\0"
"-t" "\0"
"-z" "\0"
"-n" "\0"
"-h" "\0"
"-O" "\0"
"-G" "\0"
"-L" "\0"
"-S" "\0"
"=" "\0"
"==" "\0"
"!=" "\0"
"<" "\0"
">" "\0"
"-eq" "\0"
"-ne" "\0"
"-ge" "\0"
"-gt" "\0"
"-le" "\0"
"-lt" "\0"
"-nt" "\0"
"-ot" "\0"
"-ef" "\0"
"!" "\0"
"-a" "\0"
"-o" "\0"
"(" "\0"
")" "\0"
;
#if ENABLE_FEATURE_TEST_64
@@ -384,29 +427,22 @@ static int equalf(const char *f1, const char *f2)
*/
static enum token check_operator(char *s)
static enum token check_operator(const char *s)
{
static const struct operator_t no_op = {
.op_num = -1,
.op_type = -1
};
const struct operator_t *op;
int n;
last_operator = &no_op;
if (s == NULL) {
if (s == NULL)
return EOI;
}
op = ops;
do {
if (strcmp(s, op->op_text) == 0) {
last_operator = op;
return op->op_num;
}
op++;
} while (op < ops + ARRAY_SIZE(ops));
return OPERAND;
n = index_in_strings(ops_texts, s);
if (n < 0)
return OPERAND;
last_operator = &ops_table[n];
return ops_table[n].op_num;
}
@@ -422,7 +458,7 @@ static int binop(void)
opnd2 = *++args;
if (opnd2 == NULL)
syntax(op->op_text, "argument expected");
syntax(args[-1], "argument expected");
if (is_int_op(op->op_num)) {
val1 = getn(opnd1);
+1
View File
@@ -84,6 +84,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
break;
}
free((char*)s1);
++dups; /* note: testing for overflow seems excessive. */
}
+7 -5
View File
@@ -2393,12 +2393,14 @@ static var *evaluate(node *op, var *res)
case XC( OC_MOVE ):
/* if source is a temporary string, jusk relink it to dest */
if (R.v == v1+1 && R.v->string) {
res = setvar_p(L.v, R.v->string);
R.v->string = NULL;
} else {
//Disabled: if R.v is numeric but happens to have cached R.v->string,
//then L.v ends up being a string, which is wrong
// if (R.v == v1+1 && R.v->string) {
// res = setvar_p(L.v, R.v->string);
// R.v->string = NULL;
// } else {
res = copyvar(L.v, R.v);
}
// }
break;
case XC( OC_TERNARY ):
+1 -3
View File
@@ -690,10 +690,8 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
if (sed_cmd->which_match)
break;
if (*line == '\0')
break;
//maybe (G.regmatch[0].rm_eo ? REG_NOTBOL : 0) instead of unconditional REG_NOTBOL?
} while (regexec(current_regex, line, 10, G.regmatch, REG_NOTBOL) != REG_NOMATCH);
} while (*line && regexec(current_regex, line, 10, G.regmatch, REG_NOTBOL) != REG_NOMATCH);
/* Copy rest of string into output pipeline */
while (1) {
+41 -27
View File
@@ -62,9 +62,6 @@
/* This is a NOEXEC applet. Be very careful! */
IF_FEATURE_FIND_XDEV(static dev_t *xdev_dev;)
IF_FEATURE_FIND_XDEV(static int xdev_count;)
typedef int (*action_fp)(const char *fileName, struct stat *statbuf, void *) FAST_FUNC;
typedef struct {
@@ -100,9 +97,24 @@ IF_FEATURE_FIND_DELETE( ACTS(delete))
IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int exec_argc;))
IF_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;))
static action ***actions;
static bool need_print = 1;
static int recurse_flags = ACTION_RECURSE;
struct globals {
IF_FEATURE_FIND_XDEV(dev_t *xdev_dev;)
IF_FEATURE_FIND_XDEV(int xdev_count;)
action ***actions;
bool need_print;
recurse_flags_t recurse_flags;
};
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { \
struct G_sizecheck { \
char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
}; \
IF_FEATURE_FIND_XDEV(G.xdev_dev = NULL;) \
IF_FEATURE_FIND_XDEV(G.xdev_count = 0;) \
G.actions = NULL; \
G.need_print = 1; \
G.recurse_flags = ACTION_RECURSE; \
} while (0)
#if ENABLE_FEATURE_FIND_EXEC
static unsigned count_subst(const char *str)
@@ -363,7 +375,7 @@ ACTF(context)
security_context_t con;
int rc;
if (recurse_flags & ACTION_FOLLOWLINKS) {
if (G.recurse_flags & ACTION_FOLLOWLINKS) {
rc = getfilecon(fileName, &con);
} else {
rc = lgetfilecon(fileName, &con);
@@ -392,18 +404,18 @@ static int FAST_FUNC fileAction(const char *fileName,
#endif
#if ENABLE_FEATURE_FIND_XDEV
if (S_ISDIR(statbuf->st_mode) && xdev_count) {
for (i = 0; i < xdev_count; i++) {
if (xdev_dev[i] == statbuf->st_dev)
if (S_ISDIR(statbuf->st_mode) && G.xdev_count) {
for (i = 0; i < G.xdev_count; i++) {
if (G.xdev_dev[i] == statbuf->st_dev)
break;
}
if (i == xdev_count)
if (i == G.xdev_count)
return SKIP;
}
#endif
i = exec_actions(actions, fileName, statbuf);
i = exec_actions(G.actions, fileName, statbuf);
/* Had no explicit -print[0] or -exec? then print */
if ((i & TRUE) && need_print)
if ((i & TRUE) && G.need_print)
puts(fileName);
/* Cannot return 0: our caller, recursive_action(),
* will perror() and skip dirs (if called on dir) */
@@ -431,7 +443,7 @@ static int find_type(const char *type)
else if (*type == 's')
mask = S_IFSOCK;
if (mask == 0 || *(type + 1) != '\0')
if (mask == 0 || type[1] != '\0')
bb_error_msg_and_die(bb_msg_invalid_arg, type, "-type");
return mask;
@@ -592,21 +604,21 @@ static action*** parse_params(char **argv)
/* --- Tests and actions --- */
else if (parm == PARM_print) {
need_print = 0;
G.need_print = 0;
/* GNU find ignores '!' here: "find ! -print" */
IF_FEATURE_FIND_NOT( invert_flag = 0; )
(void) ALLOC_ACTION(print);
}
#if ENABLE_FEATURE_FIND_PRINT0
else if (parm == PARM_print0) {
need_print = 0;
G.need_print = 0;
IF_FEATURE_FIND_NOT( invert_flag = 0; )
(void) ALLOC_ACTION(print0);
}
#endif
#if ENABLE_FEATURE_FIND_DEPTH
else if (parm == PARM_depth) {
recurse_flags |= ACTION_DEPTHFIRST;
G.recurse_flags |= ACTION_DEPTHFIRST;
}
#endif
#if ENABLE_FEATURE_FIND_PRUNE
@@ -617,8 +629,8 @@ static action*** parse_params(char **argv)
#endif
#if ENABLE_FEATURE_FIND_DELETE
else if (parm == PARM_delete) {
need_print = 0;
recurse_flags |= ACTION_DEPTHFIRST;
G.need_print = 0;
G.recurse_flags |= ACTION_DEPTHFIRST;
(void) ALLOC_ACTION(delete);
}
#endif
@@ -626,7 +638,7 @@ static action*** parse_params(char **argv)
else if (parm == PARM_exec) {
int i;
action_exec *ap;
need_print = 0;
G.need_print = 0;
IF_FEATURE_FIND_NOT( invert_flag = 0; )
ap = ALLOC_ACTION(exec);
ap->exec_argv = ++argv; /* first arg after -exec */
@@ -834,6 +846,8 @@ IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
#define minmaxdepth NULL
#endif
INIT_G();
for (firstopt = 1; firstopt < argc; firstopt++) {
if (argv[firstopt][0] == '-')
break;
@@ -861,21 +875,21 @@ IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
while ((arg = argp[0])) {
int opt = index_in_strings(options, arg);
if (opt == OPT_FOLLOW) {
recurse_flags |= ACTION_FOLLOWLINKS;
G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
argp[0] = (char*)"-a";
}
#if ENABLE_FEATURE_FIND_XDEV
if (opt == OPT_XDEV) {
struct stat stbuf;
if (!xdev_count) {
xdev_count = firstopt - 1;
xdev_dev = xmalloc(xdev_count * sizeof(dev_t));
if (!G.xdev_count) {
G.xdev_count = firstopt - 1;
G.xdev_dev = xmalloc(G.xdev_count * sizeof(dev_t));
for (i = 1; i < firstopt; i++) {
/* not xstat(): shouldn't bomb out on
* "find not_exist exist -xdev" */
if (stat(argv[i], &stbuf))
stbuf.st_dev = -1L;
xdev_dev[i-1] = stbuf.st_dev;
G.xdev_dev[i-1] = stbuf.st_dev;
}
}
argp[0] = (char*)"-a";
@@ -894,11 +908,11 @@ IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
argp++;
}
actions = parse_params(&argv[firstopt]);
G.actions = parse_params(&argv[firstopt]);
for (i = 1; i < firstopt; i++) {
if (!recursive_action(argv[i],
recurse_flags, /* flags */
G.recurse_flags,/* flags */
fileAction, /* file action */
fileAction, /* dir action */
#if ENABLE_FEATURE_FIND_MAXDEPTH
+2
View File
@@ -377,6 +377,8 @@ static int grep_file(FILE *file)
print_line(line + gl->matched_range.rm_so,
end - gl->matched_range.rm_so,
linenum, ':');
if (old == '\0')
break;
line[end] = old;
#if !ENABLE_EXTRA_COMPAT
if (regexec(&gl->compiled_regex, line + end,
+2
View File
@@ -286,7 +286,9 @@ enum {
ACTION_DEPTHFIRST = (1 << 3),
/*ACTION_REVERSE = (1 << 4), - unused */
ACTION_QUIET = (1 << 5),
ACTION_DANGLING_OK = (1 << 6),
};
typedef uint8_t recurse_flags_t;
extern int recursive_action(const char *fileName, unsigned flags,
int FAST_FUNC (*fileAction)(const char *fileName, struct stat* statbuf, void* userData, int depth),
int FAST_FUNC (*dirAction)(const char *fileName, struct stat* statbuf, void* userData, int depth),
+2
View File
@@ -174,12 +174,14 @@ char *strchrnul(const char *s, int c);
* a lvalue. This makes it more likely to not swap them by mistake
*/
#if defined(i386) || defined(__x86_64__)
# define move_from_unaligned_int(v, intp) ((v) = *(int*)(intp))
# define move_from_unaligned16(v, u16p) ((v) = *(uint16_t*)(u16p))
# define move_from_unaligned32(v, u32p) ((v) = *(uint32_t*)(u32p))
# define move_to_unaligned32(u32p, v) (*(uint32_t*)(u32p) = (v))
/* #elif ... - add your favorite arch today! */
#else
/* performs reasonably well (gcc usually inlines memcpy here) */
# define move_from_unaligned_int(v, intp) (memcpy(&(v), (intp), sizeof(int)))
# define move_from_unaligned16(v, u16p) (memcpy(&(v), (u16p), 2))
# define move_from_unaligned32(v, u32p) (memcpy(&(v), (u32p), 4))
# define move_to_unaligned32(u32p, v) do { \
+1
View File
@@ -143,6 +143,7 @@ lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o
lib-$(CONFIG_DF) += find_mount_point.o
lib-$(CONFIG_MKFS_MINIX) += find_mount_point.o
lib-$(CONFIG_FSCK_MINIX) += find_mount_point.o
lib-$(CONFIG_MOUNT) += find_mount_point.o
lib-$(CONFIG_HWCLOCK) += rtc.o
lib-$(CONFIG_RTCWAKE) += rtc.o
+27 -22
View File
@@ -114,8 +114,8 @@ struct lineedit_statics {
unsigned cmdedit_prmt_len; /* length of prompt (without colors etc) */
unsigned cursor;
unsigned command_len;
/* *int* maxsize: we want x in "if (x > S.maxsize)"
int command_len; /* must be signed (^D returns -1 len) */
/* signed maxsize: we want x in "if (x > S.maxsize)"
* to _not_ be promoted to unsigned */
int maxsize;
CHAR_T *command_ps;
@@ -1095,15 +1095,15 @@ static void save_command_ps_at_cur_history(void)
int cur = state->cur_history;
free(state->history[cur]);
#if ENABLE_FEATURE_ASSUME_UNICODE
# if ENABLE_FEATURE_ASSUME_UNICODE
{
char tbuf[MAX_LINELEN];
save_string(tbuf, sizeof(tbuf));
state->history[cur] = xstrdup(tbuf);
}
#else
# else
state->history[cur] = xstrdup(command_ps);
#endif
# endif
}
}
@@ -1131,7 +1131,7 @@ static int get_next_history(void)
return 0;
}
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
# if ENABLE_FEATURE_EDITING_SAVEHISTORY
/* We try to ensure that concurrent additions to the history
* do not overwrite each other.
* Otherwise shell users get unhappy.
@@ -1256,10 +1256,10 @@ static void save_history(char *str)
free_line_input_t(st_temp);
}
}
#else
#define load_history(a) ((void)0)
#define save_history(a) ((void)0)
#endif /* FEATURE_COMMAND_SAVEHISTORY */
# else
# define load_history(a) ((void)0)
# define save_history(a) ((void)0)
# endif /* FEATURE_COMMAND_SAVEHISTORY */
static void remember_in_history(char *str)
{
@@ -1290,15 +1290,15 @@ static void remember_in_history(char *str)
/* i <= MAX_HISTORY */
state->cur_history = i;
state->cnt_history = i;
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
if ((state->flags & SAVE_HISTORY) && state->hist_file)
save_history(str);
#endif
# endif
IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;)
}
#else /* MAX_HISTORY == 0 */
#define remember_in_history(a) ((void)0)
# define remember_in_history(a) ((void)0)
#endif /* MAX_HISTORY */
@@ -1476,11 +1476,11 @@ static void parse_and_put_prompt(const char *prmt_ptr)
c = *prmt_ptr++;
switch (c) {
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
case 'u':
pbuf = user_buf ? user_buf : (char*)"";
break;
#endif
# endif
case 'h':
pbuf = free_me = safe_gethostname();
*strchrnul(pbuf, '.') = '\0';
@@ -1488,7 +1488,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
case '$':
c = (geteuid() == 0 ? '#' : '$');
break;
#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
case 'w':
/* /home/user[/something] -> ~[/something] */
pbuf = cwd_buf;
@@ -1501,7 +1501,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
pbuf = free_me = xasprintf("~%s", cwd_buf + l);
}
break;
#endif
# endif
case 'W':
pbuf = cwd_buf;
cp = strrchr(pbuf, '/');
@@ -1688,13 +1688,15 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
/* With null flags, no other fields are ever used */
state = st ? st : (line_input_t*) &const_int_0;
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
#if MAX_HISTORY > 0
# if ENABLE_FEATURE_EDITING_SAVEHISTORY
if ((state->flags & SAVE_HISTORY) && state->hist_file)
if (state->cnt_history == 0)
load_history(state);
#endif
# endif
if (state->flags & DO_HISTORY)
state->cur_history = state->cnt_history;
#endif
/* prepare before init handlers */
cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */
@@ -1716,7 +1718,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
new_settings.c_cc[VTIME] = 0;
/* Turn off CTRL-C, so we can trap it */
#ifndef _POSIX_VDISABLE
#define _POSIX_VDISABLE '\0'
# define _POSIX_VDISABLE '\0'
#endif
new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
tcsetattr_stdin_TCSANOW(&new_settings);
@@ -2037,7 +2039,8 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
rewrite_line:
/* Rewrite the line with the selected history item */
/* change command */
command_len = load_string(state->history[state->cur_history] ? : "", maxsize);
command_len = load_string(state->history[state->cur_history] ?
state->history[state->cur_history] : "", maxsize);
/* redraw and go to eol (bol, in vi) */
redraw(cmdedit_y, (state->flags & VI_MODE) ? 9999 : 0);
break;
@@ -2121,7 +2124,9 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li
#undef command
#if ENABLE_FEATURE_ASSUME_UNICODE
command_len = save_string(command, maxsize - 1);
command[0] = '\0';
if (command_len > 0)
command_len = save_string(command, maxsize - 1);
free(command_ps);
#endif
+71 -62
View File
@@ -134,8 +134,8 @@ static unsigned long fast_strtoul_16(char **endptr)
return n;
}
/* TOPMEM uses fast_strtoul_10, so... */
#undef ENABLE_FEATURE_FAST_TOP
#define ENABLE_FEATURE_FAST_TOP 1
# undef ENABLE_FEATURE_FAST_TOP
# define ENABLE_FEATURE_FAST_TOP 1
#endif
#if ENABLE_FEATURE_FAST_TOP
@@ -198,14 +198,16 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
if (errno)
continue;
/* After this point we have to break, not continue
* ("continue" would mean that current /proc/NNN
* is not a valid process info) */
/* After this point we can:
* "break": stop parsing, return the data
* "continue": try next /proc/XXX
*/
memset(&sp->vsz, 0, sizeof(*sp) - offsetof(procps_status_t, vsz));
sp->pid = pid;
if (!(flags & ~PSSCAN_PID)) break;
if (!(flags & ~PSSCAN_PID))
break; /* we needed only pid, we got it */
#if ENABLE_SELINUX
if (flags & PSSCAN_CONTEXT) {
@@ -218,7 +220,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
if (flags & PSSCAN_UIDGID) {
if (stat(filename, &sb))
break;
continue; /* process probably exited */
/* Effective UID/GID, not real */
sp->uid = sb.st_uid;
sp->gid = sb.st_gid;
@@ -234,10 +236,10 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
strcpy(filename_tail, "stat");
n = read_to_buf(filename, buf);
if (n < 0)
break;
continue; /* process probably exited */
cp = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */
/*if (!cp || cp[1] != ' ')
break;*/
continue;*/
cp[0] = '\0';
if (sizeof(sp->comm) < 16)
BUG_comm_size();
@@ -257,12 +259,12 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
"%lu " /* start_time */
"%lu " /* vsize */
"%lu " /* rss */
#if ENABLE_FEATURE_TOP_SMP_PROCESS
# if ENABLE_FEATURE_TOP_SMP_PROCESS
"%*s %*s %*s %*s %*s %*s " /*rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */
"%*s %*s %*s %*s " /*signal, blocked, sigignore, sigcatch */
"%*s %*s %*s %*s " /*wchan, nswap, cnswap, exit_signal */
"%d" /*cpu last seen on*/
#endif
# endif
,
sp->state, &sp->ppid,
&sp->pgid, &sp->sid, &tty,
@@ -271,17 +273,17 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
&sp->start_time,
&vsz,
&rss
#if ENABLE_FEATURE_TOP_SMP_PROCESS
# if ENABLE_FEATURE_TOP_SMP_PROCESS
, &sp->last_seen_on_cpu
#endif
# endif
);
if (n < 11)
break;
#if ENABLE_FEATURE_TOP_SMP_PROCESS
continue; /* bogus data, get next /proc/XXX */
# if ENABLE_FEATURE_TOP_SMP_PROCESS
if (n < 11+15)
sp->last_seen_on_cpu = 0;
#endif
# endif
/* vsz is in bytes and we want kb */
sp->vsz = vsz >> 10;
@@ -311,14 +313,14 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
sp->vsz = fast_strtoul_10(&cp) >> 10;
/* vsz is in bytes but rss is in *PAGES*! Can you believe that? */
sp->rss = fast_strtoul_10(&cp) << sp->shift_pages_to_kb;
#if ENABLE_FEATURE_TOP_SMP_PROCESS
# if ENABLE_FEATURE_TOP_SMP_PROCESS
/* (6): rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */
/* (4): signal, blocked, sigignore, sigcatch */
/* (4): wchan, nswap, cnswap, exit_signal */
cp = skip_fields(cp, 14);
//FIXME: is it safe to assume this field exists?
sp->last_seen_on_cpu = fast_strtoul_10(&cp);
#endif
# endif
#endif /* end of !ENABLE_FEATURE_TOP_SMP_PROCESS */
#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
@@ -343,48 +345,48 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
strcpy(filename_tail, "smaps");
file = fopen_for_read(filename);
if (!file)
break;
while (fgets(buf, sizeof(buf), file)) {
unsigned long sz;
char *tp;
char w;
if (file) {
while (fgets(buf, sizeof(buf), file)) {
unsigned long sz;
char *tp;
char w;
#define SCAN(str, name) \
if (strncmp(buf, str, sizeof(str)-1) == 0) { \
tp = skip_whitespace(buf + sizeof(str)-1); \
sp->name += fast_strtoul_10(&tp); \
continue; \
}
SCAN("Shared_Clean:" , shared_clean );
SCAN("Shared_Dirty:" , shared_dirty );
SCAN("Private_Clean:", private_clean);
SCAN("Private_Dirty:", private_dirty);
SCAN("Shared_Clean:" , shared_clean );
SCAN("Shared_Dirty:" , shared_dirty );
SCAN("Private_Clean:", private_clean);
SCAN("Private_Dirty:", private_dirty);
#undef SCAN
// f7d29000-f7d39000 rw-s ADR M:m OFS FILE
tp = strchr(buf, '-');
if (tp) {
*tp = ' ';
tp = buf;
sz = fast_strtoul_16(&tp); /* start */
sz = (fast_strtoul_16(&tp) - sz) >> 10; /* end - start */
// tp -> "rw-s" string
w = tp[1];
// skipping "rw-s ADR M:m OFS "
tp = skip_whitespace(skip_fields(tp, 4));
// filter out /dev/something (something != zero)
if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) {
if (w == 'w') {
sp->mapped_rw += sz;
} else if (w == '-') {
sp->mapped_ro += sz;
// f7d29000-f7d39000 rw-s ADR M:m OFS FILE
tp = strchr(buf, '-');
if (tp) {
*tp = ' ';
tp = buf;
sz = fast_strtoul_16(&tp); /* start */
sz = (fast_strtoul_16(&tp) - sz) >> 10; /* end - start */
// tp -> "rw-s" string
w = tp[1];
// skipping "rw-s ADR M:m OFS "
tp = skip_whitespace(skip_fields(tp, 4));
// filter out /dev/something (something != zero)
if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) {
if (w == 'w') {
sp->mapped_rw += sz;
} else if (w == '-') {
sp->mapped_ro += sz;
}
}
}
//else printf("DROPPING %s (%s)\n", buf, tp);
if (strcmp(tp, "[stack]\n") == 0)
sp->stack += sz;
if (strcmp(tp, "[stack]\n") == 0)
sp->stack += sz;
}
}
fclose(file);
}
fclose(file);
}
#endif /* TOPMEM */
#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
@@ -393,23 +395,34 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
strcpy(filename_tail, "status");
file = fopen_for_read(filename);
if (!file)
break;
while (fgets(buf, sizeof(buf), file)) {
char *tp;
if (file) {
while (fgets(buf, sizeof(buf), file)) {
char *tp;
#define SCAN_TWO(str, name, statement) \
if (strncmp(buf, str, sizeof(str)-1) == 0) { \
tp = skip_whitespace(buf + sizeof(str)-1); \
sscanf(tp, "%u", &sp->name); \
statement; \
}
SCAN_TWO("Uid:", ruid, continue);
SCAN_TWO("Gid:", rgid, break);
SCAN_TWO("Uid:", ruid, continue);
SCAN_TWO("Gid:", rgid, break);
#undef SCAN_TWO
}
fclose(file);
}
fclose(file);
}
#endif /* PS_ADDITIONAL_COLUMNS */
if (flags & PSSCAN_EXE) {
strcpy(filename_tail, "exe");
free(sp->exe);
sp->exe = xmalloc_readlink(filename);
}
/* Note: if /proc/PID/cmdline is empty,
* code below "breaks". Therefore it must be
* the last code to parse /proc/PID/xxx data
* (we used to have /proc/PID/exe parsing after it
* and were getting stale sp->exe).
*/
#if 0 /* PSSCAN_CMD is not used */
if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) {
free(sp->argv0);
@@ -452,13 +465,9 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
}
}
#endif
if (flags & PSSCAN_EXE) {
strcpy(filename_tail, "exe");
free(sp->exe);
sp->exe = xmalloc_readlink(filename);
}
break;
}
} /* for (;;) */
return sp;
}
+13 -4
View File
@@ -61,6 +61,7 @@ int FAST_FUNC recursive_action(const char *fileName,
unsigned depth)
{
struct stat statbuf;
unsigned follow;
int status;
DIR *dir;
struct dirent *next;
@@ -68,14 +69,22 @@ int FAST_FUNC recursive_action(const char *fileName,
if (!fileAction) fileAction = true_action;
if (!dirAction) dirAction = true_action;
status = ACTION_FOLLOWLINKS; /* hijack a variable for bitmask... */
if (!depth)
status = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0;
status = ((flags & status) ? stat : lstat)(fileName, &statbuf);
follow = ACTION_FOLLOWLINKS;
if (depth == 0)
follow = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0;
follow &= flags;
status = (follow ? stat : lstat)(fileName, &statbuf);
if (status < 0) {
#ifdef DEBUG_RECURS_ACTION
bb_error_msg("status=%d flags=%x", status, flags);
#endif
if ((flags & ACTION_DANGLING_OK)
&& errno == ENOENT
&& lstat(fileName, &statbuf) == 0
) {
/* Dangling link */
return fileAction(fileName, &statbuf, userData, depth);
}
goto done_nak_warn;
}
+30 -17
View File
@@ -12,22 +12,35 @@
#include "libbb.h"
#include <mtd/mtd-user.h>
#include <mtd/jffs2-user.h>
#include <linux/jffs2.h>
#define OPTION_J (1 << 0)
#define OPTION_Q (1 << 1)
#define IS_NAND (1 << 2)
#define BBTEST (1 << 3)
struct globals {
/* This is used in the cpu_to_je/je_to_cpu macros in jffs2_user.h */
int tgt_endian;
};
#define G (*(struct globals*)&bb_common_bufsiz1)
#define target_endian (G.tgt_endian)
#define INIT_G() do { \
target_endian = __BYTE_ORDER; \
} while (0)
/* mtd/jffs2-user.h used to have this atrocity:
extern int target_endian;
#define t16(x) ({ __u16 __b = (x); (target_endian==__BYTE_ORDER)?__b:bswap_16(__b); })
#define t32(x) ({ __u32 __b = (x); (target_endian==__BYTE_ORDER)?__b:bswap_32(__b); })
#define cpu_to_je16(x) ((jint16_t){t16(x)})
#define cpu_to_je32(x) ((jint32_t){t32(x)})
#define cpu_to_jemode(x) ((jmode_t){t32(x)})
#define je16_to_cpu(x) (t16((x).v16))
#define je32_to_cpu(x) (t32((x).v32))
#define jemode_to_cpu(x) (t32((x).m))
but mtd/jffs2-user.h is gone now (at least 2.6.31.6 does not have it anymore)
*/
/* We always use native endianness */
#undef cpu_to_je16
#undef cpu_to_je32
#define cpu_to_je16(v) ((jint16_t){(v)})
#define cpu_to_je32(v) ((jint32_t){(v)})
static uint32_t crc32(uint32_t val, const void *ss, int len,
uint32_t *crc32_table)
@@ -40,9 +53,11 @@ static uint32_t crc32(uint32_t val, const void *ss, int len,
static void show_progress(mtd_info_t *meminfo, erase_info_t *erase)
{
printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
(unsigned)meminfo->erasesize / 1024, erase->start,
(unsigned long long) erase->start * 100 / meminfo->size);
printf("\rErasing %u Kibyte @ %x - %2u%% complete.",
(unsigned)meminfo->erasesize / 1024,
erase->start,
(unsigned) ((unsigned long long) erase->start * 100 / meminfo->size)
);
fflush(stdout);
}
@@ -57,17 +72,15 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv)
unsigned int flags;
char *mtd_name;
INIT_G();
opt_complementary = "=1";
flags = BBTEST | getopt32(argv, "jq");
mtd_name = argv[optind];
xstat(mtd_name, &st);
fd = xopen(mtd_name, O_RDWR);
fstat(fd, &st);
if (!S_ISCHR(st.st_mode))
bb_error_msg_and_die("%s: not a char device", mtd_name);
fd = xopen(mtd_name, O_RDWR);
xioctl(fd, MEMGETINFO, &meminfo);
erase.length = meminfo.erasesize;
if (meminfo.type == MTD_NANDFLASH)
+3
View File
@@ -15,6 +15,9 @@
/* must be _after_ libbb.h: */
#include <linux/hdreg.h>
#include <sys/mount.h>
#if !defined(BLKGETSIZE64)
# define BLKGETSIZE64 _IOR(0x12,114,size_t)
#endif
/* device types */
/* ------------ */
+1
View File
@@ -218,6 +218,7 @@ static void parse_module(module_info *info, const char *pathname)
bksp(); /* remove last ' ' */
appendc('\0');
info->aliases = copy_stringbuf();
replace(info->aliases, '-', '_');
/* "dependency1 depandency2" */
reset_stringbuf();
+13 -19
View File
@@ -2101,8 +2101,12 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
}
send_cgi_and_exit(urlcopy, prequest, length, cookie, content_type);
}
#endif
if (urlp[-1] == '/')
strcpy(urlp, index_page);
if (stat(tptr, &sb) == 0) {
#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
{
char *suffix = strrchr(tptr, '.');
if (suffix) {
Htaccess *cur;
@@ -2112,16 +2116,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
}
}
}
}
#endif
if (prequest != request_GET && prequest != request_HEAD) {
send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
}
#endif /* FEATURE_HTTPD_CGI */
if (urlp[-1] == '/')
strcpy(urlp, index_page);
if (stat(tptr, &sb) == 0) {
file_size = sb.st_size;
last_mod = sb.st_mtime;
}
@@ -2135,19 +2130,18 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
send_cgi_and_exit("/cgi-bin/index.cgi", prequest, length, cookie, content_type);
}
}
#endif
/* else {
* fall through to send_file, it errors out if open fails
* }
*/
/* else fall through to send_file, it errors out if open fails: */
if (prequest != request_GET && prequest != request_HEAD) {
/* POST for files does not make sense */
send_headers_and_exit(HTTP_NOT_IMPLEMENTED);
}
send_file_and_exit(tptr,
#if ENABLE_FEATURE_HTTPD_CGI
(prequest != request_HEAD ? SEND_HEADERS_AND_BODY : SEND_HEADERS)
#else
SEND_HEADERS_AND_BODY
#endif
);
#else
send_file_and_exit(tptr, SEND_HEADERS_AND_BODY);
#endif
}
/*
+18 -7
View File
@@ -1031,10 +1031,10 @@ static void reap_child(int sig UNUSED_PARAM)
continue;
/* One of our "wait" services */
if (WIFEXITED(status) && WEXITSTATUS(status))
bb_error_msg("%s: exit status 0x%x",
bb_error_msg("%s: exit status %u",
sep->se_program, WEXITSTATUS(status));
else if (WIFSIGNALED(status))
bb_error_msg("%s: exit signal 0x%x",
bb_error_msg("%s: exit signal %u",
sep->se_program, WTERMSIG(status));
sep->se_wait = 1;
add_fd_to_set(sep->se_fd);
@@ -1119,7 +1119,12 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
else
bb_sanitize_stdio();
if (!(opt & 4)) {
openlog(applet_name, LOG_PID, LOG_DAEMON);
/* LOG_NDELAY: connect to syslog daemon NOW.
* Otherwise, we may open syslog socket
* in vforked child, making opened fds and syslog()
* internal state inconsistent.
* This was observed to leak file descriptors. */
openlog(applet_name, LOG_PID | LOG_NDELAY, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
}
@@ -1355,17 +1360,23 @@ int inetd_main(int argc UNUSED_PARAM, char **argv)
if (rlim_ofile.rlim_cur != rlim_ofile_cur)
if (setrlimit(RLIMIT_NOFILE, &rlim_ofile) < 0)
bb_perror_msg("setrlimit");
closelog();
/* closelog(); - WRONG. we are after vfork,
* this may confuse syslog() internal state.
* Let's hope libc sets syslog fd to CLOEXEC...
*/
xmove_fd(ctrl, STDIN_FILENO);
xdup2(STDIN_FILENO, STDOUT_FILENO);
/* manpages of inetd I managed to find either say
* that stderr is also redirected to the network,
* or do not talk about redirection at all (!) */
xdup2(STDIN_FILENO, STDERR_FILENO);
/* NB: among others, this loop closes listening socket
if (!sep->se_wait) /* only for usual "tcp nowait" */
xdup2(STDIN_FILENO, STDERR_FILENO);
/* NB: among others, this loop closes listening sockets
* for nowait stream children */
for (sep2 = serv_list; sep2; sep2 = sep2->se_next)
maybe_close(sep2->se_fd);
if (sep2->se_fd != ctrl)
maybe_close(sep2->se_fd);
sigaction_set(SIGPIPE, &saved_pipe_handler);
restore_sigmask(&omask);
BB_EXECVP(sep->se_program, sep->se_argv);
+24 -12
View File
@@ -173,13 +173,14 @@ static void ping6(len_and_sockaddr *lsa)
}
#endif
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ping_main(int argc UNUSED_PARAM, char **argv)
#if !ENABLE_PING6
# define common_ping_main(af, argv) common_ping_main(argv)
#endif
static int common_ping_main(sa_family_t af, char **argv)
{
len_and_sockaddr *lsa;
#if ENABLE_PING6
sa_family_t af = AF_UNSPEC;
#if ENABLE_PING6
while ((++argv)[0] && argv[0][0] == '-') {
if (argv[0][1] == '4') {
af = AF_INET;
@@ -689,7 +690,8 @@ static void ping6(len_and_sockaddr *lsa)
/* don't check len - we trust the kernel: */
/* && mp->cmsg_len >= CMSG_LEN(sizeof(int)) */
) {
hoplimit = *(int*)CMSG_DATA(mp);
/*hoplimit = *(int*)CMSG_DATA(mp); - unaligned access */
move_from_unaligned_int(hoplimit, CMSG_DATA(mp));
}
}
unpack6(packet, c, /*&from,*/ hoplimit);
@@ -716,18 +718,16 @@ static void ping(len_and_sockaddr *lsa)
ping4(lsa);
}
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ping_main(int argc UNUSED_PARAM, char **argv)
static int common_ping_main(int opt, char **argv)
{
len_and_sockaddr *lsa;
char *str_s;
int opt;
INIT_G();
/* exactly one argument needed; -v and -q don't mix; -c NUM, -w NUM, -W NUM */
opt_complementary = "=1:q--v:v--q:c+:w+:W+";
opt = getopt32(argv, OPT_STRING, &pingcount, &str_s, &deadline, &timeout, &str_I);
opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &deadline, &timeout, &str_I);
if (opt & OPT_s)
datalen = xatou16(str_s); // -s
if (opt & OPT_I) { // -I
@@ -765,13 +765,25 @@ int ping_main(int argc UNUSED_PARAM, char **argv)
#endif /* FEATURE_FANCY_PING */
int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ping_main(int argc UNUSED_PARAM, char **argv)
{
#if !ENABLE_FEATURE_FANCY_PING
return common_ping_main(AF_UNSPEC, argv);
#else
return common_ping_main(0, argv);
#endif
}
#if ENABLE_PING6
int ping6_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ping6_main(int argc UNUSED_PARAM, char **argv)
{
argv[0] = (char*)"-6";
return ping_main(0 /* argc+1 - but it's unused anyway */,
argv - 1);
# if !ENABLE_FEATURE_FANCY_PING
return common_ping_main(AF_INET6, argv);
# else
return common_ping_main(OPT_IPV6, argv);
# endif
}
#endif
+23
View File
@@ -17,11 +17,28 @@ menuconfig: $(obj)/mconf
config: $(obj)/conf
$< Config.in
# Mtime granularity problem.
# It was observed that these commands:
# make allnoconfig; sed -i -e '/CONFIG_TRUE/s/.*/CONFIG_TRUE=y/' .config; make
# sometimes produce busybox with "true" applet still disabled.
# This is caused by .config updated by sed having mtime which is still
# equal to (not bigger than) include/autoconf.h's mtime,
# and thus 2nd make does not regenerate include/autoconf.h.
# Waiting for 1 second after non-interactive "make XXXXconfig"
# prevents this from happening.
#
# We'd like to detect whether filesystem we are on has coarse mtimes,
# but can't do it yet, bbox ls hasn't got --full-time.
#MTIME_IS_COARSE:=@ls --full-time -ld | grep -F .000 >/dev/null
MTIME_IS_COARSE:=@true
oldconfig: $(obj)/conf
$< -o Config.in
$(MTIME_IS_COARSE) && sleep 1
silentoldconfig: $(obj)/conf
$< -s Config.in
$(MTIME_IS_COARSE) && sleep 1
update-po-config: $(obj)/kxgettext
xgettext --default-domain=linux \
@@ -46,15 +63,19 @@ PHONY += randconfig allyesconfig allnoconfig allmodconfig defconfig
randconfig: $(obj)/conf
$< -r Config.in
$(MTIME_IS_COARSE) && sleep 1
allyesconfig: $(obj)/conf
$< -y Config.in
$(MTIME_IS_COARSE) && sleep 1
allnoconfig: $(obj)/conf
$< -n Config.in
$(MTIME_IS_COARSE) && sleep 1
allmodconfig: $(obj)/conf
$< -m Config.in
$(MTIME_IS_COARSE) && sleep 1
defconfig: $(obj)/conf
ifeq ($(KBUILD_DEFCONFIG),)
@@ -63,9 +84,11 @@ else
@echo *** Default configuration is based on '$(KBUILD_DEFCONFIG)'
$(Q)$< -D $(KBUILD_DEFCONFIG) Config.in
endif
$(MTIME_IS_COARSE) && sleep 1
%_defconfig: $(obj)/conf
$(Q)$< -D $@ Config.in
$(MTIME_IS_COARSE) && sleep 1
# Help text used by make help
help:
+629 -560
View File
File diff suppressed because it is too large. Load diff
+3
View File
@@ -0,0 +1,3 @@
Ok
Ok
Done
+12
View File
@@ -0,0 +1,12 @@
# Chars above 0x7f are used as special codes.
# 0x81 is CTLESC (see ash.c).
# The bug was that quoting and unquoting of them
# was out of sync for redirect filenames.
>unicode.sh
echo -e 'echo Ok >uni\x81code' >>unicode.sh
echo -e 'cat uni\x81code' >>unicode.sh
echo -e 'cat uni?code' >>unicode.sh
. unicode.sh
rm uni*code*
echo Done
+3
View File
@@ -0,0 +1,3 @@
Ok
Ok
Done
+15
View File
@@ -0,0 +1,15 @@
# Chars above 0x7f are used as special codes.
# 0x81 is CTLESC (see ash.c).
# The bug was that quoting and unquoting of them
# was out of sync for redirect filenames.
# Subcase when redirect filename is specified in a variable.
>unicode.sh
echo -e 'v=uni\x81code' >>unicode.sh
echo -e 'echo Ok >"$v"' >>unicode.sh
echo -e 'cat uni\x81code' >>unicode.sh
echo -e 'cat uni?code' >>unicode.sh
. unicode.sh
rm uni*code*
echo Done
@@ -0,0 +1,8 @@
trap -- 'echo Exiting' EXIT
trap -- 'echo WINCH!' WINCH
trap -- 'echo Exiting' EXIT
trap -- 'echo WINCH!' WINCH
trap -- 'echo Exiting' EXIT
trap -- 'echo WINCH!' WINCH
Done
Exiting
+9
View File
@@ -0,0 +1,9 @@
trap 'echo Exiting' EXIT
trap 'echo WINCH!' SIGWINCH
v=` trap `
echo "$v"
v=$( trap )
echo "$v"
v=`trap`
echo "$v"
echo Done
+182 -65
View File
@@ -58,7 +58,7 @@
* TODOs:
* grep for "TODO" and fix (some of them are easy)
* builtins: ulimit
* special variables (PWD etc)
* special variables (done: PWD)
* follow IFS rules more precisely, including update semantics
* export builtin should be special, its arguments are assignments
* and therefore expansion of them should be "one-word" expansion:
@@ -78,6 +78,7 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
#include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */
#include <malloc.h> /* for malloc_trim */
#include <glob.h>
/* #include <dmalloc.h> */
#if ENABLE_HUSH_CASE
@@ -786,7 +787,7 @@ static void xxfree(void *ptr)
* HUSH_DEBUG >= 2 prints line number in this file where it was detected.
*/
#if HUSH_DEBUG < 2
# define die_if_script(lineno, fmt...) die_if_script(fmt)
# define die_if_script(lineno, ...) die_if_script(__VA_ARGS__)
# define syntax_error(lineno, msg) syntax_error(msg)
# define syntax_error_at(lineno, msg) syntax_error_at(msg)
# define syntax_error_unterm_ch(lineno, ch) syntax_error_unterm_ch(ch)
@@ -855,7 +856,7 @@ static void syntax_error_unexpected_ch(unsigned lineno, int ch)
# undef syntax_error_unterm_str
# undef syntax_error_unexpected_ch
#else
# define die_if_script(fmt...) die_if_script(__LINE__, fmt)
# define die_if_script(...) die_if_script(__LINE__, __VA_ARGS__)
# define syntax_error(msg) syntax_error(__LINE__, msg)
# define syntax_error_at(msg) syntax_error_at(__LINE__, msg)
# define syntax_error_unterm_ch(ch) syntax_error_unterm_ch(__LINE__, ch)
@@ -898,7 +899,7 @@ static int is_well_formed_var_name(const char *s, char terminator)
/* Replace each \x with x in place, return ptr past NUL. */
static char *unbackslash(char *src)
{
char *dst = src;
char *dst = src = strchrnul(src, '\\');
while (1) {
if (*src == '\\')
src++;
@@ -1037,7 +1038,7 @@ static void restore_G_args(save_arg_t *sv, char **argv)
* is finished or backgrounded. It is the same in interactive and
* non-interactive shells, and is the same regardless of whether
* a user trap handler is installed or a shell special one is in effect.
* ^C or ^Z from keyboard seem to execute "at once" because it usually
* ^C or ^Z from keyboard seems to execute "at once" because it usually
* backgrounds (i.e. stops) or kills all members of currently running
* pipe.
*
@@ -1104,12 +1105,17 @@ static void restore_G_args(save_arg_t *sv, char **argv)
* (child shell is not interactive),
* unset all traps (note: regardless of child shell's type - {}, (), etc)
* after [v]fork, if we plan to exec:
* POSIX says pending signal mask is cleared in child - no need to clear it.
* POSIX says fork clears pending signal mask in child - no need to clear it.
* Restore blocked signal set to one inherited by shell just prior to exec.
*
* Note: as a result, we do not use signal handlers much. The only uses
* are to count SIGCHLDs
* and to restore tty pgrp on signal-induced exit.
*
* Note 2 (compat):
* Standard says "When a subshell is entered, traps that are not being ignored
* are set to the default actions". bash interprets it so that traps which
* are set to "" (ignore) are NOT reset to defaults. We do the same.
*/
enum {
SPECIAL_INTERACTIVE_SIGS = 0
@@ -1432,6 +1438,13 @@ static int set_local_var(char *str, int flg_export, int local_lvl, int flg_read_
return 0;
}
/* Used at startup and after each cd */
static void set_pwd_var(int exp)
{
set_local_var(xasprintf("PWD=%s", get_cwd(/*force:*/ 1)),
/*exp:*/ exp, /*lvl:*/ 0, /*ro:*/ 0);
}
static int unset_local_var_len(const char *name, int name_len)
{
struct variable *cur;
@@ -1604,6 +1617,9 @@ static const char* setup_prompt_string(int promptmode)
/* Set up the prompt */
if (promptmode == 0) { /* PS1 */
free((char*)G.PS1);
/* bash uses $PWD value, even if it is set by user.
* It uses current dir only if PWD is unset.
* We always use current dir. */
G.PS1 = xasprintf("%s %c ", get_cwd(0), (geteuid() != 0) ? '$' : '#');
prompt_str = G.PS1;
} else
@@ -2586,43 +2602,51 @@ static void reset_traps_to_defaults(void)
{
/* This function is always called in a child shell
* after fork (not vfork, NOMMU doesn't use this function).
* Child shells are not interactive.
* SIGTTIN/SIGTTOU/SIGTSTP should not have special handling.
* Testcase: (while :; do :; done) + ^Z should background.
* Same goes for SIGTERM, SIGHUP, SIGINT.
*/
unsigned sig;
unsigned mask;
/* Child shells are not interactive.
* SIGTTIN/SIGTTOU/SIGTSTP should not have special handling.
* Testcase: (while :; do :; done) + ^Z should background.
* Same goes for SIGTERM, SIGHUP, SIGINT.
*/
if (!G.traps && !(G.non_DFL_mask & SPECIAL_INTERACTIVE_SIGS))
return;
return; /* already no traps and no SPECIAL_INTERACTIVE_SIGS */
/* Stupid. It can be done with *single* &= op, but we can't use
* the fact that G.blocked_set is implemented as a bitmask... */
/* Switching off SPECIAL_INTERACTIVE_SIGS.
* Stupid. It can be done with *single* &= op, but we can't use
* the fact that G.blocked_set is implemented as a bitmask
* in libc... */
mask = (SPECIAL_INTERACTIVE_SIGS >> 1);
sig = 1;
while (1) {
if (mask & 1)
sigdelset(&G.blocked_set, sig);
if (mask & 1) {
/* Careful. Only if no trap or trap is not "" */
if (!G.traps || !G.traps[sig] || G.traps[sig][0])
sigdelset(&G.blocked_set, sig);
}
mask >>= 1;
if (!mask)
break;
sig++;
}
/* Our homegrown sig mask is saner to work with :) */
G.non_DFL_mask &= ~SPECIAL_INTERACTIVE_SIGS;
/* Resetting all traps to default except empty ones */
mask = G.non_DFL_mask;
if (G.traps) for (sig = 0; sig < NSIG; sig++, mask >>= 1) {
if (!G.traps[sig])
if (!G.traps[sig] || !G.traps[sig][0])
continue;
free(G.traps[sig]);
G.traps[sig] = NULL;
/* There is no signal for 0 (EXIT) */
if (sig == 0)
continue;
/* There was a trap handler, we are removing it.
/* There was a trap handler, we just removed it.
* But if sig still has non-DFL handling,
* we should not unblock it. */
* we should not unblock the sig. */
if (mask & 1)
continue;
sigdelset(&G.blocked_set, sig);
@@ -3069,15 +3093,21 @@ static const struct built_in_command* find_builtin(const char *name)
}
#if ENABLE_HUSH_FUNCTIONS
static const struct function *find_function(const char *name)
static struct function **find_function_slot(const char *name)
{
const struct function *funcp = G.top_func;
while (funcp) {
if (strcmp(name, funcp->name) == 0) {
struct function **funcpp = &G.top_func;
while (*funcpp) {
if (strcmp(name, (*funcpp)->name) == 0) {
break;
}
funcp = funcp->next;
funcpp = &(*funcpp)->next;
}
return funcpp;
}
static const struct function *find_function(const char *name)
{
const struct function *funcp = *find_function_slot(name);
if (funcp)
debug_printf_exec("found function '%s'\n", name);
return funcp;
@@ -3086,18 +3116,11 @@ static const struct function *find_function(const char *name)
/* Note: takes ownership on name ptr */
static struct function *new_function(char *name)
{
struct function *funcp;
struct function **funcpp = &G.top_func;
struct function **funcpp = find_function_slot(name);
struct function *funcp = *funcpp;
while ((funcp = *funcpp) != NULL) {
struct command *cmd;
if (strcmp(funcp->name, name) != 0) {
funcpp = &funcp->next;
continue;
}
cmd = funcp->parent_cmd;
if (funcp != NULL) {
struct command *cmd = funcp->parent_cmd;
debug_printf_exec("func %p parent_cmd %p\n", funcp, cmd);
if (!cmd) {
debug_printf_exec("freeing & replacing function '%s'\n", funcp->name);
@@ -3119,39 +3142,36 @@ static struct function *new_function(char *name)
cmd->group_as_string = funcp->body_as_string;
# endif
}
goto skip;
} else {
debug_printf_exec("remembering new function '%s'\n", name);
funcp = *funcpp = xzalloc(sizeof(*funcp));
/*funcp->next = NULL;*/
}
debug_printf_exec("remembering new function '%s'\n", name);
funcp = *funcpp = xzalloc(sizeof(*funcp));
/*funcp->next = NULL;*/
skip:
funcp->name = name;
return funcp;
}
static void unset_func(const char *name)
{
struct function *funcp;
struct function **funcpp = &G.top_func;
struct function **funcpp = find_function_slot(name);
struct function *funcp = *funcpp;
while ((funcp = *funcpp) != NULL) {
if (strcmp(funcp->name, name) == 0) {
*funcpp = funcp->next;
/* funcp is unlinked now, deleting it.
* Note: if !funcp->body, the function was created by
* "-F name body", do not free ->body_as_string
* and ->name as they were not malloced. */
if (funcp->body) {
free_pipe_list(funcp->body);
free(funcp->name);
if (funcp != NULL) {
debug_printf_exec("freeing function '%s'\n", funcp->name);
*funcpp = funcp->next;
/* funcp is unlinked now, deleting it.
* Note: if !funcp->body, the function was created by
* "-F name body", do not free ->body_as_string
* and ->name as they were not malloced. */
if (funcp->body) {
free_pipe_list(funcp->body);
free(funcp->name);
# if !BB_MMU
free(funcp->body_as_string);
free(funcp->body_as_string);
# endif
}
free(funcp);
break;
}
funcpp = &funcp->next;
free(funcp);
}
}
@@ -3618,9 +3638,9 @@ static int checkjobs(struct pipe* fg_pipe)
/* Note: is WIFSIGNALED, WEXITSTATUS = sig + 128 */
rcode = WEXITSTATUS(status);
IF_HAS_KEYWORDS(if (fg_pipe->pi_inverted) rcode = !rcode;)
/* bash prints killing signal's name for *last*
/* bash prints killer signal's name for *last*
* process in pipe (prints just newline for SIGINT).
* Mimic this. Example: "sleep 5" + ^\
* Mimic this. Example: "sleep 5" + (^\ or kill -QUIT)
*/
if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
@@ -5173,6 +5193,47 @@ static FILE *generate_stream_from_string(const char *s)
xmove_fd(channel[1], 1);
/* Prevent it from trying to handle ctrl-z etc */
IF_HUSH_JOB(G.run_list_level = 1;)
/* Awful hack for `trap` or $(trap).
*
* http://www.opengroup.org/onlinepubs/009695399/utilities/trap.html
* contains an example where "trap" is executed in a subshell:
*
* save_traps=$(trap)
* ...
* eval "$save_traps"
*
* Standard does not say that "trap" in subshell shall print
* parent shell's traps. It only says that its output
* must have suitable form, but then, in the above example
* (which is not supposed to be normative), it implies that.
*
* bash (and probably other shell) does implement it
* (traps are reset to defaults, but "trap" still shows them),
* but as a result, "trap" logic is hopelessly messed up:
*
* # trap
* trap -- 'echo Ho' SIGWINCH <--- we have a handler
* # (trap) <--- trap is in subshell - no output (correct, traps are reset)
* # true | trap <--- trap is in subshell - no output (ditto)
* # echo `true | trap` <--- in subshell - output (but traps are reset!)
* trap -- 'echo Ho' SIGWINCH
* # echo `(trap)` <--- in subshell in subshell - output
* trap -- 'echo Ho' SIGWINCH
* # echo `true | (trap)` <--- in subshell in subshell in subshell - output!
* trap -- 'echo Ho' SIGWINCH
*
* The rules when to forget and when to not forget traps
* get really complex and nonsensical.
*
* Our solution: ONLY bare $(trap) or `trap` is special.
*/
s = skip_whitespace(s);
if (strncmp(s, "trap", 4) == 0 && (*skip_whitespace(s + 4) == '\0'))
{
static const char *const argv[] = { NULL, NULL };
builtin_trap((char**)argv);
exit(0); /* not _exit() - we need to fflush */
}
#if BB_MMU
reset_traps_to_defaults();
parse_and_run_string(s);
@@ -5666,8 +5727,10 @@ static int handle_dollar(o_string *as_string,
goto make_var;
}
/* else: it's $_ */
/* TODO: */
/* $_ Shell or shell script name; or last cmd name */
/* TODO: $_ and $-: */
/* $_ Shell or shell script name; or last argument of last command
* (if last command wasn't a pipe; if it was, bash sets $_ to "");
* but in command's env, set to full pathname used to invoke it */
/* $- Option flags set by set builtin or shell options (-i etc) */
default:
o_addQchr(dest, '$');
@@ -5784,7 +5847,7 @@ static struct pipe *parse_stream(char **pstring,
* found. When recursing, quote state is passed in via dest->o_escape.
*/
debug_printf_parse("parse_stream entered, end_trigger='%c'\n",
end_trigger ? : 'X');
end_trigger ? end_trigger : 'X');
debug_enter();
G.ifs = get_local_var_value("IFS");
@@ -6432,8 +6495,49 @@ int hush_main(int argc, char **argv)
}
e++;
}
/* reinstate HUSH_VERSION */
debug_printf_env("putenv '%s'\n", hush_version_str);
putenv((char *)hush_version_str); /* reinstate HUSH_VERSION */
putenv((char *)hush_version_str);
/* Export PWD */
set_pwd_var(/*exp:*/ 1);
/* bash also exports SHLVL and _,
* and sets (but doesn't export) the following variables:
* BASH=/bin/bash
* BASH_VERSINFO=([0]="3" [1]="2" [2]="0" [3]="1" [4]="release" [5]="i386-pc-linux-gnu")
* BASH_VERSION='3.2.0(1)-release'
* HOSTTYPE=i386
* MACHTYPE=i386-pc-linux-gnu
* OSTYPE=linux-gnu
* HOSTNAME=<xxxxxxxxxx>
* PPID=<NNNNN>
* EUID=<NNNNN>
* UID=<NNNNN>
* GROUPS=()
* LINES=<NNN>
* COLUMNS=<NNN>
* BASH_ARGC=()
* BASH_ARGV=()
* BASH_LINENO=()
* BASH_SOURCE=()
* DIRSTACK=()
* PIPESTATUS=([0]="0")
* HISTFILE=/<xxx>/.bash_history
* HISTFILESIZE=500
* HISTSIZE=500
* MAILCHECK=60
* PATH=/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.
* SHELL=/bin/bash
* SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
* TERM=dumb
* OPTERR=1
* OPTIND=1
* IFS=$' \t\n'
* PS1='\s-\v\$ '
* PS2='> '
* PS4='+ '
*/
#if ENABLE_FEATURE_EDITING
G.line_input_state = new_line_input_t(FOR_SHELL);
#endif
@@ -6809,14 +6913,19 @@ static int FAST_FUNC builtin_cd(char **argv)
* bash says "bash: cd: HOME not set" and does nothing
* (exitcode 1)
*/
newdir = get_local_var_value("HOME") ? : "/";
const char *home = get_local_var_value("HOME");
newdir = home ? home : "/";
}
if (chdir(newdir)) {
/* Mimic bash message exactly */
bb_perror_msg("cd: %s", newdir);
return EXIT_FAILURE;
}
get_cwd(1);
/* Read current dir (get_cwd(1) is inside) and set PWD.
* Note: do not enforce exporting. If PWD was unset or unexported,
* set it again, but do not export. bash does the same.
*/
set_pwd_var(/*exp:*/ 0);
return EXIT_SUCCESS;
}
@@ -7002,6 +7111,10 @@ static int FAST_FUNC builtin_trap(char **argv)
if (G.traps[i]) {
printf("trap -- ");
print_escaped(G.traps[i]);
/* note: bash adds "SIG", but only if invoked
* as "bash". If called as "sh", or if set -o posix,
* then it prints short signal names.
* We are printing short names: */
printf(" %s\n", get_signame(i));
}
}
@@ -7213,6 +7326,10 @@ static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM)
void *p;
unsigned long l;
#ifdef M_TRIM_THRESHOLD
/* Optional. Reduces probability of false positives */
malloc_trim(0);
#endif
/* Crude attempt to find where "free memory" starts,
* sans fragmentation. */
p = malloc(240);
+8
View File
@@ -0,0 +1,8 @@
trap -- 'echo Exiting' EXIT
trap -- 'echo WINCH!' WINCH
trap -- 'echo Exiting' EXIT
trap -- 'echo WINCH!' WINCH
trap -- 'echo Exiting' EXIT
trap -- 'echo WINCH!' WINCH
Done
Exiting
+9
View File
@@ -0,0 +1,9 @@
trap 'echo Exiting' EXIT
trap 'echo WINCH!' SIGWINCH
v=` trap `
echo "$v"
v=$( trap )
echo "$v"
v=`trap`
echo "$v"
echo Done
+6
View File
@@ -0,0 +1,6 @@
Ok
Ok
Ok
Ok
TERM
Done
+20
View File
@@ -0,0 +1,20 @@
# Non-empty traps should be reset in subshell
# HUP is special in interactive shells
trap '' HUP
# QUIT is always special
trap '' QUIT
# SYS is not special
trap '' SYS
# WINCH is harmless
trap 'bad: caught WINCH' WINCH
# With TERM we'll check whether it is reset
trap 'bad: caught TERM' TERM
# using bash, because we don't have $PPID (yet)
(bash -c 'kill -HUP $PPID'; echo Ok)
(bash -c 'kill -QUIT $PPID'; echo Ok)
(bash -c 'kill -SYS $PPID'; echo Ok)
(bash -c 'kill -WINCH $PPID'; echo Ok)
(bash -c 'kill -TERM $PPID'; echo Bad: TERM is not reset)
echo Done
+17
View File
@@ -47,4 +47,21 @@ testing "awk NF in BEGIN" \
":0::::\n" \
"" ""
prg='
function b(tmp) {
tmp = 0;
print "" tmp; #this line causes the bug
return tmp;
}
function c(tmpc) {
tmpc = b(); return tmpc;
}
BEGIN {
print (c() ? "string" : "number");
}'
testing "awk string cast (bug 725)" \
"awk '$prg'" \
"0\nnumber\n" \
"" ""
exit $FAILCOUNT
+5
View File
@@ -90,4 +90,9 @@ testing "grep -E -o prints all matches" \
"00:19:3E:00:AA:5E\n00:1D:60:3D:3A:FB\n00:22:43:49:FB:AA\n" \
"" "00:19:3E:00:AA:5E 00:1D:60:3D:3A:FB 00:22:43:49:FB:AA\n"
testing "grep -o does not loop forever" \
'grep -o "[^/]*$"' \
"test\n" \
"" "/var/test\n"
exit $FAILCOUNT
+4 -1
View File
@@ -9,13 +9,16 @@
#ifndef _LARGEFILE64_SOURCE
/* For lseek64 */
#define _LARGEFILE64_SOURCE
# define _LARGEFILE64_SOURCE
#endif
#include <assert.h> /* assert */
#include <sys/mount.h>
#if !defined(BLKSSZGET)
# define BLKSSZGET _IO(0x12, 104)
#endif
#if !defined(BLKGETSIZE64)
# define BLKGETSIZE64 _IOR(0x12,114,size_t)
#endif
#include "libbb.h"
/* Looks like someone forgot to add this to config system */
+20 -4
View File
@@ -1958,6 +1958,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
// If we're mounting all
} else {
struct mntent *mp;
// No, mount -a won't mount anything,
// even user mounts, for mere humans
if (nonroot)
@@ -1985,10 +1986,25 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
// NFS mounts want this to be xrealloc-able
mtcur->mnt_opts = xstrdup(mtcur->mnt_opts);
// Mount this thing
if (singlemount(mtcur, 1)) {
// Count number of failed mounts
rc++;
// If nothing is mounted on this directory...
// (otherwise repeated "mount -a" mounts everything again)
mp = find_mount_point(mtcur->mnt_dir, /*subdir_too:*/ 0);
// We do not check fsname match of found mount point -
// "/" may have fsname of "/dev/root" while fstab
// says "/dev/something_else".
if (mp) {
if (verbose) {
bb_error_msg("according to %s, "
"%s is already mounted on %s",
bb_path_mtab_file,
mp->mnt_fsname, mp->mnt_dir);
}
} else {
// ...mount this thing
if (singlemount(mtcur, /*ignore_busy:*/ 1)) {
// Count number of failed mounts
rc++;
}
}
free(mtcur->mnt_opts);
}