From 20a63b2c18e9e69b02090d49b4aec399f082fdaf Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 22 Aug 2017 22:03:17 +0200 Subject: ash: report reason when a script file could not be opened It is always nicer to give the user some sort of indication why an operation failed. Signed-off-by: Johannes Schindelin Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index 703802ff5..a67a45376 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10575,7 +10575,7 @@ setinputfile(const char *fname, int flags) if (flags & INPUT_NOFILE_OK) goto out; exitstatus = 127; - ash_msg_and_raise_error("can't open '%s'", fname); + ash_msg_and_raise_perror("can't open '%s'", fname); } if (fd < 10) fd = savefd(fd); -- cgit v1.2.3-55-g6feb From 687aac056d08ef7c0eafb3d610d3dcdce35b635a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 22 Aug 2017 22:03:22 +0200 Subject: ash: when cd fails, say why Signed-off-by: Johannes Schindelin Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index a67a45376..60bcd1b0a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2748,7 +2748,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) goto docd; err: - ash_msg_and_raise_error("can't cd to %s", dest); + ash_msg_and_raise_perror("can't cd to %s", dest); /* NOTREACHED */ out: if (flags & CD_PRINT) -- cgit v1.2.3-55-g6feb From 12ffefb5490b281db7f2cde11bf8cf8c91283e83 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 23 Aug 2017 14:52:56 +0200 Subject: ash: more s/error/perror/ for better error reporting Signed-off-by: Denys Vlasenko --- shell/ash.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 60bcd1b0a..3fa7f4d9f 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -4994,7 +4994,7 @@ forkchild(struct job *jp, union node *n, int mode) if (jp->nprocs == 0) { close(0); if (open(bb_dev_null, O_RDONLY) != 0) - ash_msg_and_raise_error("can't open '%s'", bb_dev_null); + ash_msg_and_raise_perror("can't open '%s'", bb_dev_null); } } if (oldlvl == 0) { @@ -5083,7 +5083,7 @@ forkshell(struct job *jp, union node *n, int mode) TRACE(("Fork failed, errno=%d", errno)); if (jp) freejob(jp); - ash_msg_and_raise_error("can't fork"); + ash_msg_and_raise_perror("can't fork"); } if (pid == 0) { CLEAR_RANDOM_T(&random_gen); /* or else $RANDOM repeats in child */ @@ -5226,7 +5226,7 @@ openhere(union node *redir) size_t len = 0; if (pipe(pip) < 0) - ash_msg_and_raise_error("pipe call failed"); + ash_msg_and_raise_perror("can't create pipe"); if (redir->type == NHERE) { len = strlen(redir->nhere.doc->narg.text); if (len <= PIPE_BUF) { @@ -6288,7 +6288,7 @@ evalbackcmd(union node *n, struct backcmd *result) } if (pipe(pip) < 0) - ash_msg_and_raise_error("pipe call failed"); + ash_msg_and_raise_perror("can't create pipe"); jp = makejob(/*n,*/ 1); if (forkshell(jp, n, FORK_NOJOB) == 0) { /* child */ @@ -9180,7 +9180,7 @@ evalpipe(union node *n, int flags) if (lp->next) { if (pipe(pip) < 0) { close(prevfd); - ash_msg_and_raise_error("pipe call failed"); + ash_msg_and_raise_perror("can't create pipe"); } } if (forkshell(jp, lp->n, n->npipe.pipe_backgnd) == 0) { -- cgit v1.2.3-55-g6feb From 8b77a9ea81a0bd89ee69e7742d9b920dd1562763 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 23 Aug 2017 15:08:25 +0200 Subject: *: fix fallout from opt_complementary conversion Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 2 +- selinux/setfiles.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 25fa44389..4f881eaf9 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -2235,7 +2235,7 @@ static NOINLINE void ntp_init(char **argv) "wp:*S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ IF_FEATURE_NTPD_SERVER("I:") /* compat */ "d" /* compat */ - "46aAbgL", /* compat, ignored */ + "46aAbgL" /* compat, ignored */ "\0" "dd:wn" /* -d: counter; -p: list; -w implies -n */ IF_FEATURE_NTPD_SERVER(":Il") /* -I implies -l */ diff --git a/selinux/setfiles.c b/selinux/setfiles.c index 8da47d274..740eaf8fb 100644 --- a/selinux/setfiles.c +++ b/selinux/setfiles.c @@ -613,19 +613,21 @@ int setfiles_main(int argc UNUSED_PARAM, char **argv) /* Option order must match OPT_x definitions! */ if (applet_name[0] == 'r') { /* restorecon */ flags = getopt32(argv, "^" - "de:*f:ilnpqrsvo:FWR", - "\0" "vv:v--p:p--v:v--q:q--v"; + "de:*f:ilnpqrsvo:FWR" + "\0" + "vv:v--p:p--v:v--q:q--v", &exclude_dir, &input_filename, &out_filename, - &verbose + &verbose ); } else { /* setfiles */ flags = getopt32(argv, "^" "de:*f:ilnpqr:svo:FW" - IF_FEATURE_SETFILES_CHECK_OPTION("c:"), - "\0" "vv:v--p:p--v:v--q:q--v"; + IF_FEATURE_SETFILES_CHECK_OPTION("c:") + "\0" + "vv:v--p:p--v:v--q:q--v", &exclude_dir, &input_filename, &rootpath, &out_filename, IF_FEATURE_SETFILES_CHECK_OPTION(&policyfile,) - &verbose + &verbose ); } argv += optind; -- cgit v1.2.3-55-g6feb From 9c47c43e07365abe1eda02d69572b9e579b49cec Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 23 Aug 2017 17:56:03 +0200 Subject: sed: in '/regexp/cmd1;//cmd2', cmd2 should use the same regexp as cmd1 function old new delta get_address 165 211 +46 Signed-off-by: Denys Vlasenko --- editors/sed.c | 14 ++++++++++---- testsuite/sed.tests | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 3fc40ceef..7ed9937d2 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -350,10 +350,16 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex) if (*my_str == '\\') delimiter = *++pos; next = index_of_next_unescaped_regexp_delim(delimiter, ++pos); - temp = copy_parsing_escapes(pos, next); - *regex = xzalloc(sizeof(regex_t)); - xregcomp(*regex, temp, G.regex_type); - free(temp); + if (next != 0) { + temp = copy_parsing_escapes(pos, next); + G.previous_regex_ptr = *regex = xzalloc(sizeof(regex_t)); + xregcomp(*regex, temp, G.regex_type); + free(temp); + } else { + *regex = G.previous_regex_ptr; + if (!G.previous_regex_ptr) + bb_error_msg_and_die("no previous regexp"); + } /* Move position to next character after last delimiter */ pos += (next+1); } diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 05c00a99b..675cb4f10 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -387,6 +387,12 @@ testing "sed 's///w FILE'" \ "" \ "123\nqwe\nasd\n" +testing "sed uses previous regexp" \ + "sed '/w/p;//q'" \ + "q\nw\nw\n" \ + "" \ + "q\nw\ne\nr\n" + # testing "description" "commands" "result" "infile" "stdin" exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From b270be3fb3a905258e1b8ebb30a17ac175b684f1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Aug 2017 11:21:27 +0200 Subject: xargs: code shrink function old new delta xargs_main 827 787 -40 Signed-off-by: Denys Vlasenko --- findutils/xargs.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/findutils/xargs.c b/findutils/xargs.c index c3d37a64d..b4e3db02c 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -14,7 +14,6 @@ * xargs is described in the Single Unix Specification v3 at * http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html */ - //config:config XARGS //config: bool "xargs (6.7 kb)" //config: default y @@ -105,6 +104,7 @@ struct globals { #define INIT_G() do { \ setup_common_bufsiz(); \ G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \ + G.idx = 0; \ IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \ IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \ } while (0) @@ -141,7 +141,7 @@ static int xargs_exec(void) static void store_param(char *s) { /* Grow by 256 elements at once */ - if (!(G.idx & 0xff)) { /* G.idx == N*256 */ + if (!(G.idx & 0xff)) { /* G.idx == N*256? */ /* Enlarge, make G.args[(N+1)*256 - 1] last valid idx */ G.args = xrealloc(G.args, sizeof(G.args[0]) * (G.idx + 0x100)); } @@ -476,8 +476,9 @@ enum { IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::") int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int xargs_main(int argc, char **argv) +int xargs_main(int argc UNUSED_PARAM, char **argv) { + int initial_idx; int i; int child_error = 0; char *max_args; @@ -513,11 +514,11 @@ int xargs_main(int argc, char **argv) } argv += optind; - argc -= optind; + //argc -= optind; if (!argv[0]) { /* default behavior is to echo all the filenames */ *--argv = (char*)"echo"; - argc++; + //argc++; } /* @@ -572,7 +573,6 @@ int xargs_main(int argc, char **argv) */ G.args = NULL; G.argv = argv; - argc = 0; read_args = process_stdin_with_replace; /* Make -I imply -r. GNU findutils seems to do the same: */ /* (otherwise "echo -n | xargs -I% echo %" would SEGV) */ @@ -580,30 +580,27 @@ int xargs_main(int argc, char **argv) } else #endif { - /* Allocate pointers for execvp. + /* Store the command to be executed, part 1. * We can statically allocate (argc + n_max_arg + 1) elements * and do not bother with resizing args[], but on 64-bit machines * this results in args[] vector which is ~8 times bigger * than n_max_chars! That is, with n_max_chars == 20k, * args[] will take 160k (!), which will most likely be * almost entirely unused. - * - * See store_param() for matching 256-step growth logic */ - G.args = xmalloc(sizeof(G.args[0]) * ((argc + 0xff) & ~0xff)); - /* Store the command to be executed, part 1 */ for (i = 0; argv[i]; i++) - G.args[i] = argv[i]; + store_param(argv[i]); } + initial_idx = G.idx; while (1) { char *rem; - G.idx = argc; + G.idx = initial_idx; rem = read_args(n_max_chars, n_max_arg, buf); store_param(NULL); - if (!G.args[argc]) { + if (!G.args[initial_idx]) { /* not even one ARG was added? */ if (*rem != '\0') bb_error_msg_and_die("argument line too long"); if (opt & OPT_NO_EMPTY) -- cgit v1.2.3-55-g6feb From 14551b7036acf98f81d76674f351ce99148762c8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 24 Aug 2017 13:23:54 +0200 Subject: xargs: optional support for -P NUM. Closes 9511 Based on patch by Johannes Schindelin function old new delta xargs_exec - 294 +294 packed_usage 31757 31772 +15 xargs_main 787 719 -68 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 309/-68) Total: 241 bytes Signed-off-by: Denys Vlasenko --- findutils/xargs.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 117 insertions(+), 18 deletions(-) diff --git a/findutils/xargs.c b/findutils/xargs.c index b4e3db02c..77e01ef6c 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -59,6 +59,11 @@ //config: depends on XARGS //config: help //config: Support -I STR and -i[STR] options. +//config: +//config:config FEATURE_XARGS_SUPPORT_PARALLEL +//config: bool "Enable -P N: processes to run in parallel" +//config: default y +//config: depends on XARGS //applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, BB_DIR_USR_BIN, BB_SUID_DROP, xargs)) @@ -99,38 +104,121 @@ struct globals { #endif const char *eof_str; int idx; +#if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL + int running_procs; + int max_procs; +#endif + smalluint xargs_exitcode; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ setup_common_bufsiz(); \ G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \ G.idx = 0; \ + IF_FEATURE_XARGS_SUPPORT_PARALLEL(G.running_procs = 0;) \ + IF_FEATURE_XARGS_SUPPORT_PARALLEL(G.max_procs = 1;) \ + G.xargs_exitcode = 0; \ IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \ IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \ } while (0) +/* + * Returns 0 if xargs should continue (but may set G.xargs_exitcode to 123). + * Else sets G.xargs_exitcode to error code and returns nonzero. + * + * If G.max_procs == 0, performs final waitpid() loop for all children. + */ static int xargs_exec(void) { int status; +#if !ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL status = spawn_and_wait(G.args); +#else + if (G.max_procs == 1) { + status = spawn_and_wait(G.args); + } else { + pid_t pid; + int wstat; + again: + if (G.running_procs >= G.max_procs) + pid = safe_waitpid(-1, &wstat, 0); + else + pid = wait_any_nohang(&wstat); + if (pid > 0) { + /* We may have children we don't know about: + * sh -c 'sleep 1 & exec xargs ...' + * Do not make G.running_procs go negative. + */ + if (G.running_procs != 0) + G.running_procs--; + status = WIFSIGNALED(wstat) + ? 0x180 + WTERMSIG(wstat) + : WEXITSTATUS(wstat); + if (status > 0 && status < 255) { + /* See below why 123 does not abort */ + G.xargs_exitcode = 123; + status = 0; + } + if (status == 0) + goto again; /* maybe we have more children? */ + /* else: "bad" status, will bail out */ + } else if (G.max_procs != 0) { + /* Not in final waitpid() loop, + * and G.running_procs < G.max_procs: start more procs + */ + status = spawn(G.args); + /* here "status" actually holds pid, or -1 */ + if (status > 0) { + G.running_procs++; + status = 0; + } + /* else: status == -1 (failed to fork or exec) */ + } else { + /* final waitpid() loop: must be ECHILD "no more children" */ + status = 0; + } + } +#endif + /* Manpage: + * """xargs exits with the following status: + * 0 if it succeeds + * 123 if any invocation of the command exited with status 1-125 + * 124 if the command exited with status 255 + * ("""If any invocation of the command exits with a status of 255, + * xargs will stop immediately without reading any further input. + * An error message is issued on stderr when this happens.""") + * 125 if the command is killed by a signal + * 126 if the command cannot be run + * 127 if the command is not found + * 1 if some other error occurred.""" + */ if (status < 0) { bb_simple_perror_msg(G.args[0]); - return errno == ENOENT ? 127 : 126; - } - if (status == 255) { - bb_error_msg("%s: exited with status 255; aborting", G.args[0]); - return 124; + status = (errno == ENOENT) ? 127 : 126; } - if (status >= 0x180) { + else if (status >= 0x180) { bb_error_msg("'%s' terminated by signal %d", G.args[0], status - 0x180); - return 125; + status = 125; } - if (status) - return 123; - return 0; + else if (status != 0) { + if (status == 255) { + bb_error_msg("%s: exited with status 255; aborting", G.args[0]); + return 124; + } + /* "123 if any invocation of the command exited with status 1-125" + * This implies that nonzero exit code is remembered, + * but does not cause xargs to stop: we return 0. + */ + G.xargs_exitcode = 123; + status = 0; + } + + if (status != 0) + G.xargs_exitcode = status; + return status; } /* In POSIX/C locale isspace is only these chars: "\t\n\v\f\r" and space. @@ -436,6 +524,9 @@ static int xargs_ask_confirmation(void) //usage: IF_FEATURE_XARGS_SUPPORT_REPL_STR( //usage: "\n -I STR Replace STR within PROG ARGS with input line" //usage: ) +//usage: IF_FEATURE_XARGS_SUPPORT_PARALLEL( +//usage: "\n -P N Run up to N PROGs in parallel" +//usage: ) //usage: IF_FEATURE_XARGS_SUPPORT_TERMOPT( //usage: "\n -x Exit if size is exceeded" //usage: ) @@ -473,14 +564,14 @@ enum { IF_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \ IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \ IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") \ - IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::") + IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::") \ + IF_FEATURE_XARGS_SUPPORT_PARALLEL( "P:+") int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int xargs_main(int argc UNUSED_PARAM, char **argv) { int initial_idx; int i; - int child_error = 0; char *max_args; char *max_chars; char *buf; @@ -500,8 +591,14 @@ int xargs_main(int argc UNUSED_PARAM, char **argv) "no-run-if-empty\0" No_argument "r", &max_args, &max_chars, &G.eof_str, &G.eof_str IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str) + IF_FEATURE_XARGS_SUPPORT_PARALLEL(, &G.max_procs) ); +#if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL + if (G.max_procs <= 0) /* -P0 means "run lots of them" */ + G.max_procs = 100; /* let's not go crazy high */ +#endif + /* -E ""? You may wonder why not just omit -E? * This is used for portability: * old xargs was using "_" as default for -E / -e */ @@ -620,11 +717,8 @@ int xargs_main(int argc UNUSED_PARAM, char **argv) } if (!(opt & OPT_INTERACTIVE) || xargs_ask_confirmation()) { - child_error = xargs_exec(); - } - - if (child_error > 0 && child_error != 123) { - break; + if (xargs_exec() != 0) + break; /* G.xargs_exitcode is set by xargs_exec() */ } overlapping_strcpy(buf, rem); @@ -635,7 +729,12 @@ int xargs_main(int argc UNUSED_PARAM, char **argv) free(buf); } - return child_error; +#if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL + G.max_procs = 0; + xargs_exec(); /* final waitpid() loop */ +#endif + + return G.xargs_exitcode; } -- cgit v1.2.3-55-g6feb From 0b6ec06bebc8774ed3b70857ff81901aca4804f4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 27 Aug 2017 08:25:18 +0100 Subject: kill: add '--' option to separate options from arguments Using a negative pid to send TERM to a process group results in an obscure error: $ ./busybox kill -12345 kill: bad signal name '12345' This is intended. Manpage says: ARGUMENTS pid Each pid can be one of four things: ... -n where n is larger than 1. All processes in process group n are signaled. When an argument of the form '-n' is given, and it is meant to denote a process group, either a signal must be specified first, or the argument must be preceded by a '--' option, otherwise it will be taken as the signal to send. However, we did not support "--". Add this capability to BusyBox. function old new delta kill_main 993 999 +6 Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- procps/kill.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/procps/kill.c b/procps/kill.c index 0ddae2f70..24cc903fc 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -184,6 +184,10 @@ int kill_main(int argc UNUSED_PARAM, char **argv) if (is_killall5 && arg[0] == 'o') goto do_it_now; + /* "--" separates options from args. Testcase: "kill -- -123" */ + if (!is_killall5 && arg[0] == '-' && arg[1] == '\0') + goto do_it_sooner; + if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ arg = *++argv; } /* else it must be -SIG */ @@ -192,6 +196,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv) bb_error_msg("bad signal name '%s'", arg); return EXIT_FAILURE; } + do_it_sooner: arg = *++argv; do_it_now: -- cgit v1.2.3-55-g6feb From 3a7b0fb7b6c6a9b0563b862e5ecd3200876ab1e4 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 28 Aug 2017 11:49:24 +0200 Subject: i2c-tools: remove unneeded include We no longer use common_bufsiz1 in i2c-tools. Don't include common_bufsiz.h. Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- miscutils/i2c_tools.c | 1 - 1 file changed, 1 deletion(-) diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index 30f606e8e..03a09d519 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c @@ -61,7 +61,6 @@ */ #include "libbb.h" -#include "common_bufsiz.h" #include #include -- cgit v1.2.3-55-g6feb From 0d1eaf407c3d077f1d6ec97ceffbafbe7591ecbf Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 29 Aug 2017 12:31:22 +0200 Subject: i2c-tools: don't include linux/i2c-dev.h Installing headers from upstream i2c-tools makes it impossible to build the busybox version due to redefined symbols. This is caused by the fact that linux/i2c-dev.h from i2c-tools overwrites the one from linux uapi and defines symbols already defined by linux' linux/i2c.h. Drop this include and simply re-implement the relevant defines from linux/i2c-dev.h in miscutils/i2c-tools.c. Tested by building on systems with and without i2c-tools headers. Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- miscutils/i2c_tools.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index 03a09d519..52fc5ec6b 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config I2CGET //config: bool "i2cget (5.6 kb)" //config: default y @@ -63,7 +62,6 @@ #include "libbb.h" #include -#include #define I2CDUMP_NUM_REGS 256 @@ -71,6 +69,25 @@ #define I2CDETECT_MODE_QUICK 1 #define I2CDETECT_MODE_READ 2 +/* linux/i2c-dev.h from i2c-tools overwrites the one from linux uapi + * and defines symbols already defined by linux/i2c.h. + * Also, it defines a bunch of static inlines which we would rather NOT + * inline. What a mess. + * We need only these definitions from linux/i2c-dev.h: + */ +#define I2C_SLAVE 0x0703 +#define I2C_SLAVE_FORCE 0x0706 +#define I2C_FUNCS 0x0705 +#define I2C_PEC 0x0708 +#define I2C_SMBUS 0x0720 +struct i2c_smbus_ioctl_data { + __u8 read_write; + __u8 command; + __u32 size; + union i2c_smbus_data *data; +}; +/* end linux/i2c-dev.h */ + /* * This is needed for ioctl_or_perror_and_die() since it only accepts pointers. */ @@ -1187,18 +1204,17 @@ static void will_skip(const char *cmd) } //usage:#define i2cdetect_trivial_usage -//usage: "[-F I2CBUS] [-l] [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]" +//usage: "-l | -F I2CBUS | [-ya] [-q|-r] I2CBUS [FIRST LAST]" //usage:#define i2cdetect_full_usage "\n\n" -//usage: "Detect I2C chips.\n" -//usage: "\n I2CBUS i2c bus number" -//usage: "\n FIRST and LAST limit the probing range" +//usage: "Detect I2C chips" //usage: "\n" -//usage: "\n -l output list of installed busses" -//usage: "\n -y disable interactive mode" -//usage: "\n -a force scanning of non-regular addresses" -//usage: "\n -q use smbus quick write commands for probing (default)" -//usage: "\n -r use smbus read byte commands for probing" -//usage: "\n -F display list of functionalities" +//usage: "\n -l Print list of installed buses" +//usage: "\n -F BUS# Print list of functionalities on this bus" +//usage: "\n -y Disable interactive mode" +//usage: "\n -a Force scanning of non-regular addresses" +//usage: "\n -q Use smbus quick write commands for probing (default)" +//usage: "\n -r Use smbus read byte commands for probing" +//usage: "\n FIRST and LAST limit probing range" int i2cdetect_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int i2cdetect_main(int argc UNUSED_PARAM, char **argv) { @@ -1213,7 +1229,8 @@ int i2cdetect_main(int argc UNUSED_PARAM, char **argv) opts = getopt32(argv, "^" "yaqrFl" "\0" - "q--r:r--q:"/*mutually exclusive*/ "?3"/*up to 3 args*/ + "q--r:r--q:"/*mutually exclusive*/ + "?3"/*up to 3 args*/ ); argv += optind; -- cgit v1.2.3-55-g6feb From 238ff98bb85adfb5563d10b37ea4c33fef3af2f2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 13:38:30 +0200 Subject: hush: fix "getopts" builtin to not be upset by other builtins calling getopt() function old new delta builtin_getopts 363 403 +40 unset_local_var_len 185 215 +30 set_local_var 440 466 +26 reset_traps_to_defaults 151 157 +6 pseudo_exec_argv 320 326 +6 install_special_sighandlers 52 58 +6 pick_sighandler 62 65 +3 execvp_or_die 85 88 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/0 up/down: 120/0) Total: 120 bytes Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-getopts/getopt_nested.right | 14 +++++ shell/ash_test/ash-getopts/getopt_nested.tests | 21 +++++++ shell/hush.c | 78 +++++++++++++++++++----- shell/hush_test/hush-getopts/getopt_nested.right | 14 +++++ shell/hush_test/hush-getopts/getopt_nested.tests | 21 +++++++ 5 files changed, 133 insertions(+), 15 deletions(-) create mode 100644 shell/ash_test/ash-getopts/getopt_nested.right create mode 100755 shell/ash_test/ash-getopts/getopt_nested.tests create mode 100644 shell/hush_test/hush-getopts/getopt_nested.right create mode 100755 shell/hush_test/hush-getopts/getopt_nested.tests diff --git a/shell/ash_test/ash-getopts/getopt_nested.right b/shell/ash_test/ash-getopts/getopt_nested.right new file mode 100644 index 000000000..b0c339db1 --- /dev/null +++ b/shell/ash_test/ash-getopts/getopt_nested.right @@ -0,0 +1,14 @@ +var:a +var:b +var:c +var:a +var:b +var:c +Illegal option -d +var:? +Illegal option -e +var:? +Illegal option -f +var:? +var:a +End: var:? OPTIND:6 diff --git a/shell/ash_test/ash-getopts/getopt_nested.tests b/shell/ash_test/ash-getopts/getopt_nested.tests new file mode 100755 index 000000000..1b48b4075 --- /dev/null +++ b/shell/ash_test/ash-getopts/getopt_nested.tests @@ -0,0 +1,21 @@ +# Test that there is no interference of getopt() +# in getopts and unset. +# It's unclear what "correct" OPTIND values should be +# for "b" and "c" results from "-bc": 2? 3? +# What we focus on here is that all options are reported +# correct number of times and in correct sequence. + +( + +loop=99 +while getopts "abc" var -a -bc -abc -def -a; do + echo "var:$var" #OPTIND:$OPTIND + # this may use getopt(): + unset -ff func + test $((--loop)) = 0 && break # BUG if this triggers +done +echo "End: var:$var OPTIND:$OPTIND" + +) 2>&1 \ +| sed -e 's/ unrecognized option: / invalid option -- /' \ + -e 's/ illegal option -- / invalid option -- /' \ diff --git a/shell/hush.c b/shell/hush.c index cdc3a8618..ceb8cbb0a 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -906,6 +906,9 @@ struct globals { #if ENABLE_HUSH_LOOPS unsigned depth_break_continue; unsigned depth_of_loop; +#endif +#if ENABLE_HUSH_GETOPTS + unsigned getopt_count; #endif const char *ifs; const char *cwd; @@ -2214,6 +2217,10 @@ static int set_local_var(char *str, unsigned flags) cur->flg_export = 1; if (name_len == 4 && cur->varstr[0] == 'P' && cur->varstr[1] == 'S') cmdedit_update_prompt(); +#if ENABLE_HUSH_GETOPTS + if (strncmp(cur->varstr, "OPTIND=", 7) == 0) + G.getopt_count = 0; +#endif if (cur->flg_export) { if (flags & SETFLAG_UNEXPORT) { cur->flg_export = 0; @@ -2244,6 +2251,10 @@ static int unset_local_var_len(const char *name, int name_len) if (!name) return EXIT_SUCCESS; +#if ENABLE_HUSH_GETOPTS + if (name_len == 6 && strncmp(name, "OPTIND", 6) == 0) + G.getopt_count = 0; +#endif var_pp = &G.top_var; while ((cur = *var_pp) != NULL) { if (strncmp(cur->varstr, name, name_len) == 0 && cur->varstr[name_len] == '=') { @@ -9889,7 +9900,8 @@ Test that VAR is a valid variable name? */ char cbuf[2]; const char *cp, *optstring, *var; - int c, exitcode; + int c, n, exitcode, my_opterr; + unsigned count; optstring = *++argv; if (!optstring || !(var = *++argv)) { @@ -9897,17 +9909,18 @@ Test that VAR is a valid variable name? return EXIT_FAILURE; } - c = 0; + if (argv[1]) + argv[0] = G.global_argv[0]; /* for error messages in getopt() */ + else + argv = G.global_argv; + cbuf[1] = '\0'; + + my_opterr = 0; if (optstring[0] != ':') { cp = get_local_var_value("OPTERR"); /* 0 if "OPTERR=0", 1 otherwise */ - c = (!cp || NOT_LONE_CHAR(cp, '0')); + my_opterr = (!cp || NOT_LONE_CHAR(cp, '0')); } - opterr = c; - cp = get_local_var_value("OPTIND"); - optind = cp ? atoi(cp) : 0; - optarg = NULL; - cbuf[1] = '\0'; /* getopts stops on first non-option. Add "+" to force that */ /*if (optstring[0] != '+')*/ { @@ -9916,11 +9929,47 @@ Test that VAR is a valid variable name? optstring = s; } - if (argv[1]) - argv[0] = G.global_argv[0]; /* for error messages */ - else - argv = G.global_argv; - c = getopt(string_array_len(argv), argv, optstring); + /* Naively, now we should just + * cp = get_local_var_value("OPTIND"); + * optind = cp ? atoi(cp) : 0; + * optarg = NULL; + * opterr = my_opterr; + * c = getopt(string_array_len(argv), argv, optstring); + * and be done? Not so fast... + * Unlike normal getopt() usage in C programs, here + * each successive call will (usually) have the same argv[] CONTENTS, + * but not the ADDRESSES. Worse yet, it's possible that between + * invocations of "getopts", there will be calls to shell builtins + * which use getopt() internally. Example: + * while getopts "abc" RES -a -bc -abc de; do + * unset -ff func + * done + * This would not work correctly: getopt() call inside "unset" + * modifies internal libc state which is tracking position in + * multi-option strings ("-abc"). At best, it can skip options + * or return the same option infinitely. With glibc implementation + * of getopt(), it would use outright invalid pointers and return + * garbage even _without_ "unset" mangling internal state. + * + * We resort to resetting getopt() state and calling it N times, + * until we get Nth result (or failure). + * (N == G.getopt_count is reset to 0 whenever OPTIND is [un]set). + */ + optind = 0; /* reset getopt() state */ + count = 0; + n = string_array_len(argv); + do { + optarg = NULL; + opterr = (count < G.getopt_count) ? 0 : my_opterr; + c = getopt(n, argv, optstring); + if (c < 0) + break; + count++; + } while (count <= G.getopt_count); + + /* Set OPTIND. Prevent resetting of the magic counter! */ + set_local_var_from_halves("OPTIND", utoa(optind)); + G.getopt_count = count; /* "next time, give me N+1'th result" */ /* Set OPTARG */ /* Always set or unset, never left as-is, even on exit/error: @@ -9949,10 +9998,9 @@ Test that VAR is a valid variable name? c = '?'; } - /* Set VAR and OPTIND */ + /* Set VAR */ cbuf[0] = c; set_local_var_from_halves(var, cbuf); - set_local_var_from_halves("OPTIND", utoa(optind)); return exitcode; } diff --git a/shell/hush_test/hush-getopts/getopt_nested.right b/shell/hush_test/hush-getopts/getopt_nested.right new file mode 100644 index 000000000..0218dba56 --- /dev/null +++ b/shell/hush_test/hush-getopts/getopt_nested.right @@ -0,0 +1,14 @@ +var:a +var:b +var:c +var:a +var:b +var:c +./getopt_nested.tests: invalid option -- d +var:? +./getopt_nested.tests: invalid option -- e +var:? +./getopt_nested.tests: invalid option -- f +var:? +var:a +End: var:? OPTIND:6 diff --git a/shell/hush_test/hush-getopts/getopt_nested.tests b/shell/hush_test/hush-getopts/getopt_nested.tests new file mode 100755 index 000000000..1b48b4075 --- /dev/null +++ b/shell/hush_test/hush-getopts/getopt_nested.tests @@ -0,0 +1,21 @@ +# Test that there is no interference of getopt() +# in getopts and unset. +# It's unclear what "correct" OPTIND values should be +# for "b" and "c" results from "-bc": 2? 3? +# What we focus on here is that all options are reported +# correct number of times and in correct sequence. + +( + +loop=99 +while getopts "abc" var -a -bc -abc -def -a; do + echo "var:$var" #OPTIND:$OPTIND + # this may use getopt(): + unset -ff func + test $((--loop)) = 0 && break # BUG if this triggers +done +echo "End: var:$var OPTIND:$OPTIND" + +) 2>&1 \ +| sed -e 's/ unrecognized option: / invalid option -- /' \ + -e 's/ illegal option -- / invalid option -- /' \ -- cgit v1.2.3-55-g6feb From 55af51c66d0dae27d188974820c4a7d53dd0be55 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 13:48:49 +0200 Subject: hush: reuse "OPTIND=..." string Signed-off-by: Denys Vlasenko --- shell/hush.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/hush.c b/shell/hush.c index ceb8cbb0a..8e0022531 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -2218,7 +2218,8 @@ static int set_local_var(char *str, unsigned flags) if (name_len == 4 && cur->varstr[0] == 'P' && cur->varstr[1] == 'S') cmdedit_update_prompt(); #if ENABLE_HUSH_GETOPTS - if (strncmp(cur->varstr, "OPTIND=", 7) == 0) + /* defoptindvar is a "OPTIND=..." constant string */ + if (strncmp(cur->varstr, defoptindvar, 7) == 0) G.getopt_count = 0; #endif if (cur->flg_export) { -- cgit v1.2.3-55-g6feb From 6016181b68a9e8a9fb99893242851128b6bd5656 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 14:32:17 +0200 Subject: hush: GETOPT_RESET() _after_ getopts too. NOEXEC'ed applets which use getopt() need this. function old new delta builtin_getopts 403 413 +10 Signed-off-by: Denys Vlasenko --- include/libbb.h | 2 +- libbb/getopt32.c | 2 +- shell/hush.c | 3 ++- shell/shell_common.c | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 95a7470a8..06f887732 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1212,7 +1212,7 @@ uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, * By ~2008, OpenBSD 3.4 was changed to survive glibc-like optind = 0 * (to interpret it as if optreset was set). */ -#ifdef __GLIBC__ +#if 1 /*def __GLIBC__*/ #define GETOPT_RESET() (optind = 0) #else /* BSD style */ #define GETOPT_RESET() (optind = 1) diff --git a/libbb/getopt32.c b/libbb/getopt32.c index f778c6e89..378510063 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -517,7 +517,7 @@ vgetopt32(char **argv, const char *applet_opts, const char *applet_long_options, } /* In case getopt32 was already called: - * reset the libc getopt() function, which keeps internal state. + * reset libc getopt() internal state. * run_nofork_applet() does this, but we might end up here * also via gunzip_main() -> gzip_main(). Play safe. */ diff --git a/shell/hush.c b/shell/hush.c index 8e0022531..d27550ba0 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -9956,7 +9956,7 @@ Test that VAR is a valid variable name? * until we get Nth result (or failure). * (N == G.getopt_count is reset to 0 whenever OPTIND is [un]set). */ - optind = 0; /* reset getopt() state */ + GETOPT_RESET(); count = 0; n = string_array_len(argv); do { @@ -9971,6 +9971,7 @@ Test that VAR is a valid variable name? /* Set OPTIND. Prevent resetting of the magic counter! */ set_local_var_from_halves("OPTIND", utoa(optind)); G.getopt_count = count; /* "next time, give me N+1'th result" */ + GETOPT_RESET(); /* just in case */ /* Set OPTARG */ /* Always set or unset, never left as-is, even on exit/error: diff --git a/shell/shell_common.c b/shell/shell_common.c index 7a0799ed5..c978693f9 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -425,8 +425,8 @@ shell_builtin_ulimit(char **argv) * ulimit 123 -c2 -l 456 */ - /* In case getopt was already called: - * reset the libc getopt() function, which keeps internal state. + /* In case getopt() was already called: + * reset libc getopt() internal state. */ GETOPT_RESET(); -- cgit v1.2.3-55-g6feb From 9fed83a7ccd589889bc08852584d5b4663fef2e0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 14:35:58 +0200 Subject: hush: fix false positive in unset.tests Signed-off-by: Denys Vlasenko --- shell/hush_test/hush-vars/unset.tests | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shell/hush_test/hush-vars/unset.tests b/shell/hush_test/hush-vars/unset.tests index 81243fbf9..268323a6d 100755 --- a/shell/hush_test/hush-vars/unset.tests +++ b/shell/hush_test/hush-vars/unset.tests @@ -1,3 +1,5 @@ +( + # check invalid options are rejected # bash: in posix mode, aborts if non-interactive unset - @@ -37,3 +39,7 @@ unset VAR_RO echo $? $f $g unset f VAR_RO g echo $? $f $g + +) 2>&1 \ +| sed -e 's/ unrecognized option: / invalid option -- /' \ + -e 's/ illegal option -- / invalid option -- /' \ -- cgit v1.2.3-55-g6feb From 0180b57aaf9fd18c2f54be508a1dc2a64f848ed1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 15:34:38 +0200 Subject: setpriv: placete "declaration of 'index' shadows a global declaration" warning Signed-off-by: Denys Vlasenko --- util-linux/setpriv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c index 12ab1bd66..af079fae8 100644 --- a/util-linux/setpriv.c +++ b/util-linux/setpriv.c @@ -173,14 +173,14 @@ static void set_ambient_caps(char *string) cap = strtok(string, ","); while (cap) { - unsigned index; + unsigned idx; - index = parse_cap(cap); + idx = parse_cap(cap); if (cap[0] == '+') { - if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, index, 0, 0) < 0) + if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, idx, 0, 0) < 0) bb_perror_msg("cap_ambient_raise"); } else { - if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, index, 0, 0) < 0) + if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, idx, 0, 0) < 0) bb_perror_msg("cap_ambient_lower"); } cap = strtok(NULL, ","); -- cgit v1.2.3-55-g6feb From f27e150fa68c50bc39e229bd276d6ea2af109463 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 15:44:01 +0200 Subject: i2c_tools: tweak --help text function old new delta packed_usage 31624 31615 -9 Signed-off-by: Denys Vlasenko --- miscutils/i2c_tools.c | 69 +++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index 52fc5ec6b..fc392d9dc 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c @@ -454,19 +454,20 @@ static void confirm_action(int bus_addr, int mode, int data_addr, int pec) #if ENABLE_I2CGET //usage:#define i2cget_trivial_usage -//usage: "[-f] [-y] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]" +//usage: "[-fy] BUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]" //usage:#define i2cget_full_usage "\n\n" -//usage: "Read from I2C/SMBus chip registers\n" -//usage: "\n I2CBUS i2c bus number" -//usage: "\n ADDRESS 0x03 - 0x77" +//usage: "Read from I2C/SMBus chip registers" +//usage: "\n" +//usage: "\n I2CBUS I2C bus number" +//usage: "\n ADDRESS 0x03-0x77" //usage: "\nMODE is:" -//usage: "\n b read byte data (default)" -//usage: "\n w read word data" -//usage: "\n c write byte/read byte" +//usage: "\n b Read byte data (default)" +//usage: "\n w Read word data" +//usage: "\n c Write byte/read byte" //usage: "\n Append p for SMBus PEC" //usage: "\n" -//usage: "\n -f force access" -//usage: "\n -y disable interactive mode" +//usage: "\n -f Force access" +//usage: "\n -y Disable interactive mode" int i2cget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int i2cget_main(int argc UNUSED_PARAM, char **argv) { @@ -536,23 +537,24 @@ int i2cget_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_I2CSET //usage:#define i2cset_trivial_usage -//usage: "[-f] [-y] [-m MASK] BUS CHIP-ADDR DATA-ADDR [VALUE] ... [MODE]" +//usage: "[-fy] [-m MASK] BUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]" //usage:#define i2cset_full_usage "\n\n" -//usage: "Set I2C registers\n" -//usage: "\n I2CBUS i2c bus number" -//usage: "\n ADDRESS 0x03 - 0x77" +//usage: "Set I2C registers" +//usage: "\n" +//usage: "\n I2CBUS I2C bus number" +//usage: "\n ADDRESS 0x03-0x77" //usage: "\nMODE is:" -//usage: "\n c byte, no value" -//usage: "\n b byte data (default)" -//usage: "\n w word data" +//usage: "\n c Byte, no value" +//usage: "\n b Byte data (default)" +//usage: "\n w Word data" //usage: "\n i I2C block data" //usage: "\n s SMBus block data" //usage: "\n Append p for SMBus PEC" //usage: "\n" -//usage: "\n -f force access" -//usage: "\n -y disable interactive mode" -//usage: "\n -r read back and compare the result" -//usage: "\n -m MASK mask specifying which bits to write" +//usage: "\n -f Force access" +//usage: "\n -y Disable interactive mode" +//usage: "\n -r Read back and compare the result" +//usage: "\n -m MASK Mask specifying which bits to write" int i2cset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int i2cset_main(int argc, char **argv) { @@ -895,23 +897,24 @@ static void dump_word_data(int bus_fd, unsigned first, unsigned last) } //usage:#define i2cdump_trivial_usage -//usage: "[-f] [-r FIRST-LAST] [-y] BUS ADDR [MODE]" +//usage: "[-fy] [-r FIRST-LAST] BUS ADDR [MODE]" //usage:#define i2cdump_full_usage "\n\n" -//usage: "Examine I2C registers\n" -//usage: "\n I2CBUS i2c bus number" -//usage: "\n ADDRESS 0x03 - 0x77" +//usage: "Examine I2C registers" +//usage: "\n" +//usage: "\n I2CBUS I2C bus number" +//usage: "\n ADDRESS 0x03-0x77" //usage: "\nMODE is:" -//usage: "\n b byte (default)" -//usage: "\n w word" -//usage: "\n W word on even register addresses" +//usage: "\n b Byte (default)" +//usage: "\n w Word" +//usage: "\n W Word on even register addresses" //usage: "\n i I2C block" //usage: "\n s SMBus block" -//usage: "\n c consecutive byte" +//usage: "\n c Consecutive byte" //usage: "\n Append p for SMBus PEC" //usage: "\n" -//usage: "\n -f force access" -//usage: "\n -y disable interactive mode" -//usage: "\n -r limit the number of registers being accessed" +//usage: "\n -f Force access" +//usage: "\n -y Disable interactive mode" +//usage: "\n -r Limit the number of registers being accessed" int i2cdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int i2cdump_main(int argc UNUSED_PARAM, char **argv) { @@ -1208,8 +1211,8 @@ static void will_skip(const char *cmd) //usage:#define i2cdetect_full_usage "\n\n" //usage: "Detect I2C chips" //usage: "\n" -//usage: "\n -l Print list of installed buses" -//usage: "\n -F BUS# Print list of functionalities on this bus" +//usage: "\n -l List installed buses" +//usage: "\n -F BUS# List functionalities on this bus" //usage: "\n -y Disable interactive mode" //usage: "\n -a Force scanning of non-regular addresses" //usage: "\n -q Use smbus quick write commands for probing (default)" -- cgit v1.2.3-55-g6feb From 3256111efb6c059400218676cbf78d226d904917 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 16:51:17 +0200 Subject: udhcpc: show only short opts in --help text function old new delta packed_usage 31615 31501 -114 Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 55e0400b9..99d91bf70 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1183,44 +1183,6 @@ static void client_background(void) //usage: " [-i IFACE]"IF_FEATURE_UDHCP_PORT(" [-P PORT]")" [-s PROG] [-p PIDFILE]\n" //usage: " [-oC] [-r IP] [-V VENDOR] [-F NAME] [-x OPT:VAL]... [-O OPT]..." //usage:#define udhcpc_full_usage "\n" -//usage: IF_LONG_OPTS( -//usage: "\n -i,--interface IFACE Interface to use (default eth0)" -//usage: IF_FEATURE_UDHCP_PORT( -//usage: "\n -P,--client-port PORT Use PORT (default 68)" -//usage: ) -//usage: "\n -s,--script PROG Run PROG at DHCP events (default "CONFIG_UDHCPC_DEFAULT_SCRIPT")" -//usage: "\n -p,--pidfile FILE Create pidfile" -//usage: "\n -B,--broadcast Request broadcast replies" -//usage: "\n -t,--retries N Send up to N discover packets (default 3)" -//usage: "\n -T,--timeout SEC Pause between packets (default 3)" -//usage: "\n -A,--tryagain SEC Wait if lease is not obtained (default 20)" -//usage: "\n -n,--now Exit if lease is not obtained" -//usage: "\n -q,--quit Exit after obtaining lease" -//usage: "\n -R,--release Release IP on exit" -//usage: "\n -f,--foreground Run in foreground" -//usage: USE_FOR_MMU( -//usage: "\n -b,--background Background if lease is not obtained" -//usage: ) -//usage: "\n -S,--syslog Log to syslog too" -//usage: IF_FEATURE_UDHCPC_ARPING( -//usage: "\n -a[MSEC],--arping[=MSEC] Validate offered address with ARP ping" -//usage: ) -//usage: "\n -r,--request IP Request this IP address" -//usage: "\n -o,--no-default-options Don't request any options (unless -O is given)" -//usage: "\n -O,--request-option OPT Request option OPT from server (cumulative)" -//usage: "\n -x OPT:VAL Include option OPT in sent packets (cumulative)" -//usage: "\n Examples of string, numeric, and hex byte opts:" -//usage: "\n -x hostname:bbox - option 12" -//usage: "\n -x lease:3600 - option 51 (lease time)" -//usage: "\n -x 0x3d:0100BEEFC0FFEE - option 61 (client id)" -//usage: "\n -F,--fqdn NAME Ask server to update DNS mapping for NAME" -//usage: "\n -V,--vendorclass VENDOR Vendor identifier (default 'udhcp VERSION')" -//usage: "\n -C,--clientid-none Don't send MAC as client identifier" -//usage: IF_UDHCP_VERBOSE( -//usage: "\n -v Verbose" -//usage: ) -//usage: ) -//usage: IF_NOT_LONG_OPTS( //usage: "\n -i IFACE Interface to use (default eth0)" //usage: IF_FEATURE_UDHCP_PORT( //usage: "\n -P PORT Use PORT (default 68)" @@ -1256,7 +1218,6 @@ static void client_background(void) //usage: IF_UDHCP_VERBOSE( //usage: "\n -v Verbose" //usage: ) -//usage: ) //usage: "\nSignals:" //usage: "\n USR1 Renew lease" //usage: "\n USR2 Release lease" -- cgit v1.2.3-55-g6feb From f41ffff2dce2c08d96a11a21a01437e6354e659e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 19:44:45 +0200 Subject: klibc-utils: remove accidental "or later" licensing wording. I (slightly) prefer my code to be under "GPLv2 only" license. Signed-off-by: Denys Vlasenko --- klibc-utils/nuke.c | 2 +- klibc-utils/resume.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/klibc-utils/nuke.c b/klibc-utils/nuke.c index a5d2f8d70..6b65f705f 100644 --- a/klibc-utils/nuke.c +++ b/klibc-utils/nuke.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2017 Denys Vlasenko * - * Licensed under GPLv2 or later, see file LICENSE in this source tree. + * Licensed under GPLv2, see file LICENSE in this source tree. */ //config:config NUKE //config: bool "nuke" diff --git a/klibc-utils/resume.c b/klibc-utils/resume.c index de142f350..f85384853 100644 --- a/klibc-utils/resume.c +++ b/klibc-utils/resume.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2017 Denys Vlasenko * - * Licensed under GPLv2 or later, see file LICENSE in this source tree. + * Licensed under GPLv2, see file LICENSE in this source tree. */ //config:config RESUME //config: bool "resume" -- cgit v1.2.3-55-g6feb From f8ee849ecd42fa11da6c5f381ad83594840b3cca Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 25 Aug 2017 22:42:05 +0200 Subject: xargs: support -a FILE The GNU-specific option -a lets xargs read the arguments from a file rather than from stdin. This is particularly convenient when debugging in gdb interactively, and it might be of more general use. function old new delta xargs_main 788 823 +35 packed_usage 31683 31671 -12 Signed-off-by: Johannes Schindelin Signed-off-by: Denys Vlasenko --- findutils/xargs.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/findutils/xargs.c b/findutils/xargs.c index 77e01ef6c..acee0319a 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -64,6 +64,11 @@ //config: bool "Enable -P N: processes to run in parallel" //config: default y //config: depends on XARGS +//config: +//config:config FEATURE_XARGS_SUPPORT_ARGS_FILE +//config: bool "Enable -a FILE: use FILE instead of stdin" +//config: default y +//config: depends on XARGS //applet:IF_XARGS(APPLET_NOEXEC(xargs, xargs, BB_DIR_USR_BIN, BB_SUID_DROP, xargs)) @@ -517,6 +522,9 @@ static int xargs_ask_confirmation(void) //usage: IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( //usage: "\n -0 Input is separated by NUL characters" //usage: ) +//usage: IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( +//usage: "\n -a FILE Read from FILE instead of stdin" +//usage: ) //usage: "\n -t Print the command on stderr before execution" //usage: "\n -e[STR] STR stops input processing" //usage: "\n -n N Pass no more than N args to PROG" @@ -565,7 +573,8 @@ enum { IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \ IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") \ IF_FEATURE_XARGS_SUPPORT_REPL_STR( "I:i::") \ - IF_FEATURE_XARGS_SUPPORT_PARALLEL( "P:+") + IF_FEATURE_XARGS_SUPPORT_PARALLEL( "P:+") \ + IF_FEATURE_XARGS_SUPPORT_ARGS_FILE( "a:") int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int xargs_main(int argc UNUSED_PARAM, char **argv) @@ -584,6 +593,7 @@ int xargs_main(int argc UNUSED_PARAM, char **argv) #else #define read_args process_stdin #endif + IF_FEATURE_XARGS_SUPPORT_PARALLEL(char *opt_a = NULL;) INIT_G(); @@ -592,6 +602,7 @@ int xargs_main(int argc UNUSED_PARAM, char **argv) &max_args, &max_chars, &G.eof_str, &G.eof_str IF_FEATURE_XARGS_SUPPORT_REPL_STR(, &G.repl_str, &G.repl_str) IF_FEATURE_XARGS_SUPPORT_PARALLEL(, &G.max_procs) + IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(, &opt_a) ); #if ENABLE_FEATURE_XARGS_SUPPORT_PARALLEL @@ -599,6 +610,11 @@ int xargs_main(int argc UNUSED_PARAM, char **argv) G.max_procs = 100; /* let's not go crazy high */ #endif +#if ENABLE_FEATURE_XARGS_SUPPORT_ARGS_FILE + if (opt_a) + xmove_fd(xopen(opt_a, O_RDONLY), 0); +#endif + /* -E ""? You may wonder why not just omit -E? * This is used for portability: * old xargs was using "_" as default for -E / -e */ -- cgit v1.2.3-55-g6feb From 58bf902a94b5d26f546e3d4186d6f51e050be427 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Aug 2017 13:44:27 +0200 Subject: xargs: fix a thinko in last commit IF_FEATURE_XARGS_SUPPORT_PARALLEL(char *opt_a = NULL;) is replaced with IF_FEATURE_XARGS_SUPPORT_ARGS_FILE Signed-off-by: Denys Vlasenko --- findutils/xargs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/findutils/xargs.c b/findutils/xargs.c index acee0319a..117a39b62 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -593,7 +593,7 @@ int xargs_main(int argc UNUSED_PARAM, char **argv) #else #define read_args process_stdin #endif - IF_FEATURE_XARGS_SUPPORT_PARALLEL(char *opt_a = NULL;) + IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(char *opt_a = NULL;) INIT_G(); -- cgit v1.2.3-55-g6feb From e39da802dd6d3ccfb95865139f98b184db0e175b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 1 Sep 2017 12:48:15 +0200 Subject: klibc-utils: add ipconfig.c work-in-progress Signed-off-by: Denys Vlasenko --- klibc-utils/ipconfig.c.txt | 316 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 klibc-utils/ipconfig.c.txt diff --git a/klibc-utils/ipconfig.c.txt b/klibc-utils/ipconfig.c.txt new file mode 100644 index 000000000..5dd95c16b --- /dev/null +++ b/klibc-utils/ipconfig.c.txt @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2017 Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ +//config:config IPCONFIG +//config: bool "ipconfig" +//config: default y +//config: help +//config: (Auto)configure network. + +//applet:IF_IPCONFIG(APPLET(ipconfig, BB_DIR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_IPCONFIG) += ipconfig.o + +#include +#include "libbb.h" + +struct globals { + int fixed; + const char *hostname; +}; +#define G (*ptr_to_globals) +#define INIT_G() do { \ + SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ +} while (0) + +struct dev { + const char *name; + uint8_t fixed; + uint32_t ip_addr; + uint32_t ip_netmask; + uint32_t ip_server; + uint32_t ip_router; +}; + +static int +parse_method(const char *method) +{ + int fixed; + + fixed = (method[0] != '\0'); + if (fixed) { + /* if it's not "" */ + fixed = index_in_strings( + /* 0 */ "on""\0" + /* 1 */ "any""\0" + /* 2 */ "both""\0" + /* 3 */ "dhcp""\0" + /* 4 */ "bootp""\0" + /* 5 */ "rarp""\0" + /* 6 */ "none""\0" + /* 7 */ "static""\0" + /* 8 */ "off""\0" + , method + ); + if (fixed > 0) + fixed /= 6; + } + return fixed; +} + +static uint32_t +parse_addr(const char *ip) +{ + struct in_addr in; + if (inet_aton(ip, &in) == 0) + bb_error_msg_and_die("bad IP address '%s'", ip); + return in.s_addr; +} + +static struct dev* +find_device(llist_t *iface_list, const char *name) +{ + while (iface_list) { + struct dev *dev = (void*) iface_list->data; + if (strcmp(dev->name, name) == 0) + return dev; + iface_list = iface_list->link; + } + return NULL; +} + +static void +set_from_template(struct dev *dev, struct dev *template) +{ + if (template->ip_addr != 0) + dev->ip_addr = template->ip_addr; + if (template->ip_netmask != 0) + dev->ip_netmask = template->ip_netmask; + if (template->ip_server != 0) + dev->ip_server = template->ip_server; + if (template->ip_router != 0) + dev->ip_router = template->ip_router; + dev->fixed = template->fixed; +} + +// "ip=PROTO" - also implies -o +// "nfsaddrs=PROTO" - also implies -o +// "" +// "[ip=/nfsaddrs=]IP:SERVER_IP:ROUTER:NETMASK:HOSTNAME:IFACE:METHOD" +// all optional. trailing empty :: can be skipped, only one : needs to be there +// (to distinguish from other formats). +// ":::::eth0" - dhcp on eth0 +// ":" - dhcp on all ifaces +// "::1.2.3.4" - dhcp on all ifaces, gateway is 1.2.3.4 (fairly nonsensical) +static void +add_all_devices(llist_t **iface_list, struct dev *template); +static struct dev* +add_device(llist_t **iface_list, char *ip) +{ + struct dev *dev; + + dev = xzalloc(sizeof(*dev)); + dev->fixed = G.fixed; + + if (strncmp("ip=", ip, 3) == 0 + || strncmp("nfsaddrs=", ip, 9) == 0 + ) { + int fixed; + + ip = strchr(ip, '=') + 1; + fixed = parse_method(ip); + if (fixed >= 0) { + add_all_devices(iface_list, dev); + free(dev); + return NULL; + } + } + + if (!strchr(ip, ':')) { + dev->name = ip; + } else { + unsigned opt = 0; + while (ip && *ip) { + char *next = strchr(ip, ':'); + if (next) + *next++ = '\0'; + if (opt > 6) + bb_error_msg_and_die("too many options for %s", dev->name); + if (ip[0]) switch (opt) { + case 0: + dev->ip_addr = parse_addr(ip); + break; + case 1: + dev->ip_server = parse_addr(ip); + break; + case 2: + dev->ip_router = parse_addr(ip); + break; + case 3: + dev->ip_netmask = parse_addr(ip); + break; + case 4: + if (G.hostname && strcmp(G.hostname, ip) != 0) + bb_error_msg_and_die("hostname must be the same"); + G.hostname = ip; + break; + case 5: + dev->name = ip; + break; + case 6: + dev->fixed = parse_method(ip); + break; + } + ip = next; + opt++; + } + } + + if (dev->name == NULL + || strcmp(dev->name, "all") == 0 + ) { + add_all_devices(iface_list, dev); + free(dev); + return NULL; + } + llist_add_to_end(iface_list, dev); + return dev; +} + +static void +add_all_devices(llist_t **iface_list, struct dev *template) +{ + DIR *d; + struct dirent *de; +#define sys_class_net "/sys/class/net" + + /* All forms of "config all ifaces" imply -o */ + option_mask32 |= 1; + + d = opendir(sys_class_net); + if (!d) + return; + + while ((de = readdir(d)) != NULL) { + struct dev *dev; + char *filename; + char p[sizeof(long)*3]; + unsigned long flags; + int r; + + /* Exclude devices beginning with dots as well as . and .. */ + if (de->d_name[0] == '.') + continue; + filename = xasprintf("%s/%s/flags", sys_class_net, de->d_name); + r = open_read_close(filename, p, sizeof(p) - 1); + free(filename); + if (r < 0) + continue; + p[r] = '\0'; + /* file's format is "0xNNNN\n" */ + flags = bb_strtoul(p, NULL, 0); + /* + * Heuristic for if this is a reasonable boot interface. + * This is the same logic the in-kernel ipconfig uses. + */ + if (flags & IFF_LOOPBACK) + continue; + if (!(flags & (IFF_BROADCAST | IFF_POINTOPOINT))) + continue; + if (find_device(*iface_list, de->d_name)) + continue; + dev = add_device(iface_list, xstrdup(de->d_name)); + if (dev) + set_from_template(dev, template); + } + closedir(d); +#undef sys_class_net +} + +//usage:#define ipconfig_trivial_usage +//usage: "[-c METHOD] [-t TIMEOUT] [-on] [-i VENDOR_ID] [-p PORT] [-d] IFACE..." +//usage:#define ipconfig_full_usage "\n\n" +//usage: "(Auto)configure network" +//usage: "\n" +//usage: "\n"" -c METHOD off/none/static or on/dhcp (default)" +//usage: "\n"" -t SECONDS Give up after SECONDS" +//usage: "\n"" -o Stop after one interface is configured" +//usage: "\n"" -n Dry run" +//usage: "\n"" -i VENDOR_ID DHCP vendor id (default '')" +//usage: "\n"" -p PORT DHCP port to use" +//usage: "\n"" [-d] IFACE... Interface(s)" +//usage: "\n" +//usage: "\n"" IFACE can be:" +//usage: "\n"" all - configure all interfaces" +//usage: "\n"" IFACE - configure this interface" +//usage: "\n"" IP:SERVER_IP:ROUTER:NETMASK:HOSTNAME:IFACE:METHOD (all optional)" +// TIMEOUT defaults to infinite +// -d actually is an option with an argument +// (not a clue why klibc-utils has two ways to specify interfaces) +int ipconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int ipconfig_main(int argc UNUSED_PARAM, char **argv) +{ + const char *method = ""; + const char *vendor_id = ""; + llist_t *devname_list = NULL; + llist_t *iface_list; + int timeout = -1; + unsigned port; + unsigned opt; + + INIT_G(); + + opt = getopt32(argv, + "onc:t:i:p:+d:*", + &method, &timeout, &vendor_id, &port, &devname_list + ); + argv += optind; + + G.fixed = parse_method(method); + if (G.fixed < 0) + bb_show_usage(); + + iface_list = NULL; + while (devname_list) + add_device(&iface_list, (char*) llist_pop(&devname_list)); + while (*argv) + add_device(&iface_list, *argv++); + + while (iface_list) { + struct dev *dev = (void*) iface_list->data; + printf("name:'%s'\n", dev->name); + printf("fixed:%u\n" , dev->fixed); + printf("ip:%s/" , inet_ntoa(*(struct in_addr*)&dev->ip_addr)); + printf("%s\n" , inet_ntoa(*(struct in_addr*)&dev->ip_netmask)); + printf("server:%s\n", inet_ntoa(*(struct in_addr*)&dev->ip_server)); + printf("router:%s\n", inet_ntoa(*(struct in_addr*)&dev->ip_router)); + iface_list = iface_list->link; + } + bb_error_msg("hostname:'%s'", G.hostname); + bb_error_msg("fixed:%u", G.fixed); + + return EXIT_SUCCESS; +} +//After device is configured, write out a "/run/net-IFACE.conf" file: +// // udchcp env values: +//write_option("DEVICE", dev->name); interface=eth0 +//write_option("PROTO", method); +//write_option("IPV4ADDR", dev->ip_addr); ip=10.43.17.38 +//write_option("IPV4BROADCAST", dev->ip_broadcast); subnet=255.255.255.0 mask=24 +//write_option("IPV4NETMASK", dev->ip_netmask); subnet=255.255.255.0 mask=24 +//write_option("IPV4GATEWAY", dev->ip_gateway); router=10.43.17.254 +//write_option("IPV4DNS0", dev->ip_nameserver[0]); dns=10.38.5.26 10.11.5.19 +//write_option("IPV4DNS1", dev->ip_nameserver[1]); dns=10.38.5.26 10.11.5.19 +//write_option("HOSTNAME", dev->hostname); hostname="STR" +//write_option("DNSDOMAIN", dev->dnsdomainname); domain=domain.com +//write_option("NISDOMAIN", dev->nisdomainname); nisdomain="STR" +//write_option("ROOTSERVER", my_inet_ntoa(dev->ip_server)); serverid=10.44.6.2 +//write_option("ROOTPATH", dev->bootpath); rootpath="STR" +//write_option("filename", dev->filename); boot_file=/pxelinux.0 +//write_option("UPTIME", dev->uptime); sysinfo()->uptime +//write_option("DHCPLEASETIME", dev->dhcpleasetime); lease=44148 +//write_option("DOMAINSEARCH", dev->domainsearch); search="ABC DEF" +// +//(write_option writes out single-quote escaped string, VAR='VAL') -- cgit v1.2.3-55-g6feb From 94aaf4b5d3c649a281299aedba08ce1939780fb4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 1 Sep 2017 17:06:12 +0200 Subject: httpd: skip "Status: " from CGI, including space. Closes 10291 Signed-off-by: Denys Vlasenko --- networking/httpd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index 9369de824..c82383507 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1371,12 +1371,13 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post out_cnt += count; count = 0; /* "Status" header format is: "Status: 302 Redirected\r\n" */ - if (out_cnt >= 7 && memcmp(rbuf, "Status:", 7) == 0) { + if (out_cnt >= 8 && memcmp(rbuf, "Status: ", 8) == 0) { /* send "HTTP/1.0 " */ if (full_write(STDOUT_FILENO, HTTP_200, 9) != 9) break; - rbuf += 7; /* skip "Status:" */ - count = out_cnt - 7; + /* skip "Status: " (including space, sending "HTTP/1.0 NNN" is wrong) */ + rbuf += 8; + count = out_cnt - 8; out_cnt = -1; /* buffering off */ } else if (out_cnt >= 4) { /* Did CGI add "HTTP"? */ -- cgit v1.2.3-55-g6feb From 9d858f5717cfc261d2ee80efff954acd7b1e5c00 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 5 Sep 2017 19:16:40 +0200 Subject: chat: do not die when HANGUP param is missing. Closes 10016 function old new delta chat_main 1356 1379 +23 Signed-off-by: Denys Vlasenko --- miscutils/chat.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/miscutils/chat.c b/miscutils/chat.c index 1446a040c..2dfe52c4f 100644 --- a/miscutils/chat.c +++ b/miscutils/chat.c @@ -238,10 +238,18 @@ int chat_main(int argc UNUSED_PARAM, char **argv) , *argv ); if (key >= 0) { + bool onoff; // cache directive value char *arg = *++argv; + + if (!arg) { +#if ENABLE_FEATURE_CHAT_TTY_HIFI + tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio0); +#endif + bb_show_usage(); + } // OFF -> 0, anything else -> 1 - bool onoff = (0 != strcmp("OFF", arg)); + onoff = (0 != strcmp("OFF", arg)); // process directive if (DIR_HANGUP == key) { // turn SIGHUP on/off -- cgit v1.2.3-55-g6feb From 0b1c62934215a08351a80977c7cf8e9346683a1e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 7 Sep 2017 14:40:28 +0200 Subject: build system: fix "allnoconfig" to clear all options. Closes 10296 Signed-off-by: Denys Vlasenko --- scripts/kconfig/conf.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index ea2446a89..e89637e7c 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -76,14 +76,51 @@ static void conf_askvalue(struct symbol *sym, const char *def) line[0] = '\n'; line[1] = 0; + line[2] = 0; if (!sym_is_changable(sym)) { printf("%s\n", def); - line[0] = '\n'; - line[1] = 0; return; } + // If autoconf run (allnoconfig and such), reset bool and tristates: + // "select ITEM" sets ITEM=y and then parent item might have been + // reset to "n" later. Try to set ITEM to "n" on the second run. + if (type == S_BOOLEAN || type == S_TRISTATE) { + switch (input_mode) { + case set_yes: + if (sym_tristate_within_range(sym, yes)) { + line[0] = 'y'; + line[1] = '\n'; + printf("%s", line); + return; + } + case set_mod: + if (type == S_TRISTATE) { + if (sym_tristate_within_range(sym, mod)) { + line[0] = 'm'; + line[1] = '\n'; + printf("%s", line); + return; + } + } else { + if (sym_tristate_within_range(sym, yes)) { + line[0] = 'y'; + line[1] = '\n'; + printf("%s", line); + return; + } + } + case set_no: + if (sym_tristate_within_range(sym, no)) { + line[0] = 'n'; + line[1] = '\n'; + printf("%s", line); + return; + } + } + } + switch (input_mode) { case set_no: case set_mod: @@ -590,6 +627,19 @@ int main(int ac, char **av) if (input_mode != ask_silent) { rootEntry = &rootmenu; conf(&rootmenu); + // If autoconf run (allnoconfig and such), run it twice: + // "select ITEM" sets ITEM=y and then parent item + // is reset to "n" later. Second run sets ITEM to "n". + // Example: ADDUSER selects LONG_OPTS. + // allnoconfig must set _both_ to "n". + // Before, LONG_OPTS remained "y". + if (input_mode == set_no + || input_mode == set_mod + || input_mode == set_yes + ) { + rootEntry = &rootmenu; + conf(&rootmenu); + } if (input_mode == ask_all) { input_mode = ask_silent; valid_stdin = 1; -- cgit v1.2.3-55-g6feb From d134aa93414c7d07a938b8076021c62d9987f683 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 7 Sep 2017 14:50:00 +0200 Subject: build system: fix a compiler warning Signed-off-by: Denys Vlasenko --- scripts/kconfig/conf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index e89637e7c..57734b590 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -118,6 +118,8 @@ static void conf_askvalue(struct symbol *sym, const char *def) printf("%s", line); return; } + default: // placate compiler + break; } } -- cgit v1.2.3-55-g6feb From b278ac0e607aa971c46706be63c580a2fd88dd56 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 8 Sep 2017 20:55:59 +0200 Subject: setfattr: new applet function old new delta setfattr_main - 189 +189 packed_usage 31516 31588 +72 setxattr - 53 +53 lsetxattr - 53 +53 removexattr - 37 +37 lremovexattr - 37 +37 applet_names 2649 2658 +9 find_applet_by_name 124 128 +4 applet_main 1532 1536 +4 ------------------------------------------------------------------------------ (add/remove: 7/0 grow/shrink: 4/0 up/down: 458/0) Total: 458 bytes Signed-off-by: Denys Vlasenko --- miscutils/setfattr.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 miscutils/setfattr.c diff --git a/miscutils/setfattr.c b/miscutils/setfattr.c new file mode 100644 index 000000000..f0ef227cb --- /dev/null +++ b/miscutils/setfattr.c @@ -0,0 +1,68 @@ +/* + * setfattr - set extended attributes of filesystem objects. + * + * Copyright (C) 2017 by Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ +//config:config SETFATTR +//config: bool "setfattr" +//config: default y +//config: help +//config: Set/delete extended attributes on files + +//applet:IF_SETFATTR(APPLET_NOEXEC(setfattr, setfattr, BB_DIR_USR_BIN, BB_SUID_DROP, setfattr)) + +//kbuild:lib-$(CONFIG_SETFATTR) += setfattr.o + +#include +#include "libbb.h" + +//usage:#define setfattr_trivial_usage +//usage: "[-h] -n|-x ATTR [-v VALUE] FILE..." +//usage:#define setfattr_full_usage "\n\n" +//usage: "Set extended attributes" +//usage: "\n" +//usage: "\n -h Do not follow symlinks" +//usage: "\n -x ATTR Remove attribute ATTR" +//usage: "\n -n ATTR Set attribute ATTR to VALUE" +//usage: "\n -v VALUE (default: empty)" +int setfattr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int setfattr_main(int argc UNUSED_PARAM, char **argv) +{ + const char *name; + const char *value = ""; + int status; + int opt; + enum { + OPT_h = (1 << 0), + OPT_x = (1 << 1), + }; + + opt = getopt32(argv, "^" + "hx:n:v:" + /* Min one arg, either -x or -n is a must, -x does not allow -v */ + "\0" "-1:x:n:n--x:x--nv:v--x" + , &name, &name, &value + ); + argv += optind; + + status = EXIT_SUCCESS; + do { + int r; + if (opt & OPT_x) + r = ((opt & OPT_h) ? lremovexattr : removexattr)(*argv, name); + else { + r = ((opt & OPT_h) ? lsetxattr : setxattr)( + *argv, name, + value, strlen(value), /*flags:*/ 0 + ); + } + if (r) { + bb_simple_perror_msg(*argv); + status = EXIT_FAILURE; + } + } while (*++argv); + + return status; +} -- cgit v1.2.3-55-g6feb From b5a0396716e6ef2882ae40b2b62b4ef6e8e21da0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 12 Sep 2017 17:54:28 +0200 Subject: networking/interface.c: remove superfluous "& 0377" Signed-off-by: Denys Vlasenko --- networking/interface.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/networking/interface.c b/networking/interface.c index c5c8f2cdd..119185881 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -223,7 +223,7 @@ static char* FAST_FUNC UNSPEC_print(unsigned char *ptr) pos = buff; for (i = 0; i < sizeof(struct sockaddr); i++) { /* careful -- not every libc's sprintf returns # bytes written */ - sprintf(pos, "%02X-", (*ptr++ & 0377)); + sprintf(pos, "%02X-", *ptr++); pos += 3; } /* Erase trailing "-". Works as long as sizeof(struct sockaddr) != 0 */ @@ -704,9 +704,8 @@ static char* FAST_FUNC ether_print(unsigned char *ptr) { char *buff; buff = xasprintf("%02X:%02X:%02X:%02X:%02X:%02X", - (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), - (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) - ); + ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5] + ); return auto_string(buff); } -- cgit v1.2.3-55-g6feb From 73af705628ddaedc4c6f7f78b9658d6c01310309 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 13 Sep 2017 19:20:27 +0200 Subject: hexedit: new applet function old new delta hexedit_main - 930 +930 format_line - 197 +197 remap - 168 +168 move_mapping_further - 141 +141 move_mapping_lower - 107 +107 redraw_cur_line - 104 +104 packed_usage 31802 31812 +10 applet_names 2688 2696 +8 applet_main 1552 1556 +4 applet_suid 97 98 +1 applet_install_loc 194 195 +1 ------------------------------------------------------------------------------ (add/remove: 7/0 grow/shrink: 5/0 up/down: 1671/0) Total: 1671 bytes Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 357 ++++++++++++++++++++++++++++++++++++++++++++++++++++ miscutils/less.c | 2 +- 2 files changed, 358 insertions(+), 1 deletion(-) create mode 100644 miscutils/hexedit.c diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c new file mode 100644 index 000000000..cd4b3b1ad --- /dev/null +++ b/miscutils/hexedit.c @@ -0,0 +1,357 @@ +/* + * Copyright (C) 2017 Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ +//config:config HEXEDIT +//config: bool "hexedit" +//config: default y +//config: help +//config: Edit file in hexadecimal. + +//applet:IF_HEXEDIT(APPLET(hexedit, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_HEXEDIT) += hexedit.o + +#include "libbb.h" + +#define ESC "\033" +#define HOME ESC"[H" +#define CLEAR ESC"[H"ESC"[J" + +struct globals { + smallint half; + int fd; + unsigned height; + uint8_t *addr; + uint8_t *current_byte; + uint8_t *eof_byte; + off_t size; + off_t offset; + struct termios orig_termios; +}; +#define G (*ptr_to_globals) +#define INIT_G() do { \ + SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ +} while (0) + +/* Hopefully there aren't arches with PAGE_SIZE > 64k */ +#define G_mapsize (64*1024) + +static void format_line(char *hex, uint8_t *data, off_t offset) +{ + char *text = hex + 16*3; + uint8_t *end, *end1; + + end1 = data + 15; + if ((G.size - offset) > 0) { + end = end1; + if ((G.size - offset) <= 15) + end = data + (G.size - offset) - 1; + while (data <= end) { + uint8_t c = *data++; + *hex++ = bb_hexdigits_upcase[c >> 4]; + *hex++ = bb_hexdigits_upcase[c & 0xf]; + *hex++ = ' '; + if (c < ' ' || c > 0x7e) + c = '.'; + *text++ = c; + } + } + while (data <= end1) { + *hex++ = ' '; + *hex++ = ' '; + *hex++ = ' '; + *text++ = ' '; + data++; + } + *text = '\0'; +} + +static void redraw(void) +{ + uint8_t *data; + off_t offset; + unsigned i; + + data = G.addr; + offset = 0; + i = 0; + while (i < G.height) { + char buf[16*4 + 8]; + format_line(buf, data, offset); + printf( + "\r\n%08"OFF_FMT"x %s" + (!i)*2, /* print \r\n only on 2nd line and later */ + offset, buf + ); + data += 16; + offset += 16; + i++; + } +} + +static void redraw_cur_line(void) +{ + off_t offset; + int len; + char buf[16*4 + 8]; + uint8_t *data; + + len = (0xf & (uintptr_t)G.current_byte); + data = G.current_byte - len; + offset = G.offset + (data - G.addr); + format_line(buf, data, offset); + printf( + "\r%08"OFF_FMT"x %s", + offset, buf + ); + printf( + "\r%08"OFF_FMT"x %.*s", + offset, (len*3 + G.half), buf + ); +} + +static void remap(unsigned cur_pos) +{ + if (G.addr) + munmap(G.addr, G_mapsize); + + G.addr = mmap(NULL, + G_mapsize, + PROT_READ | PROT_WRITE, + MAP_SHARED, + G.fd, + G.offset + ); + if (G.addr == MAP_FAILED) +//TODO: restore termios? + bb_perror_msg_and_die("mmap"); + + G.current_byte = G.addr + cur_pos; + + G.eof_byte = G.addr + G_mapsize; + if ((G.size - G.offset) < G_mapsize) { + /* mapping covers tail of the file */ + /* we do have a mapped byte which is past eof */ + G.eof_byte = G.addr + (G.size - G.offset); + } +} +static void move_mapping_further(void) +{ + unsigned pos; + unsigned pagesize; + + if ((G.size - G.offset) < G_mapsize) + return; /* can't move mapping even further, it's at the end already */ + + pagesize = getpagesize(); /* constant on most arches */ + pos = G.current_byte - G.addr; + if (pos >= pagesize) { + /* Move offset up until current position is in 1st page */ + do { + G.offset += pagesize; + if (G.offset == 0) { /* whoops */ + G.offset -= pagesize; + break; + } + pos -= pagesize; + } while (pos >= pagesize); + remap(pos); + } +} +static void move_mapping_lower(void) +{ + unsigned pos; + unsigned pagesize; + + if (G.offset == 0) + return; /* we are at 0 already */ + + pagesize = getpagesize(); /* constant on most arches */ + pos = G.current_byte - G.addr; + + /* Move offset down until current position is in last page */ + pos += pagesize; + while (pos < G_mapsize) { + pos += pagesize; + G.offset -= pagesize; + if (G.offset == 0) + break; + } + pos -= pagesize; + + remap(pos); +} + +static void sig_catcher(int sig) +{ + tcsetattr_stdin_TCSANOW(&G.orig_termios); + kill_myself_with_sig(sig); +} + +//usage:#define hexedit_trivial_usage +//usage: "FILE" +//usage:#define hexedit_full_usage "\n\n" +//usage: "Edit FILE in hexadecimal" +int hexedit_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int hexedit_main(int argc UNUSED_PARAM, char **argv) +{ + unsigned row = 0; + + INIT_G(); + + getopt32(argv, ""); + argv += optind; + + get_terminal_width_height(-1, NULL, &G.height); + + G.fd = xopen(*argv, O_RDWR); + G.size = xlseek(G.fd, 0, SEEK_END); + + /* TERMIOS_RAW_CRNL suppresses \n -> \r\n translation, helps with down-arrow */ + set_termios_to_raw(STDIN_FILENO, &G.orig_termios, TERMIOS_RAW_CRNL); + bb_signals(BB_FATAL_SIGS, sig_catcher); + + remap(0); + + printf(CLEAR); + redraw(); + printf(HOME "%08x ", 0); + +//TODO: //PgUp/PgDown; Home/End: start/end of line; '<'/'>': start/end of file + //Backspace: undo + //Enter: goto specified position + //Ctrl-L: redraw + //Ctrl-X: save and exit (maybe also Q?) + //Ctrl-Z: suspend + //'/', Ctrl-S: search +//TODO: go to end-of-screen on exit (for this, sighandler should interrupt read_key()) +//TODO: detect window resize +//TODO: read-only mode if open(O_RDWR) fails? hide cursor in this case? + +//TODO: smarter redraw: if down-arrow is pressed on last visible line, +//emit LF, then print the tail of next line, then CR, then beginning - +//which makes cursor end up exactly where it should be! Same for up-arrow. + + for (;;) { + char read_key_buffer[KEYCODE_BUFFER_SIZE]; + int32_t key; + uint8_t byte; + + fflush_all(); + key = read_key(STDIN_FILENO, read_key_buffer, -1); + + switch (key) { + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + /* lowercase, then convert to '0'+10...15 */ + key = (key | 0x20) - ('a' - '0' - 10); + /* fall through */ + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (G.current_byte == G.eof_byte) { + move_mapping_further(); + if (G.current_byte == G.eof_byte) { + /* extend the file */ + if (++G.size <= 0 /* overflow? */ + || ftruncate(G.fd, G.size) != 0 /* error extending? (e.g. block dev) */ + ) { + G.size--; + break; + } + G.eof_byte++; + } + } + key -= '0'; + byte = *G.current_byte & 0xf0; + if (!G.half) { + byte = *G.current_byte & 0x0f; + key <<= 4; + } + *G.current_byte = byte + key; + /* can't just print one updated hex char: need to update right-hand ASCII too */ + redraw_cur_line(); + /* fall through */ + case KEYCODE_RIGHT: + if (G.current_byte == G.eof_byte) + break; /* eof - don't allow going past it */ + byte = *G.current_byte; + if (!G.half) { + G.half = 1; + putchar(bb_hexdigits_upcase[byte >> 4]); + } else { + G.half = 0; + G.current_byte++; + if ((0xf & (uintptr_t)G.current_byte) == 0) { + /* rightmost pos, wrap to next line */ + if (G.current_byte == G.eof_byte) + move_mapping_further(); + printf(ESC"[46D"); /* cursor left 3*15 + 1 chars */ + goto down; + } + putchar(bb_hexdigits_upcase[byte & 0xf]); + putchar(' '); + } + break; + case KEYCODE_DOWN: + G.current_byte += 16; + if (G.current_byte >= G.eof_byte) { + move_mapping_further(); + if (G.current_byte > G.eof_byte) { + /* eof - don't allow going past it */ + G.current_byte -= 16; + break; + } + } + down: + putchar('\n'); /* down one line, possibly scroll screen */ + row++; + if (row >= G.height) { + row--; + redraw_cur_line(); + } + break; + + case KEYCODE_LEFT: + if (G.half) { + G.half = 0; + printf(ESC"[D"); + break; + } + if ((0xf & (uintptr_t)G.current_byte) == 0) { + /* leftmost pos, wrap to prev line */ + if (G.current_byte == G.addr) + move_mapping_lower(); + if ((G.current_byte - G.addr) < 16) + break; /* first line, don't do anything */ + G.half = 1; + G.current_byte--; + printf(ESC"[46C"); /* cursor right 3*15 + 1 chars */ + goto up; + } + G.half = 1; + G.current_byte--; + printf(ESC"[2D"); + break; + case KEYCODE_UP: + if ((G.current_byte - G.addr) < 16) { + move_mapping_lower(); + if ((G.current_byte - G.addr) < 16) + break; + } + G.current_byte -= 16; + up: + if (row != 0) { + row--; + printf(ESC"[A"); /* up (won't scroll) */ + } else { + //printf(ESC"[T"); /* scroll up */ - not implemented on Linux VT! + printf(ESC"M"); /* scroll up */ + redraw_cur_line(); + } + break; + } + } + + return EXIT_SUCCESS; +} diff --git a/miscutils/less.c b/miscutils/less.c index c1d5e1b39..f37c80ad8 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -139,7 +139,7 @@ #define HIGHLIGHT ESC"[7m" #define NORMAL ESC"[0m" /* The escape code to home and clear to the end of screen */ -#define CLEAR ESC"[H\033[J" +#define CLEAR ESC"[H"ESC"[J" /* The escape code to clear to the end of line */ #define CLEAR_2_EOL ESC"[K" -- cgit v1.2.3-55-g6feb From 136946c3ea6a14d391b5045b5eb71fa8ec207077 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 13 Sep 2017 21:38:55 +0200 Subject: hexedit: smarter redraw function old new delta format_line 197 209 +12 hexedit_main 930 924 -6 redraw_cur_line 104 94 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 12/-16) Total: -4 bytes Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 67 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index cd4b3b1ad..ac38978fd 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -38,11 +38,27 @@ struct globals { /* Hopefully there aren't arches with PAGE_SIZE > 64k */ #define G_mapsize (64*1024) -static void format_line(char *hex, uint8_t *data, off_t offset) +/* "12ef5670 (nn )*16 abcdef_1_3_5_7_9\n" */ +#define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 /*paranoia:*/ + 14) + +static int format_line(char *hex, uint8_t *data, off_t offset) { - char *text = hex + 16*3; + int ofs_pos; + char *text; uint8_t *end, *end1; +#if 1 + /* Can be more than 4Gb, thus >8 chars, thus use a variable - don't assume 8! */ + ofs_pos = sprintf(hex, "%08"OFF_FMT"x ", offset); +#else + if (offset <= 0xffff) + ofs_pos = sprintf(hex, "%04"OFF_FMT"x ", offset); + else + ofs_pos = sprintf(hex, "%08"OFF_FMT"x ", offset); +#endif + hex += ofs_pos; + + text = hex + 16*3; end1 = data + 15; if ((G.size - offset) > 0) { end = end1; @@ -66,6 +82,8 @@ static void format_line(char *hex, uint8_t *data, off_t offset) data++; } *text = '\0'; + + return ofs_pos; } static void redraw(void) @@ -78,11 +96,11 @@ static void redraw(void) offset = 0; i = 0; while (i < G.height) { - char buf[16*4 + 8]; + char buf[LINEBUF_SIZE]; format_line(buf, data, offset); printf( - "\r\n%08"OFF_FMT"x %s" + (!i)*2, /* print \r\n only on 2nd line and later */ - offset, buf + "\r\n%s" + (!i)*2, /* print \r\n only on 2nd line and later */ + buf ); data += 16; offset += 16; @@ -92,22 +110,22 @@ static void redraw(void) static void redraw_cur_line(void) { - off_t offset; - int len; - char buf[16*4 + 8]; + char buf[LINEBUF_SIZE]; uint8_t *data; + off_t offset; + int column; - len = (0xf & (uintptr_t)G.current_byte); - data = G.current_byte - len; + column = (0xf & (uintptr_t)G.current_byte); + data = G.current_byte - column; offset = G.offset + (data - G.addr); - format_line(buf, data, offset); - printf( - "\r%08"OFF_FMT"x %s", - offset, buf - ); - printf( - "\r%08"OFF_FMT"x %.*s", - offset, (len*3 + G.half), buf + + column = column*3 + G.half; + column += format_line(buf, data, offset); + printf("%s" + "\r" + "%.*s", + buf + column, + column, buf ); } @@ -216,7 +234,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) printf(CLEAR); redraw(); - printf(HOME "%08x ", 0); + printf(ESC"[1;10H"); /* position on 1st hex byte in first line */ //TODO: //PgUp/PgDown; Home/End: start/end of line; '<'/'>': start/end of file //Backspace: undo @@ -229,10 +247,6 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) //TODO: detect window resize //TODO: read-only mode if open(O_RDWR) fails? hide cursor in this case? -//TODO: smarter redraw: if down-arrow is pressed on last visible line, -//emit LF, then print the tail of next line, then CR, then beginning - -//which makes cursor end up exactly where it should be! Same for up-arrow. - for (;;) { char read_key_buffer[KEYCODE_BUFFER_SIZE]; int32_t key; @@ -320,10 +334,11 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) } if ((0xf & (uintptr_t)G.current_byte) == 0) { /* leftmost pos, wrap to prev line */ - if (G.current_byte == G.addr) + if (G.current_byte == G.addr) { move_mapping_lower(); - if ((G.current_byte - G.addr) < 16) - break; /* first line, don't do anything */ + if (G.current_byte == G.addr) + break; /* first line, don't do anything */ + } G.half = 1; G.current_byte--; printf(ESC"[46C"); /* cursor right 3*15 + 1 chars */ -- cgit v1.2.3-55-g6feb From 8187e0143874e1bf0412263e716cf8c782a5aa16 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 13 Sep 2017 22:48:30 +0200 Subject: *: use ESC define instead of "\033"; use ESC[m instead of ESC[0m text data bss dec hex filename 922535 481 6832 929848 e3038 busybox_old 922534 481 6832 929847 e3037 busybox_unstripped Signed-off-by: Denys Vlasenko --- console-tools/clear.c | 4 +++- console-tools/reset.c | 4 ++-- coreutils/ls.c | 10 ++++++---- editors/vi.c | 21 +++++++++++---------- libbb/lineedit.c | 2 +- miscutils/fbsplash.c | 6 ++++-- miscutils/less.c | 4 ++-- procps/powertop.c | 6 ++++-- procps/top.c | 9 +++++---- procps/watch.c | 4 +++- 10 files changed, 41 insertions(+), 29 deletions(-) diff --git a/console-tools/clear.c b/console-tools/clear.c index 3cc16257b..09ef1ea68 100644 --- a/console-tools/clear.c +++ b/console-tools/clear.c @@ -23,9 +23,11 @@ #include "libbb.h" +#define ESC "\033" + int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) { /* home; clear to the end of screen */ - return full_write1_str("\033[H""\033[J") != 6; + return full_write1_str(ESC"[H" ESC"[J") != 6; } diff --git a/console-tools/reset.c b/console-tools/reset.c index f2b900ddb..471ef9158 100644 --- a/console-tools/reset.c +++ b/console-tools/reset.c @@ -46,11 +46,11 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) /* See 'man 4 console_codes' for details: * "ESC c" -- Reset * "ESC ( B" -- Select G0 Character Set (B = US) - * "ESC [ 0 m" -- Reset all display attributes + * "ESC [ m" -- Reset all display attributes * "ESC [ J" -- Erase to the end of screen * "ESC [ ? 25 h" -- Make cursor visible */ - printf(ESC"c" ESC"(B" ESC"[0m" ESC"[J" ESC"[?25h"); + printf(ESC"c" ESC"(B" ESC"[m" ESC"[J" ESC"[?25h"); /* http://bugs.busybox.net/view.php?id=1414: * people want it to reset echo etc: */ #if ENABLE_STTY diff --git a/coreutils/ls.c b/coreutils/ls.c index af5e6cb51..a4e324b00 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -347,6 +347,8 @@ struct globals { IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \ } while (0) +#define ESC "\033" + /*** Output code ***/ @@ -586,12 +588,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn) if (!mode) if (lstat(dn->fullname, &statbuf) == 0) mode = statbuf.st_mode; - printf("\033[%u;%um", bold(mode), fgcolor(mode)); + printf(ESC"[%u;%um", bold(mode), fgcolor(mode)); } #endif column += print_name(dn->name); if (G_show_color) { - printf("\033[0m"); + printf(ESC"[m"); } if (lpath) { @@ -609,7 +611,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn) # endif # if ENABLE_FEATURE_LS_COLOR if (G_show_color) { - printf("\033[%u;%um", bold(mode), fgcolor(mode)); + printf(ESC"[%u;%um", bold(mode), fgcolor(mode)); } # endif } @@ -617,7 +619,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn) column += print_name(lpath) + 4; free(lpath); if (G_show_color) { - printf("\033[0m"); + printf(ESC"[m"); } } #if ENABLE_FEATURE_LS_FILETYPES diff --git a/editors/vi.c b/editors/vi.c index 116022c93..c010f7999 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -224,24 +224,25 @@ enum { * See "Xterm Control Sequences" * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html */ +#define ESC "\033" /* Inverse/Normal text */ -#define ESC_BOLD_TEXT "\033[7m" -#define ESC_NORM_TEXT "\033[0m" +#define ESC_BOLD_TEXT ESC"[7m" +#define ESC_NORM_TEXT ESC"[m" /* Bell */ #define ESC_BELL "\007" /* Clear-to-end-of-line */ -#define ESC_CLEAR2EOL "\033[K" +#define ESC_CLEAR2EOL ESC"[K" /* Clear-to-end-of-screen. * (We use default param here. * Full sequence is "ESC [ J", * is 0/1/2 = "erase below/above/all".) */ -#define ESC_CLEAR2EOS "\033[J" +#define ESC_CLEAR2EOS ESC"[J" /* Cursor to given coordinate (1,1: top left) */ -#define ESC_SET_CURSOR_POS "\033[%u;%uH" +#define ESC_SET_CURSOR_POS ESC"[%u;%uH" //UNUSED ///* Cursor up and down */ -//#define ESC_CURSOR_UP "\033[A" +//#define ESC_CURSOR_UP ESC"[A" //#define ESC_CURSOR_DOWN "\n" #if ENABLE_FEATURE_VI_DOT_CMD || ENABLE_FEATURE_VI_YANKMARK @@ -696,14 +697,14 @@ int vi_main(int argc, char **argv) save_argc = argc; optind = 0; // "Save cursor, use alternate screen buffer, clear screen" - write1("\033[?1049h"); + write1(ESC"[?1049h"); while (1) { edit_file(argv[optind]); /* param might be NULL */ if (++optind >= argc) break; } // "Use normal screen buffer, restore cursor" - write1("\033[?1049l"); + write1(ESC"[?1049l"); //----------------------------------------------------------- return 0; @@ -772,7 +773,7 @@ static void edit_file(char *fn) #if ENABLE_FEATURE_VI_ASK_TERMINAL if (G.get_rowcol_error /* TODO? && no input on stdin */) { uint64_t k; - write1("\033[999;999H" "\033[6n"); + write1(ESC"[999;999H" ESC"[6n"); fflush_all(); k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100); if ((int32_t)k == KEYCODE_CURSOR_POS) { @@ -4454,7 +4455,7 @@ static void crash_dummy() sleeptime = 0; // how fast to type } } - strcat(readbuffer, "\033"); + strcat(readbuffer, ESC); } readbuffer[0] = strlen(readbuffer + 1); cd1: diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 0106093a1..17766a126 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2868,7 +2868,7 @@ int main(int argc, char **argv) #if ENABLE_FEATURE_EDITING_FANCY_PROMPT "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:" "\\[\\033[34;1m\\]\\w\\[\\033[35;1m\\] " - "\\!\\[\\e[36;1m\\]\\$ \\[\\E[0m\\]"; + "\\!\\[\\e[36;1m\\]\\$ \\[\\E[m\\]"; #else "% "; #endif diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 9ac91e01e..5b2e5ac56 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c @@ -65,6 +65,8 @@ /* If you want logging messages on /tmp/fbsplash.log... */ #define DEBUG 0 +#define ESC "\033" + struct globals { #if DEBUG bool bdebug_messages; // enable/disable logging @@ -514,7 +516,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv) if (fifo_filename && bCursorOff) { // hide cursor (BEFORE any fb ops) - full_write(STDOUT_FILENO, "\033[?25l", 6); + full_write(STDOUT_FILENO, ESC"[?25l", 6); } fb_drawimage(); @@ -559,7 +561,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv) } if (bCursorOff) // restore cursor - full_write(STDOUT_FILENO, "\033[?25h", 6); + full_write(STDOUT_FILENO, ESC"[?25h", 6); return EXIT_SUCCESS; } diff --git a/miscutils/less.c b/miscutils/less.c index f37c80ad8..241f7f8ba 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -137,7 +137,7 @@ #define ESC "\033" /* The escape codes for highlighted and normal text */ #define HIGHLIGHT ESC"[7m" -#define NORMAL ESC"[0m" +#define NORMAL ESC"[m" /* The escape code to home and clear to the end of screen */ #define CLEAR ESC"[H"ESC"[J" /* The escape code to clear to the end of line */ @@ -1042,7 +1042,7 @@ static void reinitialize(void) open_file_and_read_lines(); #if ENABLE_FEATURE_LESS_ASK_TERMINAL if (G.winsize_err) - printf("\033[999;999H" "\033[6n"); + printf(ESC"[999;999H" ESC"[6n"); #endif buffer_fill_and_print(); } diff --git a/procps/powertop.c b/procps/powertop.c index 5d522bf91..2872035cf 100644 --- a/procps/powertop.c +++ b/procps/powertop.c @@ -51,6 +51,8 @@ /* Max filename length of entry in /sys/devices subsystem */ #define BIG_SYSNAME_LEN 16 +#define ESC "\033" + typedef unsigned long long ullong; struct line { @@ -776,8 +778,8 @@ int powertop_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv) } } - /* Clear the screen */ - printf("\033[H\033[J"); + /* Home; clear screen */ + printf(ESC"[H" ESC"[J"); /* Clear C-state lines */ memset(&cstate_lines, 0, sizeof(cstate_lines)); diff --git a/procps/top.c b/procps/top.c index f97ded5d6..b777c494e 100644 --- a/procps/top.c +++ b/procps/top.c @@ -117,6 +117,7 @@ #include "libbb.h" +#define ESC "\033" typedef struct top_status_t { unsigned long vsz; @@ -580,7 +581,7 @@ static unsigned long display_header(int scr_width, int *lines_rem_p) meminfo[MI_BUFFERS], meminfo[MI_CACHED]); /* Go to top & clear to the end of screen */ - printf(OPT_BATCH_MODE ? "%s\n" : "\033[H\033[J%s\n", scrbuf); + printf(OPT_BATCH_MODE ? "%s\n" : ESC"[H" ESC"[J" "%s\n", scrbuf); (*lines_rem_p)--; /* Display CPU time split as percentage of total time. @@ -618,7 +619,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) #endif /* what info of the processes is shown */ - printf(OPT_BATCH_MODE ? "%.*s" : "\033[7m%.*s\033[0m", scr_width, + printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width, " PID PPID USER STAT VSZ %VSZ" IF_FEATURE_TOP_SMP_PROCESS(" CPU") IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU") @@ -802,7 +803,7 @@ static void display_topmem_header(int scr_width, int *lines_rem_p) meminfo[MI_ANONPAGES], meminfo[MI_MAPPED], meminfo[MI_MEMFREE]); - printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, line_buf); + printf(OPT_BATCH_MODE ? "%.*s\n" : ESC"[H" ESC"[J" "%.*s\n", scr_width, line_buf); snprintf(line_buf, LINE_BUF_SIZE, " slab:%lu buf:%lu cache:%lu dirty:%lu write:%lu", @@ -844,7 +845,7 @@ static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) cp[6] = ch; do *cp++ = ch; while (*cp == ' '); - printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf); + printf(OPT_BATCH_MODE ? "%.*s" : ESC"[7m" "%.*s" ESC"[m", scr_width, line_buf); lines_rem--; if (lines_rem > ntop - G_scroll_ofs) diff --git a/procps/watch.c b/procps/watch.c index 6fc9f7db7..e58fd1f11 100644 --- a/procps/watch.c +++ b/procps/watch.c @@ -37,6 +37,8 @@ #include "libbb.h" +#define ESC "\033" + // procps 2.0.18: // watch [-d] [-n seconds] // [--differences[=cumulative]] [--interval=seconds] command @@ -77,7 +79,7 @@ int watch_main(int argc UNUSED_PARAM, char **argv) header = NULL; while (1) { /* home; clear to the end of screen */ - printf("\033[H""\033[J"); + printf(ESC"[H" ESC"[J"); if (!(opt & 0x2)) { // no -t const unsigned time_len = sizeof("1234-67-90 23:56:89"); -- cgit v1.2.3-55-g6feb From 62643017c3d5bc1bb9fff91553e52a47e7730a01 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 13 Sep 2017 23:02:51 +0200 Subject: hexedit: implement page up/down function old new delta hexedit_main 924 970 +46 Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index ac38978fd..a99569706 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -236,7 +236,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) redraw(); printf(ESC"[1;10H"); /* position on 1st hex byte in first line */ -//TODO: //PgUp/PgDown; Home/End: start/end of line; '<'/'>': start/end of file +//TODO: //Home/End: start/end of line; '<'/'>': start/end of file //Backspace: undo //Enter: goto specified position //Ctrl-L: redraw @@ -249,12 +249,14 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) for (;;) { char read_key_buffer[KEYCODE_BUFFER_SIZE]; + unsigned cnt; int32_t key; uint8_t byte; fflush_all(); key = read_key(STDIN_FILENO, read_key_buffer, -1); + cnt = 1; switch (key) { case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': @@ -307,7 +309,10 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) putchar(' '); } break; + case KEYCODE_PAGEDOWN: + cnt = G.height; case KEYCODE_DOWN: + k_down: G.current_byte += 16; if (G.current_byte >= G.eof_byte) { move_mapping_further(); @@ -324,6 +329,8 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) row--; redraw_cur_line(); } + if (--cnt) + goto k_down; break; case KEYCODE_LEFT: @@ -348,7 +355,10 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) G.current_byte--; printf(ESC"[2D"); break; + case KEYCODE_PAGEUP: + cnt = G.height; case KEYCODE_UP: + k_up: if ((G.current_byte - G.addr) < 16) { move_mapping_lower(); if ((G.current_byte - G.addr) < 16) @@ -364,6 +374,8 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) printf(ESC"M"); /* scroll up */ redraw_cur_line(); } + if (--cnt) + goto k_up; break; } } -- cgit v1.2.3-55-g6feb From d72e804e6db1bd6eb2417961004b4fe33aba9384 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Sep 2017 00:04:16 +0200 Subject: hexedit: optimize output buffering function old new delta hexedit_main 970 998 +28 Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index a99569706..e8bc73b7e 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -38,8 +38,8 @@ struct globals { /* Hopefully there aren't arches with PAGE_SIZE > 64k */ #define G_mapsize (64*1024) -/* "12ef5670 (nn )*16 abcdef_1_3_5_7_9\n" */ -#define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 /*paranoia:*/ + 14) +/* "12ef5670 (xx )*16 _1_3_5_7_9abcdef\n"NUL */ +#define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 + 1 /*paranoia:*/ + 13) static int format_line(char *hex, uint8_t *data, off_t offset) { @@ -165,7 +165,7 @@ static void move_mapping_further(void) pagesize = getpagesize(); /* constant on most arches */ pos = G.current_byte - G.addr; if (pos >= pagesize) { - /* Move offset up until current position is in 1st page */ + /* move offset up until current position is in 1st page */ do { G.offset += pagesize; if (G.offset == 0) { /* whoops */ @@ -188,7 +188,7 @@ static void move_mapping_lower(void) pagesize = getpagesize(); /* constant on most arches */ pos = G.current_byte - G.addr; - /* Move offset down until current position is in last page */ + /* move offset down until current position is in last page */ pos += pagesize; while (pos < G_mapsize) { pos += pagesize; @@ -218,10 +218,15 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - getopt32(argv, ""); - argv += optind; - get_terminal_width_height(-1, NULL, &G.height); + if (1) { + /* reduce number of write() syscalls while PgUp/Down: fully buffered output */ + unsigned sz = (G.height | 0xf) * LINEBUF_SIZE; + setvbuf(stdout, xmalloc(sz), _IOFBF, sz); + } + + getopt32(argv, "^" "" "\0" "=1"/*one arg*/); + argv += optind; G.fd = xopen(*argv, O_RDWR); G.size = xlseek(G.fd, 0, SEEK_END); -- cgit v1.2.3-55-g6feb From 363fb5ec4091120003b3f204996e7ff0aa354e58 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Sep 2017 09:42:40 +0200 Subject: hexedit: restore screen on exit function old new delta hexedit_main 998 1082 +84 restore_term - 29 +29 remap 168 173 +5 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/0 up/down: 118/0) Total: 118 bytes Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 79 +++++++++++++++++++++++++++++++++++------------------ miscutils/less.c | 2 +- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index e8bc73b7e..b8627e826 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -15,19 +15,28 @@ #include "libbb.h" -#define ESC "\033" -#define HOME ESC"[H" -#define CLEAR ESC"[H"ESC"[J" +#define ESC "\033" +#define HOME ESC"[H" +#define CLEAR ESC"[H"ESC"[J" +#define SET_ALT_SCR ESC"[?1049h" +#define POP_ALT_SCR ESC"[?1049l" + +#undef CTRL +#define CTRL(c) ((c) & (uint8_t)~0x60) struct globals { smallint half; + smallint in_read_key; int fd; unsigned height; + unsigned row; uint8_t *addr; uint8_t *current_byte; uint8_t *eof_byte; off_t size; off_t offset; + /* needs to be zero-inited, thus keeping it in G: */ + char read_key_buffer[KEYCODE_BUFFER_SIZE]; struct termios orig_termios; }; #define G (*ptr_to_globals) @@ -41,6 +50,24 @@ struct globals { /* "12ef5670 (xx )*16 _1_3_5_7_9abcdef\n"NUL */ #define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 + 1 /*paranoia:*/ + 13) +static void restore_term(void) +{ + tcsetattr_stdin_TCSANOW(&G.orig_termios); + printf(POP_ALT_SCR); + fflush_all(); +} + +static void sig_catcher(int sig) +{ + if (!G.in_read_key) { + /* now it's not safe to do I/O, just inform the main loop */ + bb_got_signal = sig; + return; + } + restore_term(); + kill_myself_with_sig(sig); +} + static int format_line(char *hex, uint8_t *data, off_t offset) { int ofs_pos; @@ -141,9 +168,10 @@ static void remap(unsigned cur_pos) G.fd, G.offset ); - if (G.addr == MAP_FAILED) -//TODO: restore termios? + if (G.addr == MAP_FAILED) { + restore_term(); bb_perror_msg_and_die("mmap"); + } G.current_byte = G.addr + cur_pos; @@ -201,12 +229,6 @@ static void move_mapping_lower(void) remap(pos); } -static void sig_catcher(int sig) -{ - tcsetattr_stdin_TCSANOW(&G.orig_termios); - kill_myself_with_sig(sig); -} - //usage:#define hexedit_trivial_usage //usage: "FILE" //usage:#define hexedit_full_usage "\n\n" @@ -214,8 +236,6 @@ static void sig_catcher(int sig) int hexedit_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int hexedit_main(int argc UNUSED_PARAM, char **argv) { - unsigned row = 0; - INIT_G(); get_terminal_width_height(-1, NULL, &G.height); @@ -237,7 +257,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) remap(0); - printf(CLEAR); + printf(SET_ALT_SCR); redraw(); printf(ESC"[1;10H"); /* position on 1st hex byte in first line */ @@ -245,21 +265,22 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) //Backspace: undo //Enter: goto specified position //Ctrl-L: redraw - //Ctrl-X: save and exit (maybe also Q?) //Ctrl-Z: suspend //'/', Ctrl-S: search -//TODO: go to end-of-screen on exit (for this, sighandler should interrupt read_key()) //TODO: detect window resize -//TODO: read-only mode if open(O_RDWR) fails? hide cursor in this case? for (;;) { - char read_key_buffer[KEYCODE_BUFFER_SIZE]; unsigned cnt; - int32_t key; + int32_t key = key; // for compiler uint8_t byte; fflush_all(); - key = read_key(STDIN_FILENO, read_key_buffer, -1); + G.in_read_key = 1; + if (!bb_got_signal) + key = read_key(STDIN_FILENO, G.read_key_buffer, -1); + G.in_read_key = 0; + if (bb_got_signal) + key = CTRL('X'); cnt = 1; switch (key) { @@ -329,9 +350,9 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) } down: putchar('\n'); /* down one line, possibly scroll screen */ - row++; - if (row >= G.height) { - row--; + G.row++; + if (G.row >= G.height) { + G.row--; redraw_cur_line(); } if (--cnt) @@ -371,8 +392,8 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) } G.current_byte -= 16; up: - if (row != 0) { - row--; + if (G.row != 0) { + G.row--; printf(ESC"[A"); /* up (won't scroll) */ } else { //printf(ESC"[T"); /* scroll up */ - not implemented on Linux VT! @@ -382,8 +403,12 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) if (--cnt) goto k_up; break; - } - } + case CTRL('X'): + restore_term(); + return EXIT_SUCCESS; + } /* switch */ + } /* for (;;) */ + /* not reached */ return EXIT_SUCCESS; } diff --git a/miscutils/less.c b/miscutils/less.c index 241f7f8ba..f869a9e82 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -1103,7 +1103,7 @@ static int64_t getch_nowait(void) goto again; } /* EOF/error (ssh session got killed etc) */ - less_exit(0); + less_exit(EXIT_SUCCESS); } set_tty_cooked(); return key64; -- cgit v1.2.3-55-g6feb From d54f58d487bfa5d6646d9a728d503351691081bf Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Sep 2017 10:51:12 +0200 Subject: hexedit: implement "[enter] goto offset" key This is a must if you need to edit sector 123456789999 on your /dev/disk. text data bss dec hex filename 922745 481 6832 930058 e310a busybox_old 923023 481 6832 930336 e3220 busybox_unstripped Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 79 ++++++++++++++++++++++++++++++++++++----------------- miscutils/less.c | 4 +-- 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index b8627e826..eaf4ba57b 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -17,7 +17,8 @@ #define ESC "\033" #define HOME ESC"[H" -#define CLEAR ESC"[H"ESC"[J" +#define CLEAR ESC"[J" +#define CLEAR_TILL_EOL ESC"[K" #define SET_ALT_SCR ESC"[?1049h" #define POP_ALT_SCR ESC"[?1049l" @@ -30,7 +31,7 @@ struct globals { int fd; unsigned height; unsigned row; - uint8_t *addr; + uint8_t *baseaddr; uint8_t *current_byte; uint8_t *eof_byte; off_t size; @@ -117,14 +118,15 @@ static void redraw(void) { uint8_t *data; off_t offset; - unsigned i; + unsigned i, pos; - data = G.addr; - offset = 0; - i = 0; + printf(HOME CLEAR); + data = G.baseaddr; + offset = G.offset; + pos = i = 0; while (i < G.height) { char buf[LINEBUF_SIZE]; - format_line(buf, data, offset); + pos = format_line(buf, data, offset); printf( "\r\n%s" + (!i)*2, /* print \r\n only on 2nd line and later */ buf @@ -133,6 +135,7 @@ static void redraw(void) offset += 16; i++; } + printf(ESC"[1;%uH", pos + 1); /* position on 1st hex byte in first line */ } static void redraw_cur_line(void) @@ -144,7 +147,7 @@ static void redraw_cur_line(void) column = (0xf & (uintptr_t)G.current_byte); data = G.current_byte - column; - offset = G.offset + (data - G.addr); + offset = G.offset + (data - G.baseaddr); column = column*3 + G.half; column += format_line(buf, data, offset); @@ -158,28 +161,28 @@ static void redraw_cur_line(void) static void remap(unsigned cur_pos) { - if (G.addr) - munmap(G.addr, G_mapsize); + if (G.baseaddr) + munmap(G.baseaddr, G_mapsize); - G.addr = mmap(NULL, + G.baseaddr = mmap(NULL, G_mapsize, PROT_READ | PROT_WRITE, MAP_SHARED, G.fd, G.offset ); - if (G.addr == MAP_FAILED) { + if (G.baseaddr == MAP_FAILED) { restore_term(); bb_perror_msg_and_die("mmap"); } - G.current_byte = G.addr + cur_pos; + G.current_byte = G.baseaddr + cur_pos; - G.eof_byte = G.addr + G_mapsize; + G.eof_byte = G.baseaddr + G_mapsize; if ((G.size - G.offset) < G_mapsize) { /* mapping covers tail of the file */ /* we do have a mapped byte which is past eof */ - G.eof_byte = G.addr + (G.size - G.offset); + G.eof_byte = G.baseaddr + (G.size - G.offset); } } static void move_mapping_further(void) @@ -191,7 +194,7 @@ static void move_mapping_further(void) return; /* can't move mapping even further, it's at the end already */ pagesize = getpagesize(); /* constant on most arches */ - pos = G.current_byte - G.addr; + pos = G.current_byte - G.baseaddr; if (pos >= pagesize) { /* move offset up until current position is in 1st page */ do { @@ -214,7 +217,7 @@ static void move_mapping_lower(void) return; /* we are at 0 already */ pagesize = getpagesize(); /* constant on most arches */ - pos = G.current_byte - G.addr; + pos = G.current_byte - G.baseaddr; /* move offset down until current position is in last page */ pos += pagesize; @@ -252,18 +255,15 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) G.size = xlseek(G.fd, 0, SEEK_END); /* TERMIOS_RAW_CRNL suppresses \n -> \r\n translation, helps with down-arrow */ + printf(SET_ALT_SCR); set_termios_to_raw(STDIN_FILENO, &G.orig_termios, TERMIOS_RAW_CRNL); bb_signals(BB_FATAL_SIGS, sig_catcher); remap(0); - - printf(SET_ALT_SCR); redraw(); - printf(ESC"[1;10H"); /* position on 1st hex byte in first line */ //TODO: //Home/End: start/end of line; '<'/'>': start/end of file //Backspace: undo - //Enter: goto specified position //Ctrl-L: redraw //Ctrl-Z: suspend //'/', Ctrl-S: search @@ -367,9 +367,9 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) } if ((0xf & (uintptr_t)G.current_byte) == 0) { /* leftmost pos, wrap to prev line */ - if (G.current_byte == G.addr) { + if (G.current_byte == G.baseaddr) { move_mapping_lower(); - if (G.current_byte == G.addr) + if (G.current_byte == G.baseaddr) break; /* first line, don't do anything */ } G.half = 1; @@ -385,9 +385,9 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) cnt = G.height; case KEYCODE_UP: k_up: - if ((G.current_byte - G.addr) < 16) { + if ((G.current_byte - G.baseaddr) < 16) { move_mapping_lower(); - if ((G.current_byte - G.addr) < 16) + if ((G.current_byte - G.baseaddr) < 16) break; } G.current_byte -= 16; @@ -403,6 +403,35 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) if (--cnt) goto k_up; break; + + case '\n': + case '\r': + /* [Enter]: goto specified position */ + { + char buf[sizeof(G.offset)*3 + 4]; + printf(ESC"[999;1H" CLEAR_TILL_EOL); /* go to last line */ + if (read_line_input(NULL, "Go to (dec,0Xhex,0oct): ", buf, sizeof(buf)) >= 0) { + off_t t; + unsigned pgmask; + + t = bb_strtoull(buf, NULL, 0); + if (t >= G.size) + t = G.size - 1; + pgmask = getpagesize() - 1; + cnt = t & pgmask; + t = t & ~(off_t)pgmask; + if (t < 0) + cnt = t = 0; + G.offset = t; + remap(0); + redraw(); + cnt /= 16; + if (cnt) + goto k_down; + break; + } + /* EOF/error on input: fall through to exiting */ + } case CTRL('X'): restore_term(); return EXIT_SUCCESS; diff --git a/miscutils/less.c b/miscutils/less.c index f869a9e82..d524b6c87 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -281,9 +281,9 @@ static void set_tty_cooked(void) /* Move the cursor to a position (x,y), where (0,0) is the top-left corner of the console */ -static void move_cursor(int line, int row) +static void move_cursor(int line, int col) { - printf(ESC"[%u;%uH", line, row); + printf(ESC"[%u;%uH", line, col); } static void clear_line(void) -- cgit v1.2.3-55-g6feb From 8838c6d53ecf9491d862ee090c9bf1579fa64eed Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Sep 2017 11:01:37 +0200 Subject: hexdump: code shrink function old new delta remap 173 178 +5 move_mapping_lower 107 109 +2 move_mapping_further 141 143 +2 hexedit_main 1191 1176 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/1 up/down: 9/-15) Total: -6 bytes Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index eaf4ba57b..bdb7683f2 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -159,7 +159,8 @@ static void redraw_cur_line(void) ); } -static void remap(unsigned cur_pos) +/* if remappers return 0, no change was done */ +static int remap(unsigned cur_pos) { if (G.baseaddr) munmap(G.baseaddr, G_mapsize); @@ -184,14 +185,15 @@ static void remap(unsigned cur_pos) /* we do have a mapped byte which is past eof */ G.eof_byte = G.baseaddr + (G.size - G.offset); } + return 1; } -static void move_mapping_further(void) +static int move_mapping_further(void) { unsigned pos; unsigned pagesize; if ((G.size - G.offset) < G_mapsize) - return; /* can't move mapping even further, it's at the end already */ + return 0; /* can't move mapping even further, it's at the end already */ pagesize = getpagesize(); /* constant on most arches */ pos = G.current_byte - G.baseaddr; @@ -205,16 +207,17 @@ static void move_mapping_further(void) } pos -= pagesize; } while (pos >= pagesize); - remap(pos); + return remap(pos); } + return 0; } -static void move_mapping_lower(void) +static int move_mapping_lower(void) { unsigned pos; unsigned pagesize; if (G.offset == 0) - return; /* we are at 0 already */ + return 0; /* we are at 0 already */ pagesize = getpagesize(); /* constant on most arches */ pos = G.current_byte - G.baseaddr; @@ -229,7 +232,7 @@ static void move_mapping_lower(void) } pos -= pagesize; - remap(pos); + return remap(pos); } //usage:#define hexedit_trivial_usage @@ -292,9 +295,8 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (G.current_byte == G.eof_byte) { - move_mapping_further(); - if (G.current_byte == G.eof_byte) { - /* extend the file */ + if (!move_mapping_further()) { + /* already at EOF; extend the file */ if (++G.size <= 0 /* overflow? */ || ftruncate(G.fd, G.size) != 0 /* error extending? (e.g. block dev) */ ) { @@ -343,7 +345,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) if (G.current_byte >= G.eof_byte) { move_mapping_further(); if (G.current_byte > G.eof_byte) { - /* eof - don't allow going past it */ + /* _after_ eof - don't allow this */ G.current_byte -= 16; break; } @@ -368,8 +370,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) if ((0xf & (uintptr_t)G.current_byte) == 0) { /* leftmost pos, wrap to prev line */ if (G.current_byte == G.baseaddr) { - move_mapping_lower(); - if (G.current_byte == G.baseaddr) + if (!move_mapping_lower()) break; /* first line, don't do anything */ } G.half = 1; @@ -386,9 +387,8 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) case KEYCODE_UP: k_up: if ((G.current_byte - G.baseaddr) < 16) { - move_mapping_lower(); - if ((G.current_byte - G.baseaddr) < 16) - break; + if (!move_mapping_lower()) + break; /* already at 0, stop */ } G.current_byte -= 16; up: -- cgit v1.2.3-55-g6feb From 44cb1666ef4403a0fa8838d49006567ac960b33a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Sep 2017 11:20:36 +0200 Subject: hexedit: code shrink function old new delta hexedit_main 1176 1169 -7 Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index bdb7683f2..1d683b7de 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -274,7 +274,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) for (;;) { unsigned cnt; - int32_t key = key; // for compiler + int32_t key = key; /* for compiler */ uint8_t byte; fflush_all(); @@ -286,11 +286,12 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) key = CTRL('X'); cnt = 1; + if ((unsigned)(key - 'A') <= 'Z' - 'A') + key |= 0x20; /* convert A-Z to a-z */ switch (key) { - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - /* lowercase, then convert to '0'+10...15 */ - key = (key | 0x20) - ('a' - '0' - 10); + /* convert to '0'+10...15 */ + key = key - ('a' - '0' - 10); /* fall through */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': -- cgit v1.2.3-55-g6feb From 9a4100cf53f75356854ce752374babf8135c3f42 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Sep 2017 13:57:07 +0200 Subject: hexedit: position in correct column on "goto" command function old new delta hexedit_main 1169 1202 +33 Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index 1d683b7de..7e74e1f24 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -424,9 +424,11 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) if (t < 0) cnt = t = 0; G.offset = t; - remap(0); + remap(cnt & 0xf); redraw(); - cnt /= 16; + if (cnt & 0xf) + printf(ESC"[%uC", (cnt & 0xf) * 3); /* cursor right 3*i */ + cnt >>= 4; if (cnt) goto k_down; break; -- cgit v1.2.3-55-g6feb From f3fa86525850620d31e48a742a25fd4965b1dba2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 15 Sep 2017 14:00:41 +0200 Subject: hexedit: fixes to "goto address" code Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 60 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index 7e74e1f24..8334181c7 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -31,6 +31,7 @@ struct globals { int fd; unsigned height; unsigned row; + unsigned pagesize; uint8_t *baseaddr; uint8_t *current_byte; uint8_t *eof_byte; @@ -45,8 +46,17 @@ struct globals { SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ } while (0) -/* Hopefully there aren't arches with PAGE_SIZE > 64k */ -#define G_mapsize (64*1024) +//TODO: move to libbb +#if defined(__x86_64__) || defined(i386) +# define G_pagesize 4096 +# define INIT_PAGESIZE() ((void)0) +#else +# define G_pagesize (G.pagesize) +# define INIT_PAGESIZE() ((void)(G.pagesize = getpagesize())) +#endif + +/* hopefully there aren't arches with PAGE_SIZE > 64k */ +#define G_mapsize (64*1024) /* "12ef5670 (xx )*16 _1_3_5_7_9abcdef\n"NUL */ #define LINEBUF_SIZE (8 + 1 + 3*16 + 16 + 1 + 1 /*paranoia:*/ + 13) @@ -86,7 +96,7 @@ static int format_line(char *hex, uint8_t *data, off_t offset) #endif hex += ofs_pos; - text = hex + 16*3; + text = hex + 16 * 3; end1 = data + 15; if ((G.size - offset) > 0) { end = end1; @@ -114,28 +124,36 @@ static int format_line(char *hex, uint8_t *data, off_t offset) return ofs_pos; } -static void redraw(void) +static void redraw(unsigned cursor) { uint8_t *data; off_t offset; unsigned i, pos; printf(HOME CLEAR); - data = G.baseaddr; - offset = G.offset; + + /* if cursor is past end of screen, how many lines to move down? */ + i = (cursor / 16) - G.height + 1; + if ((int)i < 0) + i = 0; + + data = G.baseaddr + i * 16; + offset = G.offset + i * 16; + cursor -= i * 16; pos = i = 0; while (i < G.height) { char buf[LINEBUF_SIZE]; pos = format_line(buf, data, offset); printf( - "\r\n%s" + (!i)*2, /* print \r\n only on 2nd line and later */ + "\r\n%s" + (!i) * 2, /* print \r\n only on 2nd line and later */ buf ); data += 16; offset += 16; i++; } - printf(ESC"[1;%uH", pos + 1); /* position on 1st hex byte in first line */ + + printf(ESC"[%u;%uH", 1 + cursor / 16, 1 + pos + (cursor & 0xf) * 3); } static void redraw_cur_line(void) @@ -195,7 +213,7 @@ static int move_mapping_further(void) if ((G.size - G.offset) < G_mapsize) return 0; /* can't move mapping even further, it's at the end already */ - pagesize = getpagesize(); /* constant on most arches */ + pagesize = G_pagesize; /* constant on most arches */ pos = G.current_byte - G.baseaddr; if (pos >= pagesize) { /* move offset up until current position is in 1st page */ @@ -219,7 +237,7 @@ static int move_mapping_lower(void) if (G.offset == 0) return 0; /* we are at 0 already */ - pagesize = getpagesize(); /* constant on most arches */ + pagesize = G_pagesize; /* constant on most arches */ pos = G.current_byte - G.baseaddr; /* move offset down until current position is in last page */ @@ -243,6 +261,7 @@ int hexedit_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int hexedit_main(int argc UNUSED_PARAM, char **argv) { INIT_G(); + INIT_PAGESIZE(); get_terminal_width_height(-1, NULL, &G.height); if (1) { @@ -263,7 +282,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) bb_signals(BB_FATAL_SIGS, sig_catcher); remap(0); - redraw(); + redraw(0); //TODO: //Home/End: start/end of line; '<'/'>': start/end of file //Backspace: undo @@ -411,26 +430,27 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) { char buf[sizeof(G.offset)*3 + 4]; printf(ESC"[999;1H" CLEAR_TILL_EOL); /* go to last line */ - if (read_line_input(NULL, "Go to (dec,0Xhex,0oct): ", buf, sizeof(buf)) >= 0) { + if (read_line_input(NULL, "Go to (dec,0Xhex,0oct): ", buf, sizeof(buf)) > 0) { off_t t; unsigned pgmask; t = bb_strtoull(buf, NULL, 0); if (t >= G.size) t = G.size - 1; - pgmask = getpagesize() - 1; + pgmask = G_pagesize - 1; cnt = t & pgmask; t = t & ~(off_t)pgmask; if (t < 0) cnt = t = 0; + if (t != 0 && cnt < 0x1ff) { + /* very close to end of page, possibly to EOF */ + /* move one page lower */ + t -= G_pagesize; + cnt += G_pagesize; + } G.offset = t; - remap(cnt & 0xf); - redraw(); - if (cnt & 0xf) - printf(ESC"[%uC", (cnt & 0xf) * 3); /* cursor right 3*i */ - cnt >>= 4; - if (cnt) - goto k_down; + remap(cnt); + redraw(cnt); break; } /* EOF/error on input: fall through to exiting */ -- cgit v1.2.3-55-g6feb From e58b44755dbac7c55bf602f7f76dfb37b47323f5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 15 Sep 2017 15:23:47 +0200 Subject: hexedit: code shrink function old new delta hexedit_main 1171 1170 -1 Signed-off-by: Denys Vlasenko --- miscutils/hexedit.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index 8334181c7..bafb834b5 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -432,28 +432,27 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) printf(ESC"[999;1H" CLEAR_TILL_EOL); /* go to last line */ if (read_line_input(NULL, "Go to (dec,0Xhex,0oct): ", buf, sizeof(buf)) > 0) { off_t t; - unsigned pgmask; + unsigned cursor; t = bb_strtoull(buf, NULL, 0); if (t >= G.size) t = G.size - 1; - pgmask = G_pagesize - 1; - cnt = t & pgmask; - t = t & ~(off_t)pgmask; + cursor = t & (G_pagesize - 1); + t -= cursor; if (t < 0) - cnt = t = 0; - if (t != 0 && cnt < 0x1ff) { + cursor = t = 0; + if (t != 0 && cursor < 0x1ff) { /* very close to end of page, possibly to EOF */ /* move one page lower */ t -= G_pagesize; - cnt += G_pagesize; + cursor += G_pagesize; } G.offset = t; - remap(cnt); - redraw(cnt); + remap(cursor); + redraw(cursor); break; } - /* EOF/error on input: fall through to exiting */ + /* ^C/EOF/error: fall through to exiting */ } case CTRL('X'): restore_term(); -- cgit v1.2.3-55-g6feb From aaaaaa5ad6a93101d38800467fe3750b35fed6ea Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 15 Sep 2017 17:14:01 +0200 Subject: less,microcom,lineedit: use common routine to set raw termios function old new delta get_termios_and_make_raw - 139 +139 xget1 39 8 -31 read_line_input 3912 3867 -45 less_main 2525 2471 -54 set_termios_to_raw 116 36 -80 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/4 up/down: 139/-210) Total: -71 bytes Signed-off-by: Denys Vlasenko --- include/libbb.h | 1 + libbb/lineedit.c | 21 +++++--------------- libbb/xfuncs.c | 55 ++++++++++++++++++++++++++++++++++++++-------------- miscutils/less.c | 12 +++--------- miscutils/microcom.c | 14 +++++-------- 5 files changed, 54 insertions(+), 49 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 06f887732..aff2825ac 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1582,6 +1582,7 @@ int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC; #define TERMIOS_CLEAR_ISIG (1 << 0) #define TERMIOS_RAW_CRNL (1 << 1) #define TERMIOS_RAW_INPUT (1 << 2) +int get_termios_and_make_raw(int fd, struct termios *newterm, struct termios *oldterm, int flags) FAST_FUNC; int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC; /* NB: "unsigned request" is crucial! "int request" will break some arches! */ diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 17766a126..3a092ffe2 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2259,7 +2259,7 @@ static int32_t reverse_i_search(int timeout) */ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize) { - int len; + int len, n; int timeout; #if ENABLE_FEATURE_TAB_COMPLETION smallint lastWasTab = 0; @@ -2274,9 +2274,10 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman INIT_S(); - if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 - || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON - ) { + n = get_termios_and_make_raw(STDIN_FILENO, &new_settings, &initial_settings, 0 + | TERMIOS_CLEAR_ISIG /* turn off INTR (ctrl-C), QUIT, SUSP */ + ); + if (n != 0 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON) { /* Happens when e.g. stty -echo was run before. * But if ICANON is not set, we don't come here. * (example: interactive python ^Z-backgrounded, @@ -2329,18 +2330,6 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman #endif #define command command_must_not_be_used - new_settings = initial_settings; - /* ~ICANON: unbuffered input (most c_cc[] are disabled, VMIN/VTIME are enabled) */ - /* ~ECHO, ~ECHONL: turn off echoing, including newline echoing */ - /* ~ISIG: turn off INTR (ctrl-C), QUIT, SUSP */ - new_settings.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG); - /* reads will block only if < 1 char is available */ - new_settings.c_cc[VMIN] = 1; - /* no timeout (reads block forever) */ - new_settings.c_cc[VTIME] = 0; - /* Should be not needed if ISIG is off: */ - /* Turn off CTRL-C */ - /* new_settings.c_cc[VINTR] = _POSIX_VDISABLE; */ tcsetattr_stdin_TCSANOW(&new_settings); #if ENABLE_USERNAME_OR_HOMEDIR diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 1b3a1667b..d7647704e 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -311,40 +311,65 @@ int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) return tcsetattr(STDIN_FILENO, TCSANOW, tp); } -int FAST_FUNC set_termios_to_raw(int fd, struct termios *oldterm, int flags) +int FAST_FUNC get_termios_and_make_raw(int fd, struct termios *newterm, struct termios *oldterm, int flags) { -//TODO: lineedit, microcom, slattach, less might be adapted to use this too: -// grep for "tcsetattr" - - struct termios newterm; +//TODO: slattach, shell read might be adapted to use this too: grep for "tcsetattr", "[VTIME] = 0" + int r; - tcgetattr(fd, oldterm); - newterm = *oldterm; + memset(oldterm, 0, sizeof(*oldterm)); /* paranoia */ + r = tcgetattr(fd, oldterm); + *newterm = *oldterm; /* Turn off buffered input (ICANON) * Turn off echoing (ECHO) * and separate echoing of newline (ECHONL, normally off anyway) */ - newterm.c_lflag &= ~(ICANON | ECHO | ECHONL); + newterm->c_lflag &= ~(ICANON | ECHO | ECHONL); if (flags & TERMIOS_CLEAR_ISIG) { /* dont recognize INT/QUIT/SUSP chars */ - newterm.c_lflag &= ~ISIG; + newterm->c_lflag &= ~ISIG; } /* reads will block only if < 1 char is available */ - newterm.c_cc[VMIN] = 1; + newterm->c_cc[VMIN] = 1; /* no timeout (reads block forever) */ - newterm.c_cc[VTIME] = 0; + newterm->c_cc[VTIME] = 0; if (flags & TERMIOS_RAW_CRNL) { +/* IXON, IXOFF, and IXANY: + * IXOFF=1: sw flow control is enabled on input queue: + * tty transmits a STOP char when input queue is close to full + * and transmits a START char when input queue is nearly empty. + * IXON=1: sw flow control is enabled on output queue: + * tty will stop sending if STOP char is received, + * and resume sending if START is received, or if any char + * is received and IXANY=1. + */ + /* IXON=0: XON/XOFF chars are treated as normal chars (why we do this?) */ /* dont convert CR to NL on input */ - newterm.c_iflag &= ~(IXON | ICRNL); - /* dont convert NL to CR on output */ - newterm.c_oflag &= ~(ONLCR); + newterm->c_iflag &= ~(IXON | ICRNL); + /* dont convert NL to CR+NL on output */ + newterm->c_oflag &= ~(ONLCR); + /* Maybe clear more c_oflag bits? usually, only OPOST and ONLCR are set. + * OPOST Enable implementation-defined output processing (is this reqd for all other bits to work?) + * OLCUC Map lowercase characters to uppercase on output. + * OCRNL Map CR to NL on output. + * ONOCR Don't output CR at column 0. + * ONLRET Don't output CR. + */ } if (flags & TERMIOS_RAW_INPUT) { + /* IXOFF=0: disable sending XON/XOFF if input buf is full */ + /* IXON=0: XON/XOFF chars are treated as normal chars */ /* dont convert anything on input */ - newterm.c_iflag &= ~(BRKINT|INLCR|ICRNL|IXON|IXOFF|IUCLC|IXANY|IMAXBEL); + newterm->c_iflag &= ~(IXOFF|IXON|IXANY|BRKINT|INLCR|ICRNL|IUCLC|IMAXBEL); } + return r; +} + +int FAST_FUNC set_termios_to_raw(int fd, struct termios *oldterm, int flags) +{ + struct termios newterm; + get_termios_and_make_raw(fd, &newterm, oldterm, flags); return tcsetattr(fd, TCSANOW, &newterm); } diff --git a/miscutils/less.c b/miscutils/less.c index d524b6c87..c6c158a51 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -1824,15 +1824,9 @@ int less_main(int argc, char **argv) G.kbd_fd_orig_flags = ndelay_on(tty_fd); kbd_fd = tty_fd; /* save in a global */ - tcgetattr(kbd_fd, &term_orig); - term_less = term_orig; - term_less.c_lflag &= ~(ICANON | ECHO); - term_less.c_iflag &= ~(IXON | ICRNL); - /*term_less.c_oflag &= ~ONLCR;*/ - term_less.c_cc[VMIN] = 1; - term_less.c_cc[VTIME] = 0; - - IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line); + get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL); + + IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line); /* 20: two tabstops + 4 */ if (width < 20 || max_displayed_line < 3) return bb_cat(argv); diff --git a/miscutils/microcom.c b/miscutils/microcom.c index b87f3273f..fa090057e 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c @@ -33,15 +33,11 @@ // set raw tty mode static void xget1(int fd, struct termios *t, struct termios *oldt) { -//TODO: use set_termios_to_raw() - tcgetattr(fd, oldt); - *t = *oldt; - cfmakeraw(t); -// t->c_lflag &= ~(ISIG|ICANON|ECHO|IEXTEN); -// t->c_iflag &= ~(BRKINT|IXON|ICRNL); -// t->c_oflag &= ~(ONLCR); -// t->c_cc[VMIN] = 1; -// t->c_cc[VTIME] = 0; + get_termios_and_make_raw(fd, t, oldt, 0 + | TERMIOS_CLEAR_ISIG /* ^C is ASCII char 3, not "interrupt me!" */ + | TERMIOS_RAW_INPUT /* pass all chars verbatim, no special handling or translating CR->NL */ + | TERMIOS_RAW_CRNL /* dont convert NL<->CR on output too */ + ); } static int xset1(int fd, struct termios *tio, const char *device) -- cgit v1.2.3-55-g6feb From 7735e52df440411ccaeb5df2824e5ba1ce4c161e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 15 Sep 2017 17:19:55 +0200 Subject: Clarify OPOST bit meaning Signed-off-by: Denys Vlasenko --- libbb/xfuncs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index d7647704e..0dfb3e2d9 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -348,8 +348,8 @@ int FAST_FUNC get_termios_and_make_raw(int fd, struct termios *newterm, struct t newterm->c_iflag &= ~(IXON | ICRNL); /* dont convert NL to CR+NL on output */ newterm->c_oflag &= ~(ONLCR); - /* Maybe clear more c_oflag bits? usually, only OPOST and ONLCR are set. - * OPOST Enable implementation-defined output processing (is this reqd for all other bits to work?) + /* Maybe clear more c_oflag bits? Usually, only OPOST and ONLCR are set. + * OPOST Enable output processing (reqd for OLCUC and *NL* bits to work) * OLCUC Map lowercase characters to uppercase on output. * OCRNL Map CR to NL on output. * ONOCR Don't output CR at column 0. @@ -358,7 +358,7 @@ int FAST_FUNC get_termios_and_make_raw(int fd, struct termios *newterm, struct t } if (flags & TERMIOS_RAW_INPUT) { /* IXOFF=0: disable sending XON/XOFF if input buf is full */ - /* IXON=0: XON/XOFF chars are treated as normal chars */ + /* IXON=0: input XON/XOFF chars are not special */ /* dont convert anything on input */ newterm->c_iflag &= ~(IXOFF|IXON|IXANY|BRKINT|INLCR|ICRNL|IUCLC|IMAXBEL); } -- cgit v1.2.3-55-g6feb From 3c34f681b35233afb7f932154e72f3eb2b335b47 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 15 Sep 2017 18:55:53 +0200 Subject: netcat: net applet (alias to nc) function old new delta packed_usage 31807 31856 +49 applet_names 2701 2708 +7 applet_main 1560 1564 +4 applet_install_loc 195 196 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 61/0) Total: 61 bytes Signed-off-by: Denys Vlasenko --- networking/nc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/networking/nc.c b/networking/nc.c index a13d77a00..f7fc9741f 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -13,17 +13,23 @@ //config: A simple Unix utility which reads and writes data across network //config: connections. //config: +//config:config NETCAT +//config: bool "netcat (11 kb)" +//config: default n +//config: help +//config: Alias to nc. +//config: //config:config NC_SERVER //config: bool "Netcat server options (-l)" //config: default y -//config: depends on NC +//config: depends on NC || NETCAT //config: help //config: Allow netcat to act as a server. //config: //config:config NC_EXTRA //config: bool "Netcat extensions (-eiw and -f FILE)" //config: default y -//config: depends on NC +//config: depends on NC || NETCAT //config: help //config: Add -e (support for executing the rest of the command line after //config: making or receiving a successful connection), -i (delay interval for @@ -31,8 +37,8 @@ //config: //config:config NC_110_COMPAT //config: bool "Netcat 1.10 compatibility (+2.5k)" -//config: default n # off specially for Rob -//config: depends on NC +//config: default y +//config: depends on NC || NETCAT //config: help //config: This option makes nc closely follow original nc-1.10. //config: The code is about 2.5k bigger. It enables @@ -40,8 +46,11 @@ //config: busybox-specific extensions: -f FILE. //applet:IF_NC(APPLET(nc, BB_DIR_USR_BIN, BB_SUID_DROP)) +// APPLET_ODDNAME:name main location suid_type help +//applet:IF_NETCAT(APPLET_ODDNAME(netcat, nc, BB_DIR_USR_BIN, BB_SUID_DROP, nc)) //kbuild:lib-$(CONFIG_NC) += nc.o +//kbuild:lib-$(CONFIG_NETCAT) += nc.o #include "libbb.h" #include "common_bufsiz.h" -- cgit v1.2.3-55-g6feb From 3f5ba0c8724d154c9f184fad458471490a4ef5b3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 18 Sep 2017 12:16:47 +0200 Subject: stty: add cmspar, flusho, extproc attributes function old new delta mode_info 688 704 +16 mode_name 502 516 +14 wrapf 162 157 -5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 30/-5) Total: 25 bytes Signed-off-by: Denys Vlasenko --- coreutils/stty.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/coreutils/stty.c b/coreutils/stty.c index 57e2cc30d..b6e836364 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c @@ -148,6 +148,9 @@ #ifndef CRDLY # define CRDLY 0 #endif +#ifndef CMSPAR +# define CMSPAR 0 +#endif #ifndef CRTSCTS # define CRTSCTS 0 #endif @@ -352,6 +355,9 @@ static const char mode_name[] ALIGN1 = #endif MI_ENTRY("parenb", control, REV, PARENB, 0 ) MI_ENTRY("parodd", control, REV, PARODD, 0 ) +#if CMSPAR + MI_ENTRY("cmspar", control, REV, CMSPAR, 0 ) +#endif MI_ENTRY("cs5", control, 0, CS5, CSIZE) MI_ENTRY("cs6", control, 0, CS6, CSIZE) MI_ENTRY("cs7", control, 0, CS7, CSIZE) @@ -476,6 +482,10 @@ static const char mode_name[] ALIGN1 = #if ECHOKE MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) MI_ENTRY("crtkill", local, OMIT | REV, ECHOKE, 0 ) +#endif + MI_ENTRY("flusho", local, SANE_UNSET | REV, FLUSHO, 0 ) +#ifdef EXTPROC + MI_ENTRY("extproc", local, SANE_UNSET | REV, EXTPROC, 0 ) #endif ; @@ -509,6 +519,9 @@ static const struct mode_info mode_info[] = { #endif MI_ENTRY("parenb", control, REV, PARENB, 0 ) MI_ENTRY("parodd", control, REV, PARODD, 0 ) +#if CMSPAR + MI_ENTRY("cmspar", control, REV, CMSPAR, 0 ) +#endif MI_ENTRY("cs5", control, 0, CS5, CSIZE) MI_ENTRY("cs6", control, 0, CS6, CSIZE) MI_ENTRY("cs7", control, 0, CS7, CSIZE) @@ -633,6 +646,10 @@ static const struct mode_info mode_info[] = { #if ECHOKE MI_ENTRY("echoke", local, SANE_SET | REV, ECHOKE, 0 ) MI_ENTRY("crtkill", local, OMIT | REV, ECHOKE, 0 ) +#endif + MI_ENTRY("flusho", local, SANE_UNSET | REV, FLUSHO, 0 ) +#ifdef EXTPROC + MI_ENTRY("extproc", local, SANE_UNSET | REV, EXTPROC, 0 ) #endif }; @@ -836,10 +853,11 @@ static void wrapf(const char *message, ...) G.current_col++; if (buf[0] != '\n') { if (G.current_col + buflen >= G.max_col) { - bb_putchar('\n'); G.current_col = 0; - } else + bb_putchar('\n'); + } else { bb_putchar(' '); + } } } fputs(buf, stdout); -- cgit v1.2.3-55-g6feb From a6390ed77ea67937c91d8100f3c7ce7c5bce2402 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 18 Sep 2017 13:09:11 +0200 Subject: httpd: fix handling of range requests Signed-off-by: Denys Vlasenko --- networking/httpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/httpd.c b/networking/httpd.c index c82383507..74196a4f1 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -2338,7 +2338,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) if (STRNCASECMP(iobuf, "Range:") == 0) { /* We know only bytes=NNN-[MMM] */ char *s = skip_whitespace(iobuf + sizeof("Range:")-1); - if (is_prefixed_with(s, "bytes=") == 0) { + if (is_prefixed_with(s, "bytes=")) { s += sizeof("bytes=")-1; range_start = BB_STRTOOFF(s, &s, 10); if (s[0] != '-' || range_start < 0) { -- cgit v1.2.3-55-g6feb From c3e60e1e9a66b45794e04e9a0a39d1c012780930 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 18 Sep 2017 14:34:15 +0200 Subject: update NOFORK_NOEXEC.lst Signed-off-by: Denys Vlasenko --- NOFORK_NOEXEC.lst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NOFORK_NOEXEC.lst b/NOFORK_NOEXEC.lst index 3070a321b..e787a346d 100644 --- a/NOFORK_NOEXEC.lst +++ b/NOFORK_NOEXEC.lst @@ -166,6 +166,7 @@ hd - noexec. runner hdparm - hardware head - noexec. runner hexdump - noexec. runner +hexedit - interactive, longterm hostid - NOFORK hostname - noexec. talks to network (hostname -d may query DNS) httpd - daemon @@ -235,6 +236,7 @@ md5sum - noexec. runner mdev - daemon mesg - NOFORK microcom - interactive, longterm +minips - noexec mkdir - NOFORK mkdosfs - needs ^C mke2fs - needs ^C @@ -264,6 +266,7 @@ nmeter - longterm nohup - noexec. spawner nproc - NOFORK ntpd - daemon +nuke - noexec od - runner openvt - longterm: spawns a child and waits for it partprobe - noexec. leaks: open+ioctl_or_perror_and_die(BLKRRPART) @@ -300,6 +303,7 @@ remove-shell - noexec. leaks: open+xfunc renice - noexec. nofork candidate(uses getpwnam, is that ok?) reset - noexec. spawner (execs "stty") resize - noexec. changes state (signal handlers) +resume - noexec rev - runner rm - noexec. rm -i interactive rmdir - NOFORK @@ -308,6 +312,7 @@ route - talks to network (may query DNS to convert IPs to names) rpm - runner rpm2cpio - runner rtcwake - longterm: puts system to sleep, optimizing this for speed is pointless +run-init - spawner, rare, changes state (oh yes), execing may be important to free binary's inode run-parts - longterm runlevel - noexec. can be nofork if "endutxent()" is called unconditionally, but too rare to bother? runsv - daemon @@ -320,6 +325,7 @@ sendmail - runner seq - noexec. runner setarch - noexec. spawner setconsole - noexec +setfattr - noexec setfont - noexec. leaks a lot of stuff setkeycodes - noexec setlogcons - noexec -- cgit v1.2.3-55-g6feb From b63afead4411c5832d427ed149683c85cc81a4c9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 18 Sep 2017 15:45:13 +0200 Subject: ip,ip*: make them NOEXEC Signed-off-by: Denys Vlasenko --- NOFORK_NOEXEC.lst | 14 +++++++------- networking/ip.c | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/NOFORK_NOEXEC.lst b/NOFORK_NOEXEC.lst index e787a346d..4e53d7204 100644 --- a/NOFORK_NOEXEC.lst +++ b/NOFORK_NOEXEC.lst @@ -187,16 +187,16 @@ insmod - noexec install - runner ionice - noexec. spawner iostat - longterm: "iostat 1" runs indefinitely -ip - noexec candidate -ipaddr - noexec candidate +ip - noexec +ipaddr - noexec ipcalc - noexec. ipcalc -h talks to network ipcrm - noexec ipcs - noexec -iplink - noexec candidate -ipneigh - noexec candidate -iproute - noexec candidate -iprule - noexec candidate -iptunnel - noexec candidate +iplink - noexec +ipneigh - noexec +iproute - noexec +iprule - noexec +iptunnel - noexec kbd_mode - noexec. leaks: xopen_nonblocking+xioctl kill - NOFORK killall - NOFORK diff --git a/networking/ip.c b/networking/ip.c index 8aaeef0db..0bc0edc57 100644 --- a/networking/ip.c +++ b/networking/ip.c @@ -126,13 +126,13 @@ //config: Ethernet, wireless, infrared, ppp/slip, ip tunnelling //config: link types are supported without this option selected. -//applet:IF_IP(APPLET(ip, BB_DIR_SBIN, BB_SUID_DROP)) -//applet:IF_IPADDR(APPLET(ipaddr, BB_DIR_SBIN, BB_SUID_DROP)) -//applet:IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP)) -//applet:IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP)) -//applet:IF_IPRULE(APPLET(iprule, BB_DIR_SBIN, BB_SUID_DROP)) -//applet:IF_IPTUNNEL(APPLET(iptunnel, BB_DIR_SBIN, BB_SUID_DROP)) -//applet:IF_IPNEIGH(APPLET(ipneigh, BB_DIR_SBIN, BB_SUID_DROP)) +//applet:IF_IP( APPLET_NOEXEC(ip , ip , BB_DIR_SBIN, BB_SUID_DROP, ip )) +//applet:IF_IPADDR( APPLET_NOEXEC(ipaddr , ipaddr , BB_DIR_SBIN, BB_SUID_DROP, ipaddr )) +//applet:IF_IPLINK( APPLET_NOEXEC(iplink , iplink , BB_DIR_SBIN, BB_SUID_DROP, iplink )) +//applet:IF_IPROUTE( APPLET_NOEXEC(iproute , iproute , BB_DIR_SBIN, BB_SUID_DROP, iproute )) +//applet:IF_IPRULE( APPLET_NOEXEC(iprule , iprule , BB_DIR_SBIN, BB_SUID_DROP, iprule )) +//applet:IF_IPTUNNEL(APPLET_NOEXEC(iptunnel, iptunnel, BB_DIR_SBIN, BB_SUID_DROP, iptunnel)) +//applet:IF_IPNEIGH( APPLET_NOEXEC(ipneigh , ipneigh , BB_DIR_SBIN, BB_SUID_DROP, ipneigh )) //kbuild:lib-$(CONFIG_IP) += ip.o //kbuild:lib-$(CONFIG_IPADDR) += ip.o -- cgit v1.2.3-55-g6feb From 0c4dbd481aedb5d22c1048e7f7eb547a3b5e50a5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 18 Sep 2017 16:28:43 +0200 Subject: regularize format of source file headers, no code changes Signed-off-by: Denys Vlasenko --- archival/ar.c | 2 +- archival/bbunzip.c | 6 ++--- archival/bzip2.c | 2 +- archival/cpio.c | 9 ++++--- archival/dpkg.c | 2 +- archival/dpkg_deb.c | 1 - archival/gzip.c | 2 +- archival/lzop.c | 2 +- archival/tar.c | 2 +- console-tools/dumpkmap.c | 1 - console-tools/reset.c | 4 +-- coreutils/printf.c | 1 - coreutils/shuf.c | 4 +-- editors/awk.c | 1 - editors/cmp.c | 11 ++++---- editors/diff.c | 6 ++--- editors/patch.c | 1 - editors/sed.c | 7 ++--- editors/vi.c | 2 -- findutils/find.c | 3 --- findutils/grep.c | 1 - init/bootchartd.c | 9 +++---- init/halt.c | 1 - init/init.c | 1 - libbb/u_signal_names.c | 1 - loginutils/addgroup.c | 1 - miscutils/beep.c | 1 - miscutils/less.c | 2 -- miscutils/nandwrite.c | 1 - miscutils/raidautorun.c | 1 - miscutils/rfkill.c | 13 +++++---- miscutils/setserial.c | 1 - miscutils/ubi_tools.c | 1 - networking/hostname.c | 1 - networking/ifupdown.c | 1 - networking/nameif.c | 1 - networking/nbd-client.c | 16 +++++------ networking/ping.c | 43 +++++++++++++++--------------- networking/udhcp/d6_dhcpc.c | 1 - networking/vconfig.c | 5 ++-- networking/wget.c | 1 - networking/whois.c | 1 - procps/iostat.c | 1 - procps/lsof.c | 1 - procps/mpstat.c | 11 ++++---- procps/nmeter.c | 1 - procps/pmap.c | 2 +- procps/pwdx.c | 1 - procps/smemcap.c | 9 +++---- procps/watch.c | 7 +++-- runit/svlogd.c | 1 - shell/cttyhack.c | 12 ++++----- util-linux/fallocate.c | 1 - util-linux/fsfreeze.c | 1 - util-linux/fstrim.c | 1 - util-linux/mdev.c | 1 - util-linux/mesg.c | 1 - util-linux/nsenter.c | 1 - util-linux/rdev.c | 1 - util-linux/taskset.c | 2 +- util-linux/volume_id/bcache.c | 5 ++-- util-linux/volume_id/btrfs.c | 5 ++-- util-linux/volume_id/cramfs.c | 5 ++-- util-linux/volume_id/exfat.c | 5 ++-- util-linux/volume_id/ext.c | 5 ++-- util-linux/volume_id/f2fs.c | 5 ++-- util-linux/volume_id/fat.c | 5 ++-- util-linux/volume_id/hfs.c | 5 ++-- util-linux/volume_id/iso9660.c | 5 ++-- util-linux/volume_id/jfs.c | 5 ++-- util-linux/volume_id/linux_raid.c | 5 ++-- util-linux/volume_id/linux_swap.c | 5 ++-- util-linux/volume_id/luks.c | 5 ++-- util-linux/volume_id/nilfs.c | 5 ++-- util-linux/volume_id/ntfs.c | 5 ++-- util-linux/volume_id/ocfs2.c | 5 ++-- util-linux/volume_id/reiserfs.c | 5 ++-- util-linux/volume_id/romfs.c | 5 ++-- util-linux/volume_id/squashfs.c | 5 ++-- util-linux/volume_id/sysv.c | 5 ++-- util-linux/volume_id/ubifs.c | 5 ++-- util-linux/volume_id/udf.c | 5 ++-- util-linux/volume_id/unused_highpoint.c | 5 ++-- util-linux/volume_id/unused_hpfs.c | 5 ++-- util-linux/volume_id/unused_isw_raid.c | 5 ++-- util-linux/volume_id/unused_lsi_raid.c | 5 ++-- util-linux/volume_id/unused_lvm.c | 5 ++-- util-linux/volume_id/unused_mac.c | 5 ++-- util-linux/volume_id/unused_msdos.c | 5 ++-- util-linux/volume_id/unused_nvidia_raid.c | 5 ++-- util-linux/volume_id/unused_promise_raid.c | 5 ++-- util-linux/volume_id/unused_silicon_raid.c | 5 ++-- util-linux/volume_id/unused_ufs.c | 5 ++-- util-linux/volume_id/unused_via_raid.c | 5 ++-- util-linux/volume_id/xfs.c | 5 ++-- util-linux/wall.c | 1 - 96 files changed, 158 insertions(+), 246 deletions(-) diff --git a/archival/ar.c b/archival/ar.c index 027cd6b5a..f4edeb087 100644 --- a/archival/ar.c +++ b/archival/ar.c @@ -16,7 +16,6 @@ * between different systems * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html */ - //config:config AR //config: bool "ar (9.5 kb)" //config: default n # needs to be improved to be able to replace binutils ar @@ -46,6 +45,7 @@ //config: This enables archive creation (-c and -r) with busybox ar. //applet:IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP)) + //kbuild:lib-$(CONFIG_AR) += ar.o //usage:#define ar_trivial_usage diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 20ab893da..944b397b3 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -4,9 +4,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -#include "libbb.h" -#include "bb_archive.h" - //kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o //kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o //kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o @@ -21,6 +18,9 @@ /* gzip_main() too: */ //kbuild:lib-$(CONFIG_GZIP) += bbunzip.o +#include "libbb.h" +#include "bb_archive.h" + /* Note: must be kept in sync with archival/lzop.c */ enum { OPT_STDOUT = 1 << 0, diff --git a/archival/bzip2.c b/archival/bzip2.c index d578eb7ad..d6fd9296d 100644 --- a/archival/bzip2.c +++ b/archival/bzip2.c @@ -6,7 +6,6 @@ * See README and LICENSE files in bz/ directory for more information * about bzip2 library code. */ - //config:config BZIP2 //config: bool "bzip2 (18 kb)" //config: default y @@ -30,6 +29,7 @@ //config: enabled. //applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) + //kbuild:lib-$(CONFIG_BZIP2) += bzip2.o //usage:#define bzip2_trivial_usage diff --git a/archival/cpio.c b/archival/cpio.c index f2165be3a..1d6cbd1e2 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -10,10 +10,6 @@ * Doesn't check CRC's * Only supports new ASCII and CRC formats */ -#include "libbb.h" -#include "common_bufsiz.h" -#include "bb_archive.h" - //config:config CPIO //config: bool "cpio (14 kb)" //config: default y @@ -44,6 +40,7 @@ //config: Passthrough mode. Rarely used. //applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP)) + //kbuild:lib-$(CONFIG_CPIO) += cpio.o //usage:#define cpio_trivial_usage @@ -142,6 +139,10 @@ -u, --unconditional Replace all files unconditionally */ +#include "libbb.h" +#include "common_bufsiz.h" +#include "bb_archive.h" + enum { OPT_EXTRACT = (1 << 0), OPT_TEST = (1 << 1), diff --git a/archival/dpkg.c b/archival/dpkg.c index 852e0cac2..58bc4dba3 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -25,7 +25,6 @@ * bugs that need to be fixed * - (unknown, please let me know when you find any) */ - //config:config DPKG //config: bool "dpkg (44 kb)" //config: default y @@ -38,6 +37,7 @@ //config: you should use the official dpkg if possible. //applet:IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP)) + //kbuild:lib-$(CONFIG_DPKG) += dpkg.o //usage:#define dpkg_trivial_usage diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index f6bf9eb04..dc4738d28 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config DPKG_DEB //config: bool "dpkg_deb" //config: default y diff --git a/archival/gzip.c b/archival/gzip.c index 9c53895e9..ac6633044 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -36,7 +36,6 @@ a: 85.1% -- replaced with a.gz gzip: bogus: No such file or directory aa: 85.1% -- replaced with aa.gz */ - //config:config GZIP //config: bool "gzip (19 kb)" //config: default y @@ -81,6 +80,7 @@ aa: 85.1% -- replaced with aa.gz //config: enabled. //applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) + //kbuild:lib-$(CONFIG_GZIP) += gzip.o //usage:#define gzip_trivial_usage diff --git a/archival/lzop.c b/archival/lzop.c index 1bf954f4f..92411c23f 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -24,7 +24,6 @@ "Minimalized" for busybox by Alain Knaff */ - //config:config LZOP //config: bool "lzop (13 kb)" //config: default y @@ -56,6 +55,7 @@ // APPLET_ODDNAME:name main location suid_type help //applet:IF_UNLZOP( APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop)) //applet:IF_LZOPCAT(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat)) + //kbuild:lib-$(CONFIG_LZOP) += lzop.o //kbuild:lib-$(CONFIG_UNLZOP) += lzop.o //kbuild:lib-$(CONFIG_LZOPCAT) += lzop.o diff --git a/archival/tar.c b/archival/tar.c index 6cf3508ec..b6d5129d8 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -22,7 +22,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config TAR //config: bool "tar (40 kb)" //config: default y @@ -113,6 +112,7 @@ //config: when extracting files from tar archives. //applet:IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP)) + //kbuild:lib-$(CONFIG_TAR) += tar.o #include diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c index b803e579a..f1c9287b5 100644 --- a/console-tools/dumpkmap.c +++ b/console-tools/dumpkmap.c @@ -5,7 +5,6 @@ * Copyright (C) Arne Bernin * * Licensed under GPLv2 or later, see file LICENSE in this source tree. - * */ //config:config DUMPKMAP //config: bool "dumpkmap (1.3 kb)" diff --git a/console-tools/reset.c b/console-tools/reset.c index 471ef9158..614806ba7 100644 --- a/console-tools/reset.c +++ b/console-tools/reset.c @@ -7,8 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -/* "Standard" version of this tool is in ncurses package */ - //config:config RESET //config: bool "reset (275 bytes)" //config: default y @@ -25,6 +23,8 @@ //usage:#define reset_full_usage "\n\n" //usage: "Reset the screen" +/* "Standard" version of this tool is in ncurses package */ + #include "libbb.h" #define ESC "\033" diff --git a/coreutils/printf.c b/coreutils/printf.c index d1ff183d0..353cfc608 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -48,7 +48,6 @@ //applet:IF_PRINTF(APPLET_NOFORK(printf, printf, BB_DIR_USR_BIN, BB_SUID_DROP, printf)) //kbuild:lib-$(CONFIG_PRINTF) += printf.o - //kbuild:lib-$(CONFIG_ASH_PRINTF) += printf.o //kbuild:lib-$(CONFIG_HUSH_PRINTF) += printf.o diff --git a/coreutils/shuf.c b/coreutils/shuf.c index d0caaa2ce..fdbd3e9b2 100644 --- a/coreutils/shuf.c +++ b/coreutils/shuf.c @@ -6,16 +6,16 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config SHUF //config: bool "shuf (5.4 kb)" //config: default y //config: help //config: Generate random permutations -//kbuild:lib-$(CONFIG_SHUF) += shuf.o //applet:IF_SHUF(APPLET_NOEXEC(shuf, shuf, BB_DIR_USR_BIN, BB_SUID_DROP, shuf)) +//kbuild:lib-$(CONFIG_SHUF) += shuf.o + //usage:#define shuf_trivial_usage //usage: "[-e|-i L-H] [-n NUM] [-o FILE] [-z] [FILE|ARG...]" //usage:#define shuf_full_usage "\n\n" diff --git a/editors/awk.c b/editors/awk.c index 2005329ad..d40c7816a 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config AWK //config: bool "awk (22 kb)" //config: default y diff --git a/editors/cmp.c b/editors/cmp.c index ec86c0ce2..2a410fdec 100644 --- a/editors/cmp.c +++ b/editors/cmp.c @@ -6,10 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -/* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */ -/* http://www.opengroup.org/onlinepubs/007904975/utilities/cmp.html */ - //config:config CMP //config: bool "cmp (5.4 kb)" //config: default y @@ -17,10 +13,10 @@ //config: cmp is used to compare two files and returns the result //config: to standard output. -//kbuild:lib-$(CONFIG_CMP) += cmp.o - //applet:IF_CMP(APPLET(cmp, BB_DIR_USR_BIN, BB_SUID_DROP)) +//kbuild:lib-$(CONFIG_CMP) += cmp.o + //usage:#define cmp_trivial_usage //usage: "[-l] [-s] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]" //usage:#define cmp_full_usage "\n\n" @@ -29,6 +25,9 @@ //usage: "\n for all differing bytes" //usage: "\n -s Quiet" +/* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */ +/* http://www.opengroup.org/onlinepubs/007904975/utilities/cmp.html */ + #include "libbb.h" static const char fmt_eof[] ALIGN1 = "cmp: EOF on %s\n"; diff --git a/editors/diff.c b/editors/diff.c index 2f254575c..1462a9b18 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -12,7 +12,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* * The following code uses an algorithm due to Harold Stone, * which finds a pair of longest identical subsequences in @@ -75,7 +74,6 @@ * 3*(number of k-candidates installed), typically about * 6n words for files of length n. */ - //config:config DIFF //config: bool "diff (13 kb)" //config: default y @@ -97,10 +95,10 @@ //config: This option enables support for directory and subdirectory //config: comparison. -//kbuild:lib-$(CONFIG_DIFF) += diff.o - //applet:IF_DIFF(APPLET(diff, BB_DIR_USR_BIN, BB_SUID_DROP)) +//kbuild:lib-$(CONFIG_DIFF) += diff.o + //usage:#define diff_trivial_usage //usage: "[-abBdiNqrTstw] [-L LABEL] [-S FILE] [-U LINES] FILE1 FILE2" //usage:#define diff_full_usage "\n\n" diff --git a/editors/patch.c b/editors/patch.c index 81316fae3..a51b7a502 100644 --- a/editors/patch.c +++ b/editors/patch.c @@ -21,7 +21,6 @@ * -F fuzz (number, default 2) * [file] which file to patch */ - //config:config PATCH //config: bool "patch (9.1 kb)" //config: default y diff --git a/editors/sed.c b/editors/sed.c index 7ed9937d2..9d800c2c3 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -12,7 +12,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - /* Code overview. * * Files are laid out to avoid unnecessary function declarations. So for @@ -29,7 +28,6 @@ * * sed_main() is where external code calls into this, with a command line. */ - /* Supported features and commands in this version of sed: * * - comments ('#') @@ -55,7 +53,6 @@ * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html * http://sed.sourceforge.net/sedfaq3.html */ - //config:config SED //config: bool "sed (12 kb)" //config: default y @@ -63,10 +60,10 @@ //config: sed is used to perform text transformations on a file //config: or input from a pipeline. -//kbuild:lib-$(CONFIG_SED) += sed.o - //applet:IF_SED(APPLET(sed, BB_DIR_BIN, BB_SUID_DROP)) +//kbuild:lib-$(CONFIG_SED) += sed.o + //usage:#define sed_trivial_usage //usage: "[-i[SFX]] [-nrE] [-f FILE]... [-e CMD]... [FILE]...\n" //usage: "or: sed [-i[SFX]] [-nrE] CMD [FILE]..." diff --git a/editors/vi.c b/editors/vi.c index c010f7999..60c73c0eb 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -5,7 +5,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* * Things To Do: * EXINIT @@ -19,7 +18,6 @@ * ":r !cmd" and "!cmd" to filter text through an external command * An "ex" line oriented mode- maybe using "cmdedit" */ - //config:config VI //config: bool "vi (22 kb)" //config: default y diff --git a/findutils/find.c b/findutils/find.c index 5857a3f44..d9a42b3c6 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -9,7 +9,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - /* findutils-4.1.20: * * # find file.txt -exec 'echo {}' '{} {}' ';' @@ -44,7 +43,6 @@ * # find t z t z '(' -name '*t*' -o -name '*z*' ')' -o -print * (no output) */ - /* Testing script * ./busybox find "$@" | tee /tmp/bb_find * echo ================== @@ -52,7 +50,6 @@ * echo ================== * diff -u /tmp/std_find /tmp/bb_find && echo Identical */ - //config:config FIND //config: bool "find (14 kb)" //config: default y diff --git a/findutils/grep.c b/findutils/grep.c index 7c5f73d2f..f72175afb 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -17,7 +17,6 @@ * * (C) 2006 Jac Goudsmit added -o option */ - //config:config GREP //config: bool "grep (8.5 kb)" //config: default y diff --git a/init/bootchartd.c b/init/bootchartd.c index b5dd17439..373cde2d8 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -2,11 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -//applet:IF_BOOTCHARTD(APPLET(bootchartd, BB_DIR_SBIN, BB_SUID_DROP)) - -//kbuild:lib-$(CONFIG_BOOTCHARTD) += bootchartd.o - //config:config BOOTCHARTD //config: bool "bootchartd (10 kb)" //config: default y @@ -46,6 +41,10 @@ //config: Enable reading and parsing of $PWD/bootchartd.conf //config: and /etc/bootchartd.conf files. +//applet:IF_BOOTCHARTD(APPLET(bootchartd, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_BOOTCHARTD) += bootchartd.o + #include "libbb.h" #include "common_bufsiz.h" /* After libbb.h, since it needs sys/types.h on some systems */ diff --git a/init/halt.c b/init/halt.c index 632c6cc56..c6c857f08 100644 --- a/init/halt.c +++ b/init/halt.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config HALT //config: bool "halt (3.7 kb)" //config: default y diff --git a/init/init.c b/init/init.c index ab137a981..64e5c3e0b 100644 --- a/init/init.c +++ b/init/init.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config INIT //config: bool "init (9.3 kb)" //config: default y diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c index b82a706d8..b3038e32d 100644 --- a/libbb/u_signal_names.c +++ b/libbb/u_signal_names.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config FEATURE_RTMINMAX //config: bool "Support RTMIN[+n] and RTMAX[-n] signal names" //config: default y diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c index adef2328d..ec11b30ca 100644 --- a/loginutils/addgroup.c +++ b/loginutils/addgroup.c @@ -7,7 +7,6 @@ * Copyright (C) 2007 by Tito Ragusa * * Licensed under GPLv2 or later, see file LICENSE in this source tree. - * */ //config:config ADDGROUP //config: bool "addgroup (8.2 kb)" diff --git a/miscutils/beep.c b/miscutils/beep.c index b9b62f79b..0c8a8225e 100644 --- a/miscutils/beep.c +++ b/miscutils/beep.c @@ -5,7 +5,6 @@ * Copyright (C) 2009 Bernhard Reutner-Fischer * * Licensed under GPLv2 or later, see file LICENSE in this source tree. - * */ //config:config BEEP //config: bool "beep (3 kb)" diff --git a/miscutils/less.c b/miscutils/less.c index c6c158a51..82092f600 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* * TODO: * - Add more regular expression support - search modifiers, certain matches, etc. @@ -20,7 +19,6 @@ * - the inp file pointer is used so that keyboard input works after * redirected input has been read from stdin */ - //config:config LESS //config: bool "less (15 kb)" //config: default y diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index 80a005821..72f028ed3 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -7,7 +7,6 @@ * * TODO: add support for large (>4GB) MTD devices */ - //config:config NANDWRITE //config: bool "nandwrite (5.9 kb)" //config: default y diff --git a/miscutils/raidautorun.c b/miscutils/raidautorun.c index caf6e0821..d315c2734 100644 --- a/miscutils/raidautorun.c +++ b/miscutils/raidautorun.c @@ -5,7 +5,6 @@ * Copyright (C) 2006 Bernhard Reutner-Fischer * * Licensed under GPLv2 or later, see file LICENSE in this source tree. - * */ //config:config RAIDAUTORUN //config: bool "raidautorun (1.4 kb)" diff --git a/miscutils/rfkill.c b/miscutils/rfkill.c index 546928402..ae38c182d 100644 --- a/miscutils/rfkill.c +++ b/miscutils/rfkill.c @@ -1,12 +1,11 @@ /* vi: set sw=4 ts=4: */ /* -* rfkill implementation for busybox -* -* Copyright (C) 2010 Malek Degachi -* -* Licensed under GPLv2 or later, see file LICENSE in this source tree. -*/ - + * rfkill implementation for busybox + * + * Copyright (C) 2010 Malek Degachi + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ //config:config RFKILL //config: bool "rfkill (5.3 kb)" //config: default n # doesn't build on Ubuntu 9.04 diff --git a/miscutils/setserial.c b/miscutils/setserial.c index f217c3beb..fd88ed106 100644 --- a/miscutils/setserial.c +++ b/miscutils/setserial.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config SETSERIAL //config: bool "setserial (6.6 kb)" //config: default y diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index d142d1144..1ef8fd90e 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c @@ -2,7 +2,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config UBIATTACH //config: bool "ubiattach (4.7 kb)" //config: default y diff --git a/networking/hostname.c b/networking/hostname.c index d87f6562f..8e3238d99 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -9,7 +9,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config HOSTNAME //config: bool "hostname (5.6 kb)" //config: default y diff --git a/networking/ifupdown.c b/networking/ifupdown.c index c2cfe82ec..5521e8a5a 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -16,7 +16,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config IFUP //config: bool "ifup (17 kb)" //config: default y diff --git a/networking/nameif.c b/networking/nameif.c index 1f2695495..91d50536a 100644 --- a/networking/nameif.c +++ b/networking/nameif.c @@ -9,7 +9,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config NAMEIF //config: bool "nameif (6.6 kb)" //config: default y diff --git a/networking/nbd-client.c b/networking/nbd-client.c index cf1857231..bedb01a1c 100644 --- a/networking/nbd-client.c +++ b/networking/nbd-client.c @@ -3,20 +3,20 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ -#include "libbb.h" -#include -#include - -//applet:IF_NBDCLIENT(APPLET_NOEXEC(nbd-client, nbdclient, BB_DIR_USR_SBIN, BB_SUID_DROP, nbdclient)) - -//kbuild:lib-$(CONFIG_NBDCLIENT) += nbd-client.o - //config:config NBDCLIENT //config: bool "nbd-client (4.6 kb)" //config: default y //config: help //config: Network block device client +//applet:IF_NBDCLIENT(APPLET_NOEXEC(nbd-client, nbdclient, BB_DIR_USR_SBIN, BB_SUID_DROP, nbdclient)) + +//kbuild:lib-$(CONFIG_NBDCLIENT) += nbd-client.o + +#include "libbb.h" +#include +#include + #define NBD_SET_SOCK _IO(0xab, 0) #define NBD_SET_BLKSIZE _IO(0xab, 1) #define NBD_SET_SIZE _IO(0xab, 2) diff --git a/networking/ping.c b/networking/ping.c index 7460e4414..774f8f3e0 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -24,28 +24,6 @@ * This version is an adaptation of ping.c from busybox. * The code was modified by Bart Visscher */ - -#include -#include -#include "libbb.h" -#include "common_bufsiz.h" - -#ifdef __BIONIC__ -/* should be in netinet/ip_icmp.h */ -# define ICMP_DEST_UNREACH 3 /* Destination Unreachable */ -# define ICMP_SOURCE_QUENCH 4 /* Source Quench */ -# define ICMP_REDIRECT 5 /* Redirect (change route) */ -# define ICMP_ECHO 8 /* Echo Request */ -# define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */ -# define ICMP_PARAMETERPROB 12 /* Parameter Problem */ -# define ICMP_TIMESTAMP 13 /* Timestamp Request */ -# define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */ -# define ICMP_INFO_REQUEST 15 /* Information Request */ -# define ICMP_INFO_REPLY 16 /* Information Reply */ -# define ICMP_ADDRESS 17 /* Address Mask Request */ -# define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */ -#endif - //config:config PING //config: bool "ping (9.5 kb)" //config: default y @@ -136,6 +114,27 @@ //usage: "1 packets transmitted, 1 packets received, 0% packet loss\n" //usage: "round-trip min/avg/max = 20.1/20.1/20.1 ms\n" +#include +#include +#include "libbb.h" +#include "common_bufsiz.h" + +#ifdef __BIONIC__ +/* should be in netinet/ip_icmp.h */ +# define ICMP_DEST_UNREACH 3 /* Destination Unreachable */ +# define ICMP_SOURCE_QUENCH 4 /* Source Quench */ +# define ICMP_REDIRECT 5 /* Redirect (change route) */ +# define ICMP_ECHO 8 /* Echo Request */ +# define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */ +# define ICMP_PARAMETERPROB 12 /* Parameter Problem */ +# define ICMP_TIMESTAMP 13 /* Timestamp Request */ +# define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */ +# define ICMP_INFO_REQUEST 15 /* Information Request */ +# define ICMP_INFO_REPLY 16 /* Information Reply */ +# define ICMP_ADDRESS 17 /* Address Mask Request */ +# define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */ +#endif + #if ENABLE_PING6 # include /* I see RENUMBERED constants in bits/in.h - !!? diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 849ca1388..714555fa8 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config UDHCPC6 //config: bool "udhcpc6" //config: default n # not yet ready diff --git a/networking/vconfig.c b/networking/vconfig.c index 62a483865..8548c8c3b 100644 --- a/networking/vconfig.c +++ b/networking/vconfig.c @@ -6,9 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -/* BB_AUDIT SUSv3 N/A */ - //config:config VCONFIG //config: bool "vconfig (2.5 kb)" //config: default y @@ -34,6 +31,8 @@ #include "libbb.h" #include +/* BB_AUDIT SUSv3 N/A */ + /* Stuff from linux/if_vlan.h, kernel version 2.4.23 */ enum vlan_ioctl_cmds { ADD_VLAN_CMD, diff --git a/networking/wget.c b/networking/wget.c index e1b40d3fd..d1d85230c 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -8,7 +8,6 @@ * Copyright (C) 2010 Bradley M. Kuhn * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2. */ - //config:config WGET //config: bool "wget (35 kb)" //config: default y diff --git a/networking/whois.c b/networking/whois.c index fd1cdf43e..f0ec86301 100644 --- a/networking/whois.c +++ b/networking/whois.c @@ -9,7 +9,6 @@ * Add ipv6 support * Add proxy support */ - //config:config WHOIS //config: bool "whois (6.6 kb)" //config: default y diff --git a/procps/iostat.c b/procps/iostat.c index fbf685568..8fb4594da 100644 --- a/procps/iostat.c +++ b/procps/iostat.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config IOSTAT //config: bool "iostat (7.4 kb)" //config: default y diff --git a/procps/lsof.c b/procps/lsof.c index 8d3a23cc8..4917cf899 100644 --- a/procps/lsof.c +++ b/procps/lsof.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config LSOF //config: bool "lsof (3.6 kb)" //config: default y diff --git a/procps/mpstat.c b/procps/mpstat.c index acaff4dc0..7ead1fa7d 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c @@ -6,18 +6,17 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - -//applet:IF_MPSTAT(APPLET(mpstat, BB_DIR_BIN, BB_SUID_DROP)) -/* shouldn't be noexec: "mpstat INTERVAL" runs indefinitely */ - -//kbuild:lib-$(CONFIG_MPSTAT) += mpstat.o - //config:config MPSTAT //config: bool "mpstat (10 kb)" //config: default y //config: help //config: Per-processor statistics +//applet:IF_MPSTAT(APPLET(mpstat, BB_DIR_BIN, BB_SUID_DROP)) +/* shouldn't be noexec: "mpstat INTERVAL" runs indefinitely */ + +//kbuild:lib-$(CONFIG_MPSTAT) += mpstat.o + #include "libbb.h" #include /* struct utsname */ diff --git a/procps/nmeter.c b/procps/nmeter.c index 9463f94dc..166c8ab18 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -5,7 +5,6 @@ * * Contact me: vda.linux@googlemail.com */ - //config:config NMETER //config: bool "nmeter (10 kb)" //config: default y diff --git a/procps/pmap.c b/procps/pmap.c index 5c2d1ad59..c8fa0d280 100644 --- a/procps/pmap.c +++ b/procps/pmap.c @@ -7,7 +7,6 @@ * Licensed under GPLv2 or later, see the LICENSE file in this source tree * for details. */ - //config:config PMAP //config: bool "pmap (6 kb)" //config: default y @@ -15,6 +14,7 @@ //config: Display processes' memory mappings. //applet:IF_PMAP(APPLET(pmap, BB_DIR_USR_BIN, BB_SUID_DROP)) + //kbuild:lib-$(CONFIG_PMAP) += pmap.o //usage:#define pmap_trivial_usage diff --git a/procps/pwdx.c b/procps/pwdx.c index c72cf804a..6009e2aa3 100644 --- a/procps/pwdx.c +++ b/procps/pwdx.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config PWDX //config: bool "pwdx (3.5 kb)" //config: default y diff --git a/procps/smemcap.c b/procps/smemcap.c index c15fef1c3..81f4cafad 100644 --- a/procps/smemcap.c +++ b/procps/smemcap.c @@ -7,11 +7,6 @@ the GNU General Public License version 2 or later, incorporated herein by reference. */ - -//applet:IF_SMEMCAP(APPLET(smemcap, BB_DIR_USR_BIN, BB_SUID_DROP)) - -//kbuild:lib-$(CONFIG_SMEMCAP) += smemcap.o - //config:config SMEMCAP //config: bool "smemcap (2.5 kb)" //config: default y @@ -19,6 +14,10 @@ //config: smemcap is a tool for capturing process data for smem, //config: a memory usage statistic tool. +//applet:IF_SMEMCAP(APPLET(smemcap, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_SMEMCAP) += smemcap.o + #include "libbb.h" #include "bb_archive.h" diff --git a/procps/watch.c b/procps/watch.c index e58fd1f11..420e6d3d1 100644 --- a/procps/watch.c +++ b/procps/watch.c @@ -7,10 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -/* BB_AUDIT SUSv3 N/A */ -/* BB_AUDIT GNU defects -- only option -n is supported. */ - //config:config WATCH //config: bool "watch (4.1 kb)" //config: default y @@ -35,6 +31,9 @@ //usage: "Mon Dec 17 10:31:42 GMT 2000\n" //usage: "Mon Dec 17 10:31:44 GMT 2000" +/* BB_AUDIT SUSv3 N/A */ +/* BB_AUDIT GNU defects -- only option -n is supported. */ + #include "libbb.h" #define ESC "\033" diff --git a/runit/svlogd.c b/runit/svlogd.c index 739483356..dfd7e38a0 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -123,7 +123,6 @@ log message, you can use a pattern like this instead -*: *: pid * */ - //config:config SVLOGD //config: bool "svlogd (15 kb)" //config: default y diff --git a/shell/cttyhack.c b/shell/cttyhack.c index 849fe9e48..ec1b6c429 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -4,12 +4,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ -#include "libbb.h" - -//applet:IF_CTTYHACK(APPLET_NOEXEC(cttyhack, cttyhack, BB_DIR_BIN, BB_SUID_DROP, cttyhack)) - -//kbuild:lib-$(CONFIG_CTTYHACK) += cttyhack.o - //config:config CTTYHACK //config: bool "cttyhack (2.5 kb)" //config: default y @@ -54,6 +48,10 @@ //config: //config: # getty 115200 $(cttyhack) +//applet:IF_CTTYHACK(APPLET_NOEXEC(cttyhack, cttyhack, BB_DIR_BIN, BB_SUID_DROP, cttyhack)) + +//kbuild:lib-$(CONFIG_CTTYHACK) += cttyhack.o + //usage:#define cttyhack_trivial_usage //usage: "[PROG ARGS]" //usage:#define cttyhack_full_usage "\n\n" @@ -65,6 +63,8 @@ //usage: "\nStarting interactive shell from boot shell script:" //usage: "\n setsid cttyhack sh" +#include "libbb.h" + #if !defined(__linux__) && !defined(TIOCGSERIAL) && !ENABLE_WERROR # warning cttyhack will not be able to detect a controlling tty on this system #endif diff --git a/util-linux/fallocate.c b/util-linux/fallocate.c index 1a02a322f..8542586dc 100644 --- a/util-linux/fallocate.c +++ b/util-linux/fallocate.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config FALLOCATE //config: bool "fallocate (5 kb)" //config: default y diff --git a/util-linux/fsfreeze.c b/util-linux/fsfreeze.c index 2e2257337..c485810aa 100644 --- a/util-linux/fsfreeze.c +++ b/util-linux/fsfreeze.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config FSFREEZE //config: bool "fsfreeze (3.6 kb)" //config: default y diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c index 4acfa567a..205d1e42b 100644 --- a/util-linux/fstrim.c +++ b/util-linux/fstrim.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config FSTRIM //config: bool "fstrim (5.5 kb)" //config: default y diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 8acc4d21d..4b4eeafba 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //config:config MDEV //config: bool "mdev (16 kb)" //config: default y diff --git a/util-linux/mesg.c b/util-linux/mesg.c index 91c05317e..35c4ec13d 100644 --- a/util-linux/mesg.c +++ b/util-linux/mesg.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config MESG //config: bool "mesg (1.2 kb)" //config: default y diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c index d91b0b509..c6933c8d5 100644 --- a/util-linux/nsenter.c +++ b/util-linux/nsenter.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config NSENTER //config: bool "nsenter (8.6 kb)" //config: default y diff --git a/util-linux/rdev.c b/util-linux/rdev.c index 7eb7413a8..97279ce61 100644 --- a/util-linux/rdev.c +++ b/util-linux/rdev.c @@ -6,7 +6,6 @@ * Grant Erickson * * Licensed under GPLv2, see file LICENSE in this source tree. - * */ //config:config RDEV //config: bool "rdev (1.4 kb)" diff --git a/util-linux/taskset.c b/util-linux/taskset.c index 401a1bcb7..67df1cb73 100644 --- a/util-linux/taskset.c +++ b/util-linux/taskset.c @@ -5,7 +5,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config TASKSET //config: bool "taskset (4.1 kb)" //config: default y @@ -23,6 +22,7 @@ //config: in this case. Otherwise, it is limited to sizeof(long). //applet:IF_TASKSET(APPLET_NOEXEC(taskset, taskset, BB_DIR_USR_BIN, BB_SUID_DROP, taskset)) + //kbuild:lib-$(CONFIG_TASKSET) += taskset.o //usage:#define taskset_trivial_usage diff --git a/util-linux/volume_id/bcache.c b/util-linux/volume_id/bcache.c index 334a341c3..085c158db 100644 --- a/util-linux/volume_id/bcache.c +++ b/util-linux/volume_id/bcache.c @@ -7,14 +7,13 @@ * Based on code fragments from bcache-tools by Kent Overstreet: * http://evilpiepirate.org/git/bcache-tools.git */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BCACHE) += bcache.o - //config:config FEATURE_VOLUMEID_BCACHE //config: bool "bcache filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BCACHE) += bcache.o + #include "volume_id_internal.h" #define SB_LABEL_SIZE 32 diff --git a/util-linux/volume_id/btrfs.c b/util-linux/volume_id/btrfs.c index 338a48762..a3ddf9782 100644 --- a/util-linux/volume_id/btrfs.c +++ b/util-linux/volume_id/btrfs.c @@ -18,14 +18,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BTRFS) += btrfs.o - //config:config FEATURE_VOLUMEID_BTRFS //config: bool "btrfs filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BTRFS) += btrfs.o + #include "volume_id_internal.h" #define BTRFS_UUID_SIZE 16 diff --git a/util-linux/volume_id/cramfs.c b/util-linux/volume_id/cramfs.c index c63223e2b..3468a5005 100644 --- a/util-linux/volume_id/cramfs.c +++ b/util-linux/volume_id/cramfs.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_CRAMFS) += cramfs.o - //config:config FEATURE_VOLUMEID_CRAMFS //config: bool "cramfs filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_CRAMFS) += cramfs.o + #include "volume_id_internal.h" struct cramfs_super { diff --git a/util-linux/volume_id/exfat.c b/util-linux/volume_id/exfat.c index 14bf9d691..952b027d9 100644 --- a/util-linux/volume_id/exfat.c +++ b/util-linux/volume_id/exfat.c @@ -17,9 +17,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_EXFAT) += exfat.o - //config:config FEATURE_VOLUMEID_EXFAT //config: bool "exFAT filesystem" //config: default y @@ -29,6 +26,8 @@ //config: for flash drives. It has many features from NTFS, but with less //config: overhead. exFAT is used on most SDXC cards for consumer electronics. +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_EXFAT) += exfat.o + #include "volume_id_internal.h" #define EXFAT_SB_OFFSET 0 diff --git a/util-linux/volume_id/ext.c b/util-linux/volume_id/ext.c index 473b3229a..f17faddb6 100644 --- a/util-linux/volume_id/ext.c +++ b/util-linux/volume_id/ext.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_EXT) += ext.o - //config:config FEATURE_VOLUMEID_EXT //config: bool "Ext filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_EXT) += ext.o + #include "volume_id_internal.h" #include "bb_e2fs_defs.h" diff --git a/util-linux/volume_id/f2fs.c b/util-linux/volume_id/f2fs.c index 3027f178e..e6100aec2 100644 --- a/util-linux/volume_id/f2fs.c +++ b/util-linux/volume_id/f2fs.c @@ -5,9 +5,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_F2FS) += f2fs.o - //config:config FEATURE_VOLUMEID_F2FS //config: bool "f2fs filesystem" //config: default y @@ -18,6 +15,8 @@ //config: known issues of the older log structured file systems, such as high //config: cleaning overhead. +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_F2FS) += f2fs.o + #include "volume_id_internal.h" #define F2FS_MAGIC 0xF2F52010 // F2FS Magic Number diff --git a/util-linux/volume_id/fat.c b/util-linux/volume_id/fat.c index bc3433daf..b24ed098e 100644 --- a/util-linux/volume_id/fat.c +++ b/util-linux/volume_id/fat.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_FAT) += fat.o - //config:config FEATURE_VOLUMEID_FAT //config: bool "fat filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_FAT) += fat.o + #include "volume_id_internal.h" /* linux/msdos_fs.h says: */ diff --git a/util-linux/volume_id/hfs.c b/util-linux/volume_id/hfs.c index 78dae0790..05d16db34 100644 --- a/util-linux/volume_id/hfs.c +++ b/util-linux/volume_id/hfs.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_HFS) += hfs.o - //config:config FEATURE_VOLUMEID_HFS //config: bool "hfs filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_HFS) += hfs.o + #include "volume_id_internal.h" struct hfs_finder_info{ diff --git a/util-linux/volume_id/iso9660.c b/util-linux/volume_id/iso9660.c index 23072f87c..c771b01f5 100644 --- a/util-linux/volume_id/iso9660.c +++ b/util-linux/volume_id/iso9660.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_ISO9660) += iso9660.o - //config:config FEATURE_VOLUMEID_ISO9660 //config: bool "iso9660 filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_ISO9660) += iso9660.o + #include "volume_id_internal.h" #define ISO_SUPERBLOCK_OFFSET 0x8000 diff --git a/util-linux/volume_id/jfs.c b/util-linux/volume_id/jfs.c index 543d90fe5..5e523e236 100644 --- a/util-linux/volume_id/jfs.c +++ b/util-linux/volume_id/jfs.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_JFS) += jfs.o - //config:config FEATURE_VOLUMEID_JFS //config: bool "jfs filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_JFS) += jfs.o + #include "volume_id_internal.h" struct jfs_super_block { diff --git a/util-linux/volume_id/linux_raid.c b/util-linux/volume_id/linux_raid.c index 0db6e8662..db6209a4d 100644 --- a/util-linux/volume_id/linux_raid.c +++ b/util-linux/volume_id/linux_raid.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LINUXRAID) += linux_raid.o - //config:config FEATURE_VOLUMEID_LINUXRAID //config: bool "linuxraid" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LINUXRAID) += linux_raid.o + #include "volume_id_internal.h" struct mdp_super_block { diff --git a/util-linux/volume_id/linux_swap.c b/util-linux/volume_id/linux_swap.c index a35769dfc..78b339cf0 100644 --- a/util-linux/volume_id/linux_swap.c +++ b/util-linux/volume_id/linux_swap.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LINUXSWAP) += linux_swap.o - //config:config FEATURE_VOLUMEID_LINUXSWAP //config: bool "linux swap filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LINUXSWAP) += linux_swap.o + #include "volume_id_internal.h" struct swap_header_v1_2 { diff --git a/util-linux/volume_id/luks.c b/util-linux/volume_id/luks.c index 4b80b7a6d..8e634d4ee 100644 --- a/util-linux/volume_id/luks.c +++ b/util-linux/volume_id/luks.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LUKS) += luks.o - //config:config FEATURE_VOLUMEID_LUKS //config: bool "luks filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_LUKS) += luks.o + #include "volume_id_internal.h" #define LUKS_MAGIC_L 6 diff --git a/util-linux/volume_id/nilfs.c b/util-linux/volume_id/nilfs.c index 9d6c57fba..7a8b798df 100644 --- a/util-linux/volume_id/nilfs.c +++ b/util-linux/volume_id/nilfs.c @@ -18,9 +18,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_NILFS) += nilfs.o - //config:config FEATURE_VOLUMEID_NILFS //config: bool "nilfs filesystem" //config: default y @@ -37,6 +34,8 @@ //config: filesystem for Linux desktop environment, or as a basis of advanced //config: storage appliances. +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_NILFS) += nilfs.o + #include "volume_id_internal.h" #define NILFS_UUID_SIZE 16 diff --git a/util-linux/volume_id/ntfs.c b/util-linux/volume_id/ntfs.c index bf85f7ed3..22dd77fc7 100644 --- a/util-linux/volume_id/ntfs.c +++ b/util-linux/volume_id/ntfs.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_NTFS) += ntfs.o - //config:config FEATURE_VOLUMEID_NTFS //config: bool "ntfs filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_NTFS) += ntfs.o + #include "volume_id_internal.h" struct ntfs_super_block { diff --git a/util-linux/volume_id/ocfs2.c b/util-linux/volume_id/ocfs2.c index 2dedac98b..235968b88 100644 --- a/util-linux/volume_id/ocfs2.c +++ b/util-linux/volume_id/ocfs2.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_OCFS2) += ocfs2.o - //config:config FEATURE_VOLUMEID_OCFS2 //config: bool "ocfs2 filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_OCFS2) += ocfs2.o + #include "volume_id_internal.h" /* All these values are taken from ocfs2-tools's ocfs2_fs.h */ diff --git a/util-linux/volume_id/reiserfs.c b/util-linux/volume_id/reiserfs.c index 369d4d9bb..d9fd8944d 100644 --- a/util-linux/volume_id/reiserfs.c +++ b/util-linux/volume_id/reiserfs.c @@ -18,14 +18,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS) += reiserfs.o - //config:config FEATURE_VOLUMEID_REISERFS //config: bool "Reiser filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS) += reiserfs.o + #include "volume_id_internal.h" struct reiserfs_super_block { diff --git a/util-linux/volume_id/romfs.c b/util-linux/volume_id/romfs.c index 95a65f9ef..bd74fda8d 100644 --- a/util-linux/volume_id/romfs.c +++ b/util-linux/volume_id/romfs.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_ROMFS) += romfs.o - //config:config FEATURE_VOLUMEID_ROMFS //config: bool "romfs filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_ROMFS) += romfs.o + #include "volume_id_internal.h" struct romfs_super { diff --git a/util-linux/volume_id/squashfs.c b/util-linux/volume_id/squashfs.c index e3ffce35e..4b65afd8b 100644 --- a/util-linux/volume_id/squashfs.c +++ b/util-linux/volume_id/squashfs.c @@ -5,9 +5,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SQUASHFS) += squashfs.o - //config:config FEATURE_VOLUMEID_SQUASHFS //config: bool "SquashFS filesystem" //config: default y @@ -18,6 +15,8 @@ //config: device/memory systems (e.g. embedded systems) where low overhead is //config: needed. +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SQUASHFS) += squashfs.o + #include "volume_id_internal.h" struct squashfs_superblock { diff --git a/util-linux/volume_id/sysv.c b/util-linux/volume_id/sysv.c index cd4cd906b..be41f8048 100644 --- a/util-linux/volume_id/sysv.c +++ b/util-linux/volume_id/sysv.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SYSV) += sysv.o - //config:config FEATURE_VOLUMEID_SYSV //config: bool "sysv filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_SYSV) += sysv.o + #include "volume_id_internal.h" #define SYSV_NICINOD 100 diff --git a/util-linux/volume_id/ubifs.c b/util-linux/volume_id/ubifs.c index 7512b84b0..aee53f9dd 100644 --- a/util-linux/volume_id/ubifs.c +++ b/util-linux/volume_id/ubifs.c @@ -5,9 +5,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_UBIFS) += ubifs.o - //config:config FEATURE_VOLUMEID_UBIFS //config: bool "UBIFS filesystem" //config: default y @@ -16,6 +13,8 @@ //config: UBIFS (Unsorted Block Image File System) is a file //config: system for use with raw flash memory media. +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_UBIFS) += ubifs.o + #include "volume_id_internal.h" #define UBIFS_NODE_MAGIC 0x06101831 diff --git a/util-linux/volume_id/udf.c b/util-linux/volume_id/udf.c index fa5dccee7..0df4a86df 100644 --- a/util-linux/volume_id/udf.c +++ b/util-linux/volume_id/udf.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_UDF) += udf.o - //config:config FEATURE_VOLUMEID_UDF //config: bool "udf filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_UDF) += udf.o + #include "volume_id_internal.h" struct volume_descriptor { diff --git a/util-linux/volume_id/unused_highpoint.c b/util-linux/volume_id/unused_highpoint.c index 4afa6d927..1d5ceb787 100644 --- a/util-linux/volume_id/unused_highpoint.c +++ b/util-linux/volume_id/unused_highpoint.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_HIGHPOINTRAID) += highpoint.o - //config:### config FEATURE_VOLUMEID_HIGHPOINTRAID //config:### bool "highpoint raid" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_HIGHPOINTRAID) += highpoint.o + #include "volume_id_internal.h" struct hpt37x_meta { diff --git a/util-linux/volume_id/unused_hpfs.c b/util-linux/volume_id/unused_hpfs.c index 3e16dedbd..26fefd415 100644 --- a/util-linux/volume_id/unused_hpfs.c +++ b/util-linux/volume_id/unused_hpfs.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_HPFS) += hpfs.o - //config:### config FEATURE_VOLUMEID_HPFS //config:### bool "hpfs filesystem" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_HPFS) += hpfs.o + #include "volume_id_internal.h" struct hpfs_super { diff --git a/util-linux/volume_id/unused_isw_raid.c b/util-linux/volume_id/unused_isw_raid.c index fba99be58..f7b3eec74 100644 --- a/util-linux/volume_id/unused_isw_raid.c +++ b/util-linux/volume_id/unused_isw_raid.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_ISWRAID) += isw_raid.o - //config:### config FEATURE_VOLUMEID_ISWRAID //config:### bool "intel raid" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_ISWRAID) += isw_raid.o + #include "volume_id_internal.h" struct isw_meta { diff --git a/util-linux/volume_id/unused_lsi_raid.c b/util-linux/volume_id/unused_lsi_raid.c index 9dd2b409c..12dabea87 100644 --- a/util-linux/volume_id/unused_lsi_raid.c +++ b/util-linux/volume_id/unused_lsi_raid.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_LSIRAID) += lsi_raid.o - //config:### config FEATURE_VOLUMEID_LSIRAID //config:### bool "lsi raid" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_LSIRAID) += lsi_raid.o + #include "volume_id_internal.h" struct lsi_meta { diff --git a/util-linux/volume_id/unused_lvm.c b/util-linux/volume_id/unused_lvm.c index 5ad6d585c..649306c85 100644 --- a/util-linux/volume_id/unused_lvm.c +++ b/util-linux/volume_id/unused_lvm.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_LVM) += lvm.o - //config:### config FEATURE_VOLUMEID_LVM //config:### bool "lvm" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_LVM) += lvm.o + #include "volume_id_internal.h" struct lvm1_super_block { diff --git a/util-linux/volume_id/unused_mac.c b/util-linux/volume_id/unused_mac.c index 997d330a4..a0d253e92 100644 --- a/util-linux/volume_id/unused_mac.c +++ b/util-linux/volume_id/unused_mac.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MAC) += mac.o - //config:### config FEATURE_VOLUMEID_MAC //config:### bool "mac filesystem" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MAC) += mac.o + #include "volume_id_internal.h" struct mac_driver_desc { diff --git a/util-linux/volume_id/unused_msdos.c b/util-linux/volume_id/unused_msdos.c index f84c0f06f..baa14c552 100644 --- a/util-linux/volume_id/unused_msdos.c +++ b/util-linux/volume_id/unused_msdos.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MSDOS) += msdos.o - //config:### config FEATURE_VOLUMEID_MSDOS //config:### bool "msdos filesystem" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MSDOS) += msdos.o + #include "volume_id_internal.h" struct msdos_partition_entry { diff --git a/util-linux/volume_id/unused_nvidia_raid.c b/util-linux/volume_id/unused_nvidia_raid.c index dfb54fa9d..e8217b402 100644 --- a/util-linux/volume_id/unused_nvidia_raid.c +++ b/util-linux/volume_id/unused_nvidia_raid.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_NVIDIARAID) += nvidia_raid.o - //config:### config FEATURE_VOLUMEID_NVIDIARAID //config:### bool "nvidia raid" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_NVIDIARAID) += nvidia_raid.o + #include "volume_id_internal.h" struct nvidia_meta { diff --git a/util-linux/volume_id/unused_promise_raid.c b/util-linux/volume_id/unused_promise_raid.c index d594de39c..c4a6f502a 100644 --- a/util-linux/volume_id/unused_promise_raid.c +++ b/util-linux/volume_id/unused_promise_raid.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_PROMISERAID) += promise_raid.o - //config:### config FEATURE_VOLUMEID_PROMISERAID //config:### bool "promise raid" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_PROMISERAID) += promise_raid.o + #include "volume_id_internal.h" struct promise_meta { diff --git a/util-linux/volume_id/unused_silicon_raid.c b/util-linux/volume_id/unused_silicon_raid.c index 886721b61..ea96dc98a 100644 --- a/util-linux/volume_id/unused_silicon_raid.c +++ b/util-linux/volume_id/unused_silicon_raid.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_SILICONRAID) += silicon_raid.o - //config:### config FEATURE_VOLUMEID_SILICONRAID //config:### bool "silicon raid" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_SILICONRAID) += silicon_raid.o + #include "volume_id_internal.h" struct silicon_meta { diff --git a/util-linux/volume_id/unused_ufs.c b/util-linux/volume_id/unused_ufs.c index 78ef26ad4..c36793a68 100644 --- a/util-linux/volume_id/unused_ufs.c +++ b/util-linux/volume_id/unused_ufs.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_UFS) += ufs.o - //config:### config FEATURE_VOLUMEID_UFS //config:### bool "ufs filesystem" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_UFS) += ufs.o + #include "volume_id_internal.h" struct ufs_super_block { diff --git a/util-linux/volume_id/unused_via_raid.c b/util-linux/volume_id/unused_via_raid.c index f82626655..c77c8393c 100644 --- a/util-linux/volume_id/unused_via_raid.c +++ b/util-linux/volume_id/unused_via_raid.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_VIARAID) += via_raid.o - //config:### config FEATURE_VOLUMEID_VIARAID //config:### bool "via raid" //config:### default y //config:### depends on VOLUMEID +//kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_VIARAID) += via_raid.o + #include "volume_id_internal.h" struct via_meta { diff --git a/util-linux/volume_id/xfs.c b/util-linux/volume_id/xfs.c index 656d5bfcf..f98b66a53 100644 --- a/util-linux/volume_id/xfs.c +++ b/util-linux/volume_id/xfs.c @@ -17,14 +17,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_XFS) += xfs.o - //config:config FEATURE_VOLUMEID_XFS //config: bool "xfs filesystem" //config: default y //config: depends on VOLUMEID +//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_XFS) += xfs.o + #include "volume_id_internal.h" struct xfs_super_block { diff --git a/util-linux/wall.c b/util-linux/wall.c index e214d8c3f..939736592 100644 --- a/util-linux/wall.c +++ b/util-linux/wall.c @@ -5,7 +5,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //config:config WALL //config: bool "wall (2.5 kb)" //config: default y -- cgit v1.2.3-55-g6feb