Compare commits

...
12 Commits
Author SHA1 Message Date
Denis Vlasenko 4a81fe4173 apply post-1.11.2 fixes, bump version to 1.11.3 2008-09-28 16:40:02 +00:00
Bernhard Reutner-Fischer 3e7eca97b9 - sync with trunk 2008-09-05 15:30:24 +00:00
Bernhard Reutner-Fischer 9e6fe061d4 - fix typo 2008-09-05 15:23:53 +00:00
Bernhard Reutner-Fischer a959a858a3 - pull r22872 from trunk:
pidof/killall: allow find_pid_by_name to find running
 processes started as scripts_with_name_longer_than_15_bytes.sh
 closes bug 4054 (and is generally neat)
2008-09-05 12:05:47 +00:00
Denis Vlasenko 2957fc6992 apply post-1.11.1 patches, bump version to 1.11.2 2008-08-21 08:32:12 +00:00
Bernhard Reutner-Fischer 6857e4e2f3 - fix typo 2008-08-06 17:39:05 +00:00
Bernhard Reutner-Fischer 9a22b56d36 - remove erroneous & from &var. By Vladimir. (r23056 from trunk) 2008-08-06 08:21:27 +00:00
Bernhard Reutner-Fischer a4d0cd0a31 - don't free user-supplied string (via -e)
- fix helptext
(r23046 from trunk)
2008-08-05 14:33:37 +00:00
Denis Vlasenko f2b846e277 cpio: dont use UNUSED_PARAM, it exists only in 1.11.1 2008-07-11 21:50:45 +00:00
Denis Vlasenko fa1649e9ac cpio: backport the fix for
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466771
2008-07-11 21:47:23 +00:00
Denis Vlasenko dee8587d92 Apply post-1.11.0 patches. Bump version to 1.11.1. 2008-07-11 12:19:14 +00:00
Denis Vlasenko f941306199 defconfig fix; "help output to fd 2" fix 2008-06-25 12:52:37 +00:00
34 changed files with 507 additions and 311 deletions

No files matched your search

+1 -1
View File
@@ -298,7 +298,7 @@ config NOMMU
config BUILD_LIBBUSYBOX
bool "Build shared libbusybox"
default n
depends on !FEATURE_PREFER_APPLETS && !PIE
depends on !FEATURE_PREFER_APPLETS && !PIE && !STATIC
help
Build a shared library libbusybox.so.N.N.N which contains all
busybox code.
+1 -1
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 11
SUBLEVEL = 0
SUBLEVEL = 3
EXTRAVERSION =
NAME = Unnamed
+1 -3
View File
@@ -14,13 +14,11 @@ const char *applet_name;
int main(int argc, char **argv)
{
applet_name = argv[0];
return APPLET_main(argc,argv);
}
void bb_show_usage(void)
{
printf(APPLET_full_usage "\n");
fputs(APPLET_full_usage "\n", stdout);
exit(EXIT_FAILURE);
}
+11 -4
View File
@@ -14,14 +14,21 @@ exec >"$target"
echo 'static const char packed_usage[] ALIGN1 = {'
# Extra effort to avoid using "od -t x1": -t is not available
# in non-CONFIG_DESKTOPed busybox od
## Breaks on big-endian systems!
## # Extra effort to avoid using "od -t x1": -t is not available
## # in non-CONFIG_DESKTOPed busybox od
##
## "$loc/usage" | bzip2 -1 | od -v -x \
## | $SED -e 's/^[^ ]*//' \
## | $SED -e 's/ //g' \
## | grep -v '^$' \
## | $SED -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
"$loc/usage" | bzip2 -1 | od -v -x \
"$loc/usage" | bzip2 -1 | od -v -t x1 \
| $SED -e 's/^[^ ]*//' \
| $SED -e 's/ //g' \
| grep -v '^$' \
| $SED -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
| $SED -e 's/\(..\)/0x\1,/g'
echo '};'
echo '#define SIZEOF_usage_messages' `expr 0 + $sz`
+94 -16
View File
@@ -14,18 +14,6 @@
#include "libbb.h"
#include "unarchive.h"
enum {
CPIO_OPT_EXTRACT = (1 << 0),
CPIO_OPT_TEST = (1 << 1),
CPIO_OPT_UNCONDITIONAL = (1 << 2),
CPIO_OPT_VERBOSE = (1 << 3),
CPIO_OPT_FILE = (1 << 4),
CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
CPIO_OPT_PRESERVE_MTIME = (1 << 6),
CPIO_OPT_CREATE = (1 << 7),
CPIO_OPT_FORMAT = (1 << 8),
};
#if ENABLE_FEATURE_CPIO_O
static off_t cpio_pad4(off_t size)
{
@@ -190,21 +178,108 @@ static int cpio_o(void)
}
#endif
/* GNU cpio (GNU cpio) 2.9 help (abridged):
Main operation mode:
-i, --extract Extract files from an archive
-o, --create Create the archive
-p, --pass-through Copy-pass mode (was ist das?!)
-t, --list List the archive
Operation modifiers valid in any mode:
--block-size=SIZE I/O block size = SIZE * 512 bytes
-B I/O block size = 5120 bytes
-c Use the old portable (ASCII) archive format
-C, --io-size=NUMBER I/O block size to the given NUMBER bytes
-f, --nonmatching Only copy files that do not match given pattern
-F, --file=FILE Use FILE instead of standard input or output
-H, --format=FORMAT Use given archive FORMAT
-M, --message=STRING Print STRING when the end of a volume of the
backup media is reached
-n, --numeric-uid-gid If -v, show numeric UID and GID
--quiet Do not print the number of blocks copied
--rsh-command=COMMAND Use remote COMMAND instead of rsh
-v, --verbose Verbosely list the files processed
-V, --dot Print a "." for each file processed
-W, --warning=FLAG Control warning display: 'none','truncate','all';
multiple options accumulate
Operation modifiers valid only in --extract mode:
-b, --swap Swap both halfwords of words and bytes of
halfwords in the data (equivalent to -sS)
-r, --rename Interactively rename files
-s, --swap-bytes Swap the bytes of each halfword in the files
-S, --swap-halfwords Swap the halfwords of each word (4 bytes)
--to-stdout Extract files to standard output
-E, --pattern-file=FILE Read additional patterns specifying filenames to
extract or list from FILE
--only-verify-crc Verify CRC's, don't actually extract the files
Operation modifiers valid only in --create mode:
-A, --append Append to an existing archive
-O FILE File to use instead of standard output
Operation modifiers valid only in --pass-through mode:
-l, --link Link files instead of copying them, when possible
Operation modifiers valid in --extract and --create modes:
--absolute-filenames Do not strip file system prefix components from
the file names
--no-absolute-filenames Create all files relative to the current dir
Operation modifiers valid in --create and --pass-through modes:
-0, --null A list of filenames is terminated by a NUL
-a, --reset-access-time Reset the access times of files after reading them
-I FILE File to use instead of standard input
-L, --dereference Dereference symbolic links (copy the files
that they point to instead of copying the links)
-R, --owner=[USER][:.][GROUP] Set owner of created files
Operation modifiers valid in --extract and --pass-through modes:
-d, --make-directories Create leading directories where needed
-m, --preserve-modification-time
Retain previous file modification times when
creating files
--no-preserve-owner Do not change the ownership of the files
--sparse Write files with blocks of zeros as sparse files
-u, --unconditional Replace all files unconditionally
*/
int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
archive_handle_t *archive_handle;
char *cpio_filename;
#if ENABLE_FEATURE_CPIO_O
const char *cpio_fmt = "";
#endif
USE_FEATURE_CPIO_O(const char *cpio_fmt = "";)
unsigned opt;
enum {
CPIO_OPT_EXTRACT = (1 << 0),
CPIO_OPT_TEST = (1 << 1),
CPIO_OPT_UNCONDITIONAL = (1 << 2),
CPIO_OPT_VERBOSE = (1 << 3),
CPIO_OPT_FILE = (1 << 4),
CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
CPIO_OPT_PRESERVE_MTIME = (1 << 6),
CPIO_OPT_CREATE = (1 << 7),
CPIO_OPT_FORMAT = (1 << 8),
};
#if ENABLE_GETOPT_LONG && ENABLE_DESKTOP
applet_long_options =
"extract\0" No_argument "i"
"list\0" No_argument "t"
#if ENABLE_FEATURE_CPIO_O
"create\0" No_argument "o"
"format\0" Required_argument "H"
#endif
;
#endif
/* Initialize */
archive_handle = init_handle();
archive_handle->src_fd = STDIN_FILENO;
archive_handle->seek = seek_by_read;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER;
#if ENABLE_FEATURE_CPIO_O
opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename, &cpio_fmt);
@@ -258,6 +333,9 @@ int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
}
if (opt & CPIO_OPT_PRESERVE_MTIME) {
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
}
while (*argv) {
archive_handle->filter = filter_accept_list;
+11 -75
View File
@@ -66,7 +66,6 @@ struct group_data {
* | grep 'bd->' | sed 's/^.*bd->/bd->/' | sort | $PAGER
* and moved it (inbufBitCount) to offset 0.
*/
struct bunzip_data {
/* I/O tracking data (file handles, buffers, positions, etc.) */
unsigned inbufBitCount, inbufBits;
@@ -102,11 +101,9 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
/* If we need to get more data from the byte buffer, do so. (Loop getting
one byte at a time to enforce endianness and avoid unaligned access.) */
while ((int)(bd->inbufBitCount) < bits_wanted) {
/* If we need to read more data from file into byte buffer, do so */
if (bd->inbufPos == bd->inbufCount) {
/* if "no input fd" case: in_fd == -1, read fails, we jump */
bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE);
@@ -116,7 +113,6 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
}
/* Avoid 32-bit overflow (dump bit buffer to top of output) */
if (bd->inbufBitCount >= 24) {
bits = bd->inbufBits & ((1 << bd->inbufBitCount) - 1);
bits_wanted -= bd->inbufBitCount;
@@ -125,13 +121,11 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
}
/* Grab next 8 bits of input from buffer. */
bd->inbufBits = (bd->inbufBits << 8) | bd->inbuf[bd->inbufPos++];
bd->inbufBitCount += 8;
}
/* Calculate result */
bd->inbufBitCount -= bits_wanted;
bits |= (bd->inbufBits >> bd->inbufBitCount) & ((1 << bits_wanted) - 1);
@@ -139,7 +133,6 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
}
/* Unpacks the next block and sets up for the inverse burrows-wheeler step. */
static int get_next_block(bunzip_data *bd)
{
struct group_data *hufGroup;
@@ -153,13 +146,11 @@ static int get_next_block(bunzip_data *bd)
selectors = bd->selectors;
/* Reset longjmp I/O error handling */
i = setjmp(bd->jmpbuf);
if (i) return i;
/* Read in header signature and CRC, then validate signature.
(last block signature means CRC is for whole file, return now) */
i = get_bits(bd, 24);
j = get_bits(bd, 24);
bd->headerCRC = get_bits(bd, 32);
@@ -169,7 +160,6 @@ static int get_next_block(bunzip_data *bd)
/* We can add support for blockRandomised if anybody complains. There was
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
it didn't actually work. */
if (get_bits(bd, 1)) return RETVAL_OBSOLETE_INPUT;
origPtr = get_bits(bd, 24);
if ((int)origPtr > dbufSize) return RETVAL_DATA_ERROR;
@@ -179,7 +169,6 @@ static int get_next_block(bunzip_data *bd)
symbols to deal with, and writes a sparse bitfield indicating which
values were present. We make a translation table to convert the symbols
back to the corresponding bytes. */
t = get_bits(bd, 16);
symTotal = 0;
for (i = 0; i < 16; i++) {
@@ -192,7 +181,6 @@ static int get_next_block(bunzip_data *bd)
}
/* How many different Huffman coding groups does this block use? */
groupCount = get_bits(bd, 3);
if (groupCount < 2 || groupCount > MAX_GROUPS)
return RETVAL_DATA_ERROR;
@@ -201,19 +189,16 @@ static int get_next_block(bunzip_data *bd)
group. Read in the group selector list, which is stored as MTF encoded
bit runs. (MTF=Move To Front, as each value is used it's moved to the
start of the list.) */
nSelectors = get_bits(bd, 15);
if (!nSelectors) return RETVAL_DATA_ERROR;
for (i = 0; i < groupCount; i++) mtfSymbol[i] = i;
for (i = 0; i < nSelectors; i++) {
/* Get next value */
for (j = 0; get_bits(bd, 1); j++)
if (j >= groupCount) return RETVAL_DATA_ERROR;
/* Decode MTF to get the next selector */
uc = mtfSymbol[j];
for (;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
mtfSymbol[0] = selectors[i] = uc;
@@ -221,10 +206,11 @@ static int get_next_block(bunzip_data *bd)
/* Read the Huffman coding tables for each group, which code for symTotal
literal symbols, plus two run symbols (RUNA, RUNB) */
symCount = symTotal + 2;
for (j = 0; j < groupCount; j++) {
unsigned char length[MAX_SYMBOLS], temp[MAX_HUFCODE_BITS+1];
unsigned char length[MAX_SYMBOLS];
/* 8 bits is ALMOST enough for temp[], see below */
unsigned temp[MAX_HUFCODE_BITS+1];
int minLen, maxLen, pp;
/* Read Huffman code lengths for each symbol. They're stored in
@@ -233,7 +219,6 @@ static int get_next_block(bunzip_data *bd)
(Subtracting 1 before the loop and then adding it back at the end is
an optimization that makes the test inside the loop simpler: symbol
length 0 becomes negative, so an unsigned inequality catches it.) */
t = get_bits(bd, 5) - 1;
for (i = 0; i < symCount; i++) {
for (;;) {
@@ -243,7 +228,6 @@ static int get_next_block(bunzip_data *bd)
/* If first bit is 0, stop. Else second bit indicates whether
to increment or decrement the value. Optimization: grab 2
bits and unget the second if the first was 0. */
k = get_bits(bd, 2);
if (k < 2) {
bd->inbufBitCount++;
@@ -251,17 +235,14 @@ static int get_next_block(bunzip_data *bd)
}
/* Add one if second bit 1, else subtract 1. Avoids if/else */
t += (((k+1) & 2) - 1);
}
/* Correct for the initial -1, to get the final symbol length */
length[i] = t + 1;
}
/* Find largest and smallest lengths in this group */
minLen = maxLen = length[0];
for (i = 1; i < symCount; i++) {
if (length[i] > maxLen) maxLen = length[i];
@@ -278,7 +259,6 @@ static int get_next_block(bunzip_data *bd)
* number of bits can have. This is how the Huffman codes can vary in
* length: each code with a value>limit[length] needs another bit.
*/
hufGroup = bd->groups + j;
hufGroup->minLen = minLen;
hufGroup->maxLen = maxLen;
@@ -286,12 +266,10 @@ static int get_next_block(bunzip_data *bd)
/* Note that minLen can't be smaller than 1, so we adjust the base
and limit array pointers so we're not always wasting the first
entry. We do this again when using them (during symbol decoding).*/
base = hufGroup->base - 1;
limit = hufGroup->limit - 1;
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
pp = 0;
for (i = minLen; i <= maxLen; i++) {
temp[i] = limit[i] = 0;
@@ -301,14 +279,14 @@ static int get_next_block(bunzip_data *bd)
}
/* Count symbols coded for at each bit length */
/* NB: in pathological cases, temp[8] can end ip being 256.
* That's why uint8_t is too small for temp[]. */
for (i = 0; i < symCount; i++) temp[length[i]]++;
/* Calculate limit[] (the largest symbol-coding value at each bit
* length, which is (previous limit<<1)+symbols at this level), and
* base[] (number of symbols to ignore at each bit length, which is
* limit minus the cumulative count of symbols coded for already). */
pp = t = 0;
for (i = minLen; i < maxLen; i++) {
pp += temp[i];
@@ -319,7 +297,6 @@ static int get_next_block(bunzip_data *bd)
each level we're really only interested in the first few bits,
so here we set all the trailing to-be-ignored bits to 1 so they
don't affect the value>limit[length] comparison. */
limit[i] = (pp << (maxLen - i)) - 1;
pp <<= 1;
t += temp[i];
@@ -335,7 +312,6 @@ static int get_next_block(bunzip_data *bd)
and run length encoding, saving the result into dbuf[dbufCount++] = uc */
/* Initialize symbol occurrence counters and symbol Move To Front table */
memset(byteCount, 0, sizeof(byteCount)); /* smaller, maybe slower? */
for (i = 0; i < 256; i++) {
//byteCount[i] = 0;
@@ -347,8 +323,7 @@ static int get_next_block(bunzip_data *bd)
runPos = dbufCount = selector = 0;
for (;;) {
/* fetch next Huffman coding group from list. */
/* Fetch next Huffman coding group from list. */
symCount = GROUP_SIZE - 1;
if (selector >= nSelectors) return RETVAL_DATA_ERROR;
hufGroup = bd->groups + selectors[selector++];
@@ -367,7 +342,6 @@ static int get_next_block(bunzip_data *bd)
dry). The following (up to got_huff_bits:) is equivalent to
j = get_bits(bd, hufGroup->maxLen);
*/
while ((int)(bd->inbufBitCount) < hufGroup->maxLen) {
if (bd->inbufPos == bd->inbufCount) {
j = get_bits(bd, hufGroup->maxLen);
@@ -382,13 +356,11 @@ static int get_next_block(bunzip_data *bd)
got_huff_bits:
/* Figure how how many bits are in next symbol and unget extras */
i = hufGroup->minLen;
while (j > limit[i]) ++i;
bd->inbufBitCount += (hufGroup->maxLen - i);
/* Huffman decode value to get nextSym (with bounds checking) */
if (i > hufGroup->maxLen)
return RETVAL_DATA_ERROR;
j = (j >> (hufGroup->maxLen - i)) - base[i];
@@ -400,11 +372,9 @@ static int get_next_block(bunzip_data *bd)
byte, or a repeated run of the most recent literal byte. First,
check if nextSym indicates a repeated run, and if so loop collecting
how many times to repeat the last literal. */
if ((unsigned)nextSym <= SYMBOL_RUNB) { /* RUNA or RUNB */
/* If this is the start of a new run, zero out counter */
if (!runPos) {
runPos = 1;
t = 0;
@@ -417,7 +387,6 @@ static int get_next_block(bunzip_data *bd)
the basic or 0/1 method (except all bits 0, which would use no
symbols, but a run of length 0 doesn't mean anything in this
context). Thus space is saved. */
t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
if (runPos < dbufSize) runPos <<= 1;
goto end_of_huffman_loop;
@@ -427,7 +396,6 @@ static int get_next_block(bunzip_data *bd)
how many times to repeat the last literal, so append that many
copies to our buffer of decoded symbols (dbuf) now. (The last
literal used is the one at the head of the mtfSymbol array.) */
if (runPos) {
runPos = 0;
if (dbufCount + t >= dbufSize) return RETVAL_DATA_ERROR;
@@ -438,7 +406,6 @@ static int get_next_block(bunzip_data *bd)
}
/* Is this the terminating symbol? */
if (nextSym > symTotal) break;
/* At this point, nextSym indicates a new literal character. Subtract
@@ -448,7 +415,6 @@ static int get_next_block(bunzip_data *bd)
first symbol in the mtf array, position 0, would have been handled
as part of a run above. Therefore 1 unused mtf position minus
2 non-literal nextSym values equals -1.) */
if (dbufCount >= dbufSize) return RETVAL_DATA_ERROR;
i = nextSym - 1;
uc = mtfSymbol[i];
@@ -457,7 +423,6 @@ static int get_next_block(bunzip_data *bd)
* small number of symbols, and are bound by 256 in any case, using
* memmove here would typically be bigger and slower due to function
* call overhead and other assorted setup costs. */
do {
mtfSymbol[i] = mtfSymbol[i-1];
} while (--i);
@@ -465,13 +430,11 @@ static int get_next_block(bunzip_data *bd)
uc = symToByte[uc];
/* We have our literal byte. Save it into dbuf. */
byteCount[uc]++;
dbuf[dbufCount++] = (unsigned)uc;
/* Skip group initialization if we're not done with this group. Done
* this way to avoid compiler warning. */
end_of_huffman_loop:
if (symCount--) goto continue_this_group;
}
@@ -484,7 +447,6 @@ static int get_next_block(bunzip_data *bd)
*/
/* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
j = 0;
for (i = 0; i < 256; i++) {
k = j + byteCount[i];
@@ -493,7 +455,6 @@ static int get_next_block(bunzip_data *bd)
}
/* Figure out what order dbuf would be in if we sorted it. */
for (i = 0; i < dbufCount; i++) {
uc = (unsigned char)(dbuf[i] & 0xff);
dbuf[byteCount[uc]] |= (i << 8);
@@ -503,11 +464,10 @@ static int get_next_block(bunzip_data *bd)
/* Decode first byte by hand to initialize "previous" byte. Note that it
doesn't get output, and if the first three characters are identical
it doesn't qualify as a run (hence writeRunCountdown=5). */
if (dbufCount) {
if ((int)origPtr >= dbufCount) return RETVAL_DATA_ERROR;
bd->writePos = dbuf[origPtr];
bd->writeCurrent = (unsigned char)(bd->writePos & 0xff);
bd->writeCurrent = (unsigned char)(bd->writePos & 0xff);
bd->writePos >>= 8;
bd->writeRunCountdown = 5;
}
@@ -522,7 +482,6 @@ static int get_next_block(bunzip_data *bd)
error (all errors are negative numbers). If out_fd!=-1, outbuf and len
are ignored, data is written to out_fd and return is RETVAL_OK or error.
*/
int read_bunzip(bunzip_data *bd, char *outbuf, int len)
{
const unsigned *dbuf;
@@ -539,19 +498,15 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* We will always have pending decoded data to write into the output
buffer unless this is the very first call (in which case we haven't
Huffman-decoded a block into the intermediate buffer yet). */
if (bd->writeCopies) {
/* Inside the loop, writeCopies means extra copies (beyond 1) */
--bd->writeCopies;
/* Loop outputting bytes */
for (;;) {
/* If the output buffer is full, snapshot state and return */
if (gotcount >= len) {
bd->writePos = pos;
bd->writeCurrent = current;
@@ -560,13 +515,11 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
}
/* Write next byte into output buffer, updating CRC */
outbuf[gotcount++] = current;
bd->writeCRC = (bd->writeCRC << 8)
^ bd->crc32Table[(bd->writeCRC >> 24) ^ current];
^ bd->crc32Table[(bd->writeCRC >> 24) ^ current];
/* Loop now if we're outputting multiple copies of this byte */
if (bd->writeCopies) {
--bd->writeCopies;
continue;
@@ -582,35 +535,29 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* After 3 consecutive copies of the same byte, the 4th
* is a repeat count. We count down from 4 instead
* of counting up because testing for non-zero is faster */
if (--bd->writeRunCountdown) {
if (current != previous)
bd->writeRunCountdown = 4;
} else {
/* We have a repeated run, this byte indicates the count */
bd->writeCopies = current;
current = previous;
bd->writeRunCountdown = 5;
/* Sometimes there are just 3 bytes (run length 0) */
if (!bd->writeCopies) goto decode_next_byte;
/* Subtract the 1 copy we'd output anyway to get extras */
--bd->writeCopies;
}
}
/* Decompression of this block completed successfully */
bd->writeCRC = ~bd->writeCRC;
bd->totalCRC = ((bd->totalCRC << 1) | (bd->totalCRC >> 31)) ^ bd->writeCRC;
/* If this block had a CRC error, force file level CRC error. */
if (bd->writeCRC != bd->headerCRC) {
bd->totalCRC = bd->headerCRC + 1;
return RETVAL_LAST_BLOCK;
@@ -619,7 +566,6 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* Refill the intermediate buffer by Huffman-decoding next block of input */
/* (previous is just a convenient unused temp variable here) */
previous = get_next_block(bd);
if (previous) {
bd->writeCount = previous;
@@ -631,7 +577,6 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
goto decode_next_byte;
}
/* Allocate the structure, read file header. If in_fd==-1, inbuf must contain
a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
ignored, and data is read from file handle into temporary buffer. */
@@ -639,7 +584,6 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* Because bunzip2 is used for help text unpacking, and because bb_show_usage()
should work for NOFORK applets too, we must be extremely careful to not leak
any allocations! */
int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
int len)
{
@@ -650,16 +594,13 @@ int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
};
/* Figure out how much data to allocate */
i = sizeof(bunzip_data);
if (in_fd != -1) i += IOBUF_SIZE;
/* Allocate bunzip_data. Most fields initialize to zero. */
bd = *bdp = xzalloc(i);
/* Setup input buffer */
bd->in_fd = in_fd;
if (-1 == in_fd) {
/* in this case, bd->inbuf is read-only */
@@ -669,22 +610,18 @@ int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
bd->inbuf = (unsigned char *)(bd + 1);
/* Init the CRC32 table (big endian) */
crc32_filltable(bd->crc32Table, 1);
/* Setup for I/O error handling via longjmp */
i = setjmp(bd->jmpbuf);
if (i) return i;
/* Ensure that file starts with "BZh['1'-'9']." */
i = get_bits(bd, 32);
if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA;
/* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
/* Fourth byte (ascii '1'-'9') indicates block size in units of 100k of
uncompressed data. Allocate intermediate buffer for block. */
bd->dbufSize = 100000 * (i - BZh0);
/* Cannot use xmalloc - may leak bd in NOFORK case! */
@@ -704,7 +641,6 @@ void dealloc_bunzip(bunzip_data *bd)
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
USE_DESKTOP(long long) int
unpack_bz2_stream(int src_fd, int dst_fd)
{
@@ -761,9 +697,9 @@ int main(int argc, char **argv)
char c;
if (i < 0)
fprintf(stderr,"%s\n", bunzip_errors[-i]);
fprintf(stderr, "%s\n", bunzip_errors[-i]);
else if (read(STDIN_FILENO, &c, 1))
fprintf(stderr,"Trailing garbage ignored\n");
fprintf(stderr, "Trailing garbage ignored\n");
return -i;
}
#endif
+3 -2
View File
@@ -7,8 +7,8 @@
#include "libbb.h"
#include "unarchive.h"
typedef struct hardlinks_s {
struct hardlinks_s *next;
typedef struct hardlinks_t {
struct hardlinks_t *next;
int inode; /* TODO: must match maj/min too! */
int mode ;
int mtime; /* These three are useful only in corner case */
@@ -144,6 +144,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
free(make_me);
goto next_link;
}
cur = cur->next;
}
/* Oops... no file with such inode was created... do it now
* (happens when hardlinked files are empty (zero length)) */
+3 -2
View File
@@ -2,7 +2,7 @@
/*
* Mini kbd_mode implementation for busybox
*
* Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com>
* Copyright (C) 2007 Loic Grenie <loic.grenie@gmail.com>
* written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
* console-utils v0.2.3, licensed under GNU GPLv2
*
@@ -46,7 +46,8 @@ int kbd_mode_main(int ATTRIBUTE_UNUSED argc, char **argv)
printf("The keyboard is in %s mode\n", mode);
} else {
opt = opt & UNICODE ? 3 : opt >> 1;
xioctl(fd, KDSKBMODE, &opt);
/* double cast prevents warnings about widening conversion */
xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
}
if (ENABLE_FEATURE_CLEAN_UP)
+1 -1
View File
@@ -48,5 +48,5 @@ int basename_main(int argc, char **argv)
/* puts(s) will do, but we can do without stdio this way: */
s[m++] = '\n';
return full_write(STDOUT_FILENO, s, m) == (ssize_t)m;
return full_write(STDOUT_FILENO, s, m) != (ssize_t)m;
}
+19 -22
View File
@@ -17,7 +17,7 @@
-m, --machine sun
-a, --all SunOS rocky8 4.0 sun
The default behavior is equivalent to `-s'.
The default behavior is equivalent to '-s'.
David MacKenzie <djm@gnu.ai.mit.edu> */
@@ -39,47 +39,43 @@ typedef struct {
} uname_info_t;
static const char options[] ALIGN1 = "snrvmpa";
static const unsigned short utsname_offset[] ALIGN2 = {
offsetof(uname_info_t,name.sysname),
offsetof(uname_info_t,name.nodename),
offsetof(uname_info_t,name.release),
offsetof(uname_info_t,name.version),
offsetof(uname_info_t,name.machine),
offsetof(uname_info_t,processor)
static const unsigned short utsname_offset[] = {
offsetof(uname_info_t, name.sysname),
offsetof(uname_info_t, name.nodename),
offsetof(uname_info_t, name.release),
offsetof(uname_info_t, name.version),
offsetof(uname_info_t, name.machine),
offsetof(uname_info_t, processor)
};
int uname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uname_main(int argc, char **argv)
int uname_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
uname_info_t uname_info;
#if defined(__sparc__) && defined(__linux__)
char *fake_sparc = getenv("FAKE_SPARC");
#endif
const unsigned short int *delta;
const unsigned short *delta;
char toprint;
toprint = getopt32(argv, options);
if (argc != optind) {
if (argv[optind]) { /* coreutils-6.9 compat */
bb_show_usage();
}
if (toprint & (1 << 6)) {
if (toprint & (1 << 6)) { /* -a => all opts on */
toprint = 0x3f;
}
if (toprint == 0) {
toprint = 1; /* sysname */
if (toprint == 0) { /* no opts => -s (sysname) */
toprint = 1;
}
if (uname(&uname_info.name) == -1) {
bb_error_msg_and_die("cannot get system name");
}
uname(&uname_info.name); /* never fails */
#if defined(__sparc__) && defined(__linux__)
if ((fake_sparc != NULL)
&& ((fake_sparc[0] == 'y')
|| (fake_sparc[0] == 'Y'))) {
if (fake_sparc && (fake_sparc[0] | 0x20) == 'y') {
strcpy(uname_info.name.machine, "sparc");
}
#endif
@@ -89,7 +85,8 @@ int uname_main(int argc, char **argv)
delta = utsname_offset;
do {
if (toprint & 1) {
printf(((char *)(&uname_info)) + *delta);
/* printf would not be safe here */
fputs((char *)(&uname_info) + *delta, stdout);
if (toprint > 1) {
bb_putchar(' ');
}
@@ -98,5 +95,5 @@ int uname_main(int argc, char **argv)
} while (toprint >>= 1);
bb_putchar('\n');
fflush_stdout_and_exit(EXIT_SUCCESS);
fflush_stdout_and_exit(EXIT_SUCCESS); /* coreutils-6.9 compat */
}
+5 -1
View File
@@ -56,16 +56,20 @@ int who_main(int argc ATTRIBUTE_UNUSED, char **argv)
printf("USER TTY IDLE TIME HOST\n");
while ((ut = getutent()) != NULL) {
if (ut->ut_user[0] && (opt || ut->ut_type == USER_PROCESS)) {
time_t tmp;
/* ut->ut_line is device name of tty - "/dev/" */
name = concat_path_file("/dev", ut->ut_line);
str6[0] = '?';
str6[1] = '\0';
if (stat(name, &st) == 0)
idle_string(str6, st.st_atime);
/* manpages say ut_tv.tv_sec *is* time_t,
* but some systems have it wrong */
tmp = ut->ut_tv.tv_sec;
/* 15 chars for time: Nov 10 19:33:20 */
printf("%-10s %-8s %-9s %-15.15s %s\n",
ut->ut_user, ut->ut_line, str6,
ctime(&(ut->ut_tv.tv_sec)) + 4, ut->ut_host);
ctime(&tmp) + 4, ut->ut_host);
if (ENABLE_FEATURE_CLEAN_UP)
free(name);
}
+16 -8
View File
@@ -326,7 +326,9 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
char *signame;
char *startas;
char *chuid;
#ifdef OLDER_VERSION_OF_X
struct stat execstat;
#endif
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
// char *retry_arg = NULL;
// int retries = -1;
@@ -361,6 +363,8 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (!(opt & OPT_a))
startas = execname;
if (!execname) /* in case -a is given and -x is not */
execname = startas;
// USE_FEATURE_START_STOP_DAEMON_FANCY(
// if (retry_arg)
@@ -374,7 +378,8 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (errno)
user_id = xuname2uid(userspec);
}
do_procinit(); /* Both start and stop needs to know current processes */
/* Both start and stop need to know current processes */
do_procinit();
if (opt & CTX_STOP) {
int i = do_stop();
@@ -383,17 +388,21 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (found) {
if (!QUIET)
printf("%s already running\n%d\n", execname, found->pid);
printf("%s is already running\n%u\n", execname, (unsigned)found->pid);
return !(opt & OPT_OKNODO);
}
#ifdef OLDER_VERSION_OF_X
if (execname)
xstat(execname, &execstat);
#endif
*--argv = startas;
if (opt & OPT_BACKGROUND) {
#if BB_MMU
bb_daemonize(0);
bb_daemonize(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS);
/* DAEMON_DEVNULL_STDIO is superfluous -
* it's always done by bb_daemonize() */
#else
pid_t pid = vfork();
if (pid < 0) /* error */
@@ -404,19 +413,18 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
* so "return 0" may do bad things */
_exit(EXIT_SUCCESS);
}
/* child */
/* Child */
setsid(); /* detach from controlling tty */
/* Redirect stdio to /dev/null, close extra FDs.
* We do not actually daemonize because of DAEMON_ONLY_SANITIZE */
bb_daemonize_or_rexec(
DAEMON_DEVNULL_STDIO
bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO
+ DAEMON_CLOSE_EXTRA_FDS
+ DAEMON_ONLY_SANITIZE,
NULL /* argv, unused */ );
#endif
}
if (opt & OPT_MAKEPID) {
/* user wants _us_ to make the pidfile */
/* User wants _us_ to make the pidfile */
write_pidfile(pidfile);
}
if (opt & OPT_c) {
@@ -434,6 +442,6 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
}
}
#endif
execv(startas, argv);
execvp(startas, argv);
bb_perror_msg_and_die("cannot start %s", startas);
}
+21 -27
View File
@@ -681,11 +681,6 @@ static ALWAYS_INLINE int isalnum_(int c)
return (isalnum(c) || c == '_');
}
static FILE *afopen(const char *path, const char *mode)
{
return (*path == '-' && *(path+1) == '\0') ? stdin : xfopen(path, mode);
}
/* -------- working with variables (set/get/copy/etc) -------- */
static xhash *iamarray(var *v)
@@ -2740,7 +2735,7 @@ static rstream *next_input_file(void)
ind = getvar_s(incvar(intvar[ARGIND]));
fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind));
if (fname && *fname && !is_assignment(fname))
F = afopen(fname, "r");
F = xfopen_stdin(fname);
}
} while (!F);
@@ -2757,8 +2752,9 @@ int awk_main(int argc, char **argv)
{
unsigned opt;
char *opt_F, *opt_W;
llist_t *opt_v = NULL;
int i, j, flen;
llist_t *list_v = NULL;
llist_t *list_f = NULL;
int i, j;
var *v;
var tv;
char **envp;
@@ -2816,35 +2812,33 @@ int awk_main(int argc, char **argv)
*s1 = '=';
}
}
opt_complementary = "v::";
opt = getopt32(argv, "F:v:f:W:", &opt_F, &opt_v, &g_progname, &opt_W);
opt_complementary = "v::f::"; /* -v and -f can occur multiple times */
opt = getopt32(argv, "F:v:f:W:", &opt_F, &list_v, &list_f, &opt_W);
argv += optind;
argc -= optind;
if (opt & 0x1)
setvar_s(intvar[FS], opt_F); // -F
while (opt_v) { /* -v */
if (!is_assignment(llist_pop(&opt_v)))
while (list_v) { /* -v */
if (!is_assignment(llist_pop(&list_v)))
bb_show_usage();
}
if (opt & 0x4) { // -f
char *s = s; /* die, gcc, die */
FILE *from_file = afopen(g_progname, "r");
/* one byte is reserved for some trick in next_token */
if (fseek(from_file, 0, SEEK_END) == 0) {
flen = ftell(from_file);
s = xmalloc(flen + 4);
fseek(from_file, 0, SEEK_SET);
i = 1 + fread(s + 1, 1, flen, from_file);
} else {
if (list_f) { /* -f */
do {
char *s = NULL;
FILE *from_file;
g_progname = llist_pop(&list_f);
from_file = xfopen_stdin(g_progname);
/* one byte is reserved for some trick in next_token */
for (i = j = 1; j > 0; i += j) {
s = xrealloc(s, i + 4096);
j = fread(s + i, 1, 4094, from_file);
}
}
s[i] = '\0';
fclose(from_file);
parse_program(s + 1);
free(s);
s[i] = '\0';
fclose(from_file);
parse_program(s + 1);
free(s);
} while (list_f);
} else { // no -f: take program from 1st parameter
if (!argc)
bb_show_usage();
+18 -16
View File
@@ -147,10 +147,10 @@ struct globals {
#endif
smallint editing; // >0 while we are editing a file
// [code audit says "can be 0 or 1 only"]
// [code audit says "can be 0, 1 or 2 only"]
smallint cmd_mode; // 0=command 1=insert 2=replace
int file_modified; // buffer contents changed (counter, not flag!)
int last_file_modified; // = -1;
int last_file_modified; // = -1;
int fn_start; // index of first cmd line file name
int save_argc; // how many file names on cmd line
int cmdcnt; // repetition count
@@ -623,7 +623,7 @@ static void edit_file(char *fn)
// These are commands that change text[].
// Remember the input for the "." command
if (!adding2q && ioq_start == NULL
&& strchr(modifying_cmds, c)
&& c != '\0' && strchr(modifying_cmds, c)
) {
start_new_cmd_q(c);
}
@@ -645,8 +645,8 @@ static void edit_file(char *fn)
}
//-------------------------------------------------------------------
place_cursor(rows, 0, FALSE); // go to bottom of screen
clear_to_eol(); // Erase to end of line
place_cursor(rows - 1, 0, FALSE); // go to bottom of screen
clear_to_eol(); // erase to end of line
cookmode();
#undef cur_line
}
@@ -1894,7 +1894,7 @@ static char *text_hole_make(char *p, int size) // at "p", make a 'size' byte hol
p = new_text + (p - text);
text = new_text;
}
memmove(p + size, p, end - p);
memmove(p + size, p, end - size - p);
memset(p, ' ', size); // clear new hole
file_modified++;
return p;
@@ -2009,9 +2009,9 @@ static void start_new_cmd_q(char c)
{
// get buffer for new cmd
// if there is a current cmd count put it in the buffer first
if (cmdcnt > 0)
if (cmdcnt > 0) {
lmc_len = sprintf(last_modifying_cmd, "%d%c", cmdcnt, c);
else { // just save char c onto queue
} else { // just save char c onto queue
last_modifying_cmd[0] = c;
lmc_len = 1;
}
@@ -2247,18 +2247,20 @@ static char readit(void) // read (maybe cursor) key from stdin
fflush(stdout);
n = chars_to_parse;
// get input from User- are there already input chars in Q?
// get input from User - are there already input chars in Q?
if (n <= 0) {
// the Q is empty, wait for a typed char
again:
n = safe_read(STDIN_FILENO, readbuffer, sizeof(readbuffer));
if (n < 0) {
if (errno == EBADF || errno == EFAULT || errno == EINVAL
|| errno == EIO)
editing = 0; // want to exit
errno = 0;
if (n <= 0) {
place_cursor(rows - 1, 0, FALSE); // go to bottom of screen
clear_to_eol(); // erase to end of line
cookmode(); // terminal to "cooked"
bb_error_msg_and_die("can't read user input");
}
if (n <= 0)
return 0; // error
/* elsewhere we can get very confused by NULs */
if (readbuffer[0] == '\0')
goto again;
if (readbuffer[0] == 27) {
// This is an ESC char. Is this Esc sequence?
// Could be bare Esc key. See if there are any
+2 -1
View File
@@ -1140,6 +1140,7 @@ typedef struct procps_status_t {
uint8_t shift_pages_to_bytes;
uint8_t shift_pages_to_kb;
/* Fields are set to 0/NULL if failed to determine (or not requested) */
uint16_t argv_len;
char *argv0;
USE_SELINUX(char *context;)
/* Everything below must contain no ptrs to malloc'ed data:
@@ -1187,7 +1188,7 @@ enum {
PSSCAN_UTIME = 1 << 13,
PSSCAN_TTY = 1 << 14,
PSSCAN_SMAPS = (1 << 15) * ENABLE_FEATURE_TOPMEM,
PSSCAN_ARGVN = (1 << 16) * (ENABLE_PGREP | ENABLE_PKILL),
PSSCAN_ARGVN = (1 << 16) * (ENABLE_PGREP || ENABLE_PKILL || ENABLE_PIDOF),
USE_SELINUX(PSSCAN_CONTEXT = 1 << 17,)
PSSCAN_START_TIME = 1 << 18,
/* These are all retrieved from proc/NN/stat in one go: */
+10 -12
View File
@@ -2916,13 +2916,13 @@
"\n -u Unlock (re-enable) account" \
#define chpasswd_trivial_usage \
USE_GETOPT_LONG("[--md5|--encrypt]") SKIP_GETOPT_LONG("[-m|-e]")
USE_GETOPT_LONG("[--md5|--encrypted]") SKIP_GETOPT_LONG("[-m|-e]")
#define chpasswd_full_usage "\n\n" \
"Read user:password information from stdin\n" \
"Read user:password information from stdin " \
"and update /etc/passwd accordingly.\n" \
"\nOptions:" \
USE_GETOPT_LONG( \
"\n -e,--encrypt Supplied passwords are in encrypted form" \
"\n -e,--encrypted Supplied passwords are in encrypted form" \
"\n -m,--md5 Use MD5 encryption instead of DES" \
) \
SKIP_GETOPT_LONG( \
@@ -3637,13 +3637,11 @@
"$ cat TODO | split -a 2 -l 2 TODO_\n"
#define start_stop_daemon_trivial_usage \
"[OPTIONS] [" \
USE_GETOPT_LONG("--start|--stop") SKIP_GETOPT_LONG("-S|-K") \
"] ... [-- arguments...]"
"[OPTIONS] [-S|-K] ... [-- arguments...]"
#define start_stop_daemon_full_usage "\n\n" \
"Search for matching processes, and then\n" \
"-S: stop all matching processes.\n" \
"-K: start a process unless a matching process is found.\n" \
"-S: start a process unless a matching process is found.\n" \
"-K: stop all matching processes.\n" \
USE_GETOPT_LONG( \
"\nProcess matching:" \
"\n -u,--user USERNAME|UID Match only this user's processes" \
@@ -3653,7 +3651,7 @@
"\n in /proc/PID/cmdline" \
"\n -p,--pidfile FILE Match a process with PID from the file" \
"\n All specified conditions must match" \
"\n-K only:" \
"\n-S only:" \
"\n -x,--exec EXECUTABLE Program to run" \
"\n -a,--startas NAME Zeroth argument" \
"\n -b,--background Background" \
@@ -3662,7 +3660,7 @@
) \
"\n -c,--chuid USER[:[GRP]] Change to user/group" \
"\n -m,--make-pidfile Write PID to the pidfile specified by -p" \
"\n-S only:" \
"\n-K only:" \
"\n -s,--signal SIG Signal to send" \
"\n -t,--test Match only, exit with 0 if a process is found" \
"\nOther:" \
@@ -3681,7 +3679,7 @@
"\n command in /proc/PID/cmdline" \
"\n -p FILE Match a process with PID from the file" \
"\n All specified conditions must match" \
"\n-K only:" \
"\n-S only:" \
"\n -x EXECUTABLE Program to run" \
"\n -a NAME Zeroth argument" \
"\n -b Background" \
@@ -3690,7 +3688,7 @@
) \
"\n -c USER[:[GRP]] Change to user/group" \
"\n -m Write PID to the pidfile specified by -p" \
"\n-S only:" \
"\n-K only:" \
"\n -s SIG Signal to send" \
"\n -t Match only, exit with 0 if a process is found" \
"\nOther:" \
+1
View File
@@ -638,6 +638,7 @@ static int busybox_main(char **argv)
/* leading tab and room to wrap */
output_width -= MAX_APPLET_NAME_LEN + 8;
dup2(1, 2);
full_write2_str(bb_banner); /* reuse const string... */
full_write2_str(" multi-call binary\n"
"Copyright (C) 1998-2008 Erik Andersen, Rob Landley, Denys Vlasenko\n"
+35 -10
View File
@@ -38,6 +38,35 @@ execXXX("/proc/self/exe", applet_name, params....)
and therefore comm field contains "exe".
*/
static int comm_match(procps_status_t *p, const char *procName)
{
int argv1idx;
/* comm does not match */
if (strncmp(p->comm, procName, 15) != 0)
return 0;
/* in Linux, if comm is 15 chars, it may be a truncated */
if (p->comm[14] == '\0') /* comm is not truncated - match */
return 1;
/* comm is truncated, but first 15 chars match.
* This can be crazily_long_script_name.sh!
* The telltale sign is basename(argv[1]) == procName. */
if (!p->argv0)
return 0;
argv1idx = strlen(p->argv0) + 1;
if (argv1idx >= p->argv_len)
return 0;
if (strcmp(bb_basename(p->argv0 + argv1idx), procName) != 0)
return 0;
return 1;
}
/* find_pid_by_name()
*
* Modified by Vladimir Oleynik for use with libbb/procps.c
@@ -48,22 +77,18 @@ and therefore comm field contains "exe".
* Returns a list of all matching PIDs
* It is the caller's duty to free the returned pidlist.
*/
pid_t* find_pid_by_name(const char* procName)
pid_t* find_pid_by_name(const char *procName)
{
pid_t* pidList;
int i = 0;
procps_status_t* p = NULL;
pidList = xmalloc(sizeof(*pidList));
while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGV0))) {
if (
/* we require comm to match and to not be truncated */
/* in Linux, if comm is 15 chars, it may be a truncated
* name, so we don't allow that to match */
(!p->comm[sizeof(p->comm)-2] && strcmp(p->comm, procName) == 0)
pidList = xzalloc(sizeof(*pidList));
while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGVN))) {
if (comm_match(p, procName)
/* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/
|| (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0)
/* TOOD: we can also try /proc/NUM/exe link, do we want that? */
/* TODO: we can also try /proc/NUM/exe link, do we want that? */
) {
pidList = xrealloc(pidList, sizeof(*pidList) * (i+2));
pidList[i++] = p->pid;
@@ -74,7 +99,7 @@ pid_t* find_pid_by_name(const char* procName)
return pidList;
}
pid_t *pidlist_reverse(pid_t *pidList)
pid_t* pidlist_reverse(pid_t *pidList)
{
int i = 0;
while (pidList[i])
+48 -27
View File
@@ -953,24 +953,33 @@ static void input_tab(smallint *lastWasTab)
#if MAX_HISTORY > 0
/* state->flags is already checked to be nonzero */
static void get_previous_history(void)
static void save_command_ps_at_cur_history(void)
{
if (command_ps[0] != '\0' || state->history[state->cur_history] == NULL) {
free(state->history[state->cur_history]);
state->history[state->cur_history] = xstrdup(command_ps);
if (command_ps[0] != '\0') {
int cur = state->cur_history;
free(state->history[cur]);
state->history[cur] = xstrdup(command_ps);
}
state->cur_history--;
}
/* state->flags is already checked to be nonzero */
static int get_previous_history(void)
{
if ((state->flags & DO_HISTORY) && state->cur_history) {
save_command_ps_at_cur_history();
state->cur_history--;
return 1;
}
beep();
return 0;
}
static int get_next_history(void)
{
if (state->flags & DO_HISTORY) {
int ch = state->cur_history;
if (ch < state->cnt_history) {
get_previous_history(); /* save the current history line */
state->cur_history = ch + 1;
return state->cur_history;
if (state->cur_history < state->cnt_history) {
save_command_ps_at_cur_history(); /* save the current history line */
return ++state->cur_history;
}
}
beep();
@@ -992,6 +1001,7 @@ static void load_history(const char *fromfile)
for (hi = state->cnt_history; hi > 0;) {
hi--;
free(state->history[hi]);
state->history[hi] = NULL;
}
for (hi = 0; hi < MAX_HISTORY;) {
@@ -1003,14 +1013,14 @@ static void load_history(const char *fromfile)
l = strlen(hl);
if (l >= MAX_LINELEN)
hl[MAX_LINELEN-1] = '\0';
if (l == 0 || hl[0] == ' ') {
if (l == 0) {
free(hl);
continue;
}
state->history[hi++] = hl;
}
fclose(fp);
state->cur_history = state->cnt_history = hi;
state->cnt_history = hi;
}
}
@@ -1040,19 +1050,27 @@ static void remember_in_history(const char *str)
if (!(state->flags & DO_HISTORY))
return;
if (str[0] == '\0')
return;
i = state->cnt_history;
free(state->history[MAX_HISTORY]);
state->history[MAX_HISTORY] = NULL;
/* After max history, remove the oldest command */
/* Don't save dupes */
if (i && strcmp(state->history[i-1], str) == 0)
return;
free(state->history[MAX_HISTORY]); /* redundant, paranoia */
state->history[MAX_HISTORY] = NULL; /* redundant, paranoia */
/* If history[] is full, remove the oldest command */
/* we need to keep history[MAX_HISTORY] empty, hence >=, not > */
if (i >= MAX_HISTORY) {
free(state->history[0]);
for (i = 0; i < MAX_HISTORY-1; i++)
state->history[i] = state->history[i+1];
/* i == MAX_HISTORY-1 */
}
// Maybe "if (!i || strcmp(history[i-1], command) != 0) ..."
// (i.e. do not save dups?)
/* i <= MAX_HISTORY-1 */
state->history[i++] = xstrdup(str);
/* i <= MAX_HISTORY */
state->cur_history = i;
state->cnt_history = i;
#if ENABLE_FEATURE_EDITING_SAVEHISTORY
@@ -1394,6 +1412,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
if ((state->flags & SAVE_HISTORY) && state->hist_file)
load_history(state->hist_file);
#endif
state->cur_history = state->cnt_history;
/* prepare before init handlers */
cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */
@@ -1429,6 +1448,13 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
}
}
#endif
#if 0
for (ic = 0; ic <= MAX_HISTORY; ic++)
bb_error_msg("history[%d]:'%s'", ic, state->history[ic]);
bb_error_msg("cur_history:%d cnt_history:%d", state->cur_history, state->cnt_history);
#endif
/* Print out the command prompt */
parse_and_put_prompt(prompt);
@@ -1537,11 +1563,8 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
vi_case(CTRL('P')|vbit:)
vi_case('k'|vbit:)
/* Control-p -- Get previous command from history */
if ((state->flags & DO_HISTORY) && state->cur_history > 0) {
get_previous_history();
if (get_previous_history())
goto rewrite_line;
}
beep();
break;
#endif
@@ -1730,10 +1753,8 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
#if MAX_HISTORY > 0
case 'A':
/* Up Arrow -- Get previous command from history */
if ((state->flags & DO_HISTORY) && state->cur_history > 0) {
get_previous_history();
if (get_previous_history())
goto rewrite_line;
}
beep();
break;
case 'B':
@@ -1743,7 +1764,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t
rewrite_line:
/* Rewrite the line with the selected history item */
/* change command */
command_len = strlen(strcpy(command, state->history[state->cur_history]));
command_len = strlen(strcpy(command, state->history[state->cur_history] ? : ""));
/* redraw and go to eol (bol, in vi */
redraw(cmdedit_y, (state->flags & VI_MODE) ? 9999 : 0);
break;
+1 -1
View File
@@ -19,8 +19,8 @@ int print_flags_separated(const int *masks, const char *labels, int flags, const
labels);
need_separator = separator;
flags &= ~ *masks;
masks++;
}
masks++;
labels += strlen(labels) + 1;
}
return flags;
+7 -8
View File
@@ -385,16 +385,15 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags)
n = read_to_buf(filename, buf);
if (n <= 0)
break;
#if ENABLE_PGREP || ENABLE_PKILL
if (flags & PSSCAN_ARGVN) {
do {
n--;
if (buf[n] == '\0')
buf[n] = ' ';
} while (n);
sp->argv_len = n;
sp->argv0 = xmalloc(n + 1);
memcpy(sp->argv0, buf, n + 1);
/* sp->argv0[n] = '\0'; - buf has it */
} else {
sp->argv_len = 0;
sp->argv0 = xstrdup(buf);
}
#endif
sp->argv0 = xstrdup(buf);
}
#endif
break;
+3 -3
View File
@@ -65,8 +65,8 @@ int chpasswd_main(int argc ATTRIBUTE_UNUSED, char **argv)
bb_info_msg("Password for '%s' changed", name);
logmode = LOGMODE_STDIO;
free(name);
free(pass);
if (!(opt & OPT_ENC))
free(pass);
}
return 0;
return EXIT_SUCCESS;
}
+10 -9
View File
@@ -93,6 +93,7 @@ int crontab_main(int argc ATTRIBUTE_UNUSED, char **argv)
char *new_fname;
char *user_name; /* -u USER */
int fd;
int src_fd;
int opt_ler;
/* file [opts] Replace crontab from file
@@ -144,15 +145,15 @@ int crontab_main(int argc ATTRIBUTE_UNUSED, char **argv)
bb_show_usage();
/* Read replacement file under user's UID/GID/group vector */
src_fd = STDIN_FILENO;
if (!opt_ler) { /* Replace? */
if (!argv[0])
bb_show_usage();
if (NOT_LONE_DASH(argv[0])) {
fd = open_as_user(pas, argv[0]);
if (fd < 0)
src_fd = open_as_user(pas, argv[0]);
if (src_fd < 0)
bb_error_msg_and_die("user %s cannot read %s",
pas->pw_name, argv[0]);
xmove_fd(fd, STDIN_FILENO);
}
}
@@ -180,23 +181,23 @@ int crontab_main(int argc ATTRIBUTE_UNUSED, char **argv)
tmp_fname = xasprintf("%s.%u", crontab_dir, (unsigned)getpid());
/* No O_EXCL: we don't want to be stuck if earlier crontabs
* were killed, leaving stale temp file behind */
fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC, 0600);
xmove_fd(fd, STDIN_FILENO);
fchown(STDIN_FILENO, pas->pw_uid, pas->pw_gid);
src_fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC, 0600);
fchown(src_fd, pas->pw_uid, pas->pw_gid);
fd = open(pas->pw_name, O_RDONLY);
if (fd >= 0) {
bb_copyfd_eof(fd, STDIN_FILENO);
bb_copyfd_eof(fd, src_fd);
close(fd);
xlseek(src_fd, 0, SEEK_SET);
}
close_on_exec_on(src_fd); /* don't want editor to see this fd */
edit_file(pas, tmp_fname);
xlseek(STDIN_FILENO, 0, SEEK_SET);
/* fall through */
case 0: /* Replace (no -l, -e, or -r were given) */
new_fname = xasprintf("%s.new", pas->pw_name);
fd = open(new_fname, O_WRONLY|O_CREAT|O_TRUNC|O_APPEND, 0600);
if (fd >= 0) {
bb_copyfd_eof(STDIN_FILENO, fd);
bb_copyfd_eof(src_fd, fd);
close(fd);
xrename(new_fname, pas->pw_name);
} else {
+2
View File
@@ -117,6 +117,8 @@ int last_main(int argc, char **argv ATTRIBUTE_UNUSED)
strcpy(ut.ut_line, "system boot");
}
}
/* manpages say ut_tv.tv_sec *is* time_t,
* but some systems have it wrong */
t_tmp = (time_t)ut.ut_tv.tv_sec;
printf("%-10s %-14s %-18s %-12.12s\n",
ut.ut_user, ut.ut_line, ut.ut_host, ctime(&t_tmp) + 4);
+5 -1
View File
@@ -48,8 +48,12 @@ static void show_entry(struct utmp *ut, int state, time_t dur_secs)
char logout_time[8];
const char *logout_str;
const char *duration_str;
time_t tmp;
safe_strncpy(login_time, ctime(&(ut->ut_tv.tv_sec)), 17);
/* manpages say ut_tv.tv_sec *is* time_t,
* but some systems have it wrong */
tmp = ut->ut_tv.tv_sec;
safe_strncpy(login_time, ctime(&tmp), 17);
snprintf(logout_time, 8, "- %s", ctime(&dur_secs) + 11);
dur_secs = MAX(dur_secs - (time_t)ut->ut_tv.tv_sec, (time_t)0);
+9 -7
View File
@@ -73,7 +73,7 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
char *sec_list;
char *cur_path, *cur_sect;
char *line, *value;
int count_mp, alloc_mp, cur_mp;
int count_mp, cur_mp;
int opt;
opt_complementary = "-1"; /* at least one argument */
@@ -81,8 +81,8 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
argv += optind;
sec_list = xstrdup("1:2:3:4:5:6:7:8:9");
alloc_mp = 10;
man_path_list = xmalloc(10 * sizeof(man_path_list[0]));
/* Last valid man_path_list[] is [0x10] */
man_path_list = xzalloc(0x11 * sizeof(man_path_list[0]));
count_mp = 0;
man_path_list[0] = xstrdup(getenv("MANPATH"));
if (man_path_list[0])
@@ -107,11 +107,13 @@ int man_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (strcmp("MANPATH", line) == 0) {
man_path_list[count_mp] = xstrdup(value);
count_mp++;
if (alloc_mp == count_mp) {
alloc_mp += 10;
man_path_list = xrealloc(man_path_list, alloc_mp * sizeof(man_path_list[0]));
/* man_path_list is NULL terminated */
man_path_list[count_mp] = NULL;
if (!(count_mp & 0xf)) { /* 0x10, 0x20 etc */
/* so that last valid man_path_list[] is [count_mp + 0x10] */
man_path_list = xrealloc(man_path_list,
(count_mp + 0x11) * sizeof(man_path_list[0]));
}
/* thus man_path_list is always NULL terminated */
}
if (strcmp("MANSECT", line) == 0) {
free(sec_list);
+2 -1
View File
@@ -35,7 +35,8 @@ static char *__from_cpuset(cpu_set_t *mask)
#define TASKSET_PRINTF_MASK "%x"
/* (void*) cast is for battling gcc: */
/* "dereferencing type-punned pointer will break strict-aliasing rules" */
#define from_cpuset(mask) (*(unsigned*)(void*)&(mask))
#define from_cpuset(mask) ({ void *__vp = &(mask); *(unsigned*)__vp; })
/* gcc 4.3.0 still complains: #define from_cpuset(mask) (*(unsigned*)(void*)&(mask)) */
#endif
+2 -1
View File
@@ -840,7 +840,8 @@ arch_apply_relocation(struct obj_file *f,
ElfW(RelM) *rel, ElfW(Addr) v)
{
#if defined(__arm__) || defined(__i386__) || defined(__mc68000__) \
|| defined(__sh__) || defined(__s390__) || defined(__x86_64__)
|| defined(__sh__) || defined(__s390__) || defined(__x86_64__) \
|| defined(__powerpc__) || defined(__mips__)
struct arch_file *ifile = (struct arch_file *) f;
#endif
enum obj_reloc ret = obj_reloc_ok;
+8 -1
View File
@@ -111,8 +111,15 @@ int pgrep_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (proc->pid == pid)
continue;
cmd = proc->argv0;
if (!cmd)
if (!cmd) {
cmd = proc->comm;
} else {
int i = proc->argv_len;
while (i) {
if (!cmd[i]) cmd[i] = ' ';
i--;
}
}
/* NB: OPT_INVERT is always 0 or 1 */
if ((regexec(&re_buffer, cmd, 1, re_match, 0) == 0 /* match found */
&& (!OPT_ANCHOR || (re_match[0].rm_so == 0 && re_match[0].rm_eo == (regoff_t)strlen(cmd)))) ^ OPT_INVERT
+26 -5
View File
@@ -1,7 +1,7 @@
#
# Automatically generated make config: don't edit
# Busybox version: 1.10.0.svn
# Fri Mar 21 21:33:40 2008
# Busybox version: 1.11.0.svn
# Wed Jun 25 12:56:32 2008
#
CONFIG_HAVE_DOT_CONFIG=y
@@ -13,6 +13,7 @@ CONFIG_HAVE_DOT_CONFIG=y
# General Configuration
#
# CONFIG_DESKTOP is not set
# CONFIG_FEATURE_ASSUME_UNICODE is not set
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
@@ -38,16 +39,19 @@ CONFIG_FEATURE_HAVE_RPC=y
# Build Options
#
# CONFIG_STATIC is not set
# CONFIG_PIE is not set
# CONFIG_NOMMU is not set
# CONFIG_BUILD_LIBBUSYBOX is not set
# CONFIG_FEATURE_INDIVIDUAL is not set
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
CONFIG_LFS=y
CONFIG_CROSS_COMPILER_PREFIX=""
#
# Debugging Options
#
# CONFIG_DEBUG is not set
# CONFIG_DEBUG_PESSIMIZE is not set
# CONFIG_WERROR is not set
CONFIG_NO_DEBUG_LIB=y
# CONFIG_DMALLOC is not set
@@ -100,6 +104,7 @@ CONFIG_FEATURE_AR_LONG_FILENAMES=y
CONFIG_BUNZIP2=y
CONFIG_BZIP2=y
CONFIG_CPIO=y
CONFIG_FEATURE_CPIO_O=y
# CONFIG_DPKG is not set
# CONFIG_DPKG_DEB is not set
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
@@ -382,8 +387,9 @@ CONFIG_MESG=y
# Login/Password Management Utilities
#
CONFIG_FEATURE_SHADOWPASSWDS=y
CONFIG_USE_BB_SHADOW=y
CONFIG_USE_BB_PWD_GRP=y
CONFIG_USE_BB_SHADOW=y
CONFIG_USE_BB_CRYPT=y
CONFIG_ADDGROUP=y
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
CONFIG_DELGROUP=y
@@ -420,6 +426,9 @@ CONFIG_LSATTR=y
#
# Linux Module Utilities
#
CONFIG_DEPMOD=y
CONFIG_FEATURE_DEPMOD_PRUNE_FANCY=y
CONFIG_FEATURE_DEPMOD_ALIAS=y
CONFIG_INSMOD=y
CONFIG_FEATURE_INSMOD_VERSION_CHECKING=y
CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS=y
@@ -432,6 +441,7 @@ CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT=y
CONFIG_MODPROBE=y
CONFIG_FEATURE_MODPROBE_MULTIPLE_OPTIONS=y
CONFIG_FEATURE_MODPROBE_FANCY_ALIAS=y
CONFIG_FEATURE_MODPROBE_BLACKLIST=y
#
# Options common to multiple modutils
@@ -439,6 +449,8 @@ CONFIG_FEATURE_MODPROBE_FANCY_ALIAS=y
CONFIG_FEATURE_CHECK_TAINTED_MODULE=y
CONFIG_FEATURE_2_4_MODULES=y
CONFIG_FEATURE_2_6_MODULES=y
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
# CONFIG_FEATURE_QUERY_MODULE_INTERFACE is not set
#
@@ -481,6 +493,7 @@ CONFIG_LOSETUP=y
CONFIG_MDEV=y
CONFIG_FEATURE_MDEV_CONF=y
CONFIG_FEATURE_MDEV_RENAME=y
CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
CONFIG_FEATURE_MDEV_EXEC=y
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
CONFIG_MKSWAP=y
@@ -517,8 +530,10 @@ CONFIG_PIVOT_ROOT=y
CONFIG_RDATE=y
CONFIG_READPROFILE=y
CONFIG_RTCWAKE=y
CONFIG_SCRIPT=y
CONFIG_SETARCH=y
CONFIG_SWAPONOFF=y
CONFIG_FEATURE_SWAPON_PRI=y
CONFIG_SWITCH_ROOT=y
CONFIG_UMOUNT=y
CONFIG_FEATURE_UMOUNT_ALL=y
@@ -556,7 +571,10 @@ CONFIG_DC=y
CONFIG_EJECT=y
CONFIG_FEATURE_EJECT_SCSI=y
CONFIG_FBSPLASH=y
CONFIG_INOTIFYD=y
CONFIG_LAST=y
CONFIG_FEATURE_LAST_SMALL=y
# CONFIG_FEATURE_LAST_FANCY is not set
CONFIG_LESS=y
CONFIG_FEATURE_LESS_MAXLINES=9999999
CONFIG_FEATURE_LESS_BRACKETS=y
@@ -574,6 +592,7 @@ CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y
CONFIG_MAKEDEVS=y
# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
CONFIG_FEATURE_MAKEDEVS_TABLE=y
CONFIG_MAN=y
CONFIG_MICROCOM=y
CONFIG_MOUNTPOINT=y
CONFIG_MT=y
@@ -581,9 +600,8 @@ CONFIG_RAIDAUTORUN=y
CONFIG_READAHEAD=y
CONFIG_RUNLEVEL=y
CONFIG_RX=y
CONFIG_SCRIPT=y
CONFIG_STRINGS=y
CONFIG_SETSID=y
CONFIG_STRINGS=y
CONFIG_TASKSET=y
CONFIG_FEATURE_TASKSET_FANCY=y
CONFIG_TIME=y
@@ -600,6 +618,7 @@ CONFIG_ARP=y
CONFIG_ARPING=y
CONFIG_BRCTL=y
CONFIG_FEATURE_BRCTL_FANCY=y
CONFIG_FEATURE_BRCTL_SHOW=y
CONFIG_DNSD=y
CONFIG_ETHER_WAKE=y
CONFIG_FAKEIDENTD=y
@@ -761,6 +780,7 @@ CONFIG_ASH_MATH_SUPPORT=y
CONFIG_ASH_MATH_SUPPORT_64=y
# CONFIG_ASH_GETOPTS is not set
CONFIG_ASH_BUILTIN_ECHO=y
CONFIG_ASH_BUILTIN_PRINTF=y
CONFIG_ASH_BUILTIN_TEST=y
CONFIG_ASH_CMDCMD=y
# CONFIG_ASH_MAIL is not set
@@ -782,6 +802,7 @@ CONFIG_ASH_RANDOM_SUPPORT=y
#
CONFIG_FEATURE_SH_EXTRA_QUIET=y
# CONFIG_FEATURE_SH_STANDALONE is not set
# CONFIG_FEATURE_SH_NOFORK is not set
# CONFIG_CTTYHACK is not set
#
+36
View File
@@ -0,0 +1,36 @@
#!/bin/sh
# Generates a small Makefile used in the root of the output
# directory, to allow make to be started from there.
# The Makefile also allow for more convinient build of external modules
# Usage
# $1 - Kernel src directory
# $2 - Output directory
# $3 - version
# $4 - patchlevel
test ! -r $2/Makefile -o -O $2/Makefile || exit 0
echo " GEN $2/Makefile"
cat << EOF > $2/Makefile
# Automatically generated by $0: don't edit
VERSION = $3
PATCHLEVEL = $4
KERNELSRC := $1
KERNELOUTPUT := $2
MAKEFLAGS += --no-print-directory
.PHONY: all \$(MAKECMDGOALS)
all:
\$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT)
Makefile:;
\$(filter-out all Makefile,\$(MAKECMDGOALS)) %/:
\$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$@
EOF
+1 -1
View File
@@ -51,7 +51,7 @@ config ASH_BASH_COMPAT
default y
depends on ASH
help
Enable bash-conpatible extensions.
Enable bash-compatible extensions.
config ASH_JOB_CONTROL
bool "Job control"
+53 -19
View File
@@ -1569,14 +1569,14 @@ static char *optionarg; /* set by nextopt (like getopt) */
static char *optptr; /* used by nextopt */
/*
* XXX - should get rid of. have all builtins use getopt(3). the
* library getopt must have the BSD extension static variable "optreset"
* otherwise it can't be used within the shell safely.
* XXX - should get rid of. Have all builtins use getopt(3).
* The library getopt must have the BSD extension static variable
* "optreset", otherwise it can't be used within the shell safely.
*
* Standard option processing (a la getopt) for builtin routines. The
* only argument that is passed to nextopt is the option string; the
* other arguments are unnecessary. It return the character, or '\0' on
* end of input.
* Standard option processing (a la getopt) for builtin routines.
* The only argument that is passed to nextopt is the option string;
* the other arguments are unnecessary. It returns the character,
* or '\0' on end of input.
*/
static int
nextopt(const char *optstring)
@@ -1587,13 +1587,20 @@ nextopt(const char *optstring)
p = optptr;
if (p == NULL || *p == '\0') {
/* We ate entire "-param", take next one */
p = *argptr;
if (p == NULL || *p != '-' || *++p == '\0')
if (p == NULL)
return '\0';
if (*p != '-')
return '\0';
if (*++p == '\0') /* just "-" ? */
return '\0';
argptr++;
if (LONE_DASH(p)) /* check for "--" */
if (LONE_DASH(p)) /* "--" ? */
return '\0';
/* p => next "-param" */
}
/* p => some option char in the middle of a "-param" */
c = *p++;
for (q = optstring; *q != c;) {
if (*q == '\0')
@@ -1602,8 +1609,11 @@ nextopt(const char *optstring)
q++;
}
if (*++q == ':') {
if (*p == '\0' && (p = *argptr++) == NULL)
ash_msg_and_raise_error("no arg for -%c option", c);
if (*p == '\0') {
p = *argptr++;
if (p == NULL)
ash_msg_and_raise_error("no arg for -%c option", c);
}
optionarg = p;
p = NULL;
}
@@ -7428,8 +7438,10 @@ commandcmd(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
else if (c != 'p')
abort();
#endif
if (verify)
/* Mimic bash: just "command -v" doesn't complain, it's a nop */
if (verify && (*argptr != NULL)) {
return describe_command(*argptr, verify - VERIFY_BRIEF);
}
return 0;
}
@@ -7788,16 +7800,33 @@ static void prehash(union node *);
static void
evaltree(union node *n, int flags)
{
struct jmploc *volatile savehandler = exception_handler;
struct jmploc jmploc;
int checkexit = 0;
void (*evalfn)(union node *, int);
unsigned isor;
int status;
if (n == NULL) {
TRACE(("evaltree(NULL) called\n"));
goto out;
goto out1;
}
TRACE(("pid %d, evaltree(%p: %d, %d) called\n",
getpid(), n, n->type, flags));
exception_handler = &jmploc;
{
int err = setjmp(jmploc.loc);
if (err) {
/* if it was a signal, check for trap handlers */
if (exception == EXSIG)
goto out;
/* continue on the way out */
exception_handler = savehandler;
longjmp(exception_handler->loc, err);
}
}
switch (n->type) {
default:
#if DEBUG
@@ -7843,19 +7872,20 @@ evaltree(union node *n, int flags)
goto calleval;
case NAND:
case NOR:
case NSEMI:
case NSEMI: {
#if NAND + 1 != NOR
#error NAND + 1 != NOR
#endif
#if NOR + 1 != NSEMI
#error NOR + 1 != NSEMI
#endif
isor = n->type - NAND;
unsigned is_or = n->type - NAND;
evaltree(
n->nbinary.ch1,
(flags | ((isor >> 1) - 1)) & EV_TESTED
(flags | ((is_or >> 1) - 1)) & EV_TESTED
);
if (!exitstatus == isor)
if (!exitstatus == is_or)
break;
if (!evalskip) {
n = n->nbinary.ch2;
@@ -7866,6 +7896,7 @@ evaltree(union node *n, int flags)
break;
}
break;
}
case NIF:
evaltree(n->nif.test, EV_TESTED);
if (evalskip)
@@ -7886,8 +7917,11 @@ evaltree(union node *n, int flags)
exitstatus = status;
break;
}
out:
if ((checkexit & exitstatus))
exception_handler = savehandler;
out1:
if (checkexit & exitstatus)
evalskip |= SKIPEVAL;
else if (pendingsig && dotrap())
goto exexit;
+41 -25
View File
@@ -4,13 +4,7 @@
. testing.sh
# check if hexdump supports the '-R' option
hexdump -R </dev/null >/dev/null 2>&1 || {
echo "'hexdump -R' is not available" >&2
exit 1
}
# ls -ln is showing date. Need to remove that, it's variable
# ls -ln shows date. Need to remove that, it's variable.
# sed: coalesce spaces
# cut: remove date
FILTER_LS="sed 's/ */ /g' | cut -d' ' -f 1-5,9-"
@@ -18,28 +12,27 @@ FILTER_LS="sed 's/ */ /g' | cut -d' ' -f 1-5,9-"
# newc cpio archive of directory cpio.testdir with empty x and y hardlinks
hexdump="\
00000000 42 5a 68 39 31 41 59 26 53 59 64 1e 91 8c 00 00
00000010 48 7f 80 4c 48 08 00 28 01 ff e0 3f 24 14 00 0e
00000020 20 dc 60 20 00 92 11 ea a0 1a 00 00 00 03 20 8a
00000030 93 d4 9a 68 1a 0d 1e 91 a1 a0 06 98 e3 5c 2f d9
00000040 26 a1 25 24 20 ed 47 c7 21 40 2b 6e f2 e6 fe 98
00000050 13 68 a8 bd 82 b2 4f 26 02 24 16 5b 22 16 72 74
00000060 15 cd c1 a6 9e a6 5e 6c 16 37 35 01 99 c4 81 21
00000070 29 28 4b 69 51 a9 3c 1a 9b 0a e1 e4 b4 af 85 73
00000080 ba 23 10 59 e8 b3 e1 a1 63 05 8c 4f c5 dc 91 4e
00000090 14 24 19 07 a4 63 00
"
\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x64\x1e\x91\x8c\x00\x00\
\x48\x7f\x80\x4c\x48\x08\x00\x28\x01\xff\xe0\x3f\x24\x14\x00\x0e\
\x20\xdc\x60\x20\x00\x92\x11\xea\xa0\x1a\x00\x00\x00\x03\x20\x8a\
\x93\xd4\x9a\x68\x1a\x0d\x1e\x91\xa1\xa0\x06\x98\xe3\x5c\x2f\xd9\
\x26\xa1\x25\x24\x20\xed\x47\xc7\x21\x40\x2b\x6e\xf2\xe6\xfe\x98\
\x13\x68\xa8\xbd\x82\xb2\x4f\x26\x02\x24\x16\x5b\x22\x16\x72\x74\
\x15\xcd\xc1\xa6\x9e\xa6\x5e\x6c\x16\x37\x35\x01\x99\xc4\x81\x21\
\x29\x28\x4b\x69\x51\xa9\x3c\x1a\x9b\x0a\xe1\xe4\xb4\xaf\x85\x73\
\xba\x23\x10\x59\xe8\xb3\xe1\xa1\x63\x05\x8c\x4f\xc5\xdc\x91\x4e\
\x14\x24\x19\x07\xa4\x63\x00"
user=$(id -u)
group=$(id -g)
rm -rf cpio.testdir
rm -rf cpio.testdir cpio.testdir2 2>/dev/null
# testing "test name" "options" "expected result" "file input" "stdin"
# testing "test name" "command" "expected result" "file input" "stdin"
testing "cpio extracts zero-sized hardlinks" \
"echo '$hexdump' | hexdump -R | bzcat | cpio -i; echo \$?;
ls -ln cpio.testdir | $FILTER_LS" \
"echo -ne '$hexdump' | bzcat | cpio -i; echo \$?;
ls -ln cpio.testdir | $FILTER_LS" \
"\
1 blocks
0
@@ -51,7 +44,7 @@ testing "cpio extracts zero-sized hardlinks" \
# Currently fails. Numerous: "1 blocks" versus "1 block",
# "1 block" must go to stderr, does not list cpio.testdir/x and cpio.testdir/y
testing "cpio lists hardlinks" \
"echo '$hexdump' | hexdump -R | bzcat | cpio -t 2>&1; echo \$?" \
"echo -ne '$hexdump' | bzcat | cpio -t 2>&1; echo \$?" \
"\
1 block
cpio.testdir
@@ -61,7 +54,30 @@ cpio.testdir/y
" \
"" ""
# clean up
rm -rf cpio.testdir
# More complex case
rm -rf cpio.testdir cpio.testdir2 2>/dev/null
mkdir cpio.testdir
touch cpio.testdir/solo
touch cpio.testdir/empty
echo x >cpio.testdir/nonempty
ln cpio.testdir/empty cpio.testdir/empty1
ln cpio.testdir/nonempty cpio.testdir/nonempty1
mkdir cpio.testdir2
testing "cpio extracts zero-sized hardlinks 2" \
"find cpio.testdir | cpio -H newc --create | (cd cpio.testdir2 && cpio -i); echo \$?;
ls -ln cpio.testdir2/cpio.testdir | $FILTER_LS" \
"\
0
-rw-r--r-- 2 $user $group 0 empty
-rw-r--r-- 2 $user $group 0 empty1
-rw-r--r-- 2 $user $group 2 nonempty
-rw-r--r-- 2 $user $group 2 nonempty1
-rw-r--r-- 1 $user $group 0 solo
" \
"" ""
# Clean up
rm -rf cpio.testdir cpio.testdir2 2>/dev/null
exit $FAILCOUNT