From a407cf74cc43c3cc26168e259cee469a4787a76c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Sep 2013 12:53:14 +0200 Subject: Make smart_ulltoa return pointer to end (allows for code shink in callers) function old new delta smart_ulltoa5 405 408 +3 smart_ulltoa4 273 276 +3 list_table 1113 1114 +1 scale 36 34 -2 put_lu 55 53 -2 ulltoa6_and_space 19 14 -5 powertop_main 1470 1461 -9 Signed-off-by: Denys Vlasenko --- include/libbb.h | 4 ++-- libbb/human_readable.c | 6 ++++-- procps/nmeter.c | 3 +-- procps/powertop.c | 3 +-- procps/ps.c | 9 +++------ procps/top.c | 3 +-- util-linux/fdisk_gpt.c | 6 ++---- 7 files changed, 14 insertions(+), 20 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 6b95dc0ec..1315e5f8f 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -815,8 +815,8 @@ char *itoa(int n) FAST_FUNC; char *utoa_to_buf(unsigned n, char *buf, unsigned buflen) FAST_FUNC; char *itoa_to_buf(int n, char *buf, unsigned buflen) FAST_FUNC; /* Intelligent formatters of bignums */ -void smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC; -void smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC; +char *smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) FAST_FUNC; +char *smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) FAST_FUNC; /* If block_size == 0, display size without fractional part, * else display (size * block_size) with one decimal digit. * If display_unit == 0, show value no bigger than 1024 with suffix (K,M,G...), diff --git a/libbb/human_readable.c b/libbb/human_readable.c index 8b22b0cb5..0b2eb777e 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c @@ -94,7 +94,7 @@ const char* FAST_FUNC make_human_readable_str(unsigned long long val, /* Convert unsigned long long value into compact 5-char representation. * String is not terminated (buf[5] is untouched) */ -void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) +char* FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) { const char *fmt; char c; @@ -145,12 +145,13 @@ void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *sca buf[3] = "0123456789"[v]; buf[4] = scale[idx]; /* typically scale = " kmgt..." */ } + return buf + 5; } /* Convert unsigned long long value into compact 4-char * representation. Examples: "1234", "1.2k", " 27M", "123T" * String is not terminated (buf[4] is untouched) */ -void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) +char* FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) { const char *fmt; char c; @@ -194,4 +195,5 @@ void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *sca buf[2] = "0123456789"[v]; buf[3] = scale[idx]; /* typically scale = " kmgt..." */ } + return buf + 4; } diff --git a/procps/nmeter.c b/procps/nmeter.c index 6a3b32743..5d5b83b8d 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -333,8 +333,7 @@ static void scale(ullong ul) char buf[5]; /* see http://en.wikipedia.org/wiki/Tera */ - smart_ulltoa4(ul, buf, " kmgtpezy"); - buf[4] = '\0'; + smart_ulltoa4(ul, buf, " kmgtpezy")[0] = '\0'; put(buf); } diff --git a/procps/powertop.c b/procps/powertop.c index 71988a295..e3c29d1c3 100644 --- a/procps/powertop.c +++ b/procps/powertop.c @@ -627,7 +627,6 @@ static void show_timerstats(void) int i, n = 0; char strbuf6[6]; - strbuf6[5] = '\0'; puts("\nTop causes for wakeups:"); for (i = 0; i < G.lines_cnt; i++) { if ((G.lines[i].count > 0 /*|| G.lines[i].disk_count > 0*/) @@ -639,7 +638,7 @@ static void show_timerstats(void) /*char c = ' '; if (G.lines[i].disk_count) c = 'D';*/ - smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY"); + smart_ulltoa5(G.lines[i].count, strbuf6, " KMGTPEZY")[0] = '\0'; printf(/*" %5.1f%% (%s)%c %s\n"*/ " %5.1f%% (%s) %s\n", G.lines[i].count * 100.0 / G.lines_cumulative_count, diff --git a/procps/ps.c b/procps/ps.c index 89cadad00..c65fa012a 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -299,8 +299,7 @@ static void put_lu(char *buf, int size, unsigned long u) char buf4[5]; /* see http://en.wikipedia.org/wiki/Tera */ - smart_ulltoa4(u, buf4, " mgtpezy"); - buf4[4] = '\0'; + smart_ulltoa4(u, buf4, " mgtpezy")[0] = '\0'; sprintf(buf, "%.*s", size, buf4); } @@ -740,8 +739,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) #endif { char buf6[6]; - smart_ulltoa5(p->vsz, buf6, " mgtpezy"); - buf6[5] = '\0'; + smart_ulltoa5(p->vsz, buf6, " mgtpezy")[0] = '\0'; #if ENABLE_FEATURE_PS_LONG if (opts & OPT_l) { char bufr[6], stime_str[6]; @@ -752,8 +750,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) time_t start = now - elapsed; struct tm *tm = localtime(&start); - smart_ulltoa5(p->rss, bufr, " mgtpezy"); - bufr[5] = '\0'; + smart_ulltoa5(p->rss, bufr, " mgtpezy")[0] = '\0'; if (p->tty_major == 136) /* It should be pts/N, not ptsN, but N > 9 diff --git a/procps/top.c b/procps/top.c index abee69806..a13a41cd8 100644 --- a/procps/top.c +++ b/procps/top.c @@ -847,8 +847,7 @@ static void display_topmem_header(int scr_width, int *lines_rem_p) static void ulltoa6_and_space(unsigned long long ul, char buf[6]) { /* see http://en.wikipedia.org/wiki/Tera */ - smart_ulltoa5(ul, buf, " mgtpezy"); - buf[5] = ' '; + smart_ulltoa5(ul, buf, " mgtpezy")[0] = '\0'; } static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c index f45f68af0..5786d5f7d 100644 --- a/util-linux/fdisk_gpt.c +++ b/util-linux/fdisk_gpt.c @@ -93,9 +93,7 @@ gpt_list_table(int xtra UNUSED_PARAM) int i; char numstr6[6]; - numstr6[5] = '\0'; - - smart_ulltoa5(total_number_of_sectors * sector_size, numstr6, " KMGTPEZY"); + smart_ulltoa5(total_number_of_sectors * sector_size, numstr6, " KMGTPEZY")[0] = '\0'; printf("Disk %s: %llu sectors, %s\n", disk_device, (unsigned long long)total_number_of_sectors, numstr6); @@ -113,7 +111,7 @@ gpt_list_table(int xtra UNUSED_PARAM) gpt_partition *p = gpt_part(i); if (p->lba_start) { smart_ulltoa5((1 + SWAP_LE64(p->lba_end) - SWAP_LE64(p->lba_start)) * sector_size, - numstr6, " KMGTPEZY"); + numstr6, " KMGTPEZY")[0] = '\0'; printf("%4u %15llu %15llu %11s %04x ", i + 1, (unsigned long long)SWAP_LE64(p->lba_start), -- cgit v1.2.3-55-g6feb From dc57294485068e644714804ad1b1a3a10c4fceec Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Sep 2013 12:59:48 +0200 Subject: top: fix breakage introduced by previous commit Signed-off-by: Denys Vlasenko --- procps/top.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/procps/top.c b/procps/top.c index a13a41cd8..31f2a5113 100644 --- a/procps/top.c +++ b/procps/top.c @@ -847,7 +847,7 @@ static void display_topmem_header(int scr_width, int *lines_rem_p) static void ulltoa6_and_space(unsigned long long ul, char buf[6]) { /* see http://en.wikipedia.org/wiki/Tera */ - smart_ulltoa5(ul, buf, " mgtpezy")[0] = '\0'; + smart_ulltoa5(ul, buf, " mgtpezy")[0] = ' '; } static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) -- cgit v1.2.3-55-g6feb From 2a053a2430e8de2f5de3da7d4d25343f61161f09 Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Tue, 10 Sep 2013 11:52:35 +0200 Subject: ar: read_num(): fix reading fields using the entire width ar fields are fixed length text strings (padded with spaces). Ensure bb_strtou doesn't read past the field in case the full width is used. The fields are only read once, so the simplest/smallest solution to me seems to be to just pass the length to read_num() and then zero terminate the string before passing it to bb_strtou. This does mean that the fields MUST be read in reverse order, so some minor reshuffling was needed. Bloat-o-meter: function old new delta get_header_ar 394 414 +20 read_num 29 36 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 27/0) Total: 27 bytes Signed-off-by: Peter Korsgaard Signed-off-by: Denys Vlasenko --- archival/libarchive/get_header_ar.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c index 23c412496..f655585fe 100644 --- a/archival/libarchive/get_header_ar.c +++ b/archival/libarchive/get_header_ar.c @@ -8,11 +8,19 @@ #include "bb_archive.h" #include "ar.h" -static unsigned read_num(const char *str, int base) +/* WARNING: Clobbers str[len], so fields must be read in reverse order! */ +static unsigned read_num(char *str, int base, int len) { + int err; + + /* ar fields are fixed length text strings (padded with spaces). + * Ensure bb_strtou doesn't read past the field in case the full + * width is used. */ + str[len] = 0; + /* This code works because * on misformatted numbers bb_strtou returns all-ones */ - int err = bb_strtou(str, NULL, base); + err = bb_strtou(str, NULL, base); if (err == -1) bb_error_msg_and_die("invalid ar header"); return err; @@ -51,11 +59,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n') bb_error_msg_and_die("invalid ar header"); - /* FIXME: more thorough routine would be in order here - * (we have something like that in tar) - * but for now we are lax. */ - ar.formatted.magic[0] = '\0'; /* else 4G-2 file will have size="4294967294`\n..." */ - typed->size = size = read_num(ar.formatted.size, 10); + typed->size = size = read_num(ar.formatted.size, 10, + sizeof(ar.formatted.size)); /* special filenames have '/' as the first character */ if (ar.formatted.name[0] == '/') { @@ -86,11 +91,13 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) /* Only size is always present, the rest may be missing in * long filename pseudo file. Thus we decode the rest * after dealing with long filename pseudo file. + * Note that the fields MUST be read in reverse order as + * read_num() clobbers the next byte after the field! */ - typed->mode = read_num(ar.formatted.mode, 8); - typed->mtime = read_num(ar.formatted.date, 10); - typed->uid = read_num(ar.formatted.uid, 10); - typed->gid = read_num(ar.formatted.gid, 10); + typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)); + typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid)); + typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid)); + typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date)); #if ENABLE_FEATURE_AR_LONG_FILENAMES if (ar.formatted.name[0] == '/') { @@ -98,7 +105,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) /* The number after the '/' indicates the offset in the ar data section * (saved in ar_long_names) that conatains the real filename */ - long_offset = read_num(&ar.formatted.name[1], 10); + long_offset = read_num(&ar.formatted.name[1], 10, + sizeof(ar.formatted.name) - 1); if (long_offset >= ar_long_name_size) { bb_error_msg_and_die("can't resolve long filename"); } -- cgit v1.2.3-55-g6feb From a613aa1b4c26be1567a59e9216c83d21d4be122b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 10 Sep 2013 16:27:08 +0200 Subject: ar: better comment Signed-off-by: Denys Vlasenko --- archival/libarchive/get_header_ar.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c index f655585fe..c66bb3ee7 100644 --- a/archival/libarchive/get_header_ar.c +++ b/archival/libarchive/get_header_ar.c @@ -59,6 +59,11 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n') bb_error_msg_and_die("invalid ar header"); + /* + * Note that the fields MUST be read in reverse order as + * read_num() clobbers the next byte after the field! + * Order is: name, date, uid, gid, mode, size, magic. + */ typed->size = size = read_num(ar.formatted.size, 10, sizeof(ar.formatted.size)); @@ -91,8 +96,6 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) /* Only size is always present, the rest may be missing in * long filename pseudo file. Thus we decode the rest * after dealing with long filename pseudo file. - * Note that the fields MUST be read in reverse order as - * read_num() clobbers the next byte after the field! */ typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)); typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid)); -- cgit v1.2.3-55-g6feb From b5352078a7eb16c33404a8b079aaa9c2b994546c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 11 Sep 2013 11:58:33 +0200 Subject: touch: add conditional support for -h Based on a patch by Andy Signed-off-by: Denys Vlasenko --- coreutils/touch.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/coreutils/touch.c b/coreutils/touch.c index 1216ca202..293a96890 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c @@ -26,6 +26,14 @@ //config: touch is used to create or change the access and/or //config: modification timestamp of specified files. //config: +//config:config FEATURE_TOUCH_NODEREF +//config: bool "Add support for -h" +//config: default y +//config: depends on TOUCH +//config: help +//config: Enable touch to have the -h option. +//config: This requires libc support for lutimes() function. +//config: //config:config FEATURE_TOUCH_SUSV3 //config: bool "Add support for SUSV3 features (-d -t -r)" //config: default y @@ -42,6 +50,9 @@ //usage:#define touch_full_usage "\n\n" //usage: "Update the last-modified date on the given FILE[s]\n" //usage: "\n -c Don't create files" +//usage: IF_FEATURE_TOUCH_NODEREF( +//usage: "\n -h Don't follow links" +//usage: ) //usage: IF_FEATURE_TOUCH_SUSV3( //usage: "\n -d DT Date/time to use" //usage: "\n -t DT Date/time to use" @@ -65,6 +76,7 @@ * parse STRING and use it instead of current time * -f (ignored, BSD compat) * -m change only the modification time + * -h, --no-dereference * -r, --reference=FILE * use this file's times instead of current time * -t STAMP @@ -79,6 +91,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv) int fd; int status = EXIT_SUCCESS; int opts; + enum { + OPT_c = (1 << 0), + OPT_r = (1 << 1) * ENABLE_FEATURE_TOUCH_SUSV3, + OPT_d = (1 << 2) * ENABLE_FEATURE_TOUCH_SUSV3, + OPT_t = (1 << 3) * ENABLE_FEATURE_TOUCH_SUSV3, + OPT_h = (1 << 4) * ENABLE_FEATURE_TOUCH_NODEREF, + }; #if ENABLE_FEATURE_TOUCH_SUSV3 # if ENABLE_LONG_OPTS static const char touch_longopts[] ALIGN1 = @@ -86,6 +105,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv) "no-create\0" No_argument "c" "reference\0" Required_argument "r" "date\0" Required_argument "d" + IF_FEATURE_TOUCH_NODEREF("no-dereference\0" No_argument "h") ; # endif char *reference_file = NULL; @@ -105,13 +125,13 @@ int touch_main(int argc UNUSED_PARAM, char **argv) * accepted data format differs a bit between -d and -t. * We accept the same formats for both */ opts = getopt32(argv, "c" IF_FEATURE_TOUCH_SUSV3("r:d:t:") + IF_FEATURE_TOUCH_NODEREF("h") /*ignored:*/ "fma" IF_FEATURE_TOUCH_SUSV3(, &reference_file) IF_FEATURE_TOUCH_SUSV3(, &date_str) IF_FEATURE_TOUCH_SUSV3(, &date_str) ); - opts &= 1; /* only -c bit is left */ argv += optind; if (!*argv) { bb_show_usage(); @@ -121,6 +141,10 @@ int touch_main(int argc UNUSED_PARAM, char **argv) struct stat stbuf; xstat(reference_file, &stbuf); timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime; + /* Can use .st_mtim.tv_nsec + * (or is it .st_mtimensec?? see date.c) + * to set microseconds too. + */ } if (date_str) { @@ -141,9 +165,16 @@ int touch_main(int argc UNUSED_PARAM, char **argv) } do { - if (utimes(*argv, (reference_file || date_str) ? timebuf : NULL) != 0) { - if (errno == ENOENT) { /* no such file */ - if (opts) { /* creation is disabled, so ignore */ + int result; + result = ( +#if ENABLE_FEATURE_TOUCH_NODEREF + (opts & OPT_h) ? lutimes : +#endif + utimes)(*argv, (reference_file || date_str) ? timebuf : NULL); + if (result != 0) { + if (errno == ENOENT) { /* no such file? */ + if (opts & OPT_c) { + /* Creation is disabled, so ignore */ continue; } /* Try to create the file */ -- cgit v1.2.3-55-g6feb From fbe250db76b409a99457b47486a09b57677d5108 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 11 Sep 2013 14:59:21 +0200 Subject: httpd: treat errors from stdin correctly. Fron bug report: If a CGI or proxied connection is rudely aborted (SIG_{KILL,BUS,SEGV}) then httpd will spin madly the poll loop in: networking/httpd.c:1080 cgi_io_loop_and_exit() Upon investigation I found that pfd[0].revents == 0x0018 (POLLHUP|POLLERR), which leads to empty read, but the pfd[0].fd (STDIN_FILENO) is left open, and in the FD list given to poll() which immediately returns to once again inform the loop of (POLLHUP|POLLERR) condition of pfd[0].fd. This continues until pfd[FROM_CGI].revents != 0 Signed-off-by: Denys Vlasenko --- networking/httpd.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index cef9b8baf..143331389 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1105,16 +1105,21 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post /* NB: breaking out of this loop jumps to log_and_exit() */ out_cnt = 0; while (1) { - memset(pfd, 0, sizeof(pfd)); + /* Note: even pfd[0].events == 0 won't prevent + * revents == POLLHUP|POLLERR reports from closed stdin. + * This works: */ + pfd[0].fd = -1; pfd[FROM_CGI].fd = fromCgi_rd; pfd[FROM_CGI].events = POLLIN; - if (toCgi_wr) { - pfd[TO_CGI].fd = toCgi_wr; - if (hdr_cnt > 0) { - pfd[TO_CGI].events = POLLOUT; - } else if (post_len > 0) { + pfd[TO_CGI].fd = toCgi_wr; + pfd[TO_CGI].events = POLLOUT; + + if (toCgi_wr && hdr_cnt <= 0) { + if (post_len > 0) { + /* Expect more POST data from network */ + pfd[0].fd = 0; pfd[0].events = POLLIN; } else { /* post_len <= 0 && hdr_cnt <= 0: @@ -1127,7 +1132,7 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post } /* Now wait on the set of sockets */ - count = safe_poll(pfd, toCgi_wr ? TO_CGI+1 : FROM_CGI+1, -1); + count = safe_poll(pfd, hdr_cnt > 0 ? TO_CGI+1 : FROM_CGI+1, -1); if (count <= 0) { #if 0 if (safe_waitpid(pid, &status, WNOHANG) <= 0) { @@ -1144,7 +1149,7 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post } if (pfd[TO_CGI].revents) { - /* hdr_cnt > 0 here due to the way pfd[TO_CGI].events set */ + /* hdr_cnt > 0 here due to the way poll() called */ /* Have data from peer and can write to CGI */ count = safe_write(toCgi_wr, hdr_ptr, hdr_cnt); /* Doesn't happen, we dont use nonblocking IO here -- cgit v1.2.3-55-g6feb From 32ed30d96b56ea7322218061f09e62feda9948e3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 17 Sep 2013 14:16:25 +0200 Subject: dumpkmap: code shrink function old new delta dumpkmap_main 223 160 -63 Signed-off-by: Denys Vlasenko --- console-tools/dumpkmap.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c index 6b923d2d4..bf8d690da 100644 --- a/console-tools/dumpkmap.c +++ b/console-tools/dumpkmap.c @@ -36,47 +36,56 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv) { struct kbentry ke; int i, j, fd; - RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS); +#define flags bb_common_bufsiz1 /* When user accidentally runs "dumpkmap FILE" * instead of "dumpkmap >FILE", we'd dump binary stuff to tty. - * Let's prevent it: */ + * Let's prevent it: + */ if (argv[1]) bb_show_usage(); /* bb_warn_ignoring_args(argv[1]);*/ fd = get_console_fd_or_die(); +#if 0 write(STDOUT_FILENO, "bkeymap", 7); - /* Here we want to set everything to 0 except for indexes: - * [0-2] [4-6] [8-10] [12] */ - memset(flags, 0x00, MAX_NR_KEYMAPS); + * [0-2] [4-6] [8-10] [12] + */ + /*memset(flags, 0x00, MAX_NR_KEYMAPS); - already is */ memset(flags, 0x01, 13); flags[3] = flags[7] = flags[11] = 0; - /* dump flags */ write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS); +#define flags7 flags +#else + /* Same effect */ + /* 0 1 2 3 4 5 6 7 8 9 a b c=12 */ + memcpy(flags, "bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1", + /* Can use sizeof, or sizeof-1. sizeof is even, using that */ + /****/ sizeof("bkeymap\1\1\1\0\1\1\1\0\1\1\1\0\1") + ); + write(STDOUT_FILENO, flags, 7 + MAX_NR_KEYMAPS); +#define flags7 (flags + 7) +#endif - for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (flags[i] == 1) { + for (i = 0; i < 13; i++) { + if (flags7[i]) { for (j = 0; j < NR_KEYS; j++) { ke.kb_index = j; ke.kb_table = i; if (!ioctl_or_perror(fd, KDGKBENT, &ke, - "ioctl failed with %s, %s, %p", - (char *)&ke.kb_index, - (char *)&ke.kb_table, - &ke.kb_value) + "ioctl(KDGKBENT{%d,%d}) failed", + j, i) ) { - write(STDOUT_FILENO, (void*)&ke.kb_value, 2); + write(STDOUT_FILENO, &ke.kb_value, 2); } } } } if (ENABLE_FEATURE_CLEAN_UP) { close(fd); - RELEASE_CONFIG_BUFFER(flags); } return EXIT_SUCCESS; } -- cgit v1.2.3-55-g6feb From d7ea34ee710fe97fc57235dce165fcc5f50a512a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 17 Sep 2013 16:24:01 +0200 Subject: Documentation update Signed-off-by: Denys Vlasenko --- docs/tcp.txt | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/tcp.txt b/docs/tcp.txt index 766766387..2000f3110 100644 --- a/docs/tcp.txt +++ b/docs/tcp.txt @@ -18,8 +18,11 @@ What will happen if we close the socket? received after close() is called, its TCP SHOULD send a RST to show that data was lost." -IOW: if we just close(sock) now, kernel can reset the TCP connection, -discarding some not-yet sent data. +IOW: if we just close(sock) now, kernel can reset the TCP connection +(send RST packet). + +This is problematic for two reasons: it discards some not-yet sent +data, and it may be reported as error, not EOF, on peer's side. What can be done about it? @@ -46,14 +49,14 @@ This makes kernel send FIN after all data is written: However, experiments on Linux 3.9.4 show that kernel can return from shutdown() and from close() before all data is sent, -and if peer sends any data to us after this, kernel stll responds with +and if peer sends any data to us after this, kernel still responds with RST before all our data is sent. In practice the protocol in use often does not allow peer to send such data to us, in which case this solution is acceptable. -If you know that peer is going to close its end after it sees our FIN -(as EOF), it might be a good idea to perform a read after shutdown(). +Solution #3: if you know that peer is going to close its end after it sees +our FIN (as EOF), it might be a good idea to perform a read after shutdown(). When read finishes with 0-sized result, we conclude that peer received all the data, saw EOF, and closed its end. @@ -61,6 +64,14 @@ However, this incurs small performance penalty (we run for a longer time) and requires safeguards (nonblocking reads, timeouts etc) against malicious peers which don't close the connection. +Solutions #1 and #2 can be combined: + + /* ...set up struct linger... then: */ + setsockopt(sock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger)); + shutdown(sock, SHUT_WR); + /* At this point, kernel sent FIN packet, not RST, to the peer, */ + /* even if there is buffered read data from the peer. */ + close(sock); Defeating Nagle. -- cgit v1.2.3-55-g6feb From a6ed6a31484243e684a51d4cb3114f17f44c3233 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 18 Sep 2013 12:08:41 +0200 Subject: httpd: make sire pfd[TO_CGI].revents is cleared before poll() Signed-off-by: Denys Vlasenko --- networking/httpd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index 143331389..621d9cddc 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1104,23 +1104,31 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post /* NB: breaking out of this loop jumps to log_and_exit() */ out_cnt = 0; + pfd[FROM_CGI].fd = fromCgi_rd; + pfd[FROM_CGI].events = POLLIN; + pfd[TO_CGI].fd = toCgi_wr; while (1) { /* Note: even pfd[0].events == 0 won't prevent * revents == POLLHUP|POLLERR reports from closed stdin. - * This works: */ + * Setting fd to -1 works: */ pfd[0].fd = -1; + pfd[0].events = POLLIN; + pfd[0].revents = 0; /* probably not needed, paranoia */ - pfd[FROM_CGI].fd = fromCgi_rd; - pfd[FROM_CGI].events = POLLIN; + /* We always poll this fd, thus kernel always sets revents: */ + /*pfd[FROM_CGI].events = POLLIN; - moved out of loop */ + /*pfd[FROM_CGI].revents = 0; - not needed */ - pfd[TO_CGI].fd = toCgi_wr; + /* gcc-4.8.0 still doesnt fill two shorts with one insn :( */ + /* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47059 */ + /* hopefully one day it will... */ pfd[TO_CGI].events = POLLOUT; + pfd[TO_CGI].revents = 0; /* needed! */ if (toCgi_wr && hdr_cnt <= 0) { if (post_len > 0) { /* Expect more POST data from network */ pfd[0].fd = 0; - pfd[0].events = POLLIN; } else { /* post_len <= 0 && hdr_cnt <= 0: * no more POST data to CGI, -- cgit v1.2.3-55-g6feb From 054f3eb7848230702b149a7e17f05314cb0157cb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 19 Sep 2013 17:56:59 +0200 Subject: loadkmap: explain what happens with K_ALLOCATED key value Signed-off-by: Denys Vlasenko --- console-tools/loadkmap.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c index bcffe16b1..66ec3b043 100644 --- a/console-tools/loadkmap.c +++ b/console-tools/loadkmap.c @@ -48,6 +48,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv) if (argv[1]) bb_show_usage(); /* bb_warn_ignoring_args(argv[1]); */ + fd = get_console_fd_or_die(); /* or maybe: opt = getopt32(argv, "C:", &tty_name); @@ -61,14 +62,24 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv) xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS); for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (flags[i] == 1) { - xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t)); - for (j = 0; j < NR_KEYS; j++) { - ke.kb_index = j; - ke.kb_table = i; - ke.kb_value = ibuff[j]; - ioctl(fd, KDSKBENT, &ke); - } + if (flags[i] != 1) + continue; + xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t)); + for (j = 0; j < NR_KEYS; j++) { + ke.kb_index = j; + ke.kb_table = i; + ke.kb_value = ibuff[j]; + /* + * Note: table[idx:0] can contain special value + * K_ALLOCATED (marks allocated tables in kernel). + * dumpkmap saves the value as-is; but attempts + * to load it here fail, since it isn't a valid + * key value: it is K(KT_SPEC,126) == 2<<8 + 126, + * whereas last valid KT_SPEC is + * K_BARENUMLOCK == K(KT_SPEC,19). + * So far we just ignore these errors: + */ + ioctl(fd, KDSKBENT, &ke); } } -- cgit v1.2.3-55-g6feb From 3eab2b7675fc7e2889cd69285a2a31980a4bf504 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 12 Sep 2013 00:29:40 -0400 Subject: trylink: only prefix libs with -l If our pkg-config queries pass back a flag like -pthread, the trylink script will expand that to -l-pthread. So change trylink to only add the -l prefix to a value that doesn't have a - prefix already. Reported-by: thaehaid@incognitomail.org Signed-off-by: Mike Frysinger --- scripts/trylink | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/trylink b/scripts/trylink index a8b0b2e03..e47169917 100755 --- a/scripts/trylink +++ b/scripts/trylink @@ -117,7 +117,7 @@ LDLIBS=`echo "$LDLIBS" | xargs -n1 | sort | uniq | xargs` # First link with all libs. If it fails, bail out echo "Trying libraries: $LDLIBS" # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" -l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` +l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" try $CC $CFLAGS $LDFLAGS \ -o $EXE \ @@ -141,7 +141,7 @@ while test "$LDLIBS"; do for one in $LDLIBS; do without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" - l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` + l_list=`echo " $without_one " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` test x"$l_list" != x"" && l_list="$START_GROUP $l_list $END_GROUP" $debug && echo "Trying -l options: '$l_list'" try $CC $CFLAGS $LDFLAGS \ @@ -172,7 +172,7 @@ done # Make the binary with final, minimal list of libs echo "Final link with: ${LDLIBS:-}" -l_list=`echo "$LDLIBS" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` +l_list=`echo " $LDLIBS " | sed -e 's: \([^- ][^ ]*\): -l\1:g'` test "x$l_list" != "x" && l_list="$START_GROUP $l_list $END_GROUP" # --verbose gives us gobs of info to stdout (e.g. linker script used) if ! test -f busybox_ldscript; then -- cgit v1.2.3-55-g6feb From cd256e1c407aa70dfefb7178ed2c0e4201f1aaf7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Oct 2013 15:14:25 +0200 Subject: wall: access FILE under real user's credentials While at it, move applet/config/kbuild bits into wall.c. (This way, it's more visible that applet is suid'ed). function old new delta wall_main 87 138 +51 Signed-off-by: Denys Vlasenko --- include/applets.src.h | 2 -- miscutils/Config.src | 7 ------- miscutils/Kbuild.src | 1 - miscutils/wall.c | 25 ++++++++++++++++++++++++- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index aa319bbc9..3a47e15b9 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -407,8 +407,6 @@ IF_VCONFIG(APPLET(vconfig, BB_DIR_SBIN, BB_SUID_DROP)) /* Needs to be run by root or be suid root - needs to change uid and gid: */ IF_VLOCK(APPLET(vlock, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) IF_VOLNAME(APPLET(volname, BB_DIR_USR_BIN, BB_SUID_DROP)) -/* Needs to be run by root or be suid root - needs to write to /dev/TTY: */ -IF_WALL(APPLET(wall, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) IF_WATCH(APPLET(watch, BB_DIR_BIN, BB_SUID_DROP)) IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP)) IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP)) diff --git a/miscutils/Config.src b/miscutils/Config.src index b9fc196d8..117ec7739 100644 --- a/miscutils/Config.src +++ b/miscutils/Config.src @@ -591,13 +591,6 @@ config VOLNAME help Prints a CD-ROM volume name. -config WALL - bool "wall" - default y - depends on FEATURE_UTMP - help - Write a message to all users that are logged in. - config WATCHDOG bool "watchdog" default y diff --git a/miscutils/Kbuild.src b/miscutils/Kbuild.src index 8c498643b..f3954f407 100644 --- a/miscutils/Kbuild.src +++ b/miscutils/Kbuild.src @@ -46,5 +46,4 @@ lib-$(CONFIG_TIME) += time.o lib-$(CONFIG_TIMEOUT) += timeout.o lib-$(CONFIG_TTYSIZE) += ttysize.o lib-$(CONFIG_VOLNAME) += volname.o -lib-$(CONFIG_WALL) += wall.o lib-$(CONFIG_WATCHDOG) += watchdog.o diff --git a/miscutils/wall.c b/miscutils/wall.c index 762f53b72..c74f4f27b 100644 --- a/miscutils/wall.c +++ b/miscutils/wall.c @@ -6,6 +6,18 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config WALL +//config: bool "wall" +//config: default y +//config: depends on FEATURE_UTMP +//config: help +//config: Write a message to all users that are logged in. + +/* Needs to be run by root or be suid root - needs to write to /dev/TTY: */ +//applet:IF_WALL(APPLET(wall, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) + +//kbuild:lib-$(CONFIG_WALL) += wall.o + //usage:#define wall_trivial_usage //usage: "[FILE]" //usage:#define wall_full_usage "\n\n" @@ -22,8 +34,19 @@ int wall_main(int argc UNUSED_PARAM, char **argv) { struct utmp *ut; char *msg; - int fd = argv[1] ? xopen(argv[1], O_RDONLY) : STDIN_FILENO; + int fd; + fd = STDIN_FILENO; + if (argv[1]) { + /* The applet is setuid. + * Access to the file must be under user's uid/gid. + */ + setfsuid(getuid()); + setfsgid(getgid()); + fd = xopen(argv[1], O_RDONLY); + setfsuid(geteuid()); + setfsgid(getegid()); + } msg = xmalloc_read(fd, NULL); if (ENABLE_FEATURE_CLEAN_UP && argv[1]) close(fd); -- cgit v1.2.3-55-g6feb From 932e233a491b6a5b9293ace04ef74667a95d739c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Oct 2013 22:53:14 +0200 Subject: bunzip2: fix off-by-one check stage3-armv7a_hardfp-20130209.tar.bz2, 149189948 bytes long, md5sum b29ce23312e14eb15a143377d4a38473, was failing to unpack. It so happened that this file has a run which exactly fills the 90k buffer. The check was "size >= bufsize", apparently it has to be ">". Signed-off-by: Denys Vlasenko --- archival/libarchive/decompress_bunzip2.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c index dc252bb82..fb1f2921f 100644 --- a/archival/libarchive/decompress_bunzip2.c +++ b/archival/libarchive/decompress_bunzip2.c @@ -42,6 +42,12 @@ #include "libbb.h" #include "bb_archive.h" +#if 0 +# define dbg(...) bb_error_msg(__VA_ARGS__) +#else +# define dbg(...) ((void)0) +#endif + /* Constants for Huffman coding */ #define MAX_GROUPS 6 #define GROUP_SIZE 50 /* 64 would have been more efficient */ @@ -52,13 +58,13 @@ /* Status return values */ #define RETVAL_OK 0 -#define RETVAL_LAST_BLOCK (-1) -#define RETVAL_NOT_BZIP_DATA (-2) -#define RETVAL_UNEXPECTED_INPUT_EOF (-3) -#define RETVAL_SHORT_WRITE (-4) -#define RETVAL_DATA_ERROR (-5) -#define RETVAL_OUT_OF_MEMORY (-6) -#define RETVAL_OBSOLETE_INPUT (-7) +#define RETVAL_LAST_BLOCK (dbg("%d", __LINE__), -1) +#define RETVAL_NOT_BZIP_DATA (dbg("%d", __LINE__), -2) +#define RETVAL_UNEXPECTED_INPUT_EOF (dbg("%d", __LINE__), -3) +#define RETVAL_SHORT_WRITE (dbg("%d", __LINE__), -4) +#define RETVAL_DATA_ERROR (dbg("%d", __LINE__), -5) +#define RETVAL_OUT_OF_MEMORY (dbg("%d", __LINE__), -6) +#define RETVAL_OBSOLETE_INPUT (dbg("%d", __LINE__), -7) /* Other housekeeping constants */ #define IOBUF_SIZE 4096 @@ -440,7 +446,11 @@ static int get_next_block(bunzip_data *bd) literal used is the one at the head of the mtfSymbol array.) */ if (runPos != 0) { uint8_t tmp_byte; - if (dbufCount + runCnt >= dbufSize) return RETVAL_DATA_ERROR; + if (dbufCount + runCnt > dbufSize) { + dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR", + dbufCount, runCnt, dbufCount + runCnt, dbufSize); + return RETVAL_DATA_ERROR; + } tmp_byte = symToByte[mtfSymbol[0]]; byteCount[tmp_byte] += runCnt; while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte; -- cgit v1.2.3-55-g6feb From 5906a5c26c392b9687d14951a6da3a5195b576be Mon Sep 17 00:00:00 2001 From: Ryan Mallon Date: Tue, 8 Oct 2013 14:52:49 +0200 Subject: libbb: Add xsetegid(), xseteuid(), xopen_as_uid_gid() functions Signed-off-by: Ryan Mallon Signed-off-by: Denys Vlasenko --- include/libbb.h | 9 ++++++--- libbb/xfuncs_printf.c | 45 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 1315e5f8f..3ab1d6b46 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -461,6 +461,8 @@ void record_signo(int signo); /* not FAST_FUNC! */ void xsetgid(gid_t gid) FAST_FUNC; void xsetuid(uid_t uid) FAST_FUNC; +void xsetegid(gid_t egid) FAST_FUNC; +void xseteuid(uid_t euid) FAST_FUNC; void xchdir(const char *path) FAST_FUNC; void xchroot(const char *path) FAST_FUNC; void xsetenv(const char *key, const char *value) FAST_FUNC; @@ -469,11 +471,12 @@ void bb_unsetenv_and_free(char *key) FAST_FUNC; void xunlink(const char *pathname) FAST_FUNC; void xstat(const char *pathname, struct stat *buf) FAST_FUNC; void xfstat(int fd, struct stat *buf, const char *errmsg) FAST_FUNC; +int open3_or_warn(const char *pathname, int flags, int mode) FAST_FUNC; +int open_or_warn(const char *pathname, int flags) FAST_FUNC; +int xopen3(const char *pathname, int flags, int mode) FAST_FUNC; int xopen(const char *pathname, int flags) FAST_FUNC; int xopen_nonblocking(const char *pathname) FAST_FUNC; -int xopen3(const char *pathname, int flags, int mode) FAST_FUNC; -int open_or_warn(const char *pathname, int flags) FAST_FUNC; -int open3_or_warn(const char *pathname, int flags, int mode) FAST_FUNC; +int xopen_as_uid_gid(const char *pathname, int flags, uid_t u, gid_t g) FAST_FUNC; int open_or_warn_stdin(const char *pathname) FAST_FUNC; int xopen_stdin(const char *pathname) FAST_FUNC; void xrename(const char *oldpath, const char *newpath) FAST_FUNC; diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index a70683241..e4ac6a002 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -140,15 +140,6 @@ int FAST_FUNC xopen(const char *pathname, int flags) return xopen3(pathname, flags, 0666); } -/* Die if we can't open an existing file readonly with O_NONBLOCK - * and return the fd. - * Note that for ioctl O_RDONLY is sufficient. - */ -int FAST_FUNC xopen_nonblocking(const char *pathname) -{ - return xopen(pathname, O_RDONLY | O_NONBLOCK); -} - // Warn if we can't open a file and return a fd. int FAST_FUNC open3_or_warn(const char *pathname, int flags, int mode) { @@ -167,6 +158,32 @@ int FAST_FUNC open_or_warn(const char *pathname, int flags) return open3_or_warn(pathname, flags, 0666); } +/* Die if we can't open an existing file readonly with O_NONBLOCK + * and return the fd. + * Note that for ioctl O_RDONLY is sufficient. + */ +int FAST_FUNC xopen_nonblocking(const char *pathname) +{ + return xopen(pathname, O_RDONLY | O_NONBLOCK); +} + +int FAST_FUNC xopen_as_uid_gid(const char *pathname, int flags, uid_t u, gid_t g) +{ + int fd; + uid_t old_euid = geteuid(); + gid_t old_egid = getegid(); + + xsetegid(g); + xseteuid(u); + + fd = xopen(pathname, flags); + + xseteuid(old_euid); + xsetegid(old_egid); + + return fd; +} + void FAST_FUNC xunlink(const char *pathname) { if (unlink(pathname)) @@ -351,6 +368,16 @@ void FAST_FUNC xsetuid(uid_t uid) if (setuid(uid)) bb_perror_msg_and_die("setuid"); } +void FAST_FUNC xsetegid(gid_t egid) +{ + if (setegid(egid)) bb_perror_msg_and_die("setegid"); +} + +void FAST_FUNC xseteuid(uid_t euid) +{ + if (seteuid(euid)) bb_perror_msg_and_die("seteuid"); +} + // Die if we can't chdir to a new path. void FAST_FUNC xchdir(const char *path) { -- cgit v1.2.3-55-g6feb From 1d30b3f1f66a0cd179f47082245079ef357b6a66 Mon Sep 17 00:00:00 2001 From: Ryan Mallon Date: Tue, 8 Oct 2013 14:53:29 +0200 Subject: wall,crontab: use xopen_as_uid_gid() This fixes a narrow security race in crontab. function old new delta xopen_as_uid_gid - 80 +80 seteuid - 64 +64 setegid - 64 +64 setreuid - 37 +37 xseteuid - 22 +22 xsetegid - 22 +22 crontab_main 590 577 -13 setfsuid 33 - -33 setfsgid 33 - -33 wall_main 138 102 -36 open_as_user 109 - -109 text data bss dec hex filename 893539 497 7568 901604 dc1e4 busybox_old 893618 497 7568 901683 dc233 busybox_unstripped Signed-off-by: Ryan Mallon Signed-off-by: Denys Vlasenko --- miscutils/crontab.c | 27 +-------------------------- miscutils/wall.c | 6 +----- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/miscutils/crontab.c b/miscutils/crontab.c index 4731d8da6..aad242fd8 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -55,28 +55,6 @@ static void edit_file(const struct passwd *pas, const char *file) bb_perror_msg_and_die("can't execute '%s'", ptr); } -static int open_as_user(const struct passwd *pas, const char *file) -{ - pid_t pid; - char c; - - pid = xvfork(); - if (pid) { /* PARENT */ - if (wait4pid(pid) == 0) { - /* exitcode 0: child says it can read */ - return open(file, O_RDONLY); - } - return -1; - } - - /* CHILD */ - /* initgroups, setgid, setuid */ - change_identity(pas); - /* We just try to read one byte. If it works, file is readable - * under this user. We signal that by exiting with 0. */ - _exit(safe_read(xopen(file, O_RDONLY), &c, 1) < 0); -} - int crontab_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int crontab_main(int argc UNUSED_PARAM, char **argv) { @@ -137,10 +115,7 @@ int crontab_main(int argc UNUSED_PARAM, char **argv) if (!argv[0]) bb_show_usage(); if (NOT_LONE_DASH(argv[0])) { - src_fd = open_as_user(pas, argv[0]); - if (src_fd < 0) - bb_error_msg_and_die("user %s cannot read %s", - pas->pw_name, argv[0]); + src_fd = xopen_as_uid_gid(argv[0], O_RDONLY, pas->pw_uid, pas->pw_gid); } } diff --git a/miscutils/wall.c b/miscutils/wall.c index c74f4f27b..bb709ee39 100644 --- a/miscutils/wall.c +++ b/miscutils/wall.c @@ -41,11 +41,7 @@ int wall_main(int argc UNUSED_PARAM, char **argv) /* The applet is setuid. * Access to the file must be under user's uid/gid. */ - setfsuid(getuid()); - setfsgid(getgid()); - fd = xopen(argv[1], O_RDONLY); - setfsuid(geteuid()); - setfsgid(getegid()); + fd = xopen_as_uid_gid(argv[1], O_RDONLY, getuid(), getgid()); } msg = xmalloc_read(fd, NULL); if (ENABLE_FEATURE_CLEAN_UP && argv[1]) -- cgit v1.2.3-55-g6feb From 7985bc109e0d738644094f391d08d9848a2f2b50 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 12 Oct 2013 04:51:54 +0200 Subject: awk: fix length(array) function old new delta evaluate 3526 3548 +22 Signed-off-by: Denys Vlasenko --- editors/awk.c | 10 +++++++++- testsuite/awk.tests | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/editors/awk.c b/editors/awk.c index 77784dfc1..8848d94a5 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2784,8 +2784,16 @@ static var *evaluate(node *op, var *res) break; case F_le: - if (!op1) + debug_printf_eval("length: L.s:'%s'\n", L.s); + if (!op1) { L.s = getvar_s(intvar[F0]); + debug_printf_eval("length: L.s='%s'\n", L.s); + } + else if (L.v->type & VF_ARRAY) { + R_d = L.v->x.array->nel; + debug_printf_eval("length: array_len:%d\n", L.v->x.array->nel); + break; + } R_d = strlen(L.s); break; diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 6af6072b8..a02302405 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -274,6 +274,11 @@ testing "awk large integer" \ "2147483647 2147483647 0 2147483648 2147483648 0\n" \ "" "" +testing "awk length(array)" \ + "awk 'BEGIN{ A[1]=2; A["qwe"]="asd"; print length(A)}'" \ + "2\n" \ + "" "" + # testing "description" "command" "result" "infile" "stdin" exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From 730e4d8b5245502803c9c2335e96d81f70d63012 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 12 Oct 2013 04:52:22 +0200 Subject: init: better --help text Signed-off-by: Denys Vlasenko --- init/init.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/init/init.c b/init/init.c index edb5be696..cc6a2b5be 100644 --- a/init/init.c +++ b/init/init.c @@ -9,11 +9,6 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -//applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP)) -//applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) - -//kbuild:lib-$(CONFIG_INIT) += init.o - //config:config INIT //config: bool "init" //config: default y @@ -108,6 +103,11 @@ //config: Note that on Linux, init attempts to detect serial terminal and //config: sets TERM to "vt102" if one is found. +//applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP)) +//applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) + +//kbuild:lib-$(CONFIG_INIT) += init.o + #define DEBUG_SEGV_HANDLER 0 #include "libbb.h" @@ -1230,7 +1230,14 @@ int init_main(int argc UNUSED_PARAM, char **argv) //usage:#define init_trivial_usage //usage: "" //usage:#define init_full_usage "\n\n" -//usage: "Init is the parent of all processes" +//usage: "Init is the first process started during boot. It never exits." +//usage: IF_FEATURE_USE_INITTAB( +//usage: "\n""It (re)spawns children according to /etc/inittab." +//usage: ) +//usage: IF_NOT_FEATURE_USE_INITTAB( +//usage: "\n""This version of init doesn't use /etc/inittab," +//usage: "\n""has fixed set of processed to run." +//usage: ) //usage: //usage:#define init_notes_usage //usage: "This version of init is designed to be run only by the kernel.\n" -- cgit v1.2.3-55-g6feb From d074b416f8d3ca6b6ae7b44d17e204ea8d81e7a0 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Sat, 12 Oct 2013 21:47:07 +0200 Subject: wget: add support for connect timeout function old new delta open_socket 33 64 +31 wget_main 2182 2194 +12 Signed-off-by: Lauri Kasanen Signed-off-by: Denys Vlasenko --- networking/Config.src | 16 +++++++++------- networking/wget.c | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/networking/Config.src b/networking/Config.src index e1ae0c9d5..ca0ddcdd9 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -970,16 +970,18 @@ config FEATURE_WGET_LONG_OPTIONS Support long options for the wget applet. config FEATURE_WGET_TIMEOUT - bool "Enable read timeout option -T SEC" + bool "Enable timeout option -T SEC" default y depends on WGET help - Supports network read timeout for wget, so that wget will give - up and timeout when reading network data, through the -T command - line option. Currently only network data read timeout is - supported (i.e., timeout is not applied to the DNS nor TCP - connection initialization). When FEATURE_WGET_LONG_OPTIONS is - also enabled, the --timeout option will work in addition to -T. + Supports network read and connect timeouts for wget, + so that wget will give up and timeout, through the -T + command line option. + + Currently only connect and network data read timeout are + supported (i.e., timeout is not applied to the DNS query). When + FEATURE_WGET_LONG_OPTIONS is also enabled, the --timeout option + will work in addition to -T. config ZCIP bool "zcip" diff --git a/networking/wget.c b/networking/wget.c index 5dac2b500..a32f85229 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -72,6 +72,7 @@ struct globals { const char *user_agent; /* "User-Agent" header field */ #if ENABLE_FEATURE_WGET_TIMEOUT unsigned timeout_seconds; + bool connecting; #endif int output_fd; int o_flags; @@ -87,7 +88,6 @@ struct globals { #define G (*ptr_to_globals) #define INIT_G() do { \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ - IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;) \ } while (0) @@ -195,13 +195,27 @@ static char* sanitize_string(char *s) return s; } +#if ENABLE_FEATURE_WGET_TIMEOUT +static void alarm_handler(int sig UNUSED_PARAM) +{ + /* This is theoretically unsafe (uses stdio and malloc in signal handler) */ + if (G.connecting) + bb_error_msg_and_die("download timed out"); +} +#endif + static FILE *open_socket(len_and_sockaddr *lsa) { + int fd; FILE *fp; + IF_FEATURE_WGET_TIMEOUT(alarm(G.timeout_seconds); G.connecting = 1;) + fd = xconnect_stream(lsa); + IF_FEATURE_WGET_TIMEOUT(G.connecting = 0;) + /* glibc 2.4 seems to try seeking on it - ??! */ /* hopefully it understands what ESPIPE means... */ - fp = fdopen(xconnect_stream(lsa), "r+"); + fp = fdopen(fd, "r+"); if (fp == NULL) bb_perror_msg_and_die(bb_msg_memory_exhausted); @@ -209,6 +223,7 @@ static FILE *open_socket(len_and_sockaddr *lsa) } /* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */ +/* FIXME: does not respect FEATURE_WGET_TIMEOUT and -T N: */ static char fgets_and_trim(FILE *fp) { char c; @@ -944,7 +959,10 @@ int wget_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;) +#if ENABLE_FEATURE_WGET_TIMEOUT + G.timeout_seconds = 900; + signal(SIGALRM, alarm_handler); +#endif G.proxy_flag = "on"; /* use proxies if env vars are set */ G.user_agent = "Wget"; /* "User-Agent" header field */ -- cgit v1.2.3-55-g6feb From eba5faec67da1c95cf9616b5deacbea24fbd3998 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Oct 2013 19:04:20 +0200 Subject: ether-wake: shorten help text, reduce packet buffer size function old new delta ether_wake_main 726 727 +1 packed_usage 29468 29434 -34 Signed-off-by: Denys Vlasenko --- networking/ether-wake.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/networking/ether-wake.c b/networking/ether-wake.c index 2d389ea30..c38547dda 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c @@ -62,17 +62,17 @@ * An alternative to needing 'root' is using a UDP broadcast socket, however * doing so only works with adapters configured for unicast+broadcast Rx * filter. That configuration consumes more power. -*/ + */ //usage:#define ether_wake_trivial_usage -//usage: "[-b] [-i iface] [-p aa:bb:cc:dd[:ee:ff]] MAC" +//usage: "[-b] [-i IFACE] [-p aa:bb:cc:dd[:ee:ff]/a.b.c.d] MAC" //usage:#define ether_wake_full_usage "\n\n" //usage: "Send a magic packet to wake up sleeping machines.\n" //usage: "MAC must be a station address (00:11:22:33:44:55) or\n" //usage: "a hostname with a known 'ethers' entry.\n" -//usage: "\n -b Send wake-up packet to the broadcast address" -//usage: "\n -i iface Interface to use (default eth0)" -//usage: "\n -p pass Append four or six byte password PW to the packet" +//usage: "\n -b Broadcast the packet" +//usage: "\n -i IFACE Interface to use (default eth0)" +//usage: "\n -p PASSWORD Append four or six byte PASSWORD to the packet" #include "libbb.h" #include @@ -130,7 +130,8 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) } } -static int get_fill(unsigned char *pkt, struct ether_addr *eaddr, int broadcast) +#define PKT_HEADER_SIZE (20 + 16*6) +static int fill_pkt_header(unsigned char *pkt, struct ether_addr *eaddr, int broadcast) { int i; unsigned char *station_addr = eaddr->ether_addr_octet; @@ -153,7 +154,7 @@ static int get_fill(unsigned char *pkt, struct ether_addr *eaddr, int broadcast) memcpy(pkt, station_addr, 6); /* 20,26,32,... */ } - return 20 + 16*6; /* length of packet */ + return PKT_HEADER_SIZE; /* length of packet */ } static int get_wol_pw(const char *ethoptarg, unsigned char *wol_passwd) @@ -195,7 +196,7 @@ int ether_wake_main(int argc UNUSED_PARAM, char **argv) int wol_passwd_sz = 0; int s; /* Raw socket */ int pktsize; - unsigned char outpack[1000]; + unsigned char outpack[PKT_HEADER_SIZE + 6 /* max passwd size */ + 16 /* paranoia */]; struct ether_addr eaddr; struct whereto_t whereto; /* who to wake up */ @@ -217,7 +218,7 @@ int ether_wake_main(int argc UNUSED_PARAM, char **argv) get_dest_addr(argv[optind], &eaddr); /* fill out the header of the packet */ - pktsize = get_fill(outpack, &eaddr, flags /* & 1 OPT_BROADCAST */); + pktsize = fill_pkt_header(outpack, &eaddr, flags /* & 1 OPT_BROADCAST */); bb_debug_dump_packet(outpack, pktsize); -- cgit v1.2.3-55-g6feb From 5117eff6f938a6daa269f965a52abc93b49d90d6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Oct 2013 14:21:20 +0200 Subject: Fix some compiler warnings emitted by gcc-4.8.0 Signed-off-by: Denys Vlasenko --- archival/libarchive/bz/compress.c | 12 ++++++------ archival/libarchive/lzo1x_9x.c | 2 +- debianutils/run_parts.c | 2 +- networking/ping.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/archival/libarchive/bz/compress.c b/archival/libarchive/bz/compress.c index e9f1afdaf..a7dd72d9e 100644 --- a/archival/libarchive/bz/compress.c +++ b/archival/libarchive/bz/compress.c @@ -501,14 +501,14 @@ void sendMTFValues(EState* s) for (i = 0; i < 16; i++) { if (sizeof(long) <= 4) { inUse16 = inUse16*2 + - ((*(uint32_t*)&(s->inUse[i * 16 + 0]) - | *(uint32_t*)&(s->inUse[i * 16 + 4]) - | *(uint32_t*)&(s->inUse[i * 16 + 8]) - | *(uint32_t*)&(s->inUse[i * 16 + 12])) != 0); + ((*(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 0]) + | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 4]) + | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 8]) + | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 12])) != 0); } else { /* Our CPU can do better */ inUse16 = inUse16*2 + - ((*(uint64_t*)&(s->inUse[i * 16 + 0]) - | *(uint64_t*)&(s->inUse[i * 16 + 8])) != 0); + ((*(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 0]) + | *(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 8])) != 0); } } diff --git a/archival/libarchive/lzo1x_9x.c b/archival/libarchive/lzo1x_9x.c index 897132987..3e331984d 100644 --- a/archival/libarchive/lzo1x_9x.c +++ b/archival/libarchive/lzo1x_9x.c @@ -94,7 +94,7 @@ typedef struct { ( ((0x9f5f * ((((b[p]<<5)^b[p+1])<<5) ^ b[p+2])) >> 5) & (SWD_HSIZE-1) ) #if defined(LZO_UNALIGNED_OK_2) -# define HEAD2(b,p) (* (uint16_t *) &(b[p])) +# define HEAD2(b,p) (* (bb__aliased_uint16_t *) &(b[p])) #else # define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8)) #endif diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 2c2b032be..527fae227 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c @@ -59,7 +59,7 @@ struct globals { char **names; int cur; - char *cmd[1]; + char *cmd[2 /* using 1 provokes compiler warning */]; } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) #define names (G.names) diff --git a/networking/ping.c b/networking/ping.c index f27e2143d..5e4771f5a 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -516,7 +516,7 @@ static void sendping6(int junk UNUSED_PARAM) pkt->icmp6_id = myid; /*if (datalen >= 4)*/ - *(uint32_t*)(&pkt->icmp6_data8[4]) = monotonic_us(); + *(bb__aliased_uint32_t*)(&pkt->icmp6_data8[4]) = monotonic_us(); //TODO? pkt->icmp_cksum = inet_cksum(...); -- cgit v1.2.3-55-g6feb From 840ef17f63c85044c15d9a38a13c6539e26dfc31 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Wed, 16 Oct 2013 14:43:30 +0200 Subject: wget: if FEATURE_CLEAN_UP, free(ptr_to_globals) Signed-off-by: Guilherme Maciel Ferreira Signed-off-by: Denys Vlasenko --- include/libbb.h | 5 +++++ networking/wget.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/include/libbb.h b/include/libbb.h index 3ab1d6b46..c96546109 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1773,6 +1773,11 @@ extern struct globals *const ptr_to_globals; (*(struct globals**)&ptr_to_globals) = (void*)(x); \ barrier(); \ } while (0) +#define FREE_PTR_TO_GLOBALS() do { \ + if (ENABLE_FEATURE_CLEAN_UP) { \ + free(ptr_to_globals); \ + } \ +} while (0) /* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it, * use bb_default_login_shell and following defines. diff --git a/networking/wget.c b/networking/wget.c index a32f85229..cfbaceced 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -89,6 +89,9 @@ struct globals { #define INIT_G() do { \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ } while (0) +#define FINI_G() do { \ + FREE_PTR_TO_GLOBALS(); \ +} while (0) /* Must match option string! */ @@ -1013,5 +1016,10 @@ int wget_main(int argc UNUSED_PARAM, char **argv) if (G.output_fd >= 0) xclose(G.output_fd); +#if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_WGET_LONG_OPTIONS + free(G.extra_headers); +#endif + FINI_G(); + return EXIT_SUCCESS; } -- cgit v1.2.3-55-g6feb From 64938011f3ba06a8f425926397172dc361bce851 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 14 Oct 2013 20:11:55 +0200 Subject: tail compat: fix header printing for tail -f Makes tail -f for multiple files display the header only if another (ie. not currently displayed) file changed. Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- TODO | 5 ----- coreutils/tail.c | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index d2a085ede..dcf48c2c2 100644 --- a/TODO +++ b/TODO @@ -127,11 +127,6 @@ patch And while we're at it, a new patch filename quoting format is apparently coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2 ---- -tail - ./busybox tail -f foo.c~ TODO - should not print fmt=header_fmt for subsequent date >> TODO; i.e. only - fmt+ if another (not the current) file did change Architectural issues: diff --git a/coreutils/tail.c b/coreutils/tail.c index 07c71ca4b..eab502beb 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -105,6 +105,7 @@ int tail_main(int argc, char **argv) int *fds; const char *fmt; + int prev_fd; INIT_G(); @@ -309,6 +310,7 @@ int tail_main(int argc, char **argv) xwrite(STDOUT_FILENO, tailbuf, taillen); } } while (++i < nfiles); + prev_fd = fds[i-1]; tailbuf = xrealloc(tailbuf, BUFSIZ); @@ -365,9 +367,10 @@ int tail_main(int argc, char **argv) nread = tail_read(fd, tailbuf, BUFSIZ); if (nread <= 0) break; - if (fmt) { + if (fmt && (fd != prev_fd)) { tail_xprint_header(fmt, filename); fmt = NULL; + prev_fd = fd; } xwrite(STDOUT_FILENO, tailbuf, nread); } -- cgit v1.2.3-55-g6feb From 28a209466f43c22db42dd02baa136ac7ac25069b Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Wed, 16 Oct 2013 19:18:05 +0200 Subject: bloat-o-meter: add usage info Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- docs/keep_data_small.txt | 15 ++++++++------- scripts/bloat-o-meter | 11 ++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/keep_data_small.txt b/docs/keep_data_small.txt index 21d732674..9fc799646 100644 --- a/docs/keep_data_small.txt +++ b/docs/keep_data_small.txt @@ -138,13 +138,6 @@ less readable, use #defines: #define sector (G.sector) - Word of caution - -If applet doesn't use much of global data, converting it to use -one of above methods is not worth the resulting code obfuscation. -If you have less than ~300 bytes of global data - don't bother. - - Finding non-shared duplicated strings strings busybox | sort | uniq -c | sort -nr @@ -224,6 +217,14 @@ Result (non-static busybox built against glibc): Keeping code small +Use scripts/bloat-o-meter to check whether introduced changes +didn't generate unnecessary bloat. This script needs unstripped binaries +to generate a detailed report. To automate this, just use +"make bloatcheck". It requires busybox_old binary to be present, +use "make baseline" to generate it from unmodified source, or +copy busybox_unstripped to busybox_old before modifying sources +and rebuilding. + Set CONFIG_EXTRA_CFLAGS="-fno-inline-functions-called-once", produce "make bloatcheck", see the biggest auto-inlined functions. Now, set CONFIG_EXTRA_CFLAGS back to "", but add NOINLINE diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter index 6db2a5e58..cb861b8e9 100755 --- a/scripts/bloat-o-meter +++ b/scripts/bloat-o-meter @@ -7,11 +7,14 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import sys, os#, re +import sys, os def usage(): - sys.stderr.write("usage: %s [-t] file1 file2\n" % sys.argv[0]) - sys.exit(-1) + sys.stderr.write("usage: %s [-t] file1 file2 [-- ]\n" + % sys.argv[0]) + sys.stderr.write("\t-t\tShow time spent on parsing/processing\n") + sys.stderr.write("\t--\tPass additional parameters to readelf\n") + sys.exit(1) f1, f2 = (None, None) flag_timing, dashes = (False, False) @@ -31,6 +34,8 @@ for f in sys.argv[1:]: f1 = f elif f2 is None: f2 = f + else: + usage() if flag_timing: import time if f1 is None or f2 is None: -- cgit v1.2.3-55-g6feb From af4f0e48eccd1ab1abe361bb70960a8b73775722 Mon Sep 17 00:00:00 2001 From: Thomas Petazzoni Date: Wed, 16 Oct 2013 19:59:45 +0200 Subject: libbb: use instead of Signed-off-by: Thomas Petazzoni Signed-off-by: Denys Vlasenko --- include/libbb.h | 4 ++-- runit/runsv.c | 1 - runit/runsvdir.c | 1 - runit/sv.c | 1 - runit/svlogd.c | 1 - 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index c96546109..58271655d 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -32,12 +32,12 @@ #include #include #include -/* There are two incompatible basename's, let not use them! */ +/* There are two incompatible basename's, let's not use them! */ /* See the dirname/basename man page for details */ #include /* dirname,basename */ #undef basename #define basename dont_use_basename -#include +#include #include #include #include diff --git a/runit/runsv.c b/runit/runsv.c index 3e1a3c8e5..d941e897d 100644 --- a/runit/runsv.c +++ b/runit/runsv.c @@ -33,7 +33,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //usage:#define runsv_full_usage "\n\n" //usage: "Start and monitor a service and optionally an appendant log service" -#include #include #include "libbb.h" #include "runit_lib.h" diff --git a/runit/runsvdir.c b/runit/runsvdir.c index 32526cf4c..af7e75ba7 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c @@ -35,7 +35,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //usage: "\n -P Put each runsv in a new session" //usage: "\n -s SCRIPT Run SCRIPT after signal is processed" -#include #include #include "libbb.h" #include "runit_lib.h" diff --git a/runit/sv.c b/runit/sv.c index 5b01c875c..825e9d45b 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -169,7 +169,6 @@ Exit Codes //usage: "pause, cont, hup, alarm, interrupt, quit, 1, 2, term, kill: send\n" //usage: "STOP, CONT, HUP, ALRM, INT, QUIT, USR1, USR2, TERM, KILL signal to service" -#include #include #include "libbb.h" #include "runit_lib.h" diff --git a/runit/svlogd.c b/runit/svlogd.c index 8b8a6d858..c080b9acc 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -142,7 +142,6 @@ log message, you can use a pattern like this instead //usage: "\n""+,-PATTERN - (de)select line for logging" //usage: "\n""E,ePATTERN - (de)select line for stderr" -#include #include #include "libbb.h" #include "runit_lib.h" -- cgit v1.2.3-55-g6feb From 2d576e2a220e28fe815ea02c38c9bfe9195406c2 Mon Sep 17 00:00:00 2001 From: Johannes Stezenbach Date: Mon, 28 Oct 2013 23:27:37 +0100 Subject: udhcpc: make DHCP packets to have at least 300 DHCP bytes Commit b8b72f02 removed all padding from DHCP packets to fix operation with buggy servers which can't handle maximum sized packets. But it introduced a regression with buggy routers which drop DHCP packets smaller than 300 bytes (i.e. 342 byte ethernet packets). Add back some padding to work around. function old new delta udhcp_send_kernel_packet 268 292 +24 udhcp_send_raw_packet 462 473 +11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 35/0) Total: 35 bytes Signed-off-by: Johannes Stezenbach Signed-off-by: Denys Vlasenko --- networking/udhcp/packet.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 33c9585cf..148f52551 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c @@ -143,8 +143,15 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt, * * In order to work with those buggy servers, * we truncate packets after end option byte. + * + * However, RFC 1542 says "The IP Total Length and UDP Length + * must be large enough to contain the minimal BOOTP header of 300 octets". + * Thus, we retain enough padding to not go below 300 BOOTP bytes. + * Some devices have filters which drop DHCP packets shorter than that. */ padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(packet.data.options); + if (padding > DHCP_SIZE - 300) + padding = DHCP_SIZE - 300; packet.ip.protocol = IPPROTO_UDP; packet.ip.saddr = source_nip; @@ -215,6 +222,8 @@ int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt, udhcp_dump_packet(dhcp_pkt); padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(dhcp_pkt->options); + if (padding > DHCP_SIZE - 300) + padding = DHCP_SIZE - 300; result = safe_write(fd, dhcp_pkt, DHCP_SIZE - padding); msg = "write"; ret_close: -- cgit v1.2.3-55-g6feb From af0cdeedc699da96e2f38c3f321150cdaa3bb7d6 Mon Sep 17 00:00:00 2001 From: "David A. Wheeler" Date: Tue, 29 Oct 2013 00:52:48 +0100 Subject: sed: accept -E as a synonym for -r Signed-off-by: David A. Wheeler Signed-off-by: Denys Vlasenko --- editors/sed.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 3a0d917aa..ef462843b 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -1435,15 +1435,21 @@ int sed_main(int argc UNUSED_PARAM, char **argv) IF_LONG_OPTS(applet_long_options = sed_longopts); /* -i must be first, to match OPT_in_place definition */ - opt = getopt32(argv, "i::rne:f:", &opt_i, &opt_e, &opt_f, + /* -E is a synonym of -r: + * GNU sed 4.2.1 mentions it in neither --help + * nor manpage, but does recognize it. + */ + opt = getopt32(argv, "i::rEne:f:", &opt_i, &opt_e, &opt_f, &G.be_quiet); /* counter for -n */ //argc -= optind; argv += optind; if (opt & OPT_in_place) { // -i atexit(cleanup_outname); } - if (opt & 0x2) G.regex_type |= REG_EXTENDED; // -r - //if (opt & 0x4) G.be_quiet++; // -n + if (opt & (2|4)) + G.regex_type |= REG_EXTENDED; // -r or -E + //if (opt & 8) + // G.be_quiet++; // -n (implemented with a counter instead) while (opt_e) { // -e add_cmd_block(llist_pop(&opt_e)); } @@ -1458,7 +1464,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) fclose(cmdfile); } /* if we didn't get a pattern from -e or -f, use argv[0] */ - if (!(opt & 0x18)) { + if (!(opt & 0x30)) { if (!*argv) bb_show_usage(); add_cmd_block(*argv++); -- cgit v1.2.3-55-g6feb From 9d46a7a9a4d70756bab24de96221bd3a44ef8f46 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Oct 2013 10:22:47 +0100 Subject: sed: fix memory leak in 'r FILE' command Signed-off-by: Denys Vlasenko --- editors/sed.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index ef462843b..e3cce433e 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -848,7 +848,7 @@ static sed_cmd_t *branch_to(char *label) static void append(char *s) { - llist_add_to_end(&G.append_head, xstrdup(s)); + llist_add_to_end(&G.append_head, s); } static void flush_append(void) @@ -1181,7 +1181,7 @@ static void process_files(void) /* Append line to linked list to be printed later */ case 'a': - append(sed_cmd->string); + append(xstrdup(sed_cmd->string)); break; /* Insert text before this line */ @@ -1203,11 +1203,10 @@ static void process_files(void) rfile = fopen_for_read(sed_cmd->string); if (rfile) { char *line; - while ((line = xmalloc_fgetline(rfile)) != NULL) append(line); - xprint_and_close_file(rfile); + fclose(rfile); } break; -- cgit v1.2.3-55-g6feb From a82e32d9ce199db01aaea92ebcb39a23d90e5b85 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Oct 2013 13:00:00 +0100 Subject: sed: document -E in help text Signed-off-by: Denys Vlasenko --- editors/sed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index e3cce433e..5577f3582 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -59,15 +59,15 @@ */ //usage:#define sed_trivial_usage -//usage: "[-inr] [-f FILE]... [-e CMD]... [FILE]...\n" -//usage: "or: sed [-inr] CMD [FILE]..." +//usage: "[-inrE] [-f FILE]... [-e CMD]... [FILE]...\n" +//usage: "or: sed [-inrE] CMD [FILE]..." //usage:#define sed_full_usage "\n\n" //usage: " -e CMD Add CMD to sed commands to be executed" //usage: "\n -f FILE Add FILE contents to sed commands to be executed" //usage: "\n -i[SFX] Edit files in-place (otherwise sends to stdout)" //usage: "\n Optionally back files up, appending SFX" //usage: "\n -n Suppress automatic printing of pattern space" -//usage: "\n -r Use extended regex syntax" +//usage: "\n -r,-E Use extended regex syntax" //usage: "\n" //usage: "\nIf no -e or -f, the first non-option argument is the sed command string." //usage: "\nRemaining arguments are input files (stdin if none)." -- cgit v1.2.3-55-g6feb From c44539fcd32a0861f9f540253b5e914028821bd7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Oct 2013 14:25:22 +0100 Subject: sed: fix "sed clusternewline" testcase function old new delta process_files 2197 2226 +29 flush_append 47 54 +7 get_next_line 184 189 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 41/0) Total: 41 bytes Signed-off-by: Denys Vlasenko --- editors/sed.c | 134 ++++++++++++++++++++++++++-------------------------- testsuite/sed.tests | 2 - 2 files changed, 67 insertions(+), 69 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 5577f3582..971375884 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -851,37 +851,79 @@ static void append(char *s) llist_add_to_end(&G.append_head, s); } -static void flush_append(void) +/* Output line of text. */ +/* Note: + * The tricks with NO_EOL_CHAR and last_puts_char are there to emulate gnu sed. + * Without them, we had this: + * echo -n thingy >z1 + * echo -n again >z2 + * >znull + * sed "s/i/z/" z1 z2 znull | hexdump -vC + * output: + * gnu sed 4.1.5: + * 00000000 74 68 7a 6e 67 79 0a 61 67 61 7a 6e |thzngy.agazn| + * bbox: + * 00000000 74 68 7a 6e 67 79 61 67 61 7a 6e |thzngyagazn| + */ +enum { + NO_EOL_CHAR = 1, + LAST_IS_NUL = 2, +}; +static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char last_gets_char) +{ + char lpc = *last_puts_char; + + /* Need to insert a '\n' between two files because first file's + * last line wasn't terminated? */ + if (lpc != '\n' && lpc != '\0') { + fputc('\n', file); + lpc = '\n'; + } + fputs(s, file); + + /* 'x' - just something which is not '\n', '\0' or NO_EOL_CHAR */ + if (s[0]) + lpc = 'x'; + + /* had trailing '\0' and it was last char of file? */ + if (last_gets_char == LAST_IS_NUL) { + fputc('\0', file); + lpc = 'x'; /* */ + } else + /* had trailing '\n' or '\0'? */ + if (last_gets_char != NO_EOL_CHAR) { + fputc(last_gets_char, file); + lpc = last_gets_char; + } + + if (ferror(file)) { + xfunc_error_retval = 4; /* It's what gnu sed exits with... */ + bb_error_msg_and_die(bb_msg_write_error); + } + *last_puts_char = lpc; +} + +static void flush_append(char *last_puts_char, char last_gets_char) { char *data; /* Output appended lines. */ while ((data = (char *)llist_pop(&G.append_head))) { - fprintf(G.nonstdout, "%s\n", data); + puts_maybe_newline(data, G.nonstdout, last_puts_char, last_gets_char); free(data); } } -static void add_input_file(FILE *file) -{ - G.input_file_list = xrealloc_vector(G.input_file_list, 2, G.input_file_count); - G.input_file_list[G.input_file_count++] = file; -} - /* Get next line of input from G.input_file_list, flushing append buffer and * noting if we ran out of files without a newline on the last line we read. */ -enum { - NO_EOL_CHAR = 1, - LAST_IS_NUL = 2, -}; -static char *get_next_line(char *gets_char) +static char *get_next_line(char *gets_char, char *last_puts_char, char last_gets_char) { char *temp = NULL; int len; char gc; - flush_append(); + flush_append(last_puts_char, last_gets_char); /* will be returned if last line in the file * doesn't end with either '\n' or '\0' */ @@ -925,54 +967,6 @@ static char *get_next_line(char *gets_char) return temp; } -/* Output line of text. */ -/* Note: - * The tricks with NO_EOL_CHAR and last_puts_char are there to emulate gnu sed. - * Without them, we had this: - * echo -n thingy >z1 - * echo -n again >z2 - * >znull - * sed "s/i/z/" z1 z2 znull | hexdump -vC - * output: - * gnu sed 4.1.5: - * 00000000 74 68 7a 6e 67 79 0a 61 67 61 7a 6e |thzngy.agazn| - * bbox: - * 00000000 74 68 7a 6e 67 79 61 67 61 7a 6e |thzngyagazn| - */ -static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char last_gets_char) -{ - char lpc = *last_puts_char; - - /* Need to insert a '\n' between two files because first file's - * last line wasn't terminated? */ - if (lpc != '\n' && lpc != '\0') { - fputc('\n', file); - lpc = '\n'; - } - fputs(s, file); - - /* 'x' - just something which is not '\n', '\0' or NO_EOL_CHAR */ - if (s[0]) - lpc = 'x'; - - /* had trailing '\0' and it was last char of file? */ - if (last_gets_char == LAST_IS_NUL) { - fputc('\0', file); - lpc = 'x'; /* */ - } else - /* had trailing '\n' or '\0'? */ - if (last_gets_char != NO_EOL_CHAR) { - fputc(last_gets_char, file); - lpc = last_gets_char; - } - - if (ferror(file)) { - xfunc_error_retval = 4; /* It's what gnu sed exits with... */ - bb_error_msg_and_die(bb_msg_write_error); - } - *last_puts_char = lpc; -} - #define sed_puts(s, n) (puts_maybe_newline(s, G.nonstdout, &last_puts_char, n)) static int beg_match(sed_cmd_t *sed_cmd, const char *pattern_space) @@ -995,7 +989,7 @@ static void process_files(void) int substituted; /* Prime the pump */ - next_line = get_next_line(&next_gets_char); + next_line = get_next_line(&next_gets_char, &last_puts_char, '\n' /*last_gets_char*/); /* Go through every line in each file */ again: @@ -1009,7 +1003,7 @@ static void process_files(void) /* Read one line in advance so we can act on the last line, * the '$' address */ - next_line = get_next_line(&next_gets_char); + next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char); linenum++; /* For every line, go through all the commands */ @@ -1227,7 +1221,7 @@ static void process_files(void) free(pattern_space); pattern_space = next_line; last_gets_char = next_gets_char; - next_line = get_next_line(&next_gets_char); + next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char); substituted = 0; linenum++; break; @@ -1263,7 +1257,7 @@ static void process_files(void) pattern_space[len] = '\n'; strcpy(pattern_space + len+1, next_line); last_gets_char = next_gets_char; - next_line = get_next_line(&next_gets_char); + next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char); linenum++; break; } @@ -1367,7 +1361,7 @@ static void process_files(void) /* Delete and such jump here. */ discard_line: - flush_append(); + flush_append(&last_puts_char, last_gets_char); free(pattern_space); goto again; @@ -1394,6 +1388,12 @@ static void add_cmd_block(char *cmdstr) free(sv); } +static void add_input_file(FILE *file) +{ + G.input_file_list = xrealloc_vector(G.input_file_list, 2, G.input_file_count); + G.input_file_list[G.input_file_count++] = file; +} + int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int sed_main(int argc UNUSED_PARAM, char **argv) { diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 2af1e4c97..9494ac2de 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests @@ -154,11 +154,9 @@ testing "sed selective matches insert newline" \ testing "sed selective matches noinsert newline" \ "sed -ne 's/woo/bang/p' input -" "a bang\nb bang" "a woo\nb woo" \ "c no\nd no" -test x"$SKIP_KNOWN_BUGS" = x"" && { testing "sed clusternewline" \ "sed -e '/one/a 111' -e '/two/i 222' -e p input -" \ "one\none\n111\n222\ntwo\ntwo" "one" "two" -} testing "sed subst+write" \ "sed -e 's/i/z/' -e 'woutputw' input -; $ECHO -n X; cat outputw" \ "thzngy\nagaznXthzngy\nagazn" "thingy" "again" -- cgit v1.2.3-55-g6feb From 17f4aca556307ddc7f86dc0a781eabef8360f732 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Nov 2013 22:06:36 +0100 Subject: Makefile.custom: make "make release" delete .gitignore files too Signed-off-by: Antony Pavlov Signed-off-by: Denys Vlasenko --- Makefile.custom | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile.custom b/Makefile.custom index 3561e5768..8c95ef2d4 100644 --- a/Makefile.custom +++ b/Makefile.custom @@ -73,6 +73,10 @@ release: distclean -name .git \ -print \ -exec rm -r -f {} \; ; \ + find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type f \ + -name .gitignore \ + -print \ + -exec rm -f {} \; ; \ find busybox-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)/ -type f \ -name .\#* \ -print \ -- cgit v1.2.3-55-g6feb From 18b461925c6297f241c2b51f96f5d6d5f5de9e1d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Nov 2013 00:07:31 +0100 Subject: bootchartd: warn if .config looks wrong Signed-off-by: Denys Vlasenko --- init/bootchartd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/init/bootchartd.c b/init/bootchartd.c index 9fd623357..c7388c99e 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -60,6 +60,12 @@ # endif #endif +#if !ENABLE_TAR && !ENABLE_WERROR +# warning Note: bootchartd requires tar command, but you did not select it. +#elif !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_WERROR +# warning Note: bootchartd requires tar -z support, but you did not select it. +#endif + #define BC_VERSION_STR "0.8" /* For debugging, set to 0: -- cgit v1.2.3-55-g6feb From b21bc80c7651bfb5a9e001cc220a598cf89b7cfd Mon Sep 17 00:00:00 2001 From: Yuan-Hsiang Lee Date: Sun, 3 Nov 2013 00:13:16 +0100 Subject: init: fix illegal memory access when max message length is reached Signed-off-by: Yuan-Hsiang Lee Signed-off-by: Denys Vlasenko --- init/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init/init.c b/init/init.c index cc6a2b5be..2dcdfd471 100644 --- a/init/init.c +++ b/init/init.c @@ -222,8 +222,8 @@ static void message(int where, const char *fmt, ...) msg[0] = '\r'; va_start(arguments, fmt); l = 1 + vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments); - if (l > sizeof(msg) - 1) - l = sizeof(msg) - 1; + if (l > sizeof(msg) - 2) + l = sizeof(msg) - 2; va_end(arguments); #if ENABLE_FEATURE_INIT_SYSLOG -- cgit v1.2.3-55-g6feb From 8d3efaf35eb9d138114563bba4173c39c1231198 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Nov 2013 19:20:54 +0100 Subject: udhcpc: allow zero server-id. Closes 6614. function old new delta bcast_or_ucast - 47 +47 udhcp_send_kernel_packet 271 295 +24 udhcpc_main 2696 2705 +9 udhcp_send_raw_packet 456 459 +3 send_release 90 76 -14 send_renew 105 77 -28 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/2 up/down: 83/-42) Total: 41 bytes Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 53d8a5e08..8dee916d9 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -667,6 +667,15 @@ static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet) client_config.ifindex); } +static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server) +{ + if (server) + return udhcp_send_kernel_packet(packet, + ciaddr, CLIENT_PORT, + server, SERVER_PORT); + return raw_bcast_from_client_config_ifindex(packet); +} + /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ /* NOINLINE: limit stack usage in caller */ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) @@ -773,11 +782,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) add_client_options(&packet); bb_info_msg("Sending renew..."); - if (server) - return udhcp_send_kernel_packet(&packet, - ciaddr, CLIENT_PORT, - server, SERVER_PORT); - return raw_bcast_from_client_config_ifindex(&packet); + return bcast_or_ucast(&packet, ciaddr, server); } #if ENABLE_FEATURE_UDHCPC_ARPING @@ -826,7 +831,11 @@ static int send_release(uint32_t server, uint32_t ciaddr) udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); bb_info_msg("Sending release..."); - return udhcp_send_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); + /* Note: normally we unicast here since "server" is not zero. + * However, there _are_ people who run "address-less" DHCP servers, + * and reportedly ISC dhcp client and Windows allow that. + */ + return bcast_or_ucast(&packet, ciaddr, server); } /* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */ @@ -1648,14 +1657,19 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) * might work too. * "Next server" and router are definitely wrong ones to use, though... */ +/* We used to ignore pcakets without DHCP_SERVER_ID. + * I've got user reports from people who run "address-less" servers. + * They either supply DHCP_SERVER_ID of 0.0.0.0 or don't supply it at all. + * They say ISC DHCP client supports this case. + */ + server_addr = 0; temp = udhcp_get_option(&packet, DHCP_SERVER_ID); if (!temp) { - bb_error_msg("no server ID, ignoring packet"); - continue; - /* still selecting - this server looks bad */ + bb_error_msg("no server ID, using 0.0.0.0"); + } else { + /* it IS unaligned sometimes, don't "optimize" */ + move_from_unaligned32(server_addr, temp); } - /* it IS unaligned sometimes, don't "optimize" */ - move_from_unaligned32(server_addr, temp); /*xid = packet.xid; - already is */ requested_ip = packet.yiaddr; -- cgit v1.2.3-55-g6feb From b541d1fcbd39f9fa8768a57e48a334b1929303e5 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Fri, 27 Sep 2013 13:39:41 +0200 Subject: swaponoff: shrink function old new delta .rodata 148469 148468 -1 swap_on_off_main 381 379 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-3) Total: -3 bytes text data bss dec hex filename 803030 4090 9504 816624 c75f0 busybox_old 803027 4090 9504 816621 c75ed busybox_unstripped --- util-linux/swaponoff.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index afad4ab8f..40f971d35 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -96,12 +96,11 @@ static int do_em_all(void) || hasmntopt(m, MNTOPT_NOAUTO) == NULL ) { #if ENABLE_FEATURE_SWAPON_PRI - char *p; g_flags = 0; /* each swap space might have different flags */ - p = strstr(m->mnt_opts, "pri="); + char *p = hasmntopt(m,"pri"); if (p) { /* Max allowed 32767 (==SWAP_FLAG_PRIO_MASK) */ - int swap_prio = MIN(bb_strtoull(p + 4 , NULL, 10), SWAP_FLAG_PRIO_MASK); + unsigned int swap_prio = MIN(bb_strtou(p + 4 , NULL, 10), SWAP_FLAG_PRIO_MASK); /* We want to allow "NNNN,foo", thus errno == EINVAL is allowed too */ if (errno != ERANGE) { g_flags = SWAP_FLAG_PREFER | -- cgit v1.2.3-55-g6feb From 200c1c46f4aa2cb70e0e3581a5bd8aa72a1aac0f Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Fri, 8 Nov 2013 14:12:13 +0100 Subject: ash: Use setvar2 some more (add/remove: 0/0 grow/shrink: 10/15 up/down: 13/-27) Total: -14 bytes Signed-off-by: Bernhard Reutner-Fischer --- shell/ash.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index d696bbdac..f9b4d3fe6 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2286,7 +2286,7 @@ unsetvar(const char *s) free(vp); INT_ON; } else { - setvar(s, 0, 0); + setvar2(s, 0); vp->flags &= ~VEXPORT; } ok: @@ -6339,7 +6339,7 @@ subevalvar(char *p, char *varname, int strloc, int subtype, switch (subtype) { case VSASSIGN: - setvar(varname, startp, 0); + setvar2(varname, startp); amount = startp - expdest; STADJUST(amount, expdest); return startp; @@ -8554,7 +8554,7 @@ evalfor(union node *n, int flags) loopnest++; flags &= EV_TESTED; for (sp = arglist.list; sp; sp = sp->next) { - setvar(n->nfor.var, sp->text, 0); + setvar2(n->nfor.var, sp->text); evaltree(n->nfor.body, flags); if (evalskip) { if (evalskip == SKIPCONT && --skipcount <= 0) { @@ -9451,7 +9451,7 @@ evalcommand(union node *cmd, int flags) * '_' in 'vi' command mode during line editing... * However I implemented that within libedit itself. */ - setvar("_", lastarg, 0); + setvar2("_", lastarg); } popstackmark(&smark); } @@ -12273,7 +12273,6 @@ dotcmd(int argc, char **argv) * bash returns exitcode 1 instead. */ fullname = find_dot_file(argv[1]); - argv += 2; argc -= 2; if (argc) { /* argc > 0, argv[0] != NULL */ @@ -13012,7 +13011,7 @@ init(void) } } - setvar("PPID", utoa(getppid()), 0); + setvar2("PPID", utoa(getppid())); p = lookupvar("PWD"); if (p) { @@ -13267,7 +13266,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) hp = lookupvar("HOME"); if (hp) { hp = concat_path_file(hp, ".ash_history"); - setvar("HISTFILE", hp, 0); + setvar2("HISTFILE", hp); free((char*)hp); hp = lookupvar("HISTFILE"); } -- cgit v1.2.3-55-g6feb From 80f8cdf04ad0e8b37c20aed883b6cbfd6636dbc3 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Fri, 8 Nov 2013 14:25:24 +0100 Subject: ash: Set SHLVL in ASH_BASH_COMPAT function old new delta ash_main 1456 1505 +49 .rodata 148488 148494 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 55/0) Total: 55 bytes Signed-off-by: Bernhard Reutner-Fischer --- shell/ash.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index f9b4d3fe6..71ef9a690 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13012,7 +13012,10 @@ init(void) } setvar2("PPID", utoa(getppid())); - +#if ENABLE_ASH_BASH_COMPAT + p = lookupvar("SHLVL"); + setvar2("SHLVL", utoa(p ? atoi(p) + 1 : 1)); +#endif p = lookupvar("PWD"); if (p) { if (*p != '/' || stat(p, &st1) || stat(".", &st2) -- cgit v1.2.3-55-g6feb From 1d39e33d46f32862da2ec1c394401239515206b8 Mon Sep 17 00:00:00 2001 From: Malek Degachi Date: Sat, 9 Nov 2013 21:27:27 +0100 Subject: fstrim: New applet fstrim applet is a port from util-linux. "Trimming" your NAND/eMMC storage will restore the write performance back to normal after having slow down issues on sequential write and random write due to usage over time. Good reading on subject: http://forum.xda-developers.com/showthread.php?t=1971852 (with long options and CLEAN_UP turned on) function old new delta .rodata 148494 148791 +297 fstrim_main - 283 +283 fstrim_sfx - 128 +128 packed_usage 28826 28903 +77 applet_main 2760 2768 +8 applet_names 2343 2350 +7 applet_nameofs 690 692 +2 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 5/0 up/down: 802/0) Total: 802 bytes Signed-off-by: Malek Degachi Cc: Eugene San (eugenesan) Signed-off-by: Bernhard Reutner-Fischer --- include/applets.src.h | 1 + util-linux/Config.src | 7 ++++ util-linux/Kbuild.src | 1 + util-linux/fstrim.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 util-linux/fstrim.c diff --git a/include/applets.src.h b/include/applets.src.h index 3a47e15b9..5268200f5 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -167,6 +167,7 @@ IF_FSCK(APPLET(fsck, BB_DIR_SBIN, BB_SUID_DROP)) //IF_E2FSCK(APPLET_ODDNAME(fsck.ext2, e2fsck, BB_DIR_SBIN, BB_SUID_DROP, fsck_ext2)) //IF_E2FSCK(APPLET_ODDNAME(fsck.ext3, e2fsck, BB_DIR_SBIN, BB_SUID_DROP, fsck_ext3)) IF_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, BB_DIR_SBIN, BB_SUID_DROP, fsck_minix)) +IF_FSTRIM(APPLET(fstrim, BB_DIR_SBIN, BB_SUID_DROP)) IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync)) IF_FTPD(APPLET(ftpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, BB_DIR_USR_BIN, BB_SUID_DROP, ftpget)) diff --git a/util-linux/Config.src b/util-linux/Config.src index 5a8b0063b..ef7039720 100644 --- a/util-linux/Config.src +++ b/util-linux/Config.src @@ -246,6 +246,13 @@ config FSCK_MINIX check for and attempt to repair any corruption that occurs to a minix filesystem. +config FSTRIM + bool "fstrim" + default y + select PLATFORM_LINUX + help + Discard unused blocks on a mounted filesystem. + config MKFS_EXT2 bool "mkfs_ext2" default y diff --git a/util-linux/Kbuild.src b/util-linux/Kbuild.src index 468fc6bc1..429cf1100 100644 --- a/util-linux/Kbuild.src +++ b/util-linux/Kbuild.src @@ -18,6 +18,7 @@ lib-$(CONFIG_FINDFS) += findfs.o lib-$(CONFIG_FLOCK) += flock.o lib-$(CONFIG_FREERAMDISK) += freeramdisk.o lib-$(CONFIG_FSCK_MINIX) += fsck_minix.o +lib-$(CONFIG_FSTRIM) += fstrim.o lib-$(CONFIG_GETOPT) += getopt.o lib-$(CONFIG_HEXDUMP) += hexdump.o lib-$(CONFIG_HWCLOCK) += hwclock.o diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c new file mode 100644 index 000000000..2fa457b5e --- /dev/null +++ b/util-linux/fstrim.c @@ -0,0 +1,111 @@ +/* vi: set sw=4 ts=4: */ +/* + * fstrim.c - discard the part (or whole) of mounted filesystem. + * + * 03 March 2012 - Malek Degachi + * Adapted for busybox from util-linux-2.12a. + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ + +//usage:#define fstrim_trivial_usage +//usage: "[Options] " +//usage:#define fstrim_full_usage "\n\n" +//usage: "Options:" +//usage: IF_LONG_OPTS( +//usage: "\n -o,--offset=offset offset in bytes to discard from" +//usage: "\n -l,--length=length length of bytes to discard from the offset" +//usage: "\n -m,--minimum=minimum minimum extent length to discard" +//usage: "\n -v,--verbose print number of discarded bytes" +//usage: ) +//usage: IF_NOT_LONG_OPTS( +//usage: "\n -o offset offset in bytes to discard from" +//usage: "\n -l length length of bytes to discard from the offset" +//usage: "\n -m minimum minimum extent length to discard" +//usage: "\n -v, print number of discarded bytes" +//usage: ) + +#include "libbb.h" +#include + +#ifndef FITRIM +struct fstrim_range { + uint64_t start; + uint64_t len; + uint64_t minlen; +}; +#define FITRIM _IOWR('X', 121, struct fstrim_range) +#endif + +static const struct suffix_mult fstrim_sfx[] = { + { "KiB", 1024 }, + { "kiB", 1024 }, + { "K", 1024 }, + { "k", 1024 }, + { "MiB", 1048576 }, + { "miB", 1048576 }, + { "M", 1048576 }, + { "m", 1048576 }, + { "GiB", 1073741824 }, + { "giB", 1073741824 }, + { "G", 1073741824 }, + { "g", 1073741824 }, + { "KB", 1000 }, + { "MB", 1000000 }, + { "GB", 1000000000 }, + { "", 0 } +}; + +int fstrim_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int fstrim_main(int argc UNUSED_PARAM, char **argv) +{ + struct fstrim_range range; + char *arg_o; + char *arg_l; + char *arg_m; + unsigned opts; + int fd; + + enum { + OPT_o = (1 << 0), + OPT_l = (1 << 1), + OPT_m = (1 << 2), + OPT_v = (1 << 3), + }; + +#if ENABLE_LONG_OPTS + static const char getopt_longopts[] ALIGN1 = + "offset\0" Required_argument "o" + "length\0" Required_argument "l" + "minimum\0" Required_argument "m" + "verbose\0" No_argument "v" + ; + applet_long_options = getopt_longopts; +#endif + + opt_complementary = "=1"; /* exactly one non-option arg: the mountpoint */ + opts = getopt32(argv, "o:l:m:v", &arg_o, &arg_l, &arg_m); + + memset(&range, 0, sizeof(range)); + range.len = ULLONG_MAX; + + if (opts & OPT_o) + range.start = xatoull_sfx(arg_o, fstrim_sfx); + if (opts & OPT_l) + range.len = xatoull_sfx(arg_l, fstrim_sfx); + if (opts & OPT_m) + range.minlen = xatoull_sfx(arg_m, fstrim_sfx); + + if (find_block_device(argv[optind])) { + fd = xopen_nonblocking(argv[optind]); + xioctl(fd, FITRIM, &range); + if (ENABLE_FEATURE_CLEAN_UP) + close(fd); + + if (opts & OPT_v) + printf("%s: %llu bytes were trimmed\n", argv[optind], range.len); + } + + return EXIT_SUCCESS; +} + -- cgit v1.2.3-55-g6feb From 140f4e351191d8633fd5bd6dcf38cdcccc1f07cb Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sat, 9 Nov 2013 23:13:17 +0100 Subject: fstrim: -17b Also, use the name of the block device we found, not necessarily the one we got from the user: fstrim -v / /dev/sdj: 4711 bytes were trimmed Signed-off-by: Bernhard Reutner-Fischer --- util-linux/fstrim.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c index 2fa457b5e..00140b340 100644 --- a/util-linux/fstrim.c +++ b/util-linux/fstrim.c @@ -60,9 +60,7 @@ int fstrim_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int fstrim_main(int argc UNUSED_PARAM, char **argv) { struct fstrim_range range; - char *arg_o; - char *arg_l; - char *arg_m; + char *arg_o, *arg_l, *arg_m, *bd; unsigned opts; int fd; @@ -96,16 +94,15 @@ int fstrim_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_m) range.minlen = xatoull_sfx(arg_m, fstrim_sfx); - if (find_block_device(argv[optind])) { - fd = xopen_nonblocking(argv[optind]); + bd = find_block_device(*(argv += optind)); + if (bd) { + fd = xopen_nonblocking(bd); xioctl(fd, FITRIM, &range); if (ENABLE_FEATURE_CLEAN_UP) close(fd); if (opts & OPT_v) - printf("%s: %llu bytes were trimmed\n", argv[optind], range.len); + printf("%s: %llu bytes were trimmed\n", bd, range.len); } - return EXIT_SUCCESS; } - -- cgit v1.2.3-55-g6feb From b1489f97e0670fed7d450bae86a3aae38bc9156b Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 10 Nov 2013 00:02:43 +0100 Subject: fstrim: Indicate failure on error +14b Signed-off-by: Bernhard Reutner-Fischer --- util-linux/fstrim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c index 00140b340..84a641022 100644 --- a/util-linux/fstrim.c +++ b/util-linux/fstrim.c @@ -103,6 +103,7 @@ int fstrim_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_v) printf("%s: %llu bytes were trimmed\n", bd, range.len); + return EXIT_SUCCESS; } - return EXIT_SUCCESS; + return EXIT_FAILURE; } -- cgit v1.2.3-55-g6feb From 5e63776212f8fab4fba08ab2b99dd5241f0c3880 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 10 Nov 2013 21:47:02 +0100 Subject: fstrim: Needs to fire at the mp, not bd It's a filesystem thing from this perspective. +1b Signed-off-by: Bernhard Reutner-Fischer --- util-linux/fstrim.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c index 84a641022..4d90fa7a3 100644 --- a/util-linux/fstrim.c +++ b/util-linux/fstrim.c @@ -60,7 +60,7 @@ int fstrim_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int fstrim_main(int argc UNUSED_PARAM, char **argv) { struct fstrim_range range; - char *arg_o, *arg_l, *arg_m, *bd; + char *arg_o, *arg_l, *arg_m, *mp; unsigned opts; int fd; @@ -94,15 +94,15 @@ int fstrim_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_m) range.minlen = xatoull_sfx(arg_m, fstrim_sfx); - bd = find_block_device(*(argv += optind)); - if (bd) { - fd = xopen_nonblocking(bd); + mp = *(argv += optind); + if (find_block_device(mp)) { + fd = xopen_nonblocking(mp); xioctl(fd, FITRIM, &range); if (ENABLE_FEATURE_CLEAN_UP) close(fd); if (opts & OPT_v) - printf("%s: %llu bytes were trimmed\n", bd, range.len); + printf("%s: %llu bytes were trimmed\n", mp, range.len); return EXIT_SUCCESS; } return EXIT_FAILURE; -- cgit v1.2.3-55-g6feb From afa63b2dcdc9b9d0183ffd84599ea5d4ad94d639 Mon Sep 17 00:00:00 2001 From: Michael Tokarev Date: Sun, 10 Nov 2013 22:01:38 +0100 Subject: fix bashisms in testsuite/ These places use ${var/search/replace}, $((n++) and `type -p' constructs which are not-so-standard. Replace with equivalent constructs. Signed-off-by: Michael Tokarev Signed-off-by: Bernhard Reutner-Fischer --- testsuite/hostid/hostid-works | 10 ++++------ testsuite/md5sum.tests | 6 +++--- testsuite/testing.sh | 8 ++++---- testsuite/which/which-uses-default-path | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/testsuite/hostid/hostid-works b/testsuite/hostid/hostid-works index bcfd717af..8c20bdfcc 100644 --- a/testsuite/hostid/hostid-works +++ b/testsuite/hostid/hostid-works @@ -1,8 +1,6 @@ h=x$(busybox hostid) # Is $h a sequence of hex numbers? -x="${h//[0123456789abcdef]/x}" -x="${x//xxx/x}" -x="${x//xxx/x}" -x="${x//xxx/x}" -x="${x//xx/x}" -test x"$x" = x"x" +case "$h" in + x*[!0-9a-f]*) false;; + *) true;; +esac diff --git a/testsuite/md5sum.tests b/testsuite/md5sum.tests index 1068b083f..6c75b6d1c 100755 --- a/testsuite/md5sum.tests +++ b/testsuite/md5sum.tests @@ -30,13 +30,13 @@ result=`( n=0 while test $n -le 999; do echo "$text" | head -c $n | "$sum" - : $((n++)) + n=$(($n+1)) done | "$sum" )` if test x"$result" = x"$expected -"; then - echo "PASS: $sum" - exit 0 + echo "PASS: $sum" + exit 0 fi echo "FAIL: $sum (r:$result exp:$expected)" diff --git a/testsuite/testing.sh b/testsuite/testing.sh index e7e64e58b..f5b756947 100644 --- a/testsuite/testing.sh +++ b/testsuite/testing.sh @@ -56,10 +56,10 @@ optional() { SKIP= while test "$1"; do - if test x"${OPTIONFLAGS/*:$1:*/y}" != x"y"; then - SKIP=1 - return - fi + case "${OPTIONFLAGS}" in + *:$1:*) ;; + *) SKIP=1; return ;; + esac shift done } diff --git a/testsuite/which/which-uses-default-path b/testsuite/which/which-uses-default-path index 63ceb9f8f..349583dcc 100644 --- a/testsuite/which/which-uses-default-path +++ b/testsuite/which/which-uses-default-path @@ -1,4 +1,4 @@ -BUSYBOX=$(type -p busybox) +BUSYBOX=$(command -pv busybox) SAVED_PATH=$PATH unset PATH $BUSYBOX which ls -- cgit v1.2.3-55-g6feb From 087843a65b82ca2be486118214293530a6814d2d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 12 Nov 2013 11:16:30 +0100 Subject: fix "warning: ISO C90 forbids mixed declarations and code" Signed-off-by: Denys Vlasenko --- util-linux/swaponoff.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 40f971d35..3f223343e 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -96,8 +96,9 @@ static int do_em_all(void) || hasmntopt(m, MNTOPT_NOAUTO) == NULL ) { #if ENABLE_FEATURE_SWAPON_PRI + char *p; g_flags = 0; /* each swap space might have different flags */ - char *p = hasmntopt(m,"pri"); + p = hasmntopt(m, "pri"); if (p) { /* Max allowed 32767 (==SWAP_FLAG_PRIO_MASK) */ unsigned int swap_prio = MIN(bb_strtou(p + 4 , NULL, 10), SWAP_FLAG_PRIO_MASK); -- cgit v1.2.3-55-g6feb From d3092c99ae90f2be2e1f990eab15921ea26652fd Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Tue, 12 Nov 2013 11:18:26 +0100 Subject: udhcp: add PXELINUX config file option (code 209) definition This change adds a definition for DHCP option 209. RFC 5071 defines code 209 as a configuration file for a PXE bootloader; this change uses the string "pxeconffile" as its text identifier. Signed-off-by: Jeremy Kerr Signed-off-by: Denys Vlasenko --- networking/udhcp/common.c | 2 ++ networking/udhcp/common.h | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 11b7b1f06..fe322db4f 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c @@ -62,6 +62,7 @@ const struct dhcp_optflag dhcp_optflags[] = { { OPTION_U16 , 0x84 }, /* DHCP_VLAN_ID */ { OPTION_U8 , 0x85 }, /* DHCP_VLAN_PRIORITY */ #endif + { OPTION_STRING , 0xd1 }, /* DHCP_PXE_CONF_FILE */ { OPTION_6RD , 0xd4 }, /* DHCP_6RD */ { OPTION_STATIC_ROUTES | OPTION_LIST , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */ { OPTION_STRING , 0xfc }, /* DHCP_WPAD */ @@ -128,6 +129,7 @@ const char dhcp_option_strings[] ALIGN1 = "vlanid" "\0" /* DHCP_VLAN_ID */ "vlanpriority" "\0"/* DHCP_VLAN_PRIORITY */ #endif + "pxeconffile" "\0" /* DHCP_PXE_CONF_FILE */ "ip6rd" "\0" /* DHCP_6RD */ "msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */ "wpad" "\0" /* DHCP_WPAD */ diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 0e8e45fd2..5e70d609f 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -149,8 +149,9 @@ enum { //#define DHCP_DOMAIN_SEARCH 0x77 /* RFC 3397. set of ASCIZ string, DNS-style compressed */ //#define DHCP_SIP_SERVERS 0x78 /* RFC 3361. flag byte, then: 0: domain names, 1: IP addrs */ //#define DHCP_STATIC_ROUTES 0x79 /* RFC 3442. (mask,ip,router) tuples */ -#define DHCP_VLAN_ID 0x84 /* 802.1P VLAN ID */ -#define DHCP_VLAN_PRIORITY 0x85 /* 802.1Q VLAN priority */ +//#define DHCP_VLAN_ID 0x84 /* 802.1P VLAN ID */ +//#define DHCP_VLAN_PRIORITY 0x85 /* 802.1Q VLAN priority */ +//#define DHCP_PXE_CONF_FILE 0xd1 /* RFC 5071 Configuration File */ //#define DHCP_MS_STATIC_ROUTES 0xf9 /* Microsoft's pre-RFC 3442 code for 0x79? */ //#define DHCP_WPAD 0xfc /* MSIE's Web Proxy Autodiscovery Protocol */ #define DHCP_END 0xff -- cgit v1.2.3-55-g6feb From cd0936be361ad2566200479d66fc1e5671182b73 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 12 Nov 2013 12:09:14 +0100 Subject: fstrim: use new-style config/kbuild/applet snippets; trim help text function old new delta packed_usage 29546 29520 -26 Signed-off-by: Denys Vlasenko --- include/applets.src.h | 1 - util-linux/Config.src | 7 ------- util-linux/Kbuild.src | 1 - util-linux/fstrim.c | 34 ++++++++++++++++++++++------------ 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index 5268200f5..3a47e15b9 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -167,7 +167,6 @@ IF_FSCK(APPLET(fsck, BB_DIR_SBIN, BB_SUID_DROP)) //IF_E2FSCK(APPLET_ODDNAME(fsck.ext2, e2fsck, BB_DIR_SBIN, BB_SUID_DROP, fsck_ext2)) //IF_E2FSCK(APPLET_ODDNAME(fsck.ext3, e2fsck, BB_DIR_SBIN, BB_SUID_DROP, fsck_ext3)) IF_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, BB_DIR_SBIN, BB_SUID_DROP, fsck_minix)) -IF_FSTRIM(APPLET(fstrim, BB_DIR_SBIN, BB_SUID_DROP)) IF_FSYNC(APPLET_NOFORK(fsync, fsync, BB_DIR_BIN, BB_SUID_DROP, fsync)) IF_FTPD(APPLET(ftpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, BB_DIR_USR_BIN, BB_SUID_DROP, ftpget)) diff --git a/util-linux/Config.src b/util-linux/Config.src index ef7039720..5a8b0063b 100644 --- a/util-linux/Config.src +++ b/util-linux/Config.src @@ -246,13 +246,6 @@ config FSCK_MINIX check for and attempt to repair any corruption that occurs to a minix filesystem. -config FSTRIM - bool "fstrim" - default y - select PLATFORM_LINUX - help - Discard unused blocks on a mounted filesystem. - config MKFS_EXT2 bool "mkfs_ext2" default y diff --git a/util-linux/Kbuild.src b/util-linux/Kbuild.src index 429cf1100..468fc6bc1 100644 --- a/util-linux/Kbuild.src +++ b/util-linux/Kbuild.src @@ -18,7 +18,6 @@ lib-$(CONFIG_FINDFS) += findfs.o lib-$(CONFIG_FLOCK) += flock.o lib-$(CONFIG_FREERAMDISK) += freeramdisk.o lib-$(CONFIG_FSCK_MINIX) += fsck_minix.o -lib-$(CONFIG_FSTRIM) += fstrim.o lib-$(CONFIG_GETOPT) += getopt.o lib-$(CONFIG_HEXDUMP) += hexdump.o lib-$(CONFIG_HWCLOCK) += hwclock.o diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c index 4d90fa7a3..675a02184 100644 --- a/util-linux/fstrim.c +++ b/util-linux/fstrim.c @@ -8,21 +8,31 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config FSTRIM +//config: bool "fstrim" +//config: default y +//config: select PLATFORM_LINUX +//config: help +//config: Discard unused blocks on a mounted filesystem. + +//applet:IF_FSTRIM(APPLET(fstrim, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_FSTRIM) += fstrim.o + //usage:#define fstrim_trivial_usage -//usage: "[Options] " +//usage: "[OPTIONS] MOUNTPOINT" //usage:#define fstrim_full_usage "\n\n" -//usage: "Options:" //usage: IF_LONG_OPTS( -//usage: "\n -o,--offset=offset offset in bytes to discard from" -//usage: "\n -l,--length=length length of bytes to discard from the offset" -//usage: "\n -m,--minimum=minimum minimum extent length to discard" -//usage: "\n -v,--verbose print number of discarded bytes" +//usage: " -o,--offset=OFFSET Offset in bytes to discard from" +//usage: "\n -l,--length=LEN Bytes to discard" +//usage: "\n -m,--minimum=MIN Minimum extent length" +//usage: "\n -v,--verbose Print number of discarded bytes" //usage: ) //usage: IF_NOT_LONG_OPTS( -//usage: "\n -o offset offset in bytes to discard from" -//usage: "\n -l length length of bytes to discard from the offset" -//usage: "\n -m minimum minimum extent length to discard" -//usage: "\n -v, print number of discarded bytes" +//usage: " -o OFFSET Offset in bytes to discard from" +//usage: "\n -l LEN Bytes to discard" +//usage: "\n -m MIN Minimum extent length" +//usage: "\n -v, Print number of discarded bytes" //usage: ) #include "libbb.h" @@ -94,7 +104,7 @@ int fstrim_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_m) range.minlen = xatoull_sfx(arg_m, fstrim_sfx); - mp = *(argv += optind); + mp = argv[optind]; if (find_block_device(mp)) { fd = xopen_nonblocking(mp); xioctl(fd, FITRIM, &range); @@ -102,7 +112,7 @@ int fstrim_main(int argc UNUSED_PARAM, char **argv) close(fd); if (opts & OPT_v) - printf("%s: %llu bytes were trimmed\n", mp, range.len); + printf("%s: %llu bytes trimmed\n", mp, (unsigned long long)range.len); return EXIT_SUCCESS; } return EXIT_FAILURE; -- cgit v1.2.3-55-g6feb From f200f732f4d04a26814f109be8db2b6510e7127c Mon Sep 17 00:00:00 2001 From: Sven-Göran Bergh Date: Tue, 12 Nov 2013 14:18:25 +0100 Subject: awk: optionally support -e AWK_PROG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit function old new delta awk_main 959 978 +19 Signed-off-by: Sven-Göran Bergh Signed-off-by: Denys Vlasenko --- editors/Config.src | 15 ------- editors/Kbuild.src | 1 - editors/awk.c | 109 ++++++++++++++++++++++++++++++++++++++------------ include/applets.src.h | 1 - 4 files changed, 84 insertions(+), 42 deletions(-) diff --git a/editors/Config.src b/editors/Config.src index af1e1de5e..d3bd46e40 100644 --- a/editors/Config.src +++ b/editors/Config.src @@ -7,21 +7,6 @@ menu "Editors" INSERT -config AWK - bool "awk" - default y - help - Awk is used as a pattern scanning and processing language. This is - the BusyBox implementation of that programming language. - -config FEATURE_AWK_LIBM - bool "Enable math functions (requires libm)" - default y - depends on AWK - help - Enable math functions of the Awk programming language. - NOTE: This will require libm to be present for linking. - config CMP bool "cmp" default y diff --git a/editors/Kbuild.src b/editors/Kbuild.src index 8888cba12..15d7a4cac 100644 --- a/editors/Kbuild.src +++ b/editors/Kbuild.src @@ -7,7 +7,6 @@ lib-y:= INSERT -lib-$(CONFIG_AWK) += awk.o lib-$(CONFIG_CMP) += cmp.o lib-$(CONFIG_DIFF) += diff.o lib-$(CONFIG_ED) += ed.o diff --git a/editors/awk.c b/editors/awk.c index 8848d94a5..29fb2e782 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -7,12 +7,45 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config AWK +//config: bool "awk" +//config: default y +//config: help +//config: Awk is used as a pattern scanning and processing language. This is +//config: the BusyBox implementation of that programming language. +//config: +//config:config FEATURE_AWK_LIBM +//config: bool "Enable math functions (requires libm)" +//config: default y +//config: depends on AWK +//config: help +//config: Enable math functions of the Awk programming language. +//config: NOTE: This will require libm to be present for linking. +//config: +//config:config FEATURE_AWK_GNU_EXTENSIONS +//config: bool "Enable a few GNU extensions" +//config: default y +//config: depends on AWK +//config: help +//config: Enable a few features from gawk: +//config: * command line option -e AWK_PROGRAM +//config: * simultaneous use of -f and -e on the command line. +//config: This enables the use of awk library files. +//config: Ex: awk -f mylib.awk -e '{print myfunction($1);}' ... + +//applet:IF_AWK(APPLET_NOEXEC(awk, awk, BB_DIR_USR_BIN, BB_SUID_DROP, awk)) + +//kbuild:lib-$(CONFIG_AWK) += awk.o + //usage:#define awk_trivial_usage //usage: "[OPTIONS] [AWK_PROGRAM] [FILE]..." //usage:#define awk_full_usage "\n\n" //usage: " -v VAR=VAL Set variable" //usage: "\n -F SEP Use SEP as field separator" //usage: "\n -f FILE Read program from FILE" +//usage: IF_FEATURE_AWK_GNU_EXTENSIONS( +//usage: "\n -e AWK_PROGRAM" +//usage: ) #include "libbb.h" #include "xregex.h" @@ -38,6 +71,25 @@ #endif +#define OPTSTR_AWK \ + "F:v:f:" \ + IF_FEATURE_AWK_GNU_EXTENSIONS("e:") \ + "W:" +#define OPTCOMPLSTR_AWK \ + "v::f::" \ + IF_FEATURE_AWK_GNU_EXTENSIONS("e::") +enum { + OPTBIT_F, /* define field separator */ + OPTBIT_v, /* define variable */ + OPTBIT_f, /* pull in awk program from file */ + IF_FEATURE_AWK_GNU_EXTENSIONS(OPTBIT_e,) /* -e AWK_PROGRAM */ + OPTBIT_W, /* -W ignored */ + OPT_F = 1 << OPTBIT_F, + OPT_v = 1 << OPTBIT_v, + OPT_f = 1 << OPTBIT_f, + OPT_e = IF_FEATURE_AWK_GNU_EXTENSIONS((1 << OPTBIT_e)) + 0, + OPT_W = 1 << OPTBIT_W +}; #define MAXVARFMT 240 #define MINNVBLOCK 64 @@ -3087,6 +3139,9 @@ int awk_main(int argc, char **argv) char *opt_F; llist_t *list_v = NULL; llist_t *list_f = NULL; +#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS + llist_t *list_e = NULL; +#endif int i, j; var *v; var tv; @@ -3145,11 +3200,11 @@ int awk_main(int argc, char **argv) *s1 = '='; } } - opt_complementary = "v::f::"; /* -v and -f can occur multiple times */ - opt = getopt32(argv, "F:v:f:W:", &opt_F, &list_v, &list_f, NULL); + opt_complementary = OPTCOMPLSTR_AWK; + opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); argv += optind; argc -= optind; - if (opt & 0x1) { /* -F */ + if (opt & OPT_F) { /* -F */ unescape_string_in_place(opt_F); setvar_s(intvar[FS], opt_F); } @@ -3157,31 +3212,35 @@ int awk_main(int argc, char **argv) if (!is_assignment(llist_pop(&list_v))) bb_show_usage(); } - if (list_f) { /* -f */ - do { - char *s = NULL; - FILE *from_file; - - g_progname = llist_pop(&list_f); - from_file = xfopen_stdin(g_progname); - /* one byte is reserved for some trick in next_token */ - for (i = j = 1; j > 0; i += j) { - s = xrealloc(s, i + 4096); - j = fread(s + i, 1, 4094, from_file); - } - s[i] = '\0'; - fclose(from_file); - parse_program(s + 1); - free(s); - } while (list_f); - argc++; - } else { // no -f: take program from 1st parameter - if (!argc) + while (list_f) { /* -f */ + char *s = NULL; + FILE *from_file; + + g_progname = llist_pop(&list_f); + from_file = xfopen_stdin(g_progname); + /* one byte is reserved for some trick in next_token */ + for (i = j = 1; j > 0; i += j) { + s = xrealloc(s, i + 4096); + j = fread(s + i, 1, 4094, from_file); + } + s[i] = '\0'; + fclose(from_file); + parse_program(s + 1); + free(s); + } + g_progname = "cmd. line"; +#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS + while (list_e) { /* -e */ + parse_program(llist_pop(&list_e)); + } +#endif + if (!(opt & (OPT_f | OPT_e))) { + if (!*argv) bb_show_usage(); - g_progname = "cmd. line"; parse_program(*argv++); + argc++; } - if (opt & 0x8) // -W + if (opt & OPT_W) // -W bb_error_msg("warning: option -W is ignored"); /* fill in ARGV array */ diff --git a/include/applets.src.h b/include/applets.src.h index 3a47e15b9..ac8f18056 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -82,7 +82,6 @@ IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP)) IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_ARP(APPLET(arp, BB_DIR_SBIN, BB_SUID_DROP)) IF_ARPING(APPLET(arping, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_AWK(APPLET_NOEXEC(awk, awk, BB_DIR_USR_BIN, BB_SUID_DROP, awk)) IF_BASENAME(APPLET_NOFORK(basename, basename, BB_DIR_USR_BIN, BB_SUID_DROP, basename)) IF_BBCONFIG(APPLET(bbconfig, BB_DIR_BIN, BB_SUID_DROP)) IF_BEEP(APPLET(beep, BB_DIR_USR_BIN, BB_SUID_DROP)) -- cgit v1.2.3-55-g6feb From 73225b6d6e14f63e048fd95b504a2d909684699f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 13 Nov 2013 12:45:33 +0100 Subject: switch editors/* to embedded-in-source kbuild system Signed-off-by: Denys Vlasenko --- editors/Config.src | 45 --------------------------------------------- editors/Kbuild.src | 4 ---- editors/cmp.c | 11 +++++++++++ editors/diff.c | 27 +++++++++++++++++++++++++++ editors/ed.c | 12 ++++++++++++ editors/sed.c | 11 +++++++++++ include/applets.src.h | 4 ---- 7 files changed, 61 insertions(+), 53 deletions(-) diff --git a/editors/Config.src b/editors/Config.src index d3bd46e40..c6e9d92af 100644 --- a/editors/Config.src +++ b/editors/Config.src @@ -7,51 +7,6 @@ menu "Editors" INSERT -config CMP - bool "cmp" - default y - help - cmp is used to compare two files and returns the result - to standard output. - -config DIFF - bool "diff" - default y - help - diff compares two files or directories and outputs the - differences between them in a form that can be given to - the patch command. - -config FEATURE_DIFF_LONG_OPTIONS - bool "Enable long options" - default y - depends on DIFF && LONG_OPTS - help - Enable use of long options. - -config FEATURE_DIFF_DIR - bool "Enable directory support" - default y - depends on DIFF - help - This option enables support for directory and subdirectory - comparison. - -config ED - bool "ed" - default y - help - The original 1970's Unix text editor, from the days of teletypes. - Small, simple, evil. Part of SUSv3. If you're not already using - this, you don't need it. - -config SED - bool "sed" - default y - help - sed is used to perform text transformations on a file - or input from a pipeline. - config FEATURE_ALLOW_EXEC bool "Allow vi and awk to execute shell commands" default y diff --git a/editors/Kbuild.src b/editors/Kbuild.src index 15d7a4cac..6b4fb7470 100644 --- a/editors/Kbuild.src +++ b/editors/Kbuild.src @@ -7,7 +7,3 @@ lib-y:= INSERT -lib-$(CONFIG_CMP) += cmp.o -lib-$(CONFIG_DIFF) += diff.o -lib-$(CONFIG_ED) += ed.o -lib-$(CONFIG_SED) += sed.o diff --git a/editors/cmp.c b/editors/cmp.c index fbe6b9753..a4af6f480 100644 --- a/editors/cmp.c +++ b/editors/cmp.c @@ -10,6 +10,17 @@ /* 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" +//config: default y +//config: help +//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)) + //usage:#define cmp_trivial_usage //usage: "[-l] [-s] FILE1 [FILE2" IF_DESKTOP(" [SKIP1 [SKIP2]]") "]" //usage:#define cmp_full_usage "\n\n" diff --git a/editors/diff.c b/editors/diff.c index b08ded3a1..a78a0ee28 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -76,6 +76,33 @@ * 6n words for files of length n. */ +//config:config DIFF +//config: bool "diff" +//config: default y +//config: help +//config: diff compares two files or directories and outputs the +//config: differences between them in a form that can be given to +//config: the patch command. +//config: +//config:config FEATURE_DIFF_LONG_OPTIONS +//config: bool "Enable long options" +//config: default y +//config: depends on DIFF && LONG_OPTS +//config: help +//config: Enable use of long options. +//config: +//config:config FEATURE_DIFF_DIR +//config: bool "Enable directory support" +//config: default y +//config: depends on DIFF +//config: help +//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)) + //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/ed.c b/editors/ed.c index dbb51306c..3087fb0b9 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -7,6 +7,18 @@ * The "ed" built-in command (much simplified) */ +//config:config ED +//config: bool "ed" +//config: default y +//config: help +//config: The original 1970's Unix text editor, from the days of teletypes. +//config: Small, simple, evil. Part of SUSv3. If you're not already using +//config: this, you don't need it. + +//kbuild:lib-$(CONFIG_ED) += ed.o + +//applet:IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP)) + //usage:#define ed_trivial_usage "" //usage:#define ed_full_usage "" diff --git a/editors/sed.c b/editors/sed.c index 971375884..777f38308 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -58,6 +58,17 @@ * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html */ +//config:config SED +//config: bool "sed" +//config: default y +//config: help +//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)) + //usage:#define sed_trivial_usage //usage: "[-inrE] [-f FILE]... [-e CMD]... [FILE]...\n" //usage: "or: sed [-inrE] CMD [FILE]..." diff --git a/include/applets.src.h b/include/applets.src.h index ac8f18056..0ba88f965 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -104,7 +104,6 @@ IF_CHRT(APPLET(chrt, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CHVT(APPLET(chvt, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_CMP(APPLET(cmp, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP)) @@ -122,7 +121,6 @@ IF_DEVFSD(APPLET(devfsd, BB_DIR_SBIN, BB_SUID_DROP)) IF_DEVMEM(APPLET(devmem, BB_DIR_SBIN, BB_SUID_DROP)) IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP)) IF_DHCPRELAY(APPLET(dhcprelay, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_DIFF(APPLET(diff, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_DIRNAME(APPLET_NOFORK(dirname, dirname, BB_DIR_USR_BIN, BB_SUID_DROP, dirname)) IF_DMESG(APPLET(dmesg, BB_DIR_BIN, BB_SUID_DROP)) IF_DNSD(APPLET(dnsd, BB_DIR_USR_SBIN, BB_SUID_DROP)) @@ -136,7 +134,6 @@ IF_DUMPLEASES(APPLET(dumpleases, BB_DIR_USR_BIN, BB_SUID_DROP)) //IF_E2FSCK(APPLET(e2fsck, BB_DIR_SBIN, BB_SUID_DROP)) //IF_E2LABEL(APPLET_ODDNAME(e2label, tune2fs, BB_DIR_SBIN, BB_SUID_DROP, e2label)) IF_ECHO(APPLET_NOFORK(echo, echo, BB_DIR_BIN, BB_SUID_DROP, echo)) -IF_ED(APPLET(ed, BB_DIR_BIN, BB_SUID_DROP)) IF_EJECT(APPLET(eject, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env)) IF_ENVDIR(APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir)) @@ -317,7 +314,6 @@ IF_RUNSVDIR(APPLET(runsvdir, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RX(APPLET(rx, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_SCRIPT(APPLET(script, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_SCRIPTREPLAY(APPLET(scriptreplay, BB_DIR_BIN, BB_SUID_DROP)) -IF_SED(APPLET(sed, BB_DIR_BIN, BB_SUID_DROP)) IF_SELINUXENABLED(APPLET(selinuxenabled, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_SENDMAIL(APPLET(sendmail, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq)) -- cgit v1.2.3-55-g6feb From 66620fa62691271d777d11c562f894c65cd4f094 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Nov 2013 09:53:52 +0100 Subject: archival/*: move "kbuild:" snippets into .c files Signed-off-by: Denys Vlasenko --- archival/Kbuild.src | 19 ------------------- archival/ar.c | 2 ++ archival/bbunzip.c | 14 +++++++++++--- archival/bzip2.c | 2 ++ archival/cpio.c | 2 ++ archival/dpkg.c | 2 ++ archival/dpkg_deb.c | 2 ++ archival/gzip.c | 2 ++ archival/lzop.c | 2 ++ archival/rpm.c | 2 ++ archival/rpm2cpio.c | 2 ++ archival/tar.c | 2 ++ archival/unzip.c | 8 ++++---- 13 files changed, 35 insertions(+), 26 deletions(-) diff --git a/archival/Kbuild.src b/archival/Kbuild.src index 3466452f7..a6fd2eac0 100644 --- a/archival/Kbuild.src +++ b/archival/Kbuild.src @@ -9,22 +9,3 @@ libs-y += libarchive/ lib-y:= INSERT - -lib-$(CONFIG_AR) += ar.o -lib-$(CONFIG_CPIO) += cpio.o -lib-$(CONFIG_DPKG) += dpkg.o -lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o -lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o -lib-$(CONFIG_RPM) += rpm.o -lib-$(CONFIG_TAR) += tar.o -lib-$(CONFIG_UNZIP) += unzip.o - -lib-$(CONFIG_LZOP) += lzop.o bbunzip.o -lib-$(CONFIG_GZIP) += gzip.o bbunzip.o -lib-$(CONFIG_BZIP2) += bzip2.o bbunzip.o - -lib-$(CONFIG_UNXZ) += bbunzip.o -lib-$(CONFIG_UNLZMA) += bbunzip.o -lib-$(CONFIG_BUNZIP2) += bbunzip.o -lib-$(CONFIG_GUNZIP) += bbunzip.o -lib-$(CONFIG_UNCOMPRESS) += bbunzip.o diff --git a/archival/ar.c b/archival/ar.c index 88236e878..0a8d828d6 100644 --- a/archival/ar.c +++ b/archival/ar.c @@ -17,6 +17,8 @@ * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html */ +//kbuild:lib-$(CONFIG_AR) += ar.o + //usage:#define ar_trivial_usage //usage: "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES" //usage:#define ar_full_usage "\n\n" diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 3735e3282..f2d796e67 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -7,6 +7,9 @@ #include "libbb.h" #include "bb_archive.h" +/* lzop_main() uses bbunpack(), need this: */ +//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o + /* Note: must be kept in sync with archival/lzop.c */ enum { OPT_STDOUT = 1 << 0, @@ -205,7 +208,6 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext) * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //usage:#define uncompress_trivial_usage //usage: "[-cf] [FILE]..." //usage:#define uncompress_full_usage "\n\n" @@ -213,6 +215,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext) //usage: "\n -c Write to stdout" //usage: "\n -f Overwrite" +//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o #if ENABLE_UNCOMPRESS static IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux) @@ -257,7 +260,6 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv) * See the license_msg below and the file COPYING for the software license. * See the file algorithm.doc for the compression algorithms and file formats. */ - //usage:#define gunzip_trivial_usage //usage: "[-cft] [FILE]..." //usage:#define gunzip_full_usage "\n\n" @@ -278,6 +280,8 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv) //usage:#define zcat_full_usage "\n\n" //usage: "Decompress to stdout" +//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o +//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o #if ENABLE_GUNZIP static char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM) @@ -356,8 +360,11 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) //usage: "[FILE]..." //usage:#define bzcat_full_usage "\n\n" //usage: "Decompress to stdout" + //applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) //applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) +//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o +//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o #if ENABLE_BUNZIP2 static IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux) @@ -385,7 +392,6 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv) * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //usage:#define unlzma_trivial_usage //usage: "[-cf] [FILE]..." //usage:#define unlzma_full_usage "\n\n" @@ -426,6 +432,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv) //usage:#define xzcat_full_usage "\n\n" //usage: "Decompress to stdout" +//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o #if ENABLE_UNLZMA static IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux) @@ -451,6 +458,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) #endif +//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o #if ENABLE_UNXZ static IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux) diff --git a/archival/bzip2.c b/archival/bzip2.c index dd77c8efc..485afeb24 100644 --- a/archival/bzip2.c +++ b/archival/bzip2.c @@ -7,6 +7,8 @@ * about bzip2 library code. */ +//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o + //usage:#define bzip2_trivial_usage //usage: "[OPTIONS] [FILE]..." //usage:#define bzip2_full_usage "\n\n" diff --git a/archival/cpio.c b/archival/cpio.c index 699c6dbb7..c228aabcc 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -14,6 +14,8 @@ #include "libbb.h" #include "bb_archive.h" +//kbuild:lib-$(CONFIG_CPIO) += cpio.o + //usage:#define cpio_trivial_usage //usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]") //usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]") diff --git a/archival/dpkg.c b/archival/dpkg.c index ed86f3355..cd88a79c2 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -28,6 +28,8 @@ * */ +//kbuild:lib-$(CONFIG_DPKG) += dpkg.o + //usage:#define dpkg_trivial_usage //usage: "[-ilCPru] [-F OPT] PACKAGE" //usage:#define dpkg_full_usage "\n\n" diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index a04ec9407..39ae3e45e 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -5,6 +5,8 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o + //usage:#define dpkg_deb_trivial_usage //usage: "[-cefxX] FILE [argument" //usage:#define dpkg_deb_full_usage "\n\n" diff --git a/archival/gzip.c b/archival/gzip.c index 31ccab3cd..c850d5f5f 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -39,6 +39,8 @@ gzip: bogus: No such file or directory aa: 85.1% -- replaced with aa.gz */ +//kbuild:lib-$(CONFIG_GZIP) += gzip.o + //usage:#define gzip_trivial_usage //usage: "[-cfd] [FILE]..." //usage:#define gzip_full_usage "\n\n" diff --git a/archival/lzop.c b/archival/lzop.c index 9b42e5fd3..3c29b6eb8 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -25,6 +25,8 @@ "Minimalized" for busybox by Alain Knaff */ +//kbuild:lib-$(CONFIG_LZOP) += lzop.o + //usage:#define lzop_trivial_usage //usage: "[-cfvd123456789CF] [FILE]..." //usage:#define lzop_full_usage "\n\n" diff --git a/archival/rpm.c b/archival/rpm.c index 86ba4dca4..3c386d238 100644 --- a/archival/rpm.c +++ b/archival/rpm.c @@ -7,6 +7,8 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//kbuild:lib-$(CONFIG_RPM) += rpm.o + //usage:#define rpm_trivial_usage //usage: "-i PACKAGE.rpm; rpm -qp[ildc] PACKAGE.rpm" //usage:#define rpm_full_usage "\n\n" diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c index f3dfa5159..cd6786cc7 100644 --- a/archival/rpm2cpio.c +++ b/archival/rpm2cpio.c @@ -7,6 +7,8 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o + //usage:#define rpm2cpio_trivial_usage //usage: "package.rpm" //usage:#define rpm2cpio_full_usage "\n\n" diff --git a/archival/tar.c b/archival/tar.c index 3cd033be3..f75a82ad9 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -42,6 +42,8 @@ * This doesn't feel right, and IIRC GNU tar doesn't do that. */ +//kbuild:lib-$(CONFIG_TAR) += tar.o + #include #include "libbb.h" #include "bb_archive.h" diff --git a/archival/unzip.c b/archival/unzip.c index 673e5fe08..71f3fbb68 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -9,16 +9,16 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* For reference see * http://www.pkware.com/company/standards/appnote/ * http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip - */ - -/* TODO + * + * TODO * Zip64 + other methods */ +//kbuild:lib-$(CONFIG_UNZIP) += unzip.o + //usage:#define unzip_trivial_usage //usage: "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]" //usage:#define unzip_full_usage "\n\n" -- cgit v1.2.3-55-g6feb From 36184a487d20d4ae168c2ae247dd064b1e9f4f64 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Nov 2013 09:54:24 +0100 Subject: archival/*: move "applet:" snippets into .c files Signed-off-by: Denys Vlasenko --- archival/ar.c | 1 + archival/bbunzip.c | 8 +++++--- archival/bzip2.c | 1 + archival/cpio.c | 2 +- archival/dpkg.c | 2 +- archival/dpkg_deb.c | 1 + archival/gzip.c | 1 + archival/lzop.c | 1 + archival/rpm.c | 1 + archival/rpm2cpio.c | 1 + archival/tar.c | 1 + include/applets.src.h | 15 --------------- 12 files changed, 15 insertions(+), 20 deletions(-) diff --git a/archival/ar.c b/archival/ar.c index 0a8d828d6..866856f87 100644 --- a/archival/ar.c +++ b/archival/ar.c @@ -17,6 +17,7 @@ * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html */ +//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 f2d796e67..d34f56885 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -215,6 +215,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext) //usage: "\n -c Write to stdout" //usage: "\n -f Overwrite" +//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o #if ENABLE_UNCOMPRESS static @@ -256,9 +257,6 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv) * Portions of the lzw code are derived from the public domain 'compress' * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies, * Ken Turkowski, Dave Mack and Peter Jannesen. - * - * See the license_msg below and the file COPYING for the software license. - * See the file algorithm.doc for the compression algorithms and file formats. */ //usage:#define gunzip_trivial_usage //usage: "[-cft] [FILE]..." @@ -280,6 +278,8 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv) //usage:#define zcat_full_usage "\n\n" //usage: "Decompress to stdout" +//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat)) //kbuild:lib-$(CONFIG_GZIP) += bbunzip.o //kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o #if ENABLE_GUNZIP @@ -432,6 +432,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv) //usage:#define xzcat_full_usage "\n\n" //usage: "Decompress to stdout" +//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o #if ENABLE_UNLZMA static @@ -458,6 +459,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) #endif +//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o #if ENABLE_UNXZ static diff --git a/archival/bzip2.c b/archival/bzip2.c index 485afeb24..eabd1c2d6 100644 --- a/archival/bzip2.c +++ b/archival/bzip2.c @@ -7,6 +7,7 @@ * about bzip2 library code. */ +//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 c228aabcc..41eb6f659 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -9,11 +9,11 @@ * Limitations: * Doesn't check CRC's * Only supports new ASCII and CRC formats - * */ #include "libbb.h" #include "bb_archive.h" +//applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_CPIO) += cpio.o //usage:#define cpio_trivial_usage diff --git a/archival/dpkg.c b/archival/dpkg.c index cd88a79c2..288e7fa9f 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -25,9 +25,9 @@ * * bugs that need to be fixed * - (unknown, please let me know when you find any) - * */ +//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 39ae3e45e..6924f8911 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -5,6 +5,7 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb)) //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o //usage:#define dpkg_deb_trivial_usage diff --git a/archival/gzip.c b/archival/gzip.c index c850d5f5f..5d6fdb91c 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -39,6 +39,7 @@ gzip: bogus: No such file or directory aa: 85.1% -- replaced with aa.gz */ +//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 3c29b6eb8..a7b42ac9d 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -25,6 +25,7 @@ "Minimalized" for busybox by Alain Knaff */ +//applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_LZOP) += lzop.o //usage:#define lzop_trivial_usage diff --git a/archival/rpm.c b/archival/rpm.c index 3c386d238..81a1d1d54 100644 --- a/archival/rpm.c +++ b/archival/rpm.c @@ -7,6 +7,7 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_RPM) += rpm.o //usage:#define rpm_trivial_usage diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c index cd6786cc7..c48fc14cd 100644 --- a/archival/rpm2cpio.c +++ b/archival/rpm2cpio.c @@ -7,6 +7,7 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o //usage:#define rpm2cpio_trivial_usage diff --git a/archival/tar.c b/archival/tar.c index f75a82ad9..25042589c 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -42,6 +42,7 @@ * This doesn't feel right, and IIRC GNU tar doesn't do that. */ +//applet:IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_TAR) += tar.o #include diff --git a/include/applets.src.h b/include/applets.src.h index 0ba88f965..0edfaaced 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -79,7 +79,6 @@ IF_ACPID(APPLET(acpid, BB_DIR_SBIN, BB_SUID_DROP)) IF_ADDGROUP(APPLET(addgroup, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_ADDUSER(APPLET(adduser, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP)) -IF_AR(APPLET(ar, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_ARP(APPLET(arp, BB_DIR_SBIN, BB_SUID_DROP)) IF_ARPING(APPLET(arping, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_BASENAME(APPLET_NOFORK(basename, basename, BB_DIR_USR_BIN, BB_SUID_DROP, basename)) @@ -87,7 +86,6 @@ IF_BBCONFIG(APPLET(bbconfig, BB_DIR_BIN, BB_SUID_DROP)) IF_BEEP(APPLET(beep, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_BLKID(APPLET(blkid, BB_DIR_SBIN, BB_SUID_DROP)) IF_BRCTL(APPLET(brctl, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CAL(APPLET(cal, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat)) IF_CATV(APPLET(catv, BB_DIR_BIN, BB_SUID_DROP)) @@ -106,7 +104,6 @@ IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) IF_CLEAR(APPLET(clear, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) -IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP)) IF_CROND(APPLET(crond, BB_DIR_USR_SBIN, BB_SUID_DROP)) /* Needs to be run by root or be suid root - needs to change /var/spool/cron* files: */ IF_CRONTAB(APPLET(crontab, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) @@ -126,8 +123,6 @@ IF_DMESG(APPLET(dmesg, BB_DIR_BIN, BB_SUID_DROP)) IF_DNSD(APPLET(dnsd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_HOSTNAME(APPLET_ODDNAME(dnsdomainname, hostname, BB_DIR_BIN, BB_SUID_DROP, dnsdomainname)) IF_DOS2UNIX(APPLET_NOEXEC(dos2unix, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, dos2unix)) -IF_DPKG(APPLET(dpkg, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb)) IF_DU(APPLET(du, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_DUMPKMAP(APPLET(dumpkmap, BB_DIR_BIN, BB_SUID_DROP)) IF_DUMPLEASES(APPLET(dumpleases, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -172,8 +167,6 @@ IF_GETENFORCE(APPLET(getenforce, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_GETOPT(APPLET(getopt, BB_DIR_BIN, BB_SUID_DROP)) IF_GETSEBOOL(APPLET(getsebool, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP)) -IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP)) -IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) IF_HD(APPLET_NOEXEC(hd, hexdump, BB_DIR_USR_BIN, BB_SUID_DROP, hd)) IF_HDPARM(APPLET(hdparm, BB_DIR_SBIN, BB_SUID_DROP)) IF_HEAD(APPLET_NOEXEC(head, head, BB_DIR_USR_BIN, BB_SUID_DROP, head)) @@ -303,8 +296,6 @@ IF_RFKILL(APPLET(rfkill, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm)) IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir)) IF_ROUTE(APPLET(route, BB_DIR_SBIN, BB_SUID_DROP)) -IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP)) -IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RTCWAKE(APPLET(rtcwake, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts)) IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -357,7 +348,6 @@ IF_BB_SYSCTL(APPLET(sysctl, BB_DIR_SBIN, BB_SUID_DROP)) IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP)) IF_TAC(APPLET_NOEXEC(tac, tac, BB_DIR_USR_BIN, BB_SUID_DROP, tac)) IF_TAIL(APPLET(tail, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP)) IF_TASKSET(APPLET(taskset, BB_DIR_USR_BIN, BB_SUID_DROP)) /* IF_TC(APPLET(tc, BB_DIR_SBIN, BB_SUID_DROP)) */ IF_TCPSVD(APPLET_ODDNAME(tcpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, tcpsvd)) @@ -386,14 +376,10 @@ IF_UDHCPD(APPLET(udhcpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_UDPSVD(APPLET_ODDNAME(udpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, udpsvd)) IF_UMOUNT(APPLET(umount, BB_DIR_BIN, BB_SUID_DROP)) IF_UNAME(APPLET(uname, BB_DIR_BIN, BB_SUID_DROP)) -IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP)) IF_UNEXPAND(APPLET_ODDNAME(unexpand, expand, BB_DIR_USR_BIN, BB_SUID_DROP, unexpand)) IF_UNIQ(APPLET(uniq, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_UNIX2DOS(APPLET_NOEXEC(unix2dos, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, unix2dos)) -IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop)) -IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_UPTIME(APPLET(uptime, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_USLEEP(APPLET_NOFORK(usleep, usleep, BB_DIR_BIN, BB_SUID_DROP, usleep)) IF_UUDECODE(APPLET(uudecode, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -411,7 +397,6 @@ IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami)) IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat)) IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz)) IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes)) -IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat)) IF_ZCIP(APPLET(zcip, BB_DIR_SBIN, BB_SUID_DROP)) #if !defined(PROTOTYPES) && !defined(NAME_MAIN_CNAME) && !defined(MAKE_USAGE) \ -- cgit v1.2.3-55-g6feb From ac216873095a0d7c30737df5cdfa3bf6c261f079 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Nov 2013 11:38:18 +0100 Subject: archival/*: move "applet:" snippets into .c files, part 2 Signed-off-by: Denys Vlasenko --- archival/bbunzip.c | 4 ++++ archival/lzop.c | 4 +++- archival/unzip.c | 1 + include/applets.src.h | 7 ------- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/archival/bbunzip.c b/archival/bbunzip.c index d34f56885..eb6f114ad 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -433,6 +433,8 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv) //usage: "Decompress to stdout" //applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat)) +//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma)) //kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o #if ENABLE_UNLZMA static @@ -460,6 +462,8 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) //applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat)) +//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz)) //kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o #if ENABLE_UNXZ static diff --git a/archival/lzop.c b/archival/lzop.c index a7b42ac9d..9007d5311 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -25,7 +25,9 @@ "Minimalized" for busybox by Alain Knaff */ -//applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP)) +//applet:IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat)) +//applet:IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop)) //kbuild:lib-$(CONFIG_LZOP) += lzop.o //usage:#define lzop_trivial_usage diff --git a/archival/unzip.c b/archival/unzip.c index 71f3fbb68..9825986bf 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -17,6 +17,7 @@ * Zip64 + other methods */ +//applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_UNZIP) += unzip.o //usage:#define unzip_trivial_usage diff --git a/include/applets.src.h b/include/applets.src.h index 0edfaaced..2ceba53bd 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -225,10 +225,6 @@ IF_LS(APPLET_NOEXEC(ls, ls, BB_DIR_BIN, BB_SUID_DROP, ls)) IF_LSATTR(APPLET(lsattr, BB_DIR_BIN, BB_SUID_DROP)) IF_LSPCI(APPLET(lspci, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_LSUSB(APPLET(lsusb, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat)) -IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma)) -IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP)) -IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat)) IF_MAKEDEVS(APPLET(makedevs, BB_DIR_SBIN, BB_SUID_DROP)) IF_MAKEMIME(APPLET(makemime, BB_DIR_BIN, BB_SUID_DROP)) IF_MAN(APPLET(man, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -379,7 +375,6 @@ IF_UNAME(APPLET(uname, BB_DIR_BIN, BB_SUID_DROP)) IF_UNEXPAND(APPLET_ODDNAME(unexpand, expand, BB_DIR_USR_BIN, BB_SUID_DROP, unexpand)) IF_UNIQ(APPLET(uniq, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_UNIX2DOS(APPLET_NOEXEC(unix2dos, dos2unix, BB_DIR_USR_BIN, BB_SUID_DROP, unix2dos)) -IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop)) IF_UPTIME(APPLET(uptime, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_USLEEP(APPLET_NOFORK(usleep, usleep, BB_DIR_BIN, BB_SUID_DROP, usleep)) IF_UUDECODE(APPLET(uudecode, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -394,8 +389,6 @@ IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_WGET(APPLET(wget, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami)) -IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat)) -IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz)) IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes)) IF_ZCIP(APPLET(zcip, BB_DIR_SBIN, BB_SUID_DROP)) -- cgit v1.2.3-55-g6feb From f6beef63c64abfc126ea4e73147af29d152f1a9e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 14 Nov 2013 11:39:00 +0100 Subject: archival/*: move "config:" snippets into .c files Signed-off-by: Denys Vlasenko --- archival/Config.src | 350 +--------------------------------------------------- archival/ar.c | 40 ++++++ archival/bbunzip.c | 70 +++++++++++ archival/bzip2.c | 13 ++ archival/cpio.c | 29 +++++ archival/dpkg.c | 12 +- archival/dpkg_deb.c | 22 ++++ archival/gzip.c | 28 ++++- archival/lzop.c | 15 +++ archival/rpm.c | 6 + archival/rpm2cpio.c | 6 + archival/tar.c | 101 ++++++++++++++- archival/unzip.c | 10 ++ 13 files changed, 349 insertions(+), 353 deletions(-) diff --git a/archival/Config.src b/archival/Config.src index ae1afc594..76635ba78 100644 --- a/archival/Config.src +++ b/archival/Config.src @@ -5,8 +5,6 @@ menu "Archival Utilities" -INSERT - config FEATURE_SEAMLESS_XZ bool "Make tar, rpm, modprobe etc understand .xz data" default y @@ -37,352 +35,6 @@ config FEATURE_SEAMLESS_Z help Make tar, rpm, modprobe etc understand .Z data. -config AR - bool "ar" - default n # needs to be improved to be able to replace binutils ar - help - ar is an archival utility program used to create, modify, and - extract contents from archives. An archive is a single file holding - a collection of other files in a structure that makes it possible to - retrieve the original individual files (called archive members). - The original files' contents, mode (permissions), timestamp, owner, - and group are preserved in the archive, and can be restored on - extraction. - - The stored filename is limited to 15 characters. (for more information - see long filename support). - ar has 60 bytes of overheads for every stored file. - - This implementation of ar can extract archives, it cannot create or - modify them. - On an x86 system, the ar applet adds about 1K. - - Unless you have a specific application which requires ar, you should - probably say N here. - -config FEATURE_AR_LONG_FILENAMES - bool "Support for long filenames (not needed for debs)" - default y - depends on AR - help - By default the ar format can only store the first 15 characters - of the filename, this option removes that limitation. - It supports the GNU ar long filename method which moves multiple long - filenames into a the data section of a new ar entry. - -config FEATURE_AR_CREATE - bool "Support archive creation" - default y - depends on AR - help - This enables archive creation (-c and -r) with busybox ar. - -config BUNZIP2 - bool "bunzip2" - default y - help - bunzip2 is a compression utility using the Burrows-Wheeler block - sorting text compression algorithm, and Huffman coding. Compression - is generally considerably better than that achieved by more - conventional LZ77/LZ78-based compressors, and approaches the - performance of the PPM family of statistical compressors. - - Unless you have a specific application which requires bunzip2, you - should probably say N here. - -config BZIP2 - bool "bzip2" - default y - help - bzip2 is a compression utility using the Burrows-Wheeler block - sorting text compression algorithm, and Huffman coding. Compression - is generally considerably better than that achieved by more - conventional LZ77/LZ78-based compressors, and approaches the - performance of the PPM family of statistical compressors. - - Unless you have a specific application which requires bzip2, you - should probably say N here. - -config CPIO - bool "cpio" - default y - help - cpio is an archival utility program used to create, modify, and - extract contents from archives. - cpio has 110 bytes of overheads for every stored file. - - This implementation of cpio can extract cpio archives created in the - "newc" or "crc" format, it cannot create or modify them. - - Unless you have a specific application which requires cpio, you - should probably say N here. - -config FEATURE_CPIO_O - bool "Support for archive creation" - default y - depends on CPIO - help - This implementation of cpio can create cpio archives in the "newc" - format only. - -config FEATURE_CPIO_P - bool "Support for passthrough mode" - default y - depends on FEATURE_CPIO_O - help - Passthrough mode. Rarely used. - -config DPKG - bool "dpkg" - default n - select FEATURE_SEAMLESS_GZ - help - dpkg is a medium-level tool to install, build, remove and manage - Debian packages. - - This implementation of dpkg has a number of limitations, - you should use the official dpkg if possible. - -config DPKG_DEB - bool "dpkg_deb" - default n - select FEATURE_SEAMLESS_GZ - help - dpkg-deb unpacks and provides information about Debian archives. - - This implementation of dpkg-deb cannot pack archives. - - Unless you have a specific application which requires dpkg-deb, - say N here. - -config FEATURE_DPKG_DEB_EXTRACT_ONLY - bool "Extract only (-x)" - default n - depends on DPKG_DEB - help - This reduces dpkg-deb to the equivalent of - "ar -p data.tar.gz | tar -zx". However it saves space as none - of the extra dpkg-deb, ar or tar options are needed, they are linked - to internally. - -config GUNZIP - bool "gunzip" - default y - help - gunzip is used to decompress archives created by gzip. - You can use the `-t' option to test the integrity of - an archive, without decompressing it. - -config GZIP - bool "gzip" - default y - help - gzip is used to compress files. - It's probably the most widely used UNIX compression program. - -config FEATURE_GZIP_LONG_OPTIONS - bool "Enable long options" - default y - depends on GZIP && LONG_OPTS - help - Enable use of long options, increases size by about 106 Bytes - -config GZIP_FAST - int "Trade memory for gzip speed (0:small,slow - 2:fast,big)" - default 0 - range 0 2 - depends on GZIP - help - Enable big memory options for gzip. - 0: small buffers, small hash-tables - 1: larger buffers, larger hash-tables - 2: larger buffers, largest hash-tables - Larger models may give slightly better compression - -config LZOP - bool "lzop" - default y - help - Lzop compression/decompresion. - -config LZOP_COMPR_HIGH - bool "lzop compression levels 7,8,9 (not very useful)" - default n - depends on LZOP - help - High levels (7,8,9) of lzop compression. These levels - are actually slower than gzip at equivalent compression ratios - and take up 3.2K of code. - -config RPM2CPIO - bool "rpm2cpio" - default y - help - Converts a RPM file into a CPIO archive. - -config RPM - bool "rpm" - default y - help - Mini RPM applet - queries and extracts RPM packages. - -config TAR - bool "tar" - default y - help - tar is an archiving program. It's commonly used with gzip to - create compressed archives. It's probably the most widely used - UNIX archive program. - -config FEATURE_TAR_CREATE - bool "Enable archive creation" - default y - depends on TAR - help - If you enable this option you'll be able to create - tar archives using the `-c' option. - -config FEATURE_TAR_AUTODETECT - bool "Autodetect compressed tarballs" - default y - depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ) - help - With this option tar can automatically detect compressed - tarballs. Currently it works only on files (not pipes etc). - -config FEATURE_TAR_FROM - bool "Enable -X (exclude from) and -T (include from) options)" - default y - depends on TAR - help - If you enable this option you'll be able to specify - a list of files to include or exclude from an archive. - -config FEATURE_TAR_OLDGNU_COMPATIBILITY - bool "Support for old tar header format" - default y - depends on TAR || DPKG - help - This option is required to unpack archives created in - the old GNU format; help to kill this old format by - repacking your ancient archives with the new format. - -config FEATURE_TAR_OLDSUN_COMPATIBILITY - bool "Enable untarring of tarballs with checksums produced by buggy Sun tar" - default y - depends on TAR || DPKG - help - This option is required to unpack archives created by some old - version of Sun's tar (it was calculating checksum using signed - arithmetic). It is said to be fixed in newer Sun tar, but "old" - tarballs still exist. - -config FEATURE_TAR_GNU_EXTENSIONS - bool "Support for GNU tar extensions (long filenames)" - default y - depends on TAR || DPKG - help - With this option busybox supports GNU long filenames and - linknames. - -config FEATURE_TAR_LONG_OPTIONS - bool "Enable long options" - default y - depends on TAR && LONG_OPTS - help - Enable use of long options, increases size by about 400 Bytes - -config FEATURE_TAR_TO_COMMAND - bool "Support for writing to an external program" - default y - depends on TAR && FEATURE_TAR_LONG_OPTIONS - help - If you enable this option you'll be able to instruct tar to send - the contents of each extracted file to the standard input of an - external program. - -config FEATURE_TAR_UNAME_GNAME - bool "Enable use of user and group names" - default y - depends on TAR - help - Enables use of user and group names in tar. This affects contents - listings (-t) and preserving permissions when unpacking (-p). - +200 bytes. - -config FEATURE_TAR_NOPRESERVE_TIME - bool "Enable -m (do not preserve time) option" - default y - depends on TAR - help - With this option busybox supports GNU tar -m - (do not preserve time) option. - -config FEATURE_TAR_SELINUX - bool "Support for extracting SELinux labels" - default n - depends on TAR && SELINUX - help - With this option busybox supports restoring SELinux labels - when extracting files from tar archives. - -config UNCOMPRESS - bool "uncompress" - default n - help - uncompress is used to decompress archives created by compress. - Not much used anymore, replaced by gzip/gunzip. - -config UNLZMA - bool "unlzma" - default y - help - unlzma is a compression utility using the Lempel-Ziv-Markov chain - compression algorithm, and range coding. Compression - is generally considerably better than that achieved by the bzip2 - compressors. - - The BusyBox unlzma applet is limited to decompression only. - On an x86 system, this applet adds about 4K. - -config FEATURE_LZMA_FAST - bool "Optimize unlzma for speed" - default n - depends on UNLZMA - help - This option reduces decompression time by about 25% at the cost of - a 1K bigger binary. - -config LZMA - bool "Provide lzma alias which supports only unpacking" - default y - depends on UNLZMA - help - Enable this option if you want commands like "lzma -d" to work. - IOW: you'll get lzma applet, but it will always require -d option. - -config UNXZ - bool "unxz" - default y - help - unxz is a unlzma successor. - -config XZ - bool "Provide xz alias which supports only unpacking" - default y - depends on UNXZ - help - Enable this option if you want commands like "xz -d" to work. - IOW: you'll get xz applet, but it will always require -d option. - -config UNZIP - bool "unzip" - default y - help - unzip will list or extract files from a ZIP archive, - commonly found on DOS/WIN systems. The default behavior - (with no options) is to extract the archive into the - current directory. Use the `-d' option to extract to a - directory of your choice. +INSERT endmenu diff --git a/archival/ar.c b/archival/ar.c index 866856f87..f86c52d9b 100644 --- a/archival/ar.c +++ b/archival/ar.c @@ -17,6 +17,46 @@ * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html */ +//config:config AR +//config: bool "ar" +//config: default n # needs to be improved to be able to replace binutils ar +//config: help +//config: ar is an archival utility program used to create, modify, and +//config: extract contents from archives. An archive is a single file holding +//config: a collection of other files in a structure that makes it possible to +//config: retrieve the original individual files (called archive members). +//config: The original files' contents, mode (permissions), timestamp, owner, +//config: and group are preserved in the archive, and can be restored on +//config: extraction. +//config: +//config: The stored filename is limited to 15 characters. (for more information +//config: see long filename support). +//config: ar has 60 bytes of overheads for every stored file. +//config: +//config: This implementation of ar can extract archives, it cannot create or +//config: modify them. +//config: On an x86 system, the ar applet adds about 1K. +//config: +//config: Unless you have a specific application which requires ar, you should +//config: probably say N here. +//config: +//config:config FEATURE_AR_LONG_FILENAMES +//config: bool "Support for long filenames (not needed for debs)" +//config: default y +//config: depends on AR +//config: help +//config: By default the ar format can only store the first 15 characters +//config: of the filename, this option removes that limitation. +//config: It supports the GNU ar long filename method which moves multiple long +//config: filenames into a the data section of a new ar entry. +//config: +//config:config FEATURE_AR_CREATE +//config: bool "Support archive creation" +//config: default y +//config: depends on AR +//config: help +//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 diff --git a/archival/bbunzip.c b/archival/bbunzip.c index eb6f114ad..b3fb90f31 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -215,6 +215,13 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext) //usage: "\n -c Write to stdout" //usage: "\n -f Overwrite" +//config:config UNCOMPRESS +//config: bool "uncompress" +//config: default n +//config: help +//config: uncompress is used to decompress archives created by compress. +//config: Not much used anymore, replaced by gzip/gunzip. + //applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o #if ENABLE_UNCOMPRESS @@ -278,6 +285,14 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv) //usage:#define zcat_full_usage "\n\n" //usage: "Decompress to stdout" +//config:config GUNZIP +//config: bool "gunzip" +//config: default y +//config: help +//config: gunzip is used to decompress archives created by gzip. +//config: You can use the `-t' option to test the integrity of +//config: an archive, without decompressing it. + //applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP)) //applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat)) //kbuild:lib-$(CONFIG_GZIP) += bbunzip.o @@ -361,6 +376,19 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) //usage:#define bzcat_full_usage "\n\n" //usage: "Decompress to stdout" +//config:config BUNZIP2 +//config: bool "bunzip2" +//config: default y +//config: help +//config: bunzip2 is a compression utility using the Burrows-Wheeler block +//config: sorting text compression algorithm, and Huffman coding. Compression +//config: is generally considerably better than that achieved by more +//config: conventional LZ77/LZ78-based compressors, and approaches the +//config: performance of the PPM family of statistical compressors. +//config: +//config: Unless you have a specific application which requires bunzip2, you +//config: should probably say N here. + //applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) //applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) //kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o @@ -432,6 +460,34 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv) //usage:#define xzcat_full_usage "\n\n" //usage: "Decompress to stdout" +//config:config UNLZMA +//config: bool "unlzma" +//config: default y +//config: help +//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain +//config: compression algorithm, and range coding. Compression +//config: is generally considerably better than that achieved by the bzip2 +//config: compressors. +//config: +//config: The BusyBox unlzma applet is limited to decompression only. +//config: On an x86 system, this applet adds about 4K. +//config: +//config:config FEATURE_LZMA_FAST +//config: bool "Optimize unlzma for speed" +//config: default n +//config: depends on UNLZMA +//config: help +//config: This option reduces decompression time by about 25% at the cost of +//config: a 1K bigger binary. +//config: +//config:config LZMA +//config: bool "Provide lzma alias which supports only unpacking" +//config: default y +//config: depends on UNLZMA +//config: help +//config: Enable this option if you want commands like "lzma -d" to work. +//config: IOW: you'll get lzma applet, but it will always require -d option. + //applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP)) //applet:IF_UNLZMA(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat)) //applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma)) @@ -461,6 +517,20 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) #endif +//config:config UNXZ +//config: bool "unxz" +//config: default y +//config: help +//config: unxz is a unlzma successor. +//config: +//config:config XZ +//config: bool "Provide xz alias which supports only unpacking" +//config: default y +//config: depends on UNXZ +//config: help +//config: Enable this option if you want commands like "xz -d" to work. +//config: IOW: you'll get xz applet, but it will always require -d option. + //applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP)) //applet:IF_UNXZ(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat)) //applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz)) diff --git a/archival/bzip2.c b/archival/bzip2.c index eabd1c2d6..f7718b411 100644 --- a/archival/bzip2.c +++ b/archival/bzip2.c @@ -7,6 +7,19 @@ * about bzip2 library code. */ +//config:config BZIP2 +//config: bool "bzip2" +//config: default y +//config: help +//config: bzip2 is a compression utility using the Burrows-Wheeler block +//config: sorting text compression algorithm, and Huffman coding. Compression +//config: is generally considerably better than that achieved by more +//config: conventional LZ77/LZ78-based compressors, and approaches the +//config: performance of the PPM family of statistical compressors. +//config: +//config: Unless you have a specific application which requires bzip2, you +//config: should probably say N here. + //applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_BZIP2) += bzip2.o diff --git a/archival/cpio.c b/archival/cpio.c index 41eb6f659..1cce7c8b4 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -13,6 +13,35 @@ #include "libbb.h" #include "bb_archive.h" +//config:config CPIO +//config: bool "cpio" +//config: default y +//config: help +//config: cpio is an archival utility program used to create, modify, and +//config: extract contents from archives. +//config: cpio has 110 bytes of overheads for every stored file. +//config: +//config: This implementation of cpio can extract cpio archives created in the +//config: "newc" or "crc" format, it cannot create or modify them. +//config: +//config: Unless you have a specific application which requires cpio, you +//config: should probably say N here. +//config: +//config:config FEATURE_CPIO_O +//config: bool "Support for archive creation" +//config: default y +//config: depends on CPIO +//config: help +//config: This implementation of cpio can create cpio archives in the "newc" +//config: format only. +//config: +//config:config FEATURE_CPIO_P +//config: bool "Support for passthrough mode" +//config: default y +//config: depends on FEATURE_CPIO_O +//config: help +//config: Passthrough mode. Rarely used. + //applet:IF_CPIO(APPLET(cpio, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_CPIO) += cpio.o diff --git a/archival/dpkg.c b/archival/dpkg.c index 288e7fa9f..2893cfc2d 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -14,7 +14,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* * known difference between busybox dpkg and the official dpkg that i don't * consider important, its worth keeping a note of differences anyway, just to @@ -27,6 +26,17 @@ * - (unknown, please let me know when you find any) */ +//config:config DPKG +//config: bool "dpkg" +//config: default n +//config: select FEATURE_SEAMLESS_GZ +//config: help +//config: dpkg is a medium-level tool to install, build, remove and manage +//config: Debian packages. +//config: +//config: This implementation of dpkg has a number of limitations, +//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 diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 6924f8911..81b5352a2 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -5,6 +5,28 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config DPKG_DEB +//config: bool "dpkg_deb" +//config: default n +//config: select FEATURE_SEAMLESS_GZ +//config: help +//config: dpkg-deb unpacks and provides information about Debian archives. +//config: +//config: This implementation of dpkg-deb cannot pack archives. +//config: +//config: Unless you have a specific application which requires dpkg-deb, +//config: say N here. +//config: +//config:config FEATURE_DPKG_DEB_EXTRACT_ONLY +//config: bool "Extract only (-x)" +//config: default n +//config: depends on DPKG_DEB +//config: help +//config: This reduces dpkg-deb to the equivalent of +//config: "ar -p data.tar.gz | tar -zx". However it saves space as none +//config: of the extra dpkg-deb, ar or tar options are needed, they are linked +//config: to internally. + //applet:IF_DPKG_DEB(APPLET_ODDNAME(dpkg-deb, dpkg_deb, BB_DIR_USR_BIN, BB_SUID_DROP, dpkg_deb)) //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o diff --git a/archival/gzip.c b/archival/gzip.c index 5d6fdb91c..1e779c9c3 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -15,7 +15,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* big objects in bss: * 00000020 b bl_count * 00000074 b base_length @@ -31,7 +30,6 @@ * 00000480 b static_ltree * 000008f4 b dyn_ltree */ - /* TODO: full support for -v for DESKTOP * "/usr/bin/gzip -v a bogus aa" should say: a: 85.1% -- replaced with a.gz @@ -39,6 +37,32 @@ gzip: bogus: No such file or directory aa: 85.1% -- replaced with aa.gz */ +//config:config GZIP +//config: bool "gzip" +//config: default y +//config: help +//config: gzip is used to compress files. +//config: It's probably the most widely used UNIX compression program. +//config: +//config:config FEATURE_GZIP_LONG_OPTIONS +//config: bool "Enable long options" +//config: default y +//config: depends on GZIP && LONG_OPTS +//config: help +//config: Enable use of long options, increases size by about 106 Bytes +//config: +//config:config GZIP_FAST +//config: int "Trade memory for gzip speed (0:small,slow - 2:fast,big)" +//config: default 0 +//config: range 0 2 +//config: depends on GZIP +//config: help +//config: Enable big memory options for gzip. +//config: 0: small buffers, small hash-tables +//config: 1: larger buffers, larger hash-tables +//config: 2: larger buffers, largest hash-tables +//config: Larger models may give slightly better compression + //applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_GZIP) += gzip.o diff --git a/archival/lzop.c b/archival/lzop.c index 9007d5311..5062d9300 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -25,6 +25,21 @@ "Minimalized" for busybox by Alain Knaff */ +//config:config LZOP +//config: bool "lzop" +//config: default y +//config: help +//config: Lzop compression/decompresion. +//config: +//config:config LZOP_COMPR_HIGH +//config: bool "lzop compression levels 7,8,9 (not very useful)" +//config: default n +//config: depends on LZOP +//config: help +//config: High levels (7,8,9) of lzop compression. These levels +//config: are actually slower than gzip at equivalent compression ratios +//config: and take up 3.2K of code. + //applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP)) //applet:IF_LZOP(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat)) //applet:IF_LZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop)) diff --git a/archival/rpm.c b/archival/rpm.c index 81a1d1d54..885eddd64 100644 --- a/archival/rpm.c +++ b/archival/rpm.c @@ -7,6 +7,12 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config RPM +//config: bool "rpm" +//config: default y +//config: help +//config: Mini RPM applet - queries and extracts RPM packages. + //applet:IF_RPM(APPLET(rpm, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_RPM) += rpm.o diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c index c48fc14cd..61adde795 100644 --- a/archival/rpm2cpio.c +++ b/archival/rpm2cpio.c @@ -7,6 +7,12 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config RPM2CPIO +//config: bool "rpm2cpio" +//config: default y +//config: help +//config: Converts a RPM file into a CPIO archive. + //applet:IF_RPM2CPIO(APPLET(rpm2cpio, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o diff --git a/archival/tar.c b/archival/tar.c index 25042589c..3877ea4db 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. */ - /* TODO: security with -C DESTDIR option can be enhanced. * Consider tar file created via: * $ tar cvf bug.tar anything.txt @@ -42,6 +41,106 @@ * This doesn't feel right, and IIRC GNU tar doesn't do that. */ +//config:config TAR +//config: bool "tar" +//config: default y +//config: help +//config: tar is an archiving program. It's commonly used with gzip to +//config: create compressed archives. It's probably the most widely used +//config: UNIX archive program. +//config: +//config:config FEATURE_TAR_CREATE +//config: bool "Enable archive creation" +//config: default y +//config: depends on TAR +//config: help +//config: If you enable this option you'll be able to create +//config: tar archives using the `-c' option. +//config: +//config:config FEATURE_TAR_AUTODETECT +//config: bool "Autodetect compressed tarballs" +//config: default y +//config: depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ) +//config: help +//config: With this option tar can automatically detect compressed +//config: tarballs. Currently it works only on files (not pipes etc). +//config: +//config:config FEATURE_TAR_FROM +//config: bool "Enable -X (exclude from) and -T (include from) options)" +//config: default y +//config: depends on TAR +//config: help +//config: If you enable this option you'll be able to specify +//config: a list of files to include or exclude from an archive. +//config: +//config:config FEATURE_TAR_OLDGNU_COMPATIBILITY +//config: bool "Support for old tar header format" +//config: default y +//config: depends on TAR || DPKG +//config: help +//config: This option is required to unpack archives created in +//config: the old GNU format; help to kill this old format by +//config: repacking your ancient archives with the new format. +//config: +//config:config FEATURE_TAR_OLDSUN_COMPATIBILITY +//config: bool "Enable untarring of tarballs with checksums produced by buggy Sun tar" +//config: default y +//config: depends on TAR || DPKG +//config: help +//config: This option is required to unpack archives created by some old +//config: version of Sun's tar (it was calculating checksum using signed +//config: arithmetic). It is said to be fixed in newer Sun tar, but "old" +//config: tarballs still exist. +//config: +//config:config FEATURE_TAR_GNU_EXTENSIONS +//config: bool "Support for GNU tar extensions (long filenames)" +//config: default y +//config: depends on TAR || DPKG +//config: help +//config: With this option busybox supports GNU long filenames and +//config: linknames. +//config: +//config:config FEATURE_TAR_LONG_OPTIONS +//config: bool "Enable long options" +//config: default y +//config: depends on TAR && LONG_OPTS +//config: help +//config: Enable use of long options, increases size by about 400 Bytes +//config: +//config:config FEATURE_TAR_TO_COMMAND +//config: bool "Support for writing to an external program" +//config: default y +//config: depends on TAR && FEATURE_TAR_LONG_OPTIONS +//config: help +//config: If you enable this option you'll be able to instruct tar to send +//config: the contents of each extracted file to the standard input of an +//config: external program. +//config: +//config:config FEATURE_TAR_UNAME_GNAME +//config: bool "Enable use of user and group names" +//config: default y +//config: depends on TAR +//config: help +//config: Enables use of user and group names in tar. This affects contents +//config: listings (-t) and preserving permissions when unpacking (-p). +//config: +200 bytes. +//config: +//config:config FEATURE_TAR_NOPRESERVE_TIME +//config: bool "Enable -m (do not preserve time) option" +//config: default y +//config: depends on TAR +//config: help +//config: With this option busybox supports GNU tar -m +//config: (do not preserve time) option. +//config: +//config:config FEATURE_TAR_SELINUX +//config: bool "Support for extracting SELinux labels" +//config: default n +//config: depends on TAR && SELINUX +//config: help +//config: With this option busybox supports restoring SELinux labels +//config: when extracting files from tar archives. + //applet:IF_TAR(APPLET(tar, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_TAR) += tar.o diff --git a/archival/unzip.c b/archival/unzip.c index 9825986bf..fcfc9a448 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -17,6 +17,16 @@ * Zip64 + other methods */ +//config:config UNZIP +//config: bool "unzip" +//config: default y +//config: help +//config: unzip will list or extract files from a ZIP archive, +//config: commonly found on DOS/WIN systems. The default behavior +//config: (with no options) is to extract the archive into the +//config: current directory. Use the `-d' option to extract to a +//config: directory of your choice. + //applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_UNZIP) += unzip.o -- cgit v1.2.3-55-g6feb From 9c1c605b1a8f34aef347bd9c2e4aea251e556d1b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Nov 2013 13:09:06 +0100 Subject: sulogin: use common password-checking routine. This needed some extensions correct_passwd() function, which got renamed ask_and_check_password() to better describe what it does. function old new delta ask_and_check_password_extended - 215 +215 ask_and_check_password - 12 +12 vlock_main 394 397 +3 sulogin_main 494 326 -168 correct_password 207 - -207 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 1/1 up/down: 230/-375) Total: -145 bytes Signed-off-by: Denys Vlasenko --- include/libbb.h | 3 ++- libbb/correct_password.c | 21 +++++++++++++++------ loginutils/login.c | 2 +- loginutils/su.c | 2 +- loginutils/sulogin.c | 43 ++++++------------------------------------- loginutils/vlock.c | 2 +- 6 files changed, 26 insertions(+), 47 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 58271655d..e99bb928f 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1301,7 +1301,8 @@ int sd_listen_fds(void); #define SETUP_ENV_TO_TMP (1 << 2) #define SETUP_ENV_NO_CHDIR (1 << 4) extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; -extern int correct_password(const struct passwd *pw) FAST_FUNC; +extern int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; +extern int ask_and_check_password(const struct passwd *pw) FAST_FUNC; /* Returns a malloced string */ #if !ENABLE_USE_BB_CRYPT #define pw_encrypt(clear, salt, cleanup) pw_encrypt(clear, salt) diff --git a/libbb/correct_password.c b/libbb/correct_password.c index 7cabd33d0..d02d0d6a0 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c @@ -31,12 +31,15 @@ #include "libbb.h" /* Ask the user for a password. + * Return 1 without asking if PW has an empty password. + * Return -1 on EOF, error while reading input, or timeout. * Return 1 if the user gives the correct password for entry PW, - * 0 if not. Return 1 without asking if PW has an empty password. + * 0 if not. * - * NULL pw means "just fake it for login with bad username" */ - -int FAST_FUNC correct_password(const struct passwd *pw) + * NULL pw means "just fake it for login with bad username" + */ +int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw, + int timeout, const char *prompt) { char *unencrypted, *encrypted; const char *correct; @@ -65,9 +68,10 @@ int FAST_FUNC correct_password(const struct passwd *pw) return 1; fake_it: - unencrypted = bb_ask_stdin("Password: "); + unencrypted = bb_ask(STDIN_FILENO, timeout, prompt); if (!unencrypted) { - return 0; + /* EOF (such as ^D) or error (such as ^C) */ + return -1; } encrypted = pw_encrypt(unencrypted, correct, 1); r = (strcmp(encrypted, correct) == 0); @@ -75,3 +79,8 @@ int FAST_FUNC correct_password(const struct passwd *pw) memset(unencrypted, 0, strlen(unencrypted)); return r; } + +int FAST_FUNC ask_and_check_password(const struct passwd *pw) +{ + return ask_and_check_password_extended(pw, 0, "Password: "); +} diff --git a/loginutils/login.c b/loginutils/login.c index 6ec8dc42e..a4b19ccfc 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -420,7 +420,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) * Note that reads (in no-echo mode) trash tty attributes. * If we get interrupted by SIGALRM, we need to restore attrs. */ - if (correct_password(pw)) + if (ask_and_check_password(pw) > 0) break; #endif /* ENABLE_PAM */ auth_failed: diff --git a/loginutils/su.c b/loginutils/su.c index 2ec05e125..c51f26f70 100644 --- a/loginutils/su.c +++ b/loginutils/su.c @@ -93,7 +93,7 @@ int su_main(int argc UNUSED_PARAM, char **argv) pw = xgetpwnam(opt_username); - if (cur_uid == 0 || correct_password(pw)) { + if (cur_uid == 0 || ask_and_check_password(pw) > 0) { if (ENABLE_FEATURE_SU_SYSLOG) syslog(LOG_NOTICE, "%c %s %s:%s", '+', tty, old_user, opt_username); diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 65e638489..2a2909937 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -14,24 +14,12 @@ #include "libbb.h" #include -//static void catchalarm(int UNUSED_PARAM junk) -//{ -// exit(EXIT_FAILURE); -//} - - int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int sulogin_main(int argc UNUSED_PARAM, char **argv) { - char *cp; int timeout = 0; struct passwd *pwd; const char *shell; -#if ENABLE_FEATURE_SHADOWPASSWDS - /* Using _r function to avoid pulling in static buffers */ - char buffer[256]; - struct spwd spw; -#endif logmode = LOGMODE_BOTH; openlog(applet_name, 0, LOG_AUTH); @@ -62,43 +50,24 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) goto auth_error; } -#if ENABLE_FEATURE_SHADOWPASSWDS - { - /* getspnam_r may return 0 yet set result to NULL. - * At least glibc 2.4 does this. Be extra paranoid here. */ - struct spwd *result = NULL; - int r = getspnam_r(pwd->pw_name, &spw, buffer, sizeof(buffer), &result); - if (r || !result) { - goto auth_error; - } - pwd->pw_passwd = result->sp_pwdp; - } -#endif - while (1) { - char *encrypted; int r; - /* cp points to a static buffer */ - cp = bb_ask(STDIN_FILENO, timeout, - "Give root password for system maintenance\n" - "(or type Control-D for normal startup):"); - if (!cp) { + r = ask_and_check_password_extended(pwd, timeout, + "Give root password for system maintenance\n" + "(or type Control-D for normal startup):" + ); + if (r < 0) { /* ^D, ^C, timeout, or read error */ bb_info_msg("Normal startup"); return 0; } - encrypted = pw_encrypt(cp, pwd->pw_passwd, 1); - r = strcmp(encrypted, pwd->pw_passwd); - free(encrypted); - if (r == 0) { + if (r > 0) { break; } bb_do_delay(LOGIN_FAIL_DELAY); bb_info_msg("Login incorrect"); } - memset(cp, 0, strlen(cp)); -// signal(SIGALRM, SIG_DFL); bb_info_msg("System Maintenance Mode"); diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 75af9390e..44b14e6bc 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c @@ -104,7 +104,7 @@ int vlock_main(int argc UNUSED_PARAM, char **argv) /* "s" if -a, else "": */ "s" + !option_mask32, pw->pw_name ); - if (correct_password(pw)) { + if (ask_and_check_password(pw) > 0) { break; } bb_do_delay(LOGIN_FAIL_DELAY); -- cgit v1.2.3-55-g6feb From 6ef77291122d231754e7292630681dc67c109d60 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Nov 2013 13:16:44 +0100 Subject: comment tweak Signed-off-by: Denys Vlasenko --- libbb/correct_password.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbb/correct_password.c b/libbb/correct_password.c index d02d0d6a0..d39a5839c 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c @@ -70,7 +70,7 @@ int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw, fake_it: unencrypted = bb_ask(STDIN_FILENO, timeout, prompt); if (!unencrypted) { - /* EOF (such as ^D) or error (such as ^C) */ + /* EOF (such as ^D) or error (such as ^C) or timeout */ return -1; } encrypted = pw_encrypt(unencrypted, correct, 1); -- cgit v1.2.3-55-g6feb From 8b59b2c13ededb2c82e36193b6d6e969df36531c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Nov 2013 13:36:45 +0100 Subject: libbb: move nuke_str() from passwd into libbb function old new delta nuke_str - 15 +15 ask_and_check_password_extended 215 206 -9 init_main 781 771 -10 nuke_str 27 - -27 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/2 up/down: 15/-46) Total: -31 bytes Signed-off-by: Denys Vlasenko --- include/libbb.h | 7 ++++--- init/init.c | 2 +- libbb/correct_password.c | 11 ++++++++++- loginutils/passwd.c | 5 ----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index e99bb928f..64167bba3 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1300,9 +1300,10 @@ int sd_listen_fds(void); #define SETUP_ENV_CLEARENV (1 << 1) #define SETUP_ENV_TO_TMP (1 << 2) #define SETUP_ENV_NO_CHDIR (1 << 4) -extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; -extern int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; -extern int ask_and_check_password(const struct passwd *pw) FAST_FUNC; +void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; +void nuke_str(char *str) FAST_FUNC; +int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; +int ask_and_check_password(const struct passwd *pw) FAST_FUNC; /* Returns a malloced string */ #if !ENABLE_USE_BB_CRYPT #define pw_encrypt(clear, salt, cleanup) pw_encrypt(clear, salt) diff --git a/init/init.c b/init/init.c index 2dcdfd471..c63bba1ff 100644 --- a/init/init.c +++ b/init/init.c @@ -1128,7 +1128,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) strncpy(argv[0], "init", strlen(argv[0])); /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ while (*++argv) - memset(*argv, 0, strlen(*argv)); + nuke_str(*argv); /* Set up signal handlers */ if (!DEBUG_INIT) { diff --git a/libbb/correct_password.c b/libbb/correct_password.c index d39a5839c..5727c65fb 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c @@ -30,6 +30,15 @@ #include "libbb.h" +void FAST_FUNC nuke_str(char *str) +{ + if (str) { + while (*str) + *str++ = 0; + /* or: memset(str, 0, strlen(str)); - not as small as above */ + } +} + /* Ask the user for a password. * Return 1 without asking if PW has an empty password. * Return -1 on EOF, error while reading input, or timeout. @@ -76,7 +85,7 @@ int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw, encrypted = pw_encrypt(unencrypted, correct, 1); r = (strcmp(encrypted, correct) == 0); free(encrypted); - memset(unencrypted, 0, strlen(unencrypted)); + nuke_str(unencrypted); return r; } diff --git a/loginutils/passwd.c b/loginutils/passwd.c index a7006f054..150908932 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -17,11 +17,6 @@ #include #include /* setrlimit */ -static void nuke_str(char *str) -{ - if (str) memset(str, 0, strlen(str)); -} - static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo) { char salt[MAX_PW_SALT_LEN]; -- cgit v1.2.3-55-g6feb From ebfa9b5aa1f1f6cd4949e1be03ebf1ce074727d1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Nov 2013 14:44:04 +0100 Subject: tar: fix exitcode check for MMU-spawned unpacking helpers Testcase: tar xvzf EMPTY_FILE function old new delta open_transformer 102 106 +4 get_header_tar 1781 1785 +4 Signed-off-by: Denys Vlasenko --- archival/libarchive/get_header_tar.c | 14 +++++++------- archival/libarchive/open_transformer.c | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index bc09756ba..32f842095 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c @@ -198,13 +198,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) * the message and we don't check whether we indeed * saw zero block directly before this. */ if (i == 0) { - xfunc_error_retval = 0; - short_read: - bb_error_msg_and_die("short read"); + bb_error_msg("short read"); + /* this merely signals end of archive, not exit(1): */ + return EXIT_FAILURE; } if (i != 512) { IF_FEATURE_TAR_AUTODETECT(goto autodetect;) - goto short_read; + bb_error_msg_and_die("short read"); } #else @@ -221,10 +221,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) */ while (full_read(archive_handle->src_fd, &tar, 512) == 512) continue; - return EXIT_FAILURE; + return EXIT_FAILURE; /* "end of archive" */ } archive_handle->tar__end = 1; - return EXIT_SUCCESS; + return EXIT_SUCCESS; /* "decoded one header" */ } archive_handle->tar__end = 0; @@ -471,5 +471,5 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) free(file_header->tar__uname); free(file_header->tar__gname); #endif - return EXIT_SUCCESS; + return EXIT_SUCCESS; /* "decoded one header" */ } diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c index 4e44a87e9..4e9826441 100644 --- a/archival/libarchive/open_transformer.c +++ b/archival/libarchive/open_transformer.c @@ -79,16 +79,17 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog) // FIXME: error check? #if BB_MMU { + IF_DESKTOP(long long) int r; transformer_aux_data_t aux; init_transformer_aux_data(&aux); aux.check_signature = check_signature; - transformer(&aux, fd, fd_pipe.wr); + r = transformer(&aux, fd, fd_pipe.wr); if (ENABLE_FEATURE_CLEAN_UP) { close(fd_pipe.wr); /* send EOF */ close(fd); } /* must be _exit! bug was actually seen here */ - _exit(EXIT_SUCCESS); + _exit(/*error if:*/ r < 0); } #else { -- cgit v1.2.3-55-g6feb From 1cbc642bed8307a78ccec655d2db61a2ce21596c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Nov 2013 14:52:02 +0100 Subject: tar: add a testcase for previous commit Signed-off-by: Denys Vlasenko --- testsuite/tar.tests | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/testsuite/tar.tests b/testsuite/tar.tests index 7927020c1..1bdd5d437 100755 --- a/testsuite/tar.tests +++ b/testsuite/tar.tests @@ -15,6 +15,18 @@ mkdir tar.tempdir && cd tar.tempdir || exit 1 # testing "test name" "script" "expected result" "file input" "stdin" +# Empty file is not a valid .tar.gz: +optional FEATURE_SEAMLESS_GZ +testing "tar hardlinks and repeated files" '\ +tar xvzf - 2>&1; echo $? +' "\ +tar: invalid magic +tar: short read +1 +" \ +"" "" +SKIP= + optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES testing "tar hardlinks and repeated files" '\ rm -rf input_* test.tar 2>/dev/null -- cgit v1.2.3-55-g6feb From dd1d8ab506420014cf0a3a076b2e3a4fa5de16ee Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Nov 2013 16:56:26 +0100 Subject: fix a copy/paste error in last tar testcase name Signed-off-by: Denys Vlasenko --- testsuite/tar.tests | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testsuite/tar.tests b/testsuite/tar.tests index 1bdd5d437..c947d3382 100755 --- a/testsuite/tar.tests +++ b/testsuite/tar.tests @@ -15,9 +15,8 @@ mkdir tar.tempdir && cd tar.tempdir || exit 1 # testing "test name" "script" "expected result" "file input" "stdin" -# Empty file is not a valid .tar.gz: optional FEATURE_SEAMLESS_GZ -testing "tar hardlinks and repeated files" '\ +testing "Empty file is not a tarball.tar.gz" '\ tar xvzf - 2>&1; echo $? ' "\ tar: invalid magic -- cgit v1.2.3-55-g6feb From 0545e3b69ab57af1c21d199611c56b7f7593c8c5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Nov 2013 17:17:48 +0100 Subject: tar: prevent empty file to be treated as valid tarball function old new delta tar_main 879 895 +16 Signed-off-by: Denys Vlasenko --- archival/tar.c | 13 ++++++++++--- testsuite/tar.tests | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/archival/tar.c b/archival/tar.c index 3877ea4db..bd61abd57 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -1196,8 +1196,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv) /*tar_handle->offset = 0; - already is */ } + /* Zero processed headers (== empty file) is not a valid tarball. + * We (ab)use bb_got_signal as exitcode here, + * because check_errors_in_children() uses _it_ as error indicator. + */ + bb_got_signal = EXIT_FAILURE; + while (get_header_tar(tar_handle) == EXIT_SUCCESS) - continue; + bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */ /* Check that every file that should have been extracted was */ while (tar_handle->accept) { @@ -1213,8 +1219,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv) close(tar_handle->src_fd); if (SEAMLESS_COMPRESSION || OPT_COMPRESS) { + /* Set bb_got_signal to 1 if a child died with !0 exitcode */ check_errors_in_children(0); - return bb_got_signal; } - return EXIT_SUCCESS; + + return bb_got_signal; } diff --git a/testsuite/tar.tests b/testsuite/tar.tests index c947d3382..93ba5f004 100755 --- a/testsuite/tar.tests +++ b/testsuite/tar.tests @@ -15,6 +15,15 @@ mkdir tar.tempdir && cd tar.tempdir || exit 1 # testing "test name" "script" "expected result" "file input" "stdin" +testing "Empty file is not a tarball" '\ +tar xvf - 2>&1; echo $? +' "\ +tar: short read +1 +" \ +"" "" +SKIP= + optional FEATURE_SEAMLESS_GZ testing "Empty file is not a tarball.tar.gz" '\ tar xvzf - 2>&1; echo $? @@ -26,6 +35,22 @@ tar: short read "" "" SKIP= +testing "Two zeroed blocks is a ('truncated') empty tarball" '\ +dd if=/dev/zero bs=512 count=2 2>/dev/null | strace -o /tmp/zzz -tt -s99 tar xvf - 2>&1; echo $? +' "\ +0 +" \ +"" "" +SKIP= + +testing "Twenty zeroed blocks is an empty tarball" '\ +dd if=/dev/zero bs=512 count=20 2>/dev/null | tar xvf - 2>&1; echo $? +' "\ +0 +" \ +"" "" +SKIP= + optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES testing "tar hardlinks and repeated files" '\ rm -rf input_* test.tar 2>/dev/null -- cgit v1.2.3-55-g6feb From 2635369a92db338321b2ba38e73539992967357c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 20 Nov 2013 14:20:07 +0100 Subject: rfkill: use new-style config/kbuild/applet Signed-off-by: Denys Vlasenko --- include/applets.src.h | 1 - miscutils/Config.src | 12 ------------ miscutils/Kbuild.src | 1 - miscutils/rfkill.c | 17 +++++++++++++++++ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index 2ceba53bd..7dbd4c7f3 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -288,7 +288,6 @@ IF_RENICE(APPLET(renice, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RESET(APPLET(reset, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RESIZE(APPLET(resize, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RESTORECON(APPLET_ODDNAME(restorecon, setfiles, BB_DIR_SBIN, BB_SUID_DROP, restorecon)) -IF_RFKILL(APPLET(rfkill, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm)) IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir)) IF_ROUTE(APPLET(route, BB_DIR_SBIN, BB_SUID_DROP)) diff --git a/miscutils/Config.src b/miscutils/Config.src index 117ec7739..1da9800bd 100644 --- a/miscutils/Config.src +++ b/miscutils/Config.src @@ -503,18 +503,6 @@ config READAHEAD As readahead(2) blocks until each file has been read, it is best to run this applet as a background job. -config RFKILL - bool "rfkill" - default n # doesn't build on Ubuntu 9.04 - select PLATFORM_LINUX - help - Enable/disable wireless devices. - - rfkill list : list all wireless devices - rfkill list bluetooth : list all bluetooth devices - rfkill list 1 : list device corresponding to the given index - rfkill block|unblock wlan : block/unblock all wlan(wifi) devices - config RUNLEVEL bool "runlevel" default y diff --git a/miscutils/Kbuild.src b/miscutils/Kbuild.src index f3954f407..9e164f16e 100644 --- a/miscutils/Kbuild.src +++ b/miscutils/Kbuild.src @@ -36,7 +36,6 @@ lib-$(CONFIG_MOUNTPOINT) += mountpoint.o lib-$(CONFIG_MT) += mt.o lib-$(CONFIG_RAIDAUTORUN) += raidautorun.o lib-$(CONFIG_READAHEAD) += readahead.o -lib-$(CONFIG_RFKILL) += rfkill.o lib-$(CONFIG_RUNLEVEL) += runlevel.o lib-$(CONFIG_RX) += rx.o lib-$(CONFIG_SETSID) += setsid.o diff --git a/miscutils/rfkill.c b/miscutils/rfkill.c index 467197371..7411b6fc3 100644 --- a/miscutils/rfkill.c +++ b/miscutils/rfkill.c @@ -7,6 +7,23 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config RFKILL +//config: bool "rfkill" +//config: default n # doesn't build on Ubuntu 9.04 +//config: select PLATFORM_LINUX +//config: help +//config: Enable/disable wireless devices. +//config: +//config: rfkill list : list all wireless devices +//config: rfkill list bluetooth : list all bluetooth devices +//config: rfkill list 1 : list device corresponding to the given index +//config: rfkill block|unblock wlan : block/unblock all wlan(wifi) devices +//config: + +//applet:IF_RFKILL(APPLET(rfkill, BB_DIR_USR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_RFKILL) += rfkill.o + //usage:#define rfkill_trivial_usage //usage: "COMMAND [INDEX|TYPE]" //usage:#define rfkill_full_usage "\n\n" -- cgit v1.2.3-55-g6feb From bd0e221620eb725043b4e748248046ece996a393 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 21 Nov 2013 15:09:55 +0100 Subject: awk: fix a bug in argc counting in recent change Signed-off-by: Denys Vlasenko --- editors/awk.c | 16 ++++++++-------- testsuite/awk.tests | 14 +++++++++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/editors/awk.c b/editors/awk.c index 29fb2e782..d0e3781e7 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -3204,15 +3204,17 @@ int awk_main(int argc, char **argv) opt = getopt32(argv, OPTSTR_AWK, &opt_F, &list_v, &list_f, IF_FEATURE_AWK_GNU_EXTENSIONS(&list_e,) NULL); argv += optind; argc -= optind; - if (opt & OPT_F) { /* -F */ + if (opt & OPT_W) + bb_error_msg("warning: option -W is ignored"); + if (opt & OPT_F) { unescape_string_in_place(opt_F); setvar_s(intvar[FS], opt_F); } - while (list_v) { /* -v */ + while (list_v) { if (!is_assignment(llist_pop(&list_v))) bb_show_usage(); } - while (list_f) { /* -f */ + while (list_f) { char *s = NULL; FILE *from_file; @@ -3230,7 +3232,7 @@ int awk_main(int argc, char **argv) } g_progname = "cmd. line"; #if ENABLE_FEATURE_AWK_GNU_EXTENSIONS - while (list_e) { /* -e */ + while (list_e) { parse_program(llist_pop(&list_e)); } #endif @@ -3238,13 +3240,11 @@ int awk_main(int argc, char **argv) if (!*argv) bb_show_usage(); parse_program(*argv++); - argc++; + argc--; } - if (opt & OPT_W) // -W - bb_error_msg("warning: option -W is ignored"); /* fill in ARGV array */ - setvar_i(intvar[ARGC], argc); + setvar_i(intvar[ARGC], argc + 1); setari_u(intvar[ARGV], 0, "awk"); i = 0; while (*argv) diff --git a/testsuite/awk.tests b/testsuite/awk.tests index a02302405..50b2a8328 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -275,10 +275,22 @@ testing "awk large integer" \ "" "" testing "awk length(array)" \ - "awk 'BEGIN{ A[1]=2; A["qwe"]="asd"; print length(A)}'" \ + "awk 'BEGIN{ A[1]=2; A[\"qwe\"]=\"asd\"; print length(A)}'" \ "2\n" \ "" "" +testing "awk -f and ARGC" \ + "awk -f - input" \ + "re\n2\n" \ + "do re mi\n" \ + '{print $2; print ARGC;}' \ + +testing "awk -e and ARGC" \ + "awk -e '{print \$2; print ARGC;}' input" \ + "re\n2\n" \ + "do re mi\n" \ + "" \ + # testing "description" "command" "result" "infile" "stdin" exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From 71f6c1aa433fb2be5c3e583ca350c1f9931817a5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 26 Nov 2013 11:44:27 +0100 Subject: logread: flush output. closes 6710 Signed-off-by: Denys Vlasenko --- sysklogd/logread.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sysklogd/logread.c b/sysklogd/logread.c index 2b6415f47..53d771d28 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c @@ -182,6 +182,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv) } free(copy); #endif + fflush_all(); } while (follow); shmdt(shbuf); -- cgit v1.2.3-55-g6feb From 26ad256bd0badc17d70f347c27cf5ed0699eccc5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 26 Nov 2013 12:02:18 +0100 Subject: logread: don't call shmdt() before exit, kernel does it for us. function old new delta logread_main 472 466 -6 interrupted 20 9 -11 error_exit 20 - -20 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-37) Total: -37 bytes Signed-off-by: Denys Vlasenko --- sysklogd/logread.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sysklogd/logread.c b/sysklogd/logread.c index 53d771d28..92a562919 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c @@ -49,6 +49,7 @@ struct globals { memcpy(SMrup, init_sem, sizeof(init_sem)); \ } while (0) +#if 0 static void error_exit(const char *str) NORETURN; static void error_exit(const char *str) { @@ -56,6 +57,10 @@ static void error_exit(const char *str) shmdt(shbuf); bb_perror_msg_and_die(str); } +#else +/* On Linux, shmdt is not mandatory on exit */ +# define error_exit(str) bb_perror_msg_and_die(str) +#endif /* * sem_up - up()'s a semaphore. @@ -68,7 +73,7 @@ static void sem_up(int semid) static void interrupted(int sig) { - shmdt(shbuf); + /* shmdt(shbuf); - on Linux, shmdt is not mandatory on exit */ kill_myself_with_sig(sig); } @@ -84,12 +89,12 @@ int logread_main(int argc UNUSED_PARAM, char **argv) log_shmid = shmget(KEY_ID, 0, 0); if (log_shmid == -1) - bb_perror_msg_and_die("can't find syslogd buffer"); + bb_perror_msg_and_die("can't %s syslogd buffer", "find"); /* Attach shared memory to our char* */ shbuf = shmat(log_shmid, NULL, SHM_RDONLY); if (shbuf == NULL) - bb_perror_msg_and_die("can't access syslogd buffer"); + bb_perror_msg_and_die("can't %s syslogd buffer", "access"); log_semid = semget(KEY_ID, 0, 0); if (log_semid == -1) @@ -185,7 +190,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv) fflush_all(); } while (follow); - shmdt(shbuf); + /* shmdt(shbuf); - on Linux, shmdt is not mandatory on exit */ fflush_stdout_and_exit(EXIT_SUCCESS); } -- cgit v1.2.3-55-g6feb From 924a179cb7fb910a9e4a13d9ef124d224b6c152b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 26 Nov 2013 12:03:24 +0100 Subject: build system: do not generate MAX_APPLET_NAME_LEN (unused) Signed-off-by: Denys Vlasenko --- applets/applet_tables.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/applets/applet_tables.c b/applets/applet_tables.c index 152d5f441..94b974e09 100644 --- a/applets/applet_tables.c +++ b/applets/applet_tables.c @@ -53,7 +53,7 @@ int main(int argc, char **argv) { int i; int ofs; - unsigned MAX_APPLET_NAME_LEN = 1; +// unsigned MAX_APPLET_NAME_LEN = 1; qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name); @@ -89,8 +89,8 @@ int main(int argc, char **argv) printf("const char applet_names[] ALIGN1 = \"\"\n"); for (i = 0; i < NUM_APPLETS; i++) { printf("\"%s\" \"\\0\"\n", applets[i].name); - if (MAX_APPLET_NAME_LEN < strlen(applets[i].name)) - MAX_APPLET_NAME_LEN = strlen(applets[i].name); +// if (MAX_APPLET_NAME_LEN < strlen(applets[i].name)) +// MAX_APPLET_NAME_LEN = strlen(applets[i].name); } printf(";\n\n"); @@ -130,8 +130,8 @@ int main(int argc, char **argv) printf("};\n"); #endif //printf("#endif /* SKIP_definitions */\n"); - printf("\n"); - printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN); +// printf("\n"); +// printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN); if (argv[2]) { char line_old[80]; -- cgit v1.2.3-55-g6feb From 4d8ad381abe9a37a8e2abc4d27afb0dea78b4f76 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 26 Nov 2013 12:12:27 +0100 Subject: devfsd: remove static variable function old new delta static.msg 4 - -4 get_uid_gid 114 107 -7 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-11) Total: -11 bytes Signed-off-by: Denys Vlasenko --- miscutils/devfsd.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 24c953bac..96ffe0738 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -1083,21 +1083,23 @@ static int get_uid_gid(int flag, const char *string) { struct passwd *pw_ent; struct group *grp_ent; - static const char *msg; + const char *msg; - if (ENABLE_DEVFSD_VERBOSE) - msg = "user"; - - if (isdigit(string[0]) ||((string[0] == '-') && isdigit(string[1]))) + if (isdigit(string[0]) || ((string[0] == '-') && isdigit(string[1]))) return atoi(string); if (flag == UID && (pw_ent = getpwnam(string)) != NULL) return pw_ent->pw_uid; - if (flag == GID && (grp_ent = getgrnam(string)) != NULL) - return grp_ent->gr_gid; - else if (ENABLE_DEVFSD_VERBOSE) - msg = "group"; + if (ENABLE_DEVFSD_VERBOSE) + msg = "user"; + + if (flag == GID) { + if ((grp_ent = getgrnam(string)) != NULL) + return grp_ent->gr_gid; + if (ENABLE_DEVFSD_VERBOSE) + msg = "group"; + } if (ENABLE_DEVFSD_VERBOSE) msg_logger(LOG_ERR, "unknown %s: %s, defaulting to %cid=0", msg, string, msg[0]); -- cgit v1.2.3-55-g6feb From cffe28ef876a6fe8a8154321bf5feb409d87cf1a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 26 Nov 2013 13:46:18 +0100 Subject: libbb: add sketch of tentative 'better' passwd/group API Signed-off-by: Denys Vlasenko --- libbb/bb_pwd.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c index 4829b723a..8250cd446 100644 --- a/libbb/bb_pwd.c +++ b/libbb/bb_pwd.c @@ -110,3 +110,51 @@ unsigned long FAST_FUNC get_ug_id(const char *s, return xname2id(s); return r; } + +/* Experimental "mallocing" API. + * The goal is nice: "we want to support a case when "guests" group is very large" + * but the code is butt-ugly. + */ +#if 0 +static char *find_latest(char last, char *cp) +{ + if (!cp) + return last; + cp += strlen(cp) + 1; + if (last < cp) + last = cp; + return last; +} + +struct group* FAST_FUNC xmalloc_getgrnam(const char *name) +{ + struct { + struct group gr; + // May still be not enough! + char buf[64*1024 - sizeof(struct group) - 16]; + } *s; + struct group *grp; + int r; + char *last; + char **gr_mem; + + s = xmalloc(sizeof(*s)); + r = getgrnam_r(name, &s->gr, s->buf, sizeof(s->buf), &grp); + if (!grp) { + free(s); + return grp; + } + last = find_latest(s->buf, grp->gr_name); + last = find_latest(last, grp->gr_passwd); + gr_mem = grp->gr_mem; + while (*gr_mem) + last = find_latest(last, *gr_mem++); + gr_mem++; /* points past NULL */ + if (last < (char*)gr_mem) + last = (char*)gr_mem; +//FIXME: what if we get not only truncated, but also moved here? +// grp->gr_name pointer and friends are invalid now!!! + s = xrealloc(s, last - (char*)s); + return grp; +} +#endif -- cgit v1.2.3-55-g6feb From 760fc6debcba8cb5ca8d8e2252fac3757c453e11 Mon Sep 17 00:00:00 2001 From: Bogdan Purcareata Date: Tue, 26 Nov 2013 13:54:48 +0100 Subject: init: halt on SIGPWR too Most init processes implement a handler for SIGPWR that gracefully stops all child processes when shutting down a machine. Some other technologies rely on this signal - e.g. Busybox powered LXC containers. This patch makes busybox init halt when receiving SIGPWR. Signed-off-by: Bogdan Purcareata Signed-off-by: Denys Vlasenko --- init/init.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/init/init.c b/init/init.c index c63bba1ff..d29328c36 100644 --- a/init/init.c +++ b/init/init.c @@ -789,7 +789,7 @@ static void run_shutdown_and_kill_processes(void) * and only one will be remembered and acted upon. */ -/* The SIGUSR[12]/SIGTERM handler */ +/* The SIGPWR/SIGUSR[12]/SIGTERM handler */ static void halt_reboot_pwoff(int sig) NORETURN; static void halt_reboot_pwoff(int sig) { @@ -1103,8 +1103,8 @@ int init_main(int argc UNUSED_PARAM, char **argv) /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, * then parse_inittab() simply adds in some default - * actions(i.e., INIT_SCRIPT and a pair - * of "askfirst" shells */ + * actions (i.e., INIT_SCRIPT and a pair + * of "askfirst" shells) */ parse_inittab(); } @@ -1135,6 +1135,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) struct sigaction sa; bb_signals(0 + + (1 << SIGPWR) /* halt */ + (1 << SIGUSR1) /* halt */ + (1 << SIGTERM) /* reboot */ + (1 << SIGUSR2) /* poweroff */ -- cgit v1.2.3-55-g6feb From 195c436f84dce8525670fa6bc6db7916a4702f57 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 26 Nov 2013 14:56:29 +0100 Subject: build system: use od -b instead of od -t x1 od -t is not available in non-CONFIG_DESKTOPed busybox od Signed-off-by: Denys Vlasenko --- applets/usage_compressed | 12 ++++++------ scripts/mkconfigs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/applets/usage_compressed b/applets/usage_compressed index af66bc5dc..fb6e1c286 100755 --- a/applets/usage_compressed +++ b/applets/usage_compressed @@ -10,20 +10,20 @@ test "$SED" || SED=sed test "$DD" || DD=dd # Some people were bitten by their system lacking a (proper) od -od -v -t x1 /dev/null +od -v -b /dev/null if test $? != 0; then - echo 'od tool is not installed or cannot accept "-v -t x1" options' + echo 'od tool is not installed or cannot accept "-v -b" options' exit 1 fi exec >"$target.$$" echo '#define UNPACKED_USAGE "" \' -"$loc/usage" | od -v -t x1 \ +"$loc/usage" | od -v -b \ | $SED -e 's/^[^ ]*//' \ -e 's/ //g' \ -e '/^$/d' \ - -e 's/\(..\)/\\x\1/g' \ + -e 's/\(...\)/\\\1/g' \ -e 's/^/"/' \ -e 's/$/" \\/' echo '' @@ -39,11 +39,11 @@ echo '#define PACKED_USAGE \' ## -e '/^$/d' \ ## -e 's/\(..\)\(..\)/0x\2,0x\1,/g' ## -e 's/$/ \\/' -"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \ +"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \ | $SED -e 's/^[^ ]*//' \ -e 's/ //g' \ -e '/^$/d' \ - -e 's/\(..\)/0x\1,/g' \ + -e 's/\(...\)/0\1,/g' \ -e 's/$/ \\/' echo '' diff --git a/scripts/mkconfigs b/scripts/mkconfigs index db94fcc44..6a26fe1dd 100755 --- a/scripts/mkconfigs +++ b/scripts/mkconfigs @@ -65,11 +65,11 @@ static const char bbconfig_config_bz2[] ALIGN1 = {" grep -e '^# CONFIG_' -e '^CONFIG_' "$config" \ | bzip2 -1 | dd bs=2 skip=1 2>/dev/null \ -| od -v -t x1 \ +| od -v -b \ | sed -e 's/^[^ ]*//' \ -e 's/ //g' \ -e '/^$/d' \ - -e 's/\(..\)/0x\1,/g' + -e 's/\(...\)/0\1,/g' echo "};" echo "#endif" -- cgit v1.2.3-55-g6feb From d9fc4d8f9249dcbbccb0007a3c609ed9ddaf5d72 Mon Sep 17 00:00:00 2001 From: Daniel Borca Date: Wed, 27 Nov 2013 00:27:46 +0100 Subject: platform: strchrnul is missing if __APPLE__ Signed-off-by: Daniel Borca Signed-off-by: Denys Vlasenko --- include/platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/platform.h b/include/platform.h index 0fa9f6182..cfc802907 100644 --- a/include/platform.h +++ b/include/platform.h @@ -434,7 +434,7 @@ typedef unsigned smalluint; # undef HAVE_UNLOCKED_LINE_OPS #endif -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__APPLE__) # undef HAVE_STRCHRNUL #endif -- cgit v1.2.3-55-g6feb From 8bd810bd276d20451faafdae88df4af9c2dd96d1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 28 Nov 2013 01:50:01 +0100 Subject: hush: typo fixes in comments Signed-off-by: Denys Vlasenko --- shell/hush.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/hush.c b/shell/hush.c index 912ecf15f..927193450 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1310,7 +1310,7 @@ static void restore_G_args(save_arg_t *sv, char **argv) * backgrounds (i.e. stops) or kills all members of currently running * pipe. * - * Wait builtin in interruptible by signals for which user trap is set + * Wait builtin is interruptible by signals for which user trap is set * or by SIGINT in interactive shell. * * Trap handlers will execute even within trap handlers. (right?) @@ -1398,7 +1398,7 @@ static void restore_G_args(save_arg_t *sv, char **argv) * for them - a bit like emulating kernel pending signal mask in userspace. * We are interested in: signals which need to have special handling * as described above, and all signals which have traps set. - * Signals are rocorded in pending_set. + * Signals are recorded in pending_set. * After each pipe execution, we extract any pending signals * and act on them. * -- cgit v1.2.3-55-g6feb From 259b3c047aea430c4aaecbdb9580a07e67691e8d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 28 Nov 2013 03:14:16 +0100 Subject: sed: open input files sequentially to avoid EMFILE Currently, sed pre-opens all files, which may cause EMFILE errors on systems with low ulimit -n. Change sed to open one file at a time. function old new delta get_next_line 177 235 +58 sed_main 682 652 -30 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 58/-30) Total: 28 bytes Based on the patch by Daniel Borca Signed-off-by: Denys Vlasenko --- editors/sed.c | 60 ++++++++++++++++++++++++++++--------------------- libbb/fclose_nonstdin.c | 3 ++- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 777f38308..87fa00291 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -23,7 +23,7 @@ * resulting sed_cmd_t structures are appended to a linked list * (G.sed_cmd_head/G.sed_cmd_tail). * - * add_input_file() adds a FILE* to the list of input files. We need to + * add_input_file() adds a char* to the list of input files. We need to * know all input sources ahead of time to find the last line for the $ match. * * process_files() does actual sedding, reading data lines from each input FILE* @@ -135,12 +135,15 @@ static const char semicolon_whitespace[] ALIGN1 = "; \n\r\t\v"; struct globals { /* options */ int be_quiet, regex_type; + FILE *nonstdout; char *outname, *hold_space; + smallint exitcode; - /* List of input files */ + /* list of input files */ int input_file_count, current_input_file; - FILE **input_file_list; + const char **input_file_list; + FILE *current_fp; regmatch_t regmatch[10]; regex_t *previous_regex_ptr; @@ -148,7 +151,7 @@ struct globals { /* linked list of sed commands */ sed_cmd_t *sed_cmd_head, **sed_cmd_tail; - /* Linked list of append lines */ + /* linked list of append lines */ llist_t *append_head; char *add_cmd_line; @@ -200,8 +203,8 @@ static void sed_free_and_close_stuff(void) free(G.hold_space); - while (G.current_input_file < G.input_file_count) - fclose(G.input_file_list[G.current_input_file++]); + if (G.current_fp) + fclose(G.current_fp); } #else void sed_free_and_close_stuff(void); @@ -939,8 +942,20 @@ static char *get_next_line(char *gets_char, char *last_puts_char, char last_gets /* will be returned if last line in the file * doesn't end with either '\n' or '\0' */ gc = NO_EOL_CHAR; - while (G.current_input_file < G.input_file_count) { - FILE *fp = G.input_file_list[G.current_input_file]; + for (; G.input_file_list[G.current_input_file]; G.current_input_file++) { + FILE *fp = G.current_fp; + if (!fp) { + const char *path = G.input_file_list[G.current_input_file]; + fp = stdin; + if (path != bb_msg_standard_input) { + fp = fopen_or_warn(path, "r"); + if (!fp) { + G.exitcode = EXIT_FAILURE; + continue; + } + } + G.current_fp = fp; + } /* Read line up to a newline or NUL byte, inclusive, * return malloc'ed char[]. length of the chunk read * is stored in len. NULL if EOF/error */ @@ -971,8 +986,8 @@ static char *get_next_line(char *gets_char, char *last_puts_char, char last_gets * (note: *no* newline after "b bang"!) */ } /* Close this file and advance to next one */ - fclose(fp); - G.current_input_file++; + fclose_if_not_stdin(fp); + G.current_fp = NULL; } *gets_char = gc; return temp; @@ -1399,7 +1414,7 @@ static void add_cmd_block(char *cmdstr) free(sv); } -static void add_input_file(FILE *file) +static void add_input_file(const char *file) { G.input_file_list = xrealloc_vector(G.input_file_list, 2, G.input_file_count); G.input_file_list[G.input_file_count++] = file; @@ -1423,8 +1438,6 @@ int sed_main(int argc UNUSED_PARAM, char **argv) "file\0" Required_argument "f"; #endif - int status = EXIT_SUCCESS; - INIT_G(); /* destroy command strings on exit */ @@ -1491,27 +1504,21 @@ int sed_main(int argc UNUSED_PARAM, char **argv) if (argv[0] == NULL) { if (opt & OPT_in_place) bb_error_msg_and_die(bb_msg_requires_arg, "-i"); - add_input_file(stdin); + add_input_file(bb_msg_standard_input); } else { int i; for (i = 0; argv[i]; i++) { struct stat statbuf; int nonstdoutfd; - FILE *file; sed_cmd_t *sed_cmd; if (LONE_DASH(argv[i]) && !(opt & OPT_in_place)) { - add_input_file(stdin); + add_input_file(bb_msg_standard_input); process_files(); continue; } - file = fopen_or_warn(argv[i], "r"); - if (!file) { - status = EXIT_FAILURE; - continue; - } - add_input_file(file); + add_input_file(argv[i]); if (!(opt & OPT_in_place)) { continue; } @@ -1523,7 +1530,7 @@ int sed_main(int argc UNUSED_PARAM, char **argv) G.nonstdout = xfdopen_for_write(nonstdoutfd); /* Set permissions/owner of output file */ - fstat(fileno(file), &statbuf); + stat(argv[i], &statbuf); /* chmod'ing AFTER chown would preserve suid/sgid bits, * but GNU sed 4.2.1 does not preserve them either */ fchmod(nonstdoutfd, statbuf.st_mode); @@ -1549,12 +1556,13 @@ int sed_main(int argc UNUSED_PARAM, char **argv) } } /* Here, to handle "sed 'cmds' nonexistent_file" case we did: - * if (G.current_input_file >= G.input_file_count) - * return status; + * if (G.current_input_file[G.current_input_file] == NULL) + * return G.exitcode; * but it's not needed since process_files() works correctly * in this case too. */ } + process_files(); - return status; + return G.exitcode; } diff --git a/libbb/fclose_nonstdin.c b/libbb/fclose_nonstdin.c index 5ce9d5b48..1b1441347 100644 --- a/libbb/fclose_nonstdin.c +++ b/libbb/fclose_nonstdin.c @@ -18,7 +18,8 @@ int FAST_FUNC fclose_if_not_stdin(FILE *f) { /* Some more paranoid applets want ferror() check too */ int r = ferror(f); /* NB: does NOT set errno! */ - if (r) errno = EIO; /* so we'll help it */ + if (r) + errno = EIO; /* so we'll help it */ if (f != stdin) return (r | fclose(f)); /* fclose does set errno on error */ return r; -- cgit v1.2.3-55-g6feb From deb0769b26c65c8796af105c705119c938c45b12 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 28 Nov 2013 12:08:51 +0100 Subject: sed: code shrink function old new delta get_next_line 246 250 +4 sed_main 671 662 -9 add_input_file 47 - -47 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 4/-56) Total: -52 bytes Signed-off-by: Denys Vlasenko --- editors/sed.c | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 87fa00291..31fb103ec 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -23,9 +23,6 @@ * resulting sed_cmd_t structures are appended to a linked list * (G.sed_cmd_head/G.sed_cmd_tail). * - * add_input_file() adds a char* to the list of input files. We need to - * know all input sources ahead of time to find the last line for the $ match. - * * process_files() does actual sedding, reading data lines from each input FILE* * (which could be stdin) and applying the sed command list (sed_cmd_head) to * each of the resulting lines. @@ -141,8 +138,8 @@ struct globals { smallint exitcode; /* list of input files */ - int input_file_count, current_input_file; - const char **input_file_list; + int current_input_file, last_input_file; + char **input_file_list; FILE *current_fp; regmatch_t regmatch[10]; @@ -942,7 +939,7 @@ static char *get_next_line(char *gets_char, char *last_puts_char, char last_gets /* will be returned if last line in the file * doesn't end with either '\n' or '\0' */ gc = NO_EOL_CHAR; - for (; G.input_file_list[G.current_input_file]; G.current_input_file++) { + for (; G.current_input_file <= G.last_input_file; G.current_input_file++) { FILE *fp = G.current_fp; if (!fp) { const char *path = G.input_file_list[G.current_input_file]; @@ -1414,12 +1411,6 @@ static void add_cmd_block(char *cmdstr) free(sv); } -static void add_input_file(const char *file) -{ - G.input_file_list = xrealloc_vector(G.input_file_list, 2, G.input_file_count); - G.input_file_list[G.input_file_count++] = file; -} - int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int sed_main(int argc UNUSED_PARAM, char **argv) { @@ -1501,36 +1492,38 @@ int sed_main(int argc UNUSED_PARAM, char **argv) /* argv[0..(argc-1)] should be names of file to process. If no * files were specified or '-' was specified, take input from stdin. * Otherwise, we process all the files specified. */ - if (argv[0] == NULL) { + G.input_file_list = argv; + if (!argv[0]) { if (opt & OPT_in_place) bb_error_msg_and_die(bb_msg_requires_arg, "-i"); - add_input_file(bb_msg_standard_input); + argv[0] = (char*)bb_msg_standard_input; + /* G.last_input_file = 0; - already is */ } else { - int i; + goto start; - for (i = 0; argv[i]; i++) { + for (; *argv; argv++) { struct stat statbuf; int nonstdoutfd; sed_cmd_t *sed_cmd; - if (LONE_DASH(argv[i]) && !(opt & OPT_in_place)) { - add_input_file(bb_msg_standard_input); - process_files(); - continue; - } - add_input_file(argv[i]); + G.last_input_file++; + start: if (!(opt & OPT_in_place)) { + if (LONE_DASH(*argv)) { + *argv = (char*)bb_msg_standard_input; + process_files(); + } continue; } /* -i: process each FILE separately: */ - G.outname = xasprintf("%sXXXXXX", argv[i]); + G.outname = xasprintf("%sXXXXXX", *argv); nonstdoutfd = xmkstemp(G.outname); G.nonstdout = xfdopen_for_write(nonstdoutfd); /* Set permissions/owner of output file */ - stat(argv[i], &statbuf); + stat(*argv, &statbuf); /* chmod'ing AFTER chown would preserve suid/sgid bits, * but GNU sed 4.2.1 does not preserve them either */ fchmod(nonstdoutfd, statbuf.st_mode); @@ -1541,12 +1534,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv) G.nonstdout = stdout; if (opt_i) { - char *backupname = xasprintf("%s%s", argv[i], opt_i); - xrename(argv[i], backupname); + char *backupname = xasprintf("%s%s", *argv, opt_i); + xrename(*argv, backupname); free(backupname); } - /* else unlink(argv[i]); - rename below does this */ - xrename(G.outname, argv[i]); //TODO: rollback backup on error? + /* else unlink(*argv); - rename below does this */ + xrename(G.outname, *argv); //TODO: rollback backup on error? free(G.outname); G.outname = NULL; -- cgit v1.2.3-55-g6feb From df0d2cd837e564e2653ce9a8b92a32d4eaf6e9c3 Mon Sep 17 00:00:00 2001 From: Daniel Borca Date: Thu, 28 Nov 2013 12:38:25 +0100 Subject: dpkg-deb: cosmetic correction to usage text Signed-off-by: Daniel Borca Signed-off-by: Denys Vlasenko --- archival/dpkg_deb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 81b5352a2..13f9db991 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -31,7 +31,7 @@ //kbuild:lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o //usage:#define dpkg_deb_trivial_usage -//usage: "[-cefxX] FILE [argument" +//usage: "[-cefxX] FILE [argument]" //usage:#define dpkg_deb_full_usage "\n\n" //usage: "Perform actions on Debian packages (.debs)\n" //usage: "\n -c List contents of filesystem tree" -- cgit v1.2.3-55-g6feb From 72745632a13ccd12232127b31e1656f2f7ebcaff Mon Sep 17 00:00:00 2001 From: Daniel Borca Date: Thu, 28 Nov 2013 12:50:25 +0100 Subject: ping: try SOCK_DGRAM if no root privileges Signed-off-by: Daniel Borca Signed-off-by: Denys Vlasenko --- networking/ping.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/networking/ping.c b/networking/ping.c index 5e4771f5a..5d71fe8cc 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -168,9 +168,22 @@ create_icmp_socket(void) #endif sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */ if (sock < 0) { - if (errno == EPERM) - bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); - bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); + if (errno != EPERM) + bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); +#if defined(__linux__) || defined(__APPLE__) + /* We don't have root privileges. Try SOCK_DGRAM instead. + * Linux needs net.ipv4.ping_group_range for this to work. + * MacOSX allows ICMP_ECHO, ICMP_TSTAMP or ICMP_MASKREQ + */ +#if ENABLE_PING6 + if (lsa->u.sa.sa_family == AF_INET6) + sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6); + else +#endif + sock = socket(AF_INET, SOCK_DGRAM, 1); /* 1 == ICMP */ + if (sock < 0) +#endif + bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); } xmove_fd(sock, pingsock); -- cgit v1.2.3-55-g6feb From 1a7256ac38284caffd2a0de2250364369059be69 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 29 Nov 2013 16:39:28 +0100 Subject: chpst: fix a bug where -U USER was using wrong USER (one from -u USER) Signed-off-by: Denys Vlasenko --- libbb/inet_common.c | 3 +-- runit/chpst.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libbb/inet_common.c b/libbb/inet_common.c index 0f4fca1a2..b3e0802ee 100644 --- a/libbb/inet_common.c +++ b/libbb/inet_common.c @@ -175,8 +175,7 @@ int FAST_FUNC INET6_resolve(const char *name, struct sockaddr_in6 *sin6) return -1; } memcpy(sin6, ai->ai_addr, sizeof(*sin6)); - if (ai) - freeaddrinfo(ai); + freeaddrinfo(ai); return 0; } diff --git a/runit/chpst.c b/runit/chpst.c index ed72c8b8c..71af29f66 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -236,7 +236,6 @@ int chpst_main(int argc UNUSED_PARAM, char **argv) { struct bb_uidgid_t ugid; char *set_user = set_user; /* for compiler */ - char *env_user = env_user; char *env_dir = env_dir; char *root; char *nicestr; @@ -264,7 +263,7 @@ int chpst_main(int argc UNUSED_PARAM, char **argv) IF_CHPST("/:n:vP012"), &limita, &limitc, &limitd, &limitf, &limitl, &limitm, &limito, &limitp, &limitr, &limits, &limitt, - &set_user, &env_user, &env_dir + &set_user, &set_user, &env_dir IF_CHPST(, &root, &nicestr)); argv += optind; if (opt & OPT_m) { // -m means -asld @@ -292,7 +291,7 @@ int chpst_main(int argc UNUSED_PARAM, char **argv) // envuidgid? if (ENABLE_ENVUIDGID && applet_name[0] == 'e' && applet_name[3] == 'u') { - env_user = *argv++; + set_user = *argv++; opt |= OPT_U; } -- cgit v1.2.3-55-g6feb From 9b2a9f0210f13f1c59c0b954c4aa0eeb0a66efd1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 29 Nov 2013 16:43:33 +0100 Subject: fix assorted unused code and wrong format specs found by cppchekc (bug 6716) Signed-off-by: Denys Vlasenko --- archival/libarchive/bz/compress.c | 4 +--- archival/libarchive/decompress_bunzip2.c | 1 - archival/libarchive/decompress_gunzip.c | 2 +- archival/libarchive/lzo1x_9x.c | 1 - e2fsprogs/old_e2fsprogs/blkid/blkidP.h | 4 ---- e2fsprogs/old_e2fsprogs/blkid/cache.c | 2 +- e2fsprogs/old_e2fsprogs/blkid/dev.c | 4 ++-- e2fsprogs/old_e2fsprogs/blkid/read.c | 2 +- e2fsprogs/old_e2fsprogs/blkid/tag.c | 6 +++--- e2fsprogs/old_e2fsprogs/e2fsck.c | 10 +++------- e2fsprogs/old_e2fsprogs/ext2fs/initialize.c | 2 +- e2fsprogs/old_e2fsprogs/ext2fs/unix_io.c | 4 ++-- e2fsprogs/old_e2fsprogs/fsck.c | 1 - e2fsprogs/old_e2fsprogs/mke2fs.c | 6 ++---- e2fsprogs/old_e2fsprogs/util.c | 2 +- libbb/pw_encrypt_md5.c | 2 +- miscutils/chat.c | 2 +- networking/tc.c | 3 --- networking/traceroute.c | 4 ++++ util-linux/volume_id/unused_msdos.c | 2 +- 20 files changed, 25 insertions(+), 39 deletions(-) diff --git a/archival/libarchive/bz/compress.c b/archival/libarchive/bz/compress.c index a7dd72d9e..23de9d3f5 100644 --- a/archival/libarchive/bz/compress.c +++ b/archival/libarchive/bz/compress.c @@ -249,7 +249,7 @@ void generateMTFValues(EState* s) static NOINLINE void sendMTFValues(EState* s) { - int32_t v, t, i, j, gs, ge, totc, bt, bc, iter; + int32_t v, t, i, j, gs, ge, bt, bc, iter; int32_t nSelectors, alphaSize, minLen, maxLen, selCtr; int32_t nGroups; @@ -345,7 +345,6 @@ void sendMTFValues(EState* s) } #endif nSelectors = 0; - totc = 0; gs = 0; while (1) { /*--- Set group start & end marks. --*/ @@ -411,7 +410,6 @@ void sendMTFValues(EState* s) bt = t; } } - totc += bc; fave[bt]++; s->selector[nSelectors] = bt; nSelectors++; diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c index fb1f2921f..6396fe40d 100644 --- a/archival/libarchive/decompress_bunzip2.c +++ b/archival/libarchive/decompress_bunzip2.c @@ -818,7 +818,6 @@ static char *const bunzip_errors[] = { /* Dumb little test thing, decompress stdin to stdout */ int main(int argc, char **argv) { - int i; char c; int i = unpack_bz2_stream(0, 1); diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index 4e6b138c3..7c6f38ec3 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c @@ -336,7 +336,7 @@ static int huft_build(const unsigned *b, const unsigned n, } /* Find minimum and maximum length, bound *m by those */ - for (j = 1; (c[j] == 0) && (j <= BMAX); j++) + for (j = 1; (j <= BMAX) && (c[j] == 0); j++) continue; k = j; /* minimum code length */ for (i = BMAX; (c[i] == 0) && i; i--) diff --git a/archival/libarchive/lzo1x_9x.c b/archival/libarchive/lzo1x_9x.c index 3e331984d..2b490ae83 100644 --- a/archival/libarchive/lzo1x_9x.c +++ b/archival/libarchive/lzo1x_9x.c @@ -466,7 +466,6 @@ static int find_match(lzo1x_999_t *c, lzo_swd_p s, } s->m_len = 1; - s->m_len = 1; #ifdef SWD_BEST_OFF if (s->use_best_off) memset(s->best_pos, 0, sizeof(s->best_pos)); diff --git a/e2fsprogs/old_e2fsprogs/blkid/blkidP.h b/e2fsprogs/old_e2fsprogs/blkid/blkidP.h index d6b2b42cc..bbadc8eb5 100644 --- a/e2fsprogs/old_e2fsprogs/blkid/blkidP.h +++ b/e2fsprogs/old_e2fsprogs/blkid/blkidP.h @@ -179,8 +179,4 @@ extern int blkid_set_tag(blkid_dev dev, const char *name, extern blkid_dev blkid_new_dev(void); extern void blkid_free_dev(blkid_dev dev); -#ifdef __cplusplus -} -#endif - #endif diff --git a/e2fsprogs/old_e2fsprogs/blkid/cache.c b/e2fsprogs/old_e2fsprogs/blkid/cache.c index d1d29146b..251e49900 100644 --- a/e2fsprogs/old_e2fsprogs/blkid/cache.c +++ b/e2fsprogs/old_e2fsprogs/blkid/cache.c @@ -115,7 +115,7 @@ int main(int argc, char** argv) argv[0], ret); exit(1); } - if ((ret = blkid_probe_all(cache) < 0)) + if ((ret = blkid_probe_all(cache)) < 0) fprintf(stderr, "error probing devices\n"); blkid_put_cache(cache); diff --git a/e2fsprogs/old_e2fsprogs/blkid/dev.c b/e2fsprogs/old_e2fsprogs/blkid/dev.c index bb0cc914a..260e49c65 100644 --- a/e2fsprogs/old_e2fsprogs/blkid/dev.c +++ b/e2fsprogs/old_e2fsprogs/blkid/dev.c @@ -153,7 +153,7 @@ extern int optind; void usage(char *prog) { fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask]\n", prog); - fprintf(stderr, "\tList all devices and exit\n", prog); + fprintf(stderr, "\tList all devices and exit\n"); exit(1); } @@ -176,7 +176,7 @@ int main(int argc, char **argv) case 'm': blkid_debug_mask = strtoul (optarg, &tmp, 0); if (*tmp) { - fprintf(stderr, "Invalid debug mask: %d\n", + fprintf(stderr, "Invalid debug mask: %s\n", optarg); exit(1); } diff --git a/e2fsprogs/old_e2fsprogs/blkid/read.c b/e2fsprogs/old_e2fsprogs/blkid/read.c index f795a5d14..feeda518b 100644 --- a/e2fsprogs/old_e2fsprogs/blkid/read.c +++ b/e2fsprogs/old_e2fsprogs/blkid/read.c @@ -385,7 +385,7 @@ void blkid_read_cache(blkid_cache cache) continue; end = strlen(buf) - 1; /* Continue reading next line if it ends with a backslash */ - while (buf[end] == '\\' && end < sizeof(buf) - 2 && + while (end < sizeof(buf) - 2 && buf[end] == '\\' && fgets(buf + end, sizeof(buf) - end, file)) { end = strlen(buf) - 1; lineno++; diff --git a/e2fsprogs/old_e2fsprogs/blkid/tag.c b/e2fsprogs/old_e2fsprogs/blkid/tag.c index 8337b46b6..7424edeb8 100644 --- a/e2fsprogs/old_e2fsprogs/blkid/tag.c +++ b/e2fsprogs/old_e2fsprogs/blkid/tag.c @@ -356,7 +356,7 @@ void usage(char *prog) fprintf(stderr, "Usage: %s [-f blkid_file] [-m debug_mask] device " "[type value]\n", prog); - fprintf(stderr, "\tList all tags for a device and exit\n", prog); + fprintf(stderr, "\tList all tags for a device and exit\n"); exit(1); } @@ -382,7 +382,7 @@ int main(int argc, char **argv) case 'm': blkid_debug_mask = strtoul (optarg, &tmp, 0); if (*tmp) { - fprintf(stderr, "Invalid debug mask: %d\n", + fprintf(stderr, "Invalid debug mask: %s\n", optarg); exit(1); } @@ -407,7 +407,7 @@ int main(int argc, char **argv) dev = blkid_get_dev(cache, devname, flags); if (!dev) { - fprintf(stderr, "%s: cannot find device in blkid cache\n"); + fprintf(stderr, "%s: cannot find device in blkid cache\n", devname); exit(1); } if (search_type) { diff --git a/e2fsprogs/old_e2fsprogs/e2fsck.c b/e2fsprogs/old_e2fsprogs/e2fsck.c index 373e8ce91..8400a92ce 100644 --- a/e2fsprogs/old_e2fsprogs/e2fsck.c +++ b/e2fsprogs/old_e2fsprogs/e2fsck.c @@ -1050,7 +1050,7 @@ static errcode_t ea_refcount_create(int size, ext2_refcount_t *ret) refcount->size = size; bytes = (size_t) (size * sizeof(struct ea_refcount_el)); #ifdef DEBUG - printf("Refcount allocated %d entries, %d bytes.\n", + printf("Refcount allocated %d entries, %lu bytes.\n", refcount->size, bytes); #endif retval = ext2fs_get_mem(bytes, &refcount->list); @@ -3424,7 +3424,7 @@ static void e2fsck_pass1(e2fsck_t ctx) continue; } if ((inode->i_links_count || inode->i_blocks || - inode->i_blocks || inode->i_block[0]) && + inode->i_block[0]) && fix_problem(ctx, PR_1_JOURNAL_INODE_NOT_CLEAR, &pctx)) { memset(inode, 0, inode_size); @@ -12195,11 +12195,7 @@ static void swap_filesys(e2fsck_t ctx) void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size, const char *description) { - void *ret; - char buf[256]; - - ret = xzalloc(size); - return ret; + return xzalloc(size); } static char *string_copy(const char *str, int len) diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/initialize.c b/e2fsprogs/old_e2fsprogs/ext2fs/initialize.c index da2d15137..240335b32 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/initialize.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/initialize.c @@ -83,7 +83,7 @@ static int calc_reserved_gdt_blocks(ext2_filsys fs) if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb)) rsv_gdb = EXT2_ADDR_PER_BLOCK(sb); #ifdef RES_GDT_DEBUG - printf("max_blocks %lu, rsv_groups = %lu, rsv_gdb = %lu\n", + printf("max_blocks %lu, rsv_groups = %lu, rsv_gdb = %u\n", max_blocks, rsv_groups, rsv_gdb); #endif diff --git a/e2fsprogs/old_e2fsprogs/ext2fs/unix_io.c b/e2fsprogs/old_e2fsprogs/ext2fs/unix_io.c index 474f07340..3c95829f0 100644 --- a/e2fsprogs/old_e2fsprogs/ext2fs/unix_io.c +++ b/e2fsprogs/old_e2fsprogs/ext2fs/unix_io.c @@ -544,7 +544,7 @@ static errcode_t unix_read_blk(io_channel channel, unsigned long block, /* If it's in the cache, use it! */ if ((cache = find_cached_block(data, block, &reuse[0]))) { #ifdef DEBUG - printf("Using cached block %d\n", block); + printf("Using cached block %lu\n", block); #endif memcpy(cp, cache->buf, channel->block_size); count--; @@ -560,7 +560,7 @@ static errcode_t unix_read_blk(io_channel channel, unsigned long block, if (find_cached_block(data, block+i, &reuse[i])) break; #ifdef DEBUG - printf("Reading %d blocks starting at %d\n", i, block); + printf("Reading %d blocks starting at %lu\n", i, block); #endif if ((retval = raw_read_blk(channel, data, block, i, cp))) return retval; diff --git a/e2fsprogs/old_e2fsprogs/fsck.c b/e2fsprogs/old_e2fsprogs/fsck.c index 3a0743bb1..91cce970c 100644 --- a/e2fsprogs/old_e2fsprogs/fsck.c +++ b/e2fsprogs/old_e2fsprogs/fsck.c @@ -1239,7 +1239,6 @@ static void PRS(int argc, char **argv) progress_fd = 0; else { goto next_arg; - i++; } } break; diff --git a/e2fsprogs/old_e2fsprogs/mke2fs.c b/e2fsprogs/old_e2fsprogs/mke2fs.c index 35d717a55..e44d9865c 100644 --- a/e2fsprogs/old_e2fsprogs/mke2fs.c +++ b/e2fsprogs/old_e2fsprogs/mke2fs.c @@ -385,7 +385,7 @@ static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num, struct progress_struct *progress, blk_t *ret_blk, int *ret_count) { - int j, count, next_update, next_update_incr; + int j, count, next_update; static char *buf; errcode_t retval; @@ -403,9 +403,7 @@ static errcode_t zero_blocks(ext2_filsys fs, blk_t blk, int num, } /* OK, do the write loop */ next_update = 0; - next_update_incr = num / 100; - if (next_update_incr < 1) - next_update_incr = 1; + for (j=0; j < num; j += STRIDE_LENGTH, blk += STRIDE_LENGTH) { count = num - j; if (count > STRIDE_LENGTH) diff --git a/e2fsprogs/old_e2fsprogs/util.c b/e2fsprogs/old_e2fsprogs/util.c index a61abc2c6..e6758e093 100644 --- a/e2fsprogs/old_e2fsprogs/util.c +++ b/e2fsprogs/old_e2fsprogs/util.c @@ -117,7 +117,7 @@ void parse_journal_opts(char **journal_device, int *journal_flags, } if (strcmp(token, "device") == 0) { *journal_device = blkid_get_devname(NULL, arg, NULL); - if (!journal_device) { + if (!*journal_device) { journal_usage++; continue; } diff --git a/libbb/pw_encrypt_md5.c b/libbb/pw_encrypt_md5.c index 889e09cab..1e52ecaea 100644 --- a/libbb/pw_encrypt_md5.c +++ b/libbb/pw_encrypt_md5.c @@ -86,7 +86,7 @@ md5_crypt(char result[MD5_OUT_BUFSIZE], const unsigned char *pw, const unsigned /* Get the length of the salt including "$1$" */ sl = 3; - while (salt[sl] && salt[sl] != '$' && sl < (3 + 8)) + while (sl < (3 + 8) && salt[sl] && salt[sl] != '$') sl++; /* Hash. the password first, since that is what is most unknown */ diff --git a/miscutils/chat.c b/miscutils/chat.c index ce994f870..bd2abc24a 100644 --- a/miscutils/chat.c +++ b/miscutils/chat.c @@ -296,7 +296,7 @@ int chat_main(int argc UNUSED_PARAM, char **argv) full_write(record_fd, buf+buf_len, 1); } // dump device input if ECHO ON - if (echo > 0) { + if (echo) { // if (buf[buf_len] < ' ') { // full_write(STDERR_FILENO, "^", 1); // buf[buf_len] += '@'; diff --git a/networking/tc.c b/networking/tc.c index b9a4d16cc..533f7c042 100644 --- a/networking/tc.c +++ b/networking/tc.c @@ -418,9 +418,6 @@ static int print_class(const struct sockaddr_nl *who UNUSED_PARAM, static int print_filter(const struct sockaddr_nl *who UNUSED_PARAM, struct nlmsghdr *hdr, void *arg UNUSED_PARAM) { - struct tcmsg *msg = NLMSG_DATA(hdr); - int len = hdr->nlmsg_len; - struct rtattr * tb[TCA_MAX+1]; return 0; } diff --git a/networking/traceroute.c b/networking/traceroute.c index 0c18d6c0c..97a7a19e0 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -791,7 +791,9 @@ static int common_traceroute_main(int op, char **argv) { int minpacket; +#ifdef IP_TOS int tos = 0; +#endif int max_ttl = 30; int nprobes = 3; int first_ttl = 1; @@ -838,8 +840,10 @@ common_traceroute_main(int op, char **argv) if (op & OPT_IP_CHKSUM) bb_error_msg("warning: ip checksums disabled"); #endif +#ifdef IP_TOS if (op & OPT_TOS) tos = xatou_range(tos_str, 0, 255); +#endif if (op & OPT_MAX_TTL) max_ttl = xatou_range(max_ttl_str, 1, 255); if (op & OPT_PORT) diff --git a/util-linux/volume_id/unused_msdos.c b/util-linux/volume_id/unused_msdos.c index d2fc66caa..5ebaa3eef 100644 --- a/util-linux/volume_id/unused_msdos.c +++ b/util-linux/volume_id/unused_msdos.c @@ -176,7 +176,7 @@ int FAST_FUNC volume_id_probe_msdos_part_table(struct volume_id *id, uint64_t of if (id->partition_count < 4) id->partition_count = 4; - p = &id->partitions[id->partition_count]; +// p = &id->partitions[id->partition_count]; // if (is_raid(part[i].sys_ind)) // volume_id_set_usage_part(p, VOLUME_ID_RAID); -- cgit v1.2.3-55-g6feb From 327f550669a80d72f36bc9e4de619c163aa46eff Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 29 Nov 2013 16:45:45 +0100 Subject: Use unsigned printf/scanf conversion where more appropriate Signed-off-by: Denys Vlasenko --- coreutils/cal.c | 2 +- coreutils/sum.c | 4 ++-- e2fsprogs/old_e2fsprogs/mke2fs.c | 2 +- e2fsprogs/old_e2fsprogs/tune2fs.c | 2 +- e2fsprogs/old_e2fsprogs/util.c | 2 +- editors/patch_bbox.c | 4 ++-- miscutils/hdparm.c | 8 ++++---- networking/arp.c | 4 ++-- networking/netstat.c | 8 ++++---- networking/pscan.c | 2 +- procps/pgrep.c | 4 ++-- procps/top.c | 2 +- sysklogd/logread.c | 2 +- util-linux/fdformat.c | 2 +- util-linux/fsck_minix.c | 2 +- util-linux/ipcs.c | 10 +++++----- util-linux/mkfs_minix.c | 2 +- util-linux/readprofile.c | 12 ++++++------ 18 files changed, 37 insertions(+), 37 deletions(-) diff --git a/coreutils/cal.c b/coreutils/cal.c index 0d388aa1c..12c46b14f 100644 --- a/coreutils/cal.c +++ b/coreutils/cal.c @@ -165,7 +165,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv) char lineout[30]; day_array(month, year, dp); - len = sprintf(lineout, "%s %d", month_names[month - 1], year); + len = sprintf(lineout, "%s %u", month_names[month - 1], year); printf("%*s%s\n%s\n", ((7*julian + WEEK_LEN) - len) / 2, "", lineout, day_headings); diff --git a/coreutils/sum.c b/coreutils/sum.c index 75f6ef60a..deb068e10 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c @@ -70,9 +70,9 @@ static unsigned sum_file(const char *file, unsigned type) if (type >= SUM_SYSV) { r = (s & 0xffff) + ((s & 0xffffffff) >> 16); s = (r & 0xffff) + (r >> 16); - printf("%d %llu %s\n", s, (total_bytes + 511) / 512, file); + printf("%u %llu %s\n", s, (total_bytes + 511) / 512, file); } else - printf("%05d %5llu %s\n", s, (total_bytes + 1023) / 1024, file); + printf("%05u %5llu %s\n", s, (total_bytes + 1023) / 1024, file); return 1; #undef buf } diff --git a/e2fsprogs/old_e2fsprogs/mke2fs.c b/e2fsprogs/old_e2fsprogs/mke2fs.c index e44d9865c..ebcb46cf2 100644 --- a/e2fsprogs/old_e2fsprogs/mke2fs.c +++ b/e2fsprogs/old_e2fsprogs/mke2fs.c @@ -239,7 +239,7 @@ static void test_disk(ext2_filsys fs, badblocks_list *bb_list) errcode_t retval; char buf[1024]; - sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize, + sprintf(buf, "badblocks -b %u %s%s%s %d", fs->blocksize, quiet ? "" : "-s ", (cflag > 1) ? "-w " : "", fs->device_name, fs->super->s_blocks_count); mke2fs_verbose("Running command: %s\n", buf); diff --git a/e2fsprogs/old_e2fsprogs/tune2fs.c b/e2fsprogs/old_e2fsprogs/tune2fs.c index 3c3f4afa5..bbe30e5a0 100644 --- a/e2fsprogs/old_e2fsprogs/tune2fs.c +++ b/e2fsprogs/old_e2fsprogs/tune2fs.c @@ -607,7 +607,7 @@ int tune2fs_main(int argc, char **argv) if (e_flag) { sb->s_errors = errors; ext2fs_mark_super_dirty(fs); - printf("Setting error behavior to %d\n", errors); + printf("Setting error behavior to %u\n", errors); } if (g_flag) { sb->s_def_resgid = resgid; diff --git a/e2fsprogs/old_e2fsprogs/util.c b/e2fsprogs/old_e2fsprogs/util.c index e6758e093..3e7ee8e75 100644 --- a/e2fsprogs/old_e2fsprogs/util.c +++ b/e2fsprogs/old_e2fsprogs/util.c @@ -239,7 +239,7 @@ void make_journal_blocks(ext2_filsys fs, int journal_size, int journal_flags, in return; } if (!quiet) - printf("Creating journal (%ld blocks): ", journal_blocks); + printf("Creating journal (%lu blocks): ", journal_blocks); fflush(stdout); retval = ext2fs_add_journal_inode(fs, journal_blocks, journal_flags); diff --git a/editors/patch_bbox.c b/editors/patch_bbox.c index 78aa5fde8..aae7b7987 100644 --- a/editors/patch_bbox.c +++ b/editors/patch_bbox.c @@ -188,8 +188,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv) unsigned src_last_line = 1; unsigned dst_last_line = 1; - if ((sscanf(patch_line, "@@ -%d,%d +%d,%d", &src_beg_line, &src_last_line, &dst_beg_line, &dst_last_line) < 3) - && (sscanf(patch_line, "@@ -%d +%d,%d", &src_beg_line, &dst_beg_line, &dst_last_line) < 2) + if ((sscanf(patch_line, "@@ -%u,%u +%u,%u", &src_beg_line, &src_last_line, &dst_beg_line, &dst_last_line) < 3) + && (sscanf(patch_line, "@@ -%u +%u,%u", &src_beg_line, &dst_beg_line, &dst_last_line) < 2) ) { /* No more hunks for this file */ break; diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 69726ae72..f0e9c9d75 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -465,14 +465,14 @@ static void on_off(int value) static void print_flag_on_off(int get_arg, const char *s, unsigned long arg) { if (get_arg) { - printf(" setting %s to %ld", s, arg); + printf(" setting %s to %lu", s, arg); on_off(arg); } } static void print_value_on_off(const char *str, unsigned long argp) { - printf(" %s\t= %2ld", str, argp); + printf(" %s\t= %2lu", str, argp); on_off(argp != 0); } @@ -1509,7 +1509,7 @@ static void bus_state_value(unsigned value) else if (value == BUSSTATE_TRISTATE) printf(" (tristate)\n"); else - printf(" (unknown: %d)\n", value); + printf(" (unknown: %u)\n", value); } #endif @@ -1589,7 +1589,7 @@ static void interpret_xfermode(unsigned xfermode) static void print_flag(int flag, const char *s, unsigned long value) { if (flag) - printf(" setting %s to %ld\n", s, value); + printf(" setting %s to %lu\n", s, value); } static void process_dev(char *devname) diff --git a/networking/arp.c b/networking/arp.c index 40d244116..e79b1b6a1 100644 --- a/networking/arp.c +++ b/networking/arp.c @@ -459,12 +459,12 @@ static int arp_show(char *name) arp_disp(hostname, ip, type, flags, hwa, mask, dev); } if (option_mask32 & ARP_OPT_v) - printf("Entries: %d\tSkipped: %d\tFound: %d\n", + printf("Entries: %u\tSkipped: %u\tFound: %u\n", entries, entries - shown, shown); if (!shown) { if (hw_set || host || device[0]) - printf("No match found in %d entries\n", entries); + printf("No match found in %u entries\n", entries); } if (ENABLE_FEATURE_CLEAN_UP) { free((char*)host); diff --git a/networking/netstat.c b/networking/netstat.c index c0c6ba501..f80b845bc 100644 --- a/networking/netstat.c +++ b/networking/netstat.c @@ -125,10 +125,10 @@ typedef enum { */ #define ADDR_WIDE 51 /* INET6_ADDRSTRLEN + 5 for the port number */ #if ENABLE_FEATURE_NETSTAT_WIDE -# define FMT_NET_CONN_DATA "%s %6ld %6ld %-*s %-*s %-12s" +# define FMT_NET_CONN_DATA "%s %6lu %6lu %-*s %-*s %-12s" # define FMT_NET_CONN_HEADER "\nProto Recv-Q Send-Q %-*s %-*s State %s\n" #else -# define FMT_NET_CONN_DATA "%s %6ld %6ld %-23s %-23s %-12s" +# define FMT_NET_CONN_DATA "%s %6lu %6lu %-23s %-23s %-12s" # define FMT_NET_CONN_HEADER "\nProto Recv-Q Send-Q %-23s %-23s State %s\n" #endif @@ -403,7 +403,7 @@ static int scan_inet_proc_line(struct inet_params *param, char *line) "%*d: %32[0-9A-Fa-f]:%X " "%32[0-9A-Fa-f]:%X %X " "%lX:%lX %*X:%*X " - "%*X %d %*d %ld ", + "%*X %d %*d %lu ", local_addr, ¶m->local_port, rem_addr, ¶m->rem_port, ¶m->state, ¶m->txq, ¶m->rxq, @@ -611,7 +611,7 @@ static int FAST_FUNC unix_do_one(char *line) strcat(ss_flags, "N "); strcat(ss_flags, "]"); - printf("%-5s %-6ld %-11s %-10s %-13s %6lu ", + printf("%-5s %-6lu %-11s %-10s %-13s %6lu ", ss_proto, refcnt, ss_flags, ss_type, ss_state, inode ); diff --git a/networking/pscan.c b/networking/pscan.c index 28005ad57..72ed8cdb5 100644 --- a/networking/pscan.c +++ b/networking/pscan.c @@ -157,7 +157,7 @@ int pscan_main(int argc UNUSED_PARAM, char **argv) } if (ENABLE_FEATURE_CLEAN_UP) free(lsap); - printf("%d closed, %d open, %d timed out (or blocked) ports\n", + printf("%u closed, %u open, %u timed out (or blocked) ports\n", closed_ports, open_ports, nports - (closed_ports + open_ports)); diff --git a/procps/pgrep.c b/procps/pgrep.c index 8daf5b28a..1c7c7c48b 100644 --- a/procps/pgrep.c +++ b/procps/pgrep.c @@ -65,9 +65,9 @@ static void act(unsigned pid, char *cmd, int signo) { if (pgrep) { if (option_mask32 & (1 << OPTBIT_L)) /* OPT_LIST */ - printf("%d %s\n", pid, cmd); + printf("%u %s\n", pid, cmd); else - printf("%d\n", pid); + printf("%u\n", pid); } else kill(pid, signo); } diff --git a/procps/top.c b/procps/top.c index 31f2a5113..51f1c1aed 100644 --- a/procps/top.c +++ b/procps/top.c @@ -677,7 +677,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) if (s->vsz >= 100000) sprintf(vsz_str_buf, "%6ldm", s->vsz/1024); else - sprintf(vsz_str_buf, "%7ld", s->vsz); + sprintf(vsz_str_buf, "%7lu", s->vsz); /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ col = snprintf(line_buf, scr_width, "\n" "%5u%6u %-8.8s %s%s" FMT diff --git a/sysklogd/logread.c b/sysklogd/logread.c index 92a562919..bea73d932 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c @@ -126,7 +126,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv) shbuf_data = shbuf->data; /* pointer! */ if (DEBUG) - printf("cur:%d tail:%i size:%i\n", + printf("cur:%u tail:%u size:%u\n", cur, shbuf_tail, shbuf_size); if (!follow) { diff --git a/util-linux/fdformat.c b/util-linux/fdformat.c index b3e918fb0..6f49cec8f 100644 --- a/util-linux/fdformat.c +++ b/util-linux/fdformat.c @@ -72,7 +72,7 @@ int fdformat_main(int argc UNUSED_PARAM, char **argv) /* original message was: "Could not determine current format type" */ xioctl(fd, FDGETPRM, ¶m); - printf("%s-sided, %d tracks, %d sec/track. Total capacity %d kB\n", + printf("%s-sided, %u tracks, %u sec/track. Total capacity %d kB\n", (param.head == 2) ? "Double" : "Single", param.track, param.sect, param.size >> 1); diff --git a/util-linux/fsck_minix.c b/util-linux/fsck_minix.c index c1d1b2cc3..33767a1af 100644 --- a/util-linux/fsck_minix.c +++ b/util-linux/fsck_minix.c @@ -686,7 +686,7 @@ static void get_inode_common(unsigned nr, uint16_t i_mode) total++; if (!inode_count[nr]) { if (!inode_in_use(nr)) { - printf("Inode %d is marked as 'unused', but it is used " + printf("Inode %u is marked as 'unused', but it is used " "for file '%s'\n", nr, current_name); if (OPT_repair) { if (ask("Mark as 'in use'", 1)) diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c index 2668cafd4..67a25a8ef 100644 --- a/util-linux/ipcs.c +++ b/util-linux/ipcs.c @@ -166,10 +166,10 @@ static NOINLINE void do_shm(void) case STATUS: printf("------ Shared Memory %s --------\n", "Status"); printf("segments allocated %d\n" - "pages allocated %ld\n" - "pages resident %ld\n" - "pages swapped %ld\n" - "Swap performance: %ld attempts\t%ld successes\n", + "pages allocated %lu\n" + "pages resident %lu\n" + "pages swapped %lu\n" + "Swap performance: %lu attempts\t%lu successes\n", shm_info.used_ids, shm_info.shm_tot, shm_info.shm_rss, @@ -569,7 +569,7 @@ static void print_sem(int semid) if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) { bb_perror_msg_and_die("semctl"); } - printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid); + printf("%-10u %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid); } bb_putchar('\n'); } diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 49afd1176..d65a5161c 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c @@ -505,7 +505,7 @@ static void get_list_blocks(char *filename) listfile = xfopen_for_read(filename); while (!feof(listfile)) { - fscanf(listfile, "%ld\n", &blockno); + fscanf(listfile, "%lu\n", &blockno); mark_zone(blockno); G.badblocks++; } diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index 974fe89c4..a64540464 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c @@ -152,7 +152,7 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) step = buf[0]; if (optInfo) { - printf("Sampling_step: %i\n", step); + printf("Sampling_step: %u\n", step); return EXIT_SUCCESS; } @@ -219,10 +219,10 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) && (fn_len = next_add-fn_add) != 0 ) { if (optVerbose) - printf("%016llx %-40s %6i %8.4f\n", fn_add, + printf("%016llx %-40s %6u %8.4f\n", fn_add, fn_name, this, this/(double)fn_len); else - printf("%6i %-40s %8.4f\n", + printf("%6u %-40s %8.4f\n", this, fn_name, this/(double)fn_len); if (optSub) { unsigned long long scan; @@ -246,14 +246,14 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv) } /* clock ticks, out of kernel text - probably modules */ - printf("%6i %s\n", buf[len/sizeof(*buf)-1], "*unknown*"); + printf("%6u %s\n", buf[len/sizeof(*buf)-1], "*unknown*"); /* trailer */ if (optVerbose) - printf("%016x %-40s %6i %8.4f\n", + printf("%016x %-40s %6u %8.4f\n", 0, "total", total, total/(double)(fn_add-add0)); else - printf("%6i %-40s %8.4f\n", + printf("%6u %-40s %8.4f\n", total, "total", total/(double)(fn_add-add0)); fclose(map); -- cgit v1.2.3-55-g6feb From cb1dc1d1d1c0132636454ecfdb6cac3eade323e6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 4 Dec 2013 13:19:04 +0100 Subject: ntpd: let user know if spike was detected function old new delta update_local_clock 861 943 +82 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 99817e83b..13cca3e77 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1347,10 +1347,12 @@ update_local_clock(peer_t *p) * offset exceeds the step threshold and when it does not. */ if (abs_offset > STEP_THRESHOLD) { + double remains; + switch (G.discipline_state) { case STATE_SYNC: /* The first outlyer: ignore it, switch to SPIK state */ - VERB3 bb_error_msg("offset:%+f - spike detected", offset); + VERB2 bb_error_msg("offset:%+f - spike", offset); G.discipline_state = STATE_SPIK; return -1; /* "decrease poll interval" */ @@ -1358,9 +1360,10 @@ update_local_clock(peer_t *p) /* Ignore succeeding outlyers until either an inlyer * is found or the stepout threshold is exceeded. */ - if (since_last_update < WATCH_THRESHOLD) { - VERB3 bb_error_msg("spike detected, datapoint ignored, %f sec remains", - WATCH_THRESHOLD - since_last_update); + remains = WATCH_THRESHOLD - since_last_update; + if (remains > 0) { + VERB2 bb_error_msg("spike, datapoint ignored, %f sec remains", + remains); return -1; /* "decrease poll interval" */ } /* fall through: we need to step */ -- cgit v1.2.3-55-g6feb From a14958c69da798e2284e8ab29492bdbdd52a2278 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 4 Dec 2013 16:32:09 +0100 Subject: ntpd: promote log level 3 to production Without it, peer selection logic is hard to debug function old new delta update_local_clock 861 982 +121 select_and_cluster 962 1065 +103 common_ping_main 1788 1821 +33 huft_build 1287 1296 +9 chpst_main 708 704 -4 INET6_resolve 127 119 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/2 up/down: 266/-12) Total: 254 bytes Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 99 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 13cca3e77..aeef0431a 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -57,10 +57,10 @@ /* Verbosity control (max level of -dddd options accepted). - * max 5 is very talkative (and bloated). 2 is non-bloated, + * max 6 is very talkative (and bloated). 3 is non-bloated, * production level setting. */ -#define MAX_VERBOSE 2 +#define MAX_VERBOSE 3 /* High-level description of the algorithm: @@ -367,6 +367,7 @@ static const int const_IPTOS_LOWDELAY = IPTOS_LOWDELAY; #define VERB3 if (MAX_VERBOSE >= 3 && G.verbose >= 3) #define VERB4 if (MAX_VERBOSE >= 4 && G.verbose >= 4) #define VERB5 if (MAX_VERBOSE >= 5 && G.verbose >= 5) +#define VERB6 if (MAX_VERBOSE >= 6 && G.verbose >= 6) static double LOG2D(int a) @@ -568,7 +569,7 @@ filter_datapoints(peer_t *p) got_newest = 0; sum = 0; for (i = 0; i < NUM_DATAPOINTS; i++) { - VERB4 { + VERB5 { bb_error_msg("datapoint[%d]: off:%f disp:%f(%f) age:%f%s", i, fdp[idx].d_offset, @@ -665,7 +666,7 @@ filter_datapoints(peer_t *p) sum = SQRT(sum / NUM_DATAPOINTS); p->filter_jitter = sum > G_precision_sec ? sum : G_precision_sec; - VERB3 bb_error_msg("filter offset:%+f disp:%f jitter:%f", + VERB4 bb_error_msg("filter offset:%+f disp:%f jitter:%f", p->filter_offset, p->filter_dispersion, p->filter_jitter); @@ -700,7 +701,7 @@ reset_peer_stats(peer_t *p, double offset) p->lastpkt_recv_time = G.cur_time; } filter_datapoints(p); /* recalc p->filter_xxx */ - VERB5 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time); + VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time); } static void @@ -972,20 +973,20 @@ fit(peer_t *p, double rd) { if ((p->reachable_bits & (p->reachable_bits-1)) == 0) { /* One or zero bits in reachable_bits */ - VERB3 bb_error_msg("peer %s unfit for selection: unreachable", p->p_dotted); + VERB4 bb_error_msg("peer %s unfit for selection: unreachable", p->p_dotted); return 0; } #if 0 /* we filter out such packets earlier */ if ((p->lastpkt_status & LI_ALARM) == LI_ALARM || p->lastpkt_stratum >= MAXSTRAT ) { - VERB3 bb_error_msg("peer %s unfit for selection: bad status/stratum", p->p_dotted); + VERB4 bb_error_msg("peer %s unfit for selection: bad status/stratum", p->p_dotted); return 0; } #endif /* rd is root_distance(p) */ if (rd > MAXDIST + FREQ_TOLERANCE * (1 << G.poll_exp)) { - VERB3 bb_error_msg("peer %s unfit for selection: root distance too high", p->p_dotted); + VERB4 bb_error_msg("peer %s unfit for selection: root distance too high", p->p_dotted); return 0; } //TODO @@ -1025,7 +1026,7 @@ select_and_cluster(void) continue; } - VERB4 bb_error_msg("interval: [%f %f %f] %s", + VERB5 bb_error_msg("interval: [%f %f %f] %s", offset - rd, offset, offset + rd, @@ -1050,7 +1051,7 @@ select_and_cluster(void) } num_candidates = num_points / 3; if (num_candidates == 0) { - VERB3 bb_error_msg("no valid datapoints, no peer selected"); + VERB3 bb_error_msg("no valid datapoints%s", ", no peer selected"); return NULL; } //TODO: sorting does not seem to be done in reference code @@ -1108,12 +1109,13 @@ select_and_cluster(void) break; num_falsetickers++; if (num_falsetickers * 2 >= num_candidates) { - VERB3 bb_error_msg("too many falsetickers:%d (candidates:%d), no peer selected", - num_falsetickers, num_candidates); + VERB3 bb_error_msg("falsetickers:%d, candidates:%d%s", + num_falsetickers, num_candidates, + ", no peer selected"); return NULL; } } - VERB3 bb_error_msg("selected interval: [%f, %f]; candidates:%d falsetickers:%d", + VERB4 bb_error_msg("selected interval: [%f, %f]; candidates:%d falsetickers:%d", low, high, num_candidates, num_falsetickers); /* Clustering */ @@ -1131,7 +1133,7 @@ select_and_cluster(void) survivor[num_survivors].p = p; /* x.opt_rd == root_distance(p); */ survivor[num_survivors].metric = MAXDIST * p->lastpkt_stratum + point[i].opt_rd; - VERB4 bb_error_msg("survivor[%d] metric:%f peer:%s", + VERB5 bb_error_msg("survivor[%d] metric:%f peer:%s", num_survivors, survivor[num_survivors].metric, p->p_dotted); num_survivors++; } @@ -1141,8 +1143,9 @@ select_and_cluster(void) * is acceptable. */ if (num_survivors < MIN_SELECTED) { - VERB3 bb_error_msg("num_survivors %d < %d, no peer selected", - num_survivors, MIN_SELECTED); + VERB3 bb_error_msg("survivors:%d%s", + num_survivors, + ", no peer selected"); return NULL; } @@ -1162,7 +1165,7 @@ select_and_cluster(void) double min_jitter = min_jitter; if (num_survivors <= MIN_CLUSTERED) { - VERB3 bb_error_msg("num_survivors %d <= %d, not discarding more", + VERB4 bb_error_msg("num_survivors %d <= %d, not discarding more", num_survivors, MIN_CLUSTERED); break; } @@ -1188,11 +1191,11 @@ select_and_cluster(void) max_selection_jitter = selection_jitter_sq; max_idx = i; } - VERB5 bb_error_msg("survivor %d selection_jitter^2:%f", + VERB6 bb_error_msg("survivor %d selection_jitter^2:%f", i, selection_jitter_sq); } max_selection_jitter = SQRT(max_selection_jitter / num_survivors); - VERB4 bb_error_msg("max_selection_jitter (at %d):%f min_jitter:%f", + VERB5 bb_error_msg("max_selection_jitter (at %d):%f min_jitter:%f", max_idx, max_selection_jitter, min_jitter); /* If the maximum selection jitter is less than the @@ -1201,7 +1204,7 @@ select_and_cluster(void) * as well stop. */ if (max_selection_jitter < min_jitter) { - VERB3 bb_error_msg("max_selection_jitter:%f < min_jitter:%f, num_survivors:%d, not discarding more", + VERB4 bb_error_msg("max_selection_jitter:%f < min_jitter:%f, num_survivors:%d, not discarding more", max_selection_jitter, min_jitter, num_survivors); break; } @@ -1209,7 +1212,7 @@ select_and_cluster(void) /* Delete survivor[max_idx] from the list * and go around again. */ - VERB5 bb_error_msg("dropping survivor %d", max_idx); + VERB6 bb_error_msg("dropping survivor %d", max_idx); num_survivors--; while (max_idx < num_survivors) { survivor[max_idx] = survivor[max_idx + 1]; @@ -1251,7 +1254,7 @@ select_and_cluster(void) /* Starting from 1 is ok here */ for (i = 1; i < num_survivors; i++) { if (G.last_update_peer == survivor[i].p) { - VERB4 bb_error_msg("keeping old synced peer"); + VERB5 bb_error_msg("keeping old synced peer"); p = G.last_update_peer; goto keep_old; } @@ -1259,7 +1262,7 @@ select_and_cluster(void) } G.last_update_peer = p; keep_old: - VERB3 bb_error_msg("selected peer %s filter_offset:%+f age:%f", + VERB4 bb_error_msg("selected peer %s filter_offset:%+f age:%f", p->p_dotted, p->filter_offset, G.cur_time - p->lastpkt_recv_time @@ -1278,7 +1281,7 @@ set_new_values(int disc_state, double offset, double recv_time) * of the last clock filter sample, which must be earlier than * the current time. */ - VERB3 bb_error_msg("disc_state=%d last update offset=%f recv_time=%f", + VERB4 bb_error_msg("disc_state=%d last update offset=%f recv_time=%f", disc_state, offset, recv_time); G.discipline_state = disc_state; G.last_update_offset = offset; @@ -1316,8 +1319,8 @@ update_local_clock(peer_t *p) * an old sample or the same sample twice. */ if (recv_time <= G.last_update_recv_time) { - VERB3 bb_error_msg("same or older datapoint: %f >= %f, not using it", - G.last_update_recv_time, recv_time); + VERB3 bb_error_msg("update from %s: same or older datapoint, not using it", + p->p_dotted); return 0; /* "leave poll interval as is" */ } @@ -1333,7 +1336,7 @@ update_local_clock(peer_t *p) if (G.discipline_state == STATE_FREQ) { /* Ignore updates until the stepout threshold */ if (since_last_update < WATCH_THRESHOLD) { - VERB3 bb_error_msg("measuring drift, datapoint ignored, %f sec remains", + VERB4 bb_error_msg("measuring drift, datapoint ignored, %f sec remains", WATCH_THRESHOLD - since_last_update); return 0; /* "leave poll interval as is" */ } @@ -1349,10 +1352,15 @@ update_local_clock(peer_t *p) if (abs_offset > STEP_THRESHOLD) { double remains; +// TODO: this "spike state" seems to be useless, peer selection already drops +// occassional "bad" datapoints. If we are here, there were _many_ large offsets - +// looks like _our_ clock is off. switch (G.discipline_state) { case STATE_SYNC: /* The first outlyer: ignore it, switch to SPIK state */ - VERB2 bb_error_msg("offset:%+f - spike", offset); + VERB3 bb_error_msg("update from %s: offset:%+f, spike%s", + p->p_dotted, offset, + ""); G.discipline_state = STATE_SPIK; return -1; /* "decrease poll interval" */ @@ -1362,8 +1370,9 @@ update_local_clock(peer_t *p) */ remains = WATCH_THRESHOLD - since_last_update; if (remains > 0) { - VERB2 bb_error_msg("spike, datapoint ignored, %f sec remains", - remains); + VERB3 bb_error_msg("update from %s: offset:%+f, spike%s", + p->p_dotted, offset, + ", datapoint ignored"); return -1; /* "decrease poll interval" */ } /* fall through: we need to step */ @@ -1390,7 +1399,7 @@ update_local_clock(peer_t *p) * is always suppressed, even at the longer poll * intervals. */ - VERB3 bb_error_msg("stepping time by %+f; poll_exp=MINPOLL", offset); + VERB4 bb_error_msg("stepping time by %+f; poll_exp=MINPOLL", offset); step_time(offset); if (option_mask32 & OPT_q) { /* We were only asked to set time once. Done. */ @@ -1415,7 +1424,7 @@ update_local_clock(peer_t *p) } else { /* abs_offset <= STEP_THRESHOLD */ if (G.poll_exp < MINPOLL && G.initial_poll_complete) { - VERB3 bb_error_msg("small offset:%+f, disabling burst mode", offset); + VERB4 bb_error_msg("small offset:%+f, disabling burst mode", offset); G.polladj_count = 0; G.poll_exp = MINPOLL; } @@ -1444,7 +1453,7 @@ update_local_clock(peer_t *p) #else set_new_values(STATE_SYNC, offset, recv_time); #endif - VERB3 bb_error_msg("transitioning to FREQ, datapoint ignored"); + VERB4 bb_error_msg("transitioning to FREQ, datapoint ignored"); return 0; /* "leave poll interval as is" */ #if 0 /* this is dead code for now */ @@ -1513,7 +1522,7 @@ update_local_clock(peer_t *p) dtemp = p->filter_jitter; // SQRT(SQUARE(p->filter_jitter) + SQUARE(G.cluster_jitter)); dtemp += MAXD(p->filter_dispersion + FREQ_TOLERANCE * (G.cur_time - p->lastpkt_recv_time) + abs_offset, MINDISP); G.rootdisp = p->lastpkt_rootdisp + dtemp; - VERB3 bb_error_msg("updating leap/refid/reftime/rootdisp from peer %s", p->p_dotted); + VERB4 bb_error_msg("updating leap/refid/reftime/rootdisp from peer %s", p->p_dotted); /* We are in STATE_SYNC now, but did not do adjtimex yet. * (Any other state does not reach this, they all return earlier) @@ -1533,13 +1542,13 @@ update_local_clock(peer_t *p) dtemp = SQUARE(dtemp); G.discipline_wander = SQRT(etemp + (dtemp - etemp) / AVG); - VERB3 bb_error_msg("discipline freq_drift=%.9f(int:%ld corr:%e) wander=%f", + VERB4 bb_error_msg("discipline freq_drift=%.9f(int:%ld corr:%e) wander=%f", G.discipline_freq_drift, (long)(G.discipline_freq_drift * 65536e6), freq_drift, G.discipline_wander); #endif - VERB3 { + VERB4 { memset(&tmx, 0, sizeof(tmx)); if (adjtimex(&tmx) < 0) bb_perror_msg_and_die("adjtimex"); @@ -1587,7 +1596,7 @@ update_local_clock(peer_t *p) /* NB: here kernel returns constant == G.poll_exp, not == G.poll_exp - 4. * Not sure why. Perhaps it is normal. */ - VERB3 bb_error_msg("adjtimex:%d freq:%ld offset:%+ld status:0x%x", + VERB4 bb_error_msg("adjtimex:%d freq:%ld offset:%+ld status:0x%x", rc, tmx.freq, tmx.offset, tmx.status); G.kernel_freq_drift = tmx.freq / 65536; VERB2 bb_error_msg("update from:%s offset:%+f jitter:%f clock drift:%+.3fppm tc:%d", @@ -1609,7 +1618,7 @@ retry_interval(void) interval = RETRY_INTERVAL; r = random(); interval += r % (unsigned)(RETRY_INTERVAL / 4); - VERB3 bb_error_msg("chose retry interval:%u", interval); + VERB4 bb_error_msg("chose retry interval:%u", interval); return interval; } static unsigned @@ -1622,7 +1631,7 @@ poll_interval(int exponent) interval = 1 << exponent; r = random(); interval += ((r & (interval-1)) >> 4) + ((r >> 8) & 1); /* + 1/16 of interval, max */ - VERB3 bb_error_msg("chose poll interval:%u (poll_exp:%d exp:%d)", interval, G.poll_exp, exponent); + VERB4 bb_error_msg("chose poll interval:%u (poll_exp:%d exp:%d)", interval, G.poll_exp, exponent); return interval; } static NOINLINE void @@ -1716,7 +1725,7 @@ recv_and_process_peer_pkt(peer_t *p) T4 = G.cur_time; p->lastpkt_recv_time = T4; - VERB5 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time); + VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time); /* The delay calculation is a special case. In cases where the * server and client clocks are running at different rates and @@ -1779,7 +1788,7 @@ recv_and_process_peer_pkt(peer_t *p) * drop poll interval one step down. */ if (fabs(q->filter_offset) >= POLLDOWN_OFFSET) { - VERB3 bb_error_msg("offset:%+f > POLLDOWN_OFFSET", q->filter_offset); + VERB4 bb_error_msg("offset:%+f > POLLDOWN_OFFSET", q->filter_offset); goto poll_down; } } @@ -1801,11 +1810,11 @@ recv_and_process_peer_pkt(peer_t *p) G.polladj_count = 0; if (G.poll_exp < MAXPOLL) { G.poll_exp++; - VERB3 bb_error_msg("polladj: discipline_jitter:%f ++poll_exp=%d", + VERB4 bb_error_msg("polladj: discipline_jitter:%f ++poll_exp=%d", G.discipline_jitter, G.poll_exp); } } else { - VERB3 bb_error_msg("polladj: incr:%d", G.polladj_count); + VERB4 bb_error_msg("polladj: incr:%d", G.polladj_count); } } else { G.polladj_count -= G.poll_exp * 2; @@ -1827,11 +1836,11 @@ recv_and_process_peer_pkt(peer_t *p) if (pp->p_fd < 0) pp->next_action_time -= (1 << G.poll_exp); } - VERB3 bb_error_msg("polladj: discipline_jitter:%f --poll_exp=%d", + VERB4 bb_error_msg("polladj: discipline_jitter:%f --poll_exp=%d", G.discipline_jitter, G.poll_exp); } } else { - VERB3 bb_error_msg("polladj: decr:%d", G.polladj_count); + VERB4 bb_error_msg("polladj: decr:%d", G.polladj_count); } } } -- cgit v1.2.3-55-g6feb From 6c46eed6e935db43dedbff1d026e4cf68f0bc67e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 4 Dec 2013 17:12:11 +0100 Subject: ntpd: comment out "spike detection" code function old new delta update_local_clock 982 835 -147 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index aeef0431a..f3a4177da 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -334,7 +334,7 @@ struct globals { #define STATE_NSET 0 /* initial state, "nothing is set" */ //#define STATE_FSET 1 /* frequency set from file */ -#define STATE_SPIK 2 /* spike detected */ +//#define STATE_SPIK 2 /* spike detected */ //#define STATE_FREQ 3 /* initial frequency */ #define STATE_SYNC 4 /* clock synchronized (normal operation) */ uint8_t discipline_state; // doc calls it c.state @@ -1350,11 +1350,15 @@ update_local_clock(peer_t *p) * offset exceeds the step threshold and when it does not. */ if (abs_offset > STEP_THRESHOLD) { +#if 0 double remains; -// TODO: this "spike state" seems to be useless, peer selection already drops -// occassional "bad" datapoints. If we are here, there were _many_ large offsets - -// looks like _our_ clock is off. +// This "spike state" seems to be useless, peer selection already drops +// occassional "bad" datapoints. If we are here, there were _many_ +// large offsets. When a few first large offsets are seen, +// we end up in "no valid datapoints, no peer selected" state. +// Only when enough of them are seen (which means it's not a fluke), +// we end up here. Looks like _our_ clock is off. switch (G.discipline_state) { case STATE_SYNC: /* The first outlyer: ignore it, switch to SPIK state */ @@ -1377,6 +1381,7 @@ update_local_clock(peer_t *p) } /* fall through: we need to step */ } /* switch */ +#endif /* Step the time and clamp down the poll interval. * -- cgit v1.2.3-55-g6feb From 777be10ebebb4afdaf057a5abe094c86eb6d8a2c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 7 Dec 2013 17:29:03 +0100 Subject: ntpd: do not invalidate datapoints after step Used to set p->filter_datapoint[i].d_dispersion = MAXDISP and clear reachable bits, but this proved to be too agressive: after step (tested with suspinding laptop for ~30 secs), this caused all previous data to be considered invalid, making us needing to collect full ~8 datapoins per peer after step in order to start trusting them. In turn, this was making poll interval decrease even after step was done. (Poll interval decreases already before step in this scenario, because we see large offsets and end up with no good peer to select). function old new delta reset_peer_stats 157 139 -18 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index f3a4177da..fd2f24a89 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -678,6 +678,18 @@ reset_peer_stats(peer_t *p, double offset) int i; bool small_ofs = fabs(offset) < 16 * STEP_THRESHOLD; + /* Used to set p->filter_datapoint[i].d_dispersion = MAXDISP + * and clear reachable bits, but this proved to be too agressive: + * after step (tested with suspinding laptop for ~30 secs), + * this caused all previous data to be considered invalid, + * making us needing to collect full ~8 datapoins per peer + * after step in order to start trusting them. + * In turn, this was making poll interval decrease even after + * step was done. (Poll interval decreases already before step + * in this scenario, because we see large offsets and end up with + * no good peer to select). + */ + for (i = 0; i < NUM_DATAPOINTS; i++) { if (small_ofs) { p->filter_datapoint[i].d_recv_time += offset; @@ -691,13 +703,13 @@ reset_peer_stats(peer_t *p, double offset) } else { p->filter_datapoint[i].d_recv_time = G.cur_time; p->filter_datapoint[i].d_offset = 0; - p->filter_datapoint[i].d_dispersion = MAXDISP; + /*p->filter_datapoint[i].d_dispersion = MAXDISP;*/ } } if (small_ofs) { p->lastpkt_recv_time += offset; } else { - p->reachable_bits = 0; + /*p->reachable_bits = 0;*/ p->lastpkt_recv_time = G.cur_time; } filter_datapoints(p); /* recalc p->filter_xxx */ -- cgit v1.2.3-55-g6feb From 0b3a38b9f573634faa4f2bc8b0ffb6f55c0958f5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 8 Dec 2013 16:11:04 +0100 Subject: ntpd: speed up resyncing if our clock is seriously off function old new delta recv_and_process_peer_pkt 892 922 +30 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index fd2f24a89..ed83415b4 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -90,12 +90,24 @@ * was hibernated, someone set totally wrong date, etc), * then the time is stepped, all datapoints are discarded, * and we go back to steady state. + * + * Made some changes to speed up re-syncing after our clock goes bad + * (tested with suspending my laptop): + * - if largish offset (>= STEP_THRESHOLD * 8 == 1 sec) is seen + * from a peer, schedule next query for this peer soon + * without drastically lowering poll interval for everybody. + * This makes us collect enough data for step much faster: + * e.g. at poll = 10 (1024 secs), step was done within 5 minutes + * after first reply which indicated that our clock is 14 seconds off. + * - on step, do not discard d_dispersion data of the existing datapoints, + * do not clear reachable_bits. This prevents discarding first ~8 + * datapoints after the step. */ -#define RETRY_INTERVAL 5 /* on error, retry in N secs */ +#define RETRY_INTERVAL 5 /* on error, retry in N secs */ #define RESPONSE_INTERVAL 15 /* wait for reply up to N secs */ -#define INITIAL_SAMPLES 4 /* how many samples do we want for init */ -#define BAD_DELAY_GROWTH 4 /* drop packet if its delay grew by more than this */ +#define INITIAL_SAMPLES 4 /* how many samples do we want for init */ +#define BAD_DELAY_GROWTH 4 /* drop packet if its delay grew by more than this */ /* Clock discipline parameters and constants */ @@ -109,6 +121,10 @@ #define FREQ_TOLERANCE 0.000015 /* frequency tolerance (15 PPM) */ #define BURSTPOLL 0 /* initial poll */ #define MINPOLL 5 /* minimum poll interval. std ntpd uses 6 (6: 64 sec) */ +/* If we got largish offset from a peer, cap next query interval + * for this peer by this many seconds: + */ +#define BIGOFF_INTERVAL (1 << 6) /* If offset > discipline_jitter * POLLADJ_GATE, and poll interval is >= 2^BIGPOLL, * then it is decreased _at once_. (If < 2^BIGPOLL, it will be decreased _eventually_). */ @@ -1658,11 +1674,13 @@ recv_and_process_peer_pkt(peer_t *p) ssize_t size; msg_t msg; double T1, T2, T3, T4; - double dv; + double dv, offset; unsigned interval; datapoint_t *datapoint; peer_t *q; + offset = 0; + /* We can recvfrom here and check from.IP, but some multihomed * ntp servers reply from their *other IP*. * TODO: maybe we should check at least what we can: from.port == 123? @@ -1766,13 +1784,13 @@ recv_and_process_peer_pkt(peer_t *p) p->datapoint_idx = p->reachable_bits ? (p->datapoint_idx + 1) % NUM_DATAPOINTS : 0; datapoint = &p->filter_datapoint[p->datapoint_idx]; datapoint->d_recv_time = T4; - datapoint->d_offset = ((T2 - T1) + (T3 - T4)) / 2; + datapoint->d_offset = offset = ((T2 - T1) + (T3 - T4)) / 2; datapoint->d_dispersion = LOG2D(msg.m_precision_exp) + G_precision_sec; if (!p->reachable_bits) { /* 1st datapoint ever - replicate offset in every element */ int i; for (i = 0; i < NUM_DATAPOINTS; i++) { - p->filter_datapoint[i].d_offset = datapoint->d_offset; + p->filter_datapoint[i].d_offset = offset; } } @@ -1780,7 +1798,7 @@ recv_and_process_peer_pkt(peer_t *p) if ((MAX_VERBOSE && G.verbose) || (option_mask32 & OPT_w)) { bb_error_msg("reply from %s: offset:%+f delay:%f status:0x%02x strat:%d refid:0x%08x rootdelay:%f reach:0x%02x", p->p_dotted, - datapoint->d_offset, + offset, p->lastpkt_delay, p->lastpkt_status, p->lastpkt_stratum, @@ -1865,6 +1883,20 @@ recv_and_process_peer_pkt(peer_t *p) /* Decide when to send new query for this peer */ pick_normal_interval: interval = poll_interval(0); + if (fabs(offset) >= STEP_THRESHOLD * 8 && interval > BIGOFF_INTERVAL) { + /* If we are synced, offsets are less than STEP_THRESHOLD, + * or at the very least not much larger than it. + * Now we see a largish one. + * Either this peer is feeling bad, or packet got corrupted, + * or _our_ clock is wrong now and _all_ peers will show similar + * largish offsets too. + * I observed this with laptop suspend stopping clock. + * In any case, it makes sense to make next request soonish: + * cases 1 and 2: get a better datapoint, + * case 3: allows to resync faster. + */ + interval = BIGOFF_INTERVAL; + } set_next_and_ret: set_next(p, interval); -- cgit v1.2.3-55-g6feb From 22bb81fa85bc2a581c368923fe6d2bd80f74708f Mon Sep 17 00:00:00 2001 From: Michael Tokarev Date: Mon, 9 Dec 2013 16:09:35 +0400 Subject: expand: use printable_string instead of hard-coding implementation function old new delta expand_main 709 690 -19 Signed-off-by: Michael Tokarev Signed-off-by: Denys Vlasenko --- coreutils/expand.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/coreutils/expand.c b/coreutils/expand.c index 25bbffc66..8d376ff4e 100644 --- a/coreutils/expand.c +++ b/coreutils/expand.c @@ -78,11 +78,7 @@ static void expand(FILE *file, unsigned tab_size, unsigned opt) unsigned len; *ptr = '\0'; # if ENABLE_UNICODE_SUPPORT - { - uni_stat_t uni_stat; - printable_string(&uni_stat, ptr_strbeg); - len = uni_stat.unicode_width; - } + len = unicode_strwidth(ptr_strbeg); # else len = ptr - ptr_strbeg; # endif @@ -138,12 +134,9 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt) printf("%*s%.*s", len, "", n, ptr); # if ENABLE_UNICODE_SUPPORT { - char c; - uni_stat_t uni_stat; - c = ptr[n]; + char c = ptr[n]; ptr[n] = '\0'; - printable_string(&uni_stat, ptr); - len = uni_stat.unicode_width; + len = unicode_strwidth(ptr); ptr[n] = c; } # else -- cgit v1.2.3-55-g6feb From 9f4f60183b2de12ff618a4966378c6b49184b1de Mon Sep 17 00:00:00 2001 From: Michael Tokarev Date: Mon, 9 Dec 2013 14:45:01 +0400 Subject: do not fail build if MAXSYMLINKS isn't defined This is needed for, eg, hurd, which is known to have no constraints. Signed-off-by: Michael Tokarev Signed-off-by: Denys Vlasenko --- libbb/xreadlink.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index 0bdf394da..bb63da08c 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c @@ -8,6 +8,12 @@ #include "libbb.h" +/* some systems (eg Hurd) does not have MAXSYMLINKS definition, + * set it to some reasonable value if it isn't defined */ +#ifndef MAXSYMLINKS +# define MAXSYMLINKS 20 +#endif + /* * NOTE: This function returns a malloced char* that you will have to free * yourself. -- cgit v1.2.3-55-g6feb From 3ac1e0d753ca8e918a3b97020ae09058efffe057 Mon Sep 17 00:00:00 2001 From: Uros Vampl Date: Mon, 16 Dec 2013 17:44:58 +0100 Subject: killall5: return 2 if no processes got killed function old new delta kill_main 943 992 +49 Signed-off-by: Denys Vlasenko --- procps/kill.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/procps/kill.c b/procps/kill.c index cd189bcd6..8e4213730 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -158,7 +158,8 @@ int kill_main(int argc, char **argv) if (killall5) { pid_t sid; procps_status_t* p = NULL; - int ret = 0; + /* compat: exitcode 2 is "no one was signaled" */ + int ret = 2; /* Find out our session id */ sid = getsid(pid); @@ -170,6 +171,7 @@ int kill_main(int argc, char **argv) int i; if (p->sid == (unsigned)sid + || p->sid == 0 /* compat: kernel thread, don't signal it */ || p->pid == (unsigned)pid || p->pid == 1 ) { @@ -200,6 +202,7 @@ int kill_main(int argc, char **argv) goto dont_kill; } kill(p->pid, signo); + ret = 0; dont_kill: ; } resume: -- cgit v1.2.3-55-g6feb From 4b26f82c787cf02d600d416159e1a022d278f6f6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 16 Dec 2013 17:45:44 +0100 Subject: kill[all[5]]: code shrink function old new delta kill_main 992 947 -45 Signed-off-by: Denys Vlasenko --- procps/kill.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/procps/kill.c b/procps/kill.c index 8e4213730..c5c7a8d72 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -60,7 +60,7 @@ * This is needed to avoid collision with kill -9 ... syntax */ -int kill_main(int argc, char **argv) +int kill_main(int argc UNUSED_PARAM, char **argv) { char *arg; pid_t pid; @@ -79,10 +79,9 @@ int kill_main(int argc, char **argv) #endif /* Parse any options */ - argc--; arg = *++argv; - if (argc < 1 || arg[0] != '-') { + if (!arg || arg[0] != '-') { goto do_it_now; } @@ -91,13 +90,14 @@ int kill_main(int argc, char **argv) * echo "Died of SIG`kill -l $?`" * We try to mimic what kill from coreutils-6.8 does */ if (arg[1] == 'l' && arg[2] == '\0') { - if (argc == 1) { + arg = *++argv; + if (!arg) { /* Print the whole signal list */ print_signames(); return 0; } /* -l */ - while ((arg = *++argv)) { + do { if (isdigit(arg[0])) { signo = bb_strtou(arg, NULL, 10); if (errno) { @@ -118,8 +118,8 @@ int kill_main(int argc, char **argv) } printf("%d\n", signo); } - } - /* If they specified -l, we are all done */ + arg = *++argv; + } while (arg); return EXIT_SUCCESS; } @@ -127,8 +127,7 @@ int kill_main(int argc, char **argv) if (killall && arg[1] == 'q' && arg[2] == '\0') { quiet = 1; arg = *++argv; - argc--; - if (argc < 1) + if (!arg) bb_show_usage(); if (arg[0] != '-') goto do_it_now; @@ -140,8 +139,7 @@ int kill_main(int argc, char **argv) if (killall5 && arg[0] == 'o') goto do_it_now; - if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ - argc--; + if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ arg = *++argv; } /* else it must be -SIG */ signo = get_signum(arg); @@ -150,7 +148,6 @@ int kill_main(int argc, char **argv) return EXIT_FAILURE; } arg = *++argv; - argc--; do_it_now: pid = getpid(); @@ -168,7 +165,7 @@ int kill_main(int argc, char **argv) kill(-1, SIGSTOP); /* Signal all processes except those in our session */ while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID)) != NULL) { - int i; + char **args; if (p->sid == (unsigned)sid || p->sid == 0 /* compat: kernel thread, don't signal it */ @@ -180,18 +177,19 @@ int kill_main(int argc, char **argv) /* All remaining args must be -o PID options. * Check p->pid against them. */ - for (i = 0; i < argc; i++) { + args = argv; + while (*args) { pid_t omit; - arg = argv[i]; + arg = *args++; if (arg[0] != '-' || arg[1] != 'o') { bb_error_msg("bad option '%s'", arg); ret = 1; goto resume; } arg += 2; - if (!arg[0] && argv[++i]) - arg = argv[i]; + if (!arg[0] && *args) + arg = *args++; omit = bb_strtoi(arg, NULL, 10); if (errno) { bb_error_msg("invalid number '%s'", arg); @@ -213,14 +211,14 @@ int kill_main(int argc, char **argv) } /* Pid or name is required for kill/killall */ - if (argc < 1) { + if (!arg) { bb_error_msg("you need to specify whom to kill"); return EXIT_FAILURE; } if (killall) { /* Looks like they want to do a killall. Do that */ - while (arg) { + do { pid_t* pidList; pidList = find_pid_by_name(arg); @@ -243,7 +241,7 @@ int kill_main(int argc, char **argv) } free(pidList); arg = *++argv; - } + } while (arg); return errors; } -- cgit v1.2.3-55-g6feb From 4967a41ba1d17090e764952975c651b22fd183d1 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Tue, 17 Dec 2013 19:03:41 +0100 Subject: wget: user-friendly fallback to http GNU wget: wget google.com // ok bb before: wget google.com // wget: not an http or ftp url function old new delta parse_url 317 339 +22 Signed-off-by: Lauri Kasanen Signed-off-by: Denys Vlasenko --- networking/wget.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index cfbaceced..d6c509edc 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -274,14 +274,21 @@ static void parse_url(const char *src_url, struct host_info *h) free(h->allocated); h->allocated = url = xstrdup(src_url); - if (strncmp(url, "http://", 7) == 0) { - h->port = bb_lookup_port("http", "tcp", 80); - h->host = url + 7; - h->is_ftp = 0; - } else if (strncmp(url, "ftp://", 6) == 0) { + if (strncmp(url, "ftp://", 6) == 0) { h->port = bb_lookup_port("ftp", "tcp", 21); h->host = url + 6; h->is_ftp = 1; + } else + if (strncmp(url, "http://", 7) == 0) { + h->host = url + 7; + http: + h->port = bb_lookup_port("http", "tcp", 80); + h->is_ftp = 0; + } else + if (!strstr(url, "//")) { + // GNU wget is user-friendly and falls back to http:// + h->host = url; + goto http; } else bb_error_msg_and_die("not an http or ftp url: %s", sanitize_string(url)); -- cgit v1.2.3-55-g6feb From e9355c43263efd8f9b31b83c4e2aeba4a82de75e Mon Sep 17 00:00:00 2001 From: Michael Tokarev Date: Tue, 17 Dec 2013 19:13:45 +0100 Subject: hostname: do not use gethostbyname() for "hostname -s" There's no reason to call gethostbyname() on the value returned by uname() when asked just for a short name of a host. This may also be wrong, when uname is set to one value, but in /etc/hosts (or elsewhere) the "canonical" name is different. This is often the case for localhost entry in /etc/hosts: 127.0.0.1 localhost myname With this content of /etc/hosts, and uname being set to myname, busybox hostname -s will return localhost, while regular hostname utility returns myname. Fix this by not calling gethostbyname() for the simple 'hostname -s' use. Signed-off-by: Michael Tokarev Signed-off-by: Denys Vlasenko --- networking/hostname.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/networking/hostname.c b/networking/hostname.c index d2516b5fb..b3e352242 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -106,7 +106,7 @@ int hostname_main(int argc UNUSED_PARAM, char **argv) OPT_i = 0x4, OPT_s = 0x8, OPT_F = 0x10, - OPT_dfis = 0xf, + OPT_dfi = 0x7, }; unsigned opts; @@ -134,7 +134,7 @@ int hostname_main(int argc UNUSED_PARAM, char **argv) if (applet_name[0] == 'd') /* dnsdomainname? */ opts = OPT_d; - if (opts & OPT_dfis) { + if (opts & OPT_dfi) { /* Cases when we need full hostname (or its part) */ struct hostent *hp; char *p; @@ -159,6 +159,9 @@ int hostname_main(int argc UNUSED_PARAM, char **argv) bb_putchar('\n'); } } + } else if (opts & OPT_s) { + strchrnul(buf, '.')[0] = '\0'; + puts(buf); } else if (opts & OPT_F) { /* Set the hostname */ do_sethostname(hostname_str, 1); -- cgit v1.2.3-55-g6feb From 80a068d741b32850a45e815db90c4d92c636b157 Mon Sep 17 00:00:00 2001 From: "David A. Wheeler" Date: Thu, 5 Dec 2013 20:42:17 -0500 Subject: sed: accept s///i as a synonym for s///I ("ignore case") Signed-off-by: David A. Wheeler Signed-off-by: Denys Vlasenko --- editors/sed.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/editors/sed.c b/editors/sed.c index 31fb103ec..e18e48ab5 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -381,7 +381,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) /* * A substitution command should look something like this: - * s/match/replace/ #gIpw + * s/match/replace/ #giIpw * || | ||| * mandatory optional */ @@ -429,6 +429,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) break; } /* Ignore case (gnu exension) */ + case 'i': case 'I': cflags |= REG_ICASE; break; -- cgit v1.2.3-55-g6feb From c9d87bed8ed6aa6b3fcad255d93dbfd2561eac1d Mon Sep 17 00:00:00 2001 From: Daniel Borca Date: Thu, 19 Dec 2013 04:43:24 +0100 Subject: build system: fix make gconfig Was getting "undefined reference to symbol 'dlsym@@GLIBC_2.2.5'". Signed-off-by: Daniel Borca Signed-off-by: Denys Vlasenko --- scripts/kconfig/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 1651390a6..38bae809a 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -150,7 +150,7 @@ HOSTCFLAGS_zconf.tab.o := -I$(src) HOSTLOADLIBES_qconf = $(KC_QT_LIBS) -ldl HOSTCXXFLAGS_qconf.o = $(KC_QT_CFLAGS) -D LKC_DIRECT_LINK -HOSTLOADLIBES_gconf = `pkg-config --libs gtk+-2.0 gmodule-2.0 libglade-2.0` +HOSTLOADLIBES_gconf = `pkg-config --libs gtk+-2.0 gmodule-2.0 libglade-2.0` -ldl HOSTCFLAGS_gconf.o = `pkg-config --cflags gtk+-2.0 gmodule-2.0 libglade-2.0` \ -D LKC_DIRECT_LINK -- cgit v1.2.3-55-g6feb From e85e260e4720cd8f652c19b4df3e6901c02b9169 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 20 Dec 2013 02:55:16 +0100 Subject: testsuite: fix false positives for du Signed-off-by: Denys Vlasenko --- testsuite/du/du-k-works | 2 ++ testsuite/du/du-l-works | 1 + 2 files changed, 3 insertions(+) diff --git a/testsuite/du/du-k-works b/testsuite/du/du-k-works index 417b0daa5..213e9ba99 100644 --- a/testsuite/du/du-k-works +++ b/testsuite/du/du-k-works @@ -4,8 +4,10 @@ dd if=/dev/zero of=file1 bs=1k count=64 2>/dev/null dd if=/dev/zero of=file2 bs=1k count=16 2>/dev/null # ext4 on images <512M gives 81kb # ext3 on images <512M gives 83kb +# a bsd system reportedly gives 82kb test x"`busybox du -k .`" = x"80 ." \ -o x"`busybox du -k .`" = x"81 ." \ + -o x"`busybox du -k .`" = x"82 ." \ -o x"`busybox du -k .`" = x"83 ." \ -o x"`busybox du -k .`" = x"84 ." \ -o x"`busybox du -k .`" = x"88 ." diff --git a/testsuite/du/du-l-works b/testsuite/du/du-l-works index 426ee891b..af87345db 100644 --- a/testsuite/du/du-l-works +++ b/testsuite/du/du-l-works @@ -6,6 +6,7 @@ dd if=/dev/zero of=file1 bs=1k count=64 2>/dev/null ln file1 file1.1 dd if=/dev/zero of=file2 bs=1k count=16 2>/dev/null test x"`busybox du -l .`" = x"144 ." \ + -o x"`busybox du -l .`" = x"146 ." \ -o x"`busybox du -l .`" = x"148 ." \ -o x"`busybox du -l .`" = x"152 ." \ -o x"`busybox du -l .`" = x"156 ." -- cgit v1.2.3-55-g6feb From e83e1c50f20f01fbb10cf65532a966f7f63a6b6d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 20 Dec 2013 20:45:02 +0100 Subject: adduser: check whether run with no USERNAME. Closes 6728 Signed-off-by: Denys Vlasenko --- loginutils/adduser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loginutils/adduser.c b/loginutils/adduser.c index dc0244476..ef390adf8 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c @@ -162,9 +162,9 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) pw.pw_shell = (char *)get_shell_name(); pw.pw_dir = NULL; - /* at most two non-option args */ + /* at least one and at most two non-option args */ /* disable interactive passwd for system accounts */ - opt_complementary = "?2:SD:u+"; + opt_complementary = "-1:?2:SD:u+"; if (sizeof(pw.pw_uid) == sizeof(int)) { opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid); } else { -- cgit v1.2.3-55-g6feb From 61be8e46a80749fe5bb16bc8f831c689d21a4e34 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 Dec 2013 18:57:39 +0100 Subject: testsuite: disable tests for no longer supported bbox-specific date formats Signed-off-by: Denys Vlasenko --- testsuite/date/date-works | 8 +++++--- testsuite/date/date-works-1 | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/testsuite/date/date-works b/testsuite/date/date-works index 901c485ec..35c24686c 100644 --- a/testsuite/date/date-works +++ b/testsuite/date/date-works @@ -31,9 +31,11 @@ dt=`busybox date -d '1999-1-2 3:4:5'` dt=`echo "$dt" | cut -b1-19` test x"$dt" = x"Sat Jan 2 03:04:05" -dt=`busybox date -d 01231133` -dt=`echo "$dt" | cut -b5-19` -test x"$dt" = x"Jan 23 11:33:00" +# date (GNU coreutils) 8.17 doesn't accept 01231133 either: +# date: invalid date '01231133' +#dt=`busybox date -d 01231133` +#dt=`echo "$dt" | cut -b5-19` +#test x"$dt" = x"Jan 23 11:33:00" dt=`busybox date -d 200001231133` dt=`echo "$dt" | cut -b1-19` diff --git a/testsuite/date/date-works-1 b/testsuite/date/date-works-1 index cb5cea2c5..4f53939ee 100644 --- a/testsuite/date/date-works-1 +++ b/testsuite/date/date-works-1 @@ -41,9 +41,9 @@ test x"$hdt" = x"$dt" # Avoiding using week day in this evaluation, as it's mostly different every year # date (GNU coreutils) 6.10 reports: # date: invalid date '01231133' -dt=`busybox date -d 01231133 +%c` -dt=`echo "$dt" | cut -b5-19` -test x"$dt" = x"Jan 23 11:33:00" +#dt=`busybox date -d 01231133 +%c` +#dt=`echo "$dt" | cut -b5-19` +#test x"$dt" = x"Jan 23 11:33:00" # date (GNU coreutils) 6.10 reports: # date: invalid date '012311332000' -- cgit v1.2.3-55-g6feb From 198b02f7dd61c6cb9fd4c379dc56edcf537a7ee1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 Dec 2013 23:22:36 +0100 Subject: fix failures found by randomconfig builds Signed-off-by: Denys Vlasenko --- libbb/Kbuild.src | 2 +- libbb/correct_password.c | 9 --------- libbb/in_ether.c | 1 + libbb/nuke_str.c | 21 +++++++++++++++++++++ scripts/randomtest | 2 ++ testsuite/awk.tests | 6 +++++- testsuite/tar.tests | 6 ++++-- 7 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 libbb/nuke_str.c diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index c5d86c092..a6468f171 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src @@ -144,7 +144,7 @@ lib-$(CONFIG_DELUSER) += update_passwd.o lib-$(CONFIG_PASSWD) += pw_encrypt.o update_passwd.o obscure.o lib-$(CONFIG_CHPASSWD) += pw_encrypt.o update_passwd.o lib-$(CONFIG_CRYPTPW) += pw_encrypt.o -lib-$(CONFIG_SULOGIN) += pw_encrypt.o +lib-$(CONFIG_SULOGIN) += pw_encrypt.o correct_password.o lib-$(CONFIG_VLOCK) += pw_encrypt.o correct_password.o lib-$(CONFIG_SU) += pw_encrypt.o correct_password.o lib-$(CONFIG_LOGIN) += pw_encrypt.o correct_password.o diff --git a/libbb/correct_password.c b/libbb/correct_password.c index 5727c65fb..acadf3914 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c @@ -30,15 +30,6 @@ #include "libbb.h" -void FAST_FUNC nuke_str(char *str) -{ - if (str) { - while (*str) - *str++ = 0; - /* or: memset(str, 0, strlen(str)); - not as small as above */ - } -} - /* Ask the user for a password. * Return 1 without asking if PW has an empty password. * Return -1 on EOF, error while reading input, or timeout. diff --git a/libbb/in_ether.c b/libbb/in_ether.c index dadadbafe..1de383bde 100644 --- a/libbb/in_ether.c +++ b/libbb/in_ether.c @@ -3,6 +3,7 @@ * Utility routines. */ +//kbuild:lib-$(CONFIG_ARP) += in_ether.o //kbuild:lib-$(CONFIG_IFCONFIG) += in_ether.o //kbuild:lib-$(CONFIG_IFENSLAVE) += in_ether.o diff --git a/libbb/nuke_str.c b/libbb/nuke_str.c new file mode 100644 index 000000000..56b808bc7 --- /dev/null +++ b/libbb/nuke_str.c @@ -0,0 +1,21 @@ +/* vi: set sw=4 ts=4: */ +/* + * Utility routines. + * + * Copyright (C) 2008 Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ + +//kbuild:lib-y += nuke_str.o + +#include "libbb.h" + +void FAST_FUNC nuke_str(char *str) +{ + if (str) { + while (*str) + *str++ = 0; + /* or: memset(str, 0, strlen(str)); - not as small as above */ + } +} diff --git a/scripts/randomtest b/scripts/randomtest index a102593d3..d2b26bc76 100755 --- a/scripts/randomtest +++ b/scripts/randomtest @@ -65,6 +65,7 @@ if test x"$LIBC" = x"uclibc"; then | grep -v CONFIG_BUILD_LIBBUSYBOX \ | grep -v CONFIG_PIE \ \ + | grep -v CONFIG_FEATURE_TOUCH_NODEREF \ | grep -v CONFIG_FEATURE_2_4_MODULES \ >.config.new mv .config.new .config @@ -72,6 +73,7 @@ if test x"$LIBC" = x"uclibc"; then echo '# CONFIG_BUILD_LIBBUSYBOX is not set' >>.config echo '# CONFIG_PIE is not set' >>.config echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config + echo '# CONFIG_FEATURE_TOUCH_NODEREF is not set' >>.config fi # If STATIC, remove some things. diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 50b2a8328..132afc6a9 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests @@ -269,10 +269,12 @@ testing "awk FS assignment" "awk '{FS=\":\"; print \$1}'" \ "" \ "a:b c:d\ne:f g:h" +optional FEATURE_AWK_LIBM testing "awk large integer" \ "awk 'BEGIN{n=(2^31)-1; print n, int(n), n%1, ++n, int(n), n%1}'" \ "2147483647 2147483647 0 2147483648 2147483648 0\n" \ "" "" +SKIP= testing "awk length(array)" \ "awk 'BEGIN{ A[1]=2; A[\"qwe\"]=\"asd\"; print length(A)}'" \ @@ -285,11 +287,13 @@ testing "awk -f and ARGC" \ "do re mi\n" \ '{print $2; print ARGC;}' \ +optional FEATURE_AWK_GNU_EXTENSIONS testing "awk -e and ARGC" \ "awk -e '{print \$2; print ARGC;}' input" \ "re\n2\n" \ "do re mi\n" \ - "" \ + "" +SKIP= # testing "description" "command" "result" "infile" "stdin" diff --git a/testsuite/tar.tests b/testsuite/tar.tests index 93ba5f004..9ea89f15f 100755 --- a/testsuite/tar.tests +++ b/testsuite/tar.tests @@ -25,10 +25,12 @@ tar: short read SKIP= optional FEATURE_SEAMLESS_GZ +# In NOMMU case, "invalid magic" message comes from gunzip child process. +# Otherwise, it comes from tar. +# Need to fix output up to avoid false positive. testing "Empty file is not a tarball.tar.gz" '\ -tar xvzf - 2>&1; echo $? +{ tar xvzf - 2>&1; echo $?; } | grep -Fv "invalid magic" ' "\ -tar: invalid magic tar: short read 1 " \ -- cgit v1.2.3-55-g6feb From 7625811d25b27d426589182befe426d7233e012a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 Dec 2013 23:25:46 +0100 Subject: testsuite: remove forgotten debug hack Signed-off-by: Denys Vlasenko --- testsuite/tar.tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/tar.tests b/testsuite/tar.tests index 9ea89f15f..4929f4e49 100755 --- a/testsuite/tar.tests +++ b/testsuite/tar.tests @@ -38,7 +38,7 @@ tar: short read SKIP= testing "Two zeroed blocks is a ('truncated') empty tarball" '\ -dd if=/dev/zero bs=512 count=2 2>/dev/null | strace -o /tmp/zzz -tt -s99 tar xvf - 2>&1; echo $? +dd if=/dev/zero bs=512 count=2 2>/dev/null | tar xvf - 2>&1; echo $? ' "\ 0 " \ -- cgit v1.2.3-55-g6feb From a2dd4ee0e80f50e204f4755e725ae0b1cd07ebad Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 1 Jan 2014 00:42:11 +0100 Subject: Bump version to 1.22.0 Signed-off-by: Denys Vlasenko --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 24942f994..48d22e2d2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = 1 PATCHLEVEL = 22 SUBLEVEL = 0 -EXTRAVERSION = .git +EXTRAVERSION = NAME = Unnamed # *DOCUMENTATION* -- cgit v1.2.3-55-g6feb From 57434022cefde87133b8ad39fb3b79c1274e7684 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 1 Jan 2014 00:44:30 +0100 Subject: Start 1.23.0 development cycle Signed-off-by: Denys Vlasenko --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 48d22e2d2..778a02ff8 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = 1 -PATCHLEVEL = 22 +PATCHLEVEL = 23 SUBLEVEL = 0 -EXTRAVERSION = +EXTRAVERSION = .git NAME = Unnamed # *DOCUMENTATION* -- cgit v1.2.3-55-g6feb