From 1303962957fb900ed97c5958403990e885b06e29 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 13 Sep 2018 12:15:36 +0200 Subject: ntpd: more verbose message for "root distance too high" case Managed to make ntpd on one of my machines to be stuck getting "root distance too high" all the time, but log is not giving me more informatin what exactly is happening... function old new delta select_and_cluster 1045 1095 +50 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 991c518f6..1ebdc34c3 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1116,20 +1116,25 @@ fit(peer_t *p, double rd) { if ((p->reachable_bits & (p->reachable_bits-1)) == 0) { /* One or zero bits in reachable_bits */ - VERB4 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 ) { - VERB4 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)) { - VERB4 bb_error_msg("peer %s unfit for selection: root distance too high", p->p_dotted); + VERB3 bb_error_msg("peer %s unfit for selection: " + "root distance %f too high, jitter:%f", + p->p_dotted, rd, p->filter_jitter + ); return 0; } //TODO -- cgit v1.2.3-55-g6feb From 426aff88a0802b8da18292079f60f56388d0cdad Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 22 Sep 2018 19:30:40 +0200 Subject: init: hopefully fix "rebooting" in containers function old new delta pause_and_low_level_reboot 48 57 +9 Signed-off-by: Denys Vlasenko --- init/init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/init/init.c b/init/init.c index 6439e2bcd..fde35f6b6 100644 --- a/init/init.c +++ b/init/init.c @@ -752,8 +752,13 @@ static void pause_and_low_level_reboot(unsigned magic) reboot(magic); _exit(EXIT_SUCCESS); } - while (1) - sleep(1); + /* Used to have "while (1) sleep(1)" here. + * However, in containers reboot() call is ignored, and with that loop + * we would eternally sleep here - not what we want. + */ + waitpid(pid, NULL, 0); + sleep(1); /* paranoia */ + _exit(EXIT_SUCCESS); } static void run_shutdown_and_kill_processes(void) -- cgit v1.2.3-55-g6feb From e0f617699f7f1dfa1e56ded54bb1d70fd91c225e Mon Sep 17 00:00:00 2001 From: Thomas De Schampheleire Date: Thu, 13 Sep 2018 15:01:45 +0200 Subject: head: add test case for negative -n invocation Commit 2da9724b56169f00bd7fb6b9a11c9409a7620981 broke 'head -n -1' and was later reverted with 0d598ab9f03dbf320f7b81c05e4a94cb303dfbc7. This commit adds a test case to avoid future breakage. Signed-off-by: Thomas De Schampheleire Signed-off-by: Denys Vlasenko --- testsuite/head.tests | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 testsuite/head.tests diff --git a/testsuite/head.tests b/testsuite/head.tests new file mode 100755 index 000000000..1feecf990 --- /dev/null +++ b/testsuite/head.tests @@ -0,0 +1,31 @@ +#!/bin/sh +# Copyright 2018 Thomas De Schampheleire +# Licensed under GPLv2 or later, see file LICENSE in this source tree. + +. ./testing.sh + +# testing "test name" "command" "expected result" "file input" "stdin" + +cat < head.input +line 1 +line 2 +line 3 +line 4 +line 5 +line 6 +line 7 +line 8 +line 9 +line 10 +line 11 +line 12 +EOF + +testing "head -n " \ + "head -n -9 head.input" \ + "line 1\nline 2\nline 3\n" \ + "" "" + +rm head.input + +exit $FAILCOUNT -- cgit v1.2.3-55-g6feb From 6608879d34f9635572415e864b4fcbc497c74bcf Mon Sep 17 00:00:00 2001 From: Thomas De Schampheleire Date: Thu, 13 Sep 2018 15:01:46 +0200 Subject: head: convert existing tests to new-style Signed-off-by: Thomas De Schampheleire Signed-off-by: Denys Vlasenko --- testsuite/head.tests | 10 ++++++++++ testsuite/head/head-n-works | 4 ---- testsuite/head/head-works | 4 ---- 3 files changed, 10 insertions(+), 8 deletions(-) delete mode 100644 testsuite/head/head-n-works delete mode 100644 testsuite/head/head-works diff --git a/testsuite/head.tests b/testsuite/head.tests index 1feecf990..50660d267 100755 --- a/testsuite/head.tests +++ b/testsuite/head.tests @@ -21,6 +21,16 @@ line 11 line 12 EOF +testing "head (without args)" \ + "head head.input" \ + "line 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\nline 10\n" \ + "" "" + +testing "head -n " \ + "head -n 2 head.input" \ + "line 1\nline 2\n" \ + "" "" + testing "head -n " \ "head -n -9 head.input" \ "line 1\nline 2\nline 3\n" \ diff --git a/testsuite/head/head-n-works b/testsuite/head/head-n-works deleted file mode 100644 index db4325556..000000000 --- a/testsuite/head/head-n-works +++ /dev/null @@ -1,4 +0,0 @@ -[ -n "$d" ] || d=.. -head -n 2 "$d/README" > logfile.gnu -busybox head -n 2 "$d/README" > logfile.bb -cmp logfile.gnu logfile.bb diff --git a/testsuite/head/head-works b/testsuite/head/head-works deleted file mode 100644 index 56ad3e36b..000000000 --- a/testsuite/head/head-works +++ /dev/null @@ -1,4 +0,0 @@ -[ -n "$d" ] || d=.. -head "$d/README" > logfile.gnu -busybox head "$d/README" > logfile.bb -cmp logfile.gnu logfile.bb -- cgit v1.2.3-55-g6feb From 76832ff5c4f107f8a8165fcafc9b05a888cdb964 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 23 Sep 2018 20:27:32 +0200 Subject: date: do not allow "month #20" and such, closes 11356 function old new delta parse_datestr 906 961 +55 Signed-off-by: Denys Vlasenko --- libbb/time.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libbb/time.c b/libbb/time.c index 82e6cb172..f9b8da0b3 100644 --- a/libbb/time.c +++ b/libbb/time.c @@ -184,6 +184,7 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm) ptm->tm_year -= 1900; /* Adjust years */ ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ } else { + err: bb_error_msg_and_die(bb_msg_invalid_date, date_str); } ptm->tm_sec = 0; /* assume zero if [.SS] is not given */ @@ -194,6 +195,19 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm) end = '\0'; /* else end != NUL and we error out */ } + /* Users were confused by "date -s 20180923" + * working (not in the way they were expecting). + * It was interpreted as MMDDhhmm, and not bothered by + * "month #20" in the least. Prevent such cases: + */ + if (ptm->tm_sec > 60 /* allow "23:60" leap second */ + || ptm->tm_min > 59 + || ptm->tm_hour > 23 + || ptm->tm_mday > 31 + || ptm->tm_mon > 11 /* month# is 0..11, not 1..12 */ + ) { + goto err; + } } if (end != '\0') { bb_error_msg_and_die(bb_msg_invalid_date, date_str); -- cgit v1.2.3-55-g6feb From 706a9a03bb0a745a1f2db1ed632542a2d2af6021 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 25 Sep 2018 12:50:54 +0200 Subject: sed: fix double-free in FEATURE_CLEAN_UP code Signed-off-by: Denys Vlasenko --- editors/sed.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index 470220859..1054c1302 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -180,18 +180,23 @@ static void sed_free_and_close_stuff(void) if (sed_cmd->sw_file) fclose(sed_cmd->sw_file); - if (sed_cmd->beg_match) { - regfree(sed_cmd->beg_match); - free(sed_cmd->beg_match); - } - if (sed_cmd->end_match) { - regfree(sed_cmd->end_match); - free(sed_cmd->end_match); - } - if (sed_cmd->sub_match) { - regfree(sed_cmd->sub_match); - free(sed_cmd->sub_match); - } + /* Used to free regexps, but now there is code + * in get_address() which can reuse a regexp + * for constructs as /regexp/cmd1;//cmd2 + * leading to double-frees here: + */ + //if (sed_cmd->beg_match) { + // regfree(sed_cmd->beg_match); + // free(sed_cmd->beg_match); + //} + //if (sed_cmd->end_match) { + // regfree(sed_cmd->end_match); + // free(sed_cmd->end_match); + //} + //if (sed_cmd->sub_match) { + // regfree(sed_cmd->sub_match); + // free(sed_cmd->sub_match); + //} free(sed_cmd->string); free(sed_cmd); sed_cmd = sed_cmd_next; -- cgit v1.2.3-55-g6feb From d1cd3da1e5cf68921b81c04e0d4be571c96976a2 Mon Sep 17 00:00:00 2001 From: Martin Kaiser Date: Mon, 24 Sep 2018 21:01:51 +0200 Subject: mdev.txt: explain the meaning of a leading "-" If a line in mdev.conf starts with "-", parsing will continue even if a match is found in that line. Signed-off-by: Martin Kaiser Signed-off-by: Denys Vlasenko --- docs/mdev.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/mdev.txt b/docs/mdev.txt index b24025f7b..b13a0bb93 100644 --- a/docs/mdev.txt +++ b/docs/mdev.txt @@ -60,9 +60,9 @@ or For example: hd[a-z][0-9]* 0:3 660 -The config file parsing stops at the first matching line. If no line is -matched, then the default of 0:0 660 is used. To set your own default, simply -create your own total match like so: +The config file parsing stops at the first matching line unless this line +starts with "-". If no line is matched, then the default of 0:0 660 is used. +To set your own default, simply create your own total match like so: .* 1:1 777 -- cgit v1.2.3-55-g6feb From 702d865fe6ab84c1179275beda6c31f7adaeafa1 Mon Sep 17 00:00:00 2001 From: Martin Kaiser Date: Mon, 24 Sep 2018 21:00:47 +0200 Subject: .gitignore: add ctags output files Exuberant ctags creates an output file called "tags" by default or "TAGS" when it's run in emacs mode. Add those two files to .gitignore so they won't be removed by git clean -df. Signed-off-by: Martin Kaiser Signed-off-by: Denys Vlasenko --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index be1d46199..c03c2e8a6 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,9 @@ cscope.files cscope.in.out cscope.out cscope.po.out + +# +# ctags output +# +tags +TAGS -- cgit v1.2.3-55-g6feb From aae428f0bf0fcd6cd0a2503b3a50de43785b8fd0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 28 Sep 2018 14:44:09 +0200 Subject: udhcpc: give SIGUSR1-induced renew one chance of unicast renew The caps were inconsistent: timeout to renew was capped at 20 seconds, and any renews with timeout <= 60 seconds were forced to broadcast. function old new delta udhcpc_main 2683 2680 -3 Signed-off-by: Denys Vlasenko --- networking/udhcp/d6_dhcpc.c | 8 +++----- networking/udhcp/dhcpc.c | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index ed2255ef3..66e4b6c6a 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -1405,7 +1405,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ case_RENEW_REQUESTED: case RENEWING: - if (timeout > 60) { + if (timeout >= 60) { /* send an unicast renew request */ /* Sometimes observed to fail (EADDRNOTAVAIL) to bind * a new UDP socket for sending inside send_renew. @@ -1465,11 +1465,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) * For the second case, must make sure timeout * is not too big, or else we can send * futile renew requests for hours. - * (Ab)use -A TIMEOUT value (usually 20 sec) - * as a cap on the timeout. */ - if (timeout > tryagain_timeout) - timeout = tryagain_timeout; + if (timeout > 60) + timeout = 60; goto case_RENEW_REQUESTED; } /* Start things over */ diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 0310663e0..ab3e5a463 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1519,7 +1519,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ case_RENEW_REQUESTED: case RENEWING: - if (timeout > 60) { + if (timeout >= 60) { /* send an unicast renew request */ /* Sometimes observed to fail (EADDRNOTAVAIL) to bind * a new UDP socket for sending inside send_renew. @@ -1592,11 +1592,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) * For the second case, must make sure timeout * is not too big, or else we can send * futile renew requests for hours. - * (Ab)use -A TIMEOUT value (usually 20 sec) - * as a cap on the timeout. */ - if (timeout > tryagain_timeout) - timeout = tryagain_timeout; + if (timeout > 60) + timeout = 60; goto case_RENEW_REQUESTED; } /* Start things over */ -- cgit v1.2.3-55-g6feb From abfa3ec0598ff431407224c6b81682f7d0d35495 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 28 Sep 2018 15:13:04 +0200 Subject: move storage helpers to libbb.h Signed-off-by: Denys Vlasenko --- e2fsprogs/tune2fs.c | 17 ----------------- include/libbb.h | 17 +++++++++++++++++ util-linux/mkfs_ext2.c | 17 ----------------- util-linux/mkfs_reiser.c | 16 ---------------- util-linux/mkfs_vfat.c | 13 ------------- 5 files changed, 17 insertions(+), 63 deletions(-) diff --git a/e2fsprogs/tune2fs.c b/e2fsprogs/tune2fs.c index a1caf011c..f7fcd88bf 100644 --- a/e2fsprogs/tune2fs.c +++ b/e2fsprogs/tune2fs.c @@ -39,23 +39,6 @@ #include #include "bb_e2fs_defs.h" -// storage helpers -char BUG_wrong_field_size(void); -#define STORE_LE(field, value) \ -do { \ - if (sizeof(field) == 4) \ - field = SWAP_LE32(value); \ - else if (sizeof(field) == 2) \ - field = SWAP_LE16(value); \ - else if (sizeof(field) == 1) \ - field = (value); \ - else \ - BUG_wrong_field_size(); \ -} while (0) - -#define FETCH_LE32(field) \ - (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size()) - enum { OPT_L = 1 << 0, // label OPT_c = 1 << 1, // max mount count diff --git a/include/libbb.h b/include/libbb.h index 7cad12c44..61fa1e03e 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -2127,6 +2127,23 @@ extern const char bb_default_login_shell[] ALIGN1; # define FB_0 "/dev/fb0" #endif +// storage helpers for mk*fs utilities +char BUG_wrong_field_size(void); +#define STORE_LE(field, value) \ +do { \ + if (sizeof(field) == 4) \ + field = SWAP_LE32((uint32_t)(value)); \ + else if (sizeof(field) == 2) \ + field = SWAP_LE16((uint16_t)(value)); \ + else if (sizeof(field) == 1) \ + field = (uint8_t)(value); \ + else \ + BUG_wrong_field_size(); \ +} while (0) + +#define FETCH_LE32(field) \ + (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size()) + #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index f524bc239..bda168f1e 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c @@ -78,23 +78,6 @@ #define EXT2_FLAGS_SIGNED_HASH 0x0001 #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 -// storage helpers -char BUG_wrong_field_size(void); -#define STORE_LE(field, value) \ -do { \ - if (sizeof(field) == 4) \ - field = SWAP_LE32((uint32_t)(value)); \ - else if (sizeof(field) == 2) \ - field = SWAP_LE16((uint16_t)(value)); \ - else if (sizeof(field) == 1) \ - field = (uint8_t)(value); \ - else \ - BUG_wrong_field_size(); \ -} while (0) - -#define FETCH_LE32(field) \ - (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size()) - // All fields are little-endian struct ext2_dir { uint32_t inode1; diff --git a/util-linux/mkfs_reiser.c b/util-linux/mkfs_reiser.c index 390aef86c..b4c8dda6f 100644 --- a/util-linux/mkfs_reiser.c +++ b/util-linux/mkfs_reiser.c @@ -28,22 +28,6 @@ #include "libbb.h" #include -char BUG_wrong_field_size(void); -#define STORE_LE(field, value) \ -do { \ - if (sizeof(field) == 4) \ - field = SWAP_LE32(value); \ - else if (sizeof(field) == 2) \ - field = SWAP_LE16(value); \ - else if (sizeof(field) == 1) \ - field = (value); \ - else \ - BUG_wrong_field_size(); \ -} while (0) - -#define FETCH_LE32(field) \ - (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size()) - struct journal_params { uint32_t jp_journal_1st_block; /* where does journal start from on its device */ uint32_t jp_journal_dev; /* journal device st_rdev */ diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c index 92f0e3b1a..6a6dc652f 100644 --- a/util-linux/mkfs_vfat.c +++ b/util-linux/mkfs_vfat.c @@ -206,19 +206,6 @@ static const char boot_code[] ALIGN1 = #define MARK_CLUSTER(cluster, value) \ ((uint32_t *)fat)[cluster] = SWAP_LE32(value) -void BUG_unsupported_field_size(void); -#define STORE_LE(field, value) \ -do { \ - if (sizeof(field) == 4) \ - field = SWAP_LE32((uint32_t)(value)); \ - else if (sizeof(field) == 2) \ - field = SWAP_LE16((uint16_t)(value)); \ - else if (sizeof(field) == 1) \ - field = (uint8_t)(value); \ - else \ - BUG_unsupported_field_size(); \ -} while (0) - /* compat: * mkdosfs 2.11 (12 Mar 2005) * Usage: mkdosfs [-A] [-c] [-C] [-v] [-I] [-l bad-block-file] -- cgit v1.2.3-55-g6feb From 14454b3071c7a5c053fde8eed416ab3b2f8475fb Mon Sep 17 00:00:00 2001 From: Brandon Maier Date: Fri, 21 Sep 2018 12:54:05 -0500 Subject: ifupdown: support "source-directory" stanza Support the "source-directory" stanza from ifupdown[1]. source-directory will include all files in the named directory. Similar to the Busybox version of the "source" stanza, this version of source-directory does not currently support shell wildcards. We only check that the stanza starts with "source-dir" as ifupdown does[2]. [1] https://manpages.debian.org/stretch/ifupdown/interfaces.5.en.html#INCLUDING_OTHER_FILES [2] https://salsa.debian.org/debian/ifupdown/blob/0.8.33/config.c#L498 function old new delta read_interfaces 1150 1241 +91 Signed-off-by: Brandon Maier Signed-off-by: Denys Vlasenko --- networking/ifupdown.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 5481134e5..80fce87a6 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -1022,6 +1022,22 @@ static struct interfaces_file_t *read_interfaces(const char *filename, struct in currently_processing = NONE; } else if (strcmp(first_word, "source") == 0) { read_interfaces(next_word(&rest_of_line), defn); + } else if (is_prefixed_with(first_word, "source-dir")) { + const char *dirpath; + DIR *dir; + struct dirent *entry; + + dirpath = next_word(&rest_of_line); + dir = xopendir(dirpath); + while ((entry = readdir(dir)) != NULL) { + char *path; + if (entry->d_name[0] == '.') + continue; + path = concat_path_file(dirpath, entry->d_name); + read_interfaces(path, defn); + free(path); + } + closedir(dir); } else { switch (currently_processing) { case IFACE: -- cgit v1.2.3-55-g6feb From 349d72c19ced4fae64e8fdd5792b37e78ac2f616 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 30 Sep 2018 16:56:56 +0200 Subject: unzip: use printable_string() for printing filenames function old new delta unzip_main 2726 2792 +66 printable_string2 - 57 +57 identify 4329 4336 +7 expmeta 659 663 +4 add_interface 99 103 +4 beep_main 286 289 +3 changepath 192 194 +2 builtin_type 115 117 +2 devmem_main 469 470 +1 input_tab 1076 1074 -2 create_J 1821 1819 -2 poplocalvars 314 311 -3 doCommands 2222 2214 -8 do_load 918 902 -16 printable_string 57 9 -48 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 8/6 up/down: 146/-79) Total: 67 bytes Signed-off-by: Denys Vlasenko --- archival/unzip.c | 57 +++++++++++++++++++++++++++++++----------------- coreutils/ls.c | 4 ++-- include/libbb.h | 3 ++- libbb/lineedit.c | 2 +- libbb/printable_string.c | 7 +++++- libbb/unicode.c | 2 +- util-linux/fdisk_gpt.c | 2 +- 7 files changed, 50 insertions(+), 27 deletions(-) diff --git a/archival/unzip.c b/archival/unzip.c index 96b7ab69b..c406d53c4 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -153,15 +153,15 @@ typedef union { #define FIX_ENDIANNESS_CDF(cdf) \ do { if (BB_BIG_ENDIAN) { \ (cdf).fmt.version_made_by = SWAP_LE16((cdf).fmt.version_made_by); \ - (cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed); \ - (cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \ - (cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \ - (cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \ - (cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \ - (cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \ - (cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \ - (cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len); \ - (cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \ + (cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed ); \ + (cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \ + (cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \ + (cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \ + (cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \ + (cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \ + (cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \ + (cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len ); \ + (cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \ (cdf).fmt.file_comment_length = SWAP_LE16((cdf).fmt.file_comment_length); \ (cdf).fmt.external_attributes = SWAP_LE32((cdf).fmt.external_attributes); \ }} while (0) @@ -456,7 +456,9 @@ static int get_lstat_mode(const char *dst_fn) struct stat stat_buf; if (lstat(dst_fn, &stat_buf) == -1) { if (errno != ENOENT) { - bb_perror_msg_and_die("can't stat '%s'", dst_fn); + bb_perror_msg_and_die("can't stat '%s'", + dst_fn + ); } /* File does not exist */ return -1; @@ -634,7 +636,9 @@ int unzip_main(int argc, char **argv) break; if (++i > 2) { *ext = '\0'; - bb_error_msg_and_die("can't open %s[.zip]", src_fn); + bb_error_msg_and_die("can't open %s[.zip]", + src_fn + ); } strcpy(ext, extn[i - 1]); } @@ -646,8 +650,11 @@ int unzip_main(int argc, char **argv) xchdir(base_dir); if (quiet <= 1) { /* not -qq */ - if (quiet == 0) - printf("Archive: %s\n", src_fn); + if (quiet == 0) { + printf("Archive: %s\n", + printable_string(src_fn) + ); + } if (opts & OPT_l) { puts(verbose ? " Length Method Size Cmpr Date Time CRC-32 Name\n" @@ -831,7 +838,8 @@ int unzip_main(int argc, char **argv) printf( "%9u " "%s " "%s\n", (unsigned)zip.fmt.ucmpsize, dtbuf, - dst_fn); + printable_string(dst_fn) + ); } else { char method6[7]; unsigned long percents; @@ -860,7 +868,8 @@ int unzip_main(int argc, char **argv) (unsigned)percents, dtbuf, zip.fmt.crc32, - dst_fn); + printable_string(dst_fn) + ); total_size += zip.fmt.cmpsize; } total_usize += zip.fmt.ucmpsize; @@ -886,7 +895,7 @@ int unzip_main(int argc, char **argv) mode = get_lstat_mode(dst_fn); if (mode == -1) { /* ENOENT */ if (!quiet) { - printf(" creating: %s\n", dst_fn); + printf(" creating: %s\n", printable_string(dst_fn)); } unzip_create_leading_dirs(dst_fn); if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) { @@ -895,7 +904,9 @@ int unzip_main(int argc, char **argv) } else { if (!S_ISDIR(mode)) { bb_error_msg_and_die("'%s' exists but is not a %s", - dst_fn, "directory"); + printable_string(dst_fn), + "directory" + ); } } goto skip_cmpsize; @@ -914,12 +925,16 @@ int unzip_main(int argc, char **argv) if (!S_ISREG(mode)) { fishy: bb_error_msg_and_die("'%s' exists but is not a %s", - dst_fn, "regular file"); + printable_string(dst_fn), + "regular file" + ); } if (overwrite == O_ALWAYS) { goto do_open_and_extract; } - printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn); + printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", + printable_string(dst_fn) + ); my_fgets80(key_buf); /* User input could take a long time. Is it still a regular file? */ mode = get_lstat_mode(dst_fn); @@ -949,7 +964,9 @@ int unzip_main(int argc, char **argv) if (!quiet) { printf(/* zip.fmt.method == 0 ? " extracting: %s\n" - : */ " inflating: %s\n", dst_fn); + : */ " inflating: %s\n", + printable_string(dst_fn) + ); } #if ENABLE_FEATURE_UNZIP_CDF if (S_ISLNK(file_mode)) { diff --git a/coreutils/ls.c b/coreutils/ls.c index b1c306809..db3ddb944 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -421,7 +421,7 @@ static unsigned calc_name_len(const char *name) uni_stat_t uni_stat; // TODO: quote tab as \t, etc, if -Q - name = printable_string(&uni_stat, name); + name = printable_string2(&uni_stat, name); if (!(option_mask32 & OPT_Q)) { return uni_stat.unicode_width; @@ -450,7 +450,7 @@ static unsigned print_name(const char *name) uni_stat_t uni_stat; // TODO: quote tab as \t, etc, if -Q - name = printable_string(&uni_stat, name); + name = printable_string2(&uni_stat, name); if (!(option_mask32 & OPT_Q)) { fputs(name, stdout); diff --git a/include/libbb.h b/include/libbb.h index 61fa1e03e..140404ff5 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -833,7 +833,8 @@ typedef struct uni_stat_t { } uni_stat_t; /* Returns a string with unprintable chars replaced by '?' or * SUBST_WCHAR. This function is unicode-aware. */ -const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str); +const char* FAST_FUNC printable_string(const char *str); +const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str); /* Prints unprintable char ch as ^C or M-c to file * (M-c is used only if ch is ORed with PRINTABLE_META), * else it is printed as-is (except for ch = 0x9b) */ diff --git a/libbb/lineedit.c b/libbb/lineedit.c index d5e92e84c..b1e971f88 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1086,7 +1086,7 @@ static void showfiles(void) ); } if (ENABLE_UNICODE_SUPPORT) - puts(printable_string(NULL, matches[n])); + puts(printable_string(matches[n])); else puts(matches[n]); } diff --git a/libbb/printable_string.c b/libbb/printable_string.c index 077d58d32..a814fd03c 100644 --- a/libbb/printable_string.c +++ b/libbb/printable_string.c @@ -9,7 +9,7 @@ #include "libbb.h" #include "unicode.h" -const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str) +const char* FAST_FUNC printable_string2(uni_stat_t *stats, const char *str) { char *dst; const char *s; @@ -55,3 +55,8 @@ const char* FAST_FUNC printable_string(uni_stat_t *stats, const char *str) #endif return auto_string(dst); } + +const char* FAST_FUNC printable_string(const char *str) +{ + return printable_string2(NULL, str); +} diff --git a/libbb/unicode.c b/libbb/unicode.c index d378175a4..89d42179b 100644 --- a/libbb/unicode.c +++ b/libbb/unicode.c @@ -996,7 +996,7 @@ size_t FAST_FUNC unicode_strlen(const char *string) size_t FAST_FUNC unicode_strwidth(const char *string) { uni_stat_t uni_stat; - printable_string(&uni_stat, string); + printable_string2(&uni_stat, string); return uni_stat.unicode_width; } diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c index cdb90627d..dbe889f7c 100644 --- a/util-linux/fdisk_gpt.c +++ b/util-linux/fdisk_gpt.c @@ -87,7 +87,7 @@ gpt_print_wide36(uint16_t *s) } wc[i] = 0; if (wcstombs(buf, wc, sizeof(buf)) <= sizeof(buf)-1) - fputs(printable_string(NULL, buf), stdout); + fputs(printable_string(buf), stdout); #else char buf[37]; int i = 0; -- cgit v1.2.3-55-g6feb