From 03718bb2743fbd772732a2c57c76c1c56fa9cd37 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 24 Feb 2016 01:22:45 +0100 Subject: ntpd: print packet delay in clock update message function old new delta update_local_clock 820 826 +6 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 1651670d9..2a96ddbd0 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1685,8 +1685,14 @@ update_local_clock(peer_t *p) 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", - p->p_dotted, offset, G.discipline_jitter, (double)tmx.freq / 65536, (int)tmx.constant); + VERB2 bb_error_msg("update from:%s offset:%+f delay:%f jitter:%f clock drift:%+.3fppm tc:%d", + p->p_dotted, + offset, + p->lastpkt_delay, + G.discipline_jitter, + (double)tmx.freq / 65536, + (int)tmx.constant + ); return 1; /* "ok to increase poll interval" */ } -- cgit v1.2.3-55-g6feb From 5fa9fefddce56fab75b2e6c88c4516e2b21d2f5a Mon Sep 17 00:00:00 2001 From: "Arnout Vandecappelle (Essensium/Mind)" Date: Sun, 14 Feb 2016 19:04:09 +0100 Subject: taskset: fix non-fancy cpuset printing on big-endian The non-fancy version of the from_cpuset uses CPU_SETSIZE as if it represents the number of bytes in the cpuset, while it is actually the number of bits. This leads to out-of-bounds accesses on the cpu_set_t in the big-endian case. Basically all uses of CPU_SETSIZE have to be divided by 8. This is done correctly in the fancy version of from_cpuset. In addition, the big-endian case is completely wrong to begin with. All standard C libraries that I know of implement cpu_set_t as an unsigned long array, so both for big and little endian, the least significant bits are in the beginning of the array. Therefore, the approach taken for the little endian case is equally valid. We only need special handling for big endian when CPU_SETSIZE is large and we use an unsigned long long to get more bits out. Signed-off-by: Arnout Vandecappelle (Essensium/Mind) Signed-off-by: Denys Vlasenko --- miscutils/taskset.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/miscutils/taskset.c b/miscutils/taskset.c index 100b1d926..fb352ab8d 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c @@ -75,27 +75,26 @@ static char *from_cpuset(cpu_set_t *mask) #define TASKSET_PRINTF_MASK "%llx" static unsigned long long from_cpuset(cpu_set_t *mask) { - char *p = (void*)mask; + BUILD_BUG_ON(CPU_SETSIZE < 8*sizeof(int)); - BUILD_BUG_ON(CPU_SETSIZE < sizeof(int)); - - /* Take the least significant bits. Careful! - * Consider both CPU_SETSIZE=4 and CPU_SETSIZE=1024 cases + /* Take the least significant bits. Assume cpu_set_t is + * implemented as an array of unsigned long or unsigned + * int. */ -#if BB_BIG_ENDIAN - /* For big endian, it means LAST bits */ - if (CPU_SETSIZE < sizeof(long)) - p += CPU_SETSIZE - sizeof(int); - else if (CPU_SETSIZE < sizeof(long long)) - p += CPU_SETSIZE - sizeof(long); - else - p += CPU_SETSIZE - sizeof(long long); -#endif - if (CPU_SETSIZE < sizeof(long)) - return *(unsigned*)p; - if (CPU_SETSIZE < sizeof(long long)) - return *(unsigned long*)p; - return *(unsigned long long*)p; + if (CPU_SETSIZE < 8*sizeof(long)) + return *(unsigned*)mask; + if (CPU_SETSIZE < 8*sizeof(long long)) + return *(unsigned long*)mask; +# if BB_BIG_ENDIAN + if (sizeof(long long) > sizeof(long)) { + /* We can put two long in the long long, but they have to + * be swapped: the least significant word comes first in the + * array */ + unsigned long *p = (void*)mask; + return p[0] + ((unsigned long long)p[1] << (8*sizeof(long))); + } +# endif + return *(unsigned long long*)mask; } #endif -- cgit v1.2.3-55-g6feb From 5bec08cebd559c906eb94b8b957afb9f0b8db338 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 26 Feb 2016 14:56:18 +0100 Subject: udhcp: trivial shrink function old new delta dname_dec 337 332 -5 Signed-off-by: Denys Vlasenko --- networking/udhcp/domain_codec.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/networking/udhcp/domain_codec.c b/networking/udhcp/domain_codec.c index c1325d8be..05cdf51e9 100644 --- a/networking/udhcp/domain_codec.c +++ b/networking/udhcp/domain_codec.c @@ -42,7 +42,7 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre) */ while (1) { /* note: "return NULL" below are leak-safe since - * dst isn't yet allocated */ + * dst isn't allocated yet */ const uint8_t *c; unsigned crtpos, retpos, depth, len; @@ -95,9 +95,8 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre) if (!dst) { /* first pass? */ /* allocate dst buffer and copy pre */ unsigned plen = strlen(pre); - ret = dst = xmalloc(plen + len); - memcpy(dst, pre, plen); - dst += plen; + ret = xmalloc(plen + len); + dst = stpcpy(ret, pre); } else { dst[len - 1] = '\0'; break; -- cgit v1.2.3-55-g6feb From 352f79acbd759c14399e39baef21fc4ffe180ac2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 26 Feb 2016 15:54:56 +0100 Subject: udhcpc: fix OPTION_6RD parsing (could overflow its malloced buffer) Signed-off-by: Denys Vlasenko --- networking/udhcp/common.c | 15 +++++++++++++-- networking/udhcp/dhcpc.c | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index bc41c8d4d..680852ce4 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c @@ -142,7 +142,7 @@ const char dhcp_option_strings[] ALIGN1 = * udhcp_str2optset: to determine how many bytes to allocate. * xmalloc_optname_optval: to estimate string length * from binary option length: (option[LEN] / dhcp_option_lengths[opt_type]) - * is the number of elements, multiply in by one element's string width + * is the number of elements, multiply it by one element's string width * (len_of_option_as_string[opt_type]) and you know how wide string you need. */ const uint8_t dhcp_option_lengths[] ALIGN1 = { @@ -162,7 +162,18 @@ const uint8_t dhcp_option_lengths[] ALIGN1 = { [OPTION_S32] = 4, /* Just like OPTION_STRING, we use minimum length here */ [OPTION_STATIC_ROUTES] = 5, - [OPTION_6RD] = 22, /* ignored by udhcp_str2optset */ + [OPTION_6RD] = 12, /* ignored by udhcp_str2optset */ + /* The above value was chosen as follows: + * len_of_option_as_string[] for this option is >60: it's a string of the form + * "32 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 ". + * Each additional ipv4 address takes 4 bytes in binary option and appends + * another "255.255.255.255 " 16-byte string. We can set [OPTION_6RD] = 4 + * but this severely overestimates string length: instead of 16 bytes, + * it adds >60 for every 4 bytes in binary option. + * We cheat and declare here that option is in units of 12 bytes. + * This adds more than 60 bytes for every three ipv4 addresses - more than enough. + * (Even 16 instead of 12 should work, but let's be paranoid). + */ }; diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 48097bc24..2fe84e1ca 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -113,7 +113,7 @@ static const uint8_t len_of_option_as_string[] = { [OPTION_IP ] = sizeof("255.255.255.255 "), [OPTION_IP_PAIR ] = sizeof("255.255.255.255 ") * 2, [OPTION_STATIC_ROUTES ] = sizeof("255.255.255.255/32 255.255.255.255 "), - [OPTION_6RD ] = sizeof("32 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 "), + [OPTION_6RD ] = sizeof("132 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 "), [OPTION_STRING ] = 1, [OPTION_STRING_HOST ] = 1, #if ENABLE_FEATURE_UDHCP_RFC3397 @@ -222,7 +222,7 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ type = optflag->flags & OPTION_TYPE_MASK; optlen = dhcp_option_lengths[type]; upper_length = len_of_option_as_string[type] - * ((unsigned)(len + optlen - 1) / (unsigned)optlen); + * ((unsigned)(len + optlen) / (unsigned)optlen); dest = ret = xmalloc(upper_length + strlen(opt_name) + 2); dest += sprintf(ret, "%s=", opt_name); -- cgit v1.2.3-55-g6feb From e5aba8871254d411766b9d04d89dcff4ded21e76 Mon Sep 17 00:00:00 2001 From: Nicolas Cavallari Date: Tue, 1 Mar 2016 18:59:08 +0100 Subject: ifupdown: allow duplicate interface definitions This patch allow to have multiple interface definitions, much like Debian's ifupdown. More specifically, it removes the check for a duplicate definition, so the impact on binary size should be fairly minimal. This configuration: iface eth0 inet static address 192.168.0.15 netmask 255.255.0.0 gateway 192.168.0.1 iface eth0 inet static address 10.0.0.1 netmask 255.255.255.0 Will add two addresses to eth0 if ip is used. If ifconfig is used, the standards methods will likely not stack, but the administrator may still use the manual method. The DHCP method may work depending on the DHCP client in use. This is a fairly advanced feature for power users who knows what they are doing. There are not many other network configuration systems that allows multiple addresses on an interface. Signed-off-by: Nicolas Cavallari Signed-off-by: Denys Vlasenko --- networking/ifupdown.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 766dfabbd..179186199 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -875,7 +875,19 @@ static struct interfaces_file_t *read_interfaces(const char *filename, struct in currif->method = get_method(currif->address_family, method_name); if (!currif->method) bb_error_msg_and_die("unknown method \"%s\"", method_name); - +#if 0 +// Allegedly, Debian allows a duplicate definition: +// iface eth0 inet static +// address 192.168.0.15 +// netmask 255.255.0.0 +// gateway 192.168.0.1 +// +// iface eth0 inet static +// address 10.0.0.1 +// netmask 255.255.255.0 +// +// This adds *two* addresses to eth0 (probably requires use of "ip", not "ifconfig" +// for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) { struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data; if ((strcmp(tmp->iface, currif->iface) == 0) @@ -884,6 +896,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename, struct in bb_error_msg_and_die("duplicate interface \"%s\"", tmp->iface); } } +#endif llist_add_to_end(&(defn->ifaces), (char*)currif); debug_noise("iface %s %s %s\n", currif->iface, address_family_name, method_name); -- cgit v1.2.3-55-g6feb From ea2b71be66b7500cc3ddaa0f617491610ff07dc4 Mon Sep 17 00:00:00 2001 From: Christian Lindeberg Date: Tue, 1 Mar 2016 19:23:22 +0100 Subject: udhcpd: keep expired leases at startup Let udhcpd retain the information about expired leases when restarting so that the leases are reserved until they possibly become the oldest expired lease. This reduces the frequency of IP address changes for example when the DHCP server and a group of clients, who do not store and request their previously offered IP address across restarts, are collectively restarted and the startup order of the clients are not guaranteed. Signed-off-by: Christian Lindeberg Signed-off-by: Denys Vlasenko --- networking/udhcp/files.c | 6 +++++- networking/udhcp/leases.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 1c8808c0f..5b90e26d2 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c @@ -195,7 +195,11 @@ void FAST_FUNC read_leases(const char *file) uint32_t static_nip; if (expires <= 0) - continue; + /* We keep expired leases: add_lease() will add + * a lease with 0 seconds remaining. + * Fewer IP address changes this way for mass reboot scenario. + */ + expires = 0; /* Check if there is a different static lease for this IP or MAC */ static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac); diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index 844bb60b1..411b74962 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c @@ -17,7 +17,9 @@ static struct dyn_lease *oldest_expired_lease(void) /* Unexpired leases have g_leases[i].expires >= current time * and therefore can't ever match */ for (i = 0; i < server_config.max_leases; i++) { - if (g_leases[i].expires < oldest_time) { + if (g_leases[i].expires == 0 /* empty entry */ + || g_leases[i].expires < oldest_time + ) { oldest_time = g_leases[i].expires; oldest_lease = &g_leases[i]; } -- cgit v1.2.3-55-g6feb From abe8f7515aded80889d78c2c1c8947997918cf90 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Thu, 18 Feb 2016 12:27:07 +0100 Subject: dhcpc: Use client IP address as source address for DHCP renew/rebind messages RFC2131 paragraph 4.1 states DHCP messages broadcast by a client prior to that client obtaining its IP address must have the source IP address field in the header set to 0. Request messages transmitted in renewing and rebinding state need to use the obtained IP address as source IP address in the header; this behavior lines up with other implementations like ISC dhcp client. Signed-off-by: Hans Dedecker Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 2fe84e1ca..6c2b112f0 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -675,10 +675,10 @@ static void add_client_options(struct dhcp_packet *packet) * client reverts to using the IP broadcast address. */ -static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet) +static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet, uint32_t src_nip) { return udhcp_send_raw_packet(packet, - /*src*/ INADDR_ANY, CLIENT_PORT, + /*src*/ src_nip, CLIENT_PORT, /*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); } @@ -689,7 +689,7 @@ static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t return udhcp_send_kernel_packet(packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); - return raw_bcast_from_client_config_ifindex(packet); + return raw_bcast_from_client_config_ifindex(packet, ciaddr); } /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ @@ -715,7 +715,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) add_client_options(&packet); bb_info_msg("Sending discover..."); - return raw_bcast_from_client_config_ifindex(&packet); + return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); } /* Broadcast a DHCP request message */ @@ -759,7 +759,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste addr.s_addr = requested; bb_info_msg("Sending select for %s...", inet_ntoa(addr)); - return raw_bcast_from_client_config_ifindex(&packet); + return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); } /* Unicast or broadcast a DHCP renew message */ @@ -827,7 +827,7 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); bb_info_msg("Sending decline..."); - return raw_bcast_from_client_config_ifindex(&packet); + return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); } #endif -- cgit v1.2.3-55-g6feb From 35e063e1b9a1d35d311859fe61a934304952d5b5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 3 Mar 2016 02:19:16 +0100 Subject: ifupdowm: fix "warning: unused variable 'iface_list'" Signed-off-by: Denys Vlasenko --- networking/ifupdown.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 179186199..2c6db926f 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -850,7 +850,6 @@ static struct interfaces_file_t *read_interfaces(const char *filename, struct in char *iface_name; char *address_family_name; char *method_name; - llist_t *iface_list; currif = xzalloc(sizeof(*currif)); iface_name = next_word(&rest_of_line); @@ -888,6 +887,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename, struct in // // This adds *two* addresses to eth0 (probably requires use of "ip", not "ifconfig" // + llist_t *iface_list; for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) { struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data; if ((strcmp(tmp->iface, currif->iface) == 0) -- cgit v1.2.3-55-g6feb From 4c48a6474701d8b396a14213ebcc979a49187faf Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 3 Mar 2016 22:01:23 +0100 Subject: ntpd: more informative poll lowering message Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 2a96ddbd0..4695c3366 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1953,8 +1953,8 @@ recv_and_process_peer_pkt(peer_t *p) adjust_poll(MINPOLL); } else { VERB3 if (rc > 0) - bb_error_msg("want smaller poll interval: offset/jitter > %u", - POLLADJ_GATE); + bb_error_msg("want smaller interval: offset/jitter = %u", + G.offset_to_jitter_ratio); adjust_poll(-G.poll_exp * 2); } } -- cgit v1.2.3-55-g6feb From f37f28199f508f5fee44753d320f044a91e76e39 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 4 Mar 2016 07:06:53 +0100 Subject: ntpd: do not use a peer more than once (say, if two peers resolve to the same IP) function old new delta add_peers 98 166 +68 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 4695c3366..517806e75 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -727,7 +727,7 @@ reset_peer_stats(peer_t *p, double offset) /* 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), + * after step (tested with suspending 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. @@ -766,11 +766,26 @@ reset_peer_stats(peer_t *p, double offset) static void add_peers(const char *s) { + llist_t *item; peer_t *p; p = xzalloc(sizeof(*p)); p->p_lsa = xhost2sockaddr(s, 123); p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa); + + /* Names like N..pool.ntp.org are randomly resolved + * to a pool of machines. Sometimes different N's resolve to the same IP. + * It is not useful to have two peers with same IP. We skip duplicates. + */ + for (item = G.ntp_peers; item != NULL; item = item->link) { + peer_t *pp = (peer_t *) item->data; + if (strcmp(p->p_dotted, pp->p_dotted) == 0) { + bb_error_msg("duplicate peer %s (%s)", s, p->p_dotted); + free(p); + return; + } + } + p->p_fd = -1; p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); p->next_action_time = G.cur_time; /* = set_next(p, 0); */ -- cgit v1.2.3-55-g6feb From c8641962e4cbde48108ddfc1c105e3320778190d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 4 Mar 2016 07:26:08 +0100 Subject: ntpd: if peer does not reply anymore, try re-resolving its hostname function old new delta ntpd_main 1053 1130 +77 add_peers 166 195 +29 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/networking/ntpd.c b/networking/ntpd.c index 517806e75..410318979 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -267,6 +267,7 @@ typedef struct { typedef struct { len_and_sockaddr *p_lsa; + char *p_hostname; char *p_dotted; int p_fd; int datapoint_idx; @@ -781,11 +782,14 @@ add_peers(const char *s) peer_t *pp = (peer_t *) item->data; if (strcmp(p->p_dotted, pp->p_dotted) == 0) { bb_error_msg("duplicate peer %s (%s)", s, p->p_dotted); + free(p->p_lsa); + free(p->p_dotted); free(p); return; } } + p->p_hostname = xstrdup(s); p->p_fd = -1; p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); p->next_action_time = G.cur_time; /* = set_next(p, 0); */ @@ -2332,6 +2336,21 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) timeout = poll_interval(NOREPLY_INTERVAL); bb_error_msg("timed out waiting for %s, reach 0x%02x, next query in %us", p->p_dotted, p->reachable_bits, timeout); + + /* What if don't see it because it changed its IP? */ + if (p->reachable_bits == 0) { + len_and_sockaddr *lsa = host2sockaddr(p->p_hostname, 123); + if (lsa) { + char *dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); + //if (strcmp(dotted, p->p_dotted) != 0) + // bb_error_msg("peer IP changed"); + free(p->p_lsa); + free(p->p_dotted); + p->p_lsa = lsa; + p->p_dotted = dotted; + } + } + set_next(p, timeout); } } -- cgit v1.2.3-55-g6feb From aee7cd82be31577c2e5c144d083af206bedbb96a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 4 Mar 2016 07:36:04 +0100 Subject: ntpd: add experimental patch Signed-off-by: Denys Vlasenko --- networking/ntpd.diff | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 networking/ntpd.diff diff --git a/networking/ntpd.diff b/networking/ntpd.diff new file mode 100644 index 000000000..4afd7e134 --- /dev/null +++ b/networking/ntpd.diff @@ -0,0 +1,24 @@ +This patch scales down small offsets quadratically. Reduces sensitivity to jitter + +diff --git a/networking/ntpd.c b/networking/ntpd.c +index 4695c33..ac05815 100644 +--- a/networking/ntpd.c ++++ b/networking/ntpd.c +@@ -1654,6 +1654,17 @@ update_local_clock(peer_t *p) + */ + if (G.offset_to_jitter_ratio >= TIMECONST_HACK_GATE) + tmx.constant--; ++ ++{ ++ double d = p->lastpkt_delay; ++ if (d > SLEW_THRESHOLD) ++ d = SLEW_THRESHOLD; ++ d /= 2; ++ if ((abs_offset / d) < 1) { ++ offset *= (abs_offset / d); ++ } ++} ++ + tmx.offset = (long)(offset * 1000000); /* usec */ + if (SLEW_THRESHOLD < STEP_THRESHOLD) { + if (tmx.offset > (long)(SLEW_THRESHOLD * 1000000)) { -- cgit v1.2.3-55-g6feb From 86d9f60f3acc4a5d755912003278267f8e6f3e89 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 4 Mar 2016 17:00:56 +0100 Subject: udhcpc: do not use -t NUM for counting "select" packets, use 3 Otherwise, "-t 0" usage may end up sending them forever if server does not respond. function old new delta udhcpc_main 2846 2836 -10 Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 6c2b112f0..dfd5ca606 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1501,7 +1501,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) packet_num = 0; continue; case REQUESTING: - if (!discover_retries || packet_num < discover_retries) { + if (packet_num < 3) { /* send broadcast select packet */ send_select(xid, server_addr, requested_ip); timeout = discover_timeout; -- cgit v1.2.3-55-g6feb From 7849ccb61c376e4704ce1c3e5a0d12fd7d743200 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Mar 2016 17:35:16 +0100 Subject: inotifyd: swap meaning of 'y' and 'm' events in help text. Closes 8726 Signed-off-by: Denys Vlasenko --- miscutils/inotifyd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miscutils/inotifyd.c b/miscutils/inotifyd.c index 7a1a6a2e5..908d657fd 100644 --- a/miscutils/inotifyd.c +++ b/miscutils/inotifyd.c @@ -47,8 +47,8 @@ //usage: "\n o Event queue overflowed" //usage: "\n x File can't be watched anymore" //usage: "\nIf watching a directory:" -//usage: "\n m Subfile is moved into dir" -//usage: "\n y Subfile is moved out of dir" +//usage: "\n y Subfile is moved into dir" +//usage: "\n m Subfile is moved out of dir" //usage: "\n n Subfile is created" //usage: "\n d Subfile is deleted" //usage: "\n" -- cgit v1.2.3-55-g6feb From ea351b97428f7dc921d5431ccac366201754fcef Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Mar 2016 17:53:11 +0100 Subject: ls: fix columnar output. Closes 8731 In coreutils/ls.c, 1.19 introduced commit 2f7d9e8903029b1b5e51a15f9cb0dcb6ca17c3ac, removing the variable tabstops and hard coding the column separation to 2 characters, but was not done correctly. The column_width assumes a gap of 1 character, so the computed number of columns exceeds the terminal width when many small files are encountered. A minor problem but surprisingly annoying. Signed-off-by: Denys Vlasenko --- coreutils/ls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coreutils/ls.c b/coreutils/ls.c index c48498858..20bd61860 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -668,7 +668,7 @@ static void display_files(struct dnode **dn, unsigned nfiles) if (column_width < len) column_width = len; } - column_width += 1 + + column_width += 2 + IF_SELINUX( ((G.all_fmt & LIST_CONTEXT) ? 33 : 0) + ) ((G.all_fmt & LIST_INO) ? 8 : 0) + ((G.all_fmt & LIST_BLOCKS) ? 5 : 0); @@ -696,8 +696,8 @@ static void display_files(struct dnode **dn, unsigned nfiles) if (i < nfiles) { if (column > 0) { nexttab -= column; - printf("%*s ", nexttab, ""); - column += nexttab + 1; + printf("%*s", nexttab, ""); + column += nexttab; } nexttab = column + column_width; column += display_single(dn[i]); -- cgit v1.2.3-55-g6feb From d2b820b540ada43dfef8751328c158e342387304 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Mar 2016 15:21:54 +0100 Subject: renice: tweak help text Signed-off-by: Denys Vlasenko --- procps/renice.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/procps/renice.c b/procps/renice.c index 77f400a1d..2b690e0ed 100644 --- a/procps/renice.c +++ b/procps/renice.c @@ -20,13 +20,14 @@ */ //usage:#define renice_trivial_usage -//usage: "{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]" +//usage: "[-n] PRIORITY [[-p | -g | -u] ID...]..." //usage:#define renice_full_usage "\n\n" -//usage: "Change scheduling priority for a running process\n" -//usage: "\n -n Adjust current nice value (smaller is faster)" -//usage: "\n -p Process id(s) (default)" -//usage: "\n -g Process group id(s)" -//usage: "\n -u Process user name(s) and/or id(s)" +//usage: "Change scheduling priority of a running process\n" +//usage: "\n -n Add PRIORITY to current nice value" +//usage: "\n Without -n, nice value is set to PRIORITY" +//usage: "\n -p Process ids (default)" +//usage: "\n -g Process group ids" +//usage: "\n -u Process user names" #include "libbb.h" #include -- cgit v1.2.3-55-g6feb From d474ffc68290e0a83651c4432eeabfa62cd51e87 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 10 Mar 2016 11:47:58 +0100 Subject: udhcp: fix a SEGV on malformed RFC1035-encoded domain name Signed-off-by: Denys Vlasenko --- networking/udhcp/domain_codec.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/networking/udhcp/domain_codec.c b/networking/udhcp/domain_codec.c index 05cdf51e9..cee31f14d 100644 --- a/networking/udhcp/domain_codec.c +++ b/networking/udhcp/domain_codec.c @@ -63,11 +63,10 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre) if (crtpos + *c + 1 > clen) /* label too long? abort */ return NULL; if (dst) - memcpy(dst + len, c + 1, *c); + /* \3com ---> "com." */ + ((char*)mempcpy(dst + len, c + 1, *c))[0] = '.'; len += *c + 1; crtpos += *c + 1; - if (dst) - dst[len - 1] = '.'; } else { /* NUL: end of current domain name */ if (retpos == 0) { @@ -78,7 +77,10 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre) crtpos = retpos; retpos = depth = 0; } - if (dst) + if (dst && len != 0) + /* \4host\3com\0\4host and we are at \0: + * \3com was converted to "com.", change dot to space. + */ dst[len - 1] = ' '; } @@ -227,6 +229,9 @@ int main(int argc, char **argv) int len; uint8_t *encoded; + uint8_t str[6] = { 0x00, 0x00, 0x02, 0x65, 0x65, 0x00 }; + printf("NUL:'%s'\n", dname_dec(str, 6, "")); + #define DNAME_DEC(encoded,pre) dname_dec((uint8_t*)(encoded), sizeof(encoded), (pre)) printf("'%s'\n", DNAME_DEC("\4host\3com\0", "test1:")); printf("test2:'%s'\n", DNAME_DEC("\4host\3com\0\4host\3com\0", "")); -- cgit v1.2.3-55-g6feb From 1b7c17391de66502dd7a97c866e0a33681edbb1f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 11 Mar 2016 00:26:58 +0100 Subject: udhcpc: fix a warning in debug code Signed-off-by: Denys Vlasenko --- networking/udhcp/domain_codec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/networking/udhcp/domain_codec.c b/networking/udhcp/domain_codec.c index cee31f14d..5a923cc2c 100644 --- a/networking/udhcp/domain_codec.c +++ b/networking/udhcp/domain_codec.c @@ -7,6 +7,7 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ #ifdef DNS_COMPR_TESTING +# define _GNU_SOURCE # define FAST_FUNC /* nothing */ # define xmalloc malloc # include -- cgit v1.2.3-55-g6feb From dbb58a3879c2daa3e286a8cd9da7935e264f3072 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Mar 2016 18:23:33 +0100 Subject: fixes for problems found by bionic build Signed-off-by: Denys Vlasenko --- include/libbb.h | 20 ++++++++++++-------- miscutils/eject.c | 26 ++++++++++++++++---------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index d05ac2976..8b226c00c 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -142,14 +142,18 @@ # include #else # include -# if !defined(__socklen_t_defined) && !defined(_SOCKLEN_T_DECLARED) -/* We #define socklen_t *after* includes, otherwise we get - * typedef redefinition errors from system headers - * (in case "is it defined already" detection above failed) - */ -# define socklen_t bb_socklen_t - typedef unsigned socklen_t; -# endif +//This breaks on bionic: +//# if !defined(__socklen_t_defined) && !defined(_SOCKLEN_T_DECLARED) +///* We #define socklen_t *after* includes, otherwise we get +// * typedef redefinition errors from system headers +// * (in case "is it defined already" detection above failed) +// */ +//# define socklen_t bb_socklen_t +// typedef unsigned socklen_t; +//# endif +//if this is still needed, add a fix along the lines of +// ifdef SPECIFIC_BROKEN_LIBC_CHECK / typedef socklen_t / endif +//in platform.h instead! #endif #ifndef HAVE_CLEARENV # define clearenv() do { if (environ) environ[0] = NULL; } while (0) diff --git a/miscutils/eject.c b/miscutils/eject.c index a20e04b7f..15eaf556d 100644 --- a/miscutils/eject.c +++ b/miscutils/eject.c @@ -25,23 +25,19 @@ #include #include "libbb.h" +#if ENABLE_FEATURE_EJECT_SCSI /* Must be after libbb.h: they need size_t */ -#include "fix_u32.h" -#include -#include - -/* various defines swiped from linux/cdrom.h */ -#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ -#define CDROMEJECT 0x5309 /* Ejects the cdrom media */ -#define CDROM_DRIVE_STATUS 0x5326 /* Get tray position, etc. */ -/* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ -#define CDS_TRAY_OPEN 2 +# include "fix_u32.h" +# include +# include +#endif #define dev_fd 3 /* Code taken from the original eject (http://eject.sourceforge.net/), * refactored it a bit for busybox (ne-bb@nicoerfurth.de) */ +#if ENABLE_FEATURE_EJECT_SCSI static void eject_scsi(const char *dev) { static const char sg_commands[3][6] = { @@ -76,6 +72,16 @@ static void eject_scsi(const char *dev) /* force kernel to reread partition table when new disc is inserted */ ioctl(dev_fd, BLKRRPART); } +#else +# define eject_scsi() ((void)0) +#endif + +/* various defines swiped from linux/cdrom.h */ +#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ +#define CDROMEJECT 0x5309 /* Ejects the cdrom media */ +#define CDROM_DRIVE_STATUS 0x5326 /* Get tray position, etc. */ +/* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ +#define CDS_TRAY_OPEN 2 #define FLAG_CLOSE 1 #define FLAG_SMART 2 -- cgit v1.2.3-55-g6feb From 23961b2fd39d1c8e8d623c15fc12dc7b1b91a1be Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Mar 2016 19:34:15 +0100 Subject: more bionic fixes Signed-off-by: Denys Vlasenko --- miscutils/eject.c | 2 +- util-linux/minix.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/miscutils/eject.c b/miscutils/eject.c index 15eaf556d..e33d79127 100644 --- a/miscutils/eject.c +++ b/miscutils/eject.c @@ -73,7 +73,7 @@ static void eject_scsi(const char *dev) ioctl(dev_fd, BLKRRPART); } #else -# define eject_scsi() ((void)0) +# define eject_scsi(dev) ((void)0) #endif /* various defines swiped from linux/cdrom.h */ diff --git a/util-linux/minix.h b/util-linux/minix.h index e0fbcf761..83ffe6da5 100644 --- a/util-linux/minix.h +++ b/util-linux/minix.h @@ -61,9 +61,14 @@ enum { MINIX_ROOT_INO = 1, MINIX_BAD_INO = 2, +#undef MINIX1_SUPER_MAGIC MINIX1_SUPER_MAGIC = 0x137F, /* original minix fs */ +#undef MINIX1_SUPER_MAGIC2 MINIX1_SUPER_MAGIC2 = 0x138F, /* minix fs, 30 char names */ +/* bionic has this define */ +#undef MINIX2_SUPER_MAGIC MINIX2_SUPER_MAGIC = 0x2468, /* minix V2 fs */ +#undef MINIX2_SUPER_MAGIC2 MINIX2_SUPER_MAGIC2 = 0x2478, /* minix V2 fs, 30 char names */ MINIX_VALID_FS = 0x0001, /* clean fs */ MINIX_ERROR_FS = 0x0002, /* fs has errors */ -- cgit v1.2.3-55-g6feb From fd5a2b7b0441495fa520cfc938818cd1555a8129 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Mar 2016 22:28:53 +0100 Subject: New example config: android_502_defconfig Signed-off-by: Denys Vlasenko --- configs/android_502_defconfig | 1142 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1142 insertions(+) create mode 100644 configs/android_502_defconfig diff --git a/configs/android_502_defconfig b/configs/android_502_defconfig new file mode 100644 index 000000000..c5146c719 --- /dev/null +++ b/configs/android_502_defconfig @@ -0,0 +1,1142 @@ +## This config was successfully used to build busybox on +## Samsung SM-T700 tablet +## Android 5.0.2 +## gcc/toolchain from https://termux.com/ +## binutils 2.26.20160125 +## gcc 4.9.3 +## bionic ANDROID_API 21 +## +## Static build did not work (static libraries not installed?): +## # CONFIG_STATIC is not set +## syslog() requires an additional library: +## CONFIG_EXTRA_LDLIBS="log" +## Bionic's botched off_t: +## # CONFIG_LFS is not set +## +## Incompatible password database API: +## # CONFIG_FEATURE_SHADOWPASSWDS is not set +## # CONFIG_USE_BB_PWD_GRP is not set +## # CONFIG_USE_BB_SHADOW is not set +## # CONFIG_ADDUSER is not set +## # CONFIG_ADDGROUP is not set +## # CONFIG_DELUSER is not set +## # CONFIG_DELGROUP is not set +## +## No utmp/wtmp: +## # CONFIG_FEATURE_UTMP is not set +## # CONFIG_FEATURE_WTMP is not set +## # CONFIG_WHO is not set +## # CONFIG_LAST is not set +## # CONFIG_USERS is not set +## # CONFIG_WALL is not set +## +## Assorted header problems: +## # CONFIG_HOSTID is not set +## # CONFIG_FEATURE_SYNC_FANCY is not set - syncfs() +## # CONFIG_FEATURE_TOUCH_NODEREF is not set - lutimes() +## # CONFIG_LOGNAME is not set - getlogin_r() +## # CONFIG_LOADFONT is not set +## # CONFIG_SETFONT is not set +## # CONFIG_MDEV is not set +## # CONFIG_FSCK_MINIX is not set +## # CONFIG_MKFS_MINIX is not set +## # CONFIG_IPCRM is not set +## # CONFIG_IPCS is not set +## # CONFIG_SWAPONOFF is not set +## # CONFIG_CONSPY is not set +## # CONFIG_NANDWRITE is not set +## # CONFIG_NANDDUMP is not set +## # CONFIG_RFKILL is not set +## # CONFIG_UBIATTACH is not set +## # CONFIG_UBIDETACH is not set +## # CONFIG_UBIMKVOL is not set +## # CONFIG_UBIRMVOL is not set +## # CONFIG_UBIRSVOL is not set +## # CONFIG_UBIUPDATEVOL is not set +## # CONFIG_FEATURE_EJECT_SCSI is not set - scsi headers +## # CONFIG_ARP is not set +## # CONFIG_ARPING is not set +## # CONFIG_ETHER_WAKE is not set +## # CONFIG_IFCONFIG is not set +## # CONFIG_IFENSLAVE is not set +## # CONFIG_NSLOOKUP is not set +## # CONFIG_ROUTE is not set +## # CONFIG_ZCIP is not set +## # CONFIG_HUSH is not set - glob.h +## # CONFIG_KLOGD is not set +## # CONFIG_LOGGER is not set +## # CONFIG_LOGREAD is not set +## # CONFIG_SYSLOGD is not set +##----------------------------------------------- + +# +# Automatically generated make config: don't edit +# Busybox version: 1.25.0.git +# Mon Mar 14 20:43:42 2016 +# +CONFIG_HAVE_DOT_CONFIG=y + +# +# Busybox Settings +# + +# +# General Configuration +# +CONFIG_DESKTOP=y +# CONFIG_EXTRA_COMPAT is not set +CONFIG_INCLUDE_SUSv2=y +# CONFIG_USE_PORTABLE_CODE is not set +CONFIG_PLATFORM_LINUX=y +CONFIG_FEATURE_BUFFERS_USE_MALLOC=y +# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set +# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set +CONFIG_SHOW_USAGE=y +CONFIG_FEATURE_VERBOSE_USAGE=y +CONFIG_FEATURE_COMPRESS_USAGE=y +CONFIG_FEATURE_INSTALLER=y +# CONFIG_INSTALL_NO_USR is not set +# CONFIG_LOCALE_SUPPORT is not set +CONFIG_UNICODE_SUPPORT=y +# CONFIG_UNICODE_USING_LOCALE is not set +# CONFIG_FEATURE_CHECK_UNICODE_IN_ENV is not set +CONFIG_SUBST_WCHAR=63 +CONFIG_LAST_SUPPORTED_WCHAR=767 +# CONFIG_UNICODE_COMBINING_WCHARS is not set +# CONFIG_UNICODE_WIDE_WCHARS is not set +# CONFIG_UNICODE_BIDI_SUPPORT is not set +# CONFIG_UNICODE_NEUTRAL_TABLE is not set +# CONFIG_UNICODE_PRESERVE_BROKEN is not set +# CONFIG_PAM is not set +CONFIG_FEATURE_USE_SENDFILE=y +CONFIG_LONG_OPTS=y +CONFIG_FEATURE_DEVPTS=y +# CONFIG_FEATURE_CLEAN_UP is not set +# CONFIG_FEATURE_UTMP is not set +# CONFIG_FEATURE_WTMP is not set +CONFIG_FEATURE_PIDFILE=y +CONFIG_PID_FILE_PATH="/var/run" +CONFIG_FEATURE_SUID=y +CONFIG_FEATURE_SUID_CONFIG=y +CONFIG_FEATURE_SUID_CONFIG_QUIET=y +# CONFIG_SELINUX is not set +# CONFIG_FEATURE_PREFER_APPLETS is not set +CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe" +CONFIG_FEATURE_SYSLOG=y +# CONFIG_FEATURE_HAVE_RPC is not set + +# +# Build Options +# +# CONFIG_STATIC is not set +# CONFIG_PIE is not set +# CONFIG_NOMMU is not set +# CONFIG_BUILD_LIBBUSYBOX is not set +# CONFIG_FEATURE_INDIVIDUAL is not set +# CONFIG_FEATURE_SHARED_BUSYBOX is not set +# CONFIG_LFS is not set +CONFIG_CROSS_COMPILER_PREFIX="" +CONFIG_SYSROOT="" +CONFIG_EXTRA_CFLAGS="" +CONFIG_EXTRA_LDFLAGS="" +CONFIG_EXTRA_LDLIBS="log" + +# +# Debugging Options +# +# CONFIG_DEBUG is not set +# CONFIG_DEBUG_PESSIMIZE is not set +# CONFIG_DEBUG_SANITIZE is not set +# CONFIG_UNIT_TEST is not set +# CONFIG_WERROR is not set +CONFIG_NO_DEBUG_LIB=y +# CONFIG_DMALLOC is not set +# CONFIG_EFENCE is not set + +# +# Installation Options ("make install" behavior) +# +CONFIG_INSTALL_APPLET_SYMLINKS=y +# CONFIG_INSTALL_APPLET_HARDLINKS is not set +# CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set +# CONFIG_INSTALL_APPLET_DONT is not set +# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set +# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set +# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set +CONFIG_PREFIX="./_install" + +# +# Busybox Library Tuning +# +CONFIG_FEATURE_RTMINMAX=y +CONFIG_PASSWORD_MINLEN=6 +CONFIG_MD5_SMALL=1 +CONFIG_SHA3_SMALL=1 +# CONFIG_FEATURE_FAST_TOP is not set +# CONFIG_FEATURE_ETC_NETWORKS is not set +CONFIG_FEATURE_USE_TERMIOS=y +CONFIG_FEATURE_EDITING=y +CONFIG_FEATURE_EDITING_MAX_LEN=1024 +# CONFIG_FEATURE_EDITING_VI is not set +CONFIG_FEATURE_EDITING_HISTORY=255 +CONFIG_FEATURE_EDITING_SAVEHISTORY=y +# CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is not set +CONFIG_FEATURE_REVERSE_SEARCH=y +CONFIG_FEATURE_TAB_COMPLETION=y +# CONFIG_FEATURE_USERNAME_COMPLETION is not set +CONFIG_FEATURE_EDITING_FANCY_PROMPT=y +# CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set +CONFIG_FEATURE_NON_POSIX_CP=y +# CONFIG_FEATURE_VERBOSE_CP_MESSAGE is not set +CONFIG_FEATURE_COPYBUF_KB=4 +CONFIG_FEATURE_SKIP_ROOTFS=y +CONFIG_MONOTONIC_SYSCALL=y +CONFIG_IOCTL_HEX2STR_ERROR=y +CONFIG_FEATURE_HWIB=y + +# +# Applets +# + +# +# Archival Utilities +# +CONFIG_FEATURE_SEAMLESS_XZ=y +CONFIG_FEATURE_SEAMLESS_LZMA=y +CONFIG_FEATURE_SEAMLESS_BZ2=y +CONFIG_FEATURE_SEAMLESS_GZ=y +# CONFIG_FEATURE_SEAMLESS_Z is not set +# CONFIG_AR is not set +# CONFIG_FEATURE_AR_LONG_FILENAMES is not set +# CONFIG_FEATURE_AR_CREATE is not set +# CONFIG_UNCOMPRESS is not set +CONFIG_GUNZIP=y +CONFIG_FEATURE_GUNZIP_LONG_OPTIONS=y +CONFIG_BUNZIP2=y +CONFIG_UNLZMA=y +# CONFIG_FEATURE_LZMA_FAST is not set +CONFIG_LZMA=y +CONFIG_UNXZ=y +CONFIG_XZ=y +CONFIG_BZIP2=y +CONFIG_CPIO=y +CONFIG_FEATURE_CPIO_O=y +CONFIG_FEATURE_CPIO_P=y +# CONFIG_DPKG is not set +# CONFIG_DPKG_DEB is not set +# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set +CONFIG_GZIP=y +CONFIG_FEATURE_GZIP_LONG_OPTIONS=y +CONFIG_GZIP_FAST=0 +# CONFIG_FEATURE_GZIP_LEVELS is not set +CONFIG_LZOP=y +# CONFIG_LZOP_COMPR_HIGH is not set +CONFIG_RPM=y +CONFIG_RPM2CPIO=y +CONFIG_TAR=y +CONFIG_FEATURE_TAR_CREATE=y +CONFIG_FEATURE_TAR_AUTODETECT=y +CONFIG_FEATURE_TAR_FROM=y +CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y +CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY=y +CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y +CONFIG_FEATURE_TAR_LONG_OPTIONS=y +CONFIG_FEATURE_TAR_TO_COMMAND=y +CONFIG_FEATURE_TAR_UNAME_GNAME=y +CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y +# CONFIG_FEATURE_TAR_SELINUX is not set +CONFIG_UNZIP=y + +# +# Coreutils +# +CONFIG_BASENAME=y +CONFIG_CAT=y +CONFIG_DATE=y +CONFIG_FEATURE_DATE_ISOFMT=y +# CONFIG_FEATURE_DATE_NANO is not set +CONFIG_FEATURE_DATE_COMPAT=y +CONFIG_DD=y +CONFIG_FEATURE_DD_SIGNAL_HANDLING=y +CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y +CONFIG_FEATURE_DD_IBS_OBS=y +CONFIG_FEATURE_DD_STATUS=y +# CONFIG_HOSTID is not set +CONFIG_ID=y +CONFIG_GROUPS=y +CONFIG_SHUF=y +CONFIG_STAT=y +CONFIG_FEATURE_STAT_FORMAT=y +CONFIG_FEATURE_STAT_FILESYSTEM=y +CONFIG_SYNC=y +# CONFIG_FEATURE_SYNC_FANCY is not set +CONFIG_TEST=y +CONFIG_FEATURE_TEST_64=y +CONFIG_TOUCH=y +# CONFIG_FEATURE_TOUCH_NODEREF is not set +CONFIG_FEATURE_TOUCH_SUSV3=y +CONFIG_TR=y +CONFIG_FEATURE_TR_CLASSES=y +CONFIG_FEATURE_TR_EQUIV=y +CONFIG_TRUNCATE=y +CONFIG_UNLINK=y +CONFIG_BASE64=y +# CONFIG_WHO is not set +# CONFIG_USERS is not set +CONFIG_CAL=y +CONFIG_CATV=y +CONFIG_CHGRP=y +CONFIG_CHMOD=y +CONFIG_CHOWN=y +CONFIG_FEATURE_CHOWN_LONG_OPTIONS=y +CONFIG_CHROOT=y +CONFIG_CKSUM=y +CONFIG_COMM=y +CONFIG_CP=y +CONFIG_FEATURE_CP_LONG_OPTIONS=y +CONFIG_CUT=y +CONFIG_DF=y +CONFIG_FEATURE_DF_FANCY=y +CONFIG_DIRNAME=y +CONFIG_DOS2UNIX=y +CONFIG_UNIX2DOS=y +CONFIG_DU=y +CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y +CONFIG_ECHO=y +CONFIG_FEATURE_FANCY_ECHO=y +CONFIG_ENV=y +CONFIG_FEATURE_ENV_LONG_OPTIONS=y +CONFIG_EXPAND=y +CONFIG_FEATURE_EXPAND_LONG_OPTIONS=y +CONFIG_EXPR=y +CONFIG_EXPR_MATH_SUPPORT_64=y +CONFIG_FALSE=y +CONFIG_FOLD=y +CONFIG_FSYNC=y +CONFIG_HEAD=y +CONFIG_FEATURE_FANCY_HEAD=y +CONFIG_INSTALL=y +CONFIG_FEATURE_INSTALL_LONG_OPTIONS=y +CONFIG_LN=y +# CONFIG_LOGNAME is not set +CONFIG_LS=y +CONFIG_FEATURE_LS_FILETYPES=y +CONFIG_FEATURE_LS_FOLLOWLINKS=y +CONFIG_FEATURE_LS_RECURSIVE=y +CONFIG_FEATURE_LS_SORTFILES=y +CONFIG_FEATURE_LS_TIMESTAMPS=y +CONFIG_FEATURE_LS_USERNAME=y +CONFIG_FEATURE_LS_COLOR=y +CONFIG_FEATURE_LS_COLOR_IS_DEFAULT=y +CONFIG_MD5SUM=y +CONFIG_MKDIR=y +CONFIG_FEATURE_MKDIR_LONG_OPTIONS=y +CONFIG_MKFIFO=y +CONFIG_MKNOD=y +CONFIG_MV=y +CONFIG_FEATURE_MV_LONG_OPTIONS=y +CONFIG_NICE=y +CONFIG_NOHUP=y +CONFIG_OD=y +CONFIG_PRINTENV=y +CONFIG_PRINTF=y +CONFIG_PWD=y +CONFIG_READLINK=y +CONFIG_FEATURE_READLINK_FOLLOW=y +CONFIG_REALPATH=y +CONFIG_RM=y +CONFIG_RMDIR=y +CONFIG_FEATURE_RMDIR_LONG_OPTIONS=y +CONFIG_SEQ=y +CONFIG_SHA1SUM=y +CONFIG_SHA256SUM=y +CONFIG_SHA512SUM=y +CONFIG_SHA3SUM=y +CONFIG_SLEEP=y +CONFIG_FEATURE_FANCY_SLEEP=y +CONFIG_FEATURE_FLOAT_SLEEP=y +CONFIG_SORT=y +CONFIG_FEATURE_SORT_BIG=y +CONFIG_SPLIT=y +CONFIG_FEATURE_SPLIT_FANCY=y +CONFIG_STTY=y +CONFIG_SUM=y +CONFIG_TAC=y +CONFIG_TAIL=y +CONFIG_FEATURE_FANCY_TAIL=y +CONFIG_TEE=y +CONFIG_FEATURE_TEE_USE_BLOCK_IO=y +CONFIG_TRUE=y +CONFIG_TTY=y +CONFIG_UNAME=y +CONFIG_UNAME_OSNAME="GNU/Linux" +CONFIG_UNEXPAND=y +CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS=y +CONFIG_UNIQ=y +CONFIG_USLEEP=y +CONFIG_UUDECODE=y +CONFIG_UUENCODE=y +CONFIG_WC=y +CONFIG_FEATURE_WC_LARGE=y +CONFIG_WHOAMI=y +CONFIG_YES=y + +# +# Common options +# +CONFIG_FEATURE_VERBOSE=y + +# +# Common options for cp and mv +# +CONFIG_FEATURE_PRESERVE_HARDLINKS=y + +# +# Common options for ls, more and telnet +# +CONFIG_FEATURE_AUTOWIDTH=y + +# +# Common options for df, du, ls +# +CONFIG_FEATURE_HUMAN_READABLE=y + +# +# Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum +# +CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y + +# +# Console Utilities +# +CONFIG_CHVT=y +CONFIG_FGCONSOLE=y +CONFIG_CLEAR=y +CONFIG_DEALLOCVT=y +CONFIG_DUMPKMAP=y +CONFIG_KBD_MODE=y +# CONFIG_LOADFONT is not set +CONFIG_LOADKMAP=y +CONFIG_OPENVT=y +CONFIG_RESET=y +CONFIG_RESIZE=y +CONFIG_FEATURE_RESIZE_PRINT=y +CONFIG_SETCONSOLE=y +CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS=y +# CONFIG_SETFONT is not set +# CONFIG_FEATURE_SETFONT_TEXTUAL_MAP is not set +CONFIG_DEFAULT_SETFONT_DIR="" +CONFIG_SETKEYCODES=y +CONFIG_SETLOGCONS=y +CONFIG_SHOWKEY=y +# CONFIG_FEATURE_LOADFONT_PSF2 is not set +# CONFIG_FEATURE_LOADFONT_RAW is not set + +# +# Debian Utilities +# +CONFIG_MKTEMP=y +CONFIG_PIPE_PROGRESS=y +CONFIG_RUN_PARTS=y +CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS=y +CONFIG_FEATURE_RUN_PARTS_FANCY=y +CONFIG_START_STOP_DAEMON=y +CONFIG_FEATURE_START_STOP_DAEMON_FANCY=y +CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS=y +CONFIG_WHICH=y + +# +# Editors +# +CONFIG_AWK=y +CONFIG_FEATURE_AWK_LIBM=y +CONFIG_FEATURE_AWK_GNU_EXTENSIONS=y +CONFIG_CMP=y +CONFIG_DIFF=y +CONFIG_FEATURE_DIFF_LONG_OPTIONS=y +CONFIG_FEATURE_DIFF_DIR=y +CONFIG_ED=y +CONFIG_PATCH=y +CONFIG_SED=y +CONFIG_VI=y +CONFIG_FEATURE_VI_MAX_LEN=4096 +# CONFIG_FEATURE_VI_8BIT is not set +CONFIG_FEATURE_VI_COLON=y +CONFIG_FEATURE_VI_YANKMARK=y +CONFIG_FEATURE_VI_SEARCH=y +# CONFIG_FEATURE_VI_REGEX_SEARCH is not set +CONFIG_FEATURE_VI_USE_SIGNALS=y +CONFIG_FEATURE_VI_DOT_CMD=y +CONFIG_FEATURE_VI_READONLY=y +CONFIG_FEATURE_VI_SETOPTS=y +CONFIG_FEATURE_VI_SET=y +CONFIG_FEATURE_VI_WIN_RESIZE=y +CONFIG_FEATURE_VI_ASK_TERMINAL=y +CONFIG_FEATURE_VI_UNDO=y +CONFIG_FEATURE_VI_UNDO_QUEUE=y +CONFIG_FEATURE_VI_UNDO_QUEUE_MAX=256 +CONFIG_FEATURE_ALLOW_EXEC=y + +# +# Finding Utilities +# +CONFIG_FIND=y +CONFIG_FEATURE_FIND_PRINT0=y +CONFIG_FEATURE_FIND_MTIME=y +CONFIG_FEATURE_FIND_MMIN=y +CONFIG_FEATURE_FIND_PERM=y +CONFIG_FEATURE_FIND_TYPE=y +CONFIG_FEATURE_FIND_XDEV=y +CONFIG_FEATURE_FIND_MAXDEPTH=y +CONFIG_FEATURE_FIND_NEWER=y +CONFIG_FEATURE_FIND_INUM=y +CONFIG_FEATURE_FIND_EXEC=y +CONFIG_FEATURE_FIND_EXEC_PLUS=y +CONFIG_FEATURE_FIND_USER=y +CONFIG_FEATURE_FIND_GROUP=y +CONFIG_FEATURE_FIND_NOT=y +CONFIG_FEATURE_FIND_DEPTH=y +CONFIG_FEATURE_FIND_PAREN=y +CONFIG_FEATURE_FIND_SIZE=y +CONFIG_FEATURE_FIND_PRUNE=y +CONFIG_FEATURE_FIND_DELETE=y +CONFIG_FEATURE_FIND_PATH=y +CONFIG_FEATURE_FIND_REGEX=y +# CONFIG_FEATURE_FIND_CONTEXT is not set +CONFIG_FEATURE_FIND_LINKS=y +CONFIG_GREP=y +CONFIG_FEATURE_GREP_EGREP_ALIAS=y +CONFIG_FEATURE_GREP_FGREP_ALIAS=y +CONFIG_FEATURE_GREP_CONTEXT=y +CONFIG_XARGS=y +CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y +CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y +CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y +CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y +CONFIG_FEATURE_XARGS_SUPPORT_REPL_STR=y + +# +# Init Utilities +# +CONFIG_BOOTCHARTD=y +CONFIG_FEATURE_BOOTCHARTD_BLOATED_HEADER=y +CONFIG_FEATURE_BOOTCHARTD_CONFIG_FILE=y +CONFIG_HALT=y +# CONFIG_FEATURE_CALL_TELINIT is not set +CONFIG_TELINIT_PATH="" +CONFIG_INIT=y +CONFIG_FEATURE_USE_INITTAB=y +# CONFIG_FEATURE_KILL_REMOVED is not set +CONFIG_FEATURE_KILL_DELAY=0 +CONFIG_FEATURE_INIT_SCTTY=y +CONFIG_FEATURE_INIT_SYSLOG=y +CONFIG_FEATURE_EXTRA_QUIET=y +CONFIG_FEATURE_INIT_COREDUMPS=y +CONFIG_FEATURE_INITRD=y +CONFIG_INIT_TERMINAL_TYPE="linux" +CONFIG_FEATURE_INIT_MODIFY_CMDLINE=y +CONFIG_MESG=y +CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y + +# +# Login/Password Management Utilities +# +# CONFIG_FEATURE_SHADOWPASSWDS is not set +# CONFIG_USE_BB_PWD_GRP is not set +# CONFIG_USE_BB_SHADOW is not set +CONFIG_USE_BB_CRYPT=y +CONFIG_USE_BB_CRYPT_SHA=y +CONFIG_ADD_SHELL=y +CONFIG_REMOVE_SHELL=y +# CONFIG_ADDGROUP is not set +# CONFIG_FEATURE_ADDGROUP_LONG_OPTIONS is not set +# CONFIG_FEATURE_ADDUSER_TO_GROUP is not set +# CONFIG_ADDUSER is not set +# CONFIG_FEATURE_ADDUSER_LONG_OPTIONS is not set +# CONFIG_FEATURE_CHECK_NAMES is not set +CONFIG_LAST_ID=0 +CONFIG_FIRST_SYSTEM_ID=0 +CONFIG_LAST_SYSTEM_ID=0 +CONFIG_CHPASSWD=y +CONFIG_FEATURE_DEFAULT_PASSWD_ALGO="des" +CONFIG_CRYPTPW=y +# CONFIG_DELUSER is not set +# CONFIG_DELGROUP is not set +# CONFIG_FEATURE_DEL_USER_FROM_GROUP is not set +CONFIG_GETTY=y +CONFIG_LOGIN=y +# CONFIG_LOGIN_SESSION_AS_CHILD is not set +CONFIG_LOGIN_SCRIPTS=y +CONFIG_FEATURE_NOLOGIN=y +CONFIG_FEATURE_SECURETTY=y +CONFIG_PASSWD=y +CONFIG_FEATURE_PASSWD_WEAK_CHECK=y +CONFIG_SU=y +CONFIG_FEATURE_SU_SYSLOG=y +CONFIG_FEATURE_SU_CHECKS_SHELLS=y +CONFIG_SULOGIN=y +CONFIG_VLOCK=y + +# +# Linux Ext2 FS Progs +# +CONFIG_CHATTR=y +CONFIG_FSCK=y +CONFIG_LSATTR=y +# CONFIG_TUNE2FS is not set + +# +# Linux Module Utilities +# +CONFIG_MODINFO=y +CONFIG_MODPROBE_SMALL=y +CONFIG_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE=y +CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y +# CONFIG_INSMOD is not set +# CONFIG_RMMOD is not set +# CONFIG_LSMOD is not set +# CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set +# CONFIG_MODPROBE is not set +# CONFIG_FEATURE_MODPROBE_BLACKLIST is not set +# CONFIG_DEPMOD is not set + +# +# Options common to multiple modutils +# +# CONFIG_FEATURE_2_4_MODULES is not set +# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set +# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set +# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set +# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set +# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set +# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set +# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set +# CONFIG_FEATURE_MODUTILS_ALIAS is not set +# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set +CONFIG_DEFAULT_MODULES_DIR="/lib/modules" +CONFIG_DEFAULT_DEPMOD_FILE="modules.dep" + +# +# Linux System Utilities +# +CONFIG_BLKDISCARD=y +CONFIG_BLOCKDEV=y +CONFIG_FATATTR=y +CONFIG_FSTRIM=y +# CONFIG_MDEV is not set +# CONFIG_FEATURE_MDEV_CONF is not set +# CONFIG_FEATURE_MDEV_RENAME is not set +# CONFIG_FEATURE_MDEV_RENAME_REGEXP is not set +# CONFIG_FEATURE_MDEV_EXEC is not set +# CONFIG_FEATURE_MDEV_LOAD_FIRMWARE is not set +CONFIG_MOUNT=y +CONFIG_FEATURE_MOUNT_FAKE=y +CONFIG_FEATURE_MOUNT_VERBOSE=y +# CONFIG_FEATURE_MOUNT_HELPERS is not set +CONFIG_FEATURE_MOUNT_LABEL=y +# CONFIG_FEATURE_MOUNT_NFS is not set +CONFIG_FEATURE_MOUNT_CIFS=y +CONFIG_FEATURE_MOUNT_FLAGS=y +CONFIG_FEATURE_MOUNT_FSTAB=y +CONFIG_FEATURE_MOUNT_OTHERTAB=y +CONFIG_REV=y +CONFIG_SETARCH=y +CONFIG_UEVENT=y +CONFIG_ACPID=y +CONFIG_FEATURE_ACPID_COMPAT=y +CONFIG_BLKID=y +# CONFIG_FEATURE_BLKID_TYPE is not set +CONFIG_DMESG=y +CONFIG_FEATURE_DMESG_PRETTY=y +CONFIG_FBSET=y +CONFIG_FEATURE_FBSET_FANCY=y +CONFIG_FEATURE_FBSET_READMODE=y +CONFIG_FDFLUSH=y +CONFIG_FDFORMAT=y +CONFIG_FDISK=y +CONFIG_FDISK_SUPPORT_LARGE_DISKS=y +CONFIG_FEATURE_FDISK_WRITABLE=y +# CONFIG_FEATURE_AIX_LABEL is not set +# CONFIG_FEATURE_SGI_LABEL is not set +# CONFIG_FEATURE_SUN_LABEL is not set +# CONFIG_FEATURE_OSF_LABEL is not set +# CONFIG_FEATURE_GPT_LABEL is not set +CONFIG_FEATURE_FDISK_ADVANCED=y +CONFIG_FINDFS=y +CONFIG_FLOCK=y +CONFIG_FREERAMDISK=y +# CONFIG_FSCK_MINIX is not set +CONFIG_MKFS_EXT2=y +# CONFIG_MKFS_MINIX is not set +# CONFIG_FEATURE_MINIX2 is not set +# CONFIG_MKFS_REISER is not set +CONFIG_MKFS_VFAT=y +CONFIG_GETOPT=y +CONFIG_FEATURE_GETOPT_LONG=y +CONFIG_HEXDUMP=y +CONFIG_FEATURE_HEXDUMP_REVERSE=y +CONFIG_HD=y +CONFIG_HWCLOCK=y +CONFIG_FEATURE_HWCLOCK_LONG_OPTIONS=y +# CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS is not set +# CONFIG_IPCRM is not set +# CONFIG_IPCS is not set +CONFIG_LOSETUP=y +CONFIG_LSPCI=y +CONFIG_LSUSB=y +CONFIG_MKSWAP=y +CONFIG_FEATURE_MKSWAP_UUID=y +CONFIG_MORE=y +CONFIG_PIVOT_ROOT=y +CONFIG_RDATE=y +CONFIG_RDEV=y +CONFIG_READPROFILE=y +CONFIG_RTCWAKE=y +CONFIG_SCRIPT=y +CONFIG_SCRIPTREPLAY=y +# CONFIG_SWAPONOFF is not set +# CONFIG_FEATURE_SWAPON_DISCARD is not set +# CONFIG_FEATURE_SWAPON_PRI is not set +CONFIG_SWITCH_ROOT=y +CONFIG_UMOUNT=y +CONFIG_FEATURE_UMOUNT_ALL=y + +# +# Common options for mount/umount +# +CONFIG_FEATURE_MOUNT_LOOP=y +CONFIG_FEATURE_MOUNT_LOOP_CREATE=y +# CONFIG_FEATURE_MTAB_SUPPORT is not set +CONFIG_VOLUMEID=y + +# +# Filesystem/Volume identification +# +CONFIG_FEATURE_VOLUMEID_BCACHE=y +CONFIG_FEATURE_VOLUMEID_BTRFS=y +CONFIG_FEATURE_VOLUMEID_CRAMFS=y +CONFIG_FEATURE_VOLUMEID_EXFAT=y +CONFIG_FEATURE_VOLUMEID_EXT=y +CONFIG_FEATURE_VOLUMEID_F2FS=y +CONFIG_FEATURE_VOLUMEID_FAT=y +CONFIG_FEATURE_VOLUMEID_HFS=y +CONFIG_FEATURE_VOLUMEID_ISO9660=y +CONFIG_FEATURE_VOLUMEID_JFS=y +CONFIG_FEATURE_VOLUMEID_LINUXRAID=y +CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y +CONFIG_FEATURE_VOLUMEID_LUKS=y +CONFIG_FEATURE_VOLUMEID_NILFS=y +CONFIG_FEATURE_VOLUMEID_NTFS=y +CONFIG_FEATURE_VOLUMEID_OCFS2=y +CONFIG_FEATURE_VOLUMEID_REISERFS=y +CONFIG_FEATURE_VOLUMEID_ROMFS=y +# CONFIG_FEATURE_VOLUMEID_SQUASHFS is not set +CONFIG_FEATURE_VOLUMEID_SYSV=y +CONFIG_FEATURE_VOLUMEID_UDF=y +CONFIG_FEATURE_VOLUMEID_XFS=y + +# +# Miscellaneous Utilities +# +# CONFIG_CONSPY is not set +CONFIG_CROND=y +CONFIG_FEATURE_CROND_D=y +CONFIG_FEATURE_CROND_CALL_SENDMAIL=y +CONFIG_FEATURE_CROND_DIR="/var/spool/cron" +CONFIG_I2CGET=y +CONFIG_I2CSET=y +CONFIG_I2CDUMP=y +CONFIG_I2CDETECT=y +CONFIG_LESS=y +CONFIG_FEATURE_LESS_MAXLINES=9999999 +CONFIG_FEATURE_LESS_BRACKETS=y +CONFIG_FEATURE_LESS_FLAGS=y +CONFIG_FEATURE_LESS_TRUNCATE=y +CONFIG_FEATURE_LESS_MARKS=y +CONFIG_FEATURE_LESS_REGEXP=y +CONFIG_FEATURE_LESS_WINCH=y +CONFIG_FEATURE_LESS_ASK_TERMINAL=y +CONFIG_FEATURE_LESS_DASHCMD=y +CONFIG_FEATURE_LESS_LINENUMS=y +# CONFIG_NANDWRITE is not set +# CONFIG_NANDDUMP is not set +# CONFIG_RFKILL is not set +CONFIG_SETSERIAL=y +CONFIG_TASKSET=y +CONFIG_FEATURE_TASKSET_FANCY=y +# CONFIG_UBIATTACH is not set +# CONFIG_UBIDETACH is not set +# CONFIG_UBIMKVOL is not set +# CONFIG_UBIRMVOL is not set +# CONFIG_UBIRSVOL is not set +# CONFIG_UBIUPDATEVOL is not set +# CONFIG_WALL is not set +CONFIG_ADJTIMEX=y +# CONFIG_BBCONFIG is not set +# CONFIG_FEATURE_COMPRESS_BBCONFIG is not set +CONFIG_BEEP=y +CONFIG_FEATURE_BEEP_FREQ=4000 +CONFIG_FEATURE_BEEP_LENGTH_MS=30 +CONFIG_CHAT=y +CONFIG_FEATURE_CHAT_NOFAIL=y +# CONFIG_FEATURE_CHAT_TTY_HIFI is not set +CONFIG_FEATURE_CHAT_IMPLICIT_CR=y +CONFIG_FEATURE_CHAT_SWALLOW_OPTS=y +CONFIG_FEATURE_CHAT_SEND_ESCAPES=y +CONFIG_FEATURE_CHAT_VAR_ABORT_LEN=y +CONFIG_FEATURE_CHAT_CLR_ABORT=y +CONFIG_CHRT=y +CONFIG_CRONTAB=y +CONFIG_DC=y +CONFIG_FEATURE_DC_LIBM=y +# CONFIG_DEVFSD is not set +# CONFIG_DEVFSD_MODLOAD is not set +# CONFIG_DEVFSD_FG_NP is not set +# CONFIG_DEVFSD_VERBOSE is not set +# CONFIG_FEATURE_DEVFS is not set +CONFIG_DEVMEM=y +CONFIG_EJECT=y +# CONFIG_FEATURE_EJECT_SCSI is not set +CONFIG_FBSPLASH=y +# CONFIG_FLASHCP is not set +# CONFIG_FLASH_LOCK is not set +# CONFIG_FLASH_UNLOCK is not set +# CONFIG_FLASH_ERASEALL is not set +CONFIG_IONICE=y +# CONFIG_INOTIFYD is not set +# CONFIG_LAST is not set +# CONFIG_FEATURE_LAST_FANCY is not set +CONFIG_HDPARM=y +CONFIG_FEATURE_HDPARM_GET_IDENTITY=y +CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF=y +CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF=y +CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET=y +CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF=y +CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y +CONFIG_MAKEDEVS=y +# CONFIG_FEATURE_MAKEDEVS_LEAF is not set +CONFIG_FEATURE_MAKEDEVS_TABLE=y +CONFIG_MAN=y +CONFIG_MICROCOM=y +CONFIG_MOUNTPOINT=y +# CONFIG_MT is not set +CONFIG_RAIDAUTORUN=y +# CONFIG_READAHEAD is not set +# CONFIG_RUNLEVEL is not set +CONFIG_RX=y +CONFIG_SETSID=y +CONFIG_STRINGS=y +CONFIG_TIME=y +CONFIG_TIMEOUT=y +CONFIG_TTYSIZE=y +CONFIG_VOLNAME=y +CONFIG_WATCHDOG=y + +# +# Networking Utilities +# +CONFIG_NAMEIF=y +CONFIG_FEATURE_NAMEIF_EXTENDED=y +CONFIG_NBDCLIENT=y +CONFIG_NC=y +CONFIG_NC_SERVER=y +CONFIG_NC_EXTRA=y +# CONFIG_NC_110_COMPAT is not set +CONFIG_PING=y +CONFIG_PING6=y +CONFIG_FEATURE_FANCY_PING=y +CONFIG_WGET=y +CONFIG_FEATURE_WGET_STATUSBAR=y +CONFIG_FEATURE_WGET_AUTHENTICATION=y +CONFIG_FEATURE_WGET_LONG_OPTIONS=y +CONFIG_FEATURE_WGET_TIMEOUT=y +CONFIG_FEATURE_WGET_OPENSSL=y +CONFIG_FEATURE_WGET_SSL_HELPER=y +CONFIG_WHOIS=y +CONFIG_FEATURE_IPV6=y +# CONFIG_FEATURE_UNIX_LOCAL is not set +CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y +# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set +# CONFIG_ARP is not set +# CONFIG_ARPING is not set +CONFIG_BRCTL=y +CONFIG_FEATURE_BRCTL_FANCY=y +CONFIG_FEATURE_BRCTL_SHOW=y +CONFIG_DNSD=y +# CONFIG_ETHER_WAKE is not set +CONFIG_FAKEIDENTD=y +CONFIG_FTPD=y +CONFIG_FEATURE_FTP_WRITE=y +CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y +CONFIG_FEATURE_FTP_AUTHENTICATION=y +CONFIG_FTPGET=y +CONFIG_FTPPUT=y +CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y +CONFIG_HOSTNAME=y +CONFIG_HTTPD=y +CONFIG_FEATURE_HTTPD_RANGES=y +CONFIG_FEATURE_HTTPD_SETUID=y +CONFIG_FEATURE_HTTPD_BASIC_AUTH=y +CONFIG_FEATURE_HTTPD_AUTH_MD5=y +CONFIG_FEATURE_HTTPD_CGI=y +CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y +CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y +CONFIG_FEATURE_HTTPD_ENCODE_URL_STR=y +CONFIG_FEATURE_HTTPD_ERROR_PAGES=y +CONFIG_FEATURE_HTTPD_PROXY=y +CONFIG_FEATURE_HTTPD_GZIP=y +# CONFIG_IFCONFIG is not set +# CONFIG_FEATURE_IFCONFIG_STATUS is not set +# CONFIG_FEATURE_IFCONFIG_SLIP is not set +# CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ is not set +# CONFIG_FEATURE_IFCONFIG_HW is not set +# CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS is not set +# CONFIG_IFENSLAVE is not set +CONFIG_IFPLUGD=y +CONFIG_IFUPDOWN=y +CONFIG_IFUPDOWN_IFSTATE_PATH="/var/run/ifstate" +CONFIG_FEATURE_IFUPDOWN_IP=y +CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN=y +# CONFIG_FEATURE_IFUPDOWN_IFCONFIG_BUILTIN is not set +CONFIG_FEATURE_IFUPDOWN_IPV4=y +CONFIG_FEATURE_IFUPDOWN_IPV6=y +CONFIG_FEATURE_IFUPDOWN_MAPPING=y +# CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set +CONFIG_INETD=y +CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO=y +CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD=y +CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME=y +CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME=y +CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN=y +# CONFIG_FEATURE_INETD_RPC is not set +CONFIG_IP=y +CONFIG_FEATURE_IP_ADDRESS=y +CONFIG_FEATURE_IP_LINK=y +CONFIG_FEATURE_IP_ROUTE=y +CONFIG_FEATURE_IP_ROUTE_DIR="/etc/iproute2" +CONFIG_FEATURE_IP_TUNNEL=y +CONFIG_FEATURE_IP_RULE=y +CONFIG_FEATURE_IP_NEIGH=y +CONFIG_FEATURE_IP_SHORT_FORMS=y +# CONFIG_FEATURE_IP_RARE_PROTOCOLS is not set +CONFIG_IPADDR=y +CONFIG_IPLINK=y +CONFIG_IPROUTE=y +CONFIG_IPTUNNEL=y +CONFIG_IPRULE=y +CONFIG_IPNEIGH=y +CONFIG_IPCALC=y +CONFIG_FEATURE_IPCALC_FANCY=y +CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y +CONFIG_NETSTAT=y +CONFIG_FEATURE_NETSTAT_WIDE=y +CONFIG_FEATURE_NETSTAT_PRG=y +# CONFIG_NSLOOKUP is not set +CONFIG_NTPD=y +CONFIG_FEATURE_NTPD_SERVER=y +CONFIG_FEATURE_NTPD_CONF=y +CONFIG_PSCAN=y +# CONFIG_ROUTE is not set +CONFIG_SLATTACH=y +CONFIG_TCPSVD=y +CONFIG_TELNET=y +CONFIG_FEATURE_TELNET_TTYPE=y +CONFIG_FEATURE_TELNET_AUTOLOGIN=y +CONFIG_TELNETD=y +CONFIG_FEATURE_TELNETD_STANDALONE=y +CONFIG_FEATURE_TELNETD_INETD_WAIT=y +CONFIG_TFTP=y +CONFIG_TFTPD=y + +# +# Common options for tftp/tftpd +# +CONFIG_FEATURE_TFTP_GET=y +CONFIG_FEATURE_TFTP_PUT=y +CONFIG_FEATURE_TFTP_BLOCKSIZE=y +CONFIG_FEATURE_TFTP_PROGRESS_BAR=y +# CONFIG_TFTP_DEBUG is not set +CONFIG_TRACEROUTE=y +CONFIG_TRACEROUTE6=y +CONFIG_FEATURE_TRACEROUTE_VERBOSE=y +# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set +# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set +CONFIG_TUNCTL=y +CONFIG_FEATURE_TUNCTL_UG=y +# CONFIG_UDHCPC6 is not set +CONFIG_UDHCPD=y +CONFIG_DHCPRELAY=y +CONFIG_DUMPLEASES=y +CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY=y +# CONFIG_FEATURE_UDHCPD_BASE_IP_ON_MAC is not set +CONFIG_DHCPD_LEASES_FILE="/var/lib/misc/udhcpd.leases" +CONFIG_UDHCPC=y +CONFIG_FEATURE_UDHCPC_ARPING=y +CONFIG_FEATURE_UDHCPC_SANITIZEOPT=y +# CONFIG_FEATURE_UDHCP_PORT is not set +CONFIG_UDHCP_DEBUG=9 +CONFIG_FEATURE_UDHCP_RFC3397=y +CONFIG_FEATURE_UDHCP_8021Q=y +CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script" +CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80 +CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n" +CONFIG_UDPSVD=y +CONFIG_VCONFIG=y +# CONFIG_ZCIP is not set + +# +# Print Utilities +# +CONFIG_LPD=y +CONFIG_LPR=y +CONFIG_LPQ=y + +# +# Mail Utilities +# +CONFIG_MAKEMIME=y +CONFIG_FEATURE_MIME_CHARSET="us-ascii" +CONFIG_POPMAILDIR=y +CONFIG_FEATURE_POPMAILDIR_DELIVERY=y +CONFIG_REFORMIME=y +CONFIG_FEATURE_REFORMIME_COMPAT=y +CONFIG_SENDMAIL=y + +# +# Process Utilities +# +CONFIG_IOSTAT=y +CONFIG_LSOF=y +CONFIG_MPSTAT=y +CONFIG_NMETER=y +CONFIG_PMAP=y +CONFIG_POWERTOP=y +CONFIG_PSTREE=y +CONFIG_PWDX=y +CONFIG_SMEMCAP=y +CONFIG_TOP=y +CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y +CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y +CONFIG_FEATURE_TOP_SMP_CPU=y +CONFIG_FEATURE_TOP_DECIMALS=y +CONFIG_FEATURE_TOP_SMP_PROCESS=y +CONFIG_FEATURE_TOPMEM=y +CONFIG_UPTIME=y +# CONFIG_FEATURE_UPTIME_UTMP_SUPPORT is not set +CONFIG_FREE=y +CONFIG_FUSER=y +CONFIG_KILL=y +CONFIG_KILLALL=y +CONFIG_KILLALL5=y +CONFIG_PGREP=y +CONFIG_PIDOF=y +CONFIG_FEATURE_PIDOF_SINGLE=y +CONFIG_FEATURE_PIDOF_OMIT=y +CONFIG_PKILL=y +CONFIG_PS=y +# CONFIG_FEATURE_PS_WIDE is not set +# CONFIG_FEATURE_PS_LONG is not set +CONFIG_FEATURE_PS_TIME=y +CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y +# CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set +CONFIG_RENICE=y +CONFIG_BB_SYSCTL=y +CONFIG_FEATURE_SHOW_THREADS=y +CONFIG_WATCH=y + +# +# Runit Utilities +# +CONFIG_CHPST=y +CONFIG_SETUIDGID=y +CONFIG_ENVUIDGID=y +CONFIG_ENVDIR=y +CONFIG_SOFTLIMIT=y +CONFIG_RUNSV=y +CONFIG_RUNSVDIR=y +# CONFIG_FEATURE_RUNSVDIR_LOG is not set +CONFIG_SV=y +CONFIG_SV_DEFAULT_SERVICE_DIR="/var/service" +CONFIG_SVLOGD=y +# CONFIG_CHCON is not set +# CONFIG_FEATURE_CHCON_LONG_OPTIONS is not set +# CONFIG_GETENFORCE is not set +# CONFIG_GETSEBOOL is not set +# CONFIG_LOAD_POLICY is not set +# CONFIG_MATCHPATHCON is not set +# CONFIG_RESTORECON is not set +# CONFIG_RUNCON is not set +# CONFIG_FEATURE_RUNCON_LONG_OPTIONS is not set +# CONFIG_SELINUXENABLED is not set +# CONFIG_SETENFORCE is not set +# CONFIG_SETFILES is not set +# CONFIG_FEATURE_SETFILES_CHECK_OPTION is not set +# CONFIG_SETSEBOOL is not set +# CONFIG_SESTATUS is not set + +# +# Shells +# +CONFIG_ASH=y +CONFIG_ASH_BASH_COMPAT=y +# CONFIG_ASH_IDLE_TIMEOUT is not set +CONFIG_ASH_JOB_CONTROL=y +CONFIG_ASH_ALIAS=y +CONFIG_ASH_GETOPTS=y +CONFIG_ASH_BUILTIN_ECHO=y +CONFIG_ASH_BUILTIN_PRINTF=y +CONFIG_ASH_BUILTIN_TEST=y +CONFIG_ASH_HELP=y +CONFIG_ASH_CMDCMD=y +# CONFIG_ASH_MAIL is not set +CONFIG_ASH_OPTIMIZE_FOR_SIZE=y +CONFIG_ASH_RANDOM_SUPPORT=y +CONFIG_ASH_EXPAND_PRMT=y +CONFIG_CTTYHACK=y +# CONFIG_HUSH is not set +# CONFIG_HUSH_BASH_COMPAT is not set +# CONFIG_HUSH_BRACE_EXPANSION is not set +# CONFIG_HUSH_HELP is not set +# CONFIG_HUSH_INTERACTIVE is not set +# CONFIG_HUSH_SAVEHISTORY is not set +# CONFIG_HUSH_JOB is not set +# CONFIG_HUSH_TICK is not set +# CONFIG_HUSH_IF is not set +# CONFIG_HUSH_LOOPS is not set +# CONFIG_HUSH_CASE is not set +# CONFIG_HUSH_FUNCTIONS is not set +# CONFIG_HUSH_LOCAL is not set +# CONFIG_HUSH_RANDOM_SUPPORT is not set +# CONFIG_HUSH_EXPORT_N is not set +# CONFIG_HUSH_MODE_X is not set +# CONFIG_MSH is not set +CONFIG_FEATURE_SH_IS_ASH=y +# CONFIG_FEATURE_SH_IS_HUSH is not set +# CONFIG_FEATURE_SH_IS_NONE is not set +# CONFIG_FEATURE_BASH_IS_ASH is not set +# CONFIG_FEATURE_BASH_IS_HUSH is not set +CONFIG_FEATURE_BASH_IS_NONE=y +CONFIG_SH_MATH_SUPPORT=y +CONFIG_SH_MATH_SUPPORT_64=y +CONFIG_FEATURE_SH_EXTRA_QUIET=y +# CONFIG_FEATURE_SH_STANDALONE is not set +# CONFIG_FEATURE_SH_NOFORK is not set +CONFIG_FEATURE_SH_HISTFILESIZE=y + +# +# System Logging Utilities +# +# CONFIG_KLOGD is not set +# CONFIG_FEATURE_KLOGD_KLOGCTL is not set +# CONFIG_LOGGER is not set +# CONFIG_LOGREAD is not set +# CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set +# CONFIG_SYSLOGD is not set +# CONFIG_FEATURE_ROTATE_LOGFILE is not set +# CONFIG_FEATURE_REMOTE_LOG is not set +# CONFIG_FEATURE_SYSLOGD_DUP is not set +# CONFIG_FEATURE_SYSLOGD_CFG is not set +CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0 +# CONFIG_FEATURE_IPC_SYSLOG is not set +CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0 +# CONFIG_FEATURE_KMSG_SYSLOG is not set -- cgit v1.2.3-55-g6feb From e4de8c631644be5e96711462763bf16491dda54f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Mar 2016 15:22:42 +0100 Subject: nmeter: fix a bug with unterminated varargs function old new delta collect_mem 361 371 +10 collect_swp 116 120 +4 vrdval 168 170 +2 collect_thread_nr 63 65 +2 collect_int 121 123 +2 collect_if 205 207 +2 collect_fork 117 119 +2 collect_fd 79 81 +2 collect_ctx 117 119 +2 collect_cpu 621 623 +2 collect_blk 557 559 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 11/0 up/down: 32/0) Total: 32 bytes Signed-off-by: Denys Vlasenko --- procps/nmeter.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/procps/nmeter.c b/procps/nmeter.c index 5d5b83b8d..0ce6842e7 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -235,6 +235,8 @@ static int vrdval(const char* p, const char* key, strtoull(p, NULL, 10) : read_after_slash(p); indexnext = va_arg(arg_ptr, int); + if (!indexnext) + return 0; } while (*p > ' ') p++; // skip over value indexline++; @@ -395,7 +397,7 @@ static void FAST_FUNC collect_cpu(cpu_stat *s) char *bar = s->bar; int i; - if (rdval(get_file(&proc_stat), "cpu ", data, 1, 2, 3, 4, 5, 6, 7)) { + if (rdval(get_file(&proc_stat), "cpu ", data, 1, 2, 3, 4, 5, 6, 7, 0)) { put_question_marks(bar_sz); return; } @@ -464,7 +466,7 @@ static void FAST_FUNC collect_int(int_stat *s) ullong data[1]; ullong old; - if (rdval(get_file(&proc_stat), "intr", data, s->no)) { + if (rdval(get_file(&proc_stat), "intr", data, s->no, 0)) { put_question_marks(4); return; } @@ -498,7 +500,7 @@ static void FAST_FUNC collect_ctx(ctx_stat *s) ullong data[1]; ullong old; - if (rdval(get_file(&proc_stat), "ctxt", data, 1)) { + if (rdval(get_file(&proc_stat), "ctxt", data, 1, 0)) { put_question_marks(4); return; } @@ -530,7 +532,7 @@ static void FAST_FUNC collect_blk(blk_stat *s) if (is26) { i = rdval_diskstats(get_file(&proc_diskstats), data); } else { - i = rdval(get_file(&proc_stat), s->lookfor, data, 1, 2); + i = rdval(get_file(&proc_stat), s->lookfor, data, 1, 2, 0); // Linux 2.4 reports bio in Kbytes, convert to sectors: data[0] *= 2; data[1] *= 2; @@ -568,7 +570,7 @@ static void FAST_FUNC collect_thread_nr(fork_stat *s UNUSED_PARAM) { ullong data[1]; - if (rdval_loadavg(get_file(&proc_loadavg), data, 4)) { + if (rdval_loadavg(get_file(&proc_loadavg), data, 4, 0)) { put_question_marks(4); return; } @@ -580,7 +582,7 @@ static void FAST_FUNC collect_fork(fork_stat *s) ullong data[1]; ullong old; - if (rdval(get_file(&proc_stat), "processes", data, 1)) { + if (rdval(get_file(&proc_stat), "processes", data, 1, 0)) { put_question_marks(4); return; } @@ -614,7 +616,7 @@ static void FAST_FUNC collect_if(if_stat *s) ullong data[4]; int i; - if (rdval(get_file(&proc_net_dev), s->device_colon, data, 1, 3, 9, 11)) { + if (rdval(get_file(&proc_net_dev), s->device_colon, data, 1, 3, 9, 11, 0)) { put_question_marks(10); return; } @@ -692,7 +694,7 @@ static void FAST_FUNC collect_mem(mem_stat *s) ullong m_cached = 0; ullong m_slab = 0; - if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1)) { + if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1, 0)) { put_question_marks(4); return; } @@ -701,10 +703,10 @@ static void FAST_FUNC collect_mem(mem_stat *s) return; } - if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1) - || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1) - || rdval(proc_meminfo.file, "Cached:", &m_cached, 1) - || rdval(proc_meminfo.file, "Slab:", &m_slab , 1) + if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1, 0) + || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1, 0) + || rdval(proc_meminfo.file, "Cached:", &m_cached, 1, 0) + || rdval(proc_meminfo.file, "Slab:", &m_slab , 1, 0) ) { put_question_marks(4); return; @@ -735,8 +737,8 @@ static void FAST_FUNC collect_swp(swp_stat *s UNUSED_PARAM) { ullong s_total[1]; ullong s_free[1]; - if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1) - || rdval(proc_meminfo.file, "SwapFree:" , s_free, 1) + if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1, 0) + || rdval(proc_meminfo.file, "SwapFree:" , s_free, 1, 0) ) { put_question_marks(4); return; @@ -759,7 +761,7 @@ static void FAST_FUNC collect_fd(fd_stat *s UNUSED_PARAM) { ullong data[2]; - if (rdval(get_file(&proc_sys_fs_filenr), "", data, 1, 2)) { + if (rdval(get_file(&proc_sys_fs_filenr), "", data, 1, 2, 0)) { put_question_marks(4); return; } -- cgit v1.2.3-55-g6feb From 99c71c9e800d51aa52d7bd592e8071341013a628 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Mar 2016 15:28:49 +0100 Subject: nmeter: code shrink function old new delta put 52 43 -9 Signed-off-by: Denys Vlasenko --- procps/nmeter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/procps/nmeter.c b/procps/nmeter.c index 0ce6842e7..8fe39c43b 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -142,11 +142,11 @@ static void print_outbuf(void) static void put(const char *s) { - int sz = strlen(s); - if (sz > outbuf + sizeof(outbuf) - cur_outbuf) - sz = outbuf + sizeof(outbuf) - cur_outbuf; - memcpy(cur_outbuf, s, sz); - cur_outbuf += sz; + char *p = cur_outbuf; + int sz = outbuf + sizeof(outbuf) - p; + while (*s && --sz >= 0) + *p++ = *s++; + cur_outbuf = p; } static void put_c(char c) -- cgit v1.2.3-55-g6feb From 8a26fda98c46b1ffd98a1a9874a0899b061226d8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Mar 2016 15:52:40 +0100 Subject: nmeter: convert field list to bit list function old new delta rdval 34 157 +123 collect_int 123 122 -1 collect_thread_nr 65 62 -3 collect_blk 559 552 -7 collect_if 207 199 -8 collect_fork 119 111 -8 collect_ctx 119 111 -8 collect_fd 81 71 -10 collect_swp 120 107 -13 collect_cpu 623 610 -13 collect_mem 371 339 -32 rdval_loadavg 38 - -38 vrdval 170 - -170 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 1/10 up/down: 123/-311) Total: -188 bytes Signed-off-by: Denys Vlasenko --- procps/nmeter.c | 106 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/procps/nmeter.c b/procps/nmeter.c index 8fe39c43b..d6222af6b 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -208,67 +208,50 @@ static ullong read_after_slash(const char *p) return strtoull(p+1, NULL, 10); } -enum conv_type { conv_decimal, conv_slash }; +enum conv_type { + conv_decimal = 0, + conv_slash = 1 +}; // Reads decimal values from line. Values start after key, for example: // "cpu 649369 0 341297 4336769..." - key is "cpu" here. -// Values are stored in vec[]. arg_ptr has list of positions -// we are interested in: for example: 1,2,5 - we want 1st, 2nd and 5th value. -static int vrdval(const char* p, const char* key, - enum conv_type conv, ullong *vec, va_list arg_ptr) +// Values are stored in vec[]. +// posbits is a bit lit of positions we are interested in. +// for example: 00100110 - we want 1st, 2nd and 5th value. +// posbits.bit0 encodes conversion type. +static int rdval(const char* p, const char* key, ullong *vec, long posbits) { - int indexline; - int indexnext; + unsigned curpos; p = strstr(p, key); if (!p) return 1; p += strlen(key); - indexline = 1; - indexnext = va_arg(arg_ptr, int); + curpos = 1 << 1; while (1) { while (*p == ' ' || *p == '\t') p++; if (*p == '\n' || *p == '\0') break; - if (indexline == indexnext) { // read this value - *vec++ = conv==conv_decimal ? + if (curpos & posbits) { // read this value + *vec++ = (posbits & 1) == conv_decimal ? strtoull(p, NULL, 10) : read_after_slash(p); - indexnext = va_arg(arg_ptr, int); - if (!indexnext) + posbits -= curpos; + if (posbits <= 1) return 0; } - while (*p > ' ') p++; // skip over value - indexline++; + while (*p > ' ') // skip over the value + p++; + curpos <<= 1; } return 0; } -// Parses files with lines like "cpu0 21727 0 15718 1813856 9461 10485 0 0": -// rdval(file_contents, "string_to_find", result_vector, value#, value#...) -// value# start with 1 -static int rdval(const char* p, const char* key, ullong *vec, ...) -{ - va_list arg_ptr; - int result; - - va_start(arg_ptr, vec); - result = vrdval(p, key, conv_decimal, vec, arg_ptr); - va_end(arg_ptr); - - return result; -} - // Parses files with lines like "... ... ... 3/148 ...." -static int rdval_loadavg(const char* p, ullong *vec, ...) +static int rdval_loadavg(const char* p, ullong *vec, long posbits) { - va_list arg_ptr; int result; - - va_start(arg_ptr, vec); - result = vrdval(p, "", conv_slash, vec, arg_ptr); - va_end(arg_ptr); - + result = rdval(p, "", vec, posbits | conv_slash); return result; } @@ -397,7 +380,15 @@ static void FAST_FUNC collect_cpu(cpu_stat *s) char *bar = s->bar; int i; - if (rdval(get_file(&proc_stat), "cpu ", data, 1, 2, 3, 4, 5, 6, 7, 0)) { + if (rdval(get_file(&proc_stat), "cpu ", data, 0 + | (1 << 1) + | (1 << 2) + | (1 << 3) + | (1 << 4) + | (1 << 5) + | (1 << 6) + | (1 << 7)) + ) { put_question_marks(bar_sz); return; } @@ -466,7 +457,7 @@ static void FAST_FUNC collect_int(int_stat *s) ullong data[1]; ullong old; - if (rdval(get_file(&proc_stat), "intr", data, s->no, 0)) { + if (rdval(get_file(&proc_stat), "intr", data, 1 << s->no)) { put_question_marks(4); return; } @@ -500,7 +491,7 @@ static void FAST_FUNC collect_ctx(ctx_stat *s) ullong data[1]; ullong old; - if (rdval(get_file(&proc_stat), "ctxt", data, 1, 0)) { + if (rdval(get_file(&proc_stat), "ctxt", data, 1 << 1)) { put_question_marks(4); return; } @@ -532,7 +523,10 @@ static void FAST_FUNC collect_blk(blk_stat *s) if (is26) { i = rdval_diskstats(get_file(&proc_diskstats), data); } else { - i = rdval(get_file(&proc_stat), s->lookfor, data, 1, 2, 0); + i = rdval(get_file(&proc_stat), s->lookfor, data, 0 + | (1 << 1) + | (1 << 2) + ); // Linux 2.4 reports bio in Kbytes, convert to sectors: data[0] *= 2; data[1] *= 2; @@ -570,7 +564,7 @@ static void FAST_FUNC collect_thread_nr(fork_stat *s UNUSED_PARAM) { ullong data[1]; - if (rdval_loadavg(get_file(&proc_loadavg), data, 4, 0)) { + if (rdval_loadavg(get_file(&proc_loadavg), data, 1 << 4)) { put_question_marks(4); return; } @@ -582,7 +576,7 @@ static void FAST_FUNC collect_fork(fork_stat *s) ullong data[1]; ullong old; - if (rdval(get_file(&proc_stat), "processes", data, 1, 0)) { + if (rdval(get_file(&proc_stat), "processes", data, 1 << 1)) { put_question_marks(4); return; } @@ -616,7 +610,12 @@ static void FAST_FUNC collect_if(if_stat *s) ullong data[4]; int i; - if (rdval(get_file(&proc_net_dev), s->device_colon, data, 1, 3, 9, 11, 0)) { + if (rdval(get_file(&proc_net_dev), s->device_colon, data, 0 + | (1 << 1) + | (1 << 3) + | (1 << 9) + | (1 << 11)) + ) { put_question_marks(10); return; } @@ -694,7 +693,7 @@ static void FAST_FUNC collect_mem(mem_stat *s) ullong m_cached = 0; ullong m_slab = 0; - if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1, 0)) { + if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1 << 1)) { put_question_marks(4); return; } @@ -703,10 +702,10 @@ static void FAST_FUNC collect_mem(mem_stat *s) return; } - if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1, 0) - || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1, 0) - || rdval(proc_meminfo.file, "Cached:", &m_cached, 1, 0) - || rdval(proc_meminfo.file, "Slab:", &m_slab , 1, 0) + if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1 << 1) + || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1 << 1) + || rdval(proc_meminfo.file, "Cached:", &m_cached, 1 << 1) + || rdval(proc_meminfo.file, "Slab:", &m_slab , 1 << 1) ) { put_question_marks(4); return; @@ -737,8 +736,8 @@ static void FAST_FUNC collect_swp(swp_stat *s UNUSED_PARAM) { ullong s_total[1]; ullong s_free[1]; - if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1, 0) - || rdval(proc_meminfo.file, "SwapFree:" , s_free, 1, 0) + if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1 << 1) + || rdval(proc_meminfo.file, "SwapFree:" , s_free, 1 << 1) ) { put_question_marks(4); return; @@ -761,7 +760,10 @@ static void FAST_FUNC collect_fd(fd_stat *s UNUSED_PARAM) { ullong data[2]; - if (rdval(get_file(&proc_sys_fs_filenr), "", data, 1, 2, 0)) { + if (rdval(get_file(&proc_sys_fs_filenr), "", data, 0 + | (1 << 1) + | (1 << 2)) + ) { put_question_marks(4); return; } -- cgit v1.2.3-55-g6feb From a63e2a8cb2dd0d6819c1844c52344c3bd6f73659 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Mar 2016 16:06:29 +0100 Subject: nmeter: simple code shrink here and there function old new delta nmeter_main 709 707 -2 init_cr 15 12 -3 collect_time 141 131 -10 collect_cpu 610 593 -17 init_cpu 82 63 -19 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-51) Total: -51 bytes Signed-off-by: Denys Vlasenko --- procps/nmeter.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/procps/nmeter.c b/procps/nmeter.c index d6222af6b..1cc908504 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -83,8 +83,8 @@ struct globals { smallint is26; // 1 if sample delay is not an integer fraction of a second smallint need_seconds; + char final_char; char *cur_outbuf; - const char *final_str; int delta; int deltanz; struct timeval tv; @@ -101,7 +101,6 @@ struct globals { #define is26 (G.is26 ) #define need_seconds (G.need_seconds ) #define cur_outbuf (G.cur_outbuf ) -#define final_str (G.final_str ) #define delta (G.delta ) #define deltanz (G.deltanz ) #define tv (G.tv ) @@ -114,7 +113,7 @@ struct globals { #define INIT_G() do { \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ cur_outbuf = outbuf; \ - final_str = "\n"; \ + G.final_char = '\n'; \ deltanz = delta = 1000000; \ } while (0) @@ -322,7 +321,6 @@ static void scale(ullong ul) put(buf); } - #define S_STAT(a) \ typedef struct a { \ struct s_stat *next; \ @@ -354,11 +352,10 @@ static s_stat* init_delay(const char *param) static s_stat* init_cr(const char *param UNUSED_PARAM) { - final_str = "\r"; - return (s_stat*)0; + G.final_char = '\r'; + return NULL; } - // user nice system idle iowait irq softirq (last 3 only in 2.6) //cpu 649369 0 341297 4336769 11640 7122 1183 //cpuN 649369 0 341297 4336769 11640 7122 1183 @@ -366,10 +363,9 @@ enum { CPU_FIELDCNT = 7 }; S_STAT(cpu_stat) ullong old[CPU_FIELDCNT]; int bar_sz; - char *bar; + char bar[1]; S_STAT_END(cpu_stat) - static void FAST_FUNC collect_cpu(cpu_stat *s) { ullong data[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 }; @@ -431,22 +427,20 @@ static void FAST_FUNC collect_cpu(cpu_stat *s) put(s->bar); } - static s_stat* init_cpu(const char *param) { int sz; - cpu_stat *s = xzalloc(sizeof(*s)); - s->collect = collect_cpu; + cpu_stat *s; sz = strtoul(param, NULL, 0); /* param can be "" */ if (sz < 10) sz = 10; if (sz > 1000) sz = 1000; - s->bar = xzalloc(sz+1); + s = xzalloc(sizeof(*s) + sz); /*s->bar[sz] = '\0'; - xzalloc did it */ s->bar_sz = sz; + s->collect = collect_cpu; return (s_stat*)s; } - S_STAT(int_stat) ullong old; int no; @@ -481,7 +475,6 @@ static s_stat* init_int(const char *param) return (s_stat*)s; } - S_STAT(ctx_stat) ullong old; S_STAT_END(ctx_stat) @@ -509,7 +502,6 @@ static s_stat* init_ctx(const char *param UNUSED_PARAM) return (s_stat*)s; } - S_STAT(blk_stat) const char* lookfor; ullong old[2]; @@ -555,7 +547,6 @@ static s_stat* init_blk(const char *param UNUSED_PARAM) return (s_stat*)s; } - S_STAT(fork_stat) ullong old; S_STAT_END(fork_stat) @@ -598,7 +589,6 @@ static s_stat* init_fork(const char *param) return (s_stat*)s; } - S_STAT(if_stat) ullong old[4]; const char *device; @@ -645,7 +635,6 @@ static s_stat* init_if(const char *device) return (s_stat*)s; } - S_STAT(mem_stat) char opt; S_STAT_END(mem_stat) @@ -728,7 +717,6 @@ static s_stat* init_mem(const char *param) return (s_stat*)s; } - S_STAT(swp_stat) S_STAT_END(swp_stat) @@ -752,7 +740,6 @@ static s_stat* init_swp(const char *param UNUSED_PARAM) return (s_stat*)s; } - S_STAT(fd_stat) S_STAT_END(fd_stat) @@ -778,17 +765,16 @@ static s_stat* init_fd(const char *param UNUSED_PARAM) return (s_stat*)s; } - S_STAT(time_stat) - int prec; - int scale; + unsigned prec; + unsigned scale; S_STAT_END(time_stat) static void FAST_FUNC collect_time(time_stat *s) { char buf[sizeof("12:34:56.123456")]; struct tm* tm; - int us = tv.tv_usec + s->scale/2; + unsigned us = tv.tv_usec + s->scale/2; time_t t = tv.tv_sec; if (us >= 1000000) { @@ -829,7 +815,6 @@ static void FAST_FUNC collect_info(s_stat *s) } } - typedef s_stat* init_func(const char *param); // Deprecated %NNNd is to be removed, -d MSEC supersedes it @@ -951,7 +936,7 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) while (1) { gettimeofday(&tv, NULL); collect_info(first); - put(final_str); + put_c(G.final_char); print_outbuf(); // Negative delta -> no usleep at all -- cgit v1.2.3-55-g6feb From 41b1e2c39238ef1f333588b9a857e5af806bd157 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Mar 2016 16:13:23 +0100 Subject: nmeter: remove undocumented %NNNd specifier function old new delta nmeter_main 707 745 +38 init_functions 48 44 -4 init_delay 63 - -63 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/1 up/down: 38/-67) Total: -29 bytes Signed-off-by: Denys Vlasenko --- procps/nmeter.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/procps/nmeter.c b/procps/nmeter.c index 1cc908504..d6c46c657 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -342,14 +342,6 @@ static s_stat* init_literal(void) return (s_stat*)s; } -static s_stat* init_delay(const char *param) -{ - delta = strtoul(param, NULL, 0) * 1000; /* param can be "" */ - deltanz = delta > 0 ? delta : 1; - need_seconds = (1000000%deltanz) != 0; - return NULL; -} - static s_stat* init_cr(const char *param UNUSED_PARAM) { G.final_char = '\r'; @@ -817,8 +809,7 @@ static void FAST_FUNC collect_info(s_stat *s) typedef s_stat* init_func(const char *param); -// Deprecated %NNNd is to be removed, -d MSEC supersedes it -static const char options[] ALIGN1 = "ncmsfixptbdr"; +static const char options[] ALIGN1 = "ncmsfixptbr"; static init_func *const init_functions[] = { init_if, init_cpu, @@ -830,7 +821,6 @@ static init_func *const init_functions[] = { init_fork, init_time, init_blk, - init_delay, init_cr }; @@ -853,8 +843,11 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) is26 = (strstr(buf, " 2.4.") == NULL); } - if (getopt32(argv, "d:", &opt_d)) - init_delay(opt_d); + if (getopt32(argv, "d:", &opt_d)) { + delta = xatou(opt_d) * 1000; + deltanz = delta > 0 ? delta : 1; + need_seconds = (1000000 % deltanz) != 0; + } argv += optind; if (!argv[0]) -- cgit v1.2.3-55-g6feb From 0d1b71e8e61491cf50fc3a21ec0a412f6dca4d56 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Mar 2016 17:54:17 +0100 Subject: nmeter: reinstate and document -d-1 Signed-off-by: Denys Vlasenko --- procps/nmeter.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/procps/nmeter.c b/procps/nmeter.c index d6c46c657..33de3790f 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -21,7 +21,7 @@ //usage:#define nmeter_full_usage "\n\n" //usage: "Monitor system in real time" //usage: "\n" -//usage: "\n -d MSEC Milliseconds between updates (default:1000)" +//usage: "\n -d MSEC Milliseconds between updates, default:1000, none:-1" //usage: "\n" //usage: "\nFormat specifiers:" //usage: "\n %Nc or %[cN] CPU. N - bar size (default:10)" @@ -86,7 +86,7 @@ struct globals { char final_char; char *cur_outbuf; int delta; - int deltanz; + unsigned deltanz; struct timeval tv; #define first_proc_file proc_stat proc_file proc_stat; // Must match the order of proc_name's! @@ -101,8 +101,6 @@ struct globals { #define is26 (G.is26 ) #define need_seconds (G.need_seconds ) #define cur_outbuf (G.cur_outbuf ) -#define delta (G.delta ) -#define deltanz (G.deltanz ) #define tv (G.tv ) #define proc_stat (G.proc_stat ) #define proc_loadavg (G.proc_loadavg ) @@ -114,7 +112,7 @@ struct globals { SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ cur_outbuf = outbuf; \ G.final_char = '\n'; \ - deltanz = delta = 1000000; \ + G.deltanz = G.delta = 1000000; \ } while (0) // We depend on this being a char[], not char* - we take sizeof() of it @@ -844,9 +842,9 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) } if (getopt32(argv, "d:", &opt_d)) { - delta = xatou(opt_d) * 1000; - deltanz = delta > 0 ? delta : 1; - need_seconds = (1000000 % deltanz) != 0; + G.delta = xatoi(opt_d) * 1000; + G.deltanz = G.delta > 0 ? G.delta : 1; + need_seconds = (1000000 % G.deltanz) != 0; } argv += optind; @@ -902,8 +900,8 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) last->next = s; last = s; } else { - // %NNNNd or %r option. remove it from string - strcpy(prev + strlen(prev), cur); + // %r option. remove it from string + overlapping_strcpy(prev + strlen(prev), cur); cur = prev; } } @@ -921,9 +919,9 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) // Generate first samples but do not print them, they're bogus collect_info(first); reset_outbuf(); - if (delta >= 0) { + if (G.delta >= 0) { gettimeofday(&tv, NULL); - usleep(delta > 1000000 ? 1000000 : delta - tv.tv_usec%deltanz); + usleep(G.delta > 1000000 ? 1000000 : G.delta - tv.tv_usec % G.deltanz); } while (1) { @@ -937,18 +935,18 @@ int nmeter_main(int argc UNUSED_PARAM, char **argv) // time resolution ;) // TODO: detect and avoid useless updates // (like: nothing happens except time) - if (delta >= 0) { + if (G.delta >= 0) { int rem; // can be commented out, will sacrifice sleep time precision a bit gettimeofday(&tv, NULL); if (need_seconds) - rem = delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % deltanz; + rem = G.delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % G.deltanz; else - rem = delta - tv.tv_usec%deltanz; + rem = G.delta - (unsigned)tv.tv_usec % G.deltanz; // Sometimes kernel wakes us up just a tiny bit earlier than asked // Do not go to very short sleep in this case - if (rem < delta/128) { - rem += delta; + if (rem < (unsigned)G.delta / 128) { + rem += G.delta; } usleep(rem); } -- cgit v1.2.3-55-g6feb From 6701e91d84fe499b5d87dc21790cd9d7bcb13220 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Mar 2016 15:58:16 +0100 Subject: wget: make -T timeout work on header reads too. Closes 8636 function old new delta set_alarm - 27 +27 fgets_and_trim 76 92 +16 wget_main 2610 2616 +6 open_socket 64 54 -10 Signed-off-by: Denys Vlasenko --- networking/wget.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/networking/wget.c b/networking/wget.c index 7f27e4e7b..5c12423c7 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -203,7 +203,7 @@ struct globals { const char *user_agent; /* "User-Agent" header field */ #if ENABLE_FEATURE_WGET_TIMEOUT unsigned timeout_seconds; - bool connecting; + bool die_if_timed_out; #endif int output_fd; int o_flags; @@ -333,9 +333,20 @@ static char* sanitize_string(char *s) static void alarm_handler(int sig UNUSED_PARAM) { /* This is theoretically unsafe (uses stdio and malloc in signal handler) */ - if (G.connecting) + if (G.die_if_timed_out) bb_error_msg_and_die("download timed out"); } +static void set_alarm(void) +{ + if (G.timeout_seconds) { + alarm(G.timeout_seconds); + G.die_if_timed_out = 1; + } +} +# define clear_alarm() ((void)(G.die_if_timed_out = 0)) +#else +# define set_alarm() ((void)0) +# define clear_alarm() ((void)0) #endif static FILE *open_socket(len_and_sockaddr *lsa) @@ -343,9 +354,9 @@ static FILE *open_socket(len_and_sockaddr *lsa) int fd; FILE *fp; - IF_FEATURE_WGET_TIMEOUT(alarm(G.timeout_seconds); G.connecting = 1;) + set_alarm(); fd = xconnect_stream(lsa); - IF_FEATURE_WGET_TIMEOUT(G.connecting = 0;) + clear_alarm(); /* glibc 2.4 seems to try seeking on it - ??! */ /* hopefully it understands what ESPIPE means... */ @@ -357,14 +368,15 @@ 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; char *buf_ptr; + set_alarm(); if (fgets(G.wget_buf, sizeof(G.wget_buf) - 1, fp) == NULL) bb_perror_msg_and_die("error getting response"); + clear_alarm(); buf_ptr = strchrnul(G.wget_buf, '\n'); c = *buf_ptr; -- cgit v1.2.3-55-g6feb From 3e3bfb896e0dd8a54caad9c6264e2452566b4012 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 18 Mar 2016 11:29:19 +0000 Subject: ash: fix corruption of ${#var} if $var contains UTF-8 characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As reported in bug 8506: $ X=abcdÉfghÍjklmnÓpqrstÚvwcyz $ echo ${#X} abcd26 The result should be 26. This regression was introduced by: 2015-05-18 [Ron Yorston] ash: code shrink around varvalue The length in characters was being used to discard the contents of the variable instead of the length in bytes. URL: https://bugs.busybox.net/8506 Reported-by: Martijn Dekker Signed-off-by: Ron Yorston Signed-off-by: Mike Frysinger --- shell/ash.c | 2 ++ shell/ash_test/ash-vars/var-utf8-length.right | 1 + shell/ash_test/ash-vars/var-utf8-length.tests | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 shell/ash_test/ash-vars/var-utf8-length.right create mode 100755 shell/ash_test/ash-vars/var-utf8-length.tests diff --git a/shell/ash.c b/shell/ash.c index b5a2d961d..5613e1f33 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -6692,6 +6692,8 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list) if (subtype == VSLENGTH && len > 0) { reinit_unicode_for_ash(); if (unicode_status == UNICODE_ON) { + STADJUST(-len, expdest); + discard = 0; len = unicode_strlen(p); } } diff --git a/shell/ash_test/ash-vars/var-utf8-length.right b/shell/ash_test/ash-vars/var-utf8-length.right new file mode 100644 index 000000000..6f4247a62 --- /dev/null +++ b/shell/ash_test/ash-vars/var-utf8-length.right @@ -0,0 +1 @@ +26 diff --git a/shell/ash_test/ash-vars/var-utf8-length.tests b/shell/ash_test/ash-vars/var-utf8-length.tests new file mode 100755 index 000000000..d04b2cbb6 --- /dev/null +++ b/shell/ash_test/ash-vars/var-utf8-length.tests @@ -0,0 +1,2 @@ +X=abcdÉfghÍjklmnÓpqrstÚvwcyz +echo ${#X} -- cgit v1.2.3-55-g6feb From 787972f60b08c34059de65f9ee24febaa50667a2 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 22 Mar 2016 18:15:14 -0400 Subject: ash_test: printenv: fix missing includes Signed-off-by: Mike Frysinger --- shell/ash_test/printenv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/ash_test/printenv.c b/shell/ash_test/printenv.c index c4ccda8a6..c0c5e197c 100644 --- a/shell/ash_test/printenv.c +++ b/shell/ash_test/printenv.c @@ -24,6 +24,7 @@ with Bash; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ +#include #include #include -- cgit v1.2.3-55-g6feb From b9b7aa1910907f59f1130667fbe7b870087e97f8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 22 Mar 2016 18:15:24 -0400 Subject: ash_test: ignore generated files Signed-off-by: Mike Frysinger --- shell/ash_test/.gitignore | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 shell/ash_test/.gitignore diff --git a/shell/ash_test/.gitignore b/shell/ash_test/.gitignore new file mode 100644 index 000000000..a1f937cdd --- /dev/null +++ b/shell/ash_test/.gitignore @@ -0,0 +1,7 @@ +/ash +/printenv +/recho +/zecho + +/*.fail +*.xx -- cgit v1.2.3-55-g6feb From 73dfdda92e20da718a9cb398ed762cc09c82e3a7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Mar 2016 22:12:09 +0200 Subject: grep: make errors other than "not found" result in exit code 2. Closes 8796 Signed-off-by: Denys Vlasenko --- findutils/grep.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/findutils/grep.c b/findutils/grep.c index 10b69275a..dece90c58 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -681,11 +681,15 @@ int grep_main(int argc UNUSED_PARAM, char **argv) FILE *file; int matched; llist_t *fopt = NULL; - - /* do normal option parsing */ #if ENABLE_FEATURE_GREP_CONTEXT int Copt, opts; +#endif + /* For grep, exitcode of 1 is "not found". Other errors are 2: */ + xfunc_error_retval = 2; + + /* do normal option parsing */ +#if ENABLE_FEATURE_GREP_CONTEXT /* -H unsets -h; -C unsets -A,-B; -e,-f are lists; * -m,-A,-B,-C have numeric param */ opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+"; -- cgit v1.2.3-55-g6feb From 2fb63292f7083fb259a3f8d8ee70ef8acdaed626 Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Mon, 28 Mar 2016 22:16:48 +0200 Subject: networking: properly initialize ipv6 scope id for printing it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Timo Teräs Signed-off-by: Denys Vlasenko --- networking/interface.c | 1 + 1 file changed, 1 insertion(+) diff --git a/networking/interface.c b/networking/interface.c index e5723b428..90c1449b3 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -885,6 +885,7 @@ static void ife_print6(struct interface *ptr) inet_pton(AF_INET6, addr6, (struct sockaddr *) &sap.sin6_addr); sap.sin6_family = AF_INET6; + sap.sin6_scope_id = scope; printf(" inet6 addr: %s/%d", INET6_sprint((struct sockaddr *) &sap, 1), plen); -- cgit v1.2.3-55-g6feb From 31c984dd6904a11b655879b3ad927bd9bf639192 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 28 Mar 2016 22:23:33 +0200 Subject: umount: build fix for older glibc Based on a patch by Veli-Pekka Peltola Signed-off-by: Denys Vlasenko --- util-linux/umount.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util-linux/umount.c b/util-linux/umount.c index 00910977d..30bef1686 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c @@ -30,6 +30,9 @@ #include #include +#ifndef MNT_DETACH +# define MNT_DETACH 0x00000002 +#endif #include "libbb.h" #if defined(__dietlibc__) -- cgit v1.2.3-55-g6feb From 20dd49934146bdcfdfc58ee4f8f566ecda1dda77 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Mar 2016 19:23:55 +0200 Subject: modprobe: skip non-.conf files only in subdirectories Signed-off-by: Denys Vlasenko --- modutils/modprobe.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 997ee3c67..8130c40b7 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c @@ -214,7 +214,7 @@ static void add_probe(const char *name) static int FAST_FUNC config_file_action(const char *filename, struct stat *statbuf UNUSED_PARAM, void *userdata UNUSED_PARAM, - int depth UNUSED_PARAM) + int depth) { char *tokens[3]; parser_t *p; @@ -222,15 +222,20 @@ static int FAST_FUNC config_file_action(const char *filename, int rc = TRUE; const char *base, *ext; - /* Skip files that begin with a ".". */ + /* Skip files that begin with a "." */ base = bb_basename(filename); if (base[0] == '.') goto error; - /* Skip files that do not end with a ".conf". */ - ext = strrchr(base, '.'); - if (ext == NULL || strcmp(ext + 1, "conf")) - goto error; + /* In dir recursion, skip files that do not end with a ".conf" + * depth==0: read_config("modules.{symbols,alias}") must work, + * "include FILE_NOT_ENDING_IN_CONF" must work too. + */ + if (depth != 0) { + ext = strrchr(base, '.'); + if (ext == NULL || strcmp(ext + 1, "conf")) + goto error; + } p = config_open2(filename, fopen_for_read); if (p == NULL) { @@ -275,7 +280,7 @@ static int FAST_FUNC config_file_action(const char *filename, m = get_or_add_modentry(tokens[1]); m->options = gather_options_str(m->options, tokens[2]); } else if (strcmp(tokens[0], "include") == 0) { - /* include */ + /* include / (yes, directories also must work) */ read_config(tokens[1]); } else if (ENABLE_FEATURE_MODPROBE_BLACKLIST && strcmp(tokens[0], "blacklist") == 0 @@ -292,7 +297,8 @@ static int FAST_FUNC config_file_action(const char *filename, static int read_config(const char *path) { return recursive_action(path, ACTION_RECURSE | ACTION_QUIET, - config_file_action, NULL, NULL, 1); + config_file_action, NULL, NULL, + /*depth:*/ 0); } static const char *humanly_readable_name(struct module_entry *m) -- cgit v1.2.3-55-g6feb From 9844d7e830a2c55421e27e8828d2067c50f57c23 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Mar 2016 19:27:00 +0200 Subject: Revert "networking: properly initialize ipv6 scope id for printing it" This reverts commit 2fb63292f7083fb259a3f8d8ee70ef8acdaed626. Signed-off-by: Denys Vlasenko --- networking/interface.c | 1 - 1 file changed, 1 deletion(-) diff --git a/networking/interface.c b/networking/interface.c index 90c1449b3..e5723b428 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -885,7 +885,6 @@ static void ife_print6(struct interface *ptr) inet_pton(AF_INET6, addr6, (struct sockaddr *) &sap.sin6_addr); sap.sin6_family = AF_INET6; - sap.sin6_scope_id = scope; printf(" inet6 addr: %s/%d", INET6_sprint((struct sockaddr *) &sap, 1), plen); -- cgit v1.2.3-55-g6feb From 610c4c385b38280c7bde7a48d95ec019cbfe1ab4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 30 Mar 2016 00:42:05 +0200 Subject: applet_tables: save space by removing applet name offsets The array applet_nameofs consumes two bytes per applet. It encodes nofork/noexec flags suid flags the offset of the applet name in the applet_name string Change the applet_table build tool to store the flags in two separate arrays (applet_flags and applet_suid). Replace applet_nameofs[] with a smaller version that only stores a limited number of offsets. This requires changes to the macros APPLET_IS_NOFORK, APPLET_IS_NOEXEC and APPLET_SUID. According to Valgrind the original find_applet_by_name required 353 cycles per call, averaged over all names. Adjusting the number of known offsets allows space to be traded off against execution time: KNOWN_OFFSETS cycles bytes (wrt KNOWN_OFFSETS = 0) 0 9057 - 2 4604 32 4 2407 75 8 1342 98 16 908 130 32 884 194 This patch uses KNOWN_OFFSETS = 8. v2: Remove some dead code from the applet_table tool; Treat the applet in the middle of the table as a special case. v3: Use the middle applet to adjust the start of the linear search as well as the last applet found. v4: Use an augmented linear search in find_applet_by_name. Drop the special treatment of the middle name from get_applet_name: most of the advantage now derives from the last stored value. v5: Don't store index in applet_nameofs, it can be calculated. v6: Tweaks by Denys function old new delta find_applet_by_name 25 125 +100 applet_suid - 92 +92 run_applet_no_and_exit 452 460 +8 run_applet_and_exit 695 697 +2 applet_name_compare 31 - -31 applet_nameofs 734 14 -720 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 3/1 up/down: 202/-751) Total: -549 bytes text data bss dec hex filename 925464 906 17160 943530 e65aa busybox_old 924915 906 17160 942981 e6385 busybox_unstripped Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- applets/applet_tables.c | 78 +++++++++++++++++++++++++++++++++---------- include/busybox.h | 15 +++------ libbb/appletlib.c | 82 ++++++++++++++++++++++++++++++---------------- libbb/vfork_daemon_rexec.c | 3 +- 4 files changed, 120 insertions(+), 58 deletions(-) diff --git a/applets/applet_tables.c b/applets/applet_tables.c index 92bf1e447..48544f08d 100644 --- a/applets/applet_tables.c +++ b/applets/applet_tables.c @@ -41,8 +41,6 @@ struct bb_applet { enum { NUM_APPLETS = ARRAY_SIZE(applets) }; -static int offset[NUM_APPLETS]; - static int cmp_name(const void *a, const void *b) { const struct bb_applet *aa = a; @@ -60,22 +58,37 @@ static int str_isalnum_(const char *s) return 1; } +// Before linear search, narrow it down by looking at N "equidistant" names: +// KNOWN_APPNAME_OFFSETS cycles code_size +// 0 9057 +// 2 4604 +32 +// 4 2407 +75 +// 8 1342 +98 +// 16 908 +130 +// 32 884 +194 +// With 8, applet_nameofs[] table has 7 elements. +#define KNOWN_APPNAME_OFFSETS 8 + int main(int argc, char **argv) { - int i; - int ofs; + int i, j; + int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS]; // unsigned MAX_APPLET_NAME_LEN = 1; qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name); + for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++) + index[i] = i * NUM_APPLETS / KNOWN_APPNAME_OFFSETS; + ofs = 0; for (i = 0; i < NUM_APPLETS; i++) { - offset[i] = ofs; + for (j = 0; j < KNOWN_APPNAME_OFFSETS; j++) + if (i == index[j]) + offset[j] = ofs; ofs += strlen(applets[i].name) + 1; } - /* We reuse 4 high-order bits of offset array for other purposes, - * so if they are indeed needed, refuse to proceed */ - if (ofs > 0xfff) + /* If the list of names is too long refuse to proceed */ + if (ofs > 0xffff) return 1; if (!argv[1]) return 1; @@ -94,7 +107,17 @@ int main(int argc, char **argv) printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name); printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main); } - printf("\n"); + + if (KNOWN_APPNAME_OFFSETS > 0 && NUM_APPLETS > 2*KNOWN_APPNAME_OFFSETS) { + printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS); + printf("const uint16_t applet_nameofs[] ALIGN2 = {\n"); + for (i = 1; i < KNOWN_APPNAME_OFFSETS; i++) + printf("%d,\n", offset[i]); + printf("};\n\n"); + } + else { + printf("#define KNOWN_APPNAME_OFFSETS 0\n\n"); + } //printf("#ifndef SKIP_definitions\n"); printf("const char applet_names[] ALIGN1 = \"\"\n"); @@ -119,20 +142,39 @@ int main(int argc, char **argv) printf("};\n"); printf("#endif\n\n"); - printf("const uint16_t applet_nameofs[] ALIGN2 = {\n"); - for (i = 0; i < NUM_APPLETS; i++) { - printf("0x%04x,\n", - offset[i] #if ENABLE_FEATURE_PREFER_APPLETS - + (applets[i].nofork << 12) - + (applets[i].noexec << 13) + printf("const uint8_t applet_flags[] ALIGN1 = {\n"); + i = 0; + while (i < NUM_APPLETS) { + int v = applets[i].nofork + (applets[i].noexec << 1); + if (++i < NUM_APPLETS) + v |= (applets[i].nofork + (applets[i].noexec << 1)) << 2; + if (++i < NUM_APPLETS) + v |= (applets[i].nofork + (applets[i].noexec << 1)) << 4; + if (++i < NUM_APPLETS) + v |= (applets[i].nofork + (applets[i].noexec << 1)) << 6; + printf("0x%02x,\n", v); + i++; + } + printf("};\n\n"); #endif + #if ENABLE_FEATURE_SUID - + (applets[i].need_suid << 14) /* 2 bits */ -#endif - ); + printf("const uint8_t applet_suid[] ALIGN1 = {\n"); + i = 0; + while (i < NUM_APPLETS) { + int v = applets[i].need_suid; /* 2 bits */ + if (++i < NUM_APPLETS) + v |= applets[i].need_suid << 2; + if (++i < NUM_APPLETS) + v |= applets[i].need_suid << 4; + if (++i < NUM_APPLETS) + v |= applets[i].need_suid << 6; + printf("0x%02x,\n", v); + i++; } printf("};\n\n"); +#endif #if ENABLE_FEATURE_INSTALLER printf("const uint8_t applet_install_loc[] ALIGN1 = {\n"); diff --git a/include/busybox.h b/include/busybox.h index b1e31e5ee..737627bd0 100644 --- a/include/busybox.h +++ b/include/busybox.h @@ -15,25 +15,20 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN /* Keep in sync with applets/applet_tables.c! */ extern const char applet_names[] ALIGN1; extern int (*const applet_main[])(int argc, char **argv); -extern const uint16_t applet_nameofs[]; +extern const uint8_t applet_flags[] ALIGN1; +extern const uint8_t applet_suid[] ALIGN1; extern const uint8_t applet_install_loc[] ALIGN1; -#if ENABLE_FEATURE_SUID || ENABLE_FEATURE_PREFER_APPLETS -# define APPLET_NAME(i) (applet_names + (applet_nameofs[i] & 0x0fff)) -#else -# define APPLET_NAME(i) (applet_names + applet_nameofs[i]) -#endif - #if ENABLE_FEATURE_PREFER_APPLETS -# define APPLET_IS_NOFORK(i) (applet_nameofs[i] & (1 << 12)) -# define APPLET_IS_NOEXEC(i) (applet_nameofs[i] & (1 << 13)) +# define APPLET_IS_NOFORK(i) (applet_flags[(i)/4] & (1 << (2 * ((i)%4)))) +# define APPLET_IS_NOEXEC(i) (applet_flags[(i)/4] & (1 << ((2 * ((i)%4))+1))) #else # define APPLET_IS_NOFORK(i) 0 # define APPLET_IS_NOEXEC(i) 0 #endif #if ENABLE_FEATURE_SUID -# define APPLET_SUID(i) ((applet_nameofs[i] >> 14) & 0x3) +# define APPLET_SUID(i) ((applet_suid[(i)/4] >> (2 * ((i)%4)) & 3)) #endif #if ENABLE_FEATURE_INSTALLER diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 95e589e74..aeaf238f1 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -139,36 +139,56 @@ void FAST_FUNC bb_show_usage(void) xfunc_die(); } -#if NUM_APPLETS > 8 -static int applet_name_compare(const void *name, const void *idx) -{ - int i = (int)(ptrdiff_t)idx - 1; - return strcmp(name, APPLET_NAME(i)); -} -#endif int FAST_FUNC find_applet_by_name(const char *name) { -#if NUM_APPLETS > 8 - /* Do a binary search to find the applet entry given the name. */ + unsigned i, max; + int j; const char *p; - p = bsearch(name, (void*)(ptrdiff_t)1, ARRAY_SIZE(applet_main), 1, applet_name_compare); - /* - * if (!p) return -1; - * ^^^^^^^^^^^^^^^^^^ the code below will do this if p == NULL :) - */ - return (int)(ptrdiff_t)p - 1; + + p = applet_names; + i = 0; +#if KNOWN_APPNAME_OFFSETS <= 0 + max = NUM_APPLETS; #else - /* A version which does not pull in bsearch */ - int i = 0; - const char *p = applet_names; - while (i < NUM_APPLETS) { - if (strcmp(name, p) == 0) - return i; - p += strlen(p) + 1; + max = NUM_APPLETS * KNOWN_APPNAME_OFFSETS; + for (j = ARRAY_SIZE(applet_nameofs)-1; j >= 0; j--) { + const char *pp = applet_names + applet_nameofs[j]; + if (strcmp(name, pp) >= 0) { + //bb_error_msg("name:'%s' >= pp:'%s'", name, pp); + p = pp; + i = max - NUM_APPLETS; + break; + } + max -= NUM_APPLETS; + } + max /= (unsigned)KNOWN_APPNAME_OFFSETS; + i /= (unsigned)KNOWN_APPNAME_OFFSETS; + //bb_error_msg("name:'%s' starting from:'%s' i:%u max:%u", name, p, i, max); +#endif + + /* Open-coding without strcmp/strlen calls for speed */ + while (i < max) { + char ch; + j = 0; + /* Do we see "name\0" in applet_names[p] position? */ + while ((ch = *p) == name[j]) { + if (ch == '\0') { + //bb_error_msg("found:'%s' i:%u", name, i); + return i; /* yes */ + } + p++; + j++; + } + /* No. + * p => 1st non-matching char in applet_names[], + * skip to and including NUL. + */ + while (ch != '\0') + ch = *++p; + p++; i++; } return -1; -#endif } @@ -583,6 +603,7 @@ static void install_links(const char *busybox, int use_symbolic_links, * busybox.h::bb_install_loc_t, or else... */ int (*lf)(const char *, const char *); char *fpc; + const char *appname = applet_names; unsigned i; int rc; @@ -593,7 +614,7 @@ static void install_links(const char *busybox, int use_symbolic_links, for (i = 0; i < ARRAY_SIZE(applet_main); i++) { fpc = concat_path_file( custom_install_dir ? custom_install_dir : install_dir[APPLET_INSTALL_LOC(i)], - APPLET_NAME(i)); + appname); // debug: bb_error_msg("%slinking %s to busybox", // use_symbolic_links ? "sym" : "", fpc); rc = lf(busybox, fpc); @@ -601,6 +622,8 @@ static void install_links(const char *busybox, int use_symbolic_links, bb_simple_perror_msg(fpc); } free(fpc); + while (*appname++ != '\0') + continue; } } # else @@ -754,7 +777,7 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) /* Reinit some shared global data */ xfunc_error_retval = EXIT_FAILURE; - applet_name = APPLET_NAME(applet_no); + applet_name = bb_get_last_path_component_nostrip(argv[0]); /* Special case. POSIX says "test --help" * should be no different from e.g. "test --foo". @@ -785,11 +808,14 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) void FAST_FUNC run_applet_and_exit(const char *name, char **argv) { - int applet = find_applet_by_name(name); - if (applet >= 0) - run_applet_no_and_exit(applet, argv); + int applet; + if (is_prefixed_with(name, "busybox")) exit(busybox_main(argv)); + /* find_applet_by_name() search is more expensive, so goes second */ + applet = find_applet_by_name(name); + if (applet >= 0) + run_applet_no_and_exit(applet, argv); } #endif /* !defined(SINGLE_APPLET_MAIN) */ diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index d6ca7b263..1adb5b3c4 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c @@ -116,8 +116,6 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv) save_nofork_data(&old); - applet_name = APPLET_NAME(applet_no); - xfunc_error_retval = EXIT_FAILURE; /* In case getopt() or getopt32() was already called: @@ -157,6 +155,7 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv) * need argv untouched because they free argv[i]! */ char *tmp_argv[argc+1]; memcpy(tmp_argv, argv, (argc+1) * sizeof(tmp_argv[0])); + applet_name = tmp_argv[0]; /* Finally we can call NOFORK applet's main() */ rc = applet_main[applet_no](argc, tmp_argv); } else { -- cgit v1.2.3-55-g6feb From 76b680c7a8d5a99e46ab8d9cad49aed0cfc440a7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 16:04:37 +0200 Subject: Use bb_error_msg instead of bb_info_msg in all commented-out debug printouts Signed-off-by: Denys Vlasenko --- e2fsprogs/fsck.c | 2 +- mailutils/sendmail.c | 2 +- miscutils/beep.c | 2 +- networking/udhcp/d6_packet.c | 2 +- util-linux/fbset.c | 18 +++++++++--------- util-linux/mkfs_ext2.c | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 627d2be31..8d89179e3 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c @@ -345,7 +345,7 @@ static void load_fs_info(const char *filename) // Loop through entries while (getmntent_r(fstab, &mte, buf, sizeof(buf))) { - //bb_info_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir, + //bb_error_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir, // mte.mnt_type, mte.mnt_opts, // mte.mnt_passno); create_fs_device(mte.mnt_fsname, mte.mnt_dir, diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c index 4355e4dc5..5143fac8f 100644 --- a/mailutils/sendmail.c +++ b/mailutils/sendmail.c @@ -270,7 +270,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) // G.method = xstrdup(a+1); } // N.B. list == NULL here - //bb_info_msg("OPT[%x] AU[%s], AP[%s], AM[%s], ARGV[%s]", opts, au, ap, am, *argv); + //bb_error_msg("OPT[%x] AU[%s], AP[%s], AM[%s], ARGV[%s]", opts, au, ap, am, *argv); // connect to server diff --git a/miscutils/beep.c b/miscutils/beep.c index 910e03e1b..18b160cc4 100644 --- a/miscutils/beep.c +++ b/miscutils/beep.c @@ -88,7 +88,7 @@ int beep_main(int argc, char **argv) bb_show_usage(); } while (rep) { -//bb_info_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); +//bb_error_msg("rep[%d] freq=%d, length=%d, delay=%d", rep, freq, length, delay); xioctl(speaker, KIOCSOUND, (void*)(uintptr_t)tickrate_div_freq); usleep(1000 * length); ioctl(speaker, KIOCSOUND, (void*)0); diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c index 79b2946ef..b340b5db6 100644 --- a/networking/udhcp/d6_packet.c +++ b/networking/udhcp/d6_packet.c @@ -22,7 +22,7 @@ void FAST_FUNC d6_dump_packet(struct d6_packet *packet) , packet->d6_xid32 ); //*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0'; - //bb_info_msg(" chaddr %s", buf); + //bb_error_msg(" chaddr %s", buf); } #endif diff --git a/util-linux/fbset.c b/util-linux/fbset.c index ac0082f70..09e96b763 100644 --- a/util-linux/fbset.c +++ b/util-linux/fbset.c @@ -248,12 +248,12 @@ static int read_mode_db(struct fb_var_screeninfo *base, const char *fn, if (!p) continue; s = p + strlen(mode); - //bb_info_msg("CHECK[%s][%s][%d]", mode, p-1, *s); + //bb_error_msg("CHECK[%s][%s][%d]", mode, p-1, *s); /* exact match? */ if (((!*s || isspace(*s)) && '"' != s[-1]) /* end-of-token */ || ('"' == *s && '"' == p[-1]) /* ends with " but starts with " too! */ ) { - //bb_info_msg("FOUND[%s][%s][%s][%d]", token[1], p, mode, isspace(*s)); + //bb_error_msg("FOUND[%s][%s][%s][%d]", token[1], p, mode, isspace(*s)); break; } } @@ -264,9 +264,9 @@ static int read_mode_db(struct fb_var_screeninfo *base, const char *fn, while (config_read(parser, token, 2, 1, "# \t", PARSE_NORMAL)) { int i; -//bb_info_msg("???[%s][%s]", token[0], token[1]); +//bb_error_msg("???[%s][%s]", token[0], token[1]); if (strcmp(token[0], "endmode") == 0) { -//bb_info_msg("OK[%s]", mode); +//bb_error_msg("OK[%s]", mode); return 1; } p = token[1]; @@ -294,7 +294,7 @@ static int read_mode_db(struct fb_var_screeninfo *base, const char *fn, base->yres_virtual = base_yres_virtual; base->bits_per_pixel = base_bits_per_pixel; } -//bb_info_msg("GEO[%s]", p); +//bb_error_msg("GEO[%s]", p); break; case 1: if (sizeof(int) == sizeof(base->xres)) { @@ -321,13 +321,13 @@ static int read_mode_db(struct fb_var_screeninfo *base, const char *fn, base->hsync_len = base_hsync_len; base->vsync_len = base_vsync_len; } -//bb_info_msg("TIM[%s]", p); +//bb_error_msg("TIM[%s]", p); break; case 2: case 3: { static const uint32_t syncs[] = {FB_VMODE_INTERLACED, FB_VMODE_DOUBLE}; ss(&base->vmode, syncs[i-2], p, "false"); -//bb_info_msg("VMODE[%s]", p); +//bb_error_msg("VMODE[%s]", p); break; } case 4: @@ -335,12 +335,12 @@ static int read_mode_db(struct fb_var_screeninfo *base, const char *fn, case 6: { static const uint32_t syncs[] = {FB_SYNC_VERT_HIGH_ACT, FB_SYNC_HOR_HIGH_ACT, FB_SYNC_COMP_HIGH_ACT}; ss(&base->sync, syncs[i-4], p, "low"); -//bb_info_msg("SYNC[%s]", p); +//bb_error_msg("SYNC[%s]", p); break; } case 7: ss(&base->sync, FB_SYNC_EXT, p, "false"); -//bb_info_msg("EXTSYNC[%s]", p); +//bb_error_msg("EXTSYNC[%s]", p); break; case 8: { int red_offset, red_length; diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index 3258d7eee..749f42068 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c @@ -116,7 +116,7 @@ static void allocate(uint8_t *bitmap, uint32_t blocksize, uint32_t start, uint32 { uint32_t i; -//bb_info_msg("ALLOC: [%u][%u][%u]: [%u-%u]:=[%x],[%x]", blocksize, start, end, start/8, blocksize - end/8 - 1, (1 << (start & 7)) - 1, (uint8_t)(0xFF00 >> (end & 7))); +//bb_error_msg("ALLOC: [%u][%u][%u]: [%u-%u]:=[%x],[%x]", blocksize, start, end, start/8, blocksize - end/8 - 1, (1 << (start & 7)) - 1, (uint8_t)(0xFF00 >> (end & 7))); memset(bitmap, 0, blocksize); i = start / 8; memset(bitmap, 0xFF, i); @@ -412,7 +412,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) // (a bit after 8M image size), but it works for two->three groups // transition (at 16M). if (remainder && (remainder < overhead + 50)) { -//bb_info_msg("CHOP[%u]", remainder); +//bb_error_msg("CHOP[%u]", remainder); nblocks -= remainder; goto retry; } @@ -568,7 +568,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) free_blocks = (n < blocks_per_group ? n : blocks_per_group) - overhead; // mark preallocated blocks as allocated -//bb_info_msg("ALLOC: [%u][%u][%u]", blocksize, overhead, blocks_per_group - (free_blocks + overhead)); +//bb_error_msg("ALLOC: [%u][%u][%u]", blocksize, overhead, blocks_per_group - (free_blocks + overhead)); allocate(buf, blocksize, // reserve "overhead" blocks overhead, @@ -647,7 +647,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) n = FETCH_LE32(inode->i_block[0]) + 1; for (i = 0; i < lost_and_found_blocks; ++i) STORE_LE(inode->i_block[i], i + n); // use next block -//bb_info_msg("LAST BLOCK USED[%u]", i + n); +//bb_error_msg("LAST BLOCK USED[%u]", i + n); PUT(((uint64_t)FETCH_LE32(gd[0].bg_inode_table) * blocksize) + (EXT2_GOOD_OLD_FIRST_INO-1) * inodesize, buf, inodesize); -- cgit v1.2.3-55-g6feb From 066e76befe5d39fc3451846af94cbba96747186c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 16:20:28 +0200 Subject: Replace a few more bb_info_msg's by bb_error_msg or printf Signed-off-by: Denys Vlasenko --- loginutils/chpasswd.c | 2 +- loginutils/passwd.c | 2 +- miscutils/devfsd.c | 2 +- miscutils/flash_eraseall.c | 2 +- networking/inetd.c | 8 ++++---- networking/traceroute.c | 2 +- networking/tunctl.c | 2 +- util-linux/mkfs_ext2.c | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index a022a42d6..2d268be67 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c @@ -105,7 +105,7 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) if (rc < 0) bb_error_msg_and_die("an error occurred updating password for %s", name); if (rc) - bb_info_msg("Password for '%s' changed", name); + bb_error_msg("password for '%s' changed", name); logmode = LOGMODE_STDIO; free(name); free(free_me); diff --git a/loginutils/passwd.c b/loginutils/passwd.c index 73726d3e0..52b66ca50 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -230,7 +230,7 @@ int passwd_main(int argc UNUSED_PARAM, char **argv) /* LOGMODE_BOTH */ if (rc < 0) bb_error_msg_and_die("can't update password file %s", filename); - bb_info_msg("Password for %s changed by %s", name, myname); + bb_error_msg("password for %s changed by %s", name, myname); /*if (ENABLE_FEATURE_CLEAN_UP) free(newp); - can't, it may be non-malloced */ skip: diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 9256567cc..6217918da 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -284,7 +284,7 @@ static const char bb_msg_variable_not_found[] ALIGN1 = "variable: %s not found"; /* Busybox stuff */ #if ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG -#define info_logger(p, fmt, args...) bb_info_msg(fmt, ## args) +#define info_logger(p, fmt, args...) bb_error_msg(fmt, ## args) #define msg_logger(p, fmt, args...) bb_error_msg(fmt, ## args) #define msg_logger_and_die(p, fmt, args...) bb_error_msg_and_die(fmt, ## args) #define error_logger(p, fmt, args...) bb_perror_msg(fmt, ## args) diff --git a/miscutils/flash_eraseall.c b/miscutils/flash_eraseall.c index bf9b739a1..d95d214d9 100644 --- a/miscutils/flash_eraseall.c +++ b/miscutils/flash_eraseall.c @@ -147,7 +147,7 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv) ret = ioctl(fd, MEMGETBADBLOCK, &offset); if (ret > 0) { if (!(flags & OPTION_Q)) - bb_info_msg("\nSkipping bad block at 0x%08x", erase.start); + printf("\nSkipping bad block at 0x%08x\n", erase.start); continue; } if (ret < 0) { diff --git a/networking/inetd.c b/networking/inetd.c index 243165a07..4f6673b12 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -834,10 +834,10 @@ static NOINLINE servtab_t *parse_one_line(void) goto parse_err; } -// bb_info_msg( -// "ENTRY[%s][%s][%s][%d][%d][%d][%d][%d][%s][%s][%s]", -// sep->se_local_hostname, sep->se_service, sep->se_proto, sep->se_wait, sep->se_proto_no, -// sep->se_max, sep->se_count, sep->se_time, sep->se_user, sep->se_group, sep->se_program); + //bb_error_msg( + // "ENTRY[%s][%s][%s][%d][%d][%d][%d][%d][%s][%s][%s]", + // sep->se_local_hostname, sep->se_service, sep->se_proto, sep->se_wait, sep->se_proto_no, + // sep->se_max, sep->se_count, sep->se_time, sep->se_user, sep->se_group, sep->se_program); /* check if the hostname specifier is a comma separated list * of hostnames. we'll make new entries for each address. */ diff --git a/networking/traceroute.c b/networking/traceroute.c index 642110c54..eee4f8873 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -497,7 +497,7 @@ send_probe(int seq, int ttl) res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len); if (res != len) - bb_info_msg("sent %d octets, ret=%d", len, res); + bb_error_msg("sent %d octets, ret=%d", len, res); } #if ENABLE_FEATURE_TRACEROUTE_VERBOSE diff --git a/networking/tunctl.c b/networking/tunctl.c index 3a0870eb5..941e8bbd3 100644 --- a/networking/tunctl.c +++ b/networking/tunctl.c @@ -82,7 +82,7 @@ int tunctl_main(int argc UNUSED_PARAM, char **argv) // delete? if (opts & OPT_d) { IOCTL(fd, TUNSETPERSIST, (void *)(uintptr_t)0); - bb_info_msg("Set '%s' %spersistent", ifr.ifr_name, "non"); + printf("Set '%s' nonpersistent\n", ifr.ifr_name); return EXIT_SUCCESS; } diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index 749f42068..f91a0b4bf 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c @@ -151,7 +151,7 @@ static uint32_t has_super(uint32_t x) static void PUT(uint64_t off, void *buf, uint32_t size) { -// bb_info_msg("PUT[%llu]:[%u]", off, size); + //bb_error_msg("PUT[%llu]:[%u]", off, size); xlseek(fd, off, SEEK_SET); xwrite(fd, buf, size); } -- cgit v1.2.3-55-g6feb From cde1199e01aa14f1777f97cdcb7d0de2d00add80 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 16:22:13 +0200 Subject: zcip: use bb_error_msg for logging, not bb_info_msg Signed-off-by: Denys Vlasenko --- networking/zcip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networking/zcip.c b/networking/zcip.c index 1d6910555..c93082619 100644 --- a/networking/zcip.c +++ b/networking/zcip.c @@ -176,7 +176,7 @@ static int run(char *argv[3], const char *param, uint32_t nip) xsetenv("ip", addr); fmt -= 3; } - bb_info_msg(fmt, argv[2], argv[0], addr); + bb_error_msg(fmt, argv[2], argv[0], addr); status = spawn_and_wait(argv + 1); if (status < 0) { @@ -317,7 +317,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv) #if BB_MMU bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/); #endif - bb_info_msg("start, interface %s", argv_intf); + bb_error_msg("start, interface %s", argv_intf); } // Run the dynamic address negotiation protocol, -- cgit v1.2.3-55-g6feb From 3b757f07982b38b7a550c10ca37c9d173d450cac Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 16:23:10 +0200 Subject: mkfs_vfat: use bb_error_msg for logging, not bb_info_msg This affects only a commented-out code section which searches for bad blocks Signed-off-by: Denys Vlasenko --- util-linux/mkfs_vfat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c index 7d81ed06d..d53c751eb 100644 --- a/util-linux/mkfs_vfat.c +++ b/util-linux/mkfs_vfat.c @@ -578,7 +578,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) start_data_sector = (reserved_sect + NUM_FATS * sect_per_fat) * (bytes_per_sect / SECTOR_SIZE); start_data_block = (start_data_sector + SECTORS_PER_BLOCK - 1) / SECTORS_PER_BLOCK; - bb_info_msg("searching for bad blocks "); + bb_error_msg("searching for bad blocks"); currently_testing = 0; try = TEST_BUFFER_BLOCKS; while (currently_testing < volume_size_blocks) { @@ -616,7 +616,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) } free(blkbuf); if (badblocks) - bb_info_msg("%d bad block(s)", badblocks); + bb_error_msg("%d bad block(s)", badblocks); } #endif -- cgit v1.2.3-55-g6feb From c418f48d8dd311f2c093f8f5727b93e40a512330 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 16:30:24 +0200 Subject: fsck: use printf for message, not bb_info_msg Signed-off-by: Denys Vlasenko --- e2fsprogs/fsck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 8d89179e3..987d97528 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c @@ -602,7 +602,7 @@ static void fsck_device(struct fs_info *fs /*, int interactive */) if (strcmp(fs->type, "auto") != 0) { type = fs->type; if (G.verbose > 2) - bb_info_msg("using filesystem type '%s' %s", + printf("using filesystem type '%s' %s\n", type, "from fstab"); } else if (G.fstype && (G.fstype[0] != 'n' || G.fstype[1] != 'o') /* != "no" */ @@ -612,12 +612,12 @@ static void fsck_device(struct fs_info *fs /*, int interactive */) ) { type = G.fstype; if (G.verbose > 2) - bb_info_msg("using filesystem type '%s' %s", + printf("using filesystem type '%s' %s\n", type, "from -t"); } else { type = "auto"; if (G.verbose > 2) - bb_info_msg("using filesystem type '%s' %s", + printf("using filesystem type '%s' %s\n", type, "(default)"); } -- cgit v1.2.3-55-g6feb From 8ac6effb029f1fe4f620e061c1b62c4721f41491 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 16:49:13 +0200 Subject: sulogin: Dorp incorrect comment about suid-ness Sulogin is not a suid app, should fail if run by non-root. Signed-off-by: Denys Vlasenko --- loginutils/sulogin.c | 1 - 1 file changed, 1 deletion(-) diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 19b1e304c..d2ac1f65d 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -12,7 +12,6 @@ //config: sulogin is invoked when the system goes into single user //config: mode (this is done through an entry in inittab). -//applet:/* Needs to be run by root or be suid root - needs to change uid and gid: */ //applet:IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o -- cgit v1.2.3-55-g6feb From 32c08acba3d938ec2fa4f9d2ff8160bbe05a20cb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 17:27:32 +0200 Subject: sulogin: remove suid paranoia code, explain why it's not necessary function old new delta sulogin_main 325 270 -55 Signed-off-by: Denys Vlasenko --- loginutils/sulogin.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index d2ac1f65d..33f078ae7 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -32,6 +32,14 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) struct passwd *pwd; const char *shell; + /* Note: sulogin is not a suid app. It is meant to be run by init + * for single user / emergency mode. init starts it as root. + * Normal users (potentially malisious ones) can only run it under + * their UID, therefore no paranoia here is warranted: + * $LD_LIBRARY_PATH in env, TTY = /dev/sda + * are no more dangerous here than in e.g. cp applet. + */ + logmode = LOGMODE_BOTH; openlog(applet_name, 0, LOG_AUTH); @@ -47,18 +55,9 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) dup(0); } - /* Malicious use like "sulogin /dev/sda"? */ - if (!isatty(0) || !isatty(1) || !isatty(2)) { - logmode = LOGMODE_SYSLOG; - bb_error_msg_and_die("not a tty"); - } - - /* Clear dangerous stuff, set PATH */ - sanitize_env_if_suid(); - pwd = getpwuid(0); if (!pwd) { - goto auth_error; + bb_error_msg_and_die("no password entry for root"); } while (1) { @@ -92,7 +91,4 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) /* Exec login shell with no additional parameters. Never returns. */ run_shell(shell, 1, NULL, NULL); - - auth_error: - bb_error_msg_and_die("no password entry for root"); } -- cgit v1.2.3-55-g6feb From 2a17fbe88a0cc064248db4ce8939f0fbc357922d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 17:36:20 +0200 Subject: sulogin: use bb_error_msg instead of bb_info_msg; better message Historic "System Maintenance Mode" message is a tiny bit cryptic. Let's say explicitly what we are doing: we are giving user a shell (presumably to do some maintenance in single-user mode). Signed-off-by: Denys Vlasenko --- loginutils/sulogin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 33f078ae7..f32469551 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -69,17 +69,17 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) ); if (r < 0) { /* ^D, ^C, timeout, or read error */ - bb_info_msg("Normal startup"); + bb_error_msg("normal startup"); return 0; } if (r > 0) { break; } bb_do_delay(LOGIN_FAIL_DELAY); - bb_info_msg("Login incorrect"); + bb_error_msg("Login incorrect"); } - bb_info_msg("System Maintenance Mode"); + bb_error_msg("starting shell for system maintenance"); IF_SELINUX(renew_current_security_context()); -- cgit v1.2.3-55-g6feb From 80f0f1d712fb3ab236e1fc8b37dfa7a9224d7849 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 18:17:35 +0200 Subject: setfiles: switch bb_info_msg to printf Presumably, bb_info_msg was used here for syslog logging (-l), but there is no actual code to activate syslog logging. Added a TODO note on that, so that selinux users would notice and fix if needed. Signed-off-by: Denys Vlasenko --- selinux/setfiles.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/selinux/setfiles.c b/selinux/setfiles.c index c974c4a9d..de99dfe44 100644 --- a/selinux/setfiles.c +++ b/selinux/setfiles.c @@ -17,6 +17,7 @@ //usage: ) //usage: "\n -d Show which specification matched each file" //usage: "\n -l Log changes in file labels to syslog" +//TODO: log to syslog is not yet implemented, it goes to stdout only now //usage: "\n -n Don't change any file labels" //usage: "\n -q Suppress warnings" //usage: "\n -r DIR Use an alternate root path" @@ -383,16 +384,16 @@ static int restore(const char *file) * the user has changed but the role and type are the * same. For "-vv", emit everything. */ if (verbose > 1 || !user_only_changed) { - bb_info_msg("%s: reset %s context %s->%s", + printf("%s: reset %s context %s->%s\n", applet_name, my_file, context ? context : "", newcon); } } if (FLAG_l_take_log && !user_only_changed) { if (context) - bb_info_msg("relabeling %s from %s to %s", my_file, context, newcon); + printf("relabeling %s from %s to %s\n", my_file, context, newcon); else - bb_info_msg("labeling %s to %s", my_file, newcon); + printf("labeling %s to %s\n", my_file, newcon); } if (outfile && !user_only_changed) -- cgit v1.2.3-55-g6feb From 8f2e99c813dcac25faf58162ed18848a02888ff6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 18:41:23 +0200 Subject: udhcp: get rid of bb_info_msg() function old new delta udhcpd_main 1501 1531 +30 d6_recv_raw_packet 251 264 +13 perform_d6_release 188 198 +10 udhcpc6_main 2443 2449 +6 udhcp_recv_raw_packet 582 588 +6 udhcp_recv_kernel_packet 132 138 +6 send_d6_renew 140 146 +6 d6_recv_kernel_packet 118 124 +6 send_renew 77 82 +5 send_discover 85 90 +5 send_decline 84 89 +5 send_d6_select 97 102 +5 send_d6_discover 174 179 +5 perform_release 167 172 +5 count_lines 72 74 +2 udhcpc_main 2836 2837 +1 bb_info_msg 125 - -125 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 17/4 up/down: 117/-180) Total: -63 bytes text data bss dec hex filename 924935 906 17160 943001 e6399 busybox_old 924736 906 17160 942802 e62d2 busybox_unstripped Signed-off-by: Denys Vlasenko --- include/libbb.h | 1 - libbb/Kbuild.src | 1 - libbb/info_msg.c | 62 ----------------------------------- networking/udhcp/arpping.c | 2 +- networking/udhcp/common.c | 8 ++--- networking/udhcp/common.h | 6 ++-- networking/udhcp/d6_dhcpc.c | 60 +++++++++++++++++----------------- networking/udhcp/d6_packet.c | 10 +++--- networking/udhcp/d6_socket.c | 2 +- networking/udhcp/dhcpc.c | 70 ++++++++++++++++++++-------------------- networking/udhcp/dhcpd.c | 34 +++++++++---------- networking/udhcp/files.c | 2 +- networking/udhcp/leases.c | 2 +- networking/udhcp/packet.c | 12 +++---- networking/udhcp/socket.c | 4 +-- networking/udhcp/static_leases.c | 2 +- 16 files changed, 107 insertions(+), 171 deletions(-) delete mode 100644 libbb/info_msg.c diff --git a/include/libbb.h b/include/libbb.h index 8b226c00c..98d788402 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1150,7 +1150,6 @@ extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; extern void bb_perror_nomsg(void) FAST_FUNC; -extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC; extern void bb_logenv_override(void) FAST_FUNC; diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index 7fb687227..b08ce1158 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src @@ -46,7 +46,6 @@ lib-y += get_volsize.o lib-y += herror_msg.o lib-y += human_readable.o lib-y += inet_common.o -lib-y += info_msg.o lib-y += inode_hash.o lib-y += isdirectory.o lib-y += kernel_version.o diff --git a/libbb/info_msg.c b/libbb/info_msg.c deleted file mode 100644 index 56ca2efd4..000000000 --- a/libbb/info_msg.c +++ /dev/null @@ -1,62 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999-2004 by Erik Andersen - * - * Licensed under GPLv2 or later, see file LICENSE in this source tree. - */ - -#include "libbb.h" -#if ENABLE_FEATURE_SYSLOG -# include -#endif - -void FAST_FUNC bb_info_msg(const char *s, ...) -{ -#ifdef THIS_ONE_DOESNT_DO_SINGLE_WRITE - va_list p; - /* va_copy is used because it is not portable - * to use va_list p twice */ - va_list p2; - - va_start(p, s); - va_copy(p2, p); - if (logmode & LOGMODE_STDIO) { - vprintf(s, p); - fputs(msg_eol, stdout); - } -# if ENABLE_FEATURE_SYSLOG - if (logmode & LOGMODE_SYSLOG) - vsyslog(LOG_INFO, s, p2); -# endif - va_end(p2); - va_end(p); -#else - int used; - char *msg; - va_list p; - - if (logmode == 0) - return; - - va_start(p, s); - used = vasprintf(&msg, s, p); - va_end(p); - if (used < 0) - return; - -# if ENABLE_FEATURE_SYSLOG - if (logmode & LOGMODE_SYSLOG) - syslog(LOG_INFO, "%s", msg); -# endif - if (logmode & LOGMODE_STDIO) { - fflush_all(); - /* used = strlen(msg); - must be true already */ - msg[used++] = '\n'; - full_write(STDOUT_FILENO, msg, used); - } - - free(msg); -#endif -} diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index fad2283c3..c98027316 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c @@ -132,6 +132,6 @@ int FAST_FUNC arpping(uint32_t test_nip, ret: close(s); - log1("%srp reply received for this address", rv ? "No a" : "A"); + log1("%srp reply received for this address", rv ? "no a" : "A"); return rv; } diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 680852ce4..1c1863451 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c @@ -183,7 +183,7 @@ static void log_option(const char *pfx, const uint8_t *opt) if (dhcp_verbose >= 2) { char buf[256 * 2 + 2]; *bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0'; - bb_info_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf); + bb_error_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf); } } #else @@ -269,7 +269,7 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code) } /* log3 because udhcpc uses it a lot - very noisy */ - log3("Option 0x%02x not found", code); + log3("option 0x%02x not found", code); return NULL; } @@ -402,7 +402,7 @@ static NOINLINE void attach_option( struct option_set *new, **curr; /* make a new option */ - log2("Attaching option %02x to list", optflag->code); + log2("attaching option %02x to list", optflag->code); new = xmalloc(sizeof(*new)); new->data = xmalloc(length + OPT_DATA); new->data[OPT_CODE] = optflag->code; @@ -422,7 +422,7 @@ static NOINLINE void attach_option( unsigned old_len; /* add it to an existing option */ - log2("Attaching option %02x to existing member of list", optflag->code); + log2("attaching option %02x to existing member of list", optflag->code); old_len = existing->data[OPT_LEN]; if (old_len + length < 255) { /* actually 255 is ok too, but adding a space can overlow it */ diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index d20659e2f..496ab11a1 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -256,16 +256,16 @@ struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code) #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 # define IF_UDHCP_VERBOSE(...) __VA_ARGS__ extern unsigned dhcp_verbose; -# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0) +# define log1(...) do { if (dhcp_verbose >= 1) bb_error_msg(__VA_ARGS__); } while (0) # if CONFIG_UDHCP_DEBUG >= 2 void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC; -# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0) +# define log2(...) do { if (dhcp_verbose >= 2) bb_error_msg(__VA_ARGS__); } while (0) # else # define udhcp_dump_packet(...) ((void)0) # define log2(...) ((void)0) # endif # if CONFIG_UDHCP_DEBUG >= 3 -# define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0) +# define log3(...) do { if (dhcp_verbose >= 3) bb_error_msg(__VA_ARGS__); } while (0) # else # define log3(...) ((void)0) # endif diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 4e9b705b9..422254d62 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -251,7 +251,7 @@ static void d6_run_script(struct d6_packet *packet, const char *name) envp = fill_envp(packet); /* call script */ - log1("Executing %s %s", client_config.script, name); + log1("executing %s %s", client_config.script, name); argv[0] = (char*) client_config.script; argv[1] = (char*) name; argv[2] = NULL; @@ -428,7 +428,7 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct in6_addr *requested_ip */ opt_ptr = add_d6_client_options(opt_ptr); - bb_info_msg("Sending discover..."); + bb_error_msg("sending %s", "discover"); return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); } @@ -481,7 +481,7 @@ static NOINLINE int send_d6_select(uint32_t xid) */ opt_ptr = add_d6_client_options(opt_ptr); - bb_info_msg("Sending select..."); + bb_error_msg("sending %s", "select"); return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); } @@ -550,7 +550,7 @@ static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, st */ opt_ptr = add_d6_client_options(opt_ptr); - bb_info_msg("Sending renew..."); + bb_error_msg("sending %s", "renew"); if (server_ipv6) return d6_send_kernel_packet( &packet, (opt_ptr - (uint8_t*) &packet), @@ -573,7 +573,7 @@ static int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cu /* IA NA (contains our current IP) */ opt_ptr = d6_store_blob(opt_ptr, client6_data.ia_na, client6_data.ia_na->len + 2+2); - bb_info_msg("Sending release..."); + bb_error_msg("sending %s", "release"); return d6_send_kernel_packet( &packet, (opt_ptr - (uint8_t*) &packet), our_cur_ipv6, CLIENT_PORT6, @@ -592,19 +592,19 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6 bytes = safe_read(fd, &packet, sizeof(packet)); if (bytes < 0) { - log1("Packet read error, ignoring"); + log1("packet read error, ignoring"); /* NB: possible down interface, etc. Caller should pause. */ return bytes; /* returns -1 */ } if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) { - log1("Packet is too short, ignoring"); + log1("packet is too short, ignoring"); return -2; } if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) { /* packet is bigger than sizeof(packet), we did partial read */ - log1("Oversized packet, ignoring"); + log1("oversized packet, ignoring"); return -2; } @@ -618,7 +618,7 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6 /* || bytes > (int) sizeof(packet) - can't happen */ || packet.udp.len != packet.ip6.ip6_plen ) { - log1("Unrelated/bogus packet, ignoring"); + log1("unrelated/bogus packet, ignoring"); return -2; } @@ -630,11 +630,11 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6 // check = packet.udp.check; // packet.udp.check = 0; // if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { -// log1("Packet with bad UDP checksum received, ignoring"); +// log1("packet with bad UDP checksum received, ignoring"); // return -2; // } - log1("Received a packet"); + log1("received %s", "a packet"); d6_dump_packet(&packet.data); bytes -= sizeof(packet.ip6) + sizeof(packet.udp); @@ -722,10 +722,10 @@ static int d6_raw_socket(int ifindex) }; #endif - log1("Opening raw socket on ifindex %d", ifindex); //log2? + log1("opening raw socket on ifindex %d", ifindex); //log2? fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)); - log1("Got raw socket fd %d", fd); //log2? + log1("got raw socket fd %d", fd); //log2? sock.sll_family = AF_PACKET; sock.sll_protocol = htons(ETH_P_IPV6); @@ -738,18 +738,18 @@ static int d6_raw_socket(int ifindex) /* Ignoring error (kernel may lack support for this) */ if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, sizeof(filter_prog)) >= 0) - log1("Attached filter to raw socket fd %d", fd); // log? + log1("attached filter to raw socket fd %d", fd); // log? } #endif - log1("Created raw socket"); + log1("created raw socket"); return fd; } static void change_listen_mode(int new_mode) { - log1("Entering listen mode: %s", + log1("entering listen mode: %s", new_mode != LISTEN_NONE ? (new_mode == LISTEN_KERNEL ? "kernel" : "raw") : "none" @@ -770,7 +770,7 @@ static void change_listen_mode(int new_mode) /* Called only on SIGUSR1 */ static void perform_renew(void) { - bb_info_msg("Performing a DHCP renew"); + bb_error_msg("performing DHCP renew"); switch (state) { case BOUND: change_listen_mode(LISTEN_KERNEL); @@ -794,11 +794,11 @@ static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *ou { /* send release packet */ if (state == BOUND || state == RENEWING || state == REBINDING) { - bb_info_msg("Unicasting a release"); + bb_error_msg("unicasting a release"); send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */ d6_run_script(NULL, "deconfig"); } - bb_info_msg("Entering released state"); + bb_error_msg("entering released state"); change_listen_mode(LISTEN_NONE); state = RELEASED; @@ -1034,7 +1034,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) /* Create pidfile */ write_pidfile(client_config.pidfile); /* Goes to stdout (unless NOMMU) and possibly syslog */ - bb_info_msg("%s (v"BB_VER") started", applet_name); + bb_error_msg("started, v"BB_VER); /* Set up the signal pipe */ udhcp_sp_setup(); /* We want random_xid to be random... */ @@ -1074,7 +1074,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) retval = 0; /* If we already timed out, fall through with retval = 0, else... */ if ((int)tv.tv_sec > 0) { - log1("Waiting on select %u seconds", (int)tv.tv_sec); + log1("waiting on select %u seconds", (int)tv.tv_sec); timestamp_before_wait = (unsigned)monotonic_sec(); retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); if (retval < 0) { @@ -1124,14 +1124,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) d6_run_script(NULL, "leasefail"); #if BB_MMU /* -b is not supported on NOMMU */ if (opt & OPT_b) { /* background if no lease */ - bb_info_msg("No lease, forking to background"); + bb_error_msg("no lease, forking to background"); client_background(); /* do not background again! */ opt = ((opt & ~OPT_b) | OPT_f); } else #endif if (opt & OPT_n) { /* abort if no lease */ - bb_info_msg("No lease, failing"); + bb_error_msg("no lease, failing"); retval = 1; goto ret; } @@ -1159,7 +1159,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) state = RENEWING; client_config.first_secs = 0; /* make secs field count from 0 */ change_listen_mode(LISTEN_KERNEL); - log1("Entering renew state"); + log1("entering renew state"); /* fall right through */ case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ case_RENEW_REQUESTED: @@ -1179,7 +1179,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) continue; } /* Timed out, enter rebinding state */ - log1("Entering rebinding state"); + log1("entering rebinding state"); state = REBINDING; /* fall right through */ case REBINDING: @@ -1194,7 +1194,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) continue; } /* Timed out, enter init state */ - bb_info_msg("Lease lost, entering init state"); + bb_error_msg("lease lost, entering init state"); d6_run_script(NULL, "deconfig"); state = INIT_SELECTING; client_config.first_secs = 0; /* make secs field count from 0 */ @@ -1242,7 +1242,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) timeout = INT_MAX; continue; case SIGTERM: - bb_info_msg("Received SIGTERM"); + bb_error_msg("received %s", "SIGTERM"); goto ret0; } @@ -1260,7 +1260,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd); if (len == -1) { /* Error is severe, reopen socket */ - bb_info_msg("Read error: %s, reopening socket", strerror(errno)); + bb_error_msg("read error: %s, reopening socket", strerror(errno)); sleep(discover_timeout); /* 3 seconds by default */ change_listen_mode(listen_mode); /* just close and reopen */ } @@ -1298,7 +1298,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE); if (option && option->data[4] != 0) { /* return to init state */ - bb_info_msg("Received DHCP NAK (%u)", option->data[4]); + bb_error_msg("received DHCP NAK (%u)", option->data[4]); d6_run_script(&packet, "nak"); if (state != REQUESTING) d6_run_script(NULL, "deconfig"); @@ -1453,7 +1453,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) lease_seconds = 0x0fffffff; /* enter bound state */ timeout = lease_seconds / 2; - bb_info_msg("Lease obtained, lease time %u", + bb_error_msg("lease obtained, lease time %u", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); d6_run_script(&packet, state == REQUESTING ? "bound" : "renew"); diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c index b340b5db6..e166f520d 100644 --- a/networking/udhcp/d6_packet.c +++ b/networking/udhcp/d6_packet.c @@ -17,8 +17,8 @@ void FAST_FUNC d6_dump_packet(struct d6_packet *packet) if (dhcp_verbose < 2) return; - bb_info_msg( - " xid %x" + bb_error_msg( + "xid %x" , packet->d6_xid32 ); //*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0'; @@ -35,15 +35,15 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6 memset(packet, 0, sizeof(*packet)); bytes = safe_read(fd, packet, sizeof(*packet)); if (bytes < 0) { - log1("Packet read error, ignoring"); + log1("packet read error, ignoring"); return bytes; /* returns -1 */ } if (bytes < offsetof(struct d6_packet, d6_options)) { - bb_info_msg("Packet with bad magic, ignoring"); + bb_error_msg("packet with bad magic, ignoring"); return -2; } - log1("Received a packet"); + log1("received %s", "a packet"); d6_dump_packet(packet); return bytes; diff --git a/networking/udhcp/d6_socket.c b/networking/udhcp/d6_socket.c index 56f69f6a1..910f296a3 100644 --- a/networking/udhcp/d6_socket.c +++ b/networking/udhcp/d6_socket.c @@ -13,7 +13,7 @@ int FAST_FUNC d6_listen_socket(int port, const char *inf) int fd; struct sockaddr_in6 addr; - log1("Opening listen socket on *:%d %s", port, inf); + log1("opening listen socket on *:%d %s", port, inf); fd = xsocket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); setsockopt_reuseaddr(fd); diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index dfd5ca606..660b943ce 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -561,7 +561,7 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name) envp = fill_envp(packet); /* call script */ - log1("Executing %s %s", client_config.script, name); + log1("executing %s %s", client_config.script, name); argv[0] = (char*) client_config.script; argv[1] = (char*) name; argv[2] = NULL; @@ -714,7 +714,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) */ add_client_options(&packet); - bb_info_msg("Sending discover..."); + bb_error_msg("sending %s", "discover"); return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); } @@ -758,7 +758,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste add_client_options(&packet); addr.s_addr = requested; - bb_info_msg("Sending select for %s...", inet_ntoa(addr)); + bb_error_msg("sending select for %s", inet_ntoa(addr)); return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); } @@ -797,7 +797,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) */ add_client_options(&packet); - bb_info_msg("Sending renew..."); + bb_error_msg("sending %s", "renew"); return bcast_or_ucast(&packet, ciaddr, server); } @@ -826,7 +826,7 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); - bb_info_msg("Sending decline..."); + bb_error_msg("sending %s", "decline"); return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); } #endif @@ -846,7 +846,7 @@ static int send_release(uint32_t server, uint32_t ciaddr) udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); - bb_info_msg("Sending release..."); + bb_error_msg("sending %s", "release"); /* 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. @@ -881,7 +881,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) if (bytes < 0) { if (errno == EINTR) continue; - log1("Packet read error, ignoring"); + log1("packet read error, ignoring"); /* NB: possible down interface, etc. Caller should pause. */ return bytes; /* returns -1 */ } @@ -889,13 +889,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) } if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { - log1("Packet is too short, ignoring"); + log1("packet is too short, ignoring"); return -2; } if (bytes < ntohs(packet.ip.tot_len)) { /* packet is bigger than sizeof(packet), we did partial read */ - log1("Oversized packet, ignoring"); + log1("oversized packet, ignoring"); return -2; } @@ -910,7 +910,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) /* || bytes > (int) sizeof(packet) - can't happen */ || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) ) { - log1("Unrelated/bogus packet, ignoring"); + log1("unrelated/bogus packet, ignoring"); return -2; } @@ -918,7 +918,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) check = packet.ip.check; packet.ip.check = 0; if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) { - log1("Bad IP header checksum, ignoring"); + log1("bad IP header checksum, ignoring"); return -2; } @@ -943,17 +943,17 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) check = packet.udp.check; packet.udp.check = 0; if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { - log1("Packet with bad UDP checksum received, ignoring"); + log1("packet with bad UDP checksum received, ignoring"); return -2; } skip_udp_sum_check: if (packet.data.cookie != htonl(DHCP_MAGIC)) { - bb_info_msg("Packet with bad magic, ignoring"); + bb_error_msg("packet with bad magic, ignoring"); return -2; } - log1("Received a packet"); + log1("received %s", "a packet"); udhcp_dump_packet(&packet.data); bytes -= sizeof(packet.ip) + sizeof(packet.udp); @@ -992,14 +992,14 @@ static int udhcp_raw_socket(int ifindex) int fd; struct sockaddr_ll sock; - log1("Opening raw socket on ifindex %d", ifindex); //log2? + log1("opening raw socket on ifindex %d", ifindex); //log2? fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); /* ^^^^^ * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them) * ETH_P_IP: want to receive only packets with IPv4 eth type */ - log1("Got raw socket fd"); //log2? + log1("got raw socket fd"); //log2? sock.sll_family = AF_PACKET; sock.sll_protocol = htons(ETH_P_IP); @@ -1055,23 +1055,23 @@ static int udhcp_raw_socket(int ifindex) /* Ignoring error (kernel may lack support for this) */ if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, sizeof(filter_prog)) >= 0) - log1("Attached filter to raw socket fd"); // log? + log1("attached filter to raw socket fd"); // log? } #endif if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) { if (errno != ENOPROTOOPT) - log1("Can't set PACKET_AUXDATA on raw socket"); + log1("can't set PACKET_AUXDATA on raw socket"); } - log1("Created raw socket"); + log1("created raw socket"); return fd; } static void change_listen_mode(int new_mode) { - log1("Entering listen mode: %s", + log1("entering listen mode: %s", new_mode != LISTEN_NONE ? (new_mode == LISTEN_KERNEL ? "kernel" : "raw") : "none" @@ -1092,7 +1092,7 @@ static void change_listen_mode(int new_mode) /* Called only on SIGUSR1 */ static void perform_renew(void) { - bb_info_msg("Performing a DHCP renew"); + bb_error_msg("performing DHCP renew"); switch (state) { case BOUND: change_listen_mode(LISTEN_KERNEL); @@ -1122,12 +1122,12 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) temp_addr.s_addr = server_addr; strcpy(buffer, inet_ntoa(temp_addr)); temp_addr.s_addr = requested_ip; - bb_info_msg("Unicasting a release of %s to %s", + bb_error_msg("unicasting a release of %s to %s", inet_ntoa(temp_addr), buffer); send_release(server_addr, requested_ip); /* unicast */ udhcp_run_script(NULL, "deconfig"); } - bb_info_msg("Entering released state"); + bb_error_msg("entering released state"); change_listen_mode(LISTEN_NONE); state = RELEASED; @@ -1395,7 +1395,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) /* Create pidfile */ write_pidfile(client_config.pidfile); /* Goes to stdout (unless NOMMU) and possibly syslog */ - bb_info_msg("%s (v"BB_VER") started", applet_name); + bb_error_msg("started, v"BB_VER); /* Set up the signal pipe */ udhcp_sp_setup(); /* We want random_xid to be random... */ @@ -1434,7 +1434,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) retval = 0; /* If we already timed out, fall through with retval = 0, else... */ if ((int)tv.tv_sec > 0) { - log1("Waiting on select %u seconds", (int)tv.tv_sec); + log1("waiting on select %u seconds", (int)tv.tv_sec); timestamp_before_wait = (unsigned)monotonic_sec(); retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); if (retval < 0) { @@ -1485,14 +1485,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) udhcp_run_script(NULL, "leasefail"); #if BB_MMU /* -b is not supported on NOMMU */ if (opt & OPT_b) { /* background if no lease */ - bb_info_msg("No lease, forking to background"); + bb_error_msg("no lease, forking to background"); client_background(); /* do not background again! */ opt = ((opt & ~OPT_b) | OPT_f); } else #endif if (opt & OPT_n) { /* abort if no lease */ - bb_info_msg("No lease, failing"); + bb_error_msg("no lease, failing"); retval = 1; goto ret; } @@ -1520,7 +1520,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) state = RENEWING; client_config.first_secs = 0; /* make secs field count from 0 */ change_listen_mode(LISTEN_KERNEL); - log1("Entering renew state"); + log1("entering renew state"); /* fall right through */ case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ case_RENEW_REQUESTED: @@ -1540,7 +1540,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) continue; } /* Timed out, enter rebinding state */ - log1("Entering rebinding state"); + log1("entering rebinding state"); state = REBINDING; /* fall right through */ case REBINDING: @@ -1555,7 +1555,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) continue; } /* Timed out, enter init state */ - bb_info_msg("Lease lost, entering init state"); + bb_error_msg("lease lost, entering init state"); udhcp_run_script(NULL, "deconfig"); state = INIT_SELECTING; client_config.first_secs = 0; /* make secs field count from 0 */ @@ -1603,7 +1603,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) timeout = INT_MAX; continue; case SIGTERM: - bb_info_msg("Received SIGTERM"); + bb_error_msg("received %s", "SIGTERM"); goto ret0; } @@ -1621,7 +1621,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) len = udhcp_recv_raw_packet(&packet, sockfd); if (len == -1) { /* Error is severe, reopen socket */ - bb_info_msg("Read error: %s, reopening socket", strerror(errno)); + bb_error_msg("read error: %s, reopening socket", strerror(errno)); sleep(discover_timeout); /* 3 seconds by default */ change_listen_mode(listen_mode); /* just close and reopen */ } @@ -1744,7 +1744,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) client_config.interface, arpping_ms) ) { - bb_info_msg("Offered address is in use " + bb_error_msg("offered address is in use " "(got ARP reply), declining"); send_decline(/*xid,*/ server_addr, packet.yiaddr); @@ -1763,7 +1763,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) #endif /* enter bound state */ temp_addr.s_addr = packet.yiaddr; - bb_info_msg("Lease of %s obtained, lease time %u", + bb_error_msg("lease of %s obtained, lease time %u", inet_ntoa(temp_addr), (unsigned)lease_seconds); requested_ip = packet.yiaddr; @@ -1817,7 +1817,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) goto non_matching_svid; } /* return to init state */ - bb_info_msg("Received DHCP NAK"); + bb_error_msg("received %s", "DHCP NAK"); udhcp_run_script(&packet, "nak"); if (state != REQUESTING) udhcp_run_script(NULL, "deconfig"); diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 2de074f9b..79677ee93 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -61,11 +61,11 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc || (dhcp_pkt->flags & htons(BROADCAST_FLAG)) || dhcp_pkt->ciaddr == 0 ) { - log1("Broadcasting packet to client"); + log1("broadcasting packet to client"); ciaddr = INADDR_BROADCAST; chaddr = MAC_BCAST_ADDR; } else { - log1("Unicasting packet to client ciaddr"); + log1("unicasting packet to client ciaddr"); ciaddr = dhcp_pkt->ciaddr; chaddr = dhcp_pkt->chaddr; } @@ -79,7 +79,7 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc /* Send a packet to gateway_nip using the kernel ip stack */ static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt) { - log1("Forwarding packet to relay"); + log1("forwarding packet to relay"); udhcp_send_kernel_packet(dhcp_pkt, server_config.server_nip, SERVER_PORT, @@ -214,7 +214,7 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket, add_server_options(&packet); addr.s_addr = packet.yiaddr; - bb_info_msg("Sending OFFER of %s", inet_ntoa(addr)); + bb_error_msg("sending OFFER of %s", inet_ntoa(addr)); /* send_packet emits error message itself if it detects failure */ send_packet(&packet, /*force_bcast:*/ 0); } @@ -226,7 +226,7 @@ static NOINLINE void send_NAK(struct dhcp_packet *oldpacket) init_packet(&packet, oldpacket, DHCPNAK); - log1("Sending NAK"); + log1("sending NAK"); send_packet(&packet, /*force_bcast:*/ 1); } @@ -247,7 +247,7 @@ static NOINLINE void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr) add_server_options(&packet); addr.s_addr = yiaddr; - bb_info_msg("Sending ACK to %s", inet_ntoa(addr)); + bb_error_msg("sending ACK to %s", inet_ntoa(addr)); send_packet(&packet, /*force_bcast:*/ 0); p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME); @@ -361,7 +361,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) write_pidfile(server_config.pidfile); /* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */ - bb_info_msg("%s (v"BB_VER") started", applet_name); + bb_error_msg("started, v"BB_VER); option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME); server_config.max_lease_sec = DEFAULT_LEASE_TIME; @@ -427,18 +427,18 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) goto continue_with_autotime; } if (retval < 0 && errno != EINTR) { - log1("Error on select"); + log1("error on select"); continue; } switch (udhcp_sp_read(&rfds)) { case SIGUSR1: - bb_info_msg("Received SIGUSR1"); + bb_error_msg("received %s", "SIGUSR1"); write_leases(); /* why not just reset the timeout, eh */ goto continue_with_autotime; case SIGTERM: - bb_info_msg("Received SIGTERM"); + bb_error_msg("received %s", "SIGTERM"); write_leases(); goto ret0; case 0: /* no signal: read a packet */ @@ -451,7 +451,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) if (bytes < 0) { /* bytes can also be -2 ("bad packet data") */ if (bytes == -1 && errno != EINTR) { - log1("Read error: %s, reopening socket", strerror(errno)); + log1("read error: %s, reopening socket", strerror(errno)); close(server_socket); server_socket = -1; } @@ -486,7 +486,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) /* Look for a static/dynamic lease */ static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr); if (static_lease_nip) { - bb_info_msg("Found static lease: %x", static_lease_nip); + bb_error_msg("found static lease: %x", static_lease_nip); memcpy(&fake_lease.lease_mac, &packet.chaddr, 6); fake_lease.lease_nip = static_lease_nip; fake_lease.expires = 0; @@ -504,13 +504,13 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) switch (state[0]) { case DHCPDISCOVER: - log1("Received DISCOVER"); + log1("received %s", "DISCOVER"); send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms); break; case DHCPREQUEST: - log1("Received REQUEST"); + log1("received %s", "REQUEST"); /* RFC 2131: o DHCPREQUEST generated during SELECTING state: @@ -635,7 +635,7 @@ o DHCPREQUEST generated during REBINDING state: * chaddr must be filled in, * ciaddr must be 0 (we do not check this) */ - log1("Received DECLINE"); + log1("received %s", "DECLINE"); if (server_id_opt && requested_ip_opt && lease /* chaddr matches this lease */ @@ -655,7 +655,7 @@ o DHCPREQUEST generated during REBINDING state: * chaddr must be filled in, * ciaddr must be filled in */ - log1("Received RELEASE"); + log1("received %s", "RELEASE"); if (server_id_opt && lease /* chaddr matches this lease */ && packet.ciaddr == lease->lease_nip @@ -665,7 +665,7 @@ o DHCPREQUEST generated during REBINDING state: break; case DHCPINFORM: - log1("Received INFORM"); + log1("received %s", "INFORM"); send_inform(&packet); break; } diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 5b90e26d2..7b57c6258 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c @@ -226,7 +226,7 @@ void FAST_FUNC read_leases(const char *file) #endif } } - log1("Read %d leases", i); + log1("read %d leases", i); ret: close(fd); } diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index 411b74962..6642e396d 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c @@ -133,7 +133,7 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigne return r; temp.s_addr = nip; - bb_info_msg("%s belongs to someone, reserving it for %u seconds", + bb_error_msg("%s belongs to someone, reserving it for %u seconds", inet_ntoa(temp), (unsigned)server_config.conflict_time); add_lease(NULL, nip, server_config.conflict_time, NULL, 0); return 0; diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 148f52551..0a31f2643 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c @@ -38,8 +38,8 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet) if (dhcp_verbose < 2) return; - bb_info_msg( - //" op %x" + bb_error_msg( + //"op %x" //" htype %x" " hlen %x" //" hops %x" @@ -73,7 +73,7 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet) //, packet->options[] ); *bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0'; - bb_info_msg(" chaddr %s", buf); + bb_error_msg("chaddr %s", buf); } #endif @@ -85,17 +85,17 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd) memset(packet, 0, sizeof(*packet)); bytes = safe_read(fd, packet, sizeof(*packet)); if (bytes < 0) { - log1("Packet read error, ignoring"); + log1("packet read error, ignoring"); return bytes; /* returns -1 */ } if (bytes < offsetof(struct dhcp_packet, options) || packet->cookie != htonl(DHCP_MAGIC) ) { - bb_info_msg("Packet with bad magic, ignoring"); + bb_error_msg("packet with bad magic, ignoring"); return -2; } - log1("Received a packet"); + log1("received %s", "a packet"); udhcp_dump_packet(packet); return bytes; diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index a42106960..4fd79f423 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c @@ -56,7 +56,7 @@ int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t close(fd); return -1; } - log1("Adapter index %d", ifr->ifr_ifindex); + log1("adapter index %d", ifr->ifr_ifindex); *ifindex = ifr->ifr_ifindex; } @@ -82,7 +82,7 @@ int FAST_FUNC udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) struct sockaddr_in addr; char *colon; - log1("Opening listen socket on *:%d %s", port, inf); + log1("opening listen socket on *:%d %s", port, inf); fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); setsockopt_reuseaddr(fd); diff --git a/networking/udhcp/static_leases.c b/networking/udhcp/static_leases.c index f4a24ab62..b7f9e5c59 100644 --- a/networking/udhcp/static_leases.c +++ b/networking/udhcp/static_leases.c @@ -66,7 +66,7 @@ void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp) cur = *st_lease_pp; while (cur) { - bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", + bb_error_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", cur->mac[0], cur->mac[1], cur->mac[2], cur->mac[3], cur->mac[4], cur->mac[5], cur->nip -- cgit v1.2.3-55-g6feb From 16efe191289ea7507410c343342486b6ea918024 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 18:44:52 +0200 Subject: dhcpd: string reuse Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 79677ee93..2671ea3e2 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -226,7 +226,7 @@ static NOINLINE void send_NAK(struct dhcp_packet *oldpacket) init_packet(&packet, oldpacket, DHCPNAK); - log1("sending NAK"); + log1("sending %s", "NAK"); send_packet(&packet, /*force_bcast:*/ 1); } -- cgit v1.2.3-55-g6feb From f75a96d74c2e87d0f11995466683b0bf316b9973 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 30 Mar 2016 18:49:45 +0200 Subject: udhcp: fix capitalization of two messages Signed-off-by: Denys Vlasenko --- networking/udhcp/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 1c1863451..0cf4dab63 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c @@ -257,7 +257,7 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code) continue; /* complain and return NULL */ if (optionptr[OPT_CODE] == code) { - log_option("Option found", optionptr); + log_option("option found", optionptr); return optionptr + OPT_DATA; } @@ -303,7 +303,7 @@ void FAST_FUNC udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addo addopt[OPT_CODE]); return; } - log_option("Adding option", addopt); + log_option("adding option", addopt); memcpy(optionptr + end, addopt, len); optionptr[end + len] = DHCP_END; } -- cgit v1.2.3-55-g6feb From a27dc33f976b15ccfe9180d652ed16579638c48c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 31 Mar 2016 00:32:39 +0200 Subject: make MKPASSWD a separate config option, not an automatic alias to cryptpw Signed-off-by: Denys Vlasenko --- loginutils/cryptpw.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c index 55dcc2914..23a1884f4 100644 --- a/loginutils/cryptpw.c +++ b/loginutils/cryptpw.c @@ -14,13 +14,22 @@ //config: default y //config: help //config: Encrypts the given password with the crypt(3) libc function +//config: using the given salt. +//config: +//config:config MKPASSWD +//config: bool "mkpasswd" +//config: default y +//config: help +//config: Encrypts the given password with the crypt(3) libc function //config: using the given salt. Debian has this utility under mkpasswd //config: name. Busybox provides mkpasswd as an alias for cryptpw. //applet:IF_CRYPTPW(APPLET(cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP)) -//applet:IF_CRYPTPW(APPLET_ODDNAME(mkpasswd, cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP, mkpasswd)) +// APPLET_ODDNAME:name main location suid_type help +//applet:IF_MKPASSWD(APPLET_ODDNAME(mkpasswd, cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP, cryptpw)) //kbuild:lib-$(CONFIG_CRYPTPW) += cryptpw.o +//kbuild:lib-$(CONFIG_MKPASSWD) += cryptpw.o //usage:#define cryptpw_trivial_usage //usage: "[OPTIONS] [PASSWORD] [SALT]" @@ -40,25 +49,6 @@ //usage: "\n -S SALT" //usage: ) -/* mkpasswd is an alias to cryptpw */ -//usage:#define mkpasswd_trivial_usage -//usage: "[OPTIONS] [PASSWORD] [SALT]" -/* We do support -s, we just don't mention it */ -//usage:#define mkpasswd_full_usage "\n\n" -//usage: "Crypt PASSWORD using crypt(3)\n" -//usage: IF_LONG_OPTS( -//usage: "\n -P,--password-fd=N Read password from fd N" -/* //usage: "\n -s,--stdin Use stdin; like -P0" */ -//usage: "\n -m,--method=TYPE Encryption method" -//usage: "\n -S,--salt=SALT" -//usage: ) -//usage: IF_NOT_LONG_OPTS( -//usage: "\n -P N Read password from fd N" -/* //usage: "\n -s Use stdin; like -P0" */ -//usage: "\n -m TYPE Encryption method TYPE" -//usage: "\n -S SALT" -//usage: ) - #include "libbb.h" /* Debian has 'mkpasswd' utility, manpage says: @@ -140,7 +130,7 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv) if (!password) { /* Only mkpasswd, and only from tty, prompts. * Otherwise it is a plain read. */ - password = (isatty(STDIN_FILENO) && applet_name[0] == 'm') + password = (ENABLE_MKPASSWD && isatty(STDIN_FILENO) && applet_name[0] == 'm') ? bb_ask_stdin("Password: ") : xmalloc_fgetline(stdin) ; -- cgit v1.2.3-55-g6feb From 52977a7d600c7db0f7c4935fd501427fd6b580d0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 31 Mar 2016 00:42:57 +0200 Subject: Rename FEATURE_INITRD to LINUXRC and make it separate, not an alias to init Signed-off-by: Denys Vlasenko --- configs/TEST_nommu_defconfig | 2 +- configs/TEST_noprintf_defconfig | 2 +- configs/TEST_rh9_defconfig | 2 +- configs/android2_defconfig | 2 +- configs/android_502_defconfig | 2 +- configs/android_defconfig | 2 +- configs/android_ndk_defconfig | 2 +- configs/cygwin_defconfig | 2 +- configs/freebsd_defconfig | 2 +- init/halt.c | 2 +- init/init.c | 41 +++++++++++++++++++++-------------------- 11 files changed, 31 insertions(+), 30 deletions(-) diff --git a/configs/TEST_nommu_defconfig b/configs/TEST_nommu_defconfig index b45afd956..5f822e598 100644 --- a/configs/TEST_nommu_defconfig +++ b/configs/TEST_nommu_defconfig @@ -390,7 +390,7 @@ CONFIG_FEATURE_INIT_SCTTY=y CONFIG_FEATURE_INIT_SYSLOG=y CONFIG_FEATURE_EXTRA_QUIET=y CONFIG_FEATURE_INIT_COREDUMPS=y -CONFIG_FEATURE_INITRD=y +CONFIG_LINUXRC=y CONFIG_HALT=y # CONFIG_FEATURE_CALL_TELINIT is not set CONFIG_TELINIT_PATH="" diff --git a/configs/TEST_noprintf_defconfig b/configs/TEST_noprintf_defconfig index 809b60cd8..c56781e32 100644 --- a/configs/TEST_noprintf_defconfig +++ b/configs/TEST_noprintf_defconfig @@ -395,7 +395,7 @@ CONFIG_FEATURE_KILL_DELAY=0 # CONFIG_FEATURE_INIT_SYSLOG is not set # CONFIG_FEATURE_EXTRA_QUIET is not set # CONFIG_FEATURE_INIT_COREDUMPS is not set -# CONFIG_FEATURE_INITRD is not set +# CONFIG_LINUXRC is not set # CONFIG_HALT is not set # CONFIG_FEATURE_CALL_TELINIT is not set CONFIG_TELINIT_PATH="" diff --git a/configs/TEST_rh9_defconfig b/configs/TEST_rh9_defconfig index 565b826d0..28daa6273 100644 --- a/configs/TEST_rh9_defconfig +++ b/configs/TEST_rh9_defconfig @@ -407,7 +407,7 @@ CONFIG_FEATURE_INIT_SCTTY=y CONFIG_FEATURE_INIT_SYSLOG=y CONFIG_FEATURE_EXTRA_QUIET=y CONFIG_FEATURE_INIT_COREDUMPS=y -CONFIG_FEATURE_INITRD=y +CONFIG_LINUXRC=y CONFIG_HALT=y # CONFIG_FEATURE_CALL_TELINIT is not set CONFIG_TELINIT_PATH="" diff --git a/configs/android2_defconfig b/configs/android2_defconfig index 1095094fe..fbc0da091 100644 --- a/configs/android2_defconfig +++ b/configs/android2_defconfig @@ -425,7 +425,7 @@ CONFIG_FEATURE_INIT_SCTTY=y CONFIG_FEATURE_INIT_SYSLOG=y CONFIG_FEATURE_EXTRA_QUIET=y CONFIG_FEATURE_INIT_COREDUMPS=y -CONFIG_FEATURE_INITRD=y +CONFIG_LINUXRC=y CONFIG_INIT_TERMINAL_TYPE="linux" CONFIG_MESG=y CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y diff --git a/configs/android_502_defconfig b/configs/android_502_defconfig index c5146c719..7ef1585fb 100644 --- a/configs/android_502_defconfig +++ b/configs/android_502_defconfig @@ -532,7 +532,7 @@ CONFIG_FEATURE_INIT_SCTTY=y CONFIG_FEATURE_INIT_SYSLOG=y CONFIG_FEATURE_EXTRA_QUIET=y CONFIG_FEATURE_INIT_COREDUMPS=y -CONFIG_FEATURE_INITRD=y +CONFIG_LINUXRC=y CONFIG_INIT_TERMINAL_TYPE="linux" CONFIG_FEATURE_INIT_MODIFY_CMDLINE=y CONFIG_MESG=y diff --git a/configs/android_defconfig b/configs/android_defconfig index 082994b6c..4e0224207 100644 --- a/configs/android_defconfig +++ b/configs/android_defconfig @@ -448,7 +448,7 @@ CONFIG_FEATURE_INIT_SCTTY=y CONFIG_FEATURE_INIT_SYSLOG=y CONFIG_FEATURE_EXTRA_QUIET=y CONFIG_FEATURE_INIT_COREDUMPS=y -CONFIG_FEATURE_INITRD=y +CONFIG_LINUXRC=y CONFIG_INIT_TERMINAL_TYPE="linux" CONFIG_MESG=y CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y diff --git a/configs/android_ndk_defconfig b/configs/android_ndk_defconfig index 63fafb468..d657d33e9 100644 --- a/configs/android_ndk_defconfig +++ b/configs/android_ndk_defconfig @@ -458,7 +458,7 @@ CONFIG_FEATURE_INIT_SCTTY=y CONFIG_FEATURE_INIT_SYSLOG=y CONFIG_FEATURE_EXTRA_QUIET=y CONFIG_FEATURE_INIT_COREDUMPS=y -CONFIG_FEATURE_INITRD=y +CONFIG_LINUXRC=y CONFIG_INIT_TERMINAL_TYPE="linux" CONFIG_MESG=y CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y diff --git a/configs/cygwin_defconfig b/configs/cygwin_defconfig index 2c02be743..38d580ad1 100644 --- a/configs/cygwin_defconfig +++ b/configs/cygwin_defconfig @@ -425,7 +425,7 @@ CONFIG_FEATURE_KILL_DELAY=0 # CONFIG_FEATURE_INIT_SYSLOG is not set # CONFIG_FEATURE_EXTRA_QUIET is not set # CONFIG_FEATURE_INIT_COREDUMPS is not set -# CONFIG_FEATURE_INITRD is not set +# CONFIG_LINUXRC is not set CONFIG_INIT_TERMINAL_TYPE="" CONFIG_MESG=y CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y diff --git a/configs/freebsd_defconfig b/configs/freebsd_defconfig index ec3ed03c4..ae62f1389 100644 --- a/configs/freebsd_defconfig +++ b/configs/freebsd_defconfig @@ -422,7 +422,7 @@ CONFIG_FEATURE_KILL_DELAY=0 # CONFIG_FEATURE_INIT_SYSLOG is not set # CONFIG_FEATURE_EXTRA_QUIET is not set # CONFIG_FEATURE_INIT_COREDUMPS is not set -# CONFIG_FEATURE_INITRD is not set +# CONFIG_LINUXRC is not set CONFIG_INIT_TERMINAL_TYPE="" # CONFIG_MESG is not set diff --git a/init/halt.c b/init/halt.c index ad12d9148..572d751b0 100644 --- a/init/halt.c +++ b/init/halt.c @@ -135,7 +135,7 @@ int halt_main(int argc UNUSED_PARAM, char **argv) if (!(flags & 4)) { /* no -f */ //TODO: I tend to think that signalling linuxrc is wrong // pity original author didn't comment on it... - if (ENABLE_FEATURE_INITRD) { + if (ENABLE_LINUXRC) { /* talk to linuxrc */ /* bbox init/linuxrc assumed */ pid_t *pidlist = find_pid_by_name("linuxrc"); diff --git a/init/init.c b/init/init.c index 25bfaec8c..6eb76b80e 100644 --- a/init/init.c +++ b/init/init.c @@ -16,10 +16,21 @@ //config: help //config: init is the first program run when the system boots. //config: +//config:config LINUXRC +//config: bool "Support running init from within an initrd (not initramfs)" +//config: default y +//config: select FEATURE_SYSLOG +//config: help +//config: Legacy support for running init under the old-style initrd. Allows +//config: the name linuxrc to act as init, and it doesn't assume init is PID 1. +//config: +//config: This does not apply to initramfs, which runs /init as PID 1 and +//config: requires no special support. +//config: //config:config FEATURE_USE_INITTAB //config: bool "Support reading an inittab file" //config: default y -//config: depends on INIT +//config: depends on INIT || LINUXRC //config: help //config: Allow init to read an inittab file when the system boot. //config: @@ -46,7 +57,7 @@ //config:config FEATURE_INIT_SCTTY //config: bool "Run commands with leading dash with controlling tty" //config: default y -//config: depends on INIT +//config: depends on INIT || LINUXRC //config: help //config: If this option is enabled, init will try to give a controlling //config: tty to any command which has leading hyphen (often it's "-/bin/sh"). @@ -61,40 +72,29 @@ //config:config FEATURE_INIT_SYSLOG //config: bool "Enable init to write to syslog" //config: default y -//config: depends on INIT +//config: depends on INIT || LINUXRC //config: //config:config FEATURE_EXTRA_QUIET //config: bool "Be _extra_ quiet on boot" //config: default y -//config: depends on INIT +//config: depends on INIT || LINUXRC //config: help //config: Prevent init from logging some messages to the console during boot. //config: //config:config FEATURE_INIT_COREDUMPS //config: bool "Support dumping core for child processes (debugging only)" //config: default y -//config: depends on INIT +//config: depends on INIT || LINUXRC //config: help //config: If this option is enabled and the file /.init_enable_core //config: exists, then init will call setrlimit() to allow unlimited //config: core file sizes. If this option is disabled, processes //config: will not generate any core files. //config: -//config:config FEATURE_INITRD -//config: bool "Support running init from within an initrd (not initramfs)" -//config: default y -//config: depends on INIT -//config: help -//config: Legacy support for running init under the old-style initrd. Allows -//config: the name linuxrc to act as init, and it doesn't assume init is PID 1. -//config: -//config: This does not apply to initramfs, which runs /init as PID 1 and -//config: requires no special support. -//config: //config:config INIT_TERMINAL_TYPE //config: string "Initial terminal type" //config: default "linux" -//config: depends on INIT +//config: depends on INIT || LINUXRC //config: help //config: This is the initial value set by init for the TERM environment //config: variable. This variable is used by programs which make use of @@ -106,7 +106,7 @@ //config:config FEATURE_INIT_MODIFY_CMDLINE //config: bool "Modify the command-line to \"init\"" //config: default y -//config: depends on INIT +//config: depends on INIT || LINUXRC //config: help //config: When launched as PID 1 and after parsing its arguments, init //config: wipes all the arguments but argv[0] and rewrites argv[0] to @@ -119,9 +119,10 @@ //config: retrieved in /proc/1/cmdline on Linux, for example. //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)) +//applet:IF_LINUXRC(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) //kbuild:lib-$(CONFIG_INIT) += init.o +//kbuild:lib-$(CONFIG_LINUXRC) += init.o #define DEBUG_SEGV_HANDLER 0 @@ -1057,7 +1058,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) if (!DEBUG_INIT) { /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ if (getpid() != 1 - && (!ENABLE_FEATURE_INITRD || applet_name[0] != 'l') /* not linuxrc? */ + && (!ENABLE_LINUXRC || applet_name[0] != 'l') /* not linuxrc? */ ) { bb_error_msg_and_die("must be run as PID 1"); } -- cgit v1.2.3-55-g6feb From 29b33b63d49be88200f794d832450a4c71e85a5e Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Fri, 1 Apr 2016 19:41:13 +0200 Subject: unshare: new applet function old new delta unshare_main - 873 +873 .rodata 154444 155131 +687 packed_usage 30329 30520 +191 unshare_longopts - 106 +106 mount_namespaces - 99 +99 mount_or_die - 51 +51 ns_list - 48 +48 wait_for_exitstatus - 41 +41 opt_str - 17 +17 applet_names 2510 2518 +8 applet_main 2912 2920 +8 applet_suid 91 92 +1 applet_install_loc 182 183 +1 ------------------------------------------------------------------------------ (add/remove: 8/0 grow/shrink: 6/0 up/down: 2131/0) Total: 2131 bytes text data bss dec hex filename 826110 4070 9080 839260 cce5c busybox_old 827961 4078 9080 841119 cd59f busybox_unstripped Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- util-linux/unshare.c | 380 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 380 insertions(+) create mode 100644 util-linux/unshare.c diff --git a/util-linux/unshare.c b/util-linux/unshare.c new file mode 100644 index 000000000..f1a9cdf19 --- /dev/null +++ b/util-linux/unshare.c @@ -0,0 +1,380 @@ +/* vi: set sw=4 ts=4: */ +/* + * Mini unshare implementation for busybox. + * + * Copyright (C) 2016 by Bartosz Golaszewski + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ + +//config:config UNSHARE +//config: bool "unshare" +//config: default y +//config: depends on LONG_OPTS && !NOMMU +//config: select PLATFORM_LINUX +//config: help +//config: Run program with some namespaces unshared from parent. + +// depends on LONG_OPTS: it is awkward to exclude code which handles --propagation +// and --setgroups based on LONG_OPTS, so instead applet requires LONG_OPTS. +// depends on !NOMMU: we need fork() + +//applet:IF_UNSHARE(APPLET(unshare, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_UNSHARE) += unshare.o + +//usage:#define unshare_trivial_usage +//usage: "[OPTIONS] [PROG [ARGS]]" +//usage:#define unshare_full_usage "\n" +//usage: "\n -m, --mount[=FILE] Unshare mount namespace" +//usage: "\n -u, --uts[=FILE] Unshare UTS namespace (hostname etc.)" +//usage: "\n -i, --ipc[=FILE] Unshare System V IPC namespace" +//usage: "\n -n, --net[=FILE] Unshare network namespace" +//usage: "\n -p, --pid[=FILE] Unshare PID namespace" +//usage: "\n -U, --user[=FILE} Unshare user namespace" +//usage: "\n -f, --fork Fork before execing PROG" +//usage: "\n -r, --map-root-user Map current user to root (implies -u)" +//usage: "\n --mount-proc[=DIR] Mount /proc filesystem first (implies -m)" +//usage: "\n --propagation slave|shared|private|unchanged" +//usage: "\n Modify mount propagation in mount namespace" +//usage: "\n --setgroups allow|deny Control the setgroups syscall in user namespaces" + +#include +#include +#include "libbb.h" + +static void mount_or_die(const char *source, const char *target, + const char *fstype, unsigned long mountflags) +{ + if (mount(source, target, fstype, mountflags, NULL)) { + bb_perror_msg_and_die("can't mount %s on %s (flags:0x%lx)", + source, target, mountflags); + /* fstype is always either NULL or "proc". + * "proc" is only used to mount /proc. + * No need to clutter up error message with fstype, + * it is easily deductible. + */ + } +} + +// TODO: move to libbb +static int wait_for_exitstatus(pid_t pid) +{ + int exit_status, n; + + n = safe_waitpid(pid, &exit_status, 0); + if (n < 0) + bb_perror_msg_and_die("waitpid"); + return exit_status; +} + +/* + * Longest possible path to a procfs file used in unshare. Must be able to + * contain the '/proc/' string, the '/ns/user' string which is the longest + * namespace name and a 32-bit integer representing the process ID. + */ +#define PATH_PROC_SETGROUPS "/proc/self/setgroups" +#define PATH_PROC_UIDMAP "/proc/self/uid_map" +#define PATH_PROC_GIDMAP "/proc/self/gid_map" + +struct namespace_descr { + int flag; + const char nsfile4[4]; +}; + +struct namespace_ctx { + char *path; +}; + +enum { + OPT_mount = 1 << 0, + OPT_uts = 1 << 1, + OPT_ipc = 1 << 2, + OPT_network = 1 << 3, + OPT_pid = 1 << 4, + OPT_user = 1 << 5, /* OPT_user, NS_USR_POS, and ns_list[] index must match! */ + OPT_fork = 1 << 6, + OPT_map_root = 1 << 7, + OPT_mount_proc = 1 << 8, + OPT_propagation = 1 << 9, + OPT_setgroups = 1 << 10, +}; +enum { + NS_MNT_POS = 0, + NS_UTS_POS, + NS_IPC_POS, + NS_NET_POS, + NS_PID_POS, + NS_USR_POS, /* OPT_user, NS_USR_POS, and ns_list[] index must match! */ + NS_COUNT, +}; +static const struct namespace_descr ns_list[] = { + { CLONE_NEWNS, "mnt" }, + { CLONE_NEWUTS, "uts" }, + { CLONE_NEWIPC, "ipc" }, + { CLONE_NEWNET, "net" }, + { CLONE_NEWPID, "pid" }, + { CLONE_NEWUSER, "user" }, /* OPT_user, NS_USR_POS, and ns_list[] index must match! */ +}; + +/* + * Upstream unshare doesn't support short options for --mount-proc, + * --propagation, --setgroups. + * Optional arguments (namespace mountpoints) exist only for long opts, + * we are forced to use "fake" letters for them. + * '+': stop at first non-option. + */ +static const char opt_str[] = "+muinpU""fr""\xfd::""\xfe:""\xff:"; +static const char unshare_longopts[] ALIGN1 = + "mount\0" Optional_argument "\xf0" + "uts\0" Optional_argument "\xf1" + "ipc\0" Optional_argument "\xf2" + "network\0" Optional_argument "\xf3" + "pid\0" Optional_argument "\xf4" + "user\0" Optional_argument "\xf5" + "fork\0" No_argument "f" + "map-root-user\0" No_argument "r" + "mount-proc\0" Optional_argument "\xfd" + "propagation\0" Required_argument "\xfe" + "setgroups\0" Required_argument "\xff" +; + +/* Ugly-looking string reuse trick */ +#define PRIVATE_STR "private\0""unchanged\0""shared\0""slave\0" +#define PRIVATE_UNCHANGED_SHARED_SLAVE PRIVATE_STR + +static unsigned long parse_propagation(const char *prop_str) +{ + int i = index_in_strings(PRIVATE_UNCHANGED_SHARED_SLAVE, prop_str); + if (i < 0) + bb_error_msg_and_die("unrecognized: --%s=%s", "propagation", prop_str); + if (i == 0) + return MS_REC | MS_PRIVATE; + if (i == 1) + return 0; + if (i == 2) + return MS_REC | MS_SHARED; + return MS_REC | MS_SLAVE; +} + +static void mount_namespaces(pid_t pid, struct namespace_ctx *ns_ctx_list) +{ + const struct namespace_descr *ns; + struct namespace_ctx *ns_ctx; + int i; + + for (i = 0; i < NS_COUNT; i++) { + char nsf[sizeof("/proc/%u/ns/AAAA") + sizeof(int)*3]; + + ns = &ns_list[i]; + ns_ctx = &ns_ctx_list[i]; + if (!ns_ctx->path) + continue; + sprintf(nsf, "/proc/%u/ns/%.4s", (unsigned)pid, ns->nsfile4); + mount_or_die(nsf, ns_ctx->path, NULL, MS_BIND); + } +} + +int unshare_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int unshare_main(int argc UNUSED_PARAM, char **argv) +{ + int i; + unsigned int opts; + int unsflags; + uintptr_t need_mount; + const char *proc_mnt_target; + const char *prop_str; + const char *setgrp_str; + unsigned long prop_flags; + uid_t reuid = geteuid(); + gid_t regid = getegid(); + struct fd_pair fdp; + pid_t child = child; /* for compiler */ + struct namespace_ctx ns_ctx_list[NS_COUNT]; + + memset(ns_ctx_list, 0, sizeof(ns_ctx_list)); + proc_mnt_target = "/proc"; + prop_str = PRIVATE_STR; + setgrp_str = NULL; + + opt_complementary = + "\xf0""m" /* long opts (via their "fake chars") imply short opts */ + ":\xf1""u" + ":\xf2""i" + ":\xf3""n" + ":\xf4""p" + ":\xf5""U" + ":ru" /* --map-root-user or -r implies -u */ + ":\xfd""m" /* --mount-proc implies -m */ + ; + applet_long_options = unshare_longopts; + opts = getopt32(argv, opt_str, + &proc_mnt_target, &prop_str, &setgrp_str, + &ns_ctx_list[NS_MNT_POS].path, + &ns_ctx_list[NS_UTS_POS].path, + &ns_ctx_list[NS_IPC_POS].path, + &ns_ctx_list[NS_NET_POS].path, + &ns_ctx_list[NS_PID_POS].path, + &ns_ctx_list[NS_USR_POS].path + ); + argv += optind; + //bb_error_msg("opts:0x%x", opts); + //bb_error_msg("mount:%s", ns_ctx_list[NS_MNT_POS].path); + //bb_error_msg("proc_mnt_target:%s", proc_mnt_target); + //bb_error_msg("prop_str:%s", prop_str); + //bb_error_msg("setgrp_str:%s", setgrp_str); + //exit(1); + + if (setgrp_str) { + if (strcmp(setgrp_str, "allow") == 0) { + if (opts & OPT_map_root) { + bb_error_msg_and_die( + "--setgroups=allow and --map-root-user " + "are mutually exclusive" + ); + } + } else { + /* It's not "allow", must be "deny" */ + if (strcmp(setgrp_str, "deny") != 0) + bb_error_msg_and_die("unrecognized: --%s=%s", + "setgroups", setgrp_str); + } + } + + unsflags = 0; + need_mount = 0; + for (i = 0; i < NS_COUNT; i++) { + const struct namespace_descr *ns = &ns_list[i]; + struct namespace_ctx *ns_ctx = &ns_ctx_list[i]; + + if (opts & (1 << i)) + unsflags |= ns->flag; + + need_mount |= (uintptr_t)(ns_ctx->path); + } + /* need_mount != 0 if at least one FILE was given */ + + prop_flags = MS_REC | MS_PRIVATE; + /* Silently ignore --propagation if --mount is not requested. */ + if (opts & OPT_mount) + prop_flags = parse_propagation(prop_str); + + /* + * Special case: if we were requested to unshare the mount namespace + * AND to make any namespace persistent (by bind mounting it) we need + * to spawn a child process which will wait for the parent to call + * unshare(), then mount parent's namespaces while still in the + * previous namespace. + */ + fdp.wr = -1; + if (need_mount && (opts & OPT_mount)) { + /* + * Can't use getppid() in child, as we can be unsharing the + * pid namespace. + */ + pid_t ppid = getpid(); + + xpiped_pair(fdp); + + child = xfork(); + if (child == 0) { + /* Child */ + close(fdp.wr); + + /* Wait until parent calls unshare() */ + read(fdp.rd, ns_ctx_list, 1); /* ...using bogus buffer */ + /*close(fdp.rd);*/ + + /* Mount parent's unshared namespaces. */ + mount_namespaces(ppid, ns_ctx_list); + return EXIT_SUCCESS; + } + /* Parent continues */ + } + + if (unshare(unsflags) != 0) + bb_perror_msg_and_die("unshare(0x%x)", unsflags); + + if (fdp.wr >= 0) { + close(fdp.wr); /* Release child */ + /*close(fdp.rd);*/ + } + + if (need_mount) { + /* Wait for the child to finish mounting the namespaces. */ + if (opts & OPT_mount) { + int exit_status = wait_for_exitstatus(child); + if (WIFEXITED(exit_status) && + WEXITSTATUS(exit_status) != EXIT_SUCCESS) + return WEXITSTATUS(exit_status); + } else { + /* + * Regular way - we were requested to mount some other + * namespaces: mount them after the call to unshare(). + */ + mount_namespaces(getpid(), ns_ctx_list); + } + } + + /* + * When we're unsharing the pid namespace, it's not the process that + * calls unshare() that is put into the new namespace, but its first + * child. The user may want to use this option to spawn a new process + * that'll become PID 1 in this new namespace. + */ + if (opts & OPT_fork) { + pid_t pid = xfork(); + if (pid > 0) { + /* Parent */ + int exit_status = wait_for_exitstatus(pid); + if (WIFSIGNALED(exit_status)) + kill_myself_with_sig(WTERMSIG(exit_status)); + return WEXITSTATUS(exit_status); + } + /* Child continues */ + } + + if (opts & OPT_map_root) { + char uidmap_buf[sizeof("%u 0 1") + sizeof(int)*3]; + + /* + * Since Linux 3.19 unprivileged writing of /proc/self/gid_map + * has been disabled unless /proc/self/setgroups is written + * first to permanently disable the ability to call setgroups + * in that user namespace. + */ + xopen_xwrite_close(PATH_PROC_SETGROUPS, "deny"); + sprintf(uidmap_buf, "%u 0 1", (unsigned)reuid); + xopen_xwrite_close(PATH_PROC_UIDMAP, uidmap_buf); + sprintf(uidmap_buf, "%u 0 1", (unsigned)regid); + xopen_xwrite_close(PATH_PROC_GIDMAP, uidmap_buf); + } else + if (setgrp_str) { + /* Write "allow" or "deny" */ + xopen_xwrite_close(PATH_PROC_SETGROUPS, setgrp_str); + } + + if (opts & OPT_mount) { + mount_or_die("none", "/", NULL, prop_flags); + } + + if (opts & OPT_mount_proc) { + /* + * When creating a new pid namespace, we might want the pid + * subdirectories in /proc to remain consistent with the new + * process IDs. Without --mount-proc the pids in /proc would + * still reflect the old pid namespace. This is why we make + * /proc private here and then do a fresh mount. + */ + mount_or_die("none", proc_mnt_target, NULL, MS_PRIVATE | MS_REC); + mount_or_die("proc", proc_mnt_target, "proc", MS_NOSUID | MS_NOEXEC | MS_NODEV); + } + + if (argv[0]) { + BB_EXECVP_or_die(argv); + } + /* unshare from util-linux 2.27.1, despite not documenting it, + * runs a login shell (argv0="-sh") if no PROG is given + */ + run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL); +} -- cgit v1.2.3-55-g6feb From c4199f22d0f7793b70db51c01783f0d45afce3d4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 1 Apr 2016 22:12:44 +0200 Subject: libbb: two new functions: wait_for_exitstatus(pid), xfchdir(fd) Bartosz Golaszewski proposed xfchdir() Signed-off-by: Denys Vlasenko --- archival/libarchive/data_extract_to_command.c | 3 +-- include/libbb.h | 2 ++ libbb/xfuncs.c | 12 ++++++++++++ libbb/xfuncs_printf.c | 6 ++++++ runit/chpst.c | 3 +-- util-linux/unshare.c | 11 ----------- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/archival/libarchive/data_extract_to_command.c b/archival/libarchive/data_extract_to_command.c index 6f5317a0e..5d8769382 100644 --- a/archival/libarchive/data_extract_to_command.c +++ b/archival/libarchive/data_extract_to_command.c @@ -112,8 +112,7 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle) bb_copyfd_exact_size(archive_handle->src_fd, p[1], -file_header->size); close(p[1]); - if (safe_waitpid(pid, &status, 0) == -1) - bb_perror_msg_and_die("waitpid"); + status = wait_for_exitstatus(pid); if (WIFEXITED(status) && WEXITSTATUS(status)) bb_error_msg_and_die("'%s' returned status %d", archive_handle->tar__to_command, WEXITSTATUS(status)); diff --git a/include/libbb.h b/include/libbb.h index 98d788402..5b4280e34 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -500,6 +500,7 @@ 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 xfchdir(int fd) FAST_FUNC; void xchroot(const char *path) FAST_FUNC; void xsetenv(const char *key, const char *value) FAST_FUNC; void bb_unsetenv(const char *key) FAST_FUNC; @@ -1021,6 +1022,7 @@ pid_t wait_any_nohang(int *wstat) FAST_FUNC; * if (rc > 0) bb_error_msg("exit code: %d", rc & 0xff); */ int wait4pid(pid_t pid) FAST_FUNC; +int wait_for_exitstatus(pid_t pid) FAST_FUNC; /* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */ int spawn_and_wait(char **argv) FAST_FUNC; /* Does NOT check that applet is NOFORK, just blindly runs it */ diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 206edb4a0..3f9a84ad4 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -315,3 +315,15 @@ int FAST_FUNC wait4pid(pid_t pid) return WTERMSIG(status) + 0x180; return 0; } + +// Useful when we do know that pid is valid, and we just want to wait +// for it to exit. Not existing pid is fatal. waitpid() status is not returned. +int FAST_FUNC wait_for_exitstatus(pid_t pid) +{ + int exit_status, n; + + n = safe_waitpid(pid, &exit_status, 0); + if (n < 0) + bb_perror_msg_and_die("waitpid"); + return exit_status; +} diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 73488908d..4aa1b5ce2 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -390,6 +390,12 @@ void FAST_FUNC xchdir(const char *path) bb_perror_msg_and_die("can't change directory to '%s'", path); } +void FAST_FUNC xfchdir(int fd) +{ + if (fchdir(fd)) + bb_perror_msg_and_die("fchdir"); +} + void FAST_FUNC xchroot(const char *path) { if (chroot(path)) diff --git a/runit/chpst.c b/runit/chpst.c index 301cdd08a..7fe5151db 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -255,8 +255,7 @@ static NOINLINE void edir(const char *directory_name) xsetenv(d->d_name, buf); } closedir(dir); - if (fchdir(wdir) == -1) - bb_perror_msg_and_die("fchdir"); + xfchdir(wdir); close(wdir); } diff --git a/util-linux/unshare.c b/util-linux/unshare.c index f1a9cdf19..b8cd4676a 100644 --- a/util-linux/unshare.c +++ b/util-linux/unshare.c @@ -57,17 +57,6 @@ static void mount_or_die(const char *source, const char *target, } } -// TODO: move to libbb -static int wait_for_exitstatus(pid_t pid) -{ - int exit_status, n; - - n = safe_waitpid(pid, &exit_status, 0); - if (n < 0) - bb_perror_msg_and_die("waitpid"); - return exit_status; -} - /* * Longest possible path to a procfs file used in unshare. Must be able to * contain the '/proc/' string, the '/ns/user' string which is the longest -- cgit v1.2.3-55-g6feb From 80c934a2517f7bfc7642da6555d7ca01bc6f2edd Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Fri, 1 Apr 2016 22:17:25 +0200 Subject: nsenter: new applet function old new delta nsenter_main - 663 +663 .rodata 155147 155612 +465 packed_usage 30536 30708 +172 nsenter_longopts - 116 +116 open_by_path_or_target - 58 +58 applet_names 2518 2526 +8 applet_main 2920 2928 +8 ------------------------------------------------------------------------------ (add/remove: 4/0 grow/shrink: 4/0 up/down: 1490/0) Total: 1490 bytes text data bss dec hex filename 827956 4078 9080 841114 cd59a busybox_old 829214 4086 9080 842380 cda8c busybox_unstripped Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- util-linux/nsenter.c | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 util-linux/nsenter.c diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c new file mode 100644 index 000000000..9c1dabaa8 --- /dev/null +++ b/util-linux/nsenter.c @@ -0,0 +1,286 @@ +/* vi: set sw=4 ts=4: */ +/* + * Mini nsenter implementation for busybox. + * + * Copyright (C) 2016 by Bartosz Golaszewski + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ + +//config:config NSENTER +//config: bool "nsenter" +//config: default y +//config: select PLATFORM_LINUX +//config: help +//config: Run program with namespaces of other processes. +//config: +//config:config FEATURE_NSENTER_LONG_OPTS +//config: bool "Enable long options" +//config: default y +//config: depends on NSENTER && LONG_OPTS +//config: help +//config: Support long options for the nsenter applet. This makes +//config: the busybox implementation more compatible with upstream. + +//applet:IF_NSENTER(APPLET(nsenter, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_NSENTER) += nsenter.o + +//usage:#define nsenter_trivial_usage +//usage: "[OPTIONS] [PROG [ARGS]]" +//usage:#if ENABLE_FEATURE_NSENTER_LONG_OPTS +//usage:#define nsenter_full_usage "\n" +//usage: "\n -t, --target=PID Target process to get namespaces from" +//usage: "\n -m, --mount[=FILE] Enter mount namespace" +//usage: "\n -u, --uts[=FILE] Enter UTS namespace (hostname etc)" +//usage: "\n -i, --ipc[=FILE] Enter System V IPC namespace" +//usage: "\n -n, --net[=FILE] Enter network namespace" +//usage: "\n -p, --pid[=FILE] Enter pid namespace" +//usage: "\n -U, --user[=FILE] Enter user namespace" +//usage: "\n -S, --setuid=UID Set uid in entered namespace" +//usage: "\n -G, --setgid=GID Set gid in entered namespace" +//usage: "\n --preserve-credentials Don't touch uids or gids" +//usage: "\n -r, --root[=DIR] Set root directory" +//usage: "\n -w, --wd[=DIR] Set working directory" +//usage: "\n -F, --no-fork Don't fork before exec'ing PROG" +//usage:#else +//usage:#define nsenter_full_usage "\n" +//usage: "\n -t PID Target process to get namespaces from" +//usage: "\n -m[FILE] Enter mount namespace" +//usage: "\n -u[FILE] Enter UTS namespace (hostname etc)" +//usage: "\n -i[FILE] Enter System V IPC namespace" +//usage: "\n -n[FILE] Enter network namespace" +//usage: "\n -p[FILE] Enter pid namespace" +//usage: "\n -U[FILE] Enter user namespace" +//usage: "\n -S UID Set uid in entered namespace" +//usage: "\n -G GID Set gid in entered namespace" +//usage: "\n -r[DIR] Set root directory" +//usage: "\n -w[DIR] Set working directory" +//usage: "\n -F Don't fork before exec'ing PROG" +//usage:#endif + +#include +#include "libbb.h" + +struct namespace_descr { + int flag; /* value passed to setns() */ + char ns_nsfile8[8]; /* "ns/" + namespace file in process' procfs entry */ +}; + +struct namespace_ctx { + char *path; /* optional path to a custom ns file */ + int fd; /* opened namespace file descriptor */ +}; + +enum { + OPT_user = 1 << 0, + OPT_ipc = 1 << 1, + OPT_uts = 1 << 2, + OPT_network = 1 << 3, + OPT_pid = 1 << 4, + OPT_mount = 1 << 5, + OPT_target = 1 << 6, + OPT_setuid = 1 << 7, + OPT_setgid = 1 << 8, + OPT_root = 1 << 9, + OPT_wd = 1 << 10, + OPT_nofork = 1 << 11, + OPT_prescred = (1 << 12) * ENABLE_FEATURE_NSENTER_LONG_OPTS, +}; +enum { + NS_USR_POS = 0, + NS_IPC_POS, + NS_UTS_POS, + NS_NET_POS, + NS_PID_POS, + NS_MNT_POS, + NS_COUNT, +}; +/* + * The order is significant in nsenter. + * The user namespace comes first, so that it is entered first. + * This gives an unprivileged user the potential to enter other namespaces. + */ +static const struct namespace_descr ns_list[] = { + { CLONE_NEWUSER, "ns/user", }, + { CLONE_NEWIPC, "ns/ipc", }, + { CLONE_NEWUTS, "ns/uts", }, + { CLONE_NEWNET, "ns/net", }, + { CLONE_NEWPID, "ns/pid", }, + { CLONE_NEWNS, "ns/mnt", }, +}; +/* + * Upstream nsenter doesn't support the short option for --preserve-credentials + */ +static const char opt_str[] = "U::i::u::n::p::m::""t+S+G+r::w::F"; + +#if ENABLE_FEATURE_NSENTER_LONG_OPTS +static const char nsenter_longopts[] ALIGN1 = + "user\0" Optional_argument "U" + "ipc\0" Optional_argument "i" + "uts\0" Optional_argument "u" + "network\0" Optional_argument "n" + "pid\0" Optional_argument "p" + "mount\0" Optional_argument "m" + "target\0" Required_argument "t" + "setuid\0" Required_argument "S" + "setgid\0" Required_argument "G" + "root\0" Optional_argument "r" + "wd\0" Optional_argument "w" + "no-fork\0" No_argument "F" + "preserve-credentials\0" No_argument "\xff" + ; +#endif + +/* + * Open a file and return the new descriptor. If a full path is provided in + * fs_path, then the file to which it points is opened. Otherwise (fd_path is + * NULL) the routine builds a path to a procfs file using the following + * template: '/proc//'. + */ +static int open_by_path_or_target(const char *path, + pid_t target_pid, const char *target_file) +{ + char proc_path_buf[sizeof("/proc/%u/1234567890") + sizeof(int)*3]; + + if (!path) { + if (target_pid == 0) { + /* Example: + * "nsenter -p PROG" - neither -pFILE nor -tPID given. + */ + bb_show_usage(); + } + snprintf(proc_path_buf, sizeof(proc_path_buf), + "/proc/%u/%s", (unsigned)target_pid, target_file); + path = proc_path_buf; + } + + return xopen(path, O_RDONLY); +} + +int nsenter_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int nsenter_main(int argc UNUSED_PARAM, char **argv) +{ + int i; + unsigned int opts; + const char *root_dir_str = NULL; + const char *wd_str = NULL; + struct namespace_ctx ns_ctx_list[NS_COUNT]; + int setgroups_failed; + int root_fd, wd_fd; + int target_pid = 0; + int uid = 0; + int gid = 0; + + memset(ns_ctx_list, 0, sizeof(ns_ctx_list)); + + IF_FEATURE_NSENTER_LONG_OPTS(applet_long_options = nsenter_longopts); + opts = getopt32(argv, opt_str, + &ns_ctx_list[NS_USR_POS].path, + &ns_ctx_list[NS_IPC_POS].path, + &ns_ctx_list[NS_UTS_POS].path, + &ns_ctx_list[NS_NET_POS].path, + &ns_ctx_list[NS_PID_POS].path, + &ns_ctx_list[NS_MNT_POS].path, + &target_pid, &uid, &gid, + &root_dir_str, &wd_str + ); + argv += optind; + + root_fd = wd_fd = -1; + if (opts & OPT_root) + root_fd = open_by_path_or_target(root_dir_str, + target_pid, "root"); + if (opts & OPT_wd) + wd_fd = open_by_path_or_target(wd_str, target_pid, "cwd"); + + for (i = 0; i < NS_COUNT; i++) { + const struct namespace_descr *ns = &ns_list[i]; + struct namespace_ctx *ns_ctx = &ns_ctx_list[i]; + + ns_ctx->fd = -1; + if (opts & (1 << i)) + ns_ctx->fd = open_by_path_or_target(ns_ctx->path, + target_pid, ns->ns_nsfile8); + } + + /* + * Entering the user namespace without --preserve-credentials implies + * --setuid & --setgid and clearing root's groups. + */ + setgroups_failed = 0; + if ((opts & OPT_user) && !(opts & OPT_prescred)) { + opts |= (OPT_setuid | OPT_setgid); + /* + * We call setgroups() before and after setns() and only + * bail-out if it fails twice. + */ + setgroups_failed = (setgroups(0, NULL) < 0); + } + + for (i = 0; i < NS_COUNT; i++) { + const struct namespace_descr *ns = &ns_list[i]; + struct namespace_ctx *ns_ctx = &ns_ctx_list[i]; + + if (ns_ctx->fd < 0) + continue; + if (setns(ns_ctx->fd, ns->flag)) { + bb_perror_msg_and_die( + "setns(): can't reassociate to namespace '%s'", + ns->ns_nsfile8 + 3 /* skip over "ns/" */ + ); + } + /*close(ns_ctx->fd);*/ + /*ns_ctx->fd = -1;*/ + } + + if (root_fd >= 0) { + if (wd_fd < 0) { + /* + * Save the current working directory if we're not + * changing it. + */ + wd_fd = xopen(".", O_RDONLY); + } + xfchdir(root_fd); + xchroot("."); + /*close(root_fd);*/ + /*root_fd = -1;*/ + } + + if (wd_fd >= 0) { + xfchdir(wd_fd); + /*close(wd_fd);*/ + /*wd_fd = -1;*/ + } + + /* + * Entering the pid namespace implies forking unless it's been + * explicitly requested by the user not to. + */ + if (!(opts & OPT_nofork) && (opts & OPT_pid)) { + pid_t pid = xvfork(); + if (pid > 0) { + /* Parent */ + int exit_status = wait_for_exitstatus(pid); + if (WIFSIGNALED(exit_status)) + kill_myself_with_sig(WTERMSIG(exit_status)); + return WEXITSTATUS(exit_status); + } + /* Child continues */ + } + + if (opts & OPT_setgid) { + if (setgroups(0, NULL) < 0 && setgroups_failed) + bb_perror_msg_and_die("setgroups"); + xsetgid(gid); + } + if (opts & OPT_setuid) + xsetuid(uid); + + if (*argv) { + BB_EXECVP_or_die(argv); + } + + run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL); +} -- cgit v1.2.3-55-g6feb From 9f2f96edfa7eddd8a77b76ccae7c2ed88348182e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Apr 2016 04:44:39 +0200 Subject: unshare: remove stale comment Signed-off-by: Denys Vlasenko --- util-linux/unshare.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/util-linux/unshare.c b/util-linux/unshare.c index b8cd4676a..2a5bea5a6 100644 --- a/util-linux/unshare.c +++ b/util-linux/unshare.c @@ -57,11 +57,6 @@ static void mount_or_die(const char *source, const char *target, } } -/* - * Longest possible path to a procfs file used in unshare. Must be able to - * contain the '/proc/' string, the '/ns/user' string which is the longest - * namespace name and a 32-bit integer representing the process ID. - */ #define PATH_PROC_SETGROUPS "/proc/self/setgroups" #define PATH_PROC_UIDMAP "/proc/self/uid_map" #define PATH_PROC_GIDMAP "/proc/self/gid_map" -- cgit v1.2.3-55-g6feb From dd02a05e082b96d76707964179921107cd43cdd8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Apr 2016 15:18:26 +0200 Subject: build system: finer-grained selection of search speedup table. KNOWN_APPNAME_OFFSETS=8 versus KNOWN_APPNAME_OFFSETS=0: function old new delta find_applet_by_name 55 136 +81 applet_nameofs - 14 +14 run_applet_and_exit 757 758 +1 Signed-off-by: Denys Vlasenko --- applets/applet_tables.c | 65 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/applets/applet_tables.c b/applets/applet_tables.c index 48544f08d..843f2ec08 100644 --- a/applets/applet_tables.c +++ b/applets/applet_tables.c @@ -58,41 +58,32 @@ static int str_isalnum_(const char *s) return 1; } -// Before linear search, narrow it down by looking at N "equidistant" names: -// KNOWN_APPNAME_OFFSETS cycles code_size -// 0 9057 -// 2 4604 +32 -// 4 2407 +75 -// 8 1342 +98 -// 16 908 +130 -// 32 884 +194 -// With 8, applet_nameofs[] table has 7 elements. -#define KNOWN_APPNAME_OFFSETS 8 - int main(int argc, char **argv) { int i, j; - int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS]; -// unsigned MAX_APPLET_NAME_LEN = 1; - qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name); + // In find_applet_by_name(), before linear search, narrow it down + // by looking at N "equidistant" names. With ~350 applets: + // KNOWN_APPNAME_OFFSETS cycles + // 0 9057 + // 2 4604 + ~100 bytes of code + // 4 2407 + 4 bytes + // 8 1342 + 8 bytes + // 16 908 + 16 bytes + // 32 884 + 32 bytes + // With 8, int16_t applet_nameofs[] table has 7 elements. + int KNOWN_APPNAME_OFFSETS = 8; + // With 128 applets we do two linear searches, with 1..7 strcmp's in the first one + // and 1..16 strcmp's in the second. With 256 apps, second search does 1..32 strcmp's. + if (NUM_APPLETS < 128) + KNOWN_APPNAME_OFFSETS = 4; + if (NUM_APPLETS < 32) + KNOWN_APPNAME_OFFSETS = 0; - for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++) - index[i] = i * NUM_APPLETS / KNOWN_APPNAME_OFFSETS; + qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name); - ofs = 0; - for (i = 0; i < NUM_APPLETS; i++) { - for (j = 0; j < KNOWN_APPNAME_OFFSETS; j++) - if (i == index[j]) - offset[j] = ofs; - ofs += strlen(applets[i].name) + 1; - } - /* If the list of names is too long refuse to proceed */ - if (ofs > 0xffff) - return 1; if (!argv[1]) return 1; - i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666); if (i < 0) return 1; @@ -108,16 +99,26 @@ int main(int argc, char **argv) printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main); } - if (KNOWN_APPNAME_OFFSETS > 0 && NUM_APPLETS > 2*KNOWN_APPNAME_OFFSETS) { - printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS); + printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS); + if (KNOWN_APPNAME_OFFSETS > 0) { + int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS]; + for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++) + index[i] = i * NUM_APPLETS / KNOWN_APPNAME_OFFSETS; + ofs = 0; + for (i = 0; i < NUM_APPLETS; i++) { + for (j = 0; j < KNOWN_APPNAME_OFFSETS; j++) + if (i == index[j]) + offset[j] = ofs; + ofs += strlen(applets[i].name) + 1; + } + /* If the list of names is too long refuse to proceed */ + if (ofs > 0xffff) + return 1; printf("const uint16_t applet_nameofs[] ALIGN2 = {\n"); for (i = 1; i < KNOWN_APPNAME_OFFSETS; i++) printf("%d,\n", offset[i]); printf("};\n\n"); } - else { - printf("#define KNOWN_APPNAME_OFFSETS 0\n\n"); - } //printf("#ifndef SKIP_definitions\n"); printf("const char applet_names[] ALIGN1 = \"\"\n"); -- cgit v1.2.3-55-g6feb From c87e81f9440278dd46a3eddd1e0f4773afd46a95 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Apr 2016 17:39:50 +0200 Subject: sort: help text does not need to say that -mST are supported but ignored Such information is useless for users of "sort --help" Signed-off-by: Denys Vlasenko --- coreutils/sort.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/coreutils/sort.c b/coreutils/sort.c index 07d903388..c8b42c719 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -14,7 +14,7 @@ //usage:#define sort_trivial_usage //usage: "[-nru" -//usage: IF_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR") +//usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR") //usage: "] [FILE]..." //usage:#define sort_full_usage "\n\n" //usage: "Sort lines of text\n" @@ -41,7 +41,10 @@ //usage: "\n -u Suppress duplicate lines" //usage: IF_FEATURE_SORT_BIG( //usage: "\n -z Lines are terminated by NUL, not newline" -//usage: "\n -mST Ignored for GNU compatibility") +////usage: "\n -m Ignored for GNU compatibility" +////usage: "\n -S BUFSZ Ignored for GNU compatibility" +////usage: "\n -T TMPDIR Ignored for GNU compatibility" +//usage: ) //usage: //usage:#define sort_example_usage //usage: "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" -- cgit v1.2.3-55-g6feb From 8220399173cf8d25e37059cadac96ac30f94e82a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Apr 2016 18:06:24 +0200 Subject: nsenter,unshare: share common code; fix a bug of not closing all fds function old new delta xvfork_parent_waits_and_exits - 64 +64 exec_prog_or_SHELL - 39 +39 unshare_main 873 810 -63 nsenter_main 663 596 -67 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 0/2 up/down: 106/-130) Total: -27 bytes Signed-off-by: Denys Vlasenko --- include/libbb.h | 6 ++++-- libbb/executable.c | 11 ++++++++++- libbb/xfuncs_printf.c | 16 ++++++++++++++++ util-linux/nsenter.c | 21 +++++---------------- util-linux/unshare.c | 19 +++---------------- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 5b4280e34..64e61cd26 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -992,9 +992,10 @@ int BB_EXECVP(const char *file, char *const argv[]) FAST_FUNC; #define BB_EXECVP(prog,cmd) execvp(prog,cmd) #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd,__VA_ARGS__) #endif -int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; +void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; +void exec_prog_or_SHELL(char **argv) NORETURN FAST_FUNC; -/* xvfork() can't be a _function_, return after vfork mangles stack +/* xvfork() can't be a _function_, return after vfork in child mangles stack * in the parent. It must be a macro. */ #define xvfork() \ ({ \ @@ -1006,6 +1007,7 @@ int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; #if BB_MMU pid_t xfork(void) FAST_FUNC; #endif +void xvfork_parent_waits_and_exits(void) FAST_FUNC; /* NOMMU friendy fork+exec: */ pid_t spawn(char **argv) FAST_FUNC; diff --git a/libbb/executable.c b/libbb/executable.c index 85ecc3e6c..05e70312f 100644 --- a/libbb/executable.c +++ b/libbb/executable.c @@ -83,10 +83,19 @@ int FAST_FUNC BB_EXECVP(const char *file, char *const argv[]) } #endif -int FAST_FUNC BB_EXECVP_or_die(char **argv) +void FAST_FUNC BB_EXECVP_or_die(char **argv) { BB_EXECVP(argv[0], argv); /* SUSv3-mandated exit codes */ xfunc_error_retval = (errno == ENOENT) ? 127 : 126; bb_perror_msg_and_die("can't execute '%s'", argv[0]); } + +/* Typical idiom for applets which exec *optional* PROG [ARGS] */ +void FAST_FUNC exec_prog_or_SHELL(char **argv) +{ + if (argv[0]) { + BB_EXECVP_or_die(argv); + } + run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL); +} diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 4aa1b5ce2..e9222f690 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -659,3 +659,19 @@ pid_t FAST_FUNC xfork(void) return pid; } #endif + +void FAST_FUNC xvfork_parent_waits_and_exits(void) +{ + pid_t pid; + + fflush_all(); + pid = xvfork(); + if (pid > 0) { + /* Parent */ + int exit_status = wait_for_exitstatus(pid); + if (WIFSIGNALED(exit_status)) + kill_myself_with_sig(WTERMSIG(exit_status)); + _exit(WEXITSTATUS(exit_status)); + } + /* Child continues */ +} diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c index 9c1dabaa8..0dad595cd 100644 --- a/util-linux/nsenter.c +++ b/util-linux/nsenter.c @@ -230,7 +230,7 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv) ns->ns_nsfile8 + 3 /* skip over "ns/" */ ); } - /*close(ns_ctx->fd);*/ + close(ns_ctx->fd); /* should close fds, to not confuse exec'ed PROG */ /*ns_ctx->fd = -1;*/ } @@ -244,13 +244,13 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv) } xfchdir(root_fd); xchroot("."); - /*close(root_fd);*/ + close(root_fd); /*root_fd = -1;*/ } if (wd_fd >= 0) { xfchdir(wd_fd); - /*close(wd_fd);*/ + close(wd_fd); /*wd_fd = -1;*/ } @@ -259,14 +259,7 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv) * explicitly requested by the user not to. */ if (!(opts & OPT_nofork) && (opts & OPT_pid)) { - pid_t pid = xvfork(); - if (pid > 0) { - /* Parent */ - int exit_status = wait_for_exitstatus(pid); - if (WIFSIGNALED(exit_status)) - kill_myself_with_sig(WTERMSIG(exit_status)); - return WEXITSTATUS(exit_status); - } + xvfork_parent_waits_and_exits(); /* Child continues */ } @@ -278,9 +271,5 @@ int nsenter_main(int argc UNUSED_PARAM, char **argv) if (opts & OPT_setuid) xsetuid(uid); - if (*argv) { - BB_EXECVP_or_die(argv); - } - - run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL); + exec_prog_or_SHELL(argv); } diff --git a/util-linux/unshare.c b/util-linux/unshare.c index 2a5bea5a6..95a7cb647 100644 --- a/util-linux/unshare.c +++ b/util-linux/unshare.c @@ -281,7 +281,7 @@ int unshare_main(int argc UNUSED_PARAM, char **argv) if (fdp.wr >= 0) { close(fdp.wr); /* Release child */ - /*close(fdp.rd);*/ + close(fdp.rd); /* should close fd, to not confuse exec'ed PROG */ } if (need_mount) { @@ -307,14 +307,7 @@ int unshare_main(int argc UNUSED_PARAM, char **argv) * that'll become PID 1 in this new namespace. */ if (opts & OPT_fork) { - pid_t pid = xfork(); - if (pid > 0) { - /* Parent */ - int exit_status = wait_for_exitstatus(pid); - if (WIFSIGNALED(exit_status)) - kill_myself_with_sig(WTERMSIG(exit_status)); - return WEXITSTATUS(exit_status); - } + xvfork_parent_waits_and_exits(); /* Child continues */ } @@ -354,11 +347,5 @@ int unshare_main(int argc UNUSED_PARAM, char **argv) mount_or_die("proc", proc_mnt_target, "proc", MS_NOSUID | MS_NOEXEC | MS_NODEV); } - if (argv[0]) { - BB_EXECVP_or_die(argv); - } - /* unshare from util-linux 2.27.1, despite not documenting it, - * runs a login shell (argv0="-sh") if no PROG is given - */ - run_shell(getenv("SHELL"), /*login:*/ 1, NULL, NULL); + exec_prog_or_SHELL(argv); } -- cgit v1.2.3-55-g6feb From b14374a5ba7060d03c9859a5f61afdcdacc3dae6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Apr 2016 18:20:26 +0200 Subject: sort: "-o FILE", not "-o", is the syntax Signed-off-by: Denys Vlasenko --- coreutils/sort.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/coreutils/sort.c b/coreutils/sort.c index c8b42c719..9139d9f47 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -19,18 +19,18 @@ //usage:#define sort_full_usage "\n\n" //usage: "Sort lines of text\n" //usage: IF_FEATURE_SORT_BIG( -//usage: "\n -b Ignore leading blanks" +//usage: "\n -o FILE Output to FILE" //usage: "\n -c Check whether input is sorted" -//usage: "\n -d Dictionary order (blank or alphanumeric only)" +//usage: "\n -b Ignore leading blanks" //usage: "\n -f Ignore case" -//usage: "\n -g General numerical sort" //usage: "\n -i Ignore unprintable characters" +//usage: "\n -d Dictionary order (blank or alphanumeric only)" +//usage: "\n -g General numerical sort" //usage: "\n -M Sort month" //usage: ) //-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G) //usage: "\n -n Sort numbers" //usage: IF_FEATURE_SORT_BIG( -//usage: "\n -o Output to file" //usage: "\n -t CHAR Field separator" //usage: "\n -k N[,M] Sort by Nth field" //usage: ) -- cgit v1.2.3-55-g6feb From 8b0f459af7aa108089d0f87b0be81ccadb8638cb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Apr 2016 19:00:44 +0200 Subject: nsenter,unshare: work around older header Signed-off-by: Denys Vlasenko --- util-linux/nsenter.c | 16 ++++++++++++++++ util-linux/unshare.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c index 0dad595cd..b08b3dae7 100644 --- a/util-linux/nsenter.c +++ b/util-linux/nsenter.c @@ -60,6 +60,22 @@ //usage:#endif #include +#ifndef CLONE_NEWUTS +# define CLONE_NEWUTS 0x04000000 +#endif +#ifndef CLONE_NEWIPC +# define CLONE_NEWIPC 0x08000000 +#endif +#ifndef CLONE_NEWUSER +# define CLONE_NEWUSER 0x10000000 +#endif +#ifndef CLONE_NEWPID +# define CLONE_NEWPID 0x20000000 +#endif +#ifndef CLONE_NEWNET +# define CLONE_NEWNET 0x40000000 +#endif + #include "libbb.h" struct namespace_descr { diff --git a/util-linux/unshare.c b/util-linux/unshare.c index 95a7cb647..d05cfdb6c 100644 --- a/util-linux/unshare.c +++ b/util-linux/unshare.c @@ -40,7 +40,36 @@ //usage: "\n --setgroups allow|deny Control the setgroups syscall in user namespaces" #include +#ifndef CLONE_NEWUTS +# define CLONE_NEWUTS 0x04000000 +#endif +#ifndef CLONE_NEWIPC +# define CLONE_NEWIPC 0x08000000 +#endif +#ifndef CLONE_NEWUSER +# define CLONE_NEWUSER 0x10000000 +#endif +#ifndef CLONE_NEWPID +# define CLONE_NEWPID 0x20000000 +#endif +#ifndef CLONE_NEWNET +# define CLONE_NEWNET 0x40000000 +#endif + #include +#ifndef MS_REC +# define MS_REC (1 << 14) +#endif +#ifndef MS_PRIVATE +# define MS_PRIVATE (1 << 18) +#endif +#ifndef MS_SLAVE +# define MS_SLAVE (1 << 19) +#endif +#ifndef MS_SHARED +# define MS_SHARED (1 << 20) +#endif + #include "libbb.h" static void mount_or_die(const char *source, const char *target, -- cgit v1.2.3-55-g6feb From a93e4fd376d990ead254657228e75715b74ca0ac Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Apr 2016 22:54:23 +0200 Subject: find_applet_by_name: add an example of faster linear search code Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index aeaf238f1..18583f91a 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -141,10 +141,28 @@ void FAST_FUNC bb_show_usage(void) int FAST_FUNC find_applet_by_name(const char *name) { - unsigned i, max; - int j; + unsigned i, j, max; const char *p; +/* The commented-out word-at-a-time code is ~40% faster, but +160 bytes. + * "Faster" here saves ~0.5 microsecond of real time - not worth it. + */ +#if 0 /*BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN*/ + uint32_t n32; + + /* Handle all names < 2 chars long early */ + if (name[0] == '\0') + return -1; /* "" is not a valid applet name */ + if (name[1] == '\0') { + if (!ENABLE_TEST) + return -1; /* 1-char name is not valid */ + if (name[0] != ']') + return -1; /* 1-char name which isn't "[" is not valid */ + /* applet "[" is always applet #0: */ + return 0; + } +#endif + p = applet_names; i = 0; #if KNOWN_APPNAME_OFFSETS <= 0 @@ -166,7 +184,62 @@ int FAST_FUNC find_applet_by_name(const char *name) //bb_error_msg("name:'%s' starting from:'%s' i:%u max:%u", name, p, i, max); #endif - /* Open-coding without strcmp/strlen calls for speed */ + /* Open-coded linear seatch without strcmp/strlen calls for speed */ + +#if 0 /*BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN*/ + /* skip "[\0" name, it's surely not it */ + if (ENABLE_TEST && LONE_CHAR(p, '[')) + i++, p += 2; + /* All remaining applet names in p[] are at least 2 chars long */ + /* name[] is also at least 2 chars long */ + + n32 = (name[0] << 0) | (name[1] << 8) | (name[2] << 16); + while (i < max) { + uint32_t p32; + char ch; + + /* Quickly check match of the first 3 bytes */ + move_from_unaligned32(p32, p); + p += 3; + if ((p32 & 0x00ffffff) != n32) { + /* Most likely case: 3 first bytes do not match */ + i++; + if ((p32 & 0x00ff0000) == '\0') + continue; // p[2] was NUL + p++; + if ((p32 & 0xff000000) == '\0') + continue; // p[3] was NUL + /* p[0..3] aren't matching and none is NUL, check the rest */ + while (*p++ != '\0') + continue; + continue; + } + + /* Unlikely branch: first 3 bytes ([0..2]) match */ + if ((p32 & 0x00ff0000) == '\0') { + /* name is 2-byte long, it is full match */ + //bb_error_msg("found:'%s' i:%u", name, i); + return i; + } + /* Check remaining bytes [3..NUL] */ + ch = (p32 >> 24); + j = 3; + while (ch == name[j]) { + if (ch == '\0') { + //bb_error_msg("found:'%s' i:%u", name, i); + return i; + } + ch = *++p; + j++; + } + /* Not a match. Skip it, including NUL */ + while (ch != '\0') + ch = *++p; + p++; + i++; + } + return -1; +#else while (i < max) { char ch; j = 0; @@ -189,6 +262,7 @@ int FAST_FUNC find_applet_by_name(const char *name) i++; } return -1; +#endif } -- cgit v1.2.3-55-g6feb From 1cf68e303328671f74dfd9f7d24e6c9f91d18969 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 2 Apr 2016 22:57:17 +0200 Subject: typo fix Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 18583f91a..4b5b09f45 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -184,7 +184,7 @@ int FAST_FUNC find_applet_by_name(const char *name) //bb_error_msg("name:'%s' starting from:'%s' i:%u max:%u", name, p, i, max); #endif - /* Open-coded linear seatch without strcmp/strlen calls for speed */ + /* Open-coded linear search without strcmp/strlen calls for speed */ #if 0 /*BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN*/ /* skip "[\0" name, it's surely not it */ -- cgit v1.2.3-55-g6feb From 056e1f558cc8bc22f221b49bf4571aed59cdae09 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Apr 2016 15:38:53 +0200 Subject: trylink: on failure, print a hint about CONFIG_EXTRA_LDLIBS Signed-off-by: Denys Vlasenko --- scripts/trylink | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/trylink b/scripts/trylink index 3c431edc3..15435f009 100755 --- a/scripts/trylink +++ b/scripts/trylink @@ -140,6 +140,8 @@ try $CC $CFLAGS $LDFLAGS \ || { echo "Failed: $l_list" cat $EXE.out + echo 'Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.' + echo 'Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"' exit 1 } -- cgit v1.2.3-55-g6feb From bc14f4d13d3cf1d43ae809d641e29174662cd1e4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Apr 2016 16:06:42 +0200 Subject: main(): add a TODO about finding a use for _end[] area Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 4b5b09f45..d798a2eac 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -902,6 +902,19 @@ int lbb_main(char **argv) int main(int argc UNUSED_PARAM, char **argv) #endif { +#if 0 + /* TODO: find a use for a block of memory between end of .bss + * and end of page. For example, I'm getting "_end:0x812e698 2408 bytes" + * - more than 2k of wasted memory (in this particular build) + * *per each running process*! + * (If your linker does not generate "_end" name, weak attribute + * makes &_end == NULL, end_len == 0 here.) + */ + extern char _end[] __attribute__((weak)); + unsigned end_len = (-(int)_end) & 0xfff; + printf("_end:%p %u bytes\n", &_end, end_len); +#endif + /* Tweak malloc for reduced memory consumption */ #ifdef M_TRIM_THRESHOLD /* M_TRIM_THRESHOLD is the maximum amount of freed top-most memory -- cgit v1.2.3-55-g6feb From 46b494635e6ef54e282749d2c65dd1922b167931 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Apr 2016 16:55:03 +0200 Subject: libbb: speed up error_msg functions function old new delta bb_verror_msg 386 466 +80 Signed-off-by: Denys Vlasenko --- libbb/verror_msg.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c index 0ef2a311f..22c30357b 100644 --- a/libbb/verror_msg.c +++ b/libbb/verror_msg.c @@ -20,6 +20,7 @@ const char *msg_eol = "\n"; void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr) { char *msg, *msg1; + char stack_msg[80]; int applet_len, strerr_len, msgeol_len, used; if (!logmode) @@ -28,6 +29,27 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr) if (!s) /* nomsg[_and_die] uses NULL fmt */ s = ""; /* some libc don't like printf(NULL) */ + applet_len = strlen(applet_name) + 2; /* "applet: " */ + strerr_len = strerr ? strlen(strerr) : 0; + msgeol_len = strlen(msg_eol); + + /* This costs ~90 bytes of code, but avoids costly + * malloc()[in vasprintf]+realloc()+memmove()+free() in 99% of cases. + * ~40% speedup. + */ + if ((int)sizeof(stack_msg) - applet_len > 0) { + va_list p2; + + /* It is not portable to use va_list twice, need to va_copy it */ + va_copy(p2, p); + used = vsnprintf(stack_msg + applet_len, (int)sizeof(stack_msg) - applet_len, s, p2); + va_end(p2); + msg = stack_msg; + used += applet_len; + if (used < (int)sizeof(stack_msg) - 3 - msgeol_len - strerr_len) + goto add_pfx_and_sfx; + } + used = vasprintf(&msg, s, p); if (used < 0) return; @@ -37,9 +59,6 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr) * This is needed for e.g. httpd logging, when multiple * children can produce log messages simultaneously. */ - applet_len = strlen(applet_name) + 2; /* "applet: " */ - strerr_len = strerr ? strlen(strerr) : 0; - msgeol_len = strlen(msg_eol); /* can't use xrealloc: it calls error_msg on failure, * that may result in a recursion */ /* +3 is for ": " before strerr and for terminating NUL */ @@ -52,6 +71,7 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr) /* TODO: maybe use writev instead of memmoving? Need full_writev? */ memmove(msg + applet_len, msg, used); used += applet_len; + add_pfx_and_sfx: strcpy(msg, applet_name); msg[applet_len - 2] = ':'; msg[applet_len - 1] = ' '; @@ -76,7 +96,8 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr) syslog(syslog_level, "%s", msg + applet_len); } #endif - free(msg); + if (msg != stack_msg) + free(msg); } #ifdef VERSION_WITH_WRITEV -- cgit v1.2.3-55-g6feb From cb9264099822505dc2930cfea0b1f9027a02dc06 Mon Sep 17 00:00:00 2001 From: Sven Eisenberg Date: Sun, 3 Apr 2016 20:12:03 +0200 Subject: ubirename: new applet function old new delta ubirename_main - 394 +394 packed_usage 30611 30674 +63 applet_names 2530 2540 +10 Signed-off-by: Sven Eisenberg Signed-off-by: Denys Vlasenko --- miscutils/ubirename.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 miscutils/ubirename.c diff --git a/miscutils/ubirename.c b/miscutils/ubirename.c new file mode 100644 index 000000000..455a49485 --- /dev/null +++ b/miscutils/ubirename.c @@ -0,0 +1,111 @@ +/* ubirename - port of the ubirename from the mtd-utils package + * + * A utility to rename one UBI volume. + * + * 2016-03-01 Sven Eisenberg + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ +//config:config UBIRENAME +//config: bool "ubirename" +//config: default y +//config: select PLATFORM_LINUX +//config: help +//config: Utility to rename UBI volumes + +//applet:IF_UBIRENAME(APPLET(ubirename, BB_DIR_USR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_UBIRENAME) += ubirename.o + +//usage:#define ubirename_trivial_usage +//usage: "UBI_DEVICE OLD_VOLNAME NEW_VOLNAME [OLD2 NEW2]..." +//usage:#define ubirename_full_usage "\n\n" +//usage: "Rename UBI volumes on UBI_DEVICE" + +#include "libbb.h" +#include + +#ifndef __packed +# define __packed __attribute__((packed)) +#endif + +// from ubi-media.h +#define UBI_VOL_NAME_MAX 127 +#define UBI_MAX_VOLUMES 128 +// end ubi-media.h + +#define UBI_MAX_VOLUME_NAME UBI_VOL_NAME_MAX + +// from ubi-user.h +/* ioctl commands of UBI character devices */ +#define UBI_IOC_MAGIC 'o' + +/* Re-name volumes */ +#define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req) + +/* Maximum amount of UBI volumes that can be re-named at one go */ +#define UBI_MAX_RNVOL 32 + +struct ubi_rnvol_req { + int32_t count; + int8_t padding1[12]; + struct { + int32_t vol_id; + int16_t name_len; + int8_t padding2[2]; + char name[UBI_MAX_VOLUME_NAME + 1]; + } ents[UBI_MAX_RNVOL]; +} __packed; +// end ubi-user.h + +int ubirename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int ubirename_main(int argc, char **argv) +{ + struct ubi_rnvol_req *rnvol; + const char *ubi_devname; + unsigned ubi_devnum; + unsigned i, n; + + /* argc can be 4, 6, 8, ... */ + if ((argc & 1) || (argc >>= 1) < 2) + bb_show_usage(); + + rnvol = xzalloc(sizeof(*rnvol)); + rnvol->count = --argc; + if (argc > ARRAY_SIZE(rnvol->ents)) + bb_error_msg_and_die("too many renames requested"); + + ubi_devname = argv[1]; + if (sscanf(ubi_devname, "/dev/ubi%u", &ubi_devnum) != 1) + bb_error_msg_and_die("not a ubi device: '%s'", ubi_devname); + + n = 0; + argv += 2; + while (argv[0]) { + for (i = 0; i < UBI_MAX_VOLUMES; i++) { + char buf[UBI_VOL_NAME_MAX + 1]; + char fname[sizeof("/sys/class/ubi/ubi%u_%u/name") + 2 * sizeof(int)*3]; + + sprintf(fname, "/sys/class/ubi/ubi%u_%u/name", ubi_devnum, i); + if (open_read_close(fname, buf, sizeof(buf)) <= 0) + continue; + + strchrnul(buf, '\n')[0] = '\0'; + if (strcmp(buf, argv[0]) == 0) + goto found; + } + bb_error_msg_and_die("no volume '%s' found", argv[0]); + found: + rnvol->ents[n].vol_id = i; + rnvol->ents[n].name_len = strlen(argv[1]); + if (rnvol->ents[n].name_len >= sizeof(rnvol->ents[n].name)) + bb_error_msg_and_die("new name '%s' is too long", argv[1]); + strcpy(rnvol->ents[n].name, argv[1]); + n++; + argv += 2; + } + + xioctl(xopen(ubi_devname, O_RDONLY), UBI_IOCRNVOL, rnvol); + + return 0; +} -- cgit v1.2.3-55-g6feb From b068cf2a7e036da8d0b3533b41886c5605c8139d Mon Sep 17 00:00:00 2001 From: Sven Eisenberg Date: Sun, 3 Apr 2016 21:53:12 +0200 Subject: ubirmvol: Implement -N switch for ubirmvol function old new delta get_volid_by_name - 125 +125 ubi_devnum_from_devname - 43 +43 ubi_tools_main 1215 1220 +5 packed_usage 30674 30655 -19 ubirename_main 394 221 -173 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 1/2 up/down: 173/-192) Total: -19 bytes Signed-off-by: Denys Vlasenko --- include/libbb.h | 3 +++ libbb/ubi.c | 43 +++++++++++++++++++++++++++++++++++++++++++ miscutils/ubi_tools.c | 29 +++++++++++++++++++---------- miscutils/ubirename.c | 25 ++++--------------------- 4 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 libbb/ubi.c diff --git a/include/libbb.h b/include/libbb.h index 64e61cd26..35c28df51 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1770,6 +1770,9 @@ void bb_progress_update(bb_progress_t *p, uoff_t transferred, uoff_t totalsize) FAST_FUNC; +unsigned ubi_devnum_from_devname(const char *str) FAST_FUNC; +int get_volid_by_name(unsigned ubi_devnum, const char *vol_name) FAST_FUNC; + extern const char *applet_name; diff --git a/libbb/ubi.c b/libbb/ubi.c new file mode 100644 index 000000000..7d3b2952d --- /dev/null +++ b/libbb/ubi.c @@ -0,0 +1,43 @@ +/* vi: set sw=4 ts=4: */ +/* + * Utility routines. + * + * Copyright (C) 2016 Denys Vlasenko + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ +//kbuild:lib-y += ubi.o + +#include "libbb.h" + +// from ubi-media.h +#define UBI_MAX_VOLUME_NAME 127 +#define UBI_MAX_VOLUMES 128 + +unsigned FAST_FUNC ubi_devnum_from_devname(const char *str) +{ + unsigned ubi_devnum; + + if (sscanf(str, "/dev/ubi%u", &ubi_devnum) != 1) + bb_error_msg_and_die("not an UBI device: '%s'", str); + return ubi_devnum; +} + +int FAST_FUNC get_volid_by_name(unsigned ubi_devnum, const char *vol_name) +{ + unsigned i; + + for (i = 0; i < UBI_MAX_VOLUMES; i++) { + char buf[UBI_MAX_VOLUME_NAME + 1]; + char fname[sizeof("/sys/class/ubi/ubi%u_%u/name") + 2 * sizeof(int)*3]; + + sprintf(fname, "/sys/class/ubi/ubi%u_%u/name", ubi_devnum, i); + if (open_read_close(fname, buf, sizeof(buf)) <= 0) + continue; + + strchrnul(buf, '\n')[0] = '\0'; + if (strcmp(vol_name, buf) == 0) + return i; + } + bb_error_msg_and_die("volume '%s' not found", vol_name); +} diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index dd1bda300..ac0c56d6b 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c @@ -195,7 +195,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) } else //usage:#define ubimkvol_trivial_usage -//usage: "UBI_DEVICE -N NAME [-s SIZE | -m]" +//usage: "-N NAME [-s SIZE | -m] UBI_DEVICE" //usage:#define ubimkvol_full_usage "\n\n" //usage: "Create UBI volume\n" //usage: "\n -a ALIGNMENT Volume alignment (default 1)" @@ -212,9 +212,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) unsigned num; char *p; - if (sscanf(ubi_ctrl, "/dev/ubi%u", &num) != 1) - bb_error_msg_and_die("wrong format of UBI device name"); - + num = ubi_devnum_from_devname(ubi_ctrl); p = path_sys_class_ubi_ubi + sprintf(path_sys_class_ubi_ubi, "%u/", num); strcpy(p, "avail_eraseblocks"); @@ -248,20 +246,31 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) } else //usage:#define ubirmvol_trivial_usage -//usage: "UBI_DEVICE -n VOLID" +//usage: "-n VOLID / -N VOLNAME UBI_DEVICE" //usage:#define ubirmvol_full_usage "\n\n" //usage: "Remove UBI volume\n" //usage: "\n -n VOLID Volume ID" +//usage: "\n -N VOLNAME Volume name" if (do_rmvol) { - if (!(opts & OPTION_n)) + if (!(opts & (OPTION_n|OPTION_N))) bb_error_msg_and_die("volume id not specified"); - /* FIXME? kernel expects int32_t* here: */ - xioctl(fd, UBI_IOCRMVOL, &vol_id); + if (opts & OPTION_N) { + unsigned num = ubi_devnum_from_devname(ubi_ctrl); + vol_id = get_volid_by_name(num, vol_name); + } + + if (sizeof(vol_id) != 4) { + /* kernel expects int32_t* in this ioctl */ + int32_t t = vol_id; + xioctl(fd, UBI_IOCRMVOL, &t); + } else { + xioctl(fd, UBI_IOCRMVOL, &vol_id); + } } else //usage:#define ubirsvol_trivial_usage -//usage: "UBI_DEVICE -n VOLID -s SIZE" +//usage: "-n VOLID -s SIZE UBI_DEVICE" //usage:#define ubirsvol_full_usage "\n\n" //usage: "Resize UBI volume\n" //usage: "\n -n VOLID Volume ID" @@ -279,7 +288,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) } else //usage:#define ubiupdatevol_trivial_usage -//usage: "UBI_DEVICE [-t | [-s SIZE] IMG_FILE]" +//usage: "[-t | [-s SIZE] IMG_FILE] UBI_DEVICE" //usage:#define ubiupdatevol_full_usage "\n\n" //usage: "Update UBI volume\n" //usage: "\n -t Truncate to zero size" diff --git a/miscutils/ubirename.c b/miscutils/ubirename.c index 455a49485..d6ccfcb10 100644 --- a/miscutils/ubirename.c +++ b/miscutils/ubirename.c @@ -30,12 +30,10 @@ #endif // from ubi-media.h -#define UBI_VOL_NAME_MAX 127 +#define UBI_MAX_VOLUME_NAME 127 #define UBI_MAX_VOLUMES 128 // end ubi-media.h -#define UBI_MAX_VOLUME_NAME UBI_VOL_NAME_MAX - // from ubi-user.h /* ioctl commands of UBI character devices */ #define UBI_IOC_MAGIC 'o' @@ -64,7 +62,7 @@ int ubirename_main(int argc, char **argv) struct ubi_rnvol_req *rnvol; const char *ubi_devname; unsigned ubi_devnum; - unsigned i, n; + unsigned n; /* argc can be 4, 6, 8, ... */ if ((argc & 1) || (argc >>= 1) < 2) @@ -76,27 +74,12 @@ int ubirename_main(int argc, char **argv) bb_error_msg_and_die("too many renames requested"); ubi_devname = argv[1]; - if (sscanf(ubi_devname, "/dev/ubi%u", &ubi_devnum) != 1) - bb_error_msg_and_die("not a ubi device: '%s'", ubi_devname); + ubi_devnum = ubi_devnum_from_devname(ubi_devname); n = 0; argv += 2; while (argv[0]) { - for (i = 0; i < UBI_MAX_VOLUMES; i++) { - char buf[UBI_VOL_NAME_MAX + 1]; - char fname[sizeof("/sys/class/ubi/ubi%u_%u/name") + 2 * sizeof(int)*3]; - - sprintf(fname, "/sys/class/ubi/ubi%u_%u/name", ubi_devnum, i); - if (open_read_close(fname, buf, sizeof(buf)) <= 0) - continue; - - strchrnul(buf, '\n')[0] = '\0'; - if (strcmp(buf, argv[0]) == 0) - goto found; - } - bb_error_msg_and_die("no volume '%s' found", argv[0]); - found: - rnvol->ents[n].vol_id = i; + rnvol->ents[n].vol_id = get_volid_by_name(ubi_devnum, argv[0]); rnvol->ents[n].name_len = strlen(argv[1]); if (rnvol->ents[n].name_len >= sizeof(rnvol->ents[n].name)) bb_error_msg_and_die("new name '%s' is too long", argv[1]); -- cgit v1.2.3-55-g6feb From 6aab9928dec29855bcee21bce163e5fdf7144350 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Apr 2016 22:24:51 +0200 Subject: whitespace and namespace cleanups Signed-off-by: Denys Vlasenko --- include/libbb.h | 2 +- libbb/ubi.c | 8 ++++---- miscutils/ubi_tools.c | 2 +- miscutils/ubirename.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 35c28df51..111dd66e0 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1771,7 +1771,7 @@ void bb_progress_update(bb_progress_t *p, uoff_t totalsize) FAST_FUNC; unsigned ubi_devnum_from_devname(const char *str) FAST_FUNC; -int get_volid_by_name(unsigned ubi_devnum, const char *vol_name) FAST_FUNC; +int ubi_get_volid_by_name(unsigned ubi_devnum, const char *vol_name) FAST_FUNC; extern const char *applet_name; diff --git a/libbb/ubi.c b/libbb/ubi.c index 7d3b2952d..34595d797 100644 --- a/libbb/ubi.c +++ b/libbb/ubi.c @@ -16,14 +16,14 @@ unsigned FAST_FUNC ubi_devnum_from_devname(const char *str) { - unsigned ubi_devnum; + unsigned ubi_devnum; - if (sscanf(str, "/dev/ubi%u", &ubi_devnum) != 1) - bb_error_msg_and_die("not an UBI device: '%s'", str); + if (sscanf(str, "/dev/ubi%u", &ubi_devnum) != 1) + bb_error_msg_and_die("not an UBI device: '%s'", str); return ubi_devnum; } -int FAST_FUNC get_volid_by_name(unsigned ubi_devnum, const char *vol_name) +int FAST_FUNC ubi_get_volid_by_name(unsigned ubi_devnum, const char *vol_name) { unsigned i; diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index ac0c56d6b..4364bc807 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c @@ -257,7 +257,7 @@ int ubi_tools_main(int argc UNUSED_PARAM, char **argv) if (opts & OPTION_N) { unsigned num = ubi_devnum_from_devname(ubi_ctrl); - vol_id = get_volid_by_name(num, vol_name); + vol_id = ubi_get_volid_by_name(num, vol_name); } if (sizeof(vol_id) != 4) { diff --git a/miscutils/ubirename.c b/miscutils/ubirename.c index d6ccfcb10..8b1c3785a 100644 --- a/miscutils/ubirename.c +++ b/miscutils/ubirename.c @@ -31,7 +31,7 @@ // from ubi-media.h #define UBI_MAX_VOLUME_NAME 127 -#define UBI_MAX_VOLUMES 128 +#define UBI_MAX_VOLUMES 128 // end ubi-media.h // from ubi-user.h @@ -79,7 +79,7 @@ int ubirename_main(int argc, char **argv) n = 0; argv += 2; while (argv[0]) { - rnvol->ents[n].vol_id = get_volid_by_name(ubi_devnum, argv[0]); + rnvol->ents[n].vol_id = ubi_get_volid_by_name(ubi_devnum, argv[0]); rnvol->ents[n].name_len = strlen(argv[1]); if (rnvol->ents[n].name_len >= sizeof(rnvol->ents[n].name)) bb_error_msg_and_die("new name '%s' is too long", argv[1]); -- cgit v1.2.3-55-g6feb From b22061718db0111f9e7474f9b60aef02456ac070 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 3 Apr 2016 22:29:35 +0200 Subject: find_applet_by_name: loop index should be signed The loop for (j = ARRAY_SIZE(applet_nameofs)-1; j >= 0; j--) { was intended to terminate when j goes negative, so j needs to be signed. Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- libbb/appletlib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libbb/appletlib.c b/libbb/appletlib.c index d798a2eac..de654f64c 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -141,7 +141,8 @@ void FAST_FUNC bb_show_usage(void) int FAST_FUNC find_applet_by_name(const char *name) { - unsigned i, j, max; + unsigned i, max; + int j; const char *p; /* The commented-out word-at-a-time code is ~40% faster, but +160 bytes. -- cgit v1.2.3-55-g6feb From 993dab78220d9dce42c45c8cecba23706735c860 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 3 Apr 2016 23:58:50 -0400 Subject: Revert "lxdialog: fix ncursesw include detection" This reverts commit e91bc53d0c2e8de7dc4fbdb888ab0a4923c2b475. Let's get back to a state that matches upstream so we can pull in all of their fixes from the last few years. Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index d34dfd46d..fcef0f59d 100644 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -19,11 +19,7 @@ ldflags() # Where is ncurses.h? ccflags() { - if [ -f /usr/include/ncursesw/ncurses.h ]; then - echo '-I/usr/include/ncursesw -DCURSES_LOC=""' - elif [ -f /usr/include/ncursesw/curses.h ]; then - echo '-I/usr/include/ncursesw -DCURSES_LOC=""' - elif [ -f /usr/include/ncurses/ncurses.h ]; then + if [ -f /usr/include/ncurses/ncurses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' elif [ -f /usr/include/ncurses/curses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' -- cgit v1.2.3-55-g6feb From f48bd92285e20f1f9955bd3b07599beb80ef9ea5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 18 Sep 2010 19:25:32 -0700 Subject: kconfig: fix menuconfig on debian lenny In 60f33b8 (kconfig: get rid of stray a.o, support ncursesw, 2006-01-15), support to link menuconfig with ncursesw library was added. To compute the linker command option -l, we check "libncursesw.{so,a,dylib}" to allow ncursesw to be used as a replacement ncurses. However, when checking what header file to include, we do not check /usr/include/ncursesw directory. Add /usr/include/ncursesw to the list of directories that are checked. With this patch, on my Debian Lenny box with libncursesw5-dev package but not libncurses5-dev package, I can say "make menuconfig". Signed-off-by: Junio C Hamano Acked-by: Sam Ravnborg Signed-off-by: Michal Marek Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index fcef0f59d..82cc3a85e 100644 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -23,6 +23,8 @@ ccflags() echo '-I/usr/include/ncurses -DCURSES_LOC=""' elif [ -f /usr/include/ncurses/curses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' + elif [ -f /usr/include/ncursesw/curses.h ]; then + echo '-I/usr/include/ncursesw -DCURSES_LOC=""' elif [ -f /usr/include/ncurses.h ]; then echo '-DCURSES_LOC=""' else -- cgit v1.2.3-55-g6feb From a0f24a06df79e70661d43fb543272e2fc1074291 Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Tue, 12 Jun 2012 19:05:02 -0500 Subject: kconfig: check ncursesw headers first in check-lxdialog Commit 8c41e5e363db55d91aa3b1cdce4ab02ad9821de7 added a check for ncursesw/curses.h for the case where ncurses and ncursesw are build separately but only one is installed. But if both are installed, the headers ncurses/curses.h and ncursesw/curses.h differ, and since libncursesw will be found first, so should ncursesw/curses.h. Signed-off-by: Yaakov Selkowitz Signed-off-by: Michal Marek Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index 82cc3a85e..b75820bbd 100644 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -19,12 +19,12 @@ ldflags() # Where is ncurses.h? ccflags() { - if [ -f /usr/include/ncurses/ncurses.h ]; then + if [ -f /usr/include/ncursesw/curses.h ]; then + echo '-I/usr/include/ncursesw -DCURSES_LOC=""' + elif [ -f /usr/include/ncurses/ncurses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' elif [ -f /usr/include/ncurses/curses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' - elif [ -f /usr/include/ncursesw/curses.h ]; then - echo '-I/usr/include/ncursesw -DCURSES_LOC=""' elif [ -f /usr/include/ncurses.h ]; then echo '-DCURSES_LOC=""' else -- cgit v1.2.3-55-g6feb From 74f58ed48cd6b8bdb3fb265b649db7dea4574341 Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Tue, 12 Jun 2012 19:05:15 -0500 Subject: kconfig: fix check-lxdialog for DLL platforms Import libraries on Cygwin and MinGW/MSYS use the .dll.a suffix, so checking this suffix is necessary to make sure ncurses will still be found when built without static libraries. Signed-off-by: Yaakov Selkowitz Signed-off-by: Michal Marek Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index b75820bbd..e3b12c010 100644 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -4,7 +4,7 @@ # What library to link ldflags() { - for ext in so a dylib ; do + for ext in so a dll.a dylib ; do for lib in ncursesw ncurses curses ; do $cc -print-file-name=lib${lib}.${ext} | grep -q / if [ $? -eq 0 ]; then -- cgit v1.2.3-55-g6feb From 8c3f943410ccfd79bb24eaa816dc8d57200d7a4c Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Tue, 2 Oct 2012 16:42:36 +0200 Subject: kbuild: Fix gcc -x syntax The correct syntax for gcc -x is "gcc -x assembler", not "gcc -xassembler". Even though the latter happens to work, the former is what is documented in the manual page and thus what gcc wrappers such as icecream do expect. This isn't a cosmetic change. The missing space prevents icecream from recognizing compilation tasks it can't handle, leading to silent kernel miscompilations. Besides me, credits go to Michael Matz and Dirk Mueller for investigating the miscompilation issue and tracking it down to this incorrect -x parameter syntax. Signed-off-by: Jean Delvare Acked-by: Ingo Molnar Cc: stable@vger.kernel.org Cc: Bernhard Walle Cc: Michal Marek Cc: Ralf Baechle Signed-off-by: Michal Marek Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index e3b12c010..c8e8a7154 100644 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -38,7 +38,7 @@ trap "rm -f $tmp" 0 1 2 3 15 # Check if we can link to ncurses check() { - $cc -xc - -o $tmp 2>/dev/null <<'EOF' + $cc -x c - -o $tmp 2>/dev/null <<'EOF' #include CURSES_LOC main() {} EOF -- cgit v1.2.3-55-g6feb From f755430d79171b2391ad9bf18da036720ab83b70 Mon Sep 17 00:00:00 2001 From: Krzysztof Mazur Date: Mon, 8 Oct 2012 18:18:22 +0200 Subject: menuconfig: fix extended colors ncurses support The ncurses library allows for extended colors. The support for extended colors support depends on wide-character support. ncurses headers enable extended colors (NCURSES_EXT_COLORS) only when wide-character support is enabled (NCURSES_WIDECHAR). The "make menuconfig" uses wide-character ncursesw library, which can be compiled with wide-character support, but does not define NCURSES_WIDECHAR and it's using headers without wide-character (and extended colors) support. This fixes problems with colors on systems with enabled extended colors (like PLD Linux). Without this patch "make menuconfig" is hard to use. Signed-off-by: Krzysztof Mazur Signed-off-by: Michal Marek Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index c8e8a7154..80788137c 100644 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -21,6 +21,7 @@ ccflags() { if [ -f /usr/include/ncursesw/curses.h ]; then echo '-I/usr/include/ncursesw -DCURSES_LOC=""' + echo ' -DNCURSES_WIDECHAR=1' elif [ -f /usr/include/ncurses/ncurses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' elif [ -f /usr/include/ncurses/curses.h ]; then -- cgit v1.2.3-55-g6feb From e62c715b3ebd6fc1d832229ded946d053bd45b94 Mon Sep 17 00:00:00 2001 From: Justin Lecher Date: Wed, 6 Mar 2013 14:02:01 +0100 Subject: menuconfig: optionally use pkg-config to detect ncurses libs When building ncurses with --with-termlib several symbols get moved from libncurses.so to libtinfo.so. Thus when linking with libncurses.so, one additionally needs to link with libtinfo.so. The ncurses pkg-config module will be used to detect the necessary libs for linking. If not available the old heuristic for detection of the ncurses libs will be used. Signed-off-by: Justin Lecher Tested-by: "Yann E. MORIN" Signed-off-by: "Yann E. MORIN" Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index 80788137c..782d20085 100644 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -4,6 +4,8 @@ # What library to link ldflags() { + pkg-config --libs ncursesw 2>/dev/null && exit + pkg-config --libs ncurses 2>/dev/null && exit for ext in so a dll.a dylib ; do for lib in ncursesw ncurses curses ; do $cc -print-file-name=lib${lib}.${ext} | grep -q / -- cgit v1.2.3-55-g6feb From d35ba8b5eddedd50349adf9358574cdbbc3c47ef Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Fri, 22 Mar 2013 23:12:16 +0100 Subject: kconfig/lxdialog: rationalise the include paths where to find {.n}curses{,w}.h The current code does this: if [ -f /usr/include/ncursesw/curses.h ]; then echo '-I/usr/include/ncursesw -DCURSES_LOC=""' elif [ -f /usr/include/ncurses/ncurses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' elif [ -f /usr/include/ncurses/curses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' [...] This is merely inconsistent: - adding the full path to the directory in the -I directive, - especially since that path is already a sub-path of the system include path, - and then repeating the sub-path in the #include directive. Rationalise each include directive: - only use the filename in the #include directive, - keep the -I directives: they are always searched for before the system include path; this ensures the correct header is used. Using the -I directives and the filename-only in #include is more in line with how pkg-config behaves, eg.: $ pkg-config --cflags ncursesw -I/usr/include/ncursesw This paves the way for using pkg-config for CFLAGS, too, now we use it to find the libraries. Signed-off-by: "Yann E. MORIN" Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index 782d20085..9d2a4c585 100644 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -22,12 +22,12 @@ ldflags() ccflags() { if [ -f /usr/include/ncursesw/curses.h ]; then - echo '-I/usr/include/ncursesw -DCURSES_LOC=""' + echo '-I/usr/include/ncursesw -DCURSES_LOC=""' echo ' -DNCURSES_WIDECHAR=1' elif [ -f /usr/include/ncurses/ncurses.h ]; then echo '-I/usr/include/ncurses -DCURSES_LOC=""' elif [ -f /usr/include/ncurses/curses.h ]; then - echo '-I/usr/include/ncurses -DCURSES_LOC=""' + echo '-I/usr/include/ncurses -DCURSES_LOC=""' elif [ -f /usr/include/ncurses.h ]; then echo '-DCURSES_LOC=""' else -- cgit v1.2.3-55-g6feb From 935fe68236f21bf641b316fea1867754e754911b Mon Sep 17 00:00:00 2001 From: Michal Marek Date: Wed, 20 Aug 2014 16:02:59 +0200 Subject: kbuild: Make scripts executable The Makefiles call the respective interpreter explicitly, but this makes it easier to use the scripts manually. Signed-off-by: Michal Marek Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/kconfig/lxdialog/check-lxdialog.sh diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh old mode 100644 new mode 100755 -- cgit v1.2.3-55-g6feb From d63d77a7f03eaa49729619a14aa9a12a0e9f95ad Mon Sep 17 00:00:00 2001 From: Bjørn Forsman Date: Sun, 14 Sep 2014 12:57:50 +0200 Subject: kconfig/lxdialog: get ncurses CFLAGS with pkg-config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes "make menuconfig" also work on systems where ncurses is not installed in a standard location (such as on NixOS). This patch changes ccflags() so that it tries pkg-config first, and only if pkg-config fails does it go back to the fallback/manual checks. This is the same algorithm that ldflags() already uses. Signed-off-by: Bjørn Forsman Signed-off-by: Michal Marek Signed-off-by: Mike Frysinger --- scripts/kconfig/lxdialog/check-lxdialog.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh index 9d2a4c585..5075ebf2d 100755 --- a/scripts/kconfig/lxdialog/check-lxdialog.sh +++ b/scripts/kconfig/lxdialog/check-lxdialog.sh @@ -21,7 +21,11 @@ ldflags() # Where is ncurses.h? ccflags() { - if [ -f /usr/include/ncursesw/curses.h ]; then + if pkg-config --cflags ncursesw 2>/dev/null; then + echo '-DCURSES_LOC="" -DNCURSES_WIDECHAR=1' + elif pkg-config --cflags ncurses 2>/dev/null; then + echo '-DCURSES_LOC=""' + elif [ -f /usr/include/ncursesw/curses.h ]; then echo '-I/usr/include/ncursesw -DCURSES_LOC=""' echo ' -DNCURSES_WIDECHAR=1' elif [ -f /usr/include/ncurses/ncurses.h ]; then -- cgit v1.2.3-55-g6feb From ea1b44412a5802f507880ae8b705d58360e387c0 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 4 Apr 2016 01:28:32 -0400 Subject: syslogd: minor tweaks to text Signed-off-by: Mike Frysinger --- sysklogd/syslogd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 0ea557a6c..a119bdeae 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -33,7 +33,7 @@ //config: depends on SYSLOGD //config: help //config: This enables syslogd to rotate the message files -//config: on his own. No need to use an external rotatescript. +//config: on his own. No need to use an external rotate script. //config: //config:config FEATURE_REMOTE_LOG //config: bool "Remote Log support" @@ -133,7 +133,7 @@ //usage: IF_FEATURE_KMSG_SYSLOG( //usage: "\n -K Log to kernel printk buffer (use dmesg to read it)" //usage: ) -//usage: "\n -O FILE Log to FILE (default:/var/log/messages, stdout if -)" +//usage: "\n -O FILE Log to FILE (default: /var/log/messages, stdout if -)" //usage: IF_FEATURE_ROTATE_LOGFILE( //usage: "\n -s SIZE Max size (KB) before rotation (default:200KB, 0=off)" //usage: "\n -b N N rotated logs to keep (default:1, max=99, 0=purge)" -- cgit v1.2.3-55-g6feb From ee22fe8793679e0f366a5501e3c7b576a9eb46c9 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 4 Apr 2016 01:35:34 -0400 Subject: undeb: clean up Signed-off-by: Mike Frysinger --- examples/undeb | 74 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/examples/undeb b/examples/undeb index 37104e9d8..c30baf31b 100755 --- a/examples/undeb +++ b/examples/undeb @@ -5,49 +5,55 @@ # Requires the programs (ar, tar, gzip, and the pager more or less). # usage() { -echo "Usage: undeb -c package.deb " -echo " undeb -l package.deb " -echo " undeb -x package.deb /foo/boo " -exit + cat < + undeb -l package.deb + undeb -x package.deb /foo/boo +EOF + exit } deb=$2 exist() { -if [ "$deb" = "" ]; then -usage -elif [ ! -s "$deb" ]; then -echo "Can't find $deb!" -exit -fi + if [ -z "${deb}" ]; then + usage + elif [ ! -s "${deb}" ]; then + echo "Can't find ${deb}!" + exit 1 + fi } -if [ "$1" = "" ]; then -usage +if [ -z "$1" ]; then + usage elif [ "$1" = "-l" ]; then -exist -type more >/dev/null 2>&1 && pager=more -type less >/dev/null 2>&1 && pager=less -[ "$pager" = "" ] && echo "No pager found!" && exit -(ar -p $deb control.tar.gz | tar -xzO *control ; echo -e "\nPress enter to scroll, q to Quit!\n" ; ar -p $deb data.tar.gz | tar -tzv) | $pager -exit + exist + type more >/dev/null 2>&1 && pager=more + type less >/dev/null 2>&1 && pager=less + [ -z "${pager}" ] && echo "No pager found!" && exit 1 + ( + ar -p "${deb}" control.tar.gz | tar -xzO *control + printf "\nPress enter to scroll, q to Quit!\n\n" + ar -p "${deb}" data.tar.gz | tar -tzv + ) | ${pager} + exit elif [ "$1" = "-c" ]; then -exist -ar -p $deb control.tar.gz | tar -xzO *control -exit + exist + ar -p "${deb}" control.tar.gz | tar -xzO *control + exit elif [ "$1" = "-x" ]; then -exist -if [ "$3" = "" ]; then -usage -elif [ ! -d "$3" ]; then -echo "No such directory $3!" -exit -fi -ar -p $deb data.tar.gz | tar -xzvpf - -C $3 || exit -echo -echo "Extracted $deb to $3!" -exit + exist + if [ -z "$3" ]; then + usage + elif [ ! -d "$3" ]; then + echo "No such directory $3!" + exit 1 + fi + ar -p "${deb}" data.tar.gz | tar -xzvpf - -C "$3" || exit + echo + echo "Extracted ${deb} to $3!" + exit else -usage + usage fi -- cgit v1.2.3-55-g6feb From d7d4750e1e213e7448147186dddfe3bfbb47eea0 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 4 Apr 2016 01:39:17 -0400 Subject: unrpm: clean up Signed-off-by: Mike Frysinger --- examples/unrpm | 65 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/examples/unrpm b/examples/unrpm index 7fd3676f6..f48550b0a 100755 --- a/examples/unrpm +++ b/examples/unrpm @@ -5,44 +5,49 @@ # Requires the programs (cpio, gzip, and the pager more or less). # usage() { -echo "Usage: unrpm -l package.rpm " -echo " unrpm -x package.rpm /foo/boo " -exit + cat < + unrpm -x package.rpm /foo/boo +EOF + exit } rpm=$2 exist() { -if [ "$rpm" = "" ]; then -usage -elif [ ! -s "$rpm" ]; then -echo "Can't find $rpm!" -exit -fi + if [ -z "${rpm}" ]; then + usage + elif [ ! -s "${rpm}" ]; then + echo "Can't find ${rpm}!" + exit 1 + fi } -if [ "$1" = "" ]; then -usage +if [ -z "$1" ]; then + usage elif [ "$1" = "-l" ]; then -exist -type more >/dev/null 2>&1 && pager=more -type less >/dev/null 2>&1 && pager=less -[ "$pager" = "" ] && echo "No pager found!" && exit -(echo -e "\nPress enter to scroll, q to Quit!\n" ; rpm2cpio $rpm | cpio -tv --quiet) | $pager -exit + exist + type more >/dev/null 2>&1 && pager=more + type less >/dev/null 2>&1 && pager=less + [ "$pager" = "" ] && echo "No pager found!" && exit + ( + printf "\nPress enter to scroll, q to Quit!\n\n" + rpm2cpio "${rpm}" | cpio -tv --quiet + ) | ${pager} + exit elif [ "$1" = "-x" ]; then -exist -if [ "$3" = "" ]; then -usage -elif [ ! -d "$3" ]; then -echo "No such directory $3!" -exit -fi -rpm2cpio $rpm | (umask 0 ; cd $3 ; cpio -idmuv) || exit -echo -echo "Extracted $rpm to $3!" -exit + exist + if [ -z "$3" ]; then + usage + elif [ ! -d "$3" ]; then + echo "No such directory $3!" + exit 1 + fi + rpm2cpio "${rpm}" | (umask 0 ; cd "$3" ; cpio -idmuv) || exit + echo + echo "Extracted ${rpm} to $3!" + exit else -usage + usage fi -- cgit v1.2.3-55-g6feb