From: Denis Vlasenko Date: Sat, 19 Apr 2008 04:05:28 +0000 (-0000) Subject: apply all post 1.10.0 fixes X-Git-Tag: 1_10_3~4 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fc9fc1f9292861cd1621d884338a766289acdf4a;p=oweals%2Fbusybox.git apply all post 1.10.0 fixes bump version to 1.10.1 --- diff --git a/Makefile b/Makefile index 4a6031bff..e18726fca 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION = 1 PATCHLEVEL = 10 -SUBLEVEL = 0 +SUBLEVEL = 1 EXTRAVERSION = NAME = Unnamed diff --git a/coreutils/tail.c b/coreutils/tail.c index 35b25a416..2f997a9f6 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -163,8 +163,6 @@ int tail_main(int argc, char **argv) fmt = header_fmt + 1; /* Skip header leading newline on first output. */ i = 0; do { - off_t current; - if (nfiles > header_threshhold) { tail_xprint_header(fmt, argv[i]); fmt = header_fmt; @@ -173,19 +171,17 @@ int tail_main(int argc, char **argv) /* Optimizing count-bytes case if the file is seekable. * Beware of backing up too far. * Also we exclude files with size 0 (because of /proc/xxx) */ - current = lseek(fds[i], 0, SEEK_END); - if (current > 0) { - if (!from_top) { + if (COUNT_BYTES && !from_top) { + off_t current = lseek(fds[i], 0, SEEK_END); + if (current > 0) { if (count == 0) continue; /* showing zero lines is easy :) */ - if (COUNT_BYTES) { - current -= count; - if (current < 0) - current = 0; - xlseek(fds[i], current, SEEK_SET); - bb_copyfd_size(fds[i], STDOUT_FILENO, count); - continue; - } + current -= count; + if (current < 0) + current = 0; + xlseek(fds[i], current, SEEK_SET); + bb_copyfd_size(fds[i], STDOUT_FILENO, count); + continue; } } diff --git a/init/init.c b/init/init.c index c4674a55f..a6c73e3fd 100644 --- a/init/init.c +++ b/init/init.c @@ -33,14 +33,15 @@ #endif /* Allowed init action types */ -#define SYSINIT 0x001 -#define RESPAWN 0x002 -#define ASKFIRST 0x004 -#define WAIT 0x008 -#define ONCE 0x010 -#define CTRLALTDEL 0x020 -#define SHUTDOWN 0x040 -#define RESTART 0x080 +#define SYSINIT 0x01 +#define RESPAWN 0x02 +/* like respawn, but wait for to be pressed on tty: */ +#define ASKFIRST 0x04 +#define WAIT 0x08 +#define ONCE 0x10 +#define CTRLALTDEL 0x20 +#define SHUTDOWN 0x40 +#define RESTART 0x80 #define STR_SYSINIT "\x01" #define STR_RESPAWN "\x02" @@ -372,7 +373,10 @@ static pid_t run(const struct init_action *a) sigemptyset(&nmask); sigaddset(&nmask, SIGCHLD); sigprocmask(SIG_BLOCK, &nmask, &omask); - pid = vfork(); + if (BB_MMU && (a->action_type & ASKFIRST)) + pid = fork(); + else + pid = vfork(); sigprocmask(SIG_SETMASK, &omask, NULL); if (pid < 0) @@ -447,7 +451,8 @@ static pid_t run(const struct init_action *a) } #endif - /* NB: on NOMMU we can't wait for input in child */ + /* NB: on NOMMU we can't wait for input in child, so + * "askfirst" will work the same as "respawn". */ if (BB_MMU && (a->action_type & ASKFIRST)) { static const char press_enter[] ALIGN1 = #ifdef CUSTOMIZED_BANNER @@ -499,7 +504,7 @@ static void run_actions(int action_type) for (a = init_action_list; a; a = tmp) { tmp = a->next; - if (a->action_type == action_type) { + if (a->action_type & action_type) { // Pointless: run() will error out if open of device fails. ///* a->terminal of "" means "init's console" */ //if (a->terminal[0] && access(a->terminal, R_OK | W_OK)) { @@ -784,6 +789,7 @@ static void parse_inittab(void) fclose(file); } +#if ENABLE_FEATURE_USE_INITTAB static void reload_signal(int sig ATTRIBUTE_UNUSED) { struct init_action *a, *tmp; @@ -827,8 +833,9 @@ static void reload_signal(int sig ATTRIBUTE_UNUSED) delete_init_action(a); } } - run_actions(RESPAWN); + run_actions(RESPAWN | ASKFIRST); } +#endif int init_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int init_main(int argc ATTRIBUTE_UNUSED, char **argv) @@ -952,18 +959,16 @@ int init_main(int argc ATTRIBUTE_UNUSED, char **argv) run_actions(ONCE); /* Redefine SIGHUP to reread /etc/inittab */ - if (ENABLE_FEATURE_USE_INITTAB) - signal(SIGHUP, reload_signal); - else - signal(SIGHUP, SIG_IGN); +#if ENABLE_FEATURE_USE_INITTAB + signal(SIGHUP, reload_signal); +#else + signal(SIGHUP, SIG_IGN); +#endif /* Now run the looping stuff for the rest of forever */ while (1) { - /* run the respawn stuff */ - run_actions(RESPAWN); - - /* run the askfirst stuff */ - run_actions(ASKFIRST); + /* run the respawn/askfirst stuff */ + run_actions(RESPAWN | ASKFIRST); /* Don't consume all CPU time -- sleep a bit */ sleep(1); diff --git a/miscutils/less.c b/miscutils/less.c index 1a67ca7ce..37ec5d976 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -384,6 +384,10 @@ static void read_lines(void) linepos = 0; } /* end of "read lines until we reach cur_fline" loop */ fill_match_lines(old_max_fline); +#if ENABLE_FEATURE_LESS_REGEXP + /* prevent us from being stuck in search for a match */ + wanted_match = -1; +#endif #undef readbuf } @@ -904,13 +908,8 @@ static void goto_match(int match) match = 0; /* Try to find next match if eof isn't reached yet */ if (match >= num_matches && eof_error > 0) { - wanted_match = match; + wanted_match = match; /* "I want to read until I see N'th match" */ read_lines(); - if (wanted_match >= num_matches) { - /* We still failed to find it. Prevent future - * read_lines() from trying... */ - wanted_match = num_matches - 1; - } } if (num_matches) { normalize_match_pos(match); diff --git a/miscutils/taskset.c b/miscutils/taskset.c index 6247aa869..bf98ea15d 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c @@ -50,6 +50,11 @@ int taskset_main(int argc ATTRIBUTE_UNUSED, char **argv) char *pid_str; char *aff = aff; /* for compiler */ + /* NB: we mimic util-linux's taskset: -p does not take + * an argument, i.e., "-pN" is NOT valid, only "-p N"! + * Indeed, util-linux-2.13-pre7 uses: + * getopt_long(argc, argv, "+pchV", ...), not "...p:..." */ + opt_complementary = "-1"; /* at least 1 arg */ opt_p = getopt32(argv, "+p"); argv += optind; diff --git a/networking/nameif.c b/networking/nameif.c index 43388ab32..afc88917e 100644 --- a/networking/nameif.c +++ b/networking/nameif.c @@ -5,6 +5,7 @@ * Written 2000 by Andi Kleen. * Busybox port 2002 by Nick Fedchik * Glenn McGrath + * Extended matching support 2008 by Nico Erfurth * * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. */ @@ -93,12 +94,10 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector) found_selector++; } else { #endif - lmac = ether_aton(selector + (strncmp(selector, "mac=", 4) == 0 ? 4 : 0)); - /* Check ascii selector, convert and copy to *mac */ - if (lmac == NULL) + lmac = xmalloc(ETH_ALEN); + ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) ? 0 : 4), lmac); + if (ch->mac == NULL) bb_error_msg_and_die("cannot parse %s", selector); - ch->mac = xmalloc(ETH_ALEN); - memcpy(ch->mac, lmac, ETH_ALEN); #if ENABLE_FEATURE_NAMEIF_EXTENDED found_selector++; }; @@ -115,7 +114,7 @@ static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *select if (strlen(ifname) >= IF_NAMESIZE) bb_error_msg_and_die("interface name '%s' too long", ifname); ch = xzalloc(sizeof(*ch)); - ch->ifname = ifname; + ch->ifname = xstrdup(ifname); nameif_parse_selector(ch, selector); ch->next = *clist; if (*clist) @@ -123,6 +122,21 @@ static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *select *clist = ch; } +#if ENABLE_FEATURE_CLEAN_UP +static void delete_eth_table(ethtable_t *ch) +{ + free(ch->ifname); +#if ENABLE_FEATURE_NAMEIF_EXTENDED + free(ch->bus_info); + free(ch->driver); +#endif + free(ch->mac); + free(ch); +}; +#else +void delete_eth_table(ethtable_t *ch); +#endif + int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int nameif_main(int argc, char **argv) { @@ -156,14 +170,13 @@ int nameif_main(int argc, char **argv) char *next; line_ptr = skip_whitespace(line); - if ((line_ptr[0] == '#') || (line_ptr[0] == '\n')) { - free(line); - continue; - } + if ((line_ptr[0] == '#') || (line_ptr[0] == '\n')) + goto read_next_line; next = skip_non_whitespace(line_ptr); if (*next) *next++ = '\0'; prepend_new_eth_table(&clist, line_ptr, next); + read_next_line: free(line); } fclose(ifh); @@ -187,7 +200,7 @@ int nameif_main(int argc, char **argv) /* Find the current interface name and copy it to ifr.ifr_name */ line_ptr = skip_whitespace(line); - *skip_non_whitespace(line_ptr) = '\0'; + *strpbrk(line_ptr, " \t\n:") = '\0'; memset(&ifr, 0, sizeof(struct ifreq)); strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name)); @@ -230,16 +243,15 @@ int nameif_main(int argc, char **argv) else clist = ch->next; if (ch->next != NULL) - ch->next->prev = ch->prev; - if (ENABLE_FEATURE_CLEAN_UP) { - free(ch->ifname); - free(ch->mac); - free(ch); - } + ch->next->prev = ch->prev; + if (ENABLE_FEATURE_CLEAN_UP) + delete_eth_table(ch); next_line: free(line); } if (ENABLE_FEATURE_CLEAN_UP) { + for (ch = clist; ch; ch = ch->next) + delete_eth_table(ch); fclose(ifh); }; diff --git a/networking/tcpudp.c b/networking/tcpudp.c index 5da4de505..0b604af48 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c @@ -29,10 +29,10 @@ * - don't know how to retrieve ORIGDST for udp. */ -#include -#include /* wants */ - #include "libbb.h" +/* Wants etc, thus included after libbb.h: */ +#include + // TODO: move into this file: #include "tcpudp_perhost.h" diff --git a/networking/udhcp/clientsocket.c b/networking/udhcp/clientsocket.c index 0be661d4f..114200192 100644 --- a/networking/udhcp/clientsocket.c +++ b/networking/udhcp/clientsocket.c @@ -22,11 +22,11 @@ */ #include +#include #if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION) #include #include #else -#include #include #include #endif diff --git a/procps/fuser.c b/procps/fuser.c index 48c9bdc1e..fd876d559 100644 --- a/procps/fuser.c +++ b/procps/fuser.c @@ -57,11 +57,11 @@ static int file_to_dev_inode(const char *filename, dev_t *dev, ino_t *inode) static char *parse_net_arg(const char *arg, unsigned *port) { - char path[12], tproto[5]; + char path[20], tproto[5]; if (sscanf(arg, "%u/%4s", port, tproto) != 2) return NULL; - sprintf(path, "net/%s", tproto); + sprintf(path, "/proc/net/%s", tproto); if (access(path, R_OK) != 0) return NULL; return xstrdup(tproto); @@ -99,7 +99,7 @@ static inode_list *add_inode(inode_list *ilist, dev_t dev, ino_t inode) static inode_list *scan_proc_net(const char *proto, unsigned port, inode_list *ilist) { - char path[12], line[MAX_LINE + 1]; + char path[20], line[MAX_LINE + 1]; char addr[128]; ino_t tmp_inode; dev_t tmp_dev; @@ -109,7 +109,7 @@ static inode_list *scan_proc_net(const char *proto, tmp_dev = find_socket_dev(); - sprintf(path, "net/%s", proto); + sprintf(path, "/proc/net/%s", proto); f = fopen(path, "r"); if (!f) return ilist; @@ -314,8 +314,6 @@ Find processes which use FILEs or PORTs opt = getopt32(argv, OPTION_STRING); argv += optind; - xchdir("/proc"); - ilist = NULL; pp = argv; while (*pp) { diff --git a/procps/top.c b/procps/top.c index e3f91c8f9..206f9e8be 100644 --- a/procps/top.c +++ b/procps/top.c @@ -861,17 +861,22 @@ int top_main(int argc ATTRIBUTE_UNUSED, char **argv) #else qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); #endif /* FEATURE_TOP_CPU_USAGE_PERCENTAGE */ - } else { /* TOPMEM */ + } +#if ENABLE_FEATURE_TOPMEM + else { /* TOPMEM */ qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); } +#endif count = lines; if (OPT_BATCH_MODE || count > ntop) { count = ntop; } if (scan_mask == TOP_MASK) display_process_list(count, col); +#if ENABLE_FEATURE_TOPMEM else display_topmem_process_list(count, col); +#endif clearmems(); if (iterations >= 0 && !--iterations) break; diff --git a/testsuite/tail/tail-n-works b/testsuite/tail/tail-n-works index 27a905f88..e5b260caf 100644 --- a/testsuite/tail/tail-n-works +++ b/testsuite/tail/tail-n-works @@ -1,4 +1,4 @@ -[ -n "$d" ] || d=.. -tail -n 2 "$d/README" > logfile.gnu -busybox tail -n 2 "$d/README" > logfile.bb -cmp logfile.gnu logfile.bb +echo -ne "abc\ndef\n123\n" >input +echo -ne "def\n123\n" >logfile.ok +busybox tail -n 2 input > logfile.bb +cmp logfile.ok logfile.bb diff --git a/testsuite/tail/tail-works b/testsuite/tail/tail-works index 27a905f88..64e6d88ab 100644 --- a/testsuite/tail/tail-works +++ b/testsuite/tail/tail-works @@ -1,4 +1,4 @@ -[ -n "$d" ] || d=.. -tail -n 2 "$d/README" > logfile.gnu -busybox tail -n 2 "$d/README" > logfile.bb -cmp logfile.gnu logfile.bb +echo -ne "abc\ndef\n123\n" >input +echo -ne "def\n123\n" >logfile.ok +busybox tail -2 input > logfile.bb +cmp logfile.ok logfile.bb diff --git a/testsuite/taskset.tests b/testsuite/taskset.tests index 6001c3e32..a3757ab5b 100755 --- a/testsuite/taskset.tests +++ b/testsuite/taskset.tests @@ -7,8 +7,8 @@ a="taskset" # testing "test name" "opts" "expected result" "file inp" "stdin" -testing "taskset (get from pid 1)" "$a -p1 >/dev/null;echo \$?" "0\n" "" "" -testing "taskset (invalid pid)" "$a -p0 >/dev/null 2>&1;echo \$?" "1\n" "" "" +testing "taskset (get from pid 1)" "$a -p 1 >/dev/null;echo \$?" "0\n" "" "" +testing "taskset (invalid pid)" "$a -p 0 >/dev/null 2>&1;echo \$?" "1\n" "" "" testing "taskset (set_aff, needs CAP_SYS_NICE)" \ "$a 0x1 $SHELL -c $a\ -p\ \$$\|grep\ \"current\ affinity\ mask:\ 1\" >/dev/null;echo \$?" \ "0\n" "" ""