From d74f8435ea7479fe558efa63c2ecc9aed5662db2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 13 Jan 2014 11:45:34 +0100 Subject: docs: tweak keep_data_small.txt Signed-off-by: Denys Vlasenko --- docs/keep_data_small.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/keep_data_small.txt b/docs/keep_data_small.txt index 9fc799646..3ced1a61d 100644 --- a/docs/keep_data_small.txt +++ b/docs/keep_data_small.txt @@ -103,7 +103,15 @@ smaller code. In order to assign it, use SET_PTR_TO_GLOBALS macro: SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); -Typically it is done in _main(). +Typically it is done in _main(). Another variation is +to use stack: + +int _main(...) +{ +#undef G + struct globals G; + memset(&G, 0, sizeof(G)); + SET_PTR_TO_GLOBALS(&G); Now you can reference "globals" by G.a, G.buf and so on, in any function. -- cgit v1.2.3-55-g6feb From 2e66daca654d130b820a4f0498de7f0ec355039a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 13 Jan 2014 13:38:53 +0100 Subject: examples/udhcp: do not rewrite resolv.conf if no DNS servers. Closes 6788 Signed-off-by: Denys Vlasenko --- examples/udhcp/sample.bound | 18 +++++++++++------- examples/udhcp/sample.renew | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/examples/udhcp/sample.bound b/examples/udhcp/sample.bound index bd3569c77..7c9d857e0 100755 --- a/examples/udhcp/sample.bound +++ b/examples/udhcp/sample.bound @@ -22,10 +22,14 @@ then done fi -echo -n > $RESOLV_CONF -[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF -for i in $dns -do - echo adding dns $i - echo nameserver $i >> $RESOLV_CONF -done +# Only replace resolv.conf is we have at least one DNS server +if [ -n "$dns" ] +then + echo -n > $RESOLV_CONF + [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF + for i in $dns + do + echo adding dns $i + echo nameserver $i >> $RESOLV_CONF + done +fi diff --git a/examples/udhcp/sample.renew b/examples/udhcp/sample.renew index ea368fc9e..4dce8486a 100755 --- a/examples/udhcp/sample.renew +++ b/examples/udhcp/sample.renew @@ -22,10 +22,14 @@ then done fi -echo -n > $RESOLV_CONF -[ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF -for i in $dns -do - echo adding dns $i - echo nameserver $i >> $RESOLV_CONF -done +# Only replace resolv.conf is we have at least one DNS server +if [ -n "$dns" ] +then + echo -n > $RESOLV_CONF + [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF + for i in $dns + do + echo adding dns $i + echo nameserver $i >> $RESOLV_CONF + done +fi -- cgit v1.2.3-55-g6feb From 891b98c9bcb0872465c1f9192b8cbc9779b8d164 Mon Sep 17 00:00:00 2001 From: Tito Ragusa Date: Fri, 17 Jan 2014 09:17:55 +0100 Subject: adduser,addgroup: introduce and use CONFIG_LAST_ID Changes adduser.c, addgroup.c and Config.src to set and use CONFIG_LAST_ID. function old new delta adduser_main 841 865 +24 addgroup_main 407 425 +18 Signed-off-by: Tito Ragusa Signed-off-by: Denys Vlasenko --- loginutils/Config.src | 11 +++++++++-- loginutils/addgroup.c | 13 +++++++------ loginutils/adduser.c | 24 +++++++++++------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/loginutils/Config.src b/loginutils/Config.src index 9bf79afee..b78d7c38e 100644 --- a/loginutils/Config.src +++ b/loginutils/Config.src @@ -118,10 +118,17 @@ config FEATURE_CHECK_NAMES For compatibility with Samba machine accounts "$" is also supported at the end of the user or group name. +config LAST_ID + int "Last valid uid or gid for adduser and addgroup" + depends on ADDUSER || ADDGROUP + default 60000 + help + Last valid uid or gid for adduser and addgroup + config FIRST_SYSTEM_ID int "First valid system uid or gid for adduser and addgroup" depends on ADDUSER || ADDGROUP - range 0 64900 + range 0 LAST_ID default 100 help First valid system uid or gid for adduser and addgroup @@ -129,7 +136,7 @@ config FIRST_SYSTEM_ID config LAST_SYSTEM_ID int "Last valid system uid or gid for adduser and addgroup" depends on ADDUSER || ADDGROUP - range 0 64900 + range FIRST_SYSTEM_ID LAST_ID default 999 help Last valid system uid or gid for adduser and addgroup diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c index b37270ff0..22cd0e661 100644 --- a/loginutils/addgroup.c +++ b/loginutils/addgroup.c @@ -22,14 +22,16 @@ #if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID #error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config #endif +#if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID +#error Bad LAST_ID or LAST_SYSTEM_ID in .config +#endif #define OPT_GID (1 << 0) #define OPT_SYSTEM_ACCOUNT (1 << 1) -/* We assume GID_T_MAX == INT_MAX */ static void xgroup_study(struct group *g) { - unsigned max = INT_MAX; + unsigned max = CONFIG_LAST_ID; /* Make sure gr_name is unused */ if (getgrnam(g->gr_name)) { @@ -46,7 +48,6 @@ static void xgroup_study(struct group *g) max = CONFIG_LAST_SYSTEM_ID; } else { g->gr_gid = CONFIG_LAST_SYSTEM_ID + 1; - max = 64999; } } /* Check if the desired gid is free @@ -125,7 +126,7 @@ int addgroup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int addgroup_main(int argc UNUSED_PARAM, char **argv) { unsigned opts; - unsigned gid = 0; + const char *gid = "0"; /* need to be root */ if (geteuid()) { @@ -139,7 +140,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv) * addgroup -g num group * addgroup user group * Check for min, max and missing args */ - opt_complementary = "-1:?2:g+"; + opt_complementary = "-1:?2"; opts = getopt32(argv, "g:S", &gid); /* move past the commandline options */ argv += optind; @@ -175,7 +176,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv) #endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */ { die_if_bad_username(argv[0]); - new_group(argv[0], gid); + new_group(argv[0], xatou_range(gid, 0, CONFIG_LAST_ID)); } /* Reached only on success */ return EXIT_SUCCESS; diff --git a/loginutils/adduser.c b/loginutils/adduser.c index ef390adf8..568a3018e 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c @@ -26,6 +26,10 @@ #if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID #error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config #endif +#if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID +#error Bad LAST_ID or LAST_SYSTEM_ID in .config +#endif + /* #define OPT_HOME (1 << 0) */ /* unused */ /* #define OPT_GECOS (1 << 1) */ /* unused */ @@ -36,12 +40,11 @@ #define OPT_DONT_MAKE_HOME (1 << 6) #define OPT_UID (1 << 7) -/* We assume UID_T_MAX == INT_MAX */ /* remix */ /* recoded such that the uid may be passed in *p */ static void passwd_study(struct passwd *p) { - int max = UINT_MAX; + int max = CONFIG_LAST_ID; if (getpwnam(p->pw_name)) { bb_error_msg_and_die("%s '%s' in use", "user", p->pw_name); @@ -54,7 +57,6 @@ static void passwd_study(struct passwd *p) max = CONFIG_LAST_SYSTEM_ID; } else { p->pw_uid = CONFIG_LAST_SYSTEM_ID + 1; - max = 64999; } } /* check for a free uid (and maybe gid) */ @@ -147,6 +149,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) const char *usegroup = NULL; char *p; unsigned opts; + char *uid; #if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS applet_long_options = adduser_longopts; @@ -164,16 +167,11 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) /* at least one and at most two non-option args */ /* disable interactive passwd for system accounts */ - 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 { - unsigned uid; - opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid); - if (opts & OPT_UID) { - pw.pw_uid = uid; - } - } + opt_complementary = "-1:?2:SD"; + opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid); + if (opts & OPT_UID) + pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID); + argv += optind; pw.pw_name = argv[0]; -- cgit v1.2.3-55-g6feb From 49111cdc4f58c844e315befb10b4b3db830eb143 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sun, 19 Jan 2014 04:29:59 +0100 Subject: gitignore: ignore files generated by 'make test' Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 0a0c65bc3..8d6d17601 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,9 @@ Config.in core .gdb_history .gdbinit + +# +# testing output +# +/busybox.links +/runtest-tempdir-links -- cgit v1.2.3-55-g6feb From 1a4d9f652169afa08680d3ff2c2cf9efa2a76a1b Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sat, 18 Jan 2014 15:25:58 +0100 Subject: sort.c: remove a magic number from compare_keys() Use bitwise OR of proper flags instead. Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- coreutils/sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coreutils/sort.c b/coreutils/sort.c index a1625fc9c..0b3b650c9 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -225,7 +225,7 @@ static int compare_keys(const void *xarg, const void *yarg) y = *(char **)yarg; #endif /* Perform actual comparison */ - switch (flags & 7) { + switch (flags & (FLAG_n | FLAG_M | FLAG_g)) { default: bb_error_msg_and_die("unknown sort type"); break; -- cgit v1.2.3-55-g6feb From 5c13ab41bb9472b792797a339f93a3a3ca62fd7a Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sun, 19 Jan 2014 09:10:14 +0100 Subject: sort: check global flags on fallback sort Sort now performs global reverse on fallback sort if -r is set. Before only key local flags were checked. function old new delta compare_keys 712 738 +26 Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- coreutils/sort.c | 8 ++++++-- testsuite/sort.tests | 3 --- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/coreutils/sort.c b/coreutils/sort.c index 0b3b650c9..1cb4c3e3f 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -302,10 +302,14 @@ static int compare_keys(const void *xarg, const void *yarg) } /* for */ /* Perform fallback sort if necessary */ - if (!retval && !(option_mask32 & FLAG_s)) + if (!retval && !(option_mask32 & FLAG_s)) { retval = strcmp(*(char **)xarg, *(char **)yarg); + flags = option_mask32; + } + + if (flags & FLAG_r) + return -retval; - if (flags & FLAG_r) return -retval; return retval; } diff --git a/testsuite/sort.tests b/testsuite/sort.tests index 91b282ea0..68fa3e405 100755 --- a/testsuite/sort.tests +++ b/testsuite/sort.tests @@ -47,8 +47,6 @@ egg 1 2 papyrus 999 3 0 algebra " "$data" "" -test x"$SKIP_KNOWN_BUGS" = x"" && { -# Busybox is definitely doing these wrong. FIXME testing "sort key range with numeric option and global reverse" \ "sort -k2,3n -r input" \ "egg 1 2 papyrus @@ -65,7 +63,6 @@ testing "sort key range with multiple options" "sort -k2,3rn input" \ 42 1 3 woot egg 1 2 papyrus " "$data" "" -} testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\ d 2 -- cgit v1.2.3-55-g6feb From 76ad7481b1697b9eb99286259395050f3169e7e8 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sat, 18 Jan 2014 15:36:27 +0100 Subject: ntpd: fix compilation warnings GCC complained about since_last_update being set but not used. Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/networking/ntpd.c b/networking/ntpd.c index c4b018778..f1f99bb2b 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1328,7 +1328,9 @@ update_local_clock(peer_t *p) #if !USING_KERNEL_PLL_LOOP double freq_drift; #endif +#if !USING_KERNEL_PLL_LOOP || USING_INITIAL_FREQ_ESTIMATION double since_last_update; +#endif double etemp, dtemp; abs_offset = fabs(offset); @@ -1356,7 +1358,9 @@ update_local_clock(peer_t *p) * action is and defines how the system reacts to large time * and frequency errors. */ +#if !USING_KERNEL_PLL_LOOP || USING_INITIAL_FREQ_ESTIMATION since_last_update = recv_time - G.reftime; +#endif #if !USING_KERNEL_PLL_LOOP freq_drift = 0; #endif -- cgit v1.2.3-55-g6feb From c009d35f0060905842c779fdf57535e0127cb238 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 20 Jan 2014 03:24:51 +0100 Subject: ntpd: remove now unnecessary check for IP_PKTINFO definition Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 3 --- networking/ntpd_simple.c | 3 --- 2 files changed, 6 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index f1f99bb2b..03fe448ca 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -51,9 +51,6 @@ #ifndef IPTOS_LOWDELAY # define IPTOS_LOWDELAY 0x10 #endif -#ifndef IP_PKTINFO -# error "Sorry, your kernel has to support IP_PKTINFO" -#endif /* Verbosity control (max level of -dddd options accepted). diff --git a/networking/ntpd_simple.c b/networking/ntpd_simple.c index 3e7fc4719..22e899cb6 100644 --- a/networking/ntpd_simple.c +++ b/networking/ntpd_simple.c @@ -11,9 +11,6 @@ #ifndef IPTOS_LOWDELAY # define IPTOS_LOWDELAY 0x10 #endif -#ifndef IP_PKTINFO -# error "Sorry, your kernel has to support IP_PKTINFO" -#endif /* Sync to peers every N secs */ -- cgit v1.2.3-55-g6feb From 2de232da53da6a79880defc5693242383af58764 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sat, 18 Jan 2014 15:36:28 +0100 Subject: top.c: fix compilation warnings pfd[1] is unused Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- procps/top.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/procps/top.c b/procps/top.c index 51f1c1aed..530f45fa1 100644 --- a/procps/top.c +++ b/procps/top.c @@ -917,17 +917,12 @@ enum { #if ENABLE_FEATURE_USE_TERMIOS static unsigned handle_input(unsigned scan_mask, unsigned interval) { - struct pollfd pfd[1]; - if (option_mask32 & OPT_EOF) { /* EOF on stdin ("top Date: Tue, 21 Jan 2014 07:58:18 +0100 Subject: libbb: fix parsing of "10101010" date/time form Signed-off-by: Denys Vlasenko --- libbb/time.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libbb/time.c b/libbb/time.c index ea2f72e3b..aa19a47d4 100644 --- a/libbb/time.c +++ b/libbb/time.c @@ -68,15 +68,23 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm) /* else end != NUL and we error out */ } } else - /* yyyy-mm-dd HH */ - if (sscanf(date_str, "%u-%u-%u %u%c", &ptm->tm_year, + if (strchr(date_str, '-') + /* Why strchr('-') check? + * sscanf below will trash ptm->tm_year, this breaks + * if parse_str is "10101010" (iow, "MMddhhmm" form) + * because we destroy year. Do these sscanf + * only if we saw a dash in parse_str. + */ + /* yyyy-mm-dd HH */ + && (sscanf(date_str, "%u-%u-%u %u%c", &ptm->tm_year, &ptm->tm_mon, &ptm->tm_mday, &ptm->tm_hour, &end) >= 4 - /* yyyy-mm-dd */ - || sscanf(date_str, "%u-%u-%u%c", &ptm->tm_year, + /* yyyy-mm-dd */ + || sscanf(date_str, "%u-%u-%u%c", &ptm->tm_year, &ptm->tm_mon, &ptm->tm_mday, &end) >= 3 + ) ) { ptm->tm_year -= 1900; /* Adjust years */ ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ -- cgit v1.2.3-55-g6feb