From 2b9acc60c0468379cd24d13bc9e3f3e50761c0c9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 29 Sep 2017 14:09:02 +0200 Subject: udhcpc[6]: initialize entire sockaddr_ll I see random field values like sll_hatype=0x267 when I strace. They seem to not matter, but just in case they sometimes do, let's at least have deterministic values (via memset(0)). function old new delta change_listen_mode 308 322 +14 Signed-off-by: Denys Vlasenko --- networking/udhcp/d6_dhcpc.c | 5 +++++ networking/udhcp/d6_packet.c | 2 ++ networking/udhcp/dhcpc.c | 5 +++++ networking/udhcp/packet.c | 2 ++ 4 files changed, 14 insertions(+) diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 714555fa8..d4bb3507b 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -881,9 +881,14 @@ static int d6_raw_socket(int ifindex) fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)); log2("got raw socket fd %d", fd); + memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ sock.sll_family = AF_PACKET; sock.sll_protocol = htons(ETH_P_IPV6); sock.sll_ifindex = ifindex; + /*sock.sll_hatype = ARPHRD_???;*/ + /*sock.sll_pkttype = PACKET_???;*/ + /*sock.sll_halen = ???;*/ + /*sock.sll_addr[8] = ???;*/ xbind(fd, (struct sockaddr *) &sock, sizeof(sock)); #if 0 diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c index 79a0ac8a8..a0656c1da 100644 --- a/networking/udhcp/d6_packet.c +++ b/networking/udhcp/d6_packet.c @@ -75,6 +75,8 @@ int FAST_FUNC d6_send_raw_packet( dest_sll.sll_family = AF_PACKET; dest_sll.sll_protocol = htons(ETH_P_IPV6); dest_sll.sll_ifindex = ifindex; + /*dest_sll.sll_hatype = ARPHRD_???;*/ + /*dest_sll.sll_pkttype = PACKET_???;*/ dest_sll.sll_halen = 6; memcpy(dest_sll.sll_addr, dest_arp, 6); diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 99d91bf70..6c74996ef 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1010,9 +1010,14 @@ static int udhcp_raw_socket(int ifindex) */ log2("got raw socket fd"); + memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ sock.sll_family = AF_PACKET; sock.sll_protocol = htons(ETH_P_IP); sock.sll_ifindex = ifindex; + /*sock.sll_hatype = ARPHRD_???;*/ + /*sock.sll_pkttype = PACKET_???;*/ + /*sock.sll_halen = ???;*/ + /*sock.sll_addr[8] = ???;*/ xbind(fd, (struct sockaddr *) &sock, sizeof(sock)); #if 0 /* Several users reported breakage when BPF filter is used */ diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 9e1b46d2f..44d9ceec7 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c @@ -129,6 +129,8 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt, dest_sll.sll_family = AF_PACKET; dest_sll.sll_protocol = htons(ETH_P_IP); dest_sll.sll_ifindex = ifindex; + /*dest_sll.sll_hatype = ARPHRD_???;*/ + /*dest_sll.sll_pkttype = PACKET_???;*/ dest_sll.sll_halen = 6; memcpy(dest_sll.sll_addr, dest_arp, 6); -- cgit v1.2.3-55-g6feb From a6a3ad327360669e0c12552f680382e3b9713489 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 29 Sep 2017 15:55:24 +0200 Subject: udhcpc: paranoia when using kernel UDP mode for sending renew: server ID may be bogus With new code, we request that target IP (server ID) must be directly reachable. If it's not, this happens: udhcpc: waiting 2000 seconds udhcpc: entering listen mode: kernel udhcpc: opening listen socket on *:68 wlan0 udhcpc: entering renew state udhcpc: sending renew to 1.1.1.1 udhcpc: send: Network is unreachable ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1.1.1.1 needs routing, this is fishy! udhcpc: entering rebinding state udhcpc: entering listen mode: raw udhcpc: created raw socket udhcpc: sending renew to 0.0.0.0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ going to use broadcast which is the desired behavior. Before the patch, packet to 1.1.1.1 was routed over eth0 (!) and maybe even into Internet (!!!). function old new delta udhcpc_main 2752 2763 +11 udhcp_send_kernel_packet 295 301 +6 send_renew 82 84 +2 send_packet 166 168 +2 bcast_or_ucast 23 25 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 23/0) Total: 23 bytes Signed-off-by: Denys Vlasenko --- networking/udhcp/common.h | 4 +++- networking/udhcp/d6_dhcpc.c | 4 +++- networking/udhcp/dhcpc.c | 34 ++++++++++++++++++++++++---------- networking/udhcp/dhcpd.c | 4 +++- networking/udhcp/packet.c | 7 ++++--- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index a9c23a186..04939e707 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h @@ -308,7 +308,9 @@ int udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt, int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt, uint32_t source_nip, int source_port, - uint32_t dest_nip, int dest_port) FAST_FUNC; + uint32_t dest_nip, int dest_port, + int send_flags +) FAST_FUNC; void udhcp_sp_setup(void) FAST_FUNC; void udhcp_sp_fd_set(struct pollfd *pfds, int extra_fd) FAST_FUNC; diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index d4bb3507b..c13f23505 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -702,13 +702,15 @@ static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, st opt_ptr = add_d6_client_options(opt_ptr); bb_error_msg("sending %s", "renew"); - if (server_ipv6) + if (server_ipv6) { return d6_send_kernel_packet( &packet, (opt_ptr - (uint8_t*) &packet), our_cur_ipv6, CLIENT_PORT6, server_ipv6, SERVER_PORT6, client_config.ifindex + /* TODO? send_flags: MSG_DONTROUTE (see IPv4 code for reason why) */ ); + } return d6_mcast_from_client_config_ifindex(&packet, opt_ptr); } diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 6c74996ef..2ae8bcc4d 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -694,10 +694,16 @@ static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet, uint static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server) { - if (server) + if (server) { + /* Without MSG_DONTROUTE, the packet was seen routed over + * _other interface_ if server ID is bogus (example: 1.1.1.1). + */ return udhcp_send_kernel_packet(packet, ciaddr, CLIENT_PORT, - server, SERVER_PORT); + server, SERVER_PORT, + /*send_flags: "to hosts only on directly connected networks" */ MSG_DONTROUTE + ); + } return raw_bcast_from_client_config_ifindex(packet, ciaddr); } @@ -735,7 +741,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requested) { struct dhcp_packet packet; - struct in_addr addr; + struct in_addr temp_addr; /* * RFC 2131 4.3.2 DHCPREQUEST message @@ -766,8 +772,8 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste */ add_client_options(&packet); - addr.s_addr = requested; - bb_error_msg("sending select for %s", inet_ntoa(addr)); + temp_addr.s_addr = requested; + bb_error_msg("sending select for %s", inet_ntoa(temp_addr)); return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); } @@ -776,6 +782,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) { struct dhcp_packet packet; + struct in_addr temp_addr; /* * RFC 2131 4.3.2 DHCPREQUEST message @@ -806,7 +813,8 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) */ add_client_options(&packet); - bb_error_msg("sending %s", "renew"); + temp_addr.s_addr = server; + bb_error_msg("sending renew to %s", inet_ntoa(temp_addr)); return bcast_or_ucast(&packet, ciaddr, server); } @@ -1524,11 +1532,17 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) * Anyway, it does recover by eventually failing through * into INIT_SELECTING state. */ - send_renew(xid, server_addr, requested_ip); - timeout >>= 1; - continue; + if (send_renew(xid, server_addr, requested_ip) >= 0) { + timeout >>= 1; + continue; + } + /* else: error sending. + * example: ENETUNREACH seen with server + * which gave us bogus server ID 1.1.1.1 + * which wasn't reachable (and probably did not exist). + */ } - /* Timed out, enter rebinding state */ + /* Timed out or error, enter rebinding state */ log1("entering rebinding state"); state = REBINDING; /* fall right through */ diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 05ddc8649..57d8b36c5 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -588,7 +588,9 @@ static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt) udhcp_send_kernel_packet(dhcp_pkt, server_config.server_nip, SERVER_PORT, - dhcp_pkt->gateway_nip, SERVER_PORT); + dhcp_pkt->gateway_nip, SERVER_PORT, + /*send_flags:*/ 0 + ); } static void send_packet(struct dhcp_packet *dhcp_pkt, int force_broadcast) diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 44d9ceec7..ad0028bd0 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c @@ -191,7 +191,8 @@ int FAST_FUNC udhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt, /* Let the kernel do all the work for packet generation */ int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt, uint32_t source_nip, int source_port, - uint32_t dest_nip, int dest_port) + uint32_t dest_nip, int dest_port, + int send_flags) { struct sockaddr_in sa; unsigned padding; @@ -228,8 +229,8 @@ int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt, padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(dhcp_pkt->options); if (padding > DHCP_SIZE - 300) padding = DHCP_SIZE - 300; - result = safe_write(fd, dhcp_pkt, DHCP_SIZE - padding); - msg = "write"; + result = send(fd, dhcp_pkt, DHCP_SIZE - padding, send_flags); + msg = "send"; ret_close: close(fd); if (result < 0) { -- cgit v1.2.3-55-g6feb From f625836e6059d307e951a60b60f1c9ed259ee983 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 29 Sep 2017 18:02:01 +0200 Subject: udhcpc[6]: make log2 messages for chaddr field indented like the rest Signed-off-by: Denys Vlasenko --- networking/udhcp/d6_packet.c | 2 +- networking/udhcp/dhcpc.c | 7 +++++++ networking/udhcp/packet.c | 6 ++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/networking/udhcp/d6_packet.c b/networking/udhcp/d6_packet.c index a0656c1da..493943d72 100644 --- a/networking/udhcp/d6_packet.c +++ b/networking/udhcp/d6_packet.c @@ -18,7 +18,7 @@ void FAST_FUNC d6_dump_packet(struct d6_packet *packet) return; bb_error_msg( - "xid %x" + " xid %x" , packet->d6_xid32 ); //*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0'; diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 2ae8bcc4d..4548d4ac7 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1534,6 +1534,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) */ if (send_renew(xid, server_addr, requested_ip) >= 0) { timeout >>= 1; +//TODO: the timeout to receive an answer for our renew should not be selected +//with "timeout = lease_seconds / 2; ...; timeout = timeout / 2": it is often huge. +//Waiting e.g. 4*3600 seconds for a reply does not make sense +//(if reply isn't coming, we keep an open socket for hours), +//it should be something like 10 seconds. +//Also, it's probably best to try sending renew in kernel mode a few (3-5) times +//and fall back to raw mode if it does not work. continue; } /* else: error sending. diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index ad0028bd0..fc2bb5416 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c @@ -41,7 +41,7 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet) return; bb_error_msg( - //"op %x" + //" op %x" //" htype %x" " hlen %x" //" hops %x" @@ -52,7 +52,6 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet) " yiaddr %x" " siaddr %x" " giaddr %x" - //" chaddr %s" //" sname %s" //" file %s" //" cookie %x" @@ -68,14 +67,13 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet) , packet->yiaddr , packet->siaddr_nip , packet->gateway_nip - //, packet->chaddr[16] //, packet->sname[64] //, packet->file[128] //, packet->cookie //, packet->options[] ); *bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0'; - bb_error_msg("chaddr %s", buf); + bb_error_msg(" chaddr %s", buf); } #endif -- cgit v1.2.3-55-g6feb From 6f97b30a904407c1f1701d937d9258ca9175c6ab Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 29 Sep 2017 18:17:25 +0200 Subject: use %m printf specifier where appropriate function old new delta out 85 75 -10 udhcpd_main 1472 1461 -11 open_stdio_to_tty 98 85 -13 init_exec 245 232 -13 udhcpc_main 2763 2749 -14 do_cmd 4771 4755 -16 status_line_bold_errno 32 14 -18 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-95) Total: -95 bytes Signed-off-by: Denys Vlasenko --- editors/vi.c | 6 +++--- include/libbb.h | 11 +++++++++++ init/init.c | 8 +++++--- networking/udhcp/d6_dhcpc.c | 2 +- networking/udhcp/dhcpc.c | 2 +- networking/udhcp/dhcpd.c | 2 +- runit/sv.c | 2 +- selinux/matchpathcon.c | 2 +- shell/ash.c | 9 +-------- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/editors/vi.c b/editors/vi.c index 60c73c0eb..cdfb27cc5 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -1038,7 +1038,7 @@ static void colon(char *buf) } if (cnt < 0) { if (cnt == -1) - status_line_bold("Write error: %s", strerror(errno)); + status_line_bold("Write error: "STRERROR_FMT STRERROR_ERRNO); } else { modified_count = 0; last_modified_count = -1; @@ -3131,7 +3131,7 @@ static void status_line_bold(const char *format, ...) static void status_line_bold_errno(const char *fn) { - status_line_bold("'%s' %s", fn, strerror(errno)); + status_line_bold("'%s' "STRERROR_FMT, fn STRERROR_ERRNO); } // format status buffer @@ -4066,7 +4066,7 @@ static void do_cmd(int c) cnt = file_write(current_filename, text, end - 1); if (cnt < 0) { if (cnt == -1) - status_line_bold("Write error: %s", strerror(errno)); + status_line_bold("Write error: "STRERROR_FMT STRERROR_ERRNO); } else if (cnt == (end - 1 - text + 1)) { editing = 0; } diff --git a/include/libbb.h b/include/libbb.h index aff2825ac..daccf154a 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -162,6 +162,17 @@ #ifndef HAVE_XTABS # define XTABS TAB3 #endif +/* + * Use '%m' to append error string on platforms that support it, + * '%s' and strerror() on those that don't. + */ +#ifdef HAVE_PRINTF_PERCENTM +# define STRERROR_FMT "%m" +# define STRERROR_ERRNO /*nothing*/ +#else +# define STRERROR_FMT "%s" +# define STRERROR_ERRNO ,strerror(errno) +#endif /* Some libc's forget to declare these, do it ourself */ diff --git a/init/init.c b/init/init.c index 64e5c3e0b..5304e5c2c 100644 --- a/init/init.c +++ b/init/init.c @@ -391,8 +391,10 @@ static int open_stdio_to_tty(const char* tty_name) /* fd can be only < 0 or 0: */ fd = device_open(tty_name, O_RDWR); if (fd) { - message(L_LOG | L_CONSOLE, "can't open %s: %s", - tty_name, strerror(errno)); + message(L_LOG | L_CONSOLE, "can't open %s: "STRERROR_FMT, + tty_name + STRERROR_ERRNO + ); return 0; /* failure */ } dup2(STDIN_FILENO, STDOUT_FILENO); @@ -469,7 +471,7 @@ static void init_exec(const char *command) } /* Here command never contains the dash, cmd[0] might */ BB_EXECVP(command, cmd); - message(L_LOG | L_CONSOLE, "can't run '%s': %s", command, strerror(errno)); + message(L_LOG | L_CONSOLE, "can't run '%s': "STRERROR_FMT, command STRERROR_ERRNO); /* returns if execvp fails */ } diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index c13f23505..37ffd064d 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -1432,7 +1432,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_error_msg("read error: %s, reopening socket", strerror(errno)); + bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); sleep(discover_timeout); /* 3 seconds by default */ change_listen_mode(listen_mode); /* just close and reopen */ } diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 4548d4ac7..0013f4aa7 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1631,7 +1631,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_error_msg("read error: %s, reopening socket", strerror(errno)); + bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); sleep(discover_timeout); /* 3 seconds by default */ change_listen_mode(listen_mode); /* just close and reopen */ } diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 57d8b36c5..238542bb0 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c @@ -948,7 +948,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: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); close(server_socket); server_socket = -1; } diff --git a/runit/sv.c b/runit/sv.c index 1d0809be8..dc5dcceb3 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -224,7 +224,7 @@ static void out(const char *p, const char *m1) { printf("%s%s%s: %s", p, *service, islog ? "/log" : "", m1); if (errno) { - printf(": %s", strerror(errno)); + printf(": "STRERROR_FMT STRERROR_ERRNO); } bb_putchar('\n'); /* will also flush the output */ } diff --git a/selinux/matchpathcon.c b/selinux/matchpathcon.c index e57120d3b..6945a0295 100644 --- a/selinux/matchpathcon.c +++ b/selinux/matchpathcon.c @@ -104,7 +104,7 @@ int matchpathcon_main(int argc UNUSED_PARAM, char **argv) freecon(con); continue; } - printf("actual context unknown: %s, should be ", strerror(errno)); + printf("actual context unknown: "STRERROR_FMT", should be " STRERROR_ERRNO); error += print_matchpathcon(path, 1); } matchpathcon_fini(); diff --git a/shell/ash.c b/shell/ash.c index 3fa7f4d9f..39705a350 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -1312,16 +1312,9 @@ ash_msg_and_raise_error(const char *msg, ...) } /* - * Use '%m' to append error string on platforms that support it, '%s' and - * strerror() on those that don't. - * * 'fmt' must be a string literal. */ -#ifdef HAVE_PRINTF_PERCENTM -#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %m", ##__VA_ARGS__) -#else -#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": %s", ##__VA_ARGS__, strerror(errno)) -#endif +#define ash_msg_and_raise_perror(fmt, ...) ash_msg_and_raise_error(fmt ": "STRERROR_FMT, ##__VA_ARGS__ STRERROR_ERRNO) static void raise_error_syntax(const char *) NORETURN; static void -- cgit v1.2.3-55-g6feb From b5d9ba8fe64a0aacf99fd1eec10375a98104a5ea Mon Sep 17 00:00:00 2001 From: Avi Fishman Date: Thu, 5 Oct 2017 11:25:16 +0200 Subject: i2cset: fix 'i' & 's' modes (3 extra bytes were sent) When 'i' or 's' modes are selected block array is filled from offset 3 (blen = 3) but copied to data.block buffer from offset 0 so first 3 bytes contains garbage from stack. The buffer that is sent is also 3 bytes too long due to those extra 3 bytes. Signed-off-by: Avi Fishman Signed-off-by: Denys Vlasenko --- miscutils/i2c_tools.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index fc392d9dc..82f9842bd 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c @@ -562,14 +562,19 @@ int i2cset_main(int argc, char **argv) opt_m = (1 << 2), opt_r = (1 << 3); int bus_num, bus_addr, data_addr, mode = I2C_SMBUS_BYTE, pec = 0; - int val, blen = 0, mask = 0, fd, status; + int val, blen, mask, fd, status; unsigned char block[I2C_SMBUS_BLOCK_MAX]; char *opt_m_arg = NULL; unsigned opts; - opts = getopt32(argv, "^" "fym:r" "\0" "-3"/*from 3 to ? args*/, &opt_m_arg); + opts = getopt32(argv, "^" + "fym:r" + "\0" "-3", /* minimum 3 args */ + &opt_m_arg + ); argv += optind; argc -= optind; + argc--; /* now argv[argc] is last arg */ bus_num = i2c_bus_lookup(argv[0]); bus_addr = i2c_parse_bus_addr(argv[1]); @@ -579,20 +584,26 @@ int i2cset_main(int argc, char **argv) if (!argv[4] && argv[3][0] != 'c') { mode = I2C_SMBUS_BYTE_DATA; /* Implicit b */ } else { - switch (argv[argc-1][0]) { - case 'c': /* Already set */ break; - case 'b': mode = I2C_SMBUS_BYTE_DATA; break; - case 'w': mode = I2C_SMBUS_WORD_DATA; break; - case 's': mode = I2C_SMBUS_BLOCK_DATA; break; - case 'i': mode = I2C_SMBUS_I2C_BLOCK_DATA; break; + switch (argv[argc][0]) { + case 'c': /* Already set */ + break; + case 'b': mode = I2C_SMBUS_BYTE_DATA; + break; + case 'w': mode = I2C_SMBUS_WORD_DATA; + break; + case 's': mode = I2C_SMBUS_BLOCK_DATA; + break; + case 'i': mode = I2C_SMBUS_I2C_BLOCK_DATA; + break; default: bb_error_msg("invalid mode"); bb_show_usage(); } - pec = argv[argc-1][1] == 'p'; - if (mode == I2C_SMBUS_BLOCK_DATA || - mode == I2C_SMBUS_I2C_BLOCK_DATA) { + pec = (argv[argc][1] == 'p'); + if (mode == I2C_SMBUS_BLOCK_DATA + || mode == I2C_SMBUS_I2C_BLOCK_DATA + ) { if (pec && mode == I2C_SMBUS_I2C_BLOCK_DATA) bb_error_msg_and_die( "PEC not supported for I2C " @@ -606,6 +617,8 @@ int i2cset_main(int argc, char **argv) } /* Prepare the value(s) to be written according to current mode. */ + mask = 0; + blen = 0; switch (mode) { case I2C_SMBUS_BYTE_DATA: val = xstrtou_range(argv[3], 0, 0, 0xff); @@ -615,8 +628,9 @@ int i2cset_main(int argc, char **argv) break; case I2C_SMBUS_BLOCK_DATA: case I2C_SMBUS_I2C_BLOCK_DATA: - for (blen = 3; blen < (argc - 1); blen++) - block[blen] = xstrtou_range(argv[blen], 0, 0, 0xff); + for (blen = 3; blen < argc; blen++) + block[blen - 3] = xstrtou_range(argv[blen], 0, 0, 0xff); + blen -= 3; val = -1; break; default: -- cgit v1.2.3-55-g6feb From 6e2beb7dfee1a4542eca1a6e8c0f33486d9d5fb9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Oct 2017 12:53:25 +0200 Subject: date: maybe_set_utc only once It's not clear at all why we do it twice. git archaeology did not help. function old new delta date_main 836 839 +3 maybe_set_utc 16 - -16 Signed-off-by: Denys Vlasenko --- coreutils/date.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/coreutils/date.c b/coreutils/date.c index 5b15ce778..87dc3bbd0 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -36,8 +36,8 @@ //config:# defaults to "no": stat's nanosecond field is a bit non-portable //config:config FEATURE_DATE_NANO //config: bool "Support %[num]N nanosecond format specifier" -//config: default n -//config: depends on DATE # syscall(__NR_clock_gettime) +//config: default n # syscall(__NR_clock_gettime) +//config: depends on DATE //config: select PLATFORM_LINUX //config: help //config: Support %[num]N format specifier. Adds ~250 bytes of code. @@ -203,6 +203,7 @@ int date_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt) ); argv += optind; + maybe_set_utc(opt); if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_TIMESPEC)) { @@ -301,8 +302,6 @@ int date_main(int argc UNUSED_PARAM, char **argv) tm_time.tm_isdst = -1; ts.tv_sec = validate_tm_time(date_str, &tm_time); - maybe_set_utc(opt); - /* if setting time, set it */ if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) { bb_perror_msg("can't set date"); -- cgit v1.2.3-55-g6feb From 318c8114deb4acd10e74398c5fb4c0068c86bcb1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Oct 2017 14:06:49 +0200 Subject: free: make it NOFORK function old new delta parse_cached_kb - 85 +85 free_main 580 537 -43 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 85/-43) Total: 42 bytes Signed-off-by: Denys Vlasenko --- NOFORK_NOEXEC.lst | 2 +- procps/free.c | 51 +++++++++++++++++++++++---------------------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/NOFORK_NOEXEC.lst b/NOFORK_NOEXEC.lst index 4e53d7204..72c33ddd7 100644 --- a/NOFORK_NOEXEC.lst +++ b/NOFORK_NOEXEC.lst @@ -144,7 +144,7 @@ flash_unlock - hardware flashcp - hardware flock - spawner, changes state (file locks), let's play safe and not be noexec fold - noexec. runner -free - noexec. nofork candidate(struct globals, needs to close /proc/meminfo fd) +free - NOFORK freeramdisk - noexec. leaks: open+ioctl_or_perror_and_die fsck - interactive, longterm fsck.minix - needs ^C diff --git a/procps/free.c b/procps/free.c index b57e4a322..fa423cfa5 100644 --- a/procps/free.c +++ b/procps/free.c @@ -15,7 +15,7 @@ //config: memory in the system, as well as the buffers used by the kernel. //config: The shared memory column should be ignored; it is obsolete. -//applet:IF_FREE(APPLET_NOEXEC(free, free, BB_DIR_USR_BIN, BB_SUID_DROP, free)) +//applet:IF_FREE(APPLET_NOFORK(free, free, BB_DIR_USR_BIN, BB_SUID_DROP, free)) //kbuild:lib-$(CONFIG_FREE) += free.o @@ -40,25 +40,21 @@ struct globals { unsigned mem_unit; #if ENABLE_DESKTOP - unsigned unit_steps; -# define G_unit_steps G.unit_steps + uint8_t unit_steps; +# define G_unit_steps g->unit_steps #else # define G_unit_steps 10 #endif -} FIX_ALIASING; -#define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { \ - setup_common_bufsiz(); \ - /* NB: noexec applet - globals not zeroed */ \ -} while (0) +}; +/* Because of NOFORK, "globals" are not in global data */ - -static unsigned long long scale(unsigned long d) +static unsigned long long scale(struct globals *g, unsigned long d) { - return ((unsigned long long)d * G.mem_unit) >> G_unit_steps; + return ((unsigned long long)d * g->mem_unit) >> G_unit_steps; } -static unsigned long parse_cached_kb(void) +/* NOINLINE reduces main() stack usage, which makes code smaller (on x86 at least) */ +static NOINLINE unsigned long parse_cached_kb(void) { char buf[60]; /* actual lines we expect are ~30 chars or less */ FILE *fp; @@ -69,8 +65,8 @@ static unsigned long parse_cached_kb(void) if (sscanf(buf, "Cached: %lu %*s\n", &cached) == 1) break; } - if (ENABLE_FEATURE_CLEAN_UP) - fclose(fp); + /* Have to close because of NOFORK */ + fclose(fp); return cached; } @@ -78,11 +74,10 @@ static unsigned long parse_cached_kb(void) int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) { + struct globals G; struct sysinfo info; unsigned long long cached; - INIT_G(); - #if ENABLE_DESKTOP G.unit_steps = 10; if (argv[1] && argv[1][0] == '-') { @@ -123,12 +118,12 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) #define FIELDS_2 (FIELDS_6 + 4*6) printf(FIELDS_6, - scale(info.totalram), //total - scale(info.totalram - info.freeram), //used - scale(info.freeram), //free - scale(info.sharedram), //shared - scale(info.bufferram), //buffers - scale(cached) //cached + scale(&G, info.totalram), //total + scale(&G, info.totalram - info.freeram), //used + scale(&G, info.freeram), //free + scale(&G, info.sharedram), //shared + scale(&G, info.bufferram), //buffers + scale(&G, cached) //cached ); /* Show alternate, more meaningful busy/free numbers by counting * buffer cache as free memory. */ @@ -136,15 +131,15 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) cached += info.freeram; cached += info.bufferram; printf(FIELDS_2, - scale(info.totalram - cached), //used - scale(cached) //free + scale(&G, info.totalram - cached), //used + scale(&G, cached) //free ); #if BB_MMU printf("Swap: "); printf(FIELDS_3, - scale(info.totalswap), //total - scale(info.totalswap - info.freeswap), //used - scale(info.freeswap) //free + scale(&G, info.totalswap), //total + scale(&G, info.totalswap - info.freeswap), //used + scale(&G, info.freeswap) //free ); #endif return EXIT_SUCCESS; -- cgit v1.2.3-55-g6feb From 099ef9324e88679e0b26f6f13476583e03f53dee Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Oct 2017 14:16:09 +0200 Subject: free: no longer include common_bufsiz.h Signed-off-by: Denys Vlasenko --- procps/free.c | 1 - 1 file changed, 1 deletion(-) diff --git a/procps/free.c b/procps/free.c index fa423cfa5..48139c4a3 100644 --- a/procps/free.c +++ b/procps/free.c @@ -32,7 +32,6 @@ //usage: "Total: 386144 257128 129016\n" #include "libbb.h" -#include "common_bufsiz.h" #ifdef __linux__ # include #endif -- cgit v1.2.3-55-g6feb From ebe6d9d8758d36e03cf39b6587597c67ab778436 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Oct 2017 14:40:24 +0200 Subject: whitespace and comment format fixes, no code changes Signed-off-by: Denys Vlasenko --- archival/libarchive/common.c | 1 - archival/libarchive/data_align.c | 1 - archival/libarchive/data_extract_all.c | 1 - archival/libarchive/data_extract_to_command.c | 1 - archival/libarchive/data_extract_to_stdout.c | 1 - archival/libarchive/data_skip.c | 1 - archival/libarchive/decompress_bunzip2.c | 18 +++--- archival/libarchive/decompress_gunzip.c | 1 - archival/libarchive/filter_accept_all.c | 1 - archival/libarchive/filter_accept_list.c | 1 - archival/libarchive/filter_accept_list_reassign.c | 3 +- archival/libarchive/filter_accept_reject_list.c | 1 - archival/libarchive/find_list_entry.c | 1 - archival/libarchive/get_header_ar.c | 1 - archival/libarchive/get_header_cpio.c | 1 - archival/libarchive/get_header_tar.c | 1 - archival/libarchive/get_header_tar_bz2.c | 1 - archival/libarchive/get_header_tar_gz.c | 1 - archival/libarchive/get_header_tar_lzma.c | 1 - archival/libarchive/get_header_tar_xz.c | 1 - archival/libarchive/header_verbose_list.c | 1 - archival/libarchive/init_handle.c | 1 - archival/libarchive/open_transformer.c | 1 - archival/libarchive/seek_by_jump.c | 1 - archival/libarchive/seek_by_read.c | 1 - archival/libarchive/unpack_ar_archive.c | 1 - archival/libarchive/unsafe_prefix.c | 1 - console-tools/setconsole.c | 6 +- coreutils/fold.c | 18 +++--- coreutils/md5_sha1_sum.c | 4 +- coreutils/printf.c | 68 +++++++++++------------ coreutils/stty.c | 36 ++++++------ coreutils/uuencode.c | 6 +- libbb/ask_confirmation.c | 3 +- libbb/bb_askpass.c | 1 - libbb/bb_do_delay.c | 1 - libbb/bb_pwd.c | 1 - libbb/bb_qsort.c | 1 - libbb/bb_strtod.c | 1 - libbb/bb_strtonum.c | 1 - libbb/bbunit.c | 2 +- libbb/change_identity.c | 1 - libbb/chomp.c | 1 - libbb/compare_string_array.c | 1 - libbb/concat_path_file.c | 3 +- libbb/concat_subpath_file.c | 3 +- libbb/copyfd.c | 1 - libbb/correct_password.c | 1 - libbb/crc32.c | 1 - libbb/default_error_retval.c | 2 - libbb/device_open.c | 1 - libbb/die_if_bad_username.c | 1 - libbb/dump.c | 1 - libbb/executable.c | 1 - libbb/fclose_nonstdin.c | 4 +- libbb/fflush_stdout_and_exit.c | 4 +- libbb/fgets_str.c | 1 - libbb/find_mount_point.c | 1 - libbb/find_pid_by_name.c | 1 - libbb/find_root_device.c | 1 - libbb/full_write.c | 1 - libbb/get_console.c | 1 - libbb/get_line_from_file.c | 1 - libbb/getpty.c | 1 - libbb/hash_md5_sha.c | 1 - libbb/human_readable.c | 1 - libbb/in_ether.c | 1 - libbb/inet_common.c | 1 - libbb/inode_hash.c | 1 - libbb/isdirectory.c | 1 - libbb/kernel_version.c | 2 - libbb/last_char_is.c | 1 - libbb/llist.c | 1 - libbb/login.c | 1 - libbb/make_directory.c | 2 - libbb/match_fstype.c | 1 - libbb/messages.c | 1 - libbb/mode_string.c | 2 - libbb/mtab.c | 1 - libbb/nuke_str.c | 1 - libbb/parse_mode.c | 3 +- libbb/percent_decode.c | 1 - libbb/printable.c | 1 - libbb/process_escape_sequence.c | 1 - libbb/procps.c | 1 - libbb/ptr_to_globals.c | 1 - libbb/pw_encrypt.c | 1 - libbb/recursive_action.c | 1 - libbb/remove_file.c | 1 - libbb/replace.c | 1 - libbb/run_shell.c | 1 - libbb/safe_gethostname.c | 2 - libbb/safe_poll.c | 1 - libbb/safe_strncpy.c | 1 - libbb/safe_write.c | 1 - libbb/setup_environment.c | 1 - libbb/signals.c | 1 - libbb/skip_whitespace.c | 1 - libbb/speed_table.c | 1 - libbb/strrstr.c | 1 - libbb/trim.c | 1 - libbb/uuencode.c | 1 - libbb/wfopen.c | 1 - libbb/wfopen_input.c | 3 +- libbb/write.c | 1 - libbb/xatonum.c | 1 - libbb/xconnect.c | 1 - libbb/xfunc_die.c | 3 +- libbb/xfuncs.c | 2 - libbb/xfuncs_printf.c | 2 - libbb/xgetcwd.c | 1 - libbb/xreadlink.c | 1 - libbb/xrealloc_vector.c | 1 - libbb/xregcomp.c | 1 - libpwdgrp/pwd_grp.c | 1 - miscutils/devmem.c | 4 +- miscutils/time.c | 17 +++--- networking/ifupdown.c | 22 ++++---- networking/interface.c | 1 - networking/libiproute/ipneigh.c | 1 - networking/libiproute/libnetlink.c | 1 - networking/libiproute/ll_map.c | 1 - networking/libiproute/ll_proto.c | 1 - networking/udhcp/dhcpc.c | 1 - networking/udhcp/dhcprelay.c | 3 +- networking/udhcp/domain_codec.c | 4 +- sysklogd/syslogd_and_logger.c | 1 - util-linux/getopt.c | 3 +- util-linux/readprofile.c | 4 +- 129 files changed, 115 insertions(+), 241 deletions(-) diff --git a/archival/libarchive/common.c b/archival/libarchive/common.c index 389cb7856..25c7bddad 100644 --- a/archival/libarchive/common.c +++ b/archival/libarchive/common.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/data_align.c b/archival/libarchive/data_align.c index a6b84a440..f61fdd93f 100644 --- a/archival/libarchive/data_align.c +++ b/archival/libarchive/data_align.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/data_extract_all.c b/archival/libarchive/data_extract_all.c index e658444e0..d3a6df5e8 100644 --- a/archival/libarchive/data_extract_all.c +++ b/archival/libarchive/data_extract_all.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/data_extract_to_command.c b/archival/libarchive/data_extract_to_command.c index 5d8769382..1114a95cb 100644 --- a/archival/libarchive/data_extract_to_command.c +++ b/archival/libarchive/data_extract_to_command.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/data_extract_to_stdout.c b/archival/libarchive/data_extract_to_stdout.c index f849f3b42..520041329 100644 --- a/archival/libarchive/data_extract_to_stdout.c +++ b/archival/libarchive/data_extract_to_stdout.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/data_skip.c b/archival/libarchive/data_skip.c index 588167f01..1a608227e 100644 --- a/archival/libarchive/data_skip.c +++ b/archival/libarchive/data_skip.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c index 803702f75..af879648d 100644 --- a/archival/libarchive/decompress_bunzip2.c +++ b/archival/libarchive/decompress_bunzip2.c @@ -1,14 +1,13 @@ /* vi: set sw=4 ts=4: */ /* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net). - - Based on bzip2 decompression code by Julian R Seward (jseward@acm.org), - which also acknowledges contributions by Mike Burrows, David Wheeler, - Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten, - Robert Sedgewick, and Jon L. Bentley. - - Licensed under GPLv2 or later, see file LICENSE in this source tree. -*/ - + * + * Based on bzip2 decompression code by Julian R Seward (jseward@acm.org), + * which also acknowledges contributions by Mike Burrows, David Wheeler, + * Peter Fenwick, Alistair Moffat, Radford Neal, Ian H. Witten, + * Robert Sedgewick, and Jon L. Bentley. + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ /* Size and speed optimizations by Manuel Novoa III (mjn3@codepoet.org). @@ -38,7 +37,6 @@ Manuel */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index c7fa5b526..c8245d736 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c @@ -32,7 +32,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/filter_accept_all.c b/archival/libarchive/filter_accept_all.c index c33f7d3e3..5a0ee9c60 100644 --- a/archival/libarchive/filter_accept_all.c +++ b/archival/libarchive/filter_accept_all.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/filter_accept_list.c b/archival/libarchive/filter_accept_list.c index a2d4b23e9..32f806574 100644 --- a/archival/libarchive/filter_accept_list.c +++ b/archival/libarchive/filter_accept_list.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/filter_accept_list_reassign.c b/archival/libarchive/filter_accept_list_reassign.c index b9acfbc05..826c5c29d 100644 --- a/archival/libarchive/filter_accept_list_reassign.c +++ b/archival/libarchive/filter_accept_list_reassign.c @@ -1,10 +1,9 @@ /* vi: set sw=4 ts=4: */ /* - * Copyright (C) 2002 by Glenn McGrath + * Copyright (C) 2002 by Glenn McGrath * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/filter_accept_reject_list.c b/archival/libarchive/filter_accept_reject_list.c index 248374941..939e626fa 100644 --- a/archival/libarchive/filter_accept_reject_list.c +++ b/archival/libarchive/filter_accept_reject_list.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/find_list_entry.c b/archival/libarchive/find_list_entry.c index 56032c65a..37726bd3d 100644 --- a/archival/libarchive/find_list_entry.c +++ b/archival/libarchive/find_list_entry.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c index c66bb3ee7..79725e535 100644 --- a/archival/libarchive/get_header_ar.c +++ b/archival/libarchive/get_header_ar.c @@ -3,7 +3,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" #include "ar.h" diff --git a/archival/libarchive/get_header_cpio.c b/archival/libarchive/get_header_cpio.c index badd4a841..ba07622fd 100644 --- a/archival/libarchive/get_header_cpio.c +++ b/archival/libarchive/get_header_cpio.c @@ -3,7 +3,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index c7e3bc16e..443a478a1 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c @@ -10,7 +10,6 @@ * Opengroup's ustar interchange format, * http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/get_header_tar_bz2.c b/archival/libarchive/get_header_tar_bz2.c index 78f78a858..c021720ac 100644 --- a/archival/libarchive/get_header_tar_bz2.c +++ b/archival/libarchive/get_header_tar_bz2.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/get_header_tar_gz.c b/archival/libarchive/get_header_tar_gz.c index b11f503dc..793b161a1 100644 --- a/archival/libarchive/get_header_tar_gz.c +++ b/archival/libarchive/get_header_tar_gz.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/get_header_tar_lzma.c b/archival/libarchive/get_header_tar_lzma.c index d228cbc13..15d10adb8 100644 --- a/archival/libarchive/get_header_tar_lzma.c +++ b/archival/libarchive/get_header_tar_lzma.c @@ -5,7 +5,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/get_header_tar_xz.c b/archival/libarchive/get_header_tar_xz.c index 7bf3b3b56..852c989ce 100644 --- a/archival/libarchive/get_header_tar_xz.c +++ b/archival/libarchive/get_header_tar_xz.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/header_verbose_list.c b/archival/libarchive/header_verbose_list.c index 87dd82136..be5140f8b 100644 --- a/archival/libarchive/header_verbose_list.c +++ b/archival/libarchive/header_verbose_list.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/init_handle.c b/archival/libarchive/init_handle.c index dcba6666f..4c64dac58 100644 --- a/archival/libarchive/init_handle.c +++ b/archival/libarchive/init_handle.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c index e81a81072..9fefd4aad 100644 --- a/archival/libarchive/open_transformer.c +++ b/archival/libarchive/open_transformer.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/seek_by_jump.c b/archival/libarchive/seek_by_jump.c index 4fcd99ac8..232d97e53 100644 --- a/archival/libarchive/seek_by_jump.c +++ b/archival/libarchive/seek_by_jump.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/seek_by_read.c b/archival/libarchive/seek_by_read.c index c0fde9660..df2346354 100644 --- a/archival/libarchive/seek_by_read.c +++ b/archival/libarchive/seek_by_read.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/unpack_ar_archive.c b/archival/libarchive/unpack_ar_archive.c index 0bc030349..4f9f89874 100644 --- a/archival/libarchive/unpack_ar_archive.c +++ b/archival/libarchive/unpack_ar_archive.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" #include "ar.h" diff --git a/archival/libarchive/unsafe_prefix.c b/archival/libarchive/unsafe_prefix.c index 9994f4d94..33e487bf9 100644 --- a/archival/libarchive/unsafe_prefix.c +++ b/archival/libarchive/unsafe_prefix.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "bb_archive.h" diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c index bad2b76e4..7f0f9c711 100644 --- a/console-tools/setconsole.c +++ b/console-tools/setconsole.c @@ -1,9 +1,9 @@ /* vi: set sw=4 ts=4: */ /* - * setconsole.c - redirect system console output + * setconsole.c - redirect system console output * - * Copyright (C) 2004,2005 Enrik Berkhan - * Copyright (C) 2008 Bernhard Reutner-Fischer + * Copyright (C) 2004,2005 Enrik Berkhan + * Copyright (C) 2008 Bernhard Reutner-Fischer * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ diff --git a/coreutils/fold.c b/coreutils/fold.c index 286db228d..578e5a4b6 100644 --- a/coreutils/fold.c +++ b/coreutils/fold.c @@ -1,14 +1,14 @@ /* vi: set sw=4 ts=4: */ /* fold -- wrap each input line to fit in specified width. - - Written by David MacKenzie, djm@gnu.ai.mit.edu. - Copyright (C) 91, 1995-2002 Free Software Foundation, Inc. - - Modified for busybox based on coreutils v 5.0 - Copyright (C) 2003 Glenn McGrath - - Licensed under GPLv2 or later, see file LICENSE in this source tree. -*/ + * + * Written by David MacKenzie, djm@gnu.ai.mit.edu. + * Copyright (C) 91, 1995-2002 Free Software Foundation, Inc. + * + * Modified for busybox based on coreutils v 5.0 + * Copyright (C) 2003 Glenn McGrath + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ //config:config FOLD //config: bool "fold (4.6 kb)" //config: default y diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 89d6cec0b..ccdfd6855 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c @@ -1,7 +1,7 @@ /* vi: set sw=4 ts=4: */ /* - * Copyright (C) 2003 Glenn L. McGrath - * Copyright (C) 2003-2004 Erik Andersen + * Copyright (C) 2003 Glenn L. McGrath + * Copyright (C) 2003-2004 Erik Andersen * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ diff --git a/coreutils/printf.c b/coreutils/printf.c index 353cfc608..413273b26 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -1,41 +1,39 @@ /* vi: set sw=4 ts=4: */ /* printf - format and print data - - Copyright 1999 Dave Cinege - Portions copyright (C) 1990-1996 Free Software Foundation, Inc. - - Licensed under GPLv2 or later, see file LICENSE in this source tree. -*/ - + * + * Copyright 1999 Dave Cinege + * Portions copyright (C) 1990-1996 Free Software Foundation, Inc. + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ /* Usage: printf format [argument...] - - A front end to the printf function that lets it be used from the shell. - - Backslash escapes: - - \" = double quote - \\ = backslash - \a = alert (bell) - \b = backspace - \c = produce no further output - \f = form feed - \n = new line - \r = carriage return - \t = horizontal tab - \v = vertical tab - \0ooo = octal number (ooo is 0 to 3 digits) - \xhhh = hexadecimal number (hhh is 1 to 3 digits) - - Additional directive: - - %b = print an argument string, interpreting backslash escapes - - The 'format' argument is re-used as many times as necessary - to convert all of the given arguments. - - David MacKenzie -*/ - + * + * A front end to the printf function that lets it be used from the shell. + * + * Backslash escapes: + * + * \" = double quote + * \\ = backslash + * \a = alert (bell) + * \b = backspace + * \c = produce no further output + * \f = form feed + * \n = new line + * \r = carriage return + * \t = horizontal tab + * \v = vertical tab + * \0ooo = octal number (ooo is 0 to 3 digits) + * \xhhh = hexadecimal number (hhh is 1 to 3 digits) + * + * Additional directive: + * + * %b = print an argument string, interpreting backslash escapes + * + * The 'format' argument is re-used as many times as necessary + * to convert all of the given arguments. + * + * David MacKenzie + */ /* 19990508 Busy Boxed! Dave Cinege */ //config:config PRINTF diff --git a/coreutils/stty.c b/coreutils/stty.c index b6e836364..df23f4cae 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c @@ -1,24 +1,24 @@ /* vi: set sw=4 ts=4: */ /* stty -- change and print terminal line settings - Copyright (C) 1990-1999 Free Software Foundation, Inc. - - Licensed under GPLv2 or later, see file LICENSE in this source tree. -*/ + * Copyright (C) 1990-1999 Free Software Foundation, Inc. + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ /* Usage: stty [-ag] [-F device] [setting...] - - Options: - -a Write all current settings to stdout in human-readable form. - -g Write all current settings to stdout in stty-readable form. - -F Open and use the specified device instead of stdin - - If no args are given, write to stdout the baud rate and settings that - have been changed from their defaults. Mode reading and changes - are done on the specified device, or stdin if none was specified. - - David MacKenzie - - Special for busybox ported by Vladimir Oleynik 2001 -*/ + * + * Options: + * -a Write all current settings to stdout in human-readable form. + * -g Write all current settings to stdout in stty-readable form. + * -F Open and use the specified device instead of stdin + * + * If no args are given, write to stdout the baud rate and settings that + * have been changed from their defaults. Mode reading and changes + * are done on the specified device, or stdin if none was specified. + * + * David MacKenzie + * + * Special for busybox ported by Vladimir Oleynik 2001 + */ //config:config STTY //config: bool "stty (8.6 kb)" //config: default y diff --git a/coreutils/uuencode.c b/coreutils/uuencode.c index d6e077430..aa53b14a6 100644 --- a/coreutils/uuencode.c +++ b/coreutils/uuencode.c @@ -1,9 +1,9 @@ /* vi: set sw=4 ts=4: */ /* - * Copyright (C) 2000 by Glenn McGrath + * Copyright (C) 2000 by Glenn McGrath * - * based on the function base64_encode from http.c in wget v1.6 - * Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc. + * based on the function base64_encode from http.c in wget v1.6 + * Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc. * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ diff --git a/libbb/ask_confirmation.c b/libbb/ask_confirmation.c index d95729cc9..6fbed89f4 100644 --- a/libbb/ask_confirmation.c +++ b/libbb/ask_confirmation.c @@ -6,12 +6,11 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +#include "libbb.h" /* Read a line from stdin. If the first non-whitespace char is 'y' or 'Y', * return 1. Otherwise return 0. */ -#include "libbb.h" - int FAST_FUNC bb_ask_confirmation(void) { char first = 0; diff --git a/libbb/bb_askpass.c b/libbb/bb_askpass.c index c2580b9eb..aae35ec41 100644 --- a/libbb/bb_askpass.c +++ b/libbb/bb_askpass.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* do nothing signal handler */ diff --git a/libbb/bb_do_delay.c b/libbb/bb_do_delay.c index 05c879fb9..65541704b 100644 --- a/libbb/bb_do_delay.c +++ b/libbb/bb_do_delay.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" void FAST_FUNC bb_do_delay(int seconds) diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c index dca0a150b..32ff83a42 100644 --- a/libbb/bb_pwd.c +++ b/libbb/bb_pwd.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* TODO: maybe change API to return malloced data? diff --git a/libbb/bb_qsort.c b/libbb/bb_qsort.c index a54e7236a..505045533 100644 --- a/libbb/bb_qsort.c +++ b/libbb/bb_qsort.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" int /* not FAST_FUNC! */ bb_pstrcmp(const void *a, const void *b) diff --git a/libbb/bb_strtod.c b/libbb/bb_strtod.c index 5dde78414..5e1d0535e 100644 --- a/libbb/bb_strtod.c +++ b/libbb/bb_strtod.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include /* just for HUGE_VAL */ diff --git a/libbb/bb_strtonum.c b/libbb/bb_strtonum.c index 949f26bee..2185017b0 100644 --- a/libbb/bb_strtonum.c +++ b/libbb/bb_strtonum.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* On exit: errno = 0 only if there was non-empty, '\0' terminated value diff --git a/libbb/bbunit.c b/libbb/bbunit.c index db67b1081..5f8d980a3 100644 --- a/libbb/bbunit.c +++ b/libbb/bbunit.c @@ -6,9 +6,9 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//applet:IF_UNIT_TEST(APPLET(unit, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_UNIT_TEST) += bbunit.o -//applet:IF_UNIT_TEST(APPLET(unit, BB_DIR_USR_BIN, BB_SUID_DROP)) //usage:#define unit_trivial_usage //usage: "" diff --git a/libbb/change_identity.c b/libbb/change_identity.c index 431f72c8c..20d7c5f2d 100644 --- a/libbb/change_identity.c +++ b/libbb/change_identity.c @@ -27,7 +27,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include "libbb.h" /* Become the user and group(s) specified by PW. */ diff --git a/libbb/chomp.c b/libbb/chomp.c index cb92befb1..3757bff2e 100644 --- a/libbb/chomp.c +++ b/libbb/chomp.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" void FAST_FUNC chomp(char *s) diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c index 2f51237a3..01a9df0e2 100644 --- a/libbb/compare_string_array.c +++ b/libbb/compare_string_array.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c index 9ed295996..5b4b7f113 100644 --- a/libbb/concat_path_file.c +++ b/libbb/concat_path_file.c @@ -7,6 +7,7 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +#include "libbb.h" /* Concatenate path and filename to new allocated buffer. * Add '/' only as needed (no duplicate // are produced). @@ -14,8 +15,6 @@ * filename should not be NULL. */ -#include "libbb.h" - char* FAST_FUNC concat_path_file(const char *path, const char *filename) { char *lc; diff --git a/libbb/concat_subpath_file.c b/libbb/concat_subpath_file.c index c9167d492..bc2ee96ca 100644 --- a/libbb/concat_subpath_file.c +++ b/libbb/concat_subpath_file.c @@ -6,6 +6,7 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +#include "libbb.h" /* This function make special for recursive actions with usage @@ -13,8 +14,6 @@ and skipping "." and ".." directory entries */ -#include "libbb.h" - char* FAST_FUNC concat_subpath_file(const char *path, const char *f) { if (f && DOT_OR_DOTDOT(f)) diff --git a/libbb/copyfd.c b/libbb/copyfd.c index 921fe3f81..dd0517cd6 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #if ENABLE_FEATURE_USE_SENDFILE # include diff --git a/libbb/correct_password.c b/libbb/correct_password.c index 51928f68d..a6f7d9b3d 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c @@ -27,7 +27,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include "libbb.h" #define SHADOW_BUFSIZE 256 diff --git a/libbb/crc32.c b/libbb/crc32.c index 0711ca84e..b00b580d0 100644 --- a/libbb/crc32.c +++ b/libbb/crc32.c @@ -15,7 +15,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" uint32_t *global_crc32_table; diff --git a/libbb/default_error_retval.c b/libbb/default_error_retval.c index 4f6395fa2..fc6a5364a 100644 --- a/libbb/default_error_retval.c +++ b/libbb/default_error_retval.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* Seems silly to copyright a global variable. ;-) Oh well. * * At least one applet (cmp) returns a value different from the typical @@ -12,7 +11,6 @@ * by the applet. I suppose we could use a wrapper function to set it, but * that too seems silly. */ - #include "libbb.h" uint8_t xfunc_error_retval = EXIT_FAILURE; diff --git a/libbb/device_open.c b/libbb/device_open.c index a8fe2fcb4..e5639c712 100644 --- a/libbb/device_open.c +++ b/libbb/device_open.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* try to open up the specified device */ diff --git a/libbb/die_if_bad_username.c b/libbb/die_if_bad_username.c index cf1297bd6..46f103340 100644 --- a/libbb/die_if_bad_username.c +++ b/libbb/die_if_bad_username.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* To avoid problems, the username should consist only of diff --git a/libbb/dump.c b/libbb/dump.c index e23b71294..db91fcfe7 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -10,7 +10,6 @@ * * Original copyright notice is retained at the end of this file. */ - #include "libbb.h" #include "dump.h" diff --git a/libbb/executable.c b/libbb/executable.c index 3a1d4ff44..325dd0107 100644 --- a/libbb/executable.c +++ b/libbb/executable.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* check if path points to an executable file; diff --git a/libbb/fclose_nonstdin.c b/libbb/fclose_nonstdin.c index 1b1441347..7d5331063 100644 --- a/libbb/fclose_nonstdin.c +++ b/libbb/fclose_nonstdin.c @@ -6,14 +6,12 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +#include "libbb.h" /* A number of standard utilities can accept multiple command line args * of '-' for stdin, according to SUSv3. So we encapsulate the check * here to save a little space. */ - -#include "libbb.h" - int FAST_FUNC fclose_if_not_stdin(FILE *f) { /* Some more paranoid applets want ferror() check too */ diff --git a/libbb/fflush_stdout_and_exit.c b/libbb/fflush_stdout_and_exit.c index b4bed865f..4c689c0fb 100644 --- a/libbb/fflush_stdout_and_exit.c +++ b/libbb/fflush_stdout_and_exit.c @@ -6,13 +6,11 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +#include "libbb.h" /* Attempt to fflush(stdout), and exit with an error code if stdout is * in an error state. */ - -#include "libbb.h" - void FAST_FUNC fflush_stdout_and_exit(int retval) { xfunc_error_retval = retval; diff --git a/libbb/fgets_str.c b/libbb/fgets_str.c index 89210a3c9..1a7f2e9e0 100644 --- a/libbb/fgets_str.c +++ b/libbb/fgets_str.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" static char *xmalloc_fgets_internal(FILE *file, const char *terminating_string, int chop_off, size_t *maxsz_p) diff --git a/libbb/find_mount_point.c b/libbb/find_mount_point.c index 9676b5f52..94bbf1d4a 100644 --- a/libbb/find_mount_point.c +++ b/libbb/find_mount_point.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index db823d05b..abbf293e8 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c index 8436cd664..d560f3ec3 100644 --- a/libbb/find_root_device.c +++ b/libbb/find_root_device.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* Find block device /dev/XXX which contains specified file diff --git a/libbb/full_write.c b/libbb/full_write.c index 777fbd910..2b7983f4c 100644 --- a/libbb/full_write.c +++ b/libbb/full_write.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* diff --git a/libbb/get_console.c b/libbb/get_console.c index 96b339ca7..0b53524aa 100644 --- a/libbb/get_console.c +++ b/libbb/get_console.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* From */ diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c index a98dd35eb..cc61a9265 100644 --- a/libbb/get_line_from_file.c +++ b/libbb/get_line_from_file.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" char* FAST_FUNC bb_get_chunk_from_file(FILE *file, int *end) diff --git a/libbb/getpty.c b/libbb/getpty.c index 391d729f2..5d24ca930 100644 --- a/libbb/getpty.c +++ b/libbb/getpty.c @@ -5,7 +5,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #define DEBUG 0 diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 2a7247430..a53a382ce 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #define NEED_SHA512 (ENABLE_SHA512SUM || ENABLE_USE_BB_CRYPT_SHA) diff --git a/libbb/human_readable.c b/libbb/human_readable.c index b4e0ef181..09221a186 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c @@ -22,7 +22,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" const char* FAST_FUNC make_human_readable_str(unsigned long long val, diff --git a/libbb/in_ether.c b/libbb/in_ether.c index 161c8ea3c..c9cf6a99b 100644 --- a/libbb/in_ether.c +++ b/libbb/in_ether.c @@ -2,7 +2,6 @@ /* * Utility routines. */ - //kbuild:lib-$(CONFIG_ARP) += in_ether.o //kbuild:lib-$(CONFIG_IFCONFIG) += in_ether.o //kbuild:lib-$(CONFIG_IFENSLAVE) += in_ether.o diff --git a/libbb/inet_common.c b/libbb/inet_common.c index 04259f47b..e9fbde7dc 100644 --- a/libbb/inet_common.c +++ b/libbb/inet_common.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" #include "inet_common.h" diff --git a/libbb/inode_hash.c b/libbb/inode_hash.c index f11c2afb2..4142813e3 100644 --- a/libbb/inode_hash.c +++ b/libbb/inode_hash.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" typedef struct ino_dev_hash_bucket_struct { diff --git a/libbb/isdirectory.c b/libbb/isdirectory.c index ba6c52ce8..462aa0067 100644 --- a/libbb/isdirectory.c +++ b/libbb/isdirectory.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include #include "libbb.h" diff --git a/libbb/kernel_version.c b/libbb/kernel_version.c index 9b6c62299..7769a091b 100644 --- a/libbb/kernel_version.c +++ b/libbb/kernel_version.c @@ -6,12 +6,10 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* After libbb.h, since it needs sys/types.h on some systems */ #include /* for uname(2) */ - /* Returns current kernel version encoded as major*65536 + minor*256 + patch, * so, for example, to check if the kernel is greater than 2.2.11: * diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index 65e6cdf04..66f2e3635 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* Find out if the last character of a string matches the one given. diff --git a/libbb/llist.c b/libbb/llist.c index 032e9fac8..e964a9b72 100644 --- a/libbb/llist.c +++ b/libbb/llist.c @@ -9,7 +9,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* Add data to the start of the linked list. */ diff --git a/libbb/login.c b/libbb/login.c index 5a7acfcf0..7f593d80d 100644 --- a/libbb/login.c +++ b/libbb/login.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* After libbb.h, since it needs sys/types.h on some systems */ #include diff --git a/libbb/make_directory.c b/libbb/make_directory.c index a6b7c28df..b9916d165 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* Mar 5, 2003 Manuel Novoa III * * This is the main work function for the 'mkdir' applet. As such, it @@ -21,7 +20,6 @@ * To set specific permissions on 'path', pass the appropriate 'mode' * val. Otherwise, pass -1 to get default permissions. */ - #include "libbb.h" /* This function is used from NOFORK applets. It must not allocate anything */ diff --git a/libbb/match_fstype.c b/libbb/match_fstype.c index 6046bc6db..1e2269c5e 100644 --- a/libbb/match_fstype.c +++ b/libbb/match_fstype.c @@ -9,7 +9,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" int FAST_FUNC fstype_matches(const char *fstype, const char *comma_list) diff --git a/libbb/messages.c b/libbb/messages.c index 27fd14ecc..0a6cf3bf8 100644 --- a/libbb/messages.c +++ b/libbb/messages.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* allow default system PATH to be extended via CFLAGS */ diff --git a/libbb/mode_string.c b/libbb/mode_string.c index 934eb6dc7..280e6d291 100644 --- a/libbb/mode_string.c +++ b/libbb/mode_string.c @@ -10,8 +10,6 @@ /* Aug 13, 2003 * Fix a bug reported by junkio@cox.net involving the mode_chars index. */ - - #include #include diff --git a/libbb/mtab.c b/libbb/mtab.c index 22bff6490..131705ddb 100644 --- a/libbb/mtab.c +++ b/libbb/mtab.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include #include "libbb.h" diff --git a/libbb/nuke_str.c b/libbb/nuke_str.c index 56b808bc7..240e68004 100644 --- a/libbb/nuke_str.c +++ b/libbb/nuke_str.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - //kbuild:lib-y += nuke_str.o #include "libbb.h" diff --git a/libbb/parse_mode.c b/libbb/parse_mode.c index bddd39bca..dc65860f6 100644 --- a/libbb/parse_mode.c +++ b/libbb/parse_mode.c @@ -6,11 +6,10 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +#include "libbb.h" /* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */ -#include "libbb.h" - /* This function is used from NOFORK applets. It must not allocate anything */ #define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) diff --git a/libbb/percent_decode.c b/libbb/percent_decode.c index 9a9d80c4a..e5e42f0b5 100644 --- a/libbb/percent_decode.c +++ b/libbb/percent_decode.c @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //kbuild:lib-y += percent_decode.o #include "libbb.h" diff --git a/libbb/printable.c b/libbb/printable.c index 9a423431e..224dde406 100644 --- a/libbb/printable.c +++ b/libbb/printable.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" void FAST_FUNC fputc_printable(int ch, FILE *file) diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c index 346ecfa1e..59d0d3ea8 100644 --- a/libbb/process_escape_sequence.c +++ b/libbb/process_escape_sequence.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #define WANT_HEX_ESCAPES 1 diff --git a/libbb/procps.c b/libbb/procps.c index b52c0f51b..9d8a921df 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" diff --git a/libbb/ptr_to_globals.c b/libbb/ptr_to_globals.c index 1074538f3..8ba9cd154 100644 --- a/libbb/ptr_to_globals.c +++ b/libbb/ptr_to_globals.c @@ -4,7 +4,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include struct globals; diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c index fe06a8fe6..1edf4b6f0 100644 --- a/libbb/pw_encrypt.c +++ b/libbb/pw_encrypt.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* static const uint8_t ascii64[] ALIGN1 = diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c index 8f2b8b932..0831ecc3a 100644 --- a/libbb/recursive_action.c +++ b/libbb/recursive_action.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #undef DEBUG_RECURS_ACTION diff --git a/libbb/remove_file.c b/libbb/remove_file.c index eaca293d9..8a1324393 100644 --- a/libbb/remove_file.c +++ b/libbb/remove_file.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* Used from NOFORK applets. Must not allocate anything */ diff --git a/libbb/replace.c b/libbb/replace.c index 8711f957d..a661d96e6 100644 --- a/libbb/replace.c +++ b/libbb/replace.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - //kbuild:lib-y += replace.o #include "libbb.h" diff --git a/libbb/run_shell.c b/libbb/run_shell.c index 3bb58bb6f..a0420d982 100644 --- a/libbb/run_shell.c +++ b/libbb/run_shell.c @@ -27,7 +27,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include "libbb.h" #if ENABLE_SELINUX #include /* for setexeccon */ diff --git a/libbb/safe_gethostname.c b/libbb/safe_gethostname.c index cac99ae03..b22e30ea3 100644 --- a/libbb/safe_gethostname.c +++ b/libbb/safe_gethostname.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* * SUSv2 guarantees that "Host names are limited to 255 bytes" * POSIX.1-2001 guarantees that "Host names (not including the terminating @@ -23,7 +22,6 @@ * Host software MUST handle host names of up to 63 characters and * SHOULD handle host names of up to 255 characters. */ - #include "libbb.h" #include diff --git a/libbb/safe_poll.c b/libbb/safe_poll.c index b492a8151..cf93a9774 100644 --- a/libbb/safe_poll.c +++ b/libbb/safe_poll.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" /* Wrapper which restarts poll on EINTR or ENOMEM. diff --git a/libbb/safe_strncpy.c b/libbb/safe_strncpy.c index 5eb0db0bd..9570aacd7 100644 --- a/libbb/safe_strncpy.c +++ b/libbb/safe_strncpy.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* Like strncpy but make sure the resulting string is always 0 terminated. */ diff --git a/libbb/safe_write.c b/libbb/safe_write.c index aad50f5e0..12bb438b7 100644 --- a/libbb/safe_write.c +++ b/libbb/safe_write.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" ssize_t FAST_FUNC safe_write(int fd, const void *buf, size_t count) diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 91b6d94db..f8de44967 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c @@ -27,7 +27,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include "libbb.h" void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) diff --git a/libbb/signals.c b/libbb/signals.c index 56512473a..3f589321c 100644 --- a/libbb/signals.c +++ b/libbb/signals.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" /* All known arches use small ints for signals */ diff --git a/libbb/skip_whitespace.c b/libbb/skip_whitespace.c index b6cfbba4d..4df5d9e4d 100644 --- a/libbb/skip_whitespace.c +++ b/libbb/skip_whitespace.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" char* FAST_FUNC skip_whitespace(const char *s) diff --git a/libbb/speed_table.c b/libbb/speed_table.c index 11ced01d0..967cf8de8 100644 --- a/libbb/speed_table.c +++ b/libbb/speed_table.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" struct speed_map { diff --git a/libbb/strrstr.c b/libbb/strrstr.c index 93d970a1b..a173b034f 100644 --- a/libbb/strrstr.c +++ b/libbb/strrstr.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* diff --git a/libbb/trim.c b/libbb/trim.c index e47fec74e..e360ba138 100644 --- a/libbb/trim.c +++ b/libbb/trim.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" char* FAST_FUNC trim(char *s) diff --git a/libbb/uuencode.c b/libbb/uuencode.c index f7b248492..f32a3da7d 100644 --- a/libbb/uuencode.c +++ b/libbb/uuencode.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* Conversion table. for base 64 */ diff --git a/libbb/wfopen.c b/libbb/wfopen.c index 76dc8b82a..20fe18b23 100644 --- a/libbb/wfopen.c +++ b/libbb/wfopen.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" FILE* FAST_FUNC fopen_or_warn(const char *path, const char *mode) diff --git a/libbb/wfopen_input.c b/libbb/wfopen_input.c index d8b1c4a36..872464248 100644 --- a/libbb/wfopen_input.c +++ b/libbb/wfopen_input.c @@ -6,14 +6,13 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +#include "libbb.h" /* A number of applets need to open a file for reading, where the filename * is a command line arg. Since often that arg is '-' (meaning stdin), * we avoid testing everywhere by consolidating things in this routine. */ -#include "libbb.h" - FILE* FAST_FUNC fopen_or_warn_stdin(const char *filename) { FILE *fp = stdin; diff --git a/libbb/write.c b/libbb/write.c index 2d67a7281..dd64b0032 100644 --- a/libbb/write.c +++ b/libbb/write.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" /* Open file and write string str to it, close file. diff --git a/libbb/xatonum.c b/libbb/xatonum.c index b63b7f54d..7639a62aa 100644 --- a/libbb/xatonum.c +++ b/libbb/xatonum.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" #define type long long diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 3a0dc2653..39e56b223 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include #include /* netinet/in.h needs it */ #include diff --git a/libbb/xfunc_die.c b/libbb/xfunc_die.c index 73f7998e5..25b99066d 100644 --- a/libbb/xfunc_die.c +++ b/libbb/xfunc_die.c @@ -6,12 +6,11 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ +#include "libbb.h" /* Keeping it separate allows to NOT pull in stdio for VERY small applets. * Try building busybox with only "true" enabled... */ -#include "libbb.h" - void (*die_func)(void); void FAST_FUNC xfunc_die(void) diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 0dfb3e2d9..9cbfb2836 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - /* We need to have separate xfuncs.c and xfuncs_printf.c because * with current linkers, even with section garbage collection, * if *.o module references any of XXXprintf functions, you pull in @@ -21,7 +20,6 @@ * * TODO: move xmalloc() and xatonum() here. */ - #include "libbb.h" /* Turn on nonblocking I/O on a fd */ diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index f569b0263..2bc01ad10 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - /* We need to have separate xfuncs.c and xfuncs_printf.c because * with current linkers, even with section garbage collection, * if *.o module references any of XXXprintf functions, you pull in @@ -19,7 +18,6 @@ * which do not pull in printf, directly or indirectly. * xfunc_printf.c contains those which do. */ - #include "libbb.h" diff --git a/libbb/xgetcwd.c b/libbb/xgetcwd.c index 71720d323..7f9088bda 100644 --- a/libbb/xgetcwd.c +++ b/libbb/xgetcwd.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" /* Return the current directory, newly allocated, arbitrarily long. diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index 7d4cb60a5..9b62bcc43 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c @@ -5,7 +5,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" /* Some systems (eg Hurd) do not have MAXSYMLINKS definition, diff --git a/libbb/xrealloc_vector.c b/libbb/xrealloc_vector.c index e8d31b7e4..dda5f3f7d 100644 --- a/libbb/xrealloc_vector.c +++ b/libbb/xrealloc_vector.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" /* Resize (grow) malloced vector. diff --git a/libbb/xregcomp.c b/libbb/xregcomp.c index 344028f44..5870012d0 100644 --- a/libbb/xregcomp.c +++ b/libbb/xregcomp.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #include "libbb.h" #include "xregex.h" diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index c9bbc8bda..7e3568f80 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c @@ -28,7 +28,6 @@ * implemented, if you need a particular missing function it should be * easy to write it by using the internal common code. */ - #include "libbb.h" struct const_passdb { diff --git a/miscutils/devmem.c b/miscutils/devmem.c index 624054770..51ac3f22f 100644 --- a/miscutils/devmem.c +++ b/miscutils/devmem.c @@ -1,7 +1,7 @@ /* + * Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl) + * Copyright (C) 2008, BusyBox Team. -solar 4/26/08 * Licensed under GPLv2 or later, see file LICENSE in this source tree. - * Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl) - * Copyright (C) 2008, BusyBox Team. -solar 4/26/08 */ //config:config DEVMEM //config: bool "devmem (2.5 kb)" diff --git a/miscutils/time.c b/miscutils/time.c index 65dbcdcf3..f4f8149d3 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -1,13 +1,14 @@ /* vi: set sw=4 ts=4: */ -/* 'time' utility to display resource usage of processes. - Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc. - - Licensed under GPLv2, see file LICENSE in this source tree. -*/ +/* + * 'time' utility to display resource usage of processes. + * Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc. + * + * Licensed under GPLv2, see file LICENSE in this source tree. + */ /* Originally written by David Keppel . - Heavily modified by David MacKenzie . - Heavily modified for busybox by Erik Andersen -*/ + * Heavily modified by David MacKenzie . + * Heavily modified for busybox by Erik Andersen + */ //config:config TIME //config: bool "time (7 kb)" //config: default y diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 5521e8a5a..534c9f0c7 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -1,18 +1,18 @@ /* vi: set sw=4 ts=4: */ /* - * ifup/ifdown for busybox - * Copyright (c) 2002 Glenn McGrath - * Copyright (c) 2003-2004 Erik Andersen + * ifup/ifdown for busybox + * Copyright (c) 2002 Glenn McGrath + * Copyright (c) 2003-2004 Erik Andersen * - * Based on ifupdown v 0.6.4 by Anthony Towns - * Copyright (c) 1999 Anthony Towns + * Based on ifupdown v 0.6.4 by Anthony Towns + * Copyright (c) 1999 Anthony Towns * - * Changes to upstream version - * Remove checks for kernel version, assume kernel version 2.2.0 or better. - * Lines in the interfaces file cannot wrap. - * To adhere to the FHS, the default state file is /var/run/ifstate - * (defined via CONFIG_IFUPDOWN_IFSTATE_PATH) and can be overridden by build - * configuration. + * Changes to upstream version + * Remove checks for kernel version, assume kernel version 2.2.0 or better. + * Lines in the interfaces file cannot wrap. + * To adhere to the FHS, the default state file is /var/run/ifstate + * (defined via CONFIG_IFUPDOWN_IFSTATE_PATH) and can be overridden by build + * configuration. * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ diff --git a/networking/interface.c b/networking/interface.c index 119185881..89427f2f4 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -30,7 +30,6 @@ * 20001008 - Bernd Eckenfels, Patch from RH for setting mtu * (default AF was wrong) */ - #include "libbb.h" #include "inet_common.h" #include diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c index 2a1c20e20..1cd90d707 100644 --- a/networking/libiproute/ipneigh.c +++ b/networking/libiproute/ipneigh.c @@ -6,7 +6,6 @@ * * Ported to Busybox by: Curt Brune */ - #include "ip_common.h" /* #include "libbb.h" is inside */ #include "common_bufsiz.h" #include "rt_names.h" diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index 7e0ff1b6c..3f0f70326 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c @@ -7,7 +7,6 @@ * * Authors: Alexey Kuznetsov, */ - #include #include diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c index af9eb46f7..be88a04e8 100644 --- a/networking/libiproute/ll_map.c +++ b/networking/libiproute/ll_map.c @@ -7,7 +7,6 @@ * * Authors: Alexey Kuznetsov, */ - #include /* struct ifreq and co. */ #include "libbb.h" diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c index 4c32ae574..7d46221ac 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c @@ -7,7 +7,6 @@ * * Authors: Alexey Kuznetsov, */ - #include "libbb.h" #include "rt_names.h" #include "utils.h" diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 0013f4aa7..55f21c187 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -1,7 +1,6 @@ /* vi: set sw=4 ts=4: */ /* * udhcp client - * * Russ Dill July 2001 * * This program is free software; you can redistribute it and/or modify diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index ea84c0dd7..4d5644093 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Port to Busybox Copyright (C) 2006 Jesse Dutton +/* + * Port to Busybox Copyright (C) 2006 Jesse Dutton * * Licensed under GPLv2, see file LICENSE in this source tree. * diff --git a/networking/udhcp/domain_codec.c b/networking/udhcp/domain_codec.c index 5a923cc2c..b7a3a5353 100644 --- a/networking/udhcp/domain_codec.c +++ b/networking/udhcp/domain_codec.c @@ -1,6 +1,6 @@ /* vi: set sw=4 ts=4: */ - -/* RFC1035 domain compression routines (C) 2007 Gabriel Somlo +/* + * RFC1035 domain compression routines (C) 2007 Gabriel Somlo * * Loosely based on the isc-dhcpd implementation by dhankins@isc.org * diff --git a/sysklogd/syslogd_and_logger.c b/sysklogd/syslogd_and_logger.c index 6d06a718b..9bba195d4 100644 --- a/sysklogd/syslogd_and_logger.c +++ b/sysklogd/syslogd_and_logger.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ - #include "libbb.h" #include "common_bufsiz.h" #define SYSLOG_NAMES diff --git a/util-linux/getopt.c b/util-linux/getopt.c index a151b7e56..4431a7e74 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c @@ -1,11 +1,10 @@ /* vi: set sw=4 ts=4: */ /* * getopt.c - Enhanced implementation of BSD getopt(1) - * Copyright (c) 1997, 1998, 1999, 2000 Frodo Looijaard + * Copyright (c) 1997, 1998, 1999, 2000 Frodo Looijaard * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* * Version 1.0-b4: Tue Sep 23 1997. First public release. * Version 1.0: Wed Nov 19 1997. diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index 394ece1dd..8fc33be3c 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c @@ -1,8 +1,8 @@ /* vi: set sw=4 ts=4: */ /* - * readprofile.c - used to read /proc/profile + * readprofile.c - used to read /proc/profile * - * Copyright (C) 1994,1996 Alessandro Rubini (rubini@ipvvis.unipv.it) + * Copyright (C) 1994,1996 Alessandro Rubini (rubini@ipvvis.unipv.it) * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -- cgit v1.2.3-55-g6feb From 416899fca6c8b7a09ec301e1a961459bb3b6c139 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Oct 2017 14:41:36 +0200 Subject: do not include just before "libbb.h", it's there already Signed-off-by: Denys Vlasenko --- libbb/isdirectory.c | 1 - libbb/mode_string.c | 6 ------ 2 files changed, 7 deletions(-) diff --git a/libbb/isdirectory.c b/libbb/isdirectory.c index 462aa0067..6225a34b2 100644 --- a/libbb/isdirectory.c +++ b/libbb/isdirectory.c @@ -7,7 +7,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -#include #include "libbb.h" /* diff --git a/libbb/mode_string.c b/libbb/mode_string.c index 280e6d291..5ffd5683e 100644 --- a/libbb/mode_string.c +++ b/libbb/mode_string.c @@ -6,13 +6,7 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -/* Aug 13, 2003 - * Fix a bug reported by junkio@cox.net involving the mode_chars index. - */ #include -#include - #include "libbb.h" #if ( S_ISUID != 04000 ) || ( S_ISGID != 02000 ) || ( S_ISVTX != 01000 ) \ -- cgit v1.2.3-55-g6feb From a02a4e98306194dc12bca46d099647bcce602bb9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Oct 2017 15:19:25 +0200 Subject: whitespace and comment format fixes, no code changes Signed-off-by: Denys Vlasenko --- coreutils/basename.c | 1 - coreutils/fold.c | 3 ++- coreutils/libcoreutils/coreutils.h | 1 - coreutils/libcoreutils/cp_mv_stat.c | 2 -- coreutils/libcoreutils/getopt_mk_fifo_nod.c | 2 -- coreutils/mktemp.c | 2 -- coreutils/nohup.c | 3 ++- coreutils/printf.c | 3 ++- coreutils/realpath.c | 3 ++- coreutils/stty.c | 3 ++- coreutils/tr.c | 2 +- coreutils/uname.c | 3 ++- coreutils/unlink.c | 3 ++- coreutils/who.c | 4 +--- libbb/appletlib.c | 1 - networking/ifconfig.c | 5 ++--- networking/libiproute/ip_parse_common_args.c | 1 - networking/libiproute/ipaddress.c | 1 - networking/libiproute/iproute.c | 1 - networking/libiproute/iprule.c | 1 - networking/libiproute/iptunnel.c | 1 - networking/libiproute/ll_addr.c | 2 -- networking/libiproute/rtm_map.c | 2 -- networking/libiproute/utils.c | 1 - networking/nc.c | 3 ++- networking/route.c | 4 ++-- networking/telnet.c | 1 - networking/zcip.c | 1 - 28 files changed, 22 insertions(+), 38 deletions(-) diff --git a/coreutils/basename.c b/coreutils/basename.c index 566aeebda..812a5e63e 100644 --- a/coreutils/basename.c +++ b/coreutils/basename.c @@ -6,7 +6,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) * * Changes: diff --git a/coreutils/fold.c b/coreutils/fold.c index 578e5a4b6..1e26dde0c 100644 --- a/coreutils/fold.c +++ b/coreutils/fold.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* fold -- wrap each input line to fit in specified width. +/* + * fold -- wrap each input line to fit in specified width. * * Written by David MacKenzie, djm@gnu.ai.mit.edu. * Copyright (C) 91, 1995-2002 Free Software Foundation, Inc. diff --git a/coreutils/libcoreutils/coreutils.h b/coreutils/libcoreutils/coreutils.h index 307d0330a..ad102e423 100644 --- a/coreutils/libcoreutils/coreutils.h +++ b/coreutils/libcoreutils/coreutils.h @@ -2,7 +2,6 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - #ifndef COREUTILS_H #define COREUTILS_H 1 diff --git a/coreutils/libcoreutils/cp_mv_stat.c b/coreutils/libcoreutils/cp_mv_stat.c index 5ba07ecc3..26c0e1645 100644 --- a/coreutils/libcoreutils/cp_mv_stat.c +++ b/coreutils/libcoreutils/cp_mv_stat.c @@ -17,9 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * */ - #include "libbb.h" #include "coreutils.h" diff --git a/coreutils/libcoreutils/getopt_mk_fifo_nod.c b/coreutils/libcoreutils/getopt_mk_fifo_nod.c index 47375ff91..dafe70edf 100644 --- a/coreutils/libcoreutils/getopt_mk_fifo_nod.c +++ b/coreutils/libcoreutils/getopt_mk_fifo_nod.c @@ -17,9 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * */ - #include "libbb.h" #include "coreutils.h" diff --git a/coreutils/mktemp.c b/coreutils/mktemp.c index d4ff883fa..c041fedf7 100644 --- a/coreutils/mktemp.c +++ b/coreutils/mktemp.c @@ -2,13 +2,11 @@ /* * Mini mktemp implementation for busybox * - * * Copyright (C) 2000 by Daniel Jacobowitz * Written by Daniel Jacobowitz * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* Coreutils 6.12 man page says: * mktemp [OPTION]... [TEMPLATE] * Create a temporary file or directory, safely, and print its name. If diff --git a/coreutils/nohup.c b/coreutils/nohup.c index 8a70ec4df..ae136e085 100644 --- a/coreutils/nohup.c +++ b/coreutils/nohup.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* nohup - invoke a utility immune to hangups. +/* + * nohup - invoke a utility immune to hangups. * * Busybox version based on nohup specification at * http://www.opengroup.org/onlinepubs/007904975/utilities/nohup.html diff --git a/coreutils/printf.c b/coreutils/printf.c index 413273b26..a666ff7ac 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* printf - format and print data +/* + * printf - format and print data * * Copyright 1999 Dave Cinege * Portions copyright (C) 1990-1996 Free Software Foundation, Inc. diff --git a/coreutils/realpath.c b/coreutils/realpath.c index f9c630135..aa878fcd2 100644 --- a/coreutils/realpath.c +++ b/coreutils/realpath.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) +/* + * Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) * * Now does proper error checking on output and returns a failure exit code * if one or more paths cannot be resolved. diff --git a/coreutils/stty.c b/coreutils/stty.c index df23f4cae..424d909cf 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* stty -- change and print terminal line settings +/* + * stty -- change and print terminal line settings * Copyright (C) 1990-1999 Free Software Foundation, Inc. * * Licensed under GPLv2 or later, see file LICENSE in this source tree. diff --git a/coreutils/tr.c b/coreutils/tr.c index c5872434a..10284e1c9 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -2,7 +2,7 @@ /* * Mini tr implementation for busybox * - ** Copyright (c) 1987,1997, Prentice Hall All rights reserved. + * Copyright (c) 1987,1997, Prentice Hall All rights reserved. * * The name of Prentice Hall may not be used to endorse or promote * products derived from this software without specific prior diff --git a/coreutils/uname.c b/coreutils/uname.c index bb2d1fe8d..57039b1bf 100644 --- a/coreutils/uname.c +++ b/coreutils/uname.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* uname -- print system information +/* + * uname -- print system information * Copyright (C) 1989-1999 Free Software Foundation, Inc. * * Licensed under GPLv2 or later, see file LICENSE in this source tree. diff --git a/coreutils/unlink.c b/coreutils/unlink.c index 56309b1c7..61b108a84 100644 --- a/coreutils/unlink.c +++ b/coreutils/unlink.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* unlink for busybox +/* + * unlink for busybox * * Copyright (C) 2014 Isaac Dunham * diff --git a/coreutils/who.c b/coreutils/who.c index cfe0c921e..80226c3d6 100644 --- a/coreutils/who.c +++ b/coreutils/who.c @@ -1,5 +1,5 @@ /* vi: set sw=4 ts=4: */ -/*---------------------------------------------------------------------- +/* * Mini who is used to display user name, login time, * idle time and host name. * @@ -13,8 +13,6 @@ * Copyright (c) 2002 AYR Networks, Inc. * * Licensed under GPLv2 or later, see file LICENSE in this source tree. - * - *---------------------------------------------------------------------- */ //config:config WHO //config: bool "who (3.7 kb)" diff --git a/libbb/appletlib.c b/libbb/appletlib.c index cbca7ef17..022455da4 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -11,7 +11,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* We are trying to not use printf, this benefits the case when selected * applets are really simple. Example: * diff --git a/networking/ifconfig.c b/networking/ifconfig.c index d1e9c58dc..61d91788a 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c @@ -1,18 +1,17 @@ /* vi: set sw=4 ts=4: */ -/* ifconfig +/* + * ifconfig * * Similar to the standard Unix ifconfig, but with only the necessary * parts for AF_INET, and without any printing of if info (for now). * * Bjorn Wesen, Axis Communications AB * - * * Authors of the original ifconfig was: * Fred N. van Kempen, * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* * Heavily modified by Manuel Novoa III Mar 6, 2001 * diff --git a/networking/libiproute/ip_parse_common_args.c b/networking/libiproute/ip_parse_common_args.c index 1a298f738..d693c54fa 100644 --- a/networking/libiproute/ip_parse_common_args.c +++ b/networking/libiproute/ip_parse_common_args.c @@ -11,7 +11,6 @@ * * Rani Assaf 980929: resolve addresses */ - #include "ip_common.h" /* #include "libbb.h" is inside */ #include "utils.h" diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 36d6b65c6..921ecf0d9 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -7,7 +7,6 @@ * Changes: * Laszlo Valko 990223: address label must be zero terminated */ - #include #include #include diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 6a41b8331..e8b26cb2f 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -9,7 +9,6 @@ * Rani Assaf 980929: resolve addresses * Kunihiro Ishiguro 001102: rtnh_ifindex was not initialized */ - #include "ip_common.h" /* #include "libbb.h" is inside */ #include "common_bufsiz.h" #include "rt_names.h" diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c index 1bb5e759e..9938b4793 100644 --- a/networking/libiproute/iprule.c +++ b/networking/libiproute/iprule.c @@ -12,7 +12,6 @@ * Rani Assaf 980929: resolve addresses * initially integrated into busybox by Bernhard Reutner-Fischer */ - #include #include #include diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index eb136e435..4002feb78 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c @@ -10,7 +10,6 @@ * Rani Assaf 980930: do not allow key for ipip/sit * Phil Karn 990408: "pmtudisc" flag */ - #include #include #include diff --git a/networking/libiproute/ll_addr.c b/networking/libiproute/ll_addr.c index 33a54ea6c..afdd81ffb 100644 --- a/networking/libiproute/ll_addr.c +++ b/networking/libiproute/ll_addr.c @@ -7,14 +7,12 @@ * * Authors: Alexey Kuznetsov, */ - #include #include "libbb.h" #include "rt_names.h" #include "utils.h" - const char* FAST_FUNC ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int blen) { int i; diff --git a/networking/libiproute/rtm_map.c b/networking/libiproute/rtm_map.c index c763da049..e94c99ab6 100644 --- a/networking/libiproute/rtm_map.c +++ b/networking/libiproute/rtm_map.c @@ -7,7 +7,6 @@ * * Authors: Alexey Kuznetsov, */ - #include "libbb.h" #include "rt_names.h" #include "utils.h" @@ -44,7 +43,6 @@ const char* FAST_FUNC rtnl_rtntype_n2a(int id) } } - int FAST_FUNC rtnl_rtntype_a2n(int *id, char *arg) { static const char keywords[] ALIGN1 = diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c index fca167ac6..bf053a54b 100644 --- a/networking/libiproute/utils.c +++ b/networking/libiproute/utils.c @@ -8,7 +8,6 @@ * * Rani Assaf 980929: resolve addresses */ - #include "libbb.h" #include "utils.h" #include "inet_common.h" diff --git a/networking/nc.c b/networking/nc.c index f7fc9741f..b208f46c6 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* nc: mini-netcat - built from the ground up for LRP +/* + * nc: mini-netcat - built from the ground up for LRP * * Copyright (C) 1998, 1999 Charles P. Wright * Copyright (C) 1998 Dave Cinege diff --git a/networking/route.c b/networking/route.c index 32789eecc..6edc0f6d7 100644 --- a/networking/route.c +++ b/networking/route.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* route +/* + * route * * Similar to the standard Unix route, but with only the necessary * parts for AF_INET and AF_INET6 @@ -18,7 +19,6 @@ * * IPV6 support added by Bart Visscher */ - /* 2004/03/09 Manuel Novoa III * * Rewritten to fix several bugs, add additional error checking, and diff --git a/networking/telnet.c b/networking/telnet.c index 1f8a44466..8b0df7f5c 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -18,7 +18,6 @@ * * Modified 2004/02/11 to add ability to pass the USER variable to remote host * by Fernando Silveira - * */ //config:config TELNET //config: bool "telnet (8.7 kb)" diff --git a/networking/zcip.c b/networking/zcip.c index 55440285f..94e49adcb 100644 --- a/networking/zcip.c +++ b/networking/zcip.c @@ -8,7 +8,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - /* * ZCIP just manages the 169.254.*.* addresses. That network is not * routed at the IP level, though various proxies or bridges can -- cgit v1.2.3-55-g6feb From 2ab9403119399ffda26f6ff83ec60ac257c29898 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Oct 2017 15:33:28 +0200 Subject: whitespace and comment format fixes, no code changes Signed-off-by: Denys Vlasenko --- archival/libarchive/decompress_bunzip2.c | 3 ++- archival/libarchive/decompress_uncompress.c | 6 ++---- archival/libarchive/get_header_ar.c | 3 ++- archival/libarchive/get_header_cpio.c | 3 ++- archival/libarchive/get_header_tar.c | 3 ++- libbb/print_flags.c | 3 ++- libpwdgrp/pwd_grp.c | 3 ++- miscutils/bbconfig.c | 3 ++- miscutils/flash_eraseall.c | 3 ++- miscutils/flash_lock_unlock.c | 3 ++- miscutils/ubi_tools.c | 3 ++- util-linux/fdformat.c | 3 ++- util-linux/fdisk.c | 3 ++- util-linux/mkswap.c | 3 ++- util-linux/switch_root.c | 3 ++- 15 files changed, 30 insertions(+), 18 deletions(-) diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c index af879648d..7cd18f5ed 100644 --- a/archival/libarchive/decompress_bunzip2.c +++ b/archival/libarchive/decompress_bunzip2.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Small bzip2 deflate implementation, by Rob Landley (rob@landley.net). +/* + * Small bzip2 deflate implementation, by Rob Landley (rob@landley.net). * * Based on bzip2 decompression code by Julian R Seward (jseward@acm.org), * which also acknowledges contributions by Mike Burrows, David Wheeler, diff --git a/archival/libarchive/decompress_uncompress.c b/archival/libarchive/decompress_uncompress.c index 034ed502d..1517559c6 100644 --- a/archival/libarchive/decompress_uncompress.c +++ b/archival/libarchive/decompress_uncompress.c @@ -1,10 +1,10 @@ /* vi: set sw=4 ts=4: */ -/* uncompress for busybox -- (c) 2002 Robert Griebl +/* + * uncompress for busybox -- (c) 2002 Robert Griebl * * based on the original compress42.c source * (see disclaimer below) */ - /* (N)compress42.c - File compression ala IEEE Computer, Mar 1992. * * Authors: @@ -21,9 +21,7 @@ * marc@suse.de : a small security fix for a buffer overflow * * [... History snipped ...] - * */ - #include "libbb.h" #include "bb_archive.h" diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c index 79725e535..1809ec396 100644 --- a/archival/libarchive/get_header_ar.c +++ b/archival/libarchive/get_header_ar.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Copyright 2001 Glenn McGrath. +/* + * Copyright 2001 Glenn McGrath. * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ diff --git a/archival/libarchive/get_header_cpio.c b/archival/libarchive/get_header_cpio.c index ba07622fd..75fc6a406 100644 --- a/archival/libarchive/get_header_cpio.c +++ b/archival/libarchive/get_header_cpio.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Copyright 2002 Laurence Anderson +/* + * Copyright 2002 Laurence Anderson * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c index 443a478a1..aeb54190f 100644 --- a/archival/libarchive/get_header_tar.c +++ b/archival/libarchive/get_header_tar.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Licensed under GPLv2 or later, see file LICENSE in this source tree. +/* + * Licensed under GPLv2 or later, see file LICENSE in this source tree. * * FIXME: * In privileged mode if uname and gname map to a uid and gid then use the diff --git a/libbb/print_flags.c b/libbb/print_flags.c index eaec731e5..0ebe842be 100644 --- a/libbb/print_flags.c +++ b/libbb/print_flags.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Print string that matches bit masked flags +/* + * Print string that matches bit masked flags * * Copyright (C) 2008 Natanael Copa * diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index 7e3568f80..b44ada432 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Copyright (C) 2014 Tito Ragusa +/* + * Copyright (C) 2014 Tito Ragusa * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ diff --git a/miscutils/bbconfig.c b/miscutils/bbconfig.c index 045aca211..9ab57876e 100644 --- a/miscutils/bbconfig.c +++ b/miscutils/bbconfig.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* This file was released into the public domain by Paul Fox. +/* + * This file was released into the public domain by Paul Fox. */ //config:config BBCONFIG //config: bool "bbconfig (9.7 kb)" diff --git a/miscutils/flash_eraseall.c b/miscutils/flash_eraseall.c index a6ce41f27..fab21291c 100644 --- a/miscutils/flash_eraseall.c +++ b/miscutils/flash_eraseall.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* eraseall.c -- erase the whole of a MTD device +/* + * eraseall.c -- erase the whole of a MTD device * * Ported to busybox from mtd-utils. * diff --git a/miscutils/flash_lock_unlock.c b/miscutils/flash_lock_unlock.c index 6f2c049f4..12f72efaf 100644 --- a/miscutils/flash_lock_unlock.c +++ b/miscutils/flash_lock_unlock.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Ported to busybox from mtd-utils. +/* + * Ported to busybox from mtd-utils. * * Licensed under GPLv2, see file LICENSE in this source tree. */ diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index 1ef8fd90e..a947abab5 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c @@ -1,4 +1,5 @@ -/* Ported to busybox from mtd-utils. +/* + * Ported to busybox from mtd-utils. * * Licensed under GPLv2, see file LICENSE in this source tree. */ diff --git a/util-linux/fdformat.c b/util-linux/fdformat.c index 855269c30..c72da8b89 100644 --- a/util-linux/fdformat.c +++ b/util-linux/fdformat.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* fdformat.c - Low-level formats a floppy disk - Werner Almesberger +/* + * fdformat.c - Low-level formats a floppy disk - Werner Almesberger * 5 July 2003 -- modified for Busybox by Erik Andersen * * Licensed under GPLv2, see file LICENSE in this source tree. diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index c4318b6c4..7275535e6 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* fdisk.c -- Partition table manipulator for Linux. +/* + * fdisk.c -- Partition table manipulator for Linux. * * Copyright (C) 1992 A. V. Le Blanc (LeBlanc@mcc.ac.uk) * Copyright (C) 2001,2002 Vladimir Oleynik (initial bb port) diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index 71449882d..2eb16bd84 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* mkswap.c - format swap device (Linux v1 only) +/* + * mkswap.c - format swap device (Linux v1 only) * * Copyright 2006 Rob Landley * diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c index 080b05e45..2d1802b79 100644 --- a/util-linux/switch_root.c +++ b/util-linux/switch_root.c @@ -1,5 +1,6 @@ /* vi: set sw=4 ts=4: */ -/* Copyright 2005 Rob Landley +/* + * Copyright 2005 Rob Landley * * Switch from rootfs to another filesystem as the root of the mount tree. * -- cgit v1.2.3-55-g6feb From 1121b4e568b340cfe2a9b7fc41fb48f4d684ad47 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Oct 2017 17:18:23 +0200 Subject: sendmail allow "=" symbol in recipient, closes 10241 Signed-off-by: Denys Vlasenko --- mailutils/sendmail.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c index defbd9552..4ca91fad8 100644 --- a/mailutils/sendmail.c +++ b/mailutils/sendmail.c @@ -150,7 +150,13 @@ static char *sane_address(char *str) trim(str); s = str; while (*s) { - if (!isalnum(*s) && !strchr("+_-.@", *s)) { + /* Standard allows these chars in username without quoting: + * /!#$%&'*+-=?^_`{|}~ + * and allows dot (.) with some restrictions. + * I chose to only allow a saner subset. + * I propose to expand it only on user's request. + */ + if (!isalnum(*s) && !strchr("=+_-.@", *s)) { bb_error_msg("bad address '%s'", str); /* returning "": */ str[0] = '\0'; -- cgit v1.2.3-55-g6feb From 0fd5dbba8f34e006aa0e999002d31e79daf2fdf3 Mon Sep 17 00:00:00 2001 From: Avi Halachmi Date: Thu, 12 Oct 2017 16:38:35 +0200 Subject: lineedit: improve multiline PS1 - redraw using last PS1 line. Closes 10381 This patch only affects prompts with newlines. We redraw the prompt [+ input] occasionally, e.g. during tab completion, history browsing or search, etc, and we expect it to align with prior redraws, such that the visible effect is that only the input changes. With multi-line PS1, redraw always printed the prompt some lines below the old one, which resulted in terminal scroll during every redraw. Now we only redraw the last PS1 line, so vertical alignment is easier to manage (we already calculated it using only the last line, but re-drew all lines - that was the culprit), which fixes those extra scrolls. Notes: - We now use the full prompt for the initial draw, after clear-screen (^L), and after tab-completion choices are displayed. Everything else now redraws using the last/sole prompt line. - During terminal resize we now only redraw the last[/sole] prompt line, which is arguably better because it's hard to do right (and we never did). - Good side effect for reverse-i-search: its prompt now replaces only the last line of the original prompt - like other shells do. function old new delta put_prompt_custom - 66 +66 draw_custom - 66 +66 parse_and_put_prompt 766 806 +40 read_line_input 3867 3884 +17 input_tab 1069 1076 +7 cmdedit_setwidth 61 63 +2 redraw 59 47 -12 put_prompt 46 - -46 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 4/1 up/down: 198/-58) Total: 140 bytes Signed-off-by: Avi Halachmi Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 88 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 3a092ffe2..c0e35bb21 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -37,11 +37,6 @@ * * Unicode in PS1 is not fully supported: prompt length calulation is wrong, * resulting in line wrap problems with long (multi-line) input. - * - * Multi-line PS1 (e.g. PS1="\n[\w]\n$ ") has problems with history - * browsing: up/down arrows result in scrolling. - * It stems from simplistic "cmdedit_y = cmdedit_prmt_len / cmdedit_termw" - * calculation of how many lines the prompt takes. */ #include "busybox.h" #include "NUM_APPLETS.h" @@ -133,7 +128,7 @@ struct lineedit_statics { unsigned cmdedit_x; /* real x (col) terminal position */ unsigned cmdedit_y; /* pseudoreal y (row) terminal position */ - unsigned cmdedit_prmt_len; /* length of prompt (without colors etc) */ + unsigned cmdedit_prmt_len; /* on-screen length of last/sole prompt line */ unsigned cursor; int command_len; /* must be signed */ @@ -143,6 +138,7 @@ struct lineedit_statics { CHAR_T *command_ps; const char *cmdedit_prompt; + const char *prompt_last_line; /* last/sole prompt line */ #if ENABLE_USERNAME_OR_HOMEDIR char *user_buf; @@ -185,6 +181,7 @@ extern struct lineedit_statics *const lineedit_ptr_to_statics; #define command_len (S.command_len ) #define command_ps (S.command_ps ) #define cmdedit_prompt (S.cmdedit_prompt ) +#define prompt_last_line (S.prompt_last_line) #define user_buf (S.user_buf ) #define home_pwd_buf (S.home_pwd_buf ) #define matches (S.matches ) @@ -437,14 +434,20 @@ static void beep(void) bb_putchar('\007'); } -static void put_prompt(void) +/* Full or last/sole prompt line, reset edit cursor, calculate terminal cursor. + * cmdedit_y is always calculated for the last/sole prompt line. + */ +static void put_prompt_custom(bool is_full) { - fputs(cmdedit_prompt, stdout); + fputs((is_full ? cmdedit_prompt : prompt_last_line), stdout); cursor = 0; cmdedit_y = cmdedit_prmt_len / cmdedit_termw; /* new quasireal y */ cmdedit_x = cmdedit_prmt_len % cmdedit_termw; } +#define put_prompt_last_line() put_prompt_custom(0) +#define put_prompt() put_prompt_custom(1) + /* Move back one character */ /* (optimized for slow terminals) */ static void input_backward(unsigned num) @@ -509,7 +512,7 @@ static void input_backward(unsigned num) printf("\r" ESC"[%uA", cmdedit_y); cmdedit_y = 0; sv_cursor = cursor; - put_prompt(); /* sets cursor to 0 */ + put_prompt_last_line(); /* sets cursor to 0 */ while (cursor < sv_cursor) put_cur_glyph_and_inc_cursor(); } else { @@ -530,18 +533,27 @@ static void input_backward(unsigned num) } } -/* draw prompt, editor line, and clear tail */ -static void redraw(int y, int back_cursor) +/* See redraw and draw_full below */ +static void draw_custom(int y, int back_cursor, bool is_full) { if (y > 0) /* up y lines */ printf(ESC"[%uA", y); bb_putchar('\r'); - put_prompt(); + put_prompt_custom(is_full); put_till_end_and_adv_cursor(); printf(SEQ_CLEAR_TILL_END_OF_SCREEN); input_backward(back_cursor); } +/* Move y lines up, draw last/sole prompt line, editor line[s], and clear tail. + * goal: redraw the prompt+input+cursor in-place, overwriting the previous */ +#define redraw(y, back_cursor) draw_custom((y), (back_cursor), 0) + +/* Like above, but without moving up, and while using all the prompt lines. + * goal: draw a full prompt+input+cursor unrelated to a previous position. + * note: cmdedit_y always ends up relating to the last/sole prompt line */ +#define draw_full(back_cursor) draw_custom(0, (back_cursor), 1) + /* Delete the char in front of the cursor, optionally saving it * for later putback */ #if !ENABLE_FEATURE_EDITING_VI @@ -1106,7 +1118,7 @@ static NOINLINE void input_tab(smallint *lastWasTab) int sav_cursor = cursor; goto_new_line(); showfiles(); - redraw(0, command_len - sav_cursor); + draw_full(command_len - sav_cursor); } return; } @@ -1782,14 +1794,37 @@ static void ask_terminal(void) #define ask_terminal() ((void)0) #endif +/* Note about multi-line PS1 (e.g. "\n\w \u@\h\n> ") and prompt redrawing: + * + * If the prompt has any newlines, after we print it once we use only its last + * line to redraw in-place, which makes it simpler to calculate how many lines + * we should move the cursor up to align the redraw (cmdedit_y). The earlier + * prompt lines just stay on screen and we redraw below them. + * + * Use cases for all prompt lines beyond the initial draw: + * - After clear-screen (^L) or after displaying tab-completion choices, we + * print the full prompt, as it isn't redrawn in-place. + * - During terminal resize we could try to redraw all lines, but we don't, + * because it requires delicate alignment, it's good enough with only the + * last line, and doing it wrong is arguably worse than not doing it at all. + * + * Terminology wise, if it doesn't mention "full", then it means the last/sole + * prompt line. We use the prompt (last/sole line) while redrawing in-place, + * and the full where we need a fresh one unrelated to an earlier position. + * + * If PS1 is not multiline, the last/sole line and the full are the same string. + */ + /* Called just once at read_line_input() init time */ #if !ENABLE_FEATURE_EDITING_FANCY_PROMPT static void parse_and_put_prompt(const char *prmt_ptr) { const char *p; - cmdedit_prompt = prmt_ptr; + cmdedit_prompt = prompt_last_line = prmt_ptr; p = strrchr(prmt_ptr, '\n'); - cmdedit_prmt_len = unicode_strwidth(p ? p+1 : prmt_ptr); + if (p) + prompt_last_line = p + 1; + cmdedit_prmt_len = unicode_strwidth(prompt_last_line); put_prompt(); } #else @@ -1973,7 +2008,11 @@ static void parse_and_put_prompt(const char *prmt_ptr) if (cwd_buf != (char *)bb_msg_unknown) free(cwd_buf); # endif - cmdedit_prompt = prmt_mem_ptr; + /* see comment (above this function) about multiline prompt redrawing */ + cmdedit_prompt = prompt_last_line = prmt_mem_ptr; + prmt_ptr = strrchr(cmdedit_prompt, '\n'); + if (prmt_ptr) + prompt_last_line = prmt_ptr + 1; put_prompt(); } #endif @@ -2145,7 +2184,7 @@ static int32_t reverse_i_search(int timeout) match_buf[0] = '\0'; /* Save and replace the prompt */ - saved_prompt = cmdedit_prompt; + saved_prompt = prompt_last_line; saved_prmt_len = cmdedit_prmt_len; goto set_prompt; @@ -2218,10 +2257,10 @@ static int32_t reverse_i_search(int timeout) cursor = match - matched_history_line; //FIXME: cursor position for Unicode case - free((char*)cmdedit_prompt); + free((char*)prompt_last_line); set_prompt: - cmdedit_prompt = xasprintf("(reverse-i-search)'%s': ", match_buf); - cmdedit_prmt_len = unicode_strwidth(cmdedit_prompt); + prompt_last_line = xasprintf("(reverse-i-search)'%s': ", match_buf); + cmdedit_prmt_len = unicode_strwidth(prompt_last_line); goto do_redraw; } } @@ -2241,8 +2280,8 @@ static int32_t reverse_i_search(int timeout) if (matched_history_line) command_len = load_string(matched_history_line); - free((char*)cmdedit_prompt); - cmdedit_prompt = saved_prompt; + free((char*)prompt_last_line); + prompt_last_line = saved_prompt; cmdedit_prmt_len = saved_prmt_len; redraw(cmdedit_y, command_len - cursor); @@ -2451,8 +2490,9 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman case CTRL('L'): vi_case(CTRL('L')|VI_CMDMODE_BIT:) /* Control-l -- clear screen */ - printf(ESC"[H"); /* cursor to top,left */ - redraw(0, command_len - cursor); + /* cursor to top,left; clear to the end of screen */ + printf(ESC"[H" ESC"[J"); + draw_full(command_len - cursor); break; #if MAX_HISTORY > 0 case CTRL('N'): -- cgit v1.2.3-55-g6feb From a2e32b324eb7440f0cd4992f54f7a5822c145e91 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 12 Oct 2017 19:20:13 +0200 Subject: ash: survive failures in $PS1 expansion. Closes 10371 function old new delta expandstr 120 209 +89 Signed-off-by: Denys Vlasenko --- shell/ash.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index 39705a350..ef81ea70f 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12656,7 +12656,24 @@ expandstr(const char *ps, int syntax_type) saveprompt = doprompt; doprompt = 0; - readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0); + + /* readtoken1() might die horribly. + * Try a prompt with syntacticallyt wrong command: + * PS1='$(date "+%H:%M:%S) > ' + */ + { + volatile int saveint; + struct jmploc *volatile savehandler = exception_handler; + struct jmploc jmploc; + SAVE_INT(saveint); + if (setjmp(jmploc.loc) == 0) { + exception_handler = &jmploc; + readtoken1(pgetc(), syntax_type, FAKEEOFMARK, 0); + } + exception_handler = savehandler; + RESTORE_INT(saveint); + } + doprompt = saveprompt; popfile(); -- cgit v1.2.3-55-g6feb From 3c183a8758e83f6809f77355e019ab98e5fd596b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 12 Oct 2017 19:35:42 +0200 Subject: typo fix Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/ash.c b/shell/ash.c index ef81ea70f..f60daefc1 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12658,7 +12658,7 @@ expandstr(const char *ps, int syntax_type) doprompt = 0; /* readtoken1() might die horribly. - * Try a prompt with syntacticallyt wrong command: + * Try a prompt with syntactically wrong command: * PS1='$(date "+%H:%M:%S) > ' */ { -- cgit v1.2.3-55-g6feb From 14c85eb7db918daa1914a0e60081b1d3ca12ae04 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 12 Oct 2017 19:40:47 +0200 Subject: whitespace fixes Signed-off-by: Denys Vlasenko --- shell/ash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index f60daefc1..88e607f08 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12742,7 +12742,7 @@ evalstring(char *s, int flags) exception_handler = savehandler; if (ex) - longjmp(exception_handler->loc, ex); + longjmp(exception_handler->loc, ex); return status; } @@ -13556,8 +13556,8 @@ umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) } } else { char *modestr = *argptr; - /* numeric umasks are taken as-is */ - /* symbolic umasks are inverted: "umask a=rx" calls umask(222) */ + /* numeric umasks are taken as-is */ + /* symbolic umasks are inverted: "umask a=rx" calls umask(222) */ if (!isdigit(modestr[0])) mask ^= 0777; mask = bb_parse_mode(modestr, mask); -- cgit v1.2.3-55-g6feb From 045327a418d1cf0a99405ca0b70ed61b5c1a1869 Mon Sep 17 00:00:00 2001 From: Markus Gothe Date: Sat, 21 Oct 2017 21:34:22 +0200 Subject: lsscsi: fix xchdir("..") from symlink in /sys/bus/scsi/devices Signed-off-by: Markus Gothe Signed-off-by: Denys Vlasenko --- miscutils/lsscsi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/miscutils/lsscsi.c b/miscutils/lsscsi.c index d7cd51056..0aaa01ded 100644 --- a/miscutils/lsscsi.c +++ b/miscutils/lsscsi.c @@ -25,6 +25,8 @@ #include "libbb.h" +static const char scsi_dir[] ALIGN1 = "/sys/bus/scsi/devices"; + static char *get_line(const char *filename, char *buf, unsigned *bufsize_p) { unsigned bufsize = *bufsize_p; @@ -53,7 +55,7 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) struct dirent *de; DIR *dir; - xchdir("/sys/bus/scsi/devices"); + xchdir(scsi_dir); dir = xopendir("."); while ((de = readdir(dir)) != NULL) { @@ -112,7 +114,10 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) ); /* TODO: also output device column, e.g. "/dev/sdX" */ - xchdir(".."); + /* chdir("..") may not work as expected, + * since we might have followed a symlink. + */ + xchdir(scsi_dir); } if (ENABLE_FEATURE_CLEAN_UP) -- cgit v1.2.3-55-g6feb From 25f3b737dc04bb84fb593ace33a5c360163bd4e4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 22 Oct 2017 15:55:48 +0200 Subject: hush: fix comment parsing in `cmd`, closes 10421 function old new delta parse_stream 2692 2690 -2 Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-parsing/comment2.right | 4 ++++ shell/ash_test/ash-parsing/comment2.tests | 13 +++++++++++++ shell/hush.c | 17 +++++++++++++---- shell/hush_test/hush-parsing/comment2.right | 4 ++++ shell/hush_test/hush-parsing/comment2.tests | 13 +++++++++++++ 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 shell/ash_test/ash-parsing/comment2.right create mode 100755 shell/ash_test/ash-parsing/comment2.tests create mode 100644 shell/hush_test/hush-parsing/comment2.right create mode 100755 shell/hush_test/hush-parsing/comment2.tests diff --git a/shell/ash_test/ash-parsing/comment2.right b/shell/ash_test/ash-parsing/comment2.right new file mode 100644 index 000000000..ee6e49a5a --- /dev/null +++ b/shell/ash_test/ash-parsing/comment2.right @@ -0,0 +1,4 @@ +Ok1 +Ok2 +Ok5 +Ok6 diff --git a/shell/ash_test/ash-parsing/comment2.tests b/shell/ash_test/ash-parsing/comment2.tests new file mode 100755 index 000000000..b7adad96a --- /dev/null +++ b/shell/ash_test/ash-parsing/comment2.tests @@ -0,0 +1,13 @@ +echo "`echo Ok1 #comment is ignored`" +echo `echo Ok2 #comment is ignored` +# +# Surprisingly, bash does not handle comments in $() +# the same way as in ``. "#" causes the rest of the line, _including_ )", +# to be ignored. These lines would cause an error: +#echo "$(echo Ok3 #comment is ignored)" +#echo $(echo Ok4 #comment is ignored) +# +echo "$(echo Ok5 #comment is ignored +)" +echo $(echo Ok6 #comment is ignored +) diff --git a/shell/hush.c b/shell/hush.c index d27550ba0..708555ac4 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -5140,14 +5140,23 @@ static struct pipe *parse_stream(char **pstring, case '#': if (dest.length == 0 && !dest.has_quoted_part) { /* skip "#comment" */ + /* note: we do not add it to &ctx.as_string */ +/* TODO: in bash: + * comment inside $() goes to the next \n, even inside quoted string (!): + * cmd "$(cmd2 #comment)" - syntax error + * cmd "`cmd2 #comment`" - ok + * We accept both (comment ends where command subst ends, in both cases). + */ while (1) { ch = i_peek(input); - if (ch == EOF || ch == '\n') + if (ch == '\n') { + nommu_addchr(&ctx.as_string, '\n'); + break; + } + ch = i_getch(input); + if (ch == EOF) break; - i_getch(input); - /* note: we do not add it to &ctx.as_string */ } - nommu_addchr(&ctx.as_string, '\n'); continue; /* back to top of while (1) */ } break; diff --git a/shell/hush_test/hush-parsing/comment2.right b/shell/hush_test/hush-parsing/comment2.right new file mode 100644 index 000000000..ee6e49a5a --- /dev/null +++ b/shell/hush_test/hush-parsing/comment2.right @@ -0,0 +1,4 @@ +Ok1 +Ok2 +Ok5 +Ok6 diff --git a/shell/hush_test/hush-parsing/comment2.tests b/shell/hush_test/hush-parsing/comment2.tests new file mode 100755 index 000000000..b7adad96a --- /dev/null +++ b/shell/hush_test/hush-parsing/comment2.tests @@ -0,0 +1,13 @@ +echo "`echo Ok1 #comment is ignored`" +echo `echo Ok2 #comment is ignored` +# +# Surprisingly, bash does not handle comments in $() +# the same way as in ``. "#" causes the rest of the line, _including_ )", +# to be ignored. These lines would cause an error: +#echo "$(echo Ok3 #comment is ignored)" +#echo $(echo Ok4 #comment is ignored) +# +echo "$(echo Ok5 #comment is ignored +)" +echo $(echo Ok6 #comment is ignored +) -- cgit v1.2.3-55-g6feb From 0402cb32df015d9372578e3db27db47b33d5c7b0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 22 Oct 2017 18:23:23 +0200 Subject: bunzip2: fix runCnt overflow from bug 10431 This particular corrupted file can be dealth with by using "unsigned". If there will be cases where it genuinely overflows, there is a disabled code to deal with that too. function old new delta get_next_block 1678 1667 -11 Signed-off-by: Denys Vlasenko --- archival/libarchive/decompress_bunzip2.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c index 7cd18f5ed..bec89edd3 100644 --- a/archival/libarchive/decompress_bunzip2.c +++ b/archival/libarchive/decompress_bunzip2.c @@ -156,15 +156,15 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted) static int get_next_block(bunzip_data *bd) { struct group_data *hufGroup; - int dbufCount, dbufSize, groupCount, *base, *limit, selector, - i, j, runPos, symCount, symTotal, nSelectors, byteCount[256]; - int runCnt = runCnt; /* for compiler */ + int groupCount, *base, *limit, selector, + i, j, symCount, symTotal, nSelectors, byteCount[256]; uint8_t uc, symToByte[256], mtfSymbol[256], *selectors; uint32_t *dbuf; unsigned origPtr, t; + unsigned dbufCount, runPos; + unsigned runCnt = runCnt; /* for compiler */ dbuf = bd->dbuf; - dbufSize = bd->dbufSize; selectors = bd->selectors; /* In bbox, we are ok with aborting through setjmp which is set up in start_bunzip */ @@ -187,7 +187,7 @@ static int get_next_block(bunzip_data *bd) it didn't actually work. */ if (get_bits(bd, 1)) return RETVAL_OBSOLETE_INPUT; origPtr = get_bits(bd, 24); - if ((int)origPtr > dbufSize) return RETVAL_DATA_ERROR; + if (origPtr > bd->dbufSize) return RETVAL_DATA_ERROR; /* mapping table: if some byte values are never used (encoding things like ascii text), the compression code removes the gaps to have fewer @@ -435,7 +435,14 @@ static int get_next_block(bunzip_data *bd) symbols, but a run of length 0 doesn't mean anything in this context). Thus space is saved. */ runCnt += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */ - if (runPos < dbufSize) runPos <<= 1; +//The 32-bit overflow of runCnt wasn't yet seen, but probably can happen. +//This would be the fix (catches too large count way before it can overflow): +// if (runCnt > bd->dbufSize) { +// dbg("runCnt:%u > dbufSize:%u RETVAL_DATA_ERROR", +// runCnt, bd->dbufSize); +// return RETVAL_DATA_ERROR; +// } + if (runPos < bd->dbufSize) runPos <<= 1; goto end_of_huffman_loop; } @@ -445,14 +452,15 @@ static int get_next_block(bunzip_data *bd) literal used is the one at the head of the mtfSymbol array.) */ if (runPos != 0) { uint8_t tmp_byte; - if (dbufCount + runCnt > dbufSize) { - dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR", - dbufCount, runCnt, dbufCount + runCnt, dbufSize); + if (dbufCount + runCnt > bd->dbufSize) { + dbg("dbufCount:%u+runCnt:%u %u > dbufSize:%u RETVAL_DATA_ERROR", + dbufCount, runCnt, dbufCount + runCnt, bd->dbufSize); return RETVAL_DATA_ERROR; } tmp_byte = symToByte[mtfSymbol[0]]; byteCount[tmp_byte] += runCnt; - while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte; + while ((int)--runCnt >= 0) + dbuf[dbufCount++] = (uint32_t)tmp_byte; runPos = 0; } @@ -466,7 +474,7 @@ static int get_next_block(bunzip_data *bd) first symbol in the mtf array, position 0, would have been handled as part of a run above. Therefore 1 unused mtf position minus 2 non-literal nextSym values equals -1.) */ - if (dbufCount >= dbufSize) return RETVAL_DATA_ERROR; + if (dbufCount >= bd->dbufSize) return RETVAL_DATA_ERROR; i = nextSym - 1; uc = mtfSymbol[i]; -- cgit v1.2.3-55-g6feb From 9ac42c500586fa5f10a1f6d22c3f797df11b1f6b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 27 Oct 2017 15:37:03 +0200 Subject: unlzma: fix SEGV, closes 10436 Signed-off-by: Denys Vlasenko --- archival/libarchive/decompress_unlzma.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/archival/libarchive/decompress_unlzma.c b/archival/libarchive/decompress_unlzma.c index a9040877e..be4342414 100644 --- a/archival/libarchive/decompress_unlzma.c +++ b/archival/libarchive/decompress_unlzma.c @@ -450,8 +450,12 @@ unpack_lzma_stream(transformer_state_t *xstate) IF_NOT_FEATURE_LZMA_FAST(string:) do { uint32_t pos = buffer_pos - rep0; - if ((int32_t)pos < 0) + if ((int32_t)pos < 0) { pos += header.dict_size; + /* bug 10436 has an example file where this triggers: */ + if ((int32_t)pos < 0) + goto bad; + } previous_byte = buffer[pos]; IF_NOT_FEATURE_LZMA_FAST(one_byte2:) buffer[buffer_pos++] = previous_byte; -- cgit v1.2.3-55-g6feb From d3a7e88008880489feb0f0adf1bcf8af1af2e9a7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 27 Oct 2017 19:05:00 +0200 Subject: time: fix build for toolchains without O_CLOEXEC Based on patch by Eugene Rudoy Signed-off-by: Denys Vlasenko --- miscutils/time.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/miscutils/time.c b/miscutils/time.c index f4f8149d3..61f078755 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -442,11 +442,16 @@ int time_main(int argc UNUSED_PARAM, char **argv) output_format = posix_format; output_fd = STDERR_FILENO; if (opt & OPT_o) { +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif output_fd = xopen(output_filename, (opt & OPT_a) /* append? */ ? (O_CREAT | O_WRONLY | O_CLOEXEC | O_APPEND) : (O_CREAT | O_WRONLY | O_CLOEXEC | O_TRUNC) ); + if (!O_CLOEXEC) + close_on_exec_on(output_fd); } run_command(argv, &res); -- cgit v1.2.3-55-g6feb From ecce3a1999f3c5ded4baebbc0b17c48d80fe2781 Mon Sep 17 00:00:00 2001 From: Eugene Rudoy Date: Thu, 19 Oct 2017 00:05:11 +0200 Subject: iproute/iprule: support toolchains without RTA_TABLE routing attribute iproute.c: In function 'print_route': iproute.c:85:9: error: 'RTA_TABLE' undeclared (first use in this function) iproute.c:85:9: note: each undeclared identifier is reported only once for each function it appears in iproute.c: In function 'iproute_modify': iproute.c:467:36: error: 'RTA_TABLE' undeclared (first use in this function) Fix it by partially #ifdef'ing the code added in b42107f21538e39d9a344376372f8261aed589b2 Signed-off-by: Eugene Rudoy Signed-off-by: Denys Vlasenko --- networking/libiproute/iproute.c | 16 ++++++++++++---- networking/libiproute/iprule.c | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index e8b26cb2f..95dafe183 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -14,6 +14,11 @@ #include "rt_names.h" #include "utils.h" +#include +/* RTA_TABLE is not a define, can't test with ifdef. */ +/* As a proxy, test which kernels toolchain expects: */ +#define HAVE_RTA_TABLE (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)) + #ifndef RTAX_RTTVAR #define RTAX_RTTVAR RTAX_HOPS #endif @@ -81,9 +86,11 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, memset(tb, 0, sizeof(tb)); parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); +#if HAVE_RTA_TABLE if (tb[RTA_TABLE]) tid = *(uint32_t *)RTA_DATA(tb[RTA_TABLE]); else +#endif tid = r->rtm_table; if (r->rtm_family == AF_INET6) @@ -459,12 +466,13 @@ IF_FEATURE_IP_RULE(ARG_table,) NEXT_ARG(); if (rtnl_rttable_a2n(&tid, *argv)) invarg_1_to_2(*argv, keyword_table); - if (tid < 256) - req.r.rtm_table = tid; - else { +#if HAVE_RTA_TABLE + if (tid > 255) { req.r.rtm_table = RT_TABLE_UNSPEC; addattr32(&req.n, sizeof(req), RTA_TABLE, tid); - } + } else +#endif + req.r.rtm_table = tid; #endif } else if (arg == ARG_dev || arg == ARG_oif) { NEXT_ARG(); diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c index 9938b4793..53b11e16c 100644 --- a/networking/libiproute/iprule.c +++ b/networking/libiproute/iprule.c @@ -24,6 +24,11 @@ #include "rt_names.h" #include "utils.h" +#include +/* RTA_TABLE is not a define, can't test with ifdef. */ +/* As a proxy, test which kernels toolchain expects: */ +#define HAVE_RTA_TABLE (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)) + /* If you add stuff here, update iprule_full_usage */ static const char keywords[] ALIGN1 = "from\0""to\0""preference\0""order\0""priority\0" @@ -120,9 +125,12 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM, printf("iif %s ", (char*)RTA_DATA(tb[RTA_IIF])); } +#if HAVE_RTA_TABLE if (tb[RTA_TABLE]) printf("lookup %s ", rtnl_rttable_n2a(*(uint32_t*)RTA_DATA(tb[RTA_TABLE]))); - else if (r->rtm_table) + else +#endif + if (r->rtm_table) printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table)); if (tb[FRA_SUPPRESS_PREFIXLEN]) { @@ -266,12 +274,15 @@ static int iprule_modify(int cmd, char **argv) NEXT_ARG(); if (rtnl_rttable_a2n(&tid, *argv)) invarg_1_to_2(*argv, "table ID"); - if (tid < 256) - req.r.rtm_table = tid; - else { + +#if HAVE_RTA_TABLE + if (tid > 255) { req.r.rtm_table = RT_TABLE_UNSPEC; addattr32(&req.n, sizeof(req), RTA_TABLE, tid); - } + } else +#endif + req.r.rtm_table = tid; + table_ok = 1; } else if (key == ARG_suppress_prefixlength) { int prefix_length; -- cgit v1.2.3-55-g6feb From a1e9bc6876f6539805095e9395c604d3675c526d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 28 Oct 2017 17:54:24 +0200 Subject: ntpd: perform DNS resolution out of send/receive loop - closes 10466 Bad case: send request to server1good.com; then try to resolve server2bad.com - this fails, and failure takes ~5 secs; then receive server1's response 5 seconds later. We'll never sync up in this case... function old new delta ntpd_main 1079 1106 +27 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 4f881eaf9..8f792d16d 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -866,10 +866,8 @@ do_sendto(int fd, static void send_query_to_peer(peer_t *p) { - if (!p->p_lsa) { - if (!resolve_peer_hostname(p)) - return; - } + if (!p->p_lsa) + return; /* Why do we need to bind()? * See what happens when we don't bind: @@ -2360,6 +2358,14 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) int nfds, timeout; double nextaction; + /* Resolve peer names to IPs, if not resolved yet */ + for (item = G.ntp_peers; item != NULL; item = item->link) { + peer_t *p = (peer_t *) item->data; + + if (p->next_action_time <= G.cur_time && !p->p_lsa) + resolve_peer_hostname(p); + } + /* Nothing between here and poll() blocks for any significant time */ nextaction = G.cur_time + 3600; -- cgit v1.2.3-55-g6feb From 4d0971b7fbb9069c104e3746bb22d2155ec275ee Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 7 Oct 2017 18:53:21 +0100 Subject: networking: Fall back on IPPROTO_RAW when SOL_RAW is not defined Signed-off-by: James Clarke Signed-off-by: Denys Vlasenko --- networking/ping.c | 8 ++++++++ networking/traceroute.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/networking/ping.c b/networking/ping.c index 774f8f3e0..d1d59d545 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -135,6 +135,14 @@ # define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */ #endif +/* Some operating systems, like GNU/Hurd, don't define SOL_RAW, but do have + * IPPROTO_RAW. Since the IPPROTO definitions are also valid to use for + * setsockopt (and take the same value as their corresponding SOL definitions, + * if they exist), we can just fall back on IPPROTO_RAW. */ +#ifndef SOL_RAW +# define SOL_RAW IPPROTO_RAW +#endif + #if ENABLE_PING6 # include /* I see RENUMBERED constants in bits/in.h - !!? diff --git a/networking/traceroute.c b/networking/traceroute.c index 8b6247482..df7122047 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -323,6 +323,14 @@ # define IPPROTO_IP 0 #endif +/* Some operating systems, like GNU/Hurd, don't define SOL_RAW, but do have + * IPPROTO_RAW. Since the IPPROTO definitions are also valid to use for + * setsockopt (and take the same value as their corresponding SOL definitions, + * if they exist), we can just fall back on IPPROTO_RAW. */ +#ifndef SOL_RAW +# define SOL_RAW IPPROTO_RAW +#endif + #define OPT_STRING \ "FIlnrdvxt:i:m:p:q:s:w:z:f:" \ -- cgit v1.2.3-55-g6feb From 160d027c2110d16ad9fb541cd966f73d971c074f Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 7 Oct 2017 18:53:19 +0100 Subject: blkdiscard: Only build on Linux Signed-off-by: James Clarke Signed-off-by: Denys Vlasenko --- util-linux/blkdiscard.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util-linux/blkdiscard.c b/util-linux/blkdiscard.c index 5863f0aab..e4902e5b5 100644 --- a/util-linux/blkdiscard.c +++ b/util-linux/blkdiscard.c @@ -8,6 +8,7 @@ //config:config BLKDISCARD //config: bool "blkdiscard (5.3 kb)" //config: default y +//config: select PLATFORM_LINUX //config: help //config: blkdiscard discards sectors on a given device. -- cgit v1.2.3-55-g6feb From 24e17b43858e165ba8384e2aa7403cecd899ad2d Mon Sep 17 00:00:00 2001 From: James Clarke Date: Mon, 30 Oct 2017 15:18:32 +0100 Subject: xfuncs: Handle missing non-POSIX termios constants Signed-off-by: James Clarke Signed-off-by: Denys Vlasenko --- libbb/xfuncs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 9cbfb2836..43ae98065 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -355,6 +355,15 @@ int FAST_FUNC get_termios_and_make_raw(int fd, struct termios *newterm, struct t */ } if (flags & TERMIOS_RAW_INPUT) { +#ifndef IMAXBEL +# define IMAXBEL 0 +#endif +#ifndef IUCLC +# define IUCLC 0 +#endif +#ifndef IXANY +# define IXANY 0 +#endif /* IXOFF=0: disable sending XON/XOFF if input buf is full */ /* IXON=0: input XON/XOFF chars are not special */ /* dont convert anything on input */ -- cgit v1.2.3-55-g6feb From d1535216ca27047e3962d61b975bd2a638aa45a2 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 7 Oct 2017 18:53:20 +0100 Subject: df: Use statvfs instead of non-standard statfs Platforms differ on what their implementations of statfs include. Importantly, FreeBSD's does not include a f_frsize member inside struct statfs. However, statvfs is specified by POSIX and includes everything we need, so we can just use that instead. Signed-off-by: James Clarke Signed-off-by: Denys Vlasenko --- coreutils/df.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coreutils/df.c b/coreutils/df.c index 121da970b..4076b5fec 100644 --- a/coreutils/df.c +++ b/coreutils/df.c @@ -77,7 +77,7 @@ //usage: "/dev/sda3 17381728 17107080 274648 98% /\n" #include -#include +#include #include "libbb.h" #include "unicode.h" @@ -98,7 +98,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) unsigned opt; FILE *mount_table; struct mntent *mount_entry; - struct statfs s; + struct statvfs s; enum { OPT_KILO = (1 << 0), @@ -211,7 +211,7 @@ int df_main(int argc UNUSED_PARAM, char **argv) mount_point = mount_entry->mnt_dir; fs_type = mount_entry->mnt_type; - if (statfs(mount_point, &s) != 0) { + if (statvfs(mount_point, &s) != 0) { bb_simple_perror_msg(mount_point); goto set_error; } -- cgit v1.2.3-55-g6feb From 518fb3ba193cddc1369090bfdf827618b42791db Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 7 Oct 2017 18:53:23 +0100 Subject: udp_io, traceroute: Standardise IPv6 PKTINFO handling to be portable The current standard (RFC 3542) is for IPV6_RECVPKTINFO to be given to setsockopt, and IPV6_PKTINFO to be used as the packet type. Previously, RFC 2292 required IPV6_PKTINFO to be used for both, but RFC 3542 re-purposed IPV6_PKTINFO when given to setsockopt. The special Linux-specific IPV6_2292PKTINFO has the same semantics as IPV6_PKTINFO in RFC 2292, but was introduced at the same time as IPV6_RECVPKTINFO. Therefore, if we have IPV6_RECVPKTINFO available, we can use the RFC 3542 style, and if not, we assume that only the RFC 2292 API is available, using IPV6_PKTINFO for both. Signed-off-by: James Clarke Signed-off-by: Denys Vlasenko --- libbb/udp_io.c | 8 ++++++-- networking/traceroute.c | 8 +++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libbb/udp_io.c b/libbb/udp_io.c index 6e3ef484e..68355e6c4 100644 --- a/libbb/udp_io.c +++ b/libbb/udp_io.c @@ -8,6 +8,10 @@ */ #include "libbb.h" +#if defined(IPV6_PKTINFO) && !defined(IPV6_RECVPKTINFO) +# define IPV6_RECVPKTINFO IPV6_PKTINFO +#endif + /* * This asks kernel to let us know dst addr/port of incoming packets * We don't check for errors here. Not supported == won't be used @@ -18,8 +22,8 @@ socket_want_pktinfo(int fd UNUSED_PARAM) #ifdef IP_PKTINFO setsockopt_1(fd, IPPROTO_IP, IP_PKTINFO); #endif -#if ENABLE_FEATURE_IPV6 && defined(IPV6_PKTINFO) - setsockopt_1(fd, IPPROTO_IPV6, IPV6_PKTINFO); +#if ENABLE_FEATURE_IPV6 && defined(IPV6_RECVPKTINFO) + setsockopt_1(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO); #endif } diff --git a/networking/traceroute.c b/networking/traceroute.c index df7122047..6dcbc2faa 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -311,6 +311,9 @@ # ifndef SOL_IPV6 # define SOL_IPV6 IPPROTO_IPV6 # endif +# if defined(IPV6_PKTINFO) && !defined(IPV6_RECVPKTINFO) +# define IPV6_RECVPKTINFO IPV6_PKTINFO +# endif #endif #include "libbb.h" @@ -911,12 +914,7 @@ common_traceroute_main(int op, char **argv) #if ENABLE_TRACEROUTE6 if (af == AF_INET6) { xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock); -# ifdef IPV6_RECVPKTINFO setsockopt_1(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO); - setsockopt_1(rcvsock, SOL_IPV6, IPV6_2292PKTINFO); -# else - setsockopt_1(rcvsock, SOL_IPV6, IPV6_PKTINFO); -# endif } else #endif { -- cgit v1.2.3-55-g6feb From 6a4f2231221c2c4f7ca82f081f442e31a6cfd051 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 Oct 2017 12:44:37 +0100 Subject: ntpd: improve treatment of DNS resolution failures function old new delta ntpd_main 1106 1177 +71 resolve_peer_hostname 122 127 +5 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 76/0) Total: 76 bytes Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index 8f792d16d..e0c9810a1 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -155,7 +155,8 @@ #define RETRY_INTERVAL 32 /* on send/recv error, retry in N secs (need to be power of 2) */ #define NOREPLY_INTERVAL 512 /* sent, but got no reply: cap next query by this many seconds */ #define RESPONSE_INTERVAL 16 /* wait for reply up to N secs */ -#define HOSTNAME_INTERVAL 5 /* hostname lookup failed. Wait N secs for next try */ +#define HOSTNAME_INTERVAL 4 /* hostname lookup failed. Wait N * peer->dns_errors secs for next try */ +#define DNS_ERRORS_CAP 0x3f /* peer->dns_errors is in [0..63] */ /* Step threshold (sec). std ntpd uses 0.128. */ @@ -301,6 +302,7 @@ typedef struct { uint8_t lastpkt_status; uint8_t lastpkt_stratum; uint8_t reachable_bits; + uint8_t dns_errors; /* when to send new query (if p_fd == -1) * or when receive times out (if p_fd >= 0): */ double next_action_time; @@ -802,10 +804,9 @@ resolve_peer_hostname(peer_t *p) p->p_dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); VERB1 if (strcmp(p->p_hostname, p->p_dotted) != 0) bb_error_msg("'%s' is %s", p->p_hostname, p->p_dotted); - } else { - /* error message is emitted by host2sockaddr() */ - set_next(p, HOSTNAME_INTERVAL); + p->dns_errors = 0; } + p->dns_errors = ((p->dns_errors << 1) | 1) & DNS_ERRORS_CAP; return lsa; } @@ -2358,14 +2359,6 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) int nfds, timeout; double nextaction; - /* Resolve peer names to IPs, if not resolved yet */ - for (item = G.ntp_peers; item != NULL; item = item->link) { - peer_t *p = (peer_t *) item->data; - - if (p->next_action_time <= G.cur_time && !p->p_lsa) - resolve_peer_hostname(p); - } - /* Nothing between here and poll() blocks for any significant time */ nextaction = G.cur_time + 3600; @@ -2447,13 +2440,38 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) did_poll: gettime1900d(); /* sets G.cur_time */ if (nfds <= 0) { - if (!bb_got_signal /* poll wasn't interrupted by a signal */ - && G.cur_time - G.last_script_run > 11*60 - ) { + double ct; + + if (bb_got_signal) + break; /* poll was interrupted by a signal */ + + if (G.cur_time - G.last_script_run > 11*60) { /* Useful for updating battery-backed RTC and such */ run_script("periodic", G.last_update_offset); gettime1900d(); /* sets G.cur_time */ } + + /* Resolve peer names to IPs, if not resolved yet. + * We do it only when poll timed out: + * this way, we almost never overlap DNS resolution with + * "request-reply" packet round trip. + */ + ct = G.cur_time; + for (item = G.ntp_peers; item != NULL; item = item->link) { + peer_t *p = (peer_t *) item->data; + if (p->next_action_time <= ct && !p->p_lsa) { + /* This can take up to ~10 sec per each DNS query */ + resolve_peer_hostname(p); + } + } + gettime1900d(); /* sets G.cur_time (needed for set_next()) */ + /* Set next time for those which are still not resolved */ + for (item = G.ntp_peers; item != NULL; item = item->link) { + peer_t *p = (peer_t *) item->data; + if (p->next_action_time <= ct && !p->p_lsa) { + set_next(p, HOSTNAME_INTERVAL * p->dns_errors); + } + } goto check_unsync; } -- cgit v1.2.3-55-g6feb From 59a5604a795ef5ba850e99a3aafc5b015dd237a1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 Oct 2017 12:47:07 +0100 Subject: ntpd: mention in help text that -d can be repeated Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index e0c9810a1..add282b1d 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -71,7 +71,7 @@ //usage: "[-dnqNw"IF_FEATURE_NTPD_SERVER("l -I IFACE")"] [-S PROG] [-p PEER]..." //usage:#define ntpd_full_usage "\n\n" //usage: "NTP client/server\n" -//usage: "\n -d Verbose" +//usage: "\n -d Verbose (may be repeated)" //usage: "\n -n Do not daemonize" //usage: "\n -q Quit after clock is set" //usage: "\n -N Run at high priority" -- cgit v1.2.3-55-g6feb From 6bcc2c0f6cb868232ec06231aa37a3fa65c59d22 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 7 Oct 2017 18:53:24 +0100 Subject: grep: skip grepping symlinks to directories When grep is passed -r, recursive_action will treat any symlinks to directories not in the root as normal files, since it lstat's them and is therefore told they are not directories. However, file_action_grep will still try to fopen and read from them to see whether they match, which varies in behaviour across platforms. Linux will give EISDIR and thus grep will not find any matching lines, but FreeBSD will give the raw contents of the directory itself, which may match the given pattern. Also, if grep is passed -c, it will even print a count for these symlinks, even on Linux. Since this recursive_action behaviour is required for the correct functioning of other applets, such as tar, grep should handle this special case and skip any such symlinks. function old new delta file_action_grep 80 161 +81 Signed-off-by: James Clarke Signed-off-by: Denys Vlasenko --- findutils/grep.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/findutils/grep.c b/findutils/grep.c index f72175afb..fc6de4b69 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -639,11 +639,28 @@ static void load_regexes_from_file(llist_t *fopt) } static int FAST_FUNC file_action_grep(const char *filename, - struct stat *statbuf UNUSED_PARAM, + struct stat *statbuf, void* matched, int depth UNUSED_PARAM) { - FILE *file = fopen_for_read(filename); + FILE *file; + + /* If we are given a link to a directory, we should bail out now, rather + * than trying to open the "file" and hoping getline gives us nothing, + * since that is not portable across operating systems (FreeBSD for + * example will return the raw directory contents). */ + if (S_ISLNK(statbuf->st_mode)) { + struct stat sb; + if (stat(filename, &sb) != 0) { + if (!SUPPRESS_ERR_MSGS) + bb_simple_perror_msg(filename); + return 0; + } + if (S_ISDIR(sb.st_mode)) + return 1; + } + + file = fopen_for_read(filename); if (file == NULL) { if (!SUPPRESS_ERR_MSGS) bb_simple_perror_msg(filename); -- cgit v1.2.3-55-g6feb From f1fdda45423a0133094840c0367aef1b026635d5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 Oct 2017 15:59:19 +0100 Subject: Fix build failures if MAXHOSTNAMELEN or MAXPATHLEN is not defined Signed-off-by: Denys Vlasenko --- networking/traceroute.c | 3 +++ util-linux/fdisk_osf.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/networking/traceroute.c b/networking/traceroute.c index 6dcbc2faa..a027b928a 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -709,6 +709,9 @@ packet_ok(int read_len, len_and_sockaddr *from_lsa, # if ENABLE_FEATURE_TRACEROUTE_VERBOSE if (verbose) { +# ifndef MAXHOSTNAMELEN +# define MAXHOSTNAMELEN 80 +# endif unsigned char *p; char pa1[MAXHOSTNAMELEN]; char pa2[MAXHOSTNAMELEN]; diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index 1141b7801..1328c1fcd 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c @@ -709,6 +709,9 @@ sync_disks(void) static void xbsd_write_bootstrap(void) { +#ifndef MAXPATHLEN +# define MAXPATHLEN 1024 +#endif char path[MAXPATHLEN]; const char *bootdir = BSD_LINUX_BOOTDIR; const char *dkbasename; -- cgit v1.2.3-55-g6feb From d5c1482fbac71c51e3add52632cdf1f9f9e6661b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 31 Oct 2017 16:53:23 +0100 Subject: ntpd: skip over setting next DNS resolution attempt if it is not needed function old new delta ntpd_main 1177 1197 +20 resolve_peer_hostname 127 129 +2 Signed-off-by: Denys Vlasenko --- networking/ntpd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/networking/ntpd.c b/networking/ntpd.c index add282b1d..0b60d003b 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -805,6 +805,7 @@ resolve_peer_hostname(peer_t *p) VERB1 if (strcmp(p->p_hostname, p->p_dotted) != 0) bb_error_msg("'%s' is %s", p->p_hostname, p->p_dotted); p->dns_errors = 0; + return lsa; } p->dns_errors = ((p->dns_errors << 1) | 1) & DNS_ERRORS_CAP; return lsa; @@ -2441,6 +2442,7 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) gettime1900d(); /* sets G.cur_time */ if (nfds <= 0) { double ct; + int dns_error; if (bb_got_signal) break; /* poll was interrupted by a signal */ @@ -2456,16 +2458,19 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) * this way, we almost never overlap DNS resolution with * "request-reply" packet round trip. */ + dns_error = 0; ct = G.cur_time; for (item = G.ntp_peers; item != NULL; item = item->link) { peer_t *p = (peer_t *) item->data; if (p->next_action_time <= ct && !p->p_lsa) { /* This can take up to ~10 sec per each DNS query */ - resolve_peer_hostname(p); + dns_error |= (!resolve_peer_hostname(p)); } } - gettime1900d(); /* sets G.cur_time (needed for set_next()) */ + if (!dns_error) + goto check_unsync; /* Set next time for those which are still not resolved */ + gettime1900d(); /* sets G.cur_time (needed for set_next()) */ for (item = G.ntp_peers; item != NULL; item = item->link) { peer_t *p = (peer_t *) item->data; if (p->next_action_time <= ct && !p->p_lsa) { -- cgit v1.2.3-55-g6feb From 9c143ce52da11ec3d21a3491c3749841d3dc10f0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 2 Nov 2017 12:56:24 +0100 Subject: ash: retain envvars with bad names in initial environment. Closes 10231 Reworks "ash: [VAR] Sanitise environment variable names on entry" commit. Signed-off-by: Denys Vlasenko --- shell/ash.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 88e607f08..7a0b88c68 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10863,9 +10863,17 @@ showvars(const char *sep_prefix, int on, int off) const char *p; const char *q; - p = strchrnul(*ep, '='); + p = endofname(*ep); +/* Used to have simple "p = strchrnul(*ep, '=')" here instead, but this + * makes "export -p" to have output not suitable for "eval": + * import os + * os.environ["test-test"]="test" + * if os.fork() == 0: + * os.execv("ash", [ 'ash', '-c', 'eval $(export -p); echo OK' ]) # fixes this + * os.execv("ash", [ 'ash', '-c', 'env | grep test-test' ]) + */ q = nullstr; - if (*p) + if (*p == '=') q = single_quote(++p); out1fmt("%s%s%.*s%s\n", sep_prefix, sep, (int)(p - *ep), *ep, q); } @@ -13639,8 +13647,18 @@ init(void) initvar(); for (envp = environ; envp && *envp; envp++) { - p = endofname(*envp); - if (p != *envp && *p == '=') { +/* Used to have + * p = endofname(*envp); + * if (p != *envp && *p == '=') { + * here to weed out badly-named variables, but this breaks + * scenarios where people do want them passed to children: + * import os + * os.environ["test-test"]="test" + * if os.fork() == 0: + * os.execv("ash", [ 'ash', '-c', 'eval $(export -p); echo OK' ]) # fixes this + * os.execv("ash", [ 'ash', '-c', 'env | grep test-test' ]) # breaks this + */ + if (strchr(*envp, '=')) { setvareq(*envp, VEXPORT|VTEXTFIXED); } } -- cgit v1.2.3-55-g6feb From f5e8b4278822f2413bf7e47466f55cc1a0fcca9a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 2 Nov 2017 15:25:28 +0100 Subject: init: reduce the window when init can lose reboot/poweroff signals function old new delta init_main 695 712 +17 Signed-off-by: Denys Vlasenko --- init/init.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/init/init.c b/init/init.c index 5304e5c2c..6f3374eac 100644 --- a/init/init.c +++ b/init/init.c @@ -1064,6 +1064,12 @@ int init_main(int argc UNUSED_PARAM, char **argv) #endif if (!DEBUG_INIT) { + /* Some users send poweroff signals to init VERY early. + * To handle this, mask signals early, + * and unmask them only after signal handlers are installed. + */ + sigprocmask_allsigs(SIG_BLOCK); + /* Expect to be invoked as init with PID=1 or be invoked as linuxrc */ if (getpid() != 1 && (!ENABLE_LINUXRC || applet_name[0] != 'l') /* not linuxrc? */ @@ -1106,29 +1112,6 @@ int init_main(int argc UNUSED_PARAM, char **argv) message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); #endif -#if 0 -/* It's 2013, does anyone really still depend on this? */ -/* If you do, consider adding swapon to sysinit actions then! */ -/* struct sysinfo is linux-specific */ -# ifdef __linux__ - /* Make sure there is enough memory to do something useful. */ - /*if (ENABLE_SWAPONOFF) - WRONG: we may have non-bbox swapon*/ { - struct sysinfo info; - - if (sysinfo(&info) == 0 - && (info.mem_unit ? info.mem_unit : 1) * (long long)info.totalram < 1024*1024 - ) { - message(L_CONSOLE, "Low memory, forcing swapon"); - /* swapon -a requires /proc typically */ - new_init_action(SYSINIT, "mount -t proc proc /proc", ""); - /* Try to turn on swap */ - new_init_action(SYSINIT, "swapon -a", ""); - run_actions(SYSINIT); /* wait and removing */ - } - } -# endif -#endif - /* Check if we are supposed to be in single user mode */ if (argv[1] && (strcmp(argv[1], "single") == 0 || strcmp(argv[1], "-s") == 0 || LONE_CHAR(argv[1], '1')) @@ -1204,6 +1187,8 @@ int init_main(int argc UNUSED_PARAM, char **argv) + (1 << SIGHUP) /* reread /etc/inittab */ #endif , record_signo); + + sigprocmask_allsigs(SIG_UNBLOCK); } /* Now run everything that needs to be run */ -- cgit v1.2.3-55-g6feb From a5060b8364faa7c677c8950f1315c451403b0660 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 3 Nov 2017 14:16:25 +0100 Subject: ash: fix nofork bug where environment is not properly passed to a command function old new delta listvars 144 252 +108 evalcommand 1500 1546 +46 showvars 142 147 +5 shellexec 242 245 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 162/0) Total: 162 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 45 +++++++++++++++++++++--- shell/ash_test/ash-standalone/nofork_env.right | 9 +++++ shell/ash_test/ash-standalone/nofork_env.tests | 15 ++++++++ shell/hush_test/hush-standalone/nofork_env.right | 9 +++++ shell/hush_test/hush-standalone/nofork_env.tests | 15 ++++++++ 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 shell/ash_test/ash-standalone/nofork_env.right create mode 100755 shell/ash_test/ash-standalone/nofork_env.tests create mode 100644 shell/hush_test/hush-standalone/nofork_env.right create mode 100755 shell/hush_test/hush-standalone/nofork_env.tests diff --git a/shell/ash.c b/shell/ash.c index 7a0b88c68..e69ddb4ff 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -2380,8 +2380,11 @@ listsetvar(struct strlist *list_set_var, int flags) /* * Generate a list of variables satisfying the given conditions. */ +#if !ENABLE_FEATURE_SH_NOFORK +# define listvars(on, off, lp, end) listvars(on, off, end) +#endif static char ** -listvars(int on, int off, char ***end) +listvars(int on, int off, struct strlist *lp, char ***end) { struct var **vpp; struct var *vp; @@ -2394,12 +2397,40 @@ listvars(int on, int off, char ***end) do { for (vp = *vpp; vp; vp = vp->next) { if ((vp->flags & mask) == on) { +#if ENABLE_FEATURE_SH_NOFORK + /* If variable with the same name is both + * exported and temporarily set for a command: + * export ZVAR=5 + * ZVAR=6 printenv + * then "ZVAR=6" will be both in vartab and + * lp lists. Do not pass it twice to printenv. + */ + struct strlist *lp1 = lp; + while (lp1) { + if (strcmp(lp1->text, vp->var_text) == 0) + goto skip; + lp1 = lp1->next; + } +#endif if (ep == stackstrend()) ep = growstackstr(); *ep++ = (char*)vp->var_text; +#if ENABLE_FEATURE_SH_NOFORK + skip: ; +#endif } } } while (++vpp < vartab + VTABSIZE); + +#if ENABLE_FEATURE_SH_NOFORK + while (lp) { + if (ep == stackstrend()) + ep = growstackstr(); + *ep++ = lp->text; + lp = lp->next; + } +#endif + if (ep == stackstrend()) ep = growstackstr(); if (end) @@ -7860,7 +7891,7 @@ static void shellexec(char *prog, char **argv, const char *path, int idx) int exerrno; int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */ - envp = listvars(VEXPORT, VUNSET, /*end:*/ NULL); + envp = listvars(VEXPORT, VUNSET, /*strlist:*/ NULL, /*end:*/ NULL); if (strchr(prog, '/') != NULL #if ENABLE_FEATURE_SH_STANDALONE || (applet_no = find_applet_by_name(prog)) >= 0 @@ -9930,7 +9961,11 @@ evalcommand(union node *cmd, int flags) /* find_command() encodes applet_no as (-2 - applet_no) */ int applet_no = (- cmdentry.u.index - 2); if (applet_no >= 0 && APPLET_IS_NOFORK(applet_no)) { - listsetvar(varlist.list, VEXPORT|VSTACK); + char **sv_environ; + + INT_OFF; + sv_environ = environ; + environ = listvars(VEXPORT, VUNSET, varlist.list, /*end:*/ NULL); /* * Run _main(). * Signals (^C) can't interrupt here. @@ -9939,8 +9974,8 @@ evalcommand(union node *cmd, int flags) * and/or wait for user input ineligible for NOFORK: * for example, "yes" or "rm" (rm -i waits for input). */ - INT_OFF; status = run_nofork_applet(applet_no, argv); + environ = sv_environ; /* * Try enabling NOFORK for "yes" applet. * ^C _will_ stop it (write returns EINTR), @@ -10854,7 +10889,7 @@ showvars(const char *sep_prefix, int on, int off) const char *sep; char **ep, **epend; - ep = listvars(on, off, &epend); + ep = listvars(on, off, /*strlist:*/ NULL, &epend); qsort(ep, epend - ep, sizeof(char *), vpcmp); sep = *sep_prefix ? " " : sep_prefix; diff --git a/shell/ash_test/ash-standalone/nofork_env.right b/shell/ash_test/ash-standalone/nofork_env.right new file mode 100644 index 000000000..3f16ff458 --- /dev/null +++ b/shell/ash_test/ash-standalone/nofork_env.right @@ -0,0 +1,9 @@ +ZVAR=1 +ZVAR=2 +ZVAR=3 +ZVAR=4 +ZVAR=5 +ZVAR=6 +ZVAR=7 +ZVAR=8 +Ok:0 diff --git a/shell/ash_test/ash-standalone/nofork_env.tests b/shell/ash_test/ash-standalone/nofork_env.tests new file mode 100755 index 000000000..111e564d2 --- /dev/null +++ b/shell/ash_test/ash-standalone/nofork_env.tests @@ -0,0 +1,15 @@ +# ash had a bug where NOFORKed applet (env/printenv) was not seeing new exported variables + +(export ZVAR=1; printenv) | grep ^ZVAR= +(ZVAR=2 printenv) | grep ^ZVAR= + +(export ZVAR=3; env) | grep ^ZVAR= +(ZVAR=4 env) | grep ^ZVAR= + +export ZVAR=5; printenv | grep ^ZVAR= +ZVAR=6 printenv | grep ^ZVAR= + +export ZVAR=7; env | grep ^ZVAR= +ZVAR=8 env | grep ^ZVAR= + +echo Ok:$? diff --git a/shell/hush_test/hush-standalone/nofork_env.right b/shell/hush_test/hush-standalone/nofork_env.right new file mode 100644 index 000000000..3f16ff458 --- /dev/null +++ b/shell/hush_test/hush-standalone/nofork_env.right @@ -0,0 +1,9 @@ +ZVAR=1 +ZVAR=2 +ZVAR=3 +ZVAR=4 +ZVAR=5 +ZVAR=6 +ZVAR=7 +ZVAR=8 +Ok:0 diff --git a/shell/hush_test/hush-standalone/nofork_env.tests b/shell/hush_test/hush-standalone/nofork_env.tests new file mode 100755 index 000000000..111e564d2 --- /dev/null +++ b/shell/hush_test/hush-standalone/nofork_env.tests @@ -0,0 +1,15 @@ +# ash had a bug where NOFORKed applet (env/printenv) was not seeing new exported variables + +(export ZVAR=1; printenv) | grep ^ZVAR= +(ZVAR=2 printenv) | grep ^ZVAR= + +(export ZVAR=3; env) | grep ^ZVAR= +(ZVAR=4 env) | grep ^ZVAR= + +export ZVAR=5; printenv | grep ^ZVAR= +ZVAR=6 printenv | grep ^ZVAR= + +export ZVAR=7; env | grep ^ZVAR= +ZVAR=8 env | grep ^ZVAR= + +echo Ok:$? -- cgit v1.2.3-55-g6feb