Skip to content

Commit

Permalink
Merge branch 'busybox'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmyorston committed Jul 25, 2018
2 parents 779fd57 + 81de30d commit 5987351
Show file tree
Hide file tree
Showing 213 changed files with 2,877 additions and 1,398 deletions.
2 changes: 1 addition & 1 deletion Config.in
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#

mainmenu "Configuration"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
@@ -1,5 +1,5 @@
VERSION = 1
PATCHLEVEL = 29
PATCHLEVEL = 30
SUBLEVEL = 0
EXTRAVERSION = .git
NAME = Unnamed
Expand Down
2 changes: 1 addition & 1 deletion archival/Config.src
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#

menu "Archival Utilities"
Expand Down
11 changes: 7 additions & 4 deletions archival/cpio.c
Expand Up @@ -64,15 +64,17 @@
//usage: "\n -p DIR Copy files to DIR"
//usage: )
//usage: "\nOptions:"
//usage: IF_FEATURE_CPIO_O(
//usage: "\n -H newc Archive format"
//usage: )
//usage: "\n -d Make leading directories"
//usage: "\n -m Preserve mtime"
//usage: "\n -v Verbose"
//usage: "\n -u Overwrite"
//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
//usage: "\n -R USER[:GRP] Set owner of created files"
//usage: IF_FEATURE_CPIO_O(
//usage: "\n -H newc Archive format"
//usage: )
//usage: "\n -L Dereference symlinks"
//usage: "\n -0 Input is separated by NULs"

/* GNU cpio 2.9 --help (abridged):
Expand Down Expand Up @@ -374,6 +376,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
#endif
"owner\0" Required_argument "R"
"verbose\0" No_argument "v"
"null\0" No_argument "0"
"quiet\0" No_argument "\xff"
"to-stdout\0" No_argument "\xfe"
;
Expand Down Expand Up @@ -508,7 +511,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;

create_symlinks_from_list(archive_handle->symlink_placeholders);
create_links_from_list(archive_handle->link_placeholders);

if (archive_handle->cpio__blocks != (off_t)-1
&& !(opt & OPT_QUIET)
Expand Down
12 changes: 6 additions & 6 deletions archival/gzip.c
Expand Up @@ -333,12 +333,6 @@ struct globals {
/* DECLARE(Pos, head, 1<<HASH_BITS); */
#define head (G1.prev + WSIZE) /* hash head (see deflate.c) */

/* =========================================================================== */
/* all members below are zeroed out in pack_gzip() for each next file */

uint32_t crc; /* shift register contents */
/*uint32_t *crc_32_tab;*/

#if ENABLE_FEATURE_GZIP_LEVELS
unsigned max_chain_length;
unsigned max_lazy_match;
Expand All @@ -350,6 +344,12 @@ struct globals {
#define nice_match (G1.nice_match)
#endif

/* =========================================================================== */
/* all members below are zeroed out in pack_gzip() for each next file */

uint32_t crc; /* shift register contents */
/*uint32_t *crc_32_tab;*/

/* window position at the beginning of the current output block. Gets
* negative when the window is moved backwards.
*/
Expand Down
16 changes: 7 additions & 9 deletions archival/libarchive/data_extract_all.c
Expand Up @@ -122,13 +122,10 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)

/* Handle hard links separately */
if (hard_link) {
res = link(hard_link, dst_name);
if (res != 0) {
/* shared message */
bb_perror_msg("can't create %slink '%s' to '%s'",
"hard", dst_name, hard_link
);
}
create_or_remember_link(&archive_handle->link_placeholders,
hard_link,
dst_name,
1);
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
goto ret;
}
Expand Down Expand Up @@ -195,9 +192,10 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
*
* Untarring bug.tar would otherwise place evil.py in '/tmp'.
*/
create_or_remember_symlink(&archive_handle->symlink_placeholders,
create_or_remember_link(&archive_handle->link_placeholders,
file_header->link_target,
dst_name);
dst_name,
0);
break;
case S_IFSOCK:
case S_IFBLK:
Expand Down
6 changes: 5 additions & 1 deletion archival/libarchive/decompress_unlzma.c
Expand Up @@ -350,8 +350,12 @@ unpack_lzma_stream(transformer_state_t *xstate)
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;

pos = buffer_pos - rep0;
if ((int32_t)pos < 0)
if ((int32_t)pos < 0) {
pos += header.dict_size;
/* see unzip_bad_lzma_2.zip: */
if (pos >= buffer_size)
goto bad;
}
previous_byte = buffer[pos];
goto one_byte1;
#else
Expand Down
2 changes: 1 addition & 1 deletion archival/libarchive/get_header_ar.c
Expand Up @@ -126,7 +126,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS)
continue;
create_symlinks_from_list(sa->symlink_placeholders);
create_links_from_list(sa->link_placeholders);
} else
#endif
archive_handle->action_data(archive_handle);
Expand Down
21 changes: 11 additions & 10 deletions archival/libarchive/unsafe_symlink_target.c
Expand Up @@ -5,15 +5,16 @@
#include "libbb.h"
#include "bb_archive.h"

void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders
void FAST_FUNC create_or_remember_link(llist_t **link_placeholders
IF_PLATFORM_MINGW32(UNUSED_PARAM),
const char *target,
const char *linkname)
const char *linkname,
int hard_link IF_PLATFORM_MINGW32(UNUSED_PARAM))
{
#if !ENABLE_PLATFORM_MINGW32
if (target[0] == '/' || strstr(target, "..")) {
llist_add_to(symlink_placeholders,
xasprintf("%s%c%s", linkname, '\0', target)
if (hard_link || target[0] == '/' || strstr(target, "..")) {
llist_add_to_end(link_placeholders,
xasprintf("%c%s%c%s", hard_link, linkname, '\0', target)
);
return;
}
Expand All @@ -30,17 +31,17 @@ void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders
}

#if !ENABLE_PLATFORM_MINGW32
void FAST_FUNC create_symlinks_from_list(llist_t *list)
void FAST_FUNC create_links_from_list(llist_t *list)
{
while (list) {
char *target;

target = list->data + strlen(list->data) + 1;
if (symlink(target, list->data)) {
target = list->data + 1 + strlen(list->data + 1) + 1;
if ((*list->data ? link : symlink) (target, list->data + 1)) {
/* shared message */
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
"sym",
list->data, target
*list->data ? "hard" : "sym",
list->data + 1, target
);
}
list = list->link;
Expand Down
2 changes: 1 addition & 1 deletion archival/tar.c
Expand Up @@ -1279,7 +1279,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */

create_symlinks_from_list(tar_handle->symlink_placeholders);
create_links_from_list(tar_handle->link_placeholders);

/* Check that every file that should have been extracted was */
while (tar_handle->accept) {
Expand Down
7 changes: 4 additions & 3 deletions archival/unzip.c
Expand Up @@ -375,9 +375,10 @@ static void unzip_extract_symlink(llist_t **symlink_placeholders,
target[xstate.mem_output_size] = '\0';
#endif
}
create_or_remember_symlink(symlink_placeholders,
create_or_remember_link(symlink_placeholders,
target,
dst_fn);
dst_fn,
0);
free(target);
}
#endif
Expand Down Expand Up @@ -993,7 +994,7 @@ int unzip_main(int argc, char **argv)
}

#if ENABLE_FEATURE_UNZIP_CDF
create_symlinks_from_list(symlink_placeholders);
create_links_from_list(symlink_placeholders);
#endif

if ((opts & OPT_l) && quiet <= 1) {
Expand Down
2 changes: 1 addition & 1 deletion console-tools/Config.src
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#

menu "Console Utilities"
Expand Down
2 changes: 1 addition & 1 deletion coreutils/Config.src
@@ -1,6 +1,6 @@
#
# For a description of the syntax of this configuration file,
# see scripts/kbuild/config-language.txt.
# see docs/Kconfig-language.txt.
#

menu "Coreutils"
Expand Down
24 changes: 24 additions & 0 deletions coreutils/cp.c
Expand Up @@ -24,6 +24,11 @@
//config: help
//config: Enable long options.
//config: Also add support for --parents option.
//config:
//config:config FEATURE_CP_REFLINK
//config: bool "Enable --reflink[=auto]"
//config: default y
//config: depends on FEATURE_CP_LONG_OPTIONS

//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
/* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */
Expand Down Expand Up @@ -72,10 +77,14 @@ int cp_main(int argc, char **argv)
#if ENABLE_FEATURE_CP_LONG_OPTIONS
/*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */
OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1),
OPT_reflink = 1 << (FILEUTILS_CP_OPTNUM+2),
#endif
};

#if ENABLE_FEATURE_CP_LONG_OPTIONS
# if ENABLE_FEATURE_CP_REFLINK
char *reflink = NULL;
# endif
flags = getopt32long(argv, "^"
FILEUTILS_CP_OPTSTR
"\0"
Expand All @@ -99,7 +108,22 @@ int cp_main(int argc, char **argv)
"update\0" No_argument "u"
"remove-destination\0" No_argument "\xff"
"parents\0" No_argument "\xfe"
# if ENABLE_FEATURE_CP_REFLINK
"reflink\0" Optional_argument "\xfd"
, &reflink
# endif
);
# if ENABLE_FEATURE_CP_REFLINK
BUILD_BUG_ON(OPT_reflink != FILEUTILS_REFLINK);
if (flags & FILEUTILS_REFLINK) {
if (!reflink)
flags |= FILEUTILS_REFLINK_ALWAYS;
else if (strcmp(reflink, "always") == 0)
flags |= FILEUTILS_REFLINK_ALWAYS;
else if (strcmp(reflink, "auto") != 0)
bb_show_usage();
}
# endif
#else
flags = getopt32(argv, "^"
FILEUTILS_CP_OPTSTR
Expand Down
6 changes: 5 additions & 1 deletion coreutils/install.c
Expand Up @@ -214,7 +214,11 @@ int install_main(int argc, char **argv)
dest = last;
if (opts & OPT_MKDIR_LEADING) {
char *ddir = xstrdup(dest);
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
/*
* -D -t DIR1/DIR2/F3 FILE: create DIR1/DIR2/F3, copy FILE there
* -D FILE DIR1/DIR2/F3: create DIR1/DIR2, copy FILE there as F3
*/
bb_make_directory((opts & OPT_TARGET) ? ddir : dirname(ddir), 0755, mkdir_flags);
/* errors are not checked. copy_file
* will fail if dir is not created.
*/
Expand Down
44 changes: 34 additions & 10 deletions coreutils/nproc.c
Expand Up @@ -14,10 +14,14 @@
//kbuild:lib-$(CONFIG_NPROC) += nproc.o

//usage:#define nproc_trivial_usage
//usage: ""
//TODO: "[--all] [--ignore=N]"
//usage: ""IF_LONG_OPTS("--all --ignore=N")
//usage:#define nproc_full_usage "\n\n"
//usage: "Print number of CPUs"
//usage: "Print number of available CPUs"
//usage: IF_LONG_OPTS(
//usage: "\n"
//usage: "\n --all Number of installed CPUs"
//usage: "\n --ignore=N Exclude N CPUs"
//usage: )

#include <sched.h>
#include "libbb.h"
Expand All @@ -26,13 +30,30 @@ int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
unsigned long mask[1024];
unsigned i, count = 0;

//getopt32(argv, "");

//if --all, count /sys/devices/system/cpu/cpuN dirs, else:
int count = 0;
#if ENABLE_LONG_OPTS
int ignore = 0;
int opts = getopt32long(argv, "\xfe:+",
"ignore\0" Required_argument "\xfe"
"all\0" No_argument "\xff"
, &ignore
);

if (opts & (1 << 1)) {
DIR *cpusd = opendir("/sys/devices/system/cpu");
if (cpusd) {
struct dirent *de;
while (NULL != (de = readdir(cpusd))) {
char *cpuid = strstr(de->d_name, "cpu");
if (cpuid && isdigit(cpuid[strlen(cpuid) - 1]))
count++;
}
closedir(cpusd);
}
} else
#endif
if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) {
int i;
for (i = 0; i < ARRAY_SIZE(mask); i++) {
unsigned long m = mask[i];
while (m) {
Expand All @@ -42,8 +63,11 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
}
}
}
if (count == 0)
count++;

IF_LONG_OPTS(count -= ignore;)
if (count <= 0)
count = 1;

printf("%u\n", count);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion coreutils/readlink.c
Expand Up @@ -86,7 +86,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv)

/* NOFORK: only one alloc is allowed; must free */
if (opt & 1) { /* -f */
buf = xmalloc_realpath(fname);
buf = xmalloc_realpath_coreutils(fname);
} else {
buf = xmalloc_readlink_or_warn(fname);
}
Expand Down
2 changes: 1 addition & 1 deletion coreutils/realpath.c
Expand Up @@ -38,7 +38,7 @@ int realpath_main(int argc UNUSED_PARAM, char **argv)

do {
/* NOFORK: only one alloc is allowed; must free */
char *resolved_path = xmalloc_realpath(*argv);
char *resolved_path = xmalloc_realpath_coreutils(*argv);
if (resolved_path != NULL) {
puts(resolved_path);
free(resolved_path);
Expand Down

0 comments on commit 5987351

Please sign in to comment.