From 7b85ec30b5941f0b90c48a990f2f6840aca87bce Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 13 Oct 2015 17:17:34 +0200 Subject: *: more BUILD_BUG_ON conversions Signed-off-by: Denys Vlasenko --- archival/libarchive/decompress_gunzip.c | 5 ++--- editors/sed.c | 10 +++++----- findutils/find.c | 4 +--- findutils/grep.c | 4 +--- miscutils/hdparm.c | 7 +++---- miscutils/taskset.c | 6 ++---- networking/inetd.c | 4 +--- networking/nbd-client.c | 5 ++--- networking/telnet.c | 4 +--- procps/top.c | 9 ++++----- 10 files changed, 22 insertions(+), 36 deletions(-) diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index 1360abef7..7b6f45934 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c @@ -1118,9 +1118,8 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate) uint8_t os_flags_UNUSED; } PACKED formatted; } header; - struct BUG_header { - char BUG_header[sizeof(header) == 8 ? 1 : -1]; - }; + + BUILD_BUG_ON(sizeof(header) != 8); /* * Rewind bytebuffer. We use the beginning because the header has 8 diff --git a/editors/sed.c b/editors/sed.c index 7bbf820d8..a8c35388b 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -162,10 +162,8 @@ struct globals { } pipeline; } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) -struct BUG_G_too_big { - char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; -}; #define INIT_G() do { \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ G.sed_cmd_tail = &G.sed_cmd_head; \ } while (0) @@ -501,9 +499,11 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) IDX_rbrace, IDX_nul }; - struct chk { char chk[sizeof(cmd_letters)-1 == IDX_nul ? 1 : -1]; }; + unsigned idx; + + BUILD_BUG_ON(sizeof(cmd_letters)-1 != IDX_nul); - unsigned idx = strchrnul(cmd_letters, sed_cmd->cmd) - cmd_letters; + idx = strchrnul(cmd_letters, sed_cmd->cmd) - cmd_letters; /* handle (s)ubstitution command */ if (idx == IDX_s) { diff --git a/findutils/find.c b/findutils/find.c index bd7ccc323..5bd753536 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -423,9 +423,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) #define INIT_G() do { \ - struct G_sizecheck { \ - char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \ - }; \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ /* we have to zero it out because of NOEXEC */ \ memset(&G, 0, sizeof(G)); \ IF_FEATURE_FIND_MAXDEPTH(G.minmaxdepth[1] = INT_MAX;) \ diff --git a/findutils/grep.c b/findutils/grep.c index b9621384e..10b69275a 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -203,9 +203,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) #define INIT_G() do { \ - struct G_sizecheck { \ - char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \ - }; \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) #define max_matches (G.max_matches ) #if !ENABLE_EXTRA_COMPAT diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 9c486e7aa..8e201ac35 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -368,9 +368,6 @@ struct globals { #endif } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) -struct BUG_G_too_big { - char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; -}; #define get_identity (G.get_identity ) #define get_geom (G.get_geom ) #define do_flush (G.do_flush ) @@ -433,7 +430,9 @@ struct BUG_G_too_big { #define hwif_data (G.hwif_data ) #define hwif_ctrl (G.hwif_ctrl ) #define hwif_irq (G.hwif_irq ) -#define INIT_G() do { } while (0) +#define INIT_G() do { \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ +} while (0) /* Busybox messages and functions */ diff --git a/miscutils/taskset.c b/miscutils/taskset.c index 2646e1dab..100b1d926 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c @@ -75,12 +75,10 @@ static char *from_cpuset(cpu_set_t *mask) #define TASKSET_PRINTF_MASK "%llx" static unsigned long long from_cpuset(cpu_set_t *mask) { - struct BUG_CPU_SETSIZE_is_too_small { - char BUG_CPU_SETSIZE_is_too_small[ - CPU_SETSIZE < sizeof(int) ? -1 : 1]; - }; char *p = (void*)mask; + BUILD_BUG_ON(CPU_SETSIZE < sizeof(int)); + /* Take the least significant bits. Careful! * Consider both CPU_SETSIZE=4 and CPU_SETSIZE=1024 cases */ diff --git a/networking/inetd.c b/networking/inetd.c index dce5a0885..243165a07 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -329,9 +329,6 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) }; -struct BUG_G_too_big { - char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; -}; #define rlim_ofile_cur (G.rlim_ofile_cur ) #define rlim_ofile (G.rlim_ofile ) #define serv_list (G.serv_list ) @@ -352,6 +349,7 @@ struct BUG_G_too_big { #define allsock (G.allsock ) #define line (G.line ) #define INIT_G() do { \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ rlim_ofile_cur = OPEN_MAX; \ global_queuelen = 128; \ config_filename = "/etc/inetd.conf"; \ diff --git a/networking/nbd-client.c b/networking/nbd-client.c index a601430b6..70869d651 100644 --- a/networking/nbd-client.c +++ b/networking/nbd-client.c @@ -57,9 +57,8 @@ int nbdclient_main(int argc, char **argv) uint32_t flags; char data[124]; } nbd_header; - struct bug_check { - char c[offsetof(struct nbd_header_t, data) == 8+8+8+4 ? 1 : -1]; - }; + + BUILD_BUG_ON(offsetof(struct nbd_header_t, data) != 8+8+8+4); // Parse command line stuff (just a stub now) if (argc != 4) diff --git a/networking/telnet.c b/networking/telnet.c index 3bb6fb1ba..944cf1bd6 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -110,9 +110,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)&bb_common_bufsiz1) #define INIT_G() do { \ - struct G_sizecheck { \ - char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \ - }; \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) diff --git a/procps/top.c b/procps/top.c index 3d67c3cfd..9a3f171ac 100644 --- a/procps/top.c +++ b/procps/top.c @@ -184,10 +184,6 @@ struct globals { }; //FIX_ALIASING; - large code growth enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; #define G (*(struct globals*)&bb_common_bufsiz1) -struct BUG_bad_size { - char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; - char BUG_line_buf_too_small[LINE_BUF_SIZE > 80 ? 1 : -1]; -}; #define top (G.top ) #define ntop (G.ntop ) #define sort_field (G.sort_field ) @@ -204,7 +200,10 @@ struct BUG_bad_size { #define num_cpus (G.num_cpus ) #define total_pcpu (G.total_pcpu ) #define line_buf (G.line_buf ) -#define INIT_G() do { } while (0) +#define INIT_G() do { \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ + BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \ +} while (0) enum { OPT_d = (1 << 0), -- cgit v1.2.3-55-g6feb From 69934701fd1b18327b3a779cb292a728834b2d0d Mon Sep 17 00:00:00 2001 From: Curt Brune Date: Wed, 14 Oct 2015 12:53:47 +0200 Subject: networking: add 'ip neigh' command This patch ports the 'ip neigh' command, originally written by Alexey Kuznetsov, , to busybox. The base of the port is the version of iproute that shipped with Debian Squeeze, taken from: http://http.debian.net/debian/pool/main/i/iproute/iproute_20100519.orig.tar.gz This patch has actively been used by the Open Network Install Environment (ONIE) project for over 3 years without incident. function old new delta print_neigh - 933 +933 ipneigh_list_or_flush - 742 +742 get_hz - 109 +109 do_ipneigh - 62 +62 do_iproute 2112 2153 +41 packed_usage 30647 30667 +20 ipneigh_main - 14 +14 static.ip_neigh_commands - 12 +12 static.nuds - 9 +9 static.ip_func_ptrs 32 36 +4 print_route 1858 1727 -131 ------------------------------------------------------------------------------ (add/remove: 8/0 grow/shrink: 3/1 up/down: 1946/-131) Total: 1815 bytes Signed-off-by: Curt Brune Signed-off-by: Denys Vlasenko --- networking/Config.src | 13 ++ networking/ip.c | 19 +- networking/libiproute/Kbuild.src | 8 + networking/libiproute/ip_common.h | 2 +- networking/libiproute/ipneigh.c | 354 ++++++++++++++++++++++++++++++++++++++ networking/libiproute/iproute.c | 26 +-- networking/libiproute/utils.c | 22 +++ networking/libiproute/utils.h | 2 + 8 files changed, 420 insertions(+), 26 deletions(-) create mode 100644 networking/libiproute/ipneigh.c diff --git a/networking/Config.src b/networking/Config.src index 43ccbf385..8c7417f86 100644 --- a/networking/Config.src +++ b/networking/Config.src @@ -554,6 +554,13 @@ config FEATURE_IP_RULE help Add support for rule commands to "ip". +config FEATURE_IP_NEIGH + bool "ip neighbor" + default y + depends on IP + help + Add support for neighbor commands to "ip". + config FEATURE_IP_SHORT_FORMS bool "Support short forms of ip commands" default y @@ -565,6 +572,7 @@ config FEATURE_IP_SHORT_FORMS ip route -> iproute ip tunnel -> iptunnel ip rule -> iprule + ip neigh -> ipneigh Say N unless you desparately need the short form of the ip object commands. @@ -604,6 +612,11 @@ config IPRULE default y depends on FEATURE_IP_SHORT_FORMS && FEATURE_IP_RULE +config IPNEIGH + bool + default y + depends on FEATURE_IP_SHORT_FORMS && FEATURE_IP_NEIGH + config IPCALC bool "ipcalc" default y diff --git a/networking/ip.c b/networking/ip.c index d35345c36..ddfe74e9c 100644 --- a/networking/ip.c +++ b/networking/ip.c @@ -16,6 +16,7 @@ //usage: IF_FEATURE_IP_ROUTE("route | ") //usage: IF_FEATURE_IP_LINK("link | ") //usage: IF_FEATURE_IP_TUNNEL("tunnel | ") +//usage: IF_FEATURE_IP_NEIGH("neigh | ") //usage: IF_FEATURE_IP_RULE("rule") //usage: "} {COMMAND}" //usage:#define ip_full_usage "\n\n" @@ -25,6 +26,7 @@ //usage: IF_FEATURE_IP_ROUTE("route | ") //usage: IF_FEATURE_IP_LINK("link | ") //usage: IF_FEATURE_IP_TUNNEL("tunnel | ") +//usage: IF_FEATURE_IP_NEIGH("neigh | ") //usage: IF_FEATURE_IP_RULE("rule") //usage: "}\n" //usage: "OPTIONS := { -f[amily] { inet | inet6 | link } | -o[neline] }" @@ -80,6 +82,11 @@ //usage: " [mode { ipip | gre | sit }] [remote ADDR] [local ADDR]\n" //usage: " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n" //usage: " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]" +//usage: +//usage:#define ipneigh_trivial_usage +//usage: "{ show | flush} [ to PREFIX ] [ dev DEV ] [ nud STATE ]" +//usage:#define ipneigh_full_usage "\n\n" +//usage: "ipneigh { show | flush} [ to PREFIX ] [ dev DEV ] [ nud STATE ]" #include "libbb.h" @@ -90,7 +97,8 @@ || ENABLE_FEATURE_IP_ROUTE \ || ENABLE_FEATURE_IP_LINK \ || ENABLE_FEATURE_IP_TUNNEL \ - || ENABLE_FEATURE_IP_RULE + || ENABLE_FEATURE_IP_RULE \ + || ENABLE_FEATURE_IP_NEIGH static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM) { @@ -140,6 +148,13 @@ int iptunnel_main(int argc UNUSED_PARAM, char **argv) return ip_do(do_iptunnel, argv); } #endif +#if ENABLE_FEATURE_IP_NEIGH +int ipneigh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int ipneigh_main(int argc UNUSED_PARAM, char **argv) +{ + return ip_do(do_ipneigh, argv); +} +#endif int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -153,6 +168,7 @@ int ip_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_IP_TUNNEL("tunnel\0") IF_FEATURE_IP_TUNNEL("tunl\0") IF_FEATURE_IP_RULE("rule\0") + IF_FEATURE_IP_NEIGH("neigh\0") ; static const ip_func_ptr_t ip_func_ptrs[] = { ip_print_help, @@ -163,6 +179,7 @@ int ip_main(int argc UNUSED_PARAM, char **argv) IF_FEATURE_IP_TUNNEL(do_iptunnel,) IF_FEATURE_IP_TUNNEL(do_iptunnel,) IF_FEATURE_IP_RULE(do_iprule,) + IF_FEATURE_IP_NEIGH(do_ipneigh,) }; ip_func_ptr_t ip_func; int key; diff --git a/networking/libiproute/Kbuild.src b/networking/libiproute/Kbuild.src index 7c78f3c6a..c20e2fee8 100644 --- a/networking/libiproute/Kbuild.src +++ b/networking/libiproute/Kbuild.src @@ -64,3 +64,11 @@ lib-$(CONFIG_FEATURE_IP_RULE) += \ iprule.o \ rt_names.o \ utils.o + +lib-$(CONFIG_FEATURE_IP_NEIGH) += \ + ip_parse_common_args.o \ + ipneigh.o \ + libnetlink.o \ + ll_map.o \ + rt_names.o \ + utils.o diff --git a/networking/libiproute/ip_common.h b/networking/libiproute/ip_common.h index 30c7e595b..40171bed9 100644 --- a/networking/libiproute/ip_common.h +++ b/networking/libiproute/ip_common.h @@ -24,7 +24,7 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush); int FAST_FUNC do_ipaddr(char **argv); int FAST_FUNC do_iproute(char **argv); int FAST_FUNC do_iprule(char **argv); -//int FAST_FUNC do_ipneigh(char **argv); +int FAST_FUNC do_ipneigh(char **argv); int FAST_FUNC do_iptunnel(char **argv); int FAST_FUNC do_iplink(char **argv); //int FAST_FUNC do_ipmonitor(char **argv); diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c new file mode 100644 index 000000000..03a15d845 --- /dev/null +++ b/networking/libiproute/ipneigh.c @@ -0,0 +1,354 @@ +/* vi: set sw=4 ts=4: */ +/* + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + * + * Authors: Alexey Kuznetsov, + * + * Ported to Busybox by: Curt Brune + */ + +#include "ip_common.h" /* #include "libbb.h" is inside */ +#include "rt_names.h" +#include "utils.h" +#include +#include + +//static int xshow_stats = 3; +enum { xshow_stats = 3 }; + +static inline uint32_t rta_getattr_u32(const struct rtattr *rta) +{ + return *(uint32_t *)RTA_DATA(rta); +} + +#ifndef RTAX_RTTVAR +#define RTAX_RTTVAR RTAX_HOPS +#endif + + +struct filter_t { + int family; + int index; + int state; + int unused_only; + inet_prefix pfx; + int flushed; + char *flushb; + int flushp; + int flushe; + struct rtnl_handle *rth; +} FIX_ALIASING; +typedef struct filter_t filter_t; + +#define G_filter (*(filter_t*)&bb_common_bufsiz1) + +static int flush_update(void) +{ + if (rtnl_send(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { + bb_perror_msg("can't send flush request"); + return -1; + } + G_filter.flushp = 0; + return 0; +} + +static unsigned nud_state_a2n(char *arg) +{ + static const char keywords[] ALIGN1 = + /* "ip neigh show/flush" parameters: */ + "permanent\0" "reachable\0" "noarp\0" "none\0" + "stale\0" "incomplete\0" "delay\0" "probe\0" + "failed\0" + ; + static uint8_t nuds[] = { + NUD_PERMANENT,NUD_REACHABLE, NUD_NOARP,NUD_NONE, + NUD_STALE, NUD_INCOMPLETE,NUD_DELAY,NUD_PROBE, + NUD_FAILED + }; + int id; + + BUILD_BUG_ON( + (NUD_PERMANENT|NUD_REACHABLE| NUD_NOARP|NUD_NONE| + NUD_STALE| NUD_INCOMPLETE|NUD_DELAY|NUD_PROBE| + NUD_FAILED) > 0xff + ); + + id = index_in_substrings(keywords, arg); + if (id < 0) + bb_error_msg_and_die(bb_msg_invalid_arg, arg, "nud state"); + return nuds[id]; +} + +#ifndef NDA_RTA +#define NDA_RTA(r) \ + ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg)))) +#endif + + +static int FAST_FUNC print_neigh(const struct sockaddr_nl *who UNUSED_PARAM, + struct nlmsghdr *n, void *arg UNUSED_PARAM) +{ + struct ndmsg *r = NLMSG_DATA(n); + int len = n->nlmsg_len; + struct rtattr *tb[NDA_MAX+1]; + char abuf[256]; + + if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) { + bb_error_msg_and_die("not RTM_NEWNEIGH: %08x %08x %08x", + n->nlmsg_len, n->nlmsg_type, + n->nlmsg_flags); + } + len -= NLMSG_LENGTH(sizeof(*r)); + if (len < 0) { + bb_error_msg_and_die("BUG: wrong nlmsg len %d", len); + } + + if (G_filter.flushb && n->nlmsg_type != RTM_NEWNEIGH) + return 0; + + if (G_filter.family && G_filter.family != r->ndm_family) + return 0; + if (G_filter.index && G_filter.index != r->ndm_ifindex) + return 0; + if (!(G_filter.state&r->ndm_state) && + !(r->ndm_flags & NTF_PROXY) && + (r->ndm_state || !(G_filter.state & 0x100)) && + (r->ndm_family != AF_DECnet)) + return 0; + + parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); + + if (tb[NDA_DST]) { + if (G_filter.pfx.family) { + inet_prefix dst; + memset(&dst, 0, sizeof(dst)); + dst.family = r->ndm_family; + memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST])); + if (inet_addr_match(&dst, &G_filter.pfx, G_filter.pfx.bitlen)) + return 0; + } + } + if (G_filter.unused_only && tb[NDA_CACHEINFO]) { + struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); + if (ci->ndm_refcnt) + return 0; + } + + if (G_filter.flushb) { + struct nlmsghdr *fn; + if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) { + if (flush_update()) + return -1; + } + fn = (struct nlmsghdr*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp)); + memcpy(fn, n, n->nlmsg_len); + fn->nlmsg_type = RTM_DELNEIGH; + fn->nlmsg_flags = NLM_F_REQUEST; + fn->nlmsg_seq = ++(G_filter.rth->seq); + G_filter.flushp = (((char*)fn) + n->nlmsg_len) - G_filter.flushb; + G_filter.flushed++; + if (xshow_stats < 2) + return 0; + } + + if (tb[NDA_DST]) { + printf("%s ", + format_host(r->ndm_family, + RTA_PAYLOAD(tb[NDA_DST]), + RTA_DATA(tb[NDA_DST]), + abuf, sizeof(abuf))); + } + if (!G_filter.index && r->ndm_ifindex) + printf("dev %s ", ll_index_to_name(r->ndm_ifindex)); + if (tb[NDA_LLADDR]) { + SPRINT_BUF(b1); + printf("lladdr %s", ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]), + RTA_PAYLOAD(tb[NDA_LLADDR]), + ARPHRD_ETHER, + b1, sizeof(b1))); + } + if (r->ndm_flags & NTF_ROUTER) { + printf(" router"); + } + if (r->ndm_flags & NTF_PROXY) { + printf(" proxy"); + } + if (tb[NDA_CACHEINFO] && xshow_stats) { + struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); + int hz = get_hz(); + + if (ci->ndm_refcnt) + printf(" ref %d", ci->ndm_refcnt); + printf(" used %d/%d/%d", ci->ndm_used/hz, + ci->ndm_confirmed/hz, ci->ndm_updated/hz); + } + + if (tb[NDA_PROBES] && xshow_stats) { + uint32_t p = rta_getattr_u32(tb[NDA_PROBES]); + printf(" probes %u", p); + } + + /*if (r->ndm_state)*/ { + int nud = r->ndm_state; + char c = ' '; +#define PRINT_FLAG(f) \ + if (nud & NUD_##f) { \ + printf("%c"#f, c); \ + c = ','; \ + } + PRINT_FLAG(INCOMPLETE); + PRINT_FLAG(REACHABLE); + PRINT_FLAG(STALE); + PRINT_FLAG(DELAY); + PRINT_FLAG(PROBE); + PRINT_FLAG(FAILED); + PRINT_FLAG(NOARP); + PRINT_FLAG(PERMANENT); +#undef PRINT_FLAG + } + bb_putchar('\n'); + + return 0; +} + +static void ipneigh_reset_filter(void) +{ + memset(&G_filter, 0, sizeof(G_filter)); + G_filter.state = ~0; +} + +#define MAX_ROUNDS 10 +/* Return value becomes exitcode. It's okay to not return at all */ +static int FAST_FUNC ipneigh_list_or_flush(char **argv, int flush) +{ + static const char keywords[] ALIGN1 = + /* "ip neigh show/flush" parameters: */ + "to\0" "dev\0" "nud\0"; + enum { + KW_to, KW_dev, KW_nud, + }; + struct rtnl_handle rth; + struct ndmsg ndm = { 0 }; + char *filter_dev = NULL; + int state_given = 0; + int arg; + + ipneigh_reset_filter(); + + if (flush && !*argv) + bb_error_msg_and_die(bb_msg_requires_arg, "\"ip neigh flush\""); + + if (!G_filter.family) + G_filter.family = preferred_family; + + G_filter.state = (flush) ? + ~(NUD_PERMANENT|NUD_NOARP) : 0xFF & ~NUD_NOARP; + + while (*argv) { + arg = index_in_substrings(keywords, *argv); + if (arg == KW_dev) { + NEXT_ARG(); + filter_dev = *argv; + } else if (arg == KW_nud) { + unsigned state; + NEXT_ARG(); + if (!state_given) { + state_given = 1; + G_filter.state = 0; + } + if (strcmp(*argv, "all") == 0) { + state = ~0; + if (flush) + state &= ~NUD_NOARP; + } else { + state = nud_state_a2n(*argv); + } + if (state == 0) + state = 0x100; + G_filter.state |= state; + } else { + if (arg == KW_to) { + NEXT_ARG(); + } + get_prefix(&G_filter.pfx, *argv, G_filter.family); + if (G_filter.family == AF_UNSPEC) + G_filter.family = G_filter.pfx.family; + } + argv++; + } + + xrtnl_open(&rth); + ll_init_map(&rth); + + if (filter_dev) { + if ((G_filter.index = xll_name_to_index(filter_dev)) == 0) { + bb_error_msg_and_die(bb_msg_invalid_arg, + filter_dev, "Cannot find device"); + } + } + + if (flush) { + int round = 0; + char flushb[4096-512]; + G_filter.flushb = flushb; + G_filter.flushp = 0; + G_filter.flushe = sizeof(flushb); + G_filter.state &= ~NUD_FAILED; + G_filter.rth = &rth; + + while (round < MAX_ROUNDS) { + if (xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETNEIGH) < 0) { + bb_perror_msg_and_die("can't send dump request"); + } + G_filter.flushed = 0; + if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { + bb_perror_msg_and_die("flush terminated"); + } + if (G_filter.flushed == 0) { + if (round == 0) + puts("Nothing to flush"); + else + printf("*** Flush is complete after %d round(s) ***\n", round); + return 0; + } + round++; + if (flush_update() < 0) + xfunc_die(); + printf("\n*** Round %d, deleting %d entries ***\n", round, G_filter.flushed); + } + bb_error_msg_and_die("*** Flush not complete bailing out after %d rounds", MAX_ROUNDS); + } + + ndm.ndm_family = G_filter.family; + + if (rtnl_dump_request(&rth, RTM_GETNEIGH, &ndm, sizeof(struct ndmsg)) < 0) { + bb_perror_msg_and_die("can't send dump request"); + } + + if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { + bb_error_msg_and_die("dump terminated"); + } + + return 0; +} + +/* Return value becomes exitcode. It's okay to not return at all */ +int FAST_FUNC do_ipneigh(char **argv) +{ + static const char ip_neigh_commands[] ALIGN1 = + /*0-1*/ "show\0" "flush\0"; + int command_num; + + if (!*argv) + return ipneigh_list_or_flush(argv, 0); + + command_num = index_in_substrings(ip_neigh_commands, *argv); + switch (command_num) { + case 0: /* show */ + return ipneigh_list_or_flush(argv + 1, 0); + case 1: /* flush */ + return ipneigh_list_or_flush(argv + 1, 1); + } + invarg(*argv, applet_name); + return 1; +} diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 6ecd5f719..f7209b126 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -55,28 +55,6 @@ static int flush_update(void) return 0; } -static unsigned get_hz(void) -{ - static unsigned hz_internal; - FILE *fp; - - if (hz_internal) - return hz_internal; - - fp = fopen_for_read("/proc/net/psched"); - if (fp) { - unsigned nom, denom; - - if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2) - if (nom == 1000000) - hz_internal = denom; - fclose(fp); - } - if (!hz_internal) - hz_internal = bb_clk_tck(); - return hz_internal; -} - static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, struct nlmsghdr *n, void *arg UNUSED_PARAM) { @@ -217,7 +195,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, if (NLMSG_ALIGN(G_filter.flushp) + n->nlmsg_len > G_filter.flushe) { if (flush_update()) - bb_error_msg_and_die("flush"); + xfunc_die(); } fn = (void*)(G_filter.flushb + NLMSG_ALIGN(G_filter.flushp)); memcpy(fn, n, n->nlmsg_len); @@ -954,7 +932,7 @@ int FAST_FUNC do_iproute(char **argv) case 11: /* flush */ return iproute_list_or_flush(argv+1, 1); default: - bb_error_msg_and_die("unknown command %s", *argv); + invarg(*argv, applet_name); } return iproute_modify(cmd, flags, argv+1); diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c index d0fe30605..37b5311f0 100644 --- a/networking/libiproute/utils.c +++ b/networking/libiproute/utils.c @@ -13,6 +13,28 @@ #include "utils.h" #include "inet_common.h" +unsigned get_hz(void) +{ + static unsigned hz_internal; + FILE *fp; + + if (hz_internal) + return hz_internal; + + fp = fopen_for_read("/proc/net/psched"); + if (fp) { + unsigned nom, denom; + + if (fscanf(fp, "%*08x%*08x%08x%08x", &nom, &denom) == 2) + if (nom == 1000000) + hz_internal = denom; + fclose(fp); + } + if (!hz_internal) + hz_internal = bb_clk_tck(); + return hz_internal; +} + unsigned get_unsigned(char *arg, const char *errmsg) { unsigned long res; diff --git a/networking/libiproute/utils.h b/networking/libiproute/utils.h index 5fb4a862c..cd15b706b 100644 --- a/networking/libiproute/utils.h +++ b/networking/libiproute/utils.h @@ -85,6 +85,8 @@ int dnet_pton(int af, const char *src, void *addr); const char *ipx_ntop(int af, const void *addr, char *str, size_t len); int ipx_pton(int af, const char *src, void *addr); +unsigned get_hz(void); + POP_SAVED_FUNCTION_VISIBILITY #endif -- cgit v1.2.3-55-g6feb From 0f296a3a56b52842057e5a2bc653621a3a6c7bec Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 14 Oct 2015 13:21:01 +0200 Subject: libiproute: rename invarg(a,b) to invarg_1_to_2(a,b) invarg(a,b) - "invalid argument", but how a and b enter the message? invarg_1_to_2(a,b) is somewhat easier to read: "invalid argument 'a' to 'b'" Audit of usage revealed a number of bad uses, with too long messages. text data bss dec hex filename 938848 932 17448 957228 e9b2c busybox_old 938788 932 17448 957168 e9af0 busybox_unstripped Signed-off-by: Denys Vlasenko --- coreutils/dd.c | 4 ++-- findutils/find.c | 2 +- include/libbb.h | 2 +- libbb/messages.c | 2 +- networking/brctl.c | 8 ++++---- networking/libiproute/ip_parse_common_args.c | 2 +- networking/libiproute/ipaddress.c | 6 +++--- networking/libiproute/iplink.c | 27 +++++++++++++-------------- networking/libiproute/ipneigh.c | 10 +++++----- networking/libiproute/iproute.c | 12 ++++++------ networking/libiproute/iprule.c | 12 ++++++------ networking/libiproute/iptunnel.c | 6 +++--- networking/libiproute/utils.c | 12 ++++++------ networking/libiproute/utils.h | 2 +- networking/slattach.c | 6 +++--- networking/tc.c | 12 ++++++------ 16 files changed, 62 insertions(+), 63 deletions(-) diff --git a/coreutils/dd.c b/coreutils/dd.c index 53a843ca0..6a5288da1 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c @@ -326,7 +326,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) *arg = '\0'; n = index_in_strings(conv_words, val); if (n < 0) - bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv"); + bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "conv"); G.flags |= (1 << n); if (!arg) /* no ',' left, so this was the last specifier */ break; @@ -368,7 +368,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) int n; n = index_in_strings(status_words, val); if (n < 0) - bb_error_msg_and_die(bb_msg_invalid_arg, val, "status"); + bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status"); G.flags |= FLAG_STATUS << n; /*continue;*/ } diff --git a/findutils/find.c b/findutils/find.c index 5bd753536..a0d4853de 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -882,7 +882,7 @@ static int find_type(const char *type) mask = S_IFSOCK; if (mask == 0 || type[1] != '\0') - bb_error_msg_and_die(bb_msg_invalid_arg, type, "-type"); + bb_error_msg_and_die(bb_msg_invalid_arg_to, type, "-type"); return mask; } diff --git a/include/libbb.h b/include/libbb.h index 5a270cdca..f04f555c0 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1786,7 +1786,7 @@ extern const char bb_msg_can_not_create_raw_socket[] ALIGN1; extern const char bb_msg_perm_denied_are_you_root[] ALIGN1; extern const char bb_msg_you_must_be_root[] ALIGN1; extern const char bb_msg_requires_arg[] ALIGN1; -extern const char bb_msg_invalid_arg[] ALIGN1; +extern const char bb_msg_invalid_arg_to[] ALIGN1; extern const char bb_msg_standard_input[] ALIGN1; extern const char bb_msg_standard_output[] ALIGN1; diff --git a/libbb/messages.c b/libbb/messages.c index c1b7ba252..23e440bcd 100644 --- a/libbb/messages.c +++ b/libbb/messages.c @@ -29,7 +29,7 @@ const char bb_msg_can_not_create_raw_socket[] ALIGN1 = "can't create raw socket" const char bb_msg_perm_denied_are_you_root[] ALIGN1 = "permission denied (are you root?)"; const char bb_msg_you_must_be_root[] ALIGN1 = "you must be root"; const char bb_msg_requires_arg[] ALIGN1 = "%s requires an argument"; -const char bb_msg_invalid_arg[] ALIGN1 = "invalid argument '%s' to '%s'"; +const char bb_msg_invalid_arg_to[] ALIGN1 = "invalid argument '%s' to '%s'"; const char bb_msg_standard_input[] ALIGN1 = "standard input"; const char bb_msg_standard_output[] ALIGN1 = "standard output"; diff --git a/networking/brctl.c b/networking/brctl.c index c01a86998..b7320966a 100644 --- a/networking/brctl.c +++ b/networking/brctl.c @@ -128,7 +128,7 @@ static ALWAYS_INLINE void bb_strtotimeval(struct timeval *tv, # else if (sscanf(time_str, "%lf", &secs) != 1) # endif - bb_error_msg_and_die(bb_msg_invalid_arg, time_str, "timespec"); + bb_error_msg_and_die(bb_msg_invalid_arg_to, time_str, "timespec"); tv->tv_sec = secs; tv->tv_usec = 1000000 * (secs - tv->tv_sec); } @@ -205,7 +205,7 @@ int brctl_main(int argc UNUSED_PARAM, char **argv) key = index_in_strings(keywords, *argv); if (key == -1) /* no match found in keywords array, bail out. */ - bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); + bb_error_msg_and_die(bb_msg_invalid_arg_to, *argv, applet_name); argv++; fd = xsocket(AF_INET, SOCK_STREAM, 0); @@ -299,7 +299,7 @@ int brctl_main(int argc UNUSED_PARAM, char **argv) "1\0" "on\0" "y\0" "yes\0"; /* 4 .. 7 */ int onoff = index_in_strings(no_yes, *argv); if (onoff < 0) - bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); + bb_error_msg_and_die(bb_msg_invalid_arg_to, *argv, applet_name); onoff = (unsigned)onoff / 4; arm_ioctl(args, BRCTL_SET_BRIDGE_STP_STATE, onoff, 0); goto fire; @@ -332,7 +332,7 @@ int brctl_main(int argc UNUSED_PARAM, char **argv) port = if_nametoindex(*argv++); if (!port) - bb_error_msg_and_die(bb_msg_invalid_arg, *argv, "port"); + bb_error_msg_and_die(bb_msg_invalid_arg_to, *argv, "port"); memset(ifidx, 0, sizeof ifidx); arm_ioctl(args, BRCTL_GET_PORT_LIST, (unsigned long)ifidx, MAX_PORTS); diff --git a/networking/libiproute/ip_parse_common_args.c b/networking/libiproute/ip_parse_common_args.c index 59c759b23..1a298f738 100644 --- a/networking/libiproute/ip_parse_common_args.c +++ b/networking/libiproute/ip_parse_common_args.c @@ -67,7 +67,7 @@ char** FAST_FUNC ip_parse_common_args(char **argv) bb_show_usage(); arg = index_in_strings(families, *argv); if (arg < 0) - invarg(*argv, "protocol family"); + invarg_1_to_2(*argv, "family"); /* now arg == 0, 1 or 2 */ } else { arg -= ARG_IPv4; diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 8845cab91..c0f27c70d 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -455,7 +455,7 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) G_filter.scopemask = -1; if (rtnl_rtscope_a2n(&scope, *argv)) { if (strcmp(*argv, "all") != 0) { - invarg(*argv, "scope"); + invarg_1_to_2(*argv, "scope"); } scope = RT_SCOPE_NOWHERE; G_filter.scopemask = 0; @@ -669,7 +669,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) } else if (arg == 5) { /* scope */ uint32_t scope = 0; if (rtnl_rtscope_a2n(&scope, *argv)) { - invarg(*argv, "scope"); + invarg_1_to_2(*argv, "scope"); } req.ifa.ifa_scope = scope; scoped = 1; @@ -751,7 +751,7 @@ int FAST_FUNC do_ipaddr(char **argv) if (*argv) { cmd = index_in_substrings(commands, *argv); if (cmd < 0) - invarg(*argv, applet_name); + invarg_1_to_2(*argv, applet_name); argv++; if (cmd <= 4) { return ipaddr_modify( diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c index 5c27c2de3..ae3ef0ceb 100644 --- a/networking/libiproute/iplink.c +++ b/networking/libiproute/iplink.c @@ -349,7 +349,7 @@ static void vlan_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size) while (*argv) { arg = index_in_substrings(keywords, *argv); if (arg < 0) - invarg(*argv, "type vlan"); + invarg_1_to_2(*argv, "type vlan"); NEXT_ARG(); if (arg == ARG_id) { @@ -512,7 +512,7 @@ static int do_add_or_delete(char **argv, const unsigned rtm) if (name_str) { const size_t name_len = strlen(name_str) + 1; if (name_len < 2 || name_len > IFNAMSIZ) - invarg(name_str, "name"); + invarg_1_to_2(name_str, "name"); addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name_str, name_len); } if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) @@ -536,14 +536,14 @@ static int do_add_or_delete(char **argv, const unsigned rtm) if (qlen != -1) duparg("txqueuelen", *argv); if (get_integer(&qlen, *argv, 0)) - invarg("Invalid \"txqueuelen\" value\n", *argv); + invarg_1_to_2(*argv, "txqueuelen"); addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4); } else if (strcmp(*argv, "mtu") == 0) { NEXT_ARG(); if (mtu != -1) duparg("mtu", *argv); if (get_integer(&mtu, *argv, 0)) - invarg("Invalid \"mtu\" value\n", *argv); + invarg_1_to_2(*argv, "mtu"); addattr_l(&req->n, sizeof(*req), IFLA_MTU, &mtu, 4); } else if (strcmp(*argv, "netns") == 0) { NEXT_ARG(); @@ -554,7 +554,7 @@ static int do_add_or_delete(char **argv, const unsigned rtm) else if (get_integer(&netns, *argv, 0) == 0) addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4); else - invarg("Invalid \"netns\" value\n", *argv); + invarg_1_to_2(*argv, "netns"); } else if (strcmp(*argv, "multicast") == 0) { NEXT_ARG(); req->i.ifi_change |= IFF_MULTICAST; @@ -604,7 +604,7 @@ static int do_add_or_delete(char **argv, const unsigned rtm) struct rtattr *vflist; NEXT_ARG(); if (get_integer(&vf, *argv, 0)) { - invarg("Invalid \"vf\" value\n", *argv); + invarg_1_to_2(*argv, "vf"); } vflist = addattr_nest(&req->n, sizeof(*req), IFLA_VFINFO_LIST); @@ -617,7 +617,7 @@ static int do_add_or_delete(char **argv, const unsigned rtm) NEXT_ARG(); ifindex = ll_name_to_index(*argv); if (!ifindex) - invarg("Device does not exist\n", *argv); + invarg_1_to_2(*argv, "master"); addattr_l(&req->n, sizeof(*req), IFLA_MASTER, &ifindex, 4); } else if (matches(*argv, "nomaster") == 0) { @@ -644,28 +644,27 @@ static int do_add_or_delete(char **argv, const unsigned rtm) if (*group != -1) duparg("group", *argv); if (rtnl_group_a2n(group, *argv)) - invarg("Invalid \"group\" value\n", *argv); + invarg_1_to_2(*argv, "group"); } else if (strcmp(*argv, "mode") == 0) { int mode; NEXT_ARG(); mode = get_link_mode(*argv); if (mode < 0) - invarg("Invalid link mode\n", *argv); + invarg_1_to_2(*argv, "mode"); addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode); } else if (strcmp(*argv, "state") == 0) { int state; NEXT_ARG(); state = get_operstate(*argv); if (state < 0) - invarg("Invalid operstate\n", *argv); - + invarg_1_to_2(*argv, "state"); addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state); } else if (matches(*argv, "numtxqueues") == 0) { NEXT_ARG(); if (numtxqueues != -1) duparg("numtxqueues", *argv); if (get_integer(&numtxqueues, *argv, 0)) - invarg("Invalid \"numtxqueues\" value\n", *argv); + invarg_1_to_2(*argv, "numtxqueues"); addattr_l(&req->n, sizeof(*req), IFLA_NUM_TX_QUEUES, &numtxqueues, 4); } else if (matches(*argv, "numrxqueues") == 0) { @@ -673,7 +672,7 @@ static int do_add_or_delete(char **argv, const unsigned rtm) if (numrxqueues != -1) duparg("numrxqueues", *argv); if (get_integer(&numrxqueues, *argv, 0)) - invarg("Invalid \"numrxqueues\" value\n", *argv); + invarg_1_to_2(*argv, "numrxqueues"); addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES, &numrxqueues, 4); } @@ -687,7 +686,7 @@ int FAST_FUNC do_iplink(char **argv) if (*argv) { int key = index_in_substrings(keywords, *argv); if (key < 0) /* invalid argument */ - invarg(*argv, applet_name); + invarg_1_to_2(*argv, applet_name); argv++; if (key <= 1) /* add/delete */ return do_add_or_delete(argv, key ? RTM_DELLINK : RTM_NEWLINK); diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c index 03a15d845..6588c12f1 100644 --- a/networking/libiproute/ipneigh.c +++ b/networking/libiproute/ipneigh.c @@ -75,7 +75,7 @@ static unsigned nud_state_a2n(char *arg) id = index_in_substrings(keywords, arg); if (id < 0) - bb_error_msg_and_die(bb_msg_invalid_arg, arg, "nud state"); + bb_error_msg_and_die(bb_msg_invalid_arg_to, arg, "nud state"); return nuds[id]; } @@ -281,9 +281,9 @@ static int FAST_FUNC ipneigh_list_or_flush(char **argv, int flush) ll_init_map(&rth); if (filter_dev) { - if ((G_filter.index = xll_name_to_index(filter_dev)) == 0) { - bb_error_msg_and_die(bb_msg_invalid_arg, - filter_dev, "Cannot find device"); + G_filter.index = xll_name_to_index(filter_dev); + if (G_filter.index == 0) { + bb_error_msg_and_die("can't find device '%s'", filter_dev); } } @@ -349,6 +349,6 @@ int FAST_FUNC do_ipneigh(char **argv) case 1: /* flush */ return ipneigh_list_or_flush(argv + 1, 1); } - invarg(*argv, applet_name); + invarg_1_to_2(*argv, applet_name); return 1; } diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index f7209b126..0d2914405 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -403,7 +403,7 @@ IF_FEATURE_IP_RULE(ARG_table,) uint32_t prot; NEXT_ARG(); if (rtnl_rtprot_a2n(&prot, *argv)) - invarg(*argv, "protocol"); + invarg_1_to_2(*argv, "protocol"); req.r.rtm_protocol = prot; ok |= proto_ok; #if ENABLE_FEATURE_IP_RULE @@ -411,7 +411,7 @@ IF_FEATURE_IP_RULE(ARG_table,) uint32_t tid; NEXT_ARG(); if (rtnl_rttable_a2n(&tid, *argv)) - invarg(*argv, "table"); + invarg_1_to_2(*argv, "table"); req.r.rtm_table = tid; #endif } else if (arg == ARG_dev || arg == ARG_oif) { @@ -597,7 +597,7 @@ static int iproute_list_or_flush(char **argv, int flush) //G_filter.protocolmask = -1; if (rtnl_rtprot_a2n(&prot, *argv)) { if (index_in_strings(keywords, *argv) != KW_all) - invarg(*argv, "protocol"); + invarg_1_to_2(*argv, "protocol"); prot = 0; //G_filter.protocolmask = 0; } @@ -622,10 +622,10 @@ static int iproute_list_or_flush(char **argv, int flush) #if ENABLE_FEATURE_IP_RULE uint32_t tid; if (rtnl_rttable_a2n(&tid, *argv)) - invarg(*argv, "table"); + invarg_1_to_2(*argv, "table"); G_filter.tb = tid; #else - invarg(*argv, "table"); + invarg_1_to_2(*argv, "table"); #endif } } else if (arg == KW_cache) { @@ -932,7 +932,7 @@ int FAST_FUNC do_iproute(char **argv) case 11: /* flush */ return iproute_list_or_flush(argv+1, 1); default: - invarg(*argv, applet_name); + invarg_1_to_2(*argv, applet_name); } return iproute_modify(cmd, flags, argv+1); diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c index 774a3e220..c3b210982 100644 --- a/networking/libiproute/iprule.c +++ b/networking/libiproute/iprule.c @@ -214,7 +214,7 @@ static int iprule_modify(int cmd, char **argv) while (*argv) { key = index_in_substrings(keywords, *argv) + 1; if (key == 0) /* no match found in keywords array, bail out. */ - invarg(*argv, applet_name); + invarg_1_to_2(*argv, applet_name); if (key == ARG_from) { inet_prefix dst; NEXT_ARG(); @@ -239,7 +239,7 @@ static int iprule_modify(int cmd, char **argv) uint32_t tos; NEXT_ARG(); if (rtnl_dsfield_a2n(&tos, *argv)) - invarg(*argv, "TOS"); + invarg_1_to_2(*argv, "TOS"); req.r.rtm_tos = tos; } else if (key == ARG_fwmark) { uint32_t fwmark; @@ -250,7 +250,7 @@ static int iprule_modify(int cmd, char **argv) uint32_t realm; NEXT_ARG(); if (get_rt_realms(&realm, *argv)) - invarg(*argv, "realms"); + invarg_1_to_2(*argv, "realms"); addattr32(&req.n, sizeof(req), RTA_FLOW, realm); } else if (key == ARG_table || key == ARG_lookup @@ -258,7 +258,7 @@ static int iprule_modify(int cmd, char **argv) uint32_t tid; NEXT_ARG(); if (rtnl_rttable_a2n(&tid, *argv)) - invarg(*argv, "table ID"); + invarg_1_to_2(*argv, "table ID"); req.r.rtm_table = tid; table_ok = 1; } else if (key == ARG_dev || @@ -281,7 +281,7 @@ static int iprule_modify(int cmd, char **argv) if (key == ARG_help) bb_show_usage(); if (rtnl_rtntype_a2n(&type, *argv)) - invarg(*argv, "type"); + invarg_1_to_2(*argv, "type"); req.r.rtm_type = type; } argv++; @@ -309,7 +309,7 @@ int FAST_FUNC do_iprule(char **argv) if (*argv) { int cmd = index_in_substrings(ip_rule_commands, *argv); if (cmd < 0) - invarg(*argv, applet_name); + invarg_1_to_2(*argv, applet_name); argv++; if (cmd < 2) return iprule_modify((cmd == 0) ? RTM_NEWRULE : RTM_DELRULE, argv); diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index a65d5e579..b88c3a401 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c @@ -294,7 +294,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) if (key != ARG_inherit) { uval = get_unsigned(*argv, "TTL"); if (uval > 255) - invarg(*argv, "TTL must be <=255"); + invarg_1_to_2(*argv, "TTL"); p->iph.ttl = uval; } } else if (key == ARG_tos || @@ -305,7 +305,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) key = index_in_strings(keywords, *argv); if (key != ARG_inherit) { if (rtnl_dsfield_a2n(&uval, *argv)) - invarg(*argv, "TOS"); + invarg_1_to_2(*argv, "TOS"); p->iph.tos = uval; } else p->iph.tos = 1; @@ -562,7 +562,7 @@ int FAST_FUNC do_iptunnel(char **argv) if (*argv) { int key = index_in_substrings(keywords, *argv); if (key < 0) - invarg(*argv, applet_name); + invarg_1_to_2(*argv, applet_name); argv++; if (key == ARG_add) return do_add(SIOCADDTUNNEL, argv); diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c index 37b5311f0..7f7cb4203 100644 --- a/networking/libiproute/utils.c +++ b/networking/libiproute/utils.c @@ -47,7 +47,7 @@ unsigned get_unsigned(char *arg, const char *errmsg) return res; } } - invarg(arg, errmsg); /* does not return */ + invarg_1_to_2(arg, errmsg); /* does not return */ } uint32_t get_u32(char *arg, const char *errmsg) @@ -62,7 +62,7 @@ uint32_t get_u32(char *arg, const char *errmsg) return res; } } - invarg(arg, errmsg); /* does not return */ + invarg_1_to_2(arg, errmsg); /* does not return */ } uint16_t get_u16(char *arg, const char *errmsg) @@ -77,7 +77,7 @@ uint16_t get_u16(char *arg, const char *errmsg) return res; } } - invarg(arg, errmsg); /* does not return */ + invarg_1_to_2(arg, errmsg); /* does not return */ } int get_addr_1(inet_prefix *addr, char *name, int family) @@ -230,12 +230,12 @@ uint32_t get_addr32(char *name) void incomplete_command(void) { - bb_error_msg_and_die("command line is not complete, try option \"help\""); + bb_error_msg_and_die("command line is not complete, try \"help\""); } -void invarg(const char *arg, const char *opt) +void invarg_1_to_2(const char *arg, const char *opt) { - bb_error_msg_and_die(bb_msg_invalid_arg, arg, opt); + bb_error_msg_and_die(bb_msg_invalid_arg_to, arg, opt); } void duparg(const char *key, const char *arg) diff --git a/networking/libiproute/utils.h b/networking/libiproute/utils.h index cd15b706b..9bbed6481 100644 --- a/networking/libiproute/utils.h +++ b/networking/libiproute/utils.h @@ -74,7 +74,7 @@ extern const char *format_host(int af, int len, void *addr, char *buf, int bufle rt_addr_n2a(af, addr, buf, buflen) #endif -void invarg(const char *, const char *) NORETURN; +void invarg_1_to_2(const char *, const char *) NORETURN; void duparg(const char *, const char *) NORETURN; void duparg2(const char *, const char *) NORETURN; int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits); diff --git a/networking/slattach.c b/networking/slattach.c index a500da6d0..14e0c1941 100644 --- a/networking/slattach.c +++ b/networking/slattach.c @@ -27,7 +27,7 @@ //usage: "\n -F Disable RTS/CTS flow control" #include "libbb.h" -#include "libiproute/utils.h" /* invarg() */ +#include "libiproute/utils.h" /* invarg_1_to_2() */ struct globals { int handle; @@ -175,7 +175,7 @@ int slattach_main(int argc UNUSED_PARAM, char **argv) encap = index_in_strings(proto_names, proto); if (encap < 0) - invarg(proto, "protocol"); + invarg_1_to_2(proto, "protocol"); if (encap > 3) encap = 8; @@ -183,7 +183,7 @@ int slattach_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_s_baud) { baud_code = tty_value_to_baud(xatoi(baud_str)); if (baud_code < 0) - invarg(baud_str, "baud rate"); + invarg_1_to_2(baud_str, "baud rate"); } /* Trap signals in order to restore tty states upon exit */ diff --git a/networking/tc.c b/networking/tc.c index 6d1fef993..c84c18a67 100644 --- a/networking/tc.c +++ b/networking/tc.c @@ -459,14 +459,14 @@ int tc_main(int argc UNUSED_PARAM, char **argv) obj = index_in_substrings(objects, *argv++); - if (obj < OBJ_qdisc) + if (obj < 0) bb_show_usage(); if (!*argv) cmd = CMD_show; /* list is the default */ else { cmd = index_in_substrings(commands, *argv); if (cmd < 0) - bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); + invarg_1_to_2(*argv, argv[-1]); argv++; } memset(&msg, 0, sizeof(msg)); @@ -489,7 +489,7 @@ int tc_main(int argc UNUSED_PARAM, char **argv) NEXT_ARG(); /* We don't care about duparg2("qdisc handle",*argv) for now */ if (get_qdisc_handle(&filter_qdisc, *argv)) - invarg(*argv, "qdisc"); + invarg_1_to_2(*argv, "qdisc"); } else if (obj != OBJ_qdisc && (arg == ARG_root @@ -499,7 +499,7 @@ int tc_main(int argc UNUSED_PARAM, char **argv) ) { /* nothing */ } else { - invarg(*argv, "command"); + invarg_1_to_2(*argv, "command"); } NEXT_ARG(); if (arg == ARG_root) { @@ -513,7 +513,7 @@ int tc_main(int argc UNUSED_PARAM, char **argv) if (msg.tcm_parent) duparg(*argv, "parent"); if (get_tc_classid(&handle, *argv)) - invarg(*argv, "parent"); + invarg_1_to_2(*argv, "parent"); msg.tcm_parent = handle; if (obj == OBJ_filter) filter_parent = handle; @@ -538,7 +538,7 @@ int tc_main(int argc UNUSED_PARAM, char **argv) if (filter_proto) duparg(*argv, "protocol"); if (ll_proto_a2n(&tmp, *argv)) - invarg(*argv, "protocol"); + invarg_1_to_2(*argv, "protocol"); filter_proto = tmp; } } -- cgit v1.2.3-55-g6feb From 926d801fa51717b3af3faf33f9d686e92a20ecfd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 14 Oct 2015 13:56:42 +0200 Subject: libiproute: make rt_addr_n2a() and format_host() return auto strings function old new delta rt_addr_n2a 56 53 -3 print_addrinfo 1227 1178 -49 print_neigh 933 881 -52 print_rule 689 617 -72 print_tunnel 640 560 -80 print_route 1727 1588 -139 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-395) Total: -395 bytes Signed-off-by: Denys Vlasenko --- networking/libiproute/ipaddress.c | 22 +++++++++------------- networking/libiproute/ipneigh.c | 5 ++--- networking/libiproute/iproute.c | 36 +++++++++++++++--------------------- networking/libiproute/iprule.c | 19 +++++++------------ networking/libiproute/iptunnel.c | 28 +++++++++++++--------------- networking/libiproute/utils.c | 14 +++++++------- networking/libiproute/utils.h | 8 ++++---- 7 files changed, 57 insertions(+), 75 deletions(-) diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index c0f27c70d..5c975d8c5 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -214,8 +214,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, { struct ifaddrmsg *ifa = NLMSG_DATA(n); int len = n->nlmsg_len; - struct rtattr * rta_tb[IFA_MAX+1]; - char abuf[256]; + struct rtattr *rta_tb[IFA_MAX+1]; if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR) return 0; @@ -291,9 +290,9 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, printf(" family %d ", ifa->ifa_family); if (rta_tb[IFA_LOCAL]) { - fputs(rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_LOCAL]), - abuf, sizeof(abuf)), stdout); + fputs(rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_LOCAL])), + stdout + ); if (rta_tb[IFA_ADDRESS] == NULL || memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0 @@ -301,25 +300,22 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, printf("/%d ", ifa->ifa_prefixlen); } else { printf(" peer %s/%d ", - rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_ADDRESS]), - abuf, sizeof(abuf)), - ifa->ifa_prefixlen); + rt_addr_n2a(ifa->ifa_family, RTA_DATA(rta_tb[IFA_ADDRESS])), + ifa->ifa_prefixlen + ); } } if (rta_tb[IFA_BROADCAST]) { printf("brd %s ", rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_BROADCAST]), - abuf, sizeof(abuf)) + RTA_DATA(rta_tb[IFA_BROADCAST])) ); } if (rta_tb[IFA_ANYCAST]) { printf("any %s ", rt_addr_n2a(ifa->ifa_family, - RTA_DATA(rta_tb[IFA_ANYCAST]), - abuf, sizeof(abuf)) + RTA_DATA(rta_tb[IFA_ANYCAST])) ); } printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope)); diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c index 6588c12f1..179505c2d 100644 --- a/networking/libiproute/ipneigh.c +++ b/networking/libiproute/ipneigh.c @@ -91,7 +91,6 @@ static int FAST_FUNC print_neigh(const struct sockaddr_nl *who UNUSED_PARAM, struct ndmsg *r = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr *tb[NDA_MAX+1]; - char abuf[256]; if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) { bb_error_msg_and_die("not RTM_NEWNEIGH: %08x %08x %08x", @@ -155,8 +154,8 @@ static int FAST_FUNC print_neigh(const struct sockaddr_nl *who UNUSED_PARAM, printf("%s ", format_host(r->ndm_family, RTA_PAYLOAD(tb[NDA_DST]), - RTA_DATA(tb[NDA_DST]), - abuf, sizeof(abuf))); + RTA_DATA(tb[NDA_DST])) + ); } if (!G_filter.index && r->ndm_ifindex) printf("dev %s ", ll_index_to_name(r->ndm_ifindex)); diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 0d2914405..d232ee6fd 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -61,7 +61,6 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, struct rtmsg *r = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr *tb[RTA_MAX+1]; - char abuf[256]; inet_prefix dst; inet_prefix src; int host_len = -1; @@ -218,17 +217,15 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, if (tb[RTA_DST]) { if (r->rtm_dst_len != host_len) { - printf("%s/%u ", rt_addr_n2a(r->rtm_family, - RTA_DATA(tb[RTA_DST]), - abuf, sizeof(abuf)), - r->rtm_dst_len - ); + printf("%s/%u ", + rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_DST])), + r->rtm_dst_len + ); } else { printf("%s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_DST]), - RTA_DATA(tb[RTA_DST]), - abuf, sizeof(abuf)) - ); + RTA_DATA(tb[RTA_DST])) + ); } } else if (r->rtm_dst_len) { printf("0/%d ", r->rtm_dst_len); @@ -237,17 +234,15 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, } if (tb[RTA_SRC]) { if (r->rtm_src_len != host_len) { - printf("from %s/%u ", rt_addr_n2a(r->rtm_family, - RTA_DATA(tb[RTA_SRC]), - abuf, sizeof(abuf)), - r->rtm_src_len - ); + printf("from %s/%u ", + rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])), + r->rtm_src_len + ); } else { printf("from %s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_SRC]), - RTA_DATA(tb[RTA_SRC]), - abuf, sizeof(abuf)) - ); + RTA_DATA(tb[RTA_SRC])) + ); } } else if (r->rtm_src_len) { printf("from 0/%u ", r->rtm_src_len); @@ -255,8 +250,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, if (tb[RTA_GATEWAY] && G_filter.rvia.bitlen != host_len) { printf("via %s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_GATEWAY]), - RTA_DATA(tb[RTA_GATEWAY]), - abuf, sizeof(abuf))); + RTA_DATA(tb[RTA_GATEWAY])) + ); } if (tb[RTA_OIF]) { printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); @@ -269,8 +264,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM, and symbolic name will not be useful. */ printf(" src %s ", rt_addr_n2a(r->rtm_family, - RTA_DATA(tb[RTA_PREFSRC]), - abuf, sizeof(abuf))); + RTA_DATA(tb[RTA_PREFSRC]))); } if (tb[RTA_PRIORITY]) { printf(" metric %d ", *(uint32_t*)RTA_DATA(tb[RTA_PRIORITY])); diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c index c3b210982..dba64346f 100644 --- a/networking/libiproute/iprule.c +++ b/networking/libiproute/iprule.c @@ -44,7 +44,6 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM, int len = n->nlmsg_len; int host_len = -1; struct rtattr * tb[RTA_MAX+1]; - char abuf[256]; if (n->nlmsg_type != RTM_NEWRULE) return 0; @@ -71,16 +70,14 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM, printf("from "); if (tb[RTA_SRC]) { if (r->rtm_src_len != host_len) { - printf("%s/%u", rt_addr_n2a(r->rtm_family, - RTA_DATA(tb[RTA_SRC]), - abuf, sizeof(abuf)), + printf("%s/%u", + rt_addr_n2a(r->rtm_family, RTA_DATA(tb[RTA_SRC])), r->rtm_src_len ); } else { fputs(format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_SRC]), - RTA_DATA(tb[RTA_SRC]), - abuf, sizeof(abuf)), + RTA_DATA(tb[RTA_SRC])), stdout ); } @@ -94,15 +91,13 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM, if (tb[RTA_DST]) { if (r->rtm_dst_len != host_len) { printf("to %s/%u ", rt_addr_n2a(r->rtm_family, - RTA_DATA(tb[RTA_DST]), - abuf, sizeof(abuf)), + RTA_DATA(tb[RTA_DST])), r->rtm_dst_len ); } else { printf("to %s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_DST]), - RTA_DATA(tb[RTA_DST]), - abuf, sizeof(abuf))); + RTA_DATA(tb[RTA_DST]))); } } else if (r->rtm_dst_len) { printf("to 0/%d ", r->rtm_dst_len); @@ -139,8 +134,8 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM, printf("map-to %s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_GATEWAY]), - RTA_DATA(tb[RTA_GATEWAY]), - abuf, sizeof(abuf))); + RTA_DATA(tb[RTA_GATEWAY])) + ); } else printf("masquerade"); } else if (r->rtm_type != RTN_UNICAST) diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index b88c3a401..eb136e435 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c @@ -404,22 +404,18 @@ static int do_del(char **argv) static void print_tunnel(struct ip_tunnel_parm *p) { - char s1[256]; - char s2[256]; - char s3[64]; - char s4[64]; - - format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)); - format_host(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)); - inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3)); - inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4)); + char s3[INET_ADDRSTRLEN]; + char s4[INET_ADDRSTRLEN]; printf("%s: %s/ip remote %s local %s ", - p->name, - p->iph.protocol == IPPROTO_IPIP ? "ip" : - (p->iph.protocol == IPPROTO_GRE ? "gre" : - (p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : "unknown")), - p->iph.daddr ? s1 : "any", p->iph.saddr ? s2 : "any"); + p->name, + p->iph.protocol == IPPROTO_IPIP ? "ip" : + p->iph.protocol == IPPROTO_GRE ? "gre" : + p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : + "unknown", + p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr) : "any", + p->iph.saddr ? format_host(AF_INET, 4, &p->iph.saddr) : "any" + ); if (p->link) { char *n = do_ioctl_get_ifname(p->link); if (n) { @@ -442,9 +438,11 @@ static void print_tunnel(struct ip_tunnel_parm *p) if (!(p->iph.frag_off & htons(IP_DF))) printf(" nopmtudisc"); + inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3)); + inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4)); if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key) printf(" key %s", s3); - else if ((p->i_flags | p->o_flags) & GRE_KEY) { + else { if (p->i_flags & GRE_KEY) printf(" ikey %s ", s3); if (p->o_flags & GRE_KEY) diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c index 7f7cb4203..42025bc66 100644 --- a/networking/libiproute/utils.c +++ b/networking/libiproute/utils.c @@ -276,20 +276,21 @@ int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits) return 0; } -const char *rt_addr_n2a(int af, - void *addr, char *buf, int buflen) +const char *rt_addr_n2a(int af, void *addr) { switch (af) { case AF_INET: case AF_INET6: - return inet_ntop(af, addr, buf, buflen); + return inet_ntop(af, addr, + auto_string(xzalloc(INET6_ADDRSTRLEN)), INET6_ADDRSTRLEN + ); default: return "???"; } } #ifdef RESOLVE_HOSTNAMES -const char *format_host(int af, int len, void *addr, char *buf, int buflen) +const char *format_host(int af, int len, void *addr) { if (resolve_hosts) { struct hostent *h_ent; @@ -308,11 +309,10 @@ const char *format_host(int af, int len, void *addr, char *buf, int buflen) if (len > 0) { h_ent = gethostbyaddr(addr, len, af); if (h_ent != NULL) { - safe_strncpy(buf, h_ent->h_name, buflen); - return buf; + return auto_string(xstrdup(h_ent->h_name)); } } } - return rt_addr_n2a(af, addr, buf, buflen); + return rt_addr_n2a(af, addr); } #endif diff --git a/networking/libiproute/utils.h b/networking/libiproute/utils.h index 9bbed6481..408d5f65f 100644 --- a/networking/libiproute/utils.h +++ b/networking/libiproute/utils.h @@ -66,12 +66,12 @@ extern unsigned get_unsigned(char *arg, const char *errmsg); extern uint32_t get_u32(char *arg, const char *errmsg); extern uint16_t get_u16(char *arg, const char *errmsg); -extern const char *rt_addr_n2a(int af, void *addr, char *buf, int buflen); +extern const char *rt_addr_n2a(int af, void *addr); #ifdef RESOLVE_HOSTNAMES -extern const char *format_host(int af, int len, void *addr, char *buf, int buflen); +extern const char *format_host(int af, int len, void *addr); #else -#define format_host(af, len, addr, buf, buflen) \ - rt_addr_n2a(af, addr, buf, buflen) +#define format_host(af, len, addr) \ + rt_addr_n2a(af, addr) #endif void invarg_1_to_2(const char *, const char *) NORETURN; -- cgit v1.2.3-55-g6feb From 4ad702c0a70628ce7574609087e50b0ce40455d6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 14 Oct 2015 22:29:52 +0200 Subject: top: make sort field for 's' mode less confusing function old new delta display_topmem_process_list 542 565 +23 Signed-off-by: Denys Vlasenko --- procps/top.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/procps/top.c b/procps/top.c index 9a3f171ac..ddf794d7d 100644 --- a/procps/top.c +++ b/procps/top.c @@ -829,10 +829,17 @@ static NOINLINE void display_topmem_process_list(int lines_rem, int scr_width) #define HDR_STR " PID VSZ VSZRW RSS (SHR) DIRTY (SHR) STACK" #define MIN_WIDTH sizeof(HDR_STR) const topmem_status_t *s = topmem + G_scroll_ofs; + char *cp, ch; display_topmem_header(scr_width, &lines_rem); + strcpy(line_buf, HDR_STR " COMMAND"); - line_buf[11 + sort_field * 6] = "^_"[inverted]; + /* Mark the ^FIELD^ we sort by */ + cp = &line_buf[5 + sort_field * 6]; + ch = "^_"[inverted]; + cp[6] = ch; + do *cp++ = ch; while (*cp == ' '); + printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf); lines_rem--; @@ -1172,10 +1179,8 @@ int top_main(int argc UNUSED_PARAM, char **argv) ntop = 0; while ((p = procps_scan(p, scan_mask)) != NULL) { int n; -#if ENABLE_FEATURE_TOPMEM - if (scan_mask != TOPMEM_MASK) -#endif - { + + IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) { n = ntop; top = xrealloc_vector(top, 6, ntop++); top[n].pid = p->pid; @@ -1215,7 +1220,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) break; } - if (scan_mask != TOPMEM_MASK) { + IF_FEATURE_TOPMEM(if (scan_mask != TOPMEM_MASK)) { #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE if (!prev_hist_count) { do_stats(); @@ -1229,17 +1234,13 @@ int top_main(int argc UNUSED_PARAM, char **argv) #else qsort(top, ntop, sizeof(top_status_t), (void*)(sort_function[0])); #endif + display_process_list(G.lines, col); } #if ENABLE_FEATURE_TOPMEM else { /* TOPMEM */ qsort(topmem, ntop, sizeof(topmem_status_t), (void*)topmem_sort); - } -#endif - if (scan_mask != TOPMEM_MASK) - display_process_list(G.lines, col); -#if ENABLE_FEATURE_TOPMEM - else display_topmem_process_list(G.lines, col); + } #endif clearmems(); if (iterations >= 0 && !--iterations) @@ -1248,7 +1249,7 @@ int top_main(int argc UNUSED_PARAM, char **argv) sleep(interval); #else scan_mask = handle_input(scan_mask, interval); -#endif /* FEATURE_USE_TERMIOS */ +#endif } /* end of "while (not Q)" */ bb_putchar('\n'); -- cgit v1.2.3-55-g6feb From 5251135bc184bdcb8cbcb964e8c44c6c301bffdc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 15 Oct 2015 02:10:11 +0200 Subject: better pinger service example Signed-off-by: Denys Vlasenko --- examples/var_service/dhcp_if_pinger/run | 44 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/examples/var_service/dhcp_if_pinger/run b/examples/var_service/dhcp_if_pinger/run index 20b2fc516..1868510d1 100755 --- a/examples/var_service/dhcp_if_pinger/run +++ b/examples/var_service/dhcp_if_pinger/run @@ -1,23 +1,47 @@ #!/bin/sh -delay=67 - +# How often to test, seconds +ping_time=67 +# "One ping, must have reply in 1 sec" +ping_opts="-c1 -W1 -w1" +# If ping failed, how soon to retry +retry_time=5 +# Reinit after this many consecutive ping error +max_fail=5 +# Interface whose DHCP data to use if=${PWD##*/dhcp_} if=${if%%_pinger} +msg() { + echo "`date '+%Y-%m-%d %H:%M:%S'` $*" >>"$0.log" +} + if test -f "$0.log"; then tail -999 "$0.log" >"$0.log.new" mv "$0.log.new" "$0.log" fi -test -f "/var/service/dhcp_$if/dhcp_$if.out" || exec env - sleep "$delay" -. "/var/service/dhcp_$if/dhcp_$if.out" -test x"$router" != x"" || exec env - sleep "$delay" +test -f "/var/service/dhcp_$if/dhcp_$if.out" || exec env - sleep "$ping_time" -#echo "`date '+%Y-%m-%d %H:%M:%S'` Testing ping -c3 $router" >>"$0.log" -ping -c3 "$router" && exec env - sleep "$delay" +. "/var/service/dhcp_$if/dhcp_$if.out" +test x"$router" != x"" || exec env - sleep "$ping_time" -echo "`date '+%Y-%m-%d %H:%M:%S'` Restarting /var/service/dhcp_$if" >>"$0.log" -sv t "/var/service/dhcp_$if" +#msg "Pinging $router" +failcnt=0 +while true; do + ping $ping_opts "$router" && exec env - sleep "$ping_time" + : $((failcnt++)) + msg "Failed to ping $router, fail count:$failcnt" + test $failcnt -ge $max_fail && break + env - sleep "$retry_time" +done -exec env - sleep "$delay" +test -d "/var/service/dhcp_$if" && { + msg "Restarting /var/service/dhcp_$if" + sv t "/var/service/dhcp_$if" +} +test -d "/var/service/supplicant_$if" && { + msg "Restarting /var/service/supplicant_$if" + sv t "/var/service/supplicant_$if" +} +exec env - sleep "$ping_time" -- cgit v1.2.3-55-g6feb From 93dd9fd90ae284e7878767fe14bcb17e3edd9cf8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 15 Oct 2015 21:33:34 +0200 Subject: du: extra compat: with -k and -m, round sizes up function old new delta print 36 65 +29 Signed-off-by: Denys Vlasenko --- coreutils/du.c | 37 +++++++++++++++++++++++-------------- libbb/human_readable.c | 11 +++-------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/coreutils/du.c b/coreutils/du.c index 9c6ff8800..1889c16bb 100644 --- a/coreutils/du.c +++ b/coreutils/du.c @@ -75,7 +75,7 @@ enum { struct globals { #if ENABLE_FEATURE_HUMAN_READABLE - unsigned long disp_hr; + unsigned long disp_unit; #else unsigned disp_k; #endif @@ -89,18 +89,27 @@ struct globals { #define INIT_G() do { } while (0) -/* FIXME? coreutils' du rounds sizes up: - * for example, 1025k file is shown as "2" by du -m. - * We round to nearest. - */ static void print(unsigned long long size, const char *filename) { /* TODO - May not want to defer error checking here. */ #if ENABLE_FEATURE_HUMAN_READABLE +# if ENABLE_DESKTOP + /* ~30 bytes of code for extra comtat: + * coreutils' du rounds sizes up: + * for example, 1025k file is shown as "2" by du -m. + * We round to nearest if human-readable [too hard to fix], + * else (fixed scale such as -m), we round up. To that end, + * add yet another half of the unit before displaying: + */ + if (G.disp_unit) + size += (G.disp_unit-1) / (unsigned)(512 * 2); +# endif printf("%s\t%s\n", - /* size x 512 / G.disp_hr, show one fractional, - * use suffixes if G.disp_hr == 0 */ - make_human_readable_str(size, 512, G.disp_hr), + /* size x 512 / G.disp_unit. + * If G.disp_unit == 0, show one fractional + * and use suffixes + */ + make_human_readable_str(size, 512, G.disp_unit), filename); #else if (G.disp_k) { @@ -199,10 +208,10 @@ int du_main(int argc UNUSED_PARAM, char **argv) INIT_G(); #if ENABLE_FEATURE_HUMAN_READABLE - IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;) - IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;) + IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 1024;) + IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 512;) if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */ - G.disp_hr = 512; + G.disp_unit = 512; #else IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;) /* IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */ @@ -220,13 +229,13 @@ int du_main(int argc UNUSED_PARAM, char **argv) opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth); argv += optind; if (opt & OPT_h_for_humans) { - G.disp_hr = 0; + G.disp_unit = 0; } if (opt & OPT_m_mbytes) { - G.disp_hr = 1024*1024; + G.disp_unit = 1024*1024; } if (opt & OPT_k_kbytes) { - G.disp_hr = 1024; + G.disp_unit = 1024; } #else opt_complementary = "H-L:L-H:s-d:d-s:d+"; diff --git a/libbb/human_readable.c b/libbb/human_readable.c index 5c7fc076f..b4e0ef181 100644 --- a/libbb/human_readable.c +++ b/libbb/human_readable.c @@ -14,16 +14,11 @@ * representations (say, powers of 1024) and manipulating coefficients. * The base ten "bytes" output could be handled similarly. * - * 2) This routine always outputs a decimal point and a tenths digit when - * display_unit != 0. Hence, it isn't uncommon for the returned string + * 2) This routine outputs a decimal point and a tenths digit when + * display_unit == 0. Hence, it isn't uncommon for the returned string * to have a length of 5 or 6. * - * It might be nice to add a flag to indicate no decimal digits in - * that case. This could be either an additional parameter, or a - * special value of display_unit. Such a flag would also be nice for du. - * - * Some code to omit the decimal point and tenths digit is sketched out - * and "#if 0"'d below. + * If block_size is also 0, no decimal digits are printed. * * Licensed under GPLv2, see file LICENSE in this source tree. */ -- cgit v1.2.3-55-g6feb From 2735bc00e35c5fd8eec6d656f4d8a17ee2630c2a Mon Sep 17 00:00:00 2001 From: Aaro Koskinen Date: Fri, 16 Oct 2015 17:24:46 +0200 Subject: cpio: implement -R/--owner Implement -R/--owner to force ownership of files. function old new delta cpio_main 532 586 +54 get_header_cpio 909 939 +30 print 36 65 +29 cpio_o 804 832 +28 cpio_TRAILER - 11 +11 packed_usage 30667 30662 -5 static.trailer 11 - -11 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 4/1 up/down: 152/-16) Total: 136 bytes Signed-off-by: Aaro Koskinen Signed-off-by: Denys Vlasenko --- archival/Kbuild.src | 2 +- archival/cpio.c | 46 +++++++++++++++++++++++++++-------- archival/libarchive/Kbuild.src | 2 +- archival/libarchive/common.c | 9 +++++++ archival/libarchive/get_header_cpio.c | 7 +++++- coreutils/chown.c | 4 +-- include/bb_archive.h | 3 +++ 7 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 archival/libarchive/common.c diff --git a/archival/Kbuild.src b/archival/Kbuild.src index a6fd2eac0..b3a7d538f 100644 --- a/archival/Kbuild.src +++ b/archival/Kbuild.src @@ -4,7 +4,7 @@ # # Licensed under GPLv2, see file LICENSE in this source tree. -libs-y += libarchive/ +libs-y += libarchive/ lib-y:= diff --git a/archival/cpio.c b/archival/cpio.c index cdc16c14e..82b3fe5ed 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -46,7 +46,7 @@ //kbuild:lib-$(CONFIG_CPIO) += cpio.o //usage:#define cpio_trivial_usage -//usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]") +//usage: "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]") //usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]") //usage: " [EXTR_FILE]..." //usage:#define cpio_full_usage "\n\n" @@ -71,6 +71,7 @@ //usage: "\n -v Verbose" //usage: "\n -u Overwrite" //usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file" +//usage: "\n -R USER[:GRP] Set owner of created files" //usage: IF_FEATURE_CPIO_O( //usage: "\n -H newc Archive format" //usage: ) @@ -130,7 +131,7 @@ -I FILE File to use instead of standard input -L, --dereference Dereference symbolic links (copy the files that they point to instead of copying the links) - -R, --owner=[USER][:.][GROUP] Set owner of created files + -R, --owner=[USER][:.][GRP] Set owner of created files Options valid in --extract and --pass-through modes: -d, --make-directories Create leading directories where needed @@ -150,7 +151,8 @@ enum { OPT_PRESERVE_MTIME = (1 << 6), OPT_DEREF = (1 << 7), OPT_FILE = (1 << 8), - OPTBIT_FILE = 8, + OPT_OWNER = (1 << 9), + OPTBIT_OWNER = 9, IF_FEATURE_CPIO_O(OPTBIT_CREATE ,) IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,) IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,) @@ -163,7 +165,17 @@ enum { OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0, }; -#define OPTION_STR "it0uvdmLF:" +#define OPTION_STR "it0uvdmLF:R:" + +struct globals { + struct bb_uidgid_t owner_ugid; +} FIX_ALIASING; +#define G (*(struct globals*)&bb_common_bufsiz1) +void BUG_cpio_globals_too_big(void); +#define INIT_G() do { \ + G.owner_ugid.uid = -1L; \ + G.owner_ugid.gid = -1L; \ +} while (0) #if ENABLE_FEATURE_CPIO_O static off_t cpio_pad4(off_t size) @@ -181,7 +193,6 @@ static off_t cpio_pad4(off_t size) * It's ok to exit instead of return. */ static NOINLINE int cpio_o(void) { - static const char trailer[] ALIGN1 = "TRAILER!!!"; struct name_s { struct name_s *next; char name[1]; @@ -223,6 +234,11 @@ static NOINLINE int cpio_o(void) bb_simple_perror_msg_and_die(name); } + if (G.owner_ugid.uid != (uid_t)-1L) + st.st_uid = G.owner_ugid.uid; + if (G.owner_ugid.gid != (gid_t)-1L) + st.st_gid = G.owner_ugid.gid; + if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode))) st.st_size = 0; /* paranoia */ @@ -275,7 +291,7 @@ static NOINLINE int cpio_o(void) } else { /* If no (more) hardlinks to output, * output "trailer" entry */ - name = trailer; + name = cpio_TRAILER; /* st.st_size == 0 is a must, but for uniformity * in the output, we zero out everything */ memset(&st, 0, sizeof(st)); @@ -323,7 +339,7 @@ static NOINLINE int cpio_o(void) } if (!line) { - if (name != trailer) + if (name != cpio_TRAILER) goto next_link; /* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */ return EXIT_SUCCESS; @@ -339,6 +355,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) { archive_handle_t *archive_handle; char *cpio_filename; + char *cpio_owner; IF_FEATURE_CPIO_O(const char *cpio_fmt = "";) unsigned opt; @@ -353,12 +370,14 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) "pass-through\0" No_argument "p" #endif #endif + "owner\0" Required_argument "R" "verbose\0" No_argument "v" "quiet\0" No_argument "\xff" "to-stdout\0" No_argument "\xfe" ; #endif + INIT_G(); archive_handle = init_handle(); /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */ archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER; @@ -369,14 +388,21 @@ int cpio_main(int argc UNUSED_PARAM, char **argv) /* -L makes sense only with -o or -p */ #if !ENABLE_FEATURE_CPIO_O - opt = getopt32(argv, OPTION_STR, &cpio_filename); + opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner); +#else + opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), + &cpio_filename, &cpio_owner, &cpio_fmt); +#endif argv += optind; + if (opt & OPT_OWNER) { /* -R */ + parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner); + archive_handle->cpio__owner = G.owner_ugid; + } +#if !ENABLE_FEATURE_CPIO_O if (opt & OPT_FILE) { /* -F */ xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO); } #else - opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt); - argv += optind; if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */ xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO); } diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src index b7faaf77f..b159a786a 100644 --- a/archival/libarchive/Kbuild.src +++ b/archival/libarchive/Kbuild.src @@ -4,7 +4,7 @@ # # Licensed under GPLv2 or later, see file LICENSE in this source tree. -lib-y:= +lib-y:= common.o COMMON_FILES:= \ \ diff --git a/archival/libarchive/common.c b/archival/libarchive/common.c new file mode 100644 index 000000000..dd69d2222 --- /dev/null +++ b/archival/libarchive/common.c @@ -0,0 +1,9 @@ +/* vi: set sw=4 ts=4: */ +/* + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ + +#include "libbb.h" +#include "bb_archive.h" + +const char cpio_TRAILER[] = "TRAILER!!!"; diff --git a/archival/libarchive/get_header_cpio.c b/archival/libarchive/get_header_cpio.c index 7861d1f6f..badd4a841 100644 --- a/archival/libarchive/get_header_cpio.c +++ b/archival/libarchive/get_header_cpio.c @@ -52,6 +52,11 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) &major, &minor, &namesize) != 10) bb_error_msg_and_die("damaged cpio file"); file_header->mode = mode; + /* "cpio -R USER:GRP" support: */ + if (archive_handle->cpio__owner.uid != (uid_t)-1L) + uid = archive_handle->cpio__owner.uid; + if (archive_handle->cpio__owner.gid != (gid_t)-1L) + gid = archive_handle->cpio__owner.gid; file_header->uid = uid; file_header->gid = gid; file_header->mtime = mtime; @@ -75,7 +80,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) /* Update offset amount and skip padding before file contents */ data_align(archive_handle, 4); - if (strcmp(file_header->name, "TRAILER!!!") == 0) { + if (strcmp(file_header->name, cpio_TRAILER) == 0) { /* Always round up. ">> 9" divides by 512 */ archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9; goto create_hardlinks; diff --git a/coreutils/chown.c b/coreutils/chown.c index 679c0d832..eaa1ee2a3 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -11,9 +11,9 @@ /* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */ //usage:#define chown_trivial_usage -//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... OWNER[<.|:>[GROUP]] FILE..." +//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... USER[:[GRP]] FILE..." //usage:#define chown_full_usage "\n\n" -//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n" +//usage: "Change the owner and/or group of each FILE to USER and/or GRP\n" //usage: "\n -R Recurse" //usage: "\n -h Affect symlinks instead of symlink targets" //usage: IF_DESKTOP( diff --git a/include/bb_archive.h b/include/bb_archive.h index 5d9e24c17..2329d025d 100644 --- a/include/bb_archive.h +++ b/include/bb_archive.h @@ -95,6 +95,7 @@ typedef struct archive_handle_t { #endif #if ENABLE_CPIO || ENABLE_RPM2CPIO || ENABLE_RPM uoff_t cpio__blocks; + struct bb_uidgid_t cpio__owner; struct hardlinks_t *cpio__hardlinks_to_create; struct hardlinks_t *cpio__created_hardlinks; #endif @@ -159,6 +160,8 @@ struct BUG_tar_header { }; +extern const char cpio_TRAILER[]; + archive_handle_t *init_handle(void) FAST_FUNC; -- cgit v1.2.3-55-g6feb From d34f300db6d7a726759f4d820a61f19eacf11288 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 18 Oct 2015 18:42:03 +0200 Subject: sysklogd/*: convert to new-style "one file" applets Signed-off-by: Denys Vlasenko --- include/applets.src.h | 4 -- sysklogd/Config.src | 159 -------------------------------------------------- sysklogd/Kbuild.src | 4 -- sysklogd/klogd.c | 33 +++++++++++ sysklogd/logger.c | 13 +++++ sysklogd/logread.c | 25 ++++++++ sysklogd/syslogd.c | 101 ++++++++++++++++++++++++++++++++ 7 files changed, 172 insertions(+), 167 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index dac83e7fb..c1b8017d4 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -201,7 +201,6 @@ IF_KBD_MODE(APPLET(kbd_mode, BB_DIR_BIN, BB_SUID_DROP)) IF_KILL(APPLET(kill, BB_DIR_BIN, BB_SUID_DROP)) IF_KILLALL(APPLET_ODDNAME(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall)) IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5)) -IF_KLOGD(APPLET(klogd, BB_DIR_SBIN, BB_SUID_DROP)) IF_LAST(APPLET(last, BB_DIR_USR_BIN, BB_SUID_DROP)) //IF_LENGTH(APPLET_NOFORK(length, length, BB_DIR_USR_BIN, BB_SUID_DROP, length)) IF_LESS(APPLET(less, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -211,11 +210,9 @@ IF_LN(APPLET_NOEXEC(ln, ln, BB_DIR_BIN, BB_SUID_DROP, ln)) IF_LOAD_POLICY(APPLET(load_policy, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_LOADKMAP(APPLET(loadkmap, BB_DIR_SBIN, BB_SUID_DROP)) -IF_LOGGER(APPLET(logger, BB_DIR_USR_BIN, BB_SUID_DROP)) /* Needs to be run by root or be suid root - needs to change uid and gid: */ IF_LOGIN(APPLET(login, BB_DIR_BIN, BB_SUID_REQUIRE)) IF_LOGNAME(APPLET_NOFORK(logname, logname, BB_DIR_USR_BIN, BB_SUID_DROP, logname)) -IF_LOGREAD(APPLET(logread, BB_DIR_SBIN, BB_SUID_DROP)) IF_LOSETUP(APPLET(losetup, BB_DIR_SBIN, BB_SUID_DROP)) IF_LPD(APPLET(lpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_LPQ(APPLET_ODDNAME(lpq, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpq)) @@ -338,7 +335,6 @@ IF_SWAPONOFF(APPLET_ODDNAME(swapoff, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swa IF_SWAPONOFF(APPLET_ODDNAME(swapon, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapon)) IF_SWITCH_ROOT(APPLET(switch_root, BB_DIR_SBIN, BB_SUID_DROP)) IF_BB_SYSCTL(APPLET(sysctl, BB_DIR_SBIN, BB_SUID_DROP)) -IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP)) IF_TAC(APPLET_NOEXEC(tac, tac, BB_DIR_USR_BIN, BB_SUID_DROP, tac)) IF_TAIL(APPLET(tail, BB_DIR_USR_BIN, BB_SUID_DROP)) /* IF_TC(APPLET(tc, BB_DIR_SBIN, BB_SUID_DROP)) */ diff --git a/sysklogd/Config.src b/sysklogd/Config.src index fcf993054..684e7d414 100644 --- a/sysklogd/Config.src +++ b/sysklogd/Config.src @@ -7,163 +7,4 @@ menu "System Logging Utilities" INSERT -config SYSLOGD - bool "syslogd" - default y - help - The syslogd utility is used to record logs of all the - significant events that occur on a system. Every - message that is logged records the date and time of the - event, and will generally also record the name of the - application that generated the message. When used in - conjunction with klogd, messages from the Linux kernel - can also be recorded. This is terribly useful, - especially for finding what happened when something goes - wrong. And something almost always will go wrong if - you wait long enough.... - -config FEATURE_ROTATE_LOGFILE - bool "Rotate message files" - default y - depends on SYSLOGD - help - This enables syslogd to rotate the message files - on his own. No need to use an external rotatescript. - -config FEATURE_REMOTE_LOG - bool "Remote Log support" - default y - depends on SYSLOGD - help - When you enable this feature, the syslogd utility can - be used to send system log messages to another system - connected via a network. This allows the remote - machine to log all the system messages, which can be - terribly useful for reducing the number of serial - cables you use. It can also be a very good security - measure to prevent system logs from being tampered with - by an intruder. - -config FEATURE_SYSLOGD_DUP - bool "Support -D (drop dups) option" - default y - depends on SYSLOGD - help - Option -D instructs syslogd to drop consecutive messages - which are totally the same. - -config FEATURE_SYSLOGD_CFG - bool "Support syslog.conf" - default y - depends on SYSLOGD - help - Supports restricted syslogd config. See docs/syslog.conf.txt - -config FEATURE_SYSLOGD_READ_BUFFER_SIZE - int "Read buffer size in bytes" - default 256 - range 256 20000 - depends on SYSLOGD - help - This option sets the size of the syslog read buffer. - Actual memory usage increases around five times the - change done here. - -config FEATURE_IPC_SYSLOG - bool "Circular Buffer support" - default y - depends on SYSLOGD - help - When you enable this feature, the syslogd utility will - use a circular buffer to record system log messages. - When the buffer is filled it will continue to overwrite - the oldest messages. This can be very useful for - systems with little or no permanent storage, since - otherwise system logs can eventually fill up your - entire filesystem, which may cause your system to - break badly. - -config FEATURE_IPC_SYSLOG_BUFFER_SIZE - int "Circular buffer size in Kbytes (minimum 4KB)" - default 16 - range 4 2147483647 - depends on FEATURE_IPC_SYSLOG - help - This option sets the size of the circular buffer - used to record system log messages. - -config LOGREAD - bool "logread" - default y - depends on FEATURE_IPC_SYSLOG - help - If you enabled Circular Buffer support, you almost - certainly want to enable this feature as well. This - utility will allow you to read the messages that are - stored in the syslogd circular buffer. - -config FEATURE_LOGREAD_REDUCED_LOCKING - bool "Double buffering" - default y - depends on LOGREAD - help - 'logread' ouput to slow serial terminals can have - side effects on syslog because of the semaphore. - This option make logread to double buffer copy - from circular buffer, minimizing semaphore - contention at some minor memory expense. - -config FEATURE_KMSG_SYSLOG - bool "Linux kernel printk buffer support" - default y - depends on SYSLOGD - select PLATFORM_LINUX - help - When you enable this feature, the syslogd utility will - write system log message to the Linux kernel's printk buffer. - This can be used as a smaller alternative to the syslogd IPC - support, as klogd and logread aren't needed. - - NOTICE: Syslog facilities in log entries needs kernel 3.5+. - -config KLOGD - bool "klogd" - default y - help - klogd is a utility which intercepts and logs all - messages from the Linux kernel and sends the messages - out to the 'syslogd' utility so they can be logged. If - you wish to record the messages produced by the kernel, - you should enable this option. - -comment "klogd should not be used together with syslog to kernel printk buffer" - depends on KLOGD && FEATURE_KMSG_SYSLOG - -config FEATURE_KLOGD_KLOGCTL - bool "Use the klogctl() interface" - default y - depends on KLOGD - select PLATFORM_LINUX - help - The klogd applet supports two interfaces for reading - kernel messages. Linux provides the klogctl() interface - which allows reading messages from the kernel ring buffer - independently from the file system. - - If you answer 'N' here, klogd will use the more portable - approach of reading them from /proc or a device node. - However, this method requires the file to be available. - - If in doubt, say 'Y'. - -config LOGGER - bool "logger" - default y - select FEATURE_SYSLOG - help - The logger utility allows you to send arbitrary text - messages to the system log (i.e. the 'syslogd' utility) so - they can be logged. This is generally used to help locate - problems that occur within programs and scripts. - endmenu diff --git a/sysklogd/Kbuild.src b/sysklogd/Kbuild.src index d386cc291..6b4fb7470 100644 --- a/sysklogd/Kbuild.src +++ b/sysklogd/Kbuild.src @@ -7,7 +7,3 @@ lib-y:= INSERT -lib-$(CONFIG_KLOGD) += klogd.o -lib-$(CONFIG_LOGGER) += syslogd_and_logger.o -lib-$(CONFIG_LOGREAD) += logread.o -lib-$(CONFIG_SYSLOGD) += syslogd_and_logger.o diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 432ded153..ca8b848bd 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -16,6 +16,39 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config KLOGD +//config: bool "klogd" +//config: default y +//config: help +//config: klogd is a utility which intercepts and logs all +//config: messages from the Linux kernel and sends the messages +//config: out to the 'syslogd' utility so they can be logged. If +//config: you wish to record the messages produced by the kernel, +//config: you should enable this option. +//config: +//config:comment "klogd should not be used together with syslog to kernel printk buffer" +//config: depends on KLOGD && FEATURE_KMSG_SYSLOG +//config: +//config:config FEATURE_KLOGD_KLOGCTL +//config: bool "Use the klogctl() interface" +//config: default y +//config: depends on KLOGD +//config: select PLATFORM_LINUX +//config: help +//config: The klogd applet supports two interfaces for reading +//config: kernel messages. Linux provides the klogctl() interface +//config: which allows reading messages from the kernel ring buffer +//config: independently from the file system. +//config: +//config: If you answer 'N' here, klogd will use the more portable +//config: approach of reading them from /proc or a device node. +//config: However, this method requires the file to be available. +//config: +//config: If in doubt, say 'Y'. + +//applet:IF_KLOGD(APPLET(klogd, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_KLOGD) += klogd.o //usage:#define klogd_trivial_usage //usage: "[-c N] [-n]" diff --git a/sysklogd/logger.c b/sysklogd/logger.c index 5a7027731..b3ca85703 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c @@ -6,6 +6,19 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config LOGGER +//config: bool "logger" +//config: default y +//config: select FEATURE_SYSLOG +//config: help +//config: The logger utility allows you to send arbitrary text +//config: messages to the system log (i.e. the 'syslogd' utility) so +//config: they can be logged. This is generally used to help locate +//config: problems that occur within programs and scripts. + +//applet:IF_LOGGER(APPLET(logger, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_LOGGER) += syslogd_and_logger.o //usage:#define logger_trivial_usage //usage: "[OPTIONS] [MESSAGE]" diff --git a/sysklogd/logread.c b/sysklogd/logread.c index da4a4d4df..781a603b2 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c @@ -8,6 +8,31 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config LOGREAD +//config: bool "logread" +//config: default y +//config: depends on FEATURE_IPC_SYSLOG +//config: help +//config: If you enabled Circular Buffer support, you almost +//config: certainly want to enable this feature as well. This +//config: utility will allow you to read the messages that are +//config: stored in the syslogd circular buffer. +//config: +//config:config FEATURE_LOGREAD_REDUCED_LOCKING +//config: bool "Double buffering" +//config: default y +//config: depends on LOGREAD +//config: help +//config: 'logread' ouput to slow serial terminals can have +//config: side effects on syslog because of the semaphore. +//config: This option make logread to double buffer copy +//config: from circular buffer, minimizing semaphore +//config: contention at some minor memory expense. +//config: + +//applet:IF_LOGREAD(APPLET(logread, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_LOGREAD) += logread.o //usage:#define logread_trivial_usage //usage: "[-fF]" diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index 156f487e5..288b29cf7 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -12,6 +12,107 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config SYSLOGD +//config: bool "syslogd" +//config: default y +//config: help +//config: The syslogd utility is used to record logs of all the +//config: significant events that occur on a system. Every +//config: message that is logged records the date and time of the +//config: event, and will generally also record the name of the +//config: application that generated the message. When used in +//config: conjunction with klogd, messages from the Linux kernel +//config: can also be recorded. This is terribly useful, +//config: especially for finding what happened when something goes +//config: wrong. And something almost always will go wrong if +//config: you wait long enough.... +//config: +//config:config FEATURE_ROTATE_LOGFILE +//config: bool "Rotate message files" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: This enables syslogd to rotate the message files +//config: on his own. No need to use an external rotatescript. +//config: +//config:config FEATURE_REMOTE_LOG +//config: bool "Remote Log support" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: When you enable this feature, the syslogd utility can +//config: be used to send system log messages to another system +//config: connected via a network. This allows the remote +//config: machine to log all the system messages, which can be +//config: terribly useful for reducing the number of serial +//config: cables you use. It can also be a very good security +//config: measure to prevent system logs from being tampered with +//config: by an intruder. +//config: +//config:config FEATURE_SYSLOGD_DUP +//config: bool "Support -D (drop dups) option" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: Option -D instructs syslogd to drop consecutive messages +//config: which are totally the same. +//config: +//config:config FEATURE_SYSLOGD_CFG +//config: bool "Support syslog.conf" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: Supports restricted syslogd config. See docs/syslog.conf.txt +//config: +//config:config FEATURE_SYSLOGD_READ_BUFFER_SIZE +//config: int "Read buffer size in bytes" +//config: default 256 +//config: range 256 20000 +//config: depends on SYSLOGD +//config: help +//config: This option sets the size of the syslog read buffer. +//config: Actual memory usage increases around five times the +//config: change done here. +//config: +//config:config FEATURE_IPC_SYSLOG +//config: bool "Circular Buffer support" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: When you enable this feature, the syslogd utility will +//config: use a circular buffer to record system log messages. +//config: When the buffer is filled it will continue to overwrite +//config: the oldest messages. This can be very useful for +//config: systems with little or no permanent storage, since +//config: otherwise system logs can eventually fill up your +//config: entire filesystem, which may cause your system to +//config: break badly. +//config: +//config:config FEATURE_IPC_SYSLOG_BUFFER_SIZE +//config: int "Circular buffer size in Kbytes (minimum 4KB)" +//config: default 16 +//config: range 4 2147483647 +//config: depends on FEATURE_IPC_SYSLOG +//config: help +//config: This option sets the size of the circular buffer +//config: used to record system log messages. +//config: +//config:config FEATURE_KMSG_SYSLOG +//config: bool "Linux kernel printk buffer support" +//config: default y +//config: depends on SYSLOGD +//config: select PLATFORM_LINUX +//config: help +//config: When you enable this feature, the syslogd utility will +//config: write system log message to the Linux kernel's printk buffer. +//config: This can be used as a smaller alternative to the syslogd IPC +//config: support, as klogd and logread aren't needed. +//config: +//config: NOTICE: Syslog facilities in log entries needs kernel 3.5+. + +//applet:IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_SYSLOGD) += syslogd_and_logger.o //usage:#define syslogd_trivial_usage //usage: "[OPTIONS]" -- cgit v1.2.3-55-g6feb From 000eda41c084bae95d9e40a570cbdaa5ffd3d22e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 18 Oct 2015 22:40:23 +0200 Subject: e2fsprogs/*: convert to new-style "one file" applets Signed-off-by: Denys Vlasenko --- e2fsprogs/Config.src | 28 ---------------------------- e2fsprogs/Kbuild.src | 6 ------ e2fsprogs/chattr.c | 16 ++++++++-------- e2fsprogs/fsck.c | 11 +++++++++++ e2fsprogs/lsattr.c | 16 +++++++++------- e2fsprogs/tune2fs.c | 43 +++++++++++++++++++++++++++---------------- include/applets.src.h | 4 ---- 7 files changed, 55 insertions(+), 69 deletions(-) diff --git a/e2fsprogs/Config.src b/e2fsprogs/Config.src index 743e1e11f..a20d849e6 100644 --- a/e2fsprogs/Config.src +++ b/e2fsprogs/Config.src @@ -7,12 +7,6 @@ menu "Linux Ext2 FS Progs" INSERT -config CHATTR - bool "chattr" - default y - help - chattr changes the file attributes on a second extended file system. - ### config E2FSCK ### bool "e2fsck" ### default y @@ -22,21 +16,6 @@ config CHATTR ### The normal compat symlinks 'fsck.ext2' and 'fsck.ext3' are also ### provided. -config FSCK - bool "fsck" - default y - help - fsck is used to check and optionally repair one or more filesystems. - In actuality, fsck is simply a front-end for the various file system - checkers (fsck.fstype) available under Linux. - -config LSATTR - bool "lsattr" - default y - select PLATFORM_LINUX - help - lsattr lists the file attributes on a second extended file system. - ### config MKE2FS ### bool "mke2fs" ### default y @@ -44,13 +23,6 @@ config LSATTR ### mke2fs is used to create an ext2/ext3 filesystem. The normal compat ### symlinks 'mkfs.ext2' and 'mkfs.ext3' are also provided. -config TUNE2FS - bool "tune2fs" - default n # off: it is too limited compared to upstream version - help - tune2fs allows the system administrator to adjust various tunable - filesystem parameters on Linux ext2/ext3 filesystems. - ### config E2LABEL ### bool "e2label" ### default y diff --git a/e2fsprogs/Kbuild.src b/e2fsprogs/Kbuild.src index b7a14c381..6b4fb7470 100644 --- a/e2fsprogs/Kbuild.src +++ b/e2fsprogs/Kbuild.src @@ -7,9 +7,3 @@ lib-y:= INSERT - -lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o -lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o - -lib-$(CONFIG_FSCK) += fsck.o -lib-$(CONFIG_TUNE2FS) += tune2fs.o diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c index f1cc8389f..c4e2415f8 100644 --- a/e2fsprogs/chattr.c +++ b/e2fsprogs/chattr.c @@ -9,15 +9,15 @@ * This file can be redistributed under the terms of the GNU General * Public License */ +//config:config CHATTR +//config: bool "chattr" +//config: default y +//config: help +//config: chattr changes the file attributes on a second extended file system. -/* - * History: - * 93/10/30 - Creation - * 93/11/13 - Replace stat() calls by lstat() to avoid loops - * 94/02/27 - Integrated in Ted's distribution - * 98/12/29 - Ignore symlinks when working recursively (G M Sipe) - * 98/12/29 - Display version info only when -V specified (G M Sipe) - */ +//applet:IF_CHATTR(APPLET(chattr, BB_DIR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_CHATTR) += chattr.o e2fs_lib.o //usage:#define chattr_trivial_usage //usage: "[-R] [-+=AacDdijsStTu] [-v VERSION] [FILE]..." diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index d2d312e5c..adaf0c538 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c @@ -33,6 +33,17 @@ * spawns actual fsck.something for each filesystem to check. * It doesn't guess filesystem types from on-disk format. */ +//config:config FSCK +//config: bool "fsck" +//config: default y +//config: help +//config: fsck is used to check and optionally repair one or more filesystems. +//config: In actuality, fsck is simply a front-end for the various file system +//config: checkers (fsck.fstype) available under Linux. + +//applet:IF_FSCK(APPLET(fsck, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_FSCK) += fsck.o //usage:#define fsck_trivial_usage //usage: "[-ANPRTV] [-C FD] [-t FSTYPE] [FS_OPTS] [BLOCKDEV]..." diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 1312fe754..3a7dd6b56 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c @@ -9,14 +9,16 @@ * This file can be redistributed under the terms of the GNU General * Public License */ +//config:config LSATTR +//config: bool "lsattr" +//config: default y +//config: select PLATFORM_LINUX +//config: help +//config: lsattr lists the file attributes on a second extended file system. -/* - * History: - * 93/10/30 - Creation - * 93/11/13 - Replace stat() calls by lstat() to avoid loops - * 94/02/27 - Integrated in Ted's distribution - * 98/12/29 - Display version info only when -V specified (G M Sipe) - */ +//applet:IF_LSATTR(APPLET(lsattr, BB_DIR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_LSATTR) += lsattr.o e2fs_lib.o //usage:#define lsattr_trivial_usage //usage: "[-Radlv] [FILE]..." diff --git a/e2fsprogs/tune2fs.c b/e2fsprogs/tune2fs.c index 46a745ee4..c9f88b39d 100644 --- a/e2fsprogs/tune2fs.c +++ b/e2fsprogs/tune2fs.c @@ -6,6 +6,33 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ +//config:config TUNE2FS +//config: bool "tune2fs" +//config: default n # off: it is too limited compared to upstream version +//config: help +//config: tune2fs allows the system administrator to adjust various tunable +//config: filesystem parameters on Linux ext2/ext3 filesystems. + +//applet:IF_TUNE2FS(APPLET(tune2fs, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_TUNE2FS) += tune2fs.o + +//usage:#define tune2fs_trivial_usage +//usage: "[-c MAX_MOUNT_COUNT] " +////usage: "[-e errors-behavior] [-g group] " +//usage: "[-i DAYS] " +////usage: "[-j] [-J journal-options] [-l] [-s sparse-flag] " +////usage: "[-m reserved-blocks-percent] [-o [^]mount-options[,...]] " +////usage: "[-r reserved-blocks-count] [-u user] " +//usage: "[-C MOUNT_COUNT] " +//usage: "[-L LABEL] " +////usage: "[-M last-mounted-dir] [-O [^]feature[,...]] " +////usage: "[-T last-check-time] [-U UUID] " +//usage: "BLOCKDEV" +//usage: +//usage:#define tune2fs_full_usage "\n\n" +//usage: "Adjust filesystem options on ext[23] filesystems" + #include "libbb.h" #include #include "bb_e2fs_defs.h" @@ -27,22 +54,6 @@ do { \ #define FETCH_LE32(field) \ (sizeof(field) == 4 ? SWAP_LE32(field) : BUG_wrong_field_size()) -//usage:#define tune2fs_trivial_usage -//usage: "[-c MAX_MOUNT_COUNT] " -////usage: "[-e errors-behavior] [-g group] " -//usage: "[-i DAYS] " -////usage: "[-j] [-J journal-options] [-l] [-s sparse-flag] " -////usage: "[-m reserved-blocks-percent] [-o [^]mount-options[,...]] " -////usage: "[-r reserved-blocks-count] [-u user] " -//usage: "[-C MOUNT_COUNT] " -//usage: "[-L LABEL] " -////usage: "[-M last-mounted-dir] [-O [^]feature[,...]] " -////usage: "[-T last-check-time] [-U UUID] " -//usage: "BLOCKDEV" -//usage: -//usage:#define tune2fs_full_usage "\n\n" -//usage: "Adjust filesystem options on ext[23] filesystems" - enum { OPT_L = 1 << 0, // label OPT_c = 1 << 1, // max mount count diff --git a/include/applets.src.h b/include/applets.src.h index c1b8017d4..c1ed0e82f 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -90,7 +90,6 @@ IF_CAL(APPLET(cal, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat)) IF_CATV(APPLET(catv, BB_DIR_BIN, BB_SUID_DROP)) IF_CHAT(APPLET(chat, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_CHATTR(APPLET(chattr, BB_DIR_BIN, BB_SUID_DROP)) IF_CHCON(APPLET(chcon, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp)) IF_CHMOD(APPLET_NOEXEC(chmod, chmod, BB_DIR_BIN, BB_SUID_DROP, chmod)) @@ -153,7 +152,6 @@ IF_FLOCK(APPLET(flock, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_FOLD(APPLET_NOEXEC(fold, fold, BB_DIR_USR_BIN, BB_SUID_DROP, fold)) IF_FREE(APPLET(free, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_FREERAMDISK(APPLET(freeramdisk, BB_DIR_SBIN, BB_SUID_DROP)) -IF_FSCK(APPLET(fsck, BB_DIR_SBIN, BB_SUID_DROP)) //IF_E2FSCK(APPLET_ODDNAME(fsck.ext2, e2fsck, BB_DIR_SBIN, BB_SUID_DROP, fsck_ext2)) //IF_E2FSCK(APPLET_ODDNAME(fsck.ext3, e2fsck, BB_DIR_SBIN, BB_SUID_DROP, fsck_ext3)) IF_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, BB_DIR_SBIN, BB_SUID_DROP, fsck_minix)) @@ -218,7 +216,6 @@ IF_LPD(APPLET(lpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_LPQ(APPLET_ODDNAME(lpq, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpq)) IF_LPR(APPLET_ODDNAME(lpr, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpr)) IF_LS(APPLET_NOEXEC(ls, ls, BB_DIR_BIN, BB_SUID_DROP, ls)) -IF_LSATTR(APPLET(lsattr, BB_DIR_BIN, BB_SUID_DROP)) IF_LSPCI(APPLET(lspci, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_LSUSB(APPLET(lsusb, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_MAKEDEVS(APPLET(makedevs, BB_DIR_SBIN, BB_SUID_DROP)) @@ -358,7 +355,6 @@ IF_TRUE(APPLET_NOFORK(true, true, BB_DIR_BIN, BB_SUID_DROP, true)) IF_TTY(APPLET(tty, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_TTYSIZE(APPLET(ttysize, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_TUNCTL(APPLET(tunctl, BB_DIR_SBIN, BB_SUID_DROP)) -IF_TUNE2FS(APPLET(tune2fs, BB_DIR_SBIN, BB_SUID_DROP)) IF_UDHCPC(APPLET(udhcpc, BB_DIR_SBIN, BB_SUID_DROP)) IF_UDHCPD(APPLET(udhcpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_UDPSVD(APPLET_ODDNAME(udpsvd, tcpudpsvd, BB_DIR_USR_BIN, BB_SUID_DROP, udpsvd)) -- cgit v1.2.3-55-g6feb From 0863e1a576c4b26bb87564b3a403f1094814f1aa Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 00:41:28 +0200 Subject: runit/*: convert to new-style "one file" applets Signed-off-by: Denys Vlasenko --- include/applets.src.h | 9 ------ runit/Config.src | 79 --------------------------------------------------- runit/Kbuild.src | 11 ------- runit/chpst.c | 45 ++++++++++++++++++++++++++++- runit/runsv.c | 12 +++++++- runit/runsvdir.c | 22 +++++++++++++- runit/sv.c | 20 ++++++++++++- runit/svlogd.c | 13 ++++++++- 8 files changed, 107 insertions(+), 104 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index c1ed0e82f..d243d89e1 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -95,7 +95,6 @@ IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp)) IF_CHMOD(APPLET_NOEXEC(chmod, chmod, BB_DIR_BIN, BB_SUID_DROP, chmod)) IF_CHOWN(APPLET_NOEXEC(chown, chown, BB_DIR_BIN, BB_SUID_DROP, chown)) IF_CHPASSWD(APPLET(chpasswd, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_CHPST(APPLET(chpst, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CHROOT(APPLET(chroot, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_CHRT(APPLET(chrt, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CHVT(APPLET(chvt, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -129,8 +128,6 @@ IF_DUMPLEASES(APPLET(dumpleases, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_ECHO(APPLET_NOFORK(echo, echo, BB_DIR_BIN, BB_SUID_DROP, echo)) IF_EJECT(APPLET(eject, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env)) -IF_ENVDIR(APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir)) -IF_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid)) IF_ETHER_WAKE(APPLET_ODDNAME(ether-wake, ether_wake, BB_DIR_USR_SBIN, BB_SUID_DROP, ether_wake)) IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_EXPR(APPLET(expr, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -288,8 +285,6 @@ IF_RTCWAKE(APPLET(rtcwake, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts)) IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RUNLEVEL(APPLET(runlevel, BB_DIR_SBIN, BB_SUID_DROP)) -IF_RUNSV(APPLET(runsv, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_RUNSVDIR(APPLET(runsvdir, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RX(APPLET(rx, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_SCRIPT(APPLET(script, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_SCRIPTREPLAY(APPLET(scriptreplay, BB_DIR_BIN, BB_SUID_DROP)) @@ -306,7 +301,6 @@ IF_SETKEYCODES(APPLET(setkeycodes, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_SETLOGCONS(APPLET(setlogcons, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_SETSEBOOL(APPLET(setsebool, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_SETSID(APPLET(setsid, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid)) IF_SHA1SUM(APPLET_NOEXEC(sha1sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha1sum)) IF_SHA3SUM(APPLET_NOEXEC(sha3sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha3sum)) IF_SHA256SUM(APPLET_NOEXEC(sha256sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha256sum)) @@ -315,7 +309,6 @@ IF_SHOWKEY(APPLET(showkey, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_SLATTACH(APPLET(slattach, BB_DIR_SBIN, BB_SUID_DROP)) /* Do not make this applet NOFORK. It breaks ^C-ing of pauses in shells: */ IF_SLEEP(APPLET(sleep, BB_DIR_BIN, BB_SUID_DROP)) -IF_SOFTLIMIT(APPLET_ODDNAME(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit)) IF_SORT(APPLET_NOEXEC(sort, sort, BB_DIR_USR_BIN, BB_SUID_DROP, sort)) IF_SPLIT(APPLET(split, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_START_STOP_DAEMON(APPLET_ODDNAME(start-stop-daemon, start_stop_daemon, BB_DIR_SBIN, BB_SUID_DROP, start_stop_daemon)) @@ -326,8 +319,6 @@ IF_STTY(APPLET(stty, BB_DIR_BIN, BB_SUID_DROP)) IF_SU(APPLET(su, BB_DIR_BIN, BB_SUID_REQUIRE)) IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP)) IF_SUM(APPLET(sum, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_SVLOGD(APPLET(svlogd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_SWAPONOFF(APPLET_ODDNAME(swapoff, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapoff)) IF_SWAPONOFF(APPLET_ODDNAME(swapon, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapon)) IF_SWITCH_ROOT(APPLET(switch_root, BB_DIR_SBIN, BB_SUID_DROP)) diff --git a/runit/Config.src b/runit/Config.src index 9db974002..8cde89680 100644 --- a/runit/Config.src +++ b/runit/Config.src @@ -7,83 +7,4 @@ menu "Runit Utilities" INSERT -config RUNSV - bool "runsv" - default y - help - runsv starts and monitors a service and optionally an appendant log - service. - -config RUNSVDIR - bool "runsvdir" - default y - help - runsvdir starts a runsv process for each subdirectory, or symlink to - a directory, in the services directory dir, up to a limit of 1000 - subdirectories, and restarts a runsv process if it terminates. - -config FEATURE_RUNSVDIR_LOG - bool "Enable scrolling argument log" - depends on RUNSVDIR - default n - help - Enable feature where second parameter of runsvdir holds last error - message (viewable via top/ps). Otherwise (feature is off - or no parameter), error messages go to stderr only. - -config SV - bool "sv" - default y - help - sv reports the current status and controls the state of services - monitored by the runsv supervisor. - -config SV_DEFAULT_SERVICE_DIR - string "Default directory for services" - default "/var/service" - depends on SV - help - Default directory for services. - Defaults to "/var/service" - -config SVLOGD - bool "svlogd" - default y - help - svlogd continuously reads log data from its standard input, optionally - filters log messages, and writes the data to one or more automatically - rotated logs. - -config CHPST - bool "chpst" - default y - help - chpst changes the process state according to the given options, and - execs specified program. - -config SETUIDGID - bool "setuidgid" - default y - help - Sets soft resource limits as specified by options - -config ENVUIDGID - bool "envuidgid" - default y - help - Sets $UID to account's uid and $GID to account's gid - -config ENVDIR - bool "envdir" - default y - help - Sets various environment variables as specified by files - in the given directory - -config SOFTLIMIT - bool "softlimit" - default y - help - Sets soft resource limits as specified by options - endmenu diff --git a/runit/Kbuild.src b/runit/Kbuild.src index 0fce95507..6b4fb7470 100644 --- a/runit/Kbuild.src +++ b/runit/Kbuild.src @@ -7,14 +7,3 @@ lib-y:= INSERT - -lib-$(CONFIG_RUNSV) += runsv.o -lib-$(CONFIG_RUNSVDIR) += runsvdir.o -lib-$(CONFIG_SV) += sv.o -lib-$(CONFIG_SVLOGD) += svlogd.o -lib-$(CONFIG_CHPST) += chpst.o - -lib-$(CONFIG_ENVDIR) += chpst.o -lib-$(CONFIG_ENVUIDGID) += chpst.o -lib-$(CONFIG_SETUIDGID) += chpst.o -lib-$(CONFIG_SOFTLIMIT) += chpst.o diff --git a/runit/chpst.c b/runit/chpst.c index 71af29f66..301cdd08a 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -26,7 +26,50 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Busyboxed by Denys Vlasenko */ -/* Dependencies on runit_lib.c removed */ + +//config:config CHPST +//config: bool "chpst" +//config: default y +//config: help +//config: chpst changes the process state according to the given options, and +//config: execs specified program. +//config: +//config:config SETUIDGID +//config: bool "setuidgid" +//config: default y +//config: help +//config: Sets soft resource limits as specified by options +//config: +//config:config ENVUIDGID +//config: bool "envuidgid" +//config: default y +//config: help +//config: Sets $UID to account's uid and $GID to account's gid +//config: +//config:config ENVDIR +//config: bool "envdir" +//config: default y +//config: help +//config: Sets various environment variables as specified by files +//config: in the given directory +//config: +//config:config SOFTLIMIT +//config: bool "softlimit" +//config: default y +//config: help +//config: Sets soft resource limits as specified by options + +//applet:IF_CHPST(APPLET(chpst, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_ENVDIR(APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir)) +//applet:IF_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid)) +//applet:IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid)) +//applet:IF_SOFTLIMIT(APPLET_ODDNAME(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit)) + +//kbuild:lib-$(CONFIG_CHPST) += chpst.o +//kbuild:lib-$(CONFIG_ENVDIR) += chpst.o +//kbuild:lib-$(CONFIG_ENVUIDGID) += chpst.o +//kbuild:lib-$(CONFIG_SETUIDGID) += chpst.o +//kbuild:lib-$(CONFIG_SOFTLIMIT) += chpst.o //usage:#define chpst_trivial_usage //usage: "[-vP012] [-u USER[:GRP]] [-U USER[:GRP]] [-e DIR]\n" diff --git a/runit/runsv.c b/runit/runsv.c index 6cf5bcc29..4b18d12d5 100644 --- a/runit/runsv.c +++ b/runit/runsv.c @@ -26,7 +26,17 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Busyboxed by Denys Vlasenko */ -/* TODO: depends on runit_lib.c - review and reduce/eliminate */ + +//config:config RUNSV +//config: bool "runsv" +//config: default y +//config: help +//config: runsv starts and monitors a service and optionally an appendant log +//config: service. + +//applet:IF_RUNSV(APPLET(runsv, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_RUNSV) += runsv.o //usage:#define runsv_trivial_usage //usage: "DIR" diff --git a/runit/runsvdir.c b/runit/runsvdir.c index b4c0b2ef0..b3d9e7390 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c @@ -26,7 +26,27 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Busyboxed by Denys Vlasenko */ -/* TODO: depends on runit_lib.c - review and reduce/eliminate */ + +//config:config RUNSVDIR +//config: bool "runsvdir" +//config: default y +//config: help +//config: runsvdir starts a runsv process for each subdirectory, or symlink to +//config: a directory, in the services directory dir, up to a limit of 1000 +//config: subdirectories, and restarts a runsv process if it terminates. +//config: +//config:config FEATURE_RUNSVDIR_LOG +//config: bool "Enable scrolling argument log" +//config: depends on RUNSVDIR +//config: default n +//config: help +//config: Enable feature where second parameter of runsvdir holds last error +//config: message (viewable via top/ps). Otherwise (feature is off +//config: or no parameter), error messages go to stderr only. + +//applet:IF_RUNSVDIR(APPLET(runsvdir, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_RUNSVDIR) += runsvdir.o //usage:#define runsvdir_trivial_usage //usage: "[-P] [-s SCRIPT] DIR" diff --git a/runit/sv.c b/runit/sv.c index 825e9d45b..de8a0d8a4 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -151,7 +151,25 @@ Exit Codes */ /* Busyboxed by Denys Vlasenko */ -/* TODO: depends on runit_lib.c - review and reduce/eliminate */ + +//config:config SV +//config: bool "sv" +//config: default y +//config: help +//config: sv reports the current status and controls the state of services +//config: monitored by the runsv supervisor. +//config: +//config:config SV_DEFAULT_SERVICE_DIR +//config: string "Default directory for services" +//config: default "/var/service" +//config: depends on SV +//config: help +//config: Default directory for services. +//config: Defaults to "/var/service" + +//applet:IF_SV(APPLET(sv, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_SV) += sv.o //usage:#define sv_trivial_usage //usage: "[-v] [-w SEC] CMD SERVICE_DIR..." diff --git a/runit/svlogd.c b/runit/svlogd.c index c080b9acc..dbe8df65c 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -26,7 +26,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Busyboxed by Denys Vlasenko */ -/* TODO: depends on runit_lib.c - review and reduce/eliminate */ /* Config files @@ -125,6 +124,18 @@ log message, you can use a pattern like this instead -*: *: pid * */ +//config:config SVLOGD +//config: bool "svlogd" +//config: default y +//config: help +//config: svlogd continuously reads log data from its standard input, optionally +//config: filters log messages, and writes the data to one or more automatically +//config: rotated logs. + +//applet:IF_SVLOGD(APPLET(svlogd, BB_DIR_USR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_SVLOGD) += svlogd.o + //usage:#define svlogd_trivial_usage //usage: "[-ttv] [-r C] [-R CHARS] [-l MATCHLEN] [-b BUFLEN] DIR..." //usage:#define svlogd_full_usage "\n\n" -- cgit v1.2.3-55-g6feb From 854bb6879da7277446c7a943387e2880017804e0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 00:45:46 +0200 Subject: printutils/*: convert to new-style "one file" applets Signed-off-by: Denys Vlasenko --- include/applets.src.h | 3 --- printutils/Config.src | 18 ------------------ printutils/Kbuild.src | 4 +--- printutils/lpd.c | 9 +++++++++ printutils/lpr.c | 17 +++++++++++++++++ 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index d243d89e1..9c4f9daa0 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -209,9 +209,6 @@ IF_LOADKMAP(APPLET(loadkmap, BB_DIR_SBIN, BB_SUID_DROP)) IF_LOGIN(APPLET(login, BB_DIR_BIN, BB_SUID_REQUIRE)) IF_LOGNAME(APPLET_NOFORK(logname, logname, BB_DIR_USR_BIN, BB_SUID_DROP, logname)) IF_LOSETUP(APPLET(losetup, BB_DIR_SBIN, BB_SUID_DROP)) -IF_LPD(APPLET(lpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_LPQ(APPLET_ODDNAME(lpq, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpq)) -IF_LPR(APPLET_ODDNAME(lpr, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpr)) IF_LS(APPLET_NOEXEC(ls, ls, BB_DIR_BIN, BB_SUID_DROP, ls)) IF_LSPCI(APPLET(lspci, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_LSUSB(APPLET(lsusb, BB_DIR_USR_BIN, BB_SUID_DROP)) diff --git a/printutils/Config.src b/printutils/Config.src index cc4ab8d28..e53b9d093 100644 --- a/printutils/Config.src +++ b/printutils/Config.src @@ -7,22 +7,4 @@ menu "Print Utilities" INSERT -config LPD - bool "lpd" - default y - help - lpd is a print spooling daemon. - -config LPR - bool "lpr" - default y - help - lpr sends files (or standard input) to a print spooling daemon. - -config LPQ - bool "lpq" - default y - help - lpq is a print spool queue examination and manipulation program. - endmenu diff --git a/printutils/Kbuild.src b/printutils/Kbuild.src index 194fe01d6..10c823063 100644 --- a/printutils/Kbuild.src +++ b/printutils/Kbuild.src @@ -4,6 +4,4 @@ lib-y := -lib-$(CONFIG_LPD) += lpd.o -lib-$(CONFIG_LPR) += lpr.o -lib-$(CONFIG_LPQ) += lpr.o +INSERT diff --git a/printutils/lpd.c b/printutils/lpd.c index c98bbb347..882393436 100644 --- a/printutils/lpd.c +++ b/printutils/lpd.c @@ -69,6 +69,15 @@ * cat ./"$DATAFILE" >/dev/lp0 * mv -f ./"$DATAFILE" save/ */ +//config:config LPD +//config: bool "lpd" +//config: default y +//config: help +//config: lpd is a print spooling daemon. + +//applet:IF_LPD(APPLET(lpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_LPD) += lpd.o //usage:#define lpd_trivial_usage //usage: "SPOOLDIR [HELPER [ARGS]]" diff --git a/printutils/lpr.c b/printutils/lpr.c index 70cda7717..ed6a84a93 100644 --- a/printutils/lpr.c +++ b/printutils/lpr.c @@ -11,6 +11,23 @@ * * See RFC 1179 for protocol description. */ +//config:config LPR +//config: bool "lpr" +//config: default y +//config: help +//config: lpr sends files (or standard input) to a print spooling daemon. +//config: +//config:config LPQ +//config: bool "lpq" +//config: default y +//config: help +//config: lpq is a print spool queue examination and manipulation program. + +//applet:IF_LPQ(APPLET_ODDNAME(lpq, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpq)) +//applet:IF_LPR(APPLET_ODDNAME(lpr, lpqr, BB_DIR_USR_BIN, BB_SUID_DROP, lpr)) + +//kbuild:lib-$(CONFIG_LPR) += lpr.o +//kbuild:lib-$(CONFIG_LPQ) += lpr.o //usage:#define lpr_trivial_usage //usage: "-P queue[@host[:port]] -U USERNAME -J TITLE -Vmh [FILE]..." -- cgit v1.2.3-55-g6feb From 28826ac8c02793431203edb4adb961d5521d643d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 00:52:26 +0200 Subject: debianutils/*: convert to new-style "one file" applets Signed-off-by: Denys Vlasenko --- debianutils/Config.src | 75 ----------------------------------------- debianutils/Kbuild.src | 5 --- debianutils/mktemp.c | 9 +++++ debianutils/pipe_progress.c | 9 +++++ debianutils/run_parts.c | 34 +++++++++++++++++++ debianutils/start_stop_daemon.c | 28 +++++++++++++++ debianutils/which.c | 10 ++++++ include/applets.src.h | 5 --- 8 files changed, 90 insertions(+), 85 deletions(-) diff --git a/debianutils/Config.src b/debianutils/Config.src index cbc09b5ce..61daeb047 100644 --- a/debianutils/Config.src +++ b/debianutils/Config.src @@ -7,79 +7,4 @@ menu "Debian Utilities" INSERT -config MKTEMP - bool "mktemp" - default y - help - mktemp is used to create unique temporary files - -config PIPE_PROGRESS - bool "pipe_progress" - default y - help - Display a dot to indicate pipe activity. - -config RUN_PARTS - bool "run-parts" - default y - help - run-parts is a utility designed to run all the scripts in a directory. - - It is useful to set up a directory like cron.daily, where you need to - execute all the scripts in that directory. - - In this implementation of run-parts some features (such as report - mode) are not implemented. - - Unless you know that run-parts is used in some of your scripts - you can safely say N here. - -config FEATURE_RUN_PARTS_LONG_OPTIONS - bool "Enable long options" - default y - depends on RUN_PARTS && LONG_OPTS - help - Support long options for the run-parts applet. - -config FEATURE_RUN_PARTS_FANCY - bool "Support additional arguments" - default y - depends on RUN_PARTS - help - Support additional options: - -l --list print the names of the all matching files (not - limited to executables), but don't actually run them. - -config START_STOP_DAEMON - bool "start-stop-daemon" - default y - help - start-stop-daemon is used to control the creation and - termination of system-level processes, usually the ones - started during the startup of the system. - -config FEATURE_START_STOP_DAEMON_FANCY - bool "Support additional arguments" - default y - depends on START_STOP_DAEMON - help - Support additional arguments. - -o|--oknodo ignored since we exit with 0 anyway - -v|--verbose - -N|--nicelevel N - -config FEATURE_START_STOP_DAEMON_LONG_OPTIONS - bool "Enable long options" - default y - depends on START_STOP_DAEMON && LONG_OPTS - help - Support long options for the start-stop-daemon applet. - -config WHICH - bool "which" - default y - help - which is used to find programs in your PATH and - print out their pathnames. - endmenu diff --git a/debianutils/Kbuild.src b/debianutils/Kbuild.src index d41b5c8e4..6b4fb7470 100644 --- a/debianutils/Kbuild.src +++ b/debianutils/Kbuild.src @@ -7,8 +7,3 @@ lib-y:= INSERT -lib-$(CONFIG_MKTEMP) += mktemp.o -lib-$(CONFIG_PIPE_PROGRESS) += pipe_progress.o -lib-$(CONFIG_RUN_PARTS) += run_parts.o -lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o -lib-$(CONFIG_WHICH) += which.o diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index 983d7a246..65353697a 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c @@ -30,6 +30,15 @@ * a directory: $TMPDIR, if set; else the directory specified via * -p; else /tmp [deprecated] */ +//config:config MKTEMP +//config: bool "mktemp" +//config: default y +//config: help +//config: mktemp is used to create unique temporary files + +//applet:IF_MKTEMP(APPLET(mktemp, BB_DIR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_MKTEMP) += mktemp.o //usage:#define mktemp_trivial_usage //usage: "[-dt] [-p DIR] [TEMPLATE]" diff --git a/debianutils/pipe_progress.c b/debianutils/pipe_progress.c index 2c7444f31..21d330b59 100644 --- a/debianutils/pipe_progress.c +++ b/debianutils/pipe_progress.c @@ -6,6 +6,15 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config PIPE_PROGRESS +//config: bool "pipe_progress" +//config: default y +//config: help +//config: Display a dot to indicate pipe activity. + +//applet:IF_PIPE_PROGRESS(APPLET(pipe_progress, BB_DIR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_PIPE_PROGRESS) += pipe_progress.o //usage:#define pipe_progress_trivial_usage NOUSAGE_STR //usage:#define pipe_progress_full_usage "" diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index dd6fe7d49..13617c6e1 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c @@ -22,6 +22,40 @@ * report mode. As the original run-parts support only long options, I've * broken compatibility because the BusyBox policy doesn't allow them. */ +//config:config RUN_PARTS +//config: bool "run-parts" +//config: default y +//config: help +//config: run-parts is a utility designed to run all the scripts in a directory. +//config: +//config: It is useful to set up a directory like cron.daily, where you need to +//config: execute all the scripts in that directory. +//config: +//config: In this implementation of run-parts some features (such as report +//config: mode) are not implemented. +//config: +//config: Unless you know that run-parts is used in some of your scripts +//config: you can safely say N here. +//config: +//config:config FEATURE_RUN_PARTS_LONG_OPTIONS +//config: bool "Enable long options" +//config: default y +//config: depends on RUN_PARTS && LONG_OPTS +//config: help +//config: Support long options for the run-parts applet. +//config: +//config:config FEATURE_RUN_PARTS_FANCY +//config: bool "Support additional arguments" +//config: default y +//config: depends on RUN_PARTS +//config: help +//config: Support additional options: +//config: -l --list print the names of the all matching files (not +//config: limited to executables), but don't actually run them. + +//applet:IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts)) + +//kbuild:lib-$(CONFIG_RUN_PARTS) += run_parts.o //usage:#define run_parts_trivial_usage //usage: "[-a ARG]... [-u UMASK] " diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 7dadc3c9e..42f1943dd 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -56,6 +56,34 @@ Misc options: -q,--quiet Quiet -v,--verbose Verbose */ +//config:config START_STOP_DAEMON +//config: bool "start-stop-daemon" +//config: default y +//config: help +//config: start-stop-daemon is used to control the creation and +//config: termination of system-level processes, usually the ones +//config: started during the startup of the system. +//config: +//config:config FEATURE_START_STOP_DAEMON_FANCY +//config: bool "Support additional arguments" +//config: default y +//config: depends on START_STOP_DAEMON +//config: help +//config: Support additional arguments. +//config: -o|--oknodo ignored since we exit with 0 anyway +//config: -v|--verbose +//config: -N|--nicelevel N +//config: +//config:config FEATURE_START_STOP_DAEMON_LONG_OPTIONS +//config: bool "Enable long options" +//config: default y +//config: depends on START_STOP_DAEMON && LONG_OPTS +//config: help +//config: Support long options for the start-stop-daemon applet. + +//applet:IF_START_STOP_DAEMON(APPLET_ODDNAME(start-stop-daemon, start_stop_daemon, BB_DIR_SBIN, BB_SUID_DROP, start_stop_daemon)) + +//kbuild:lib-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o //usage:#define start_stop_daemon_trivial_usage //usage: "[OPTIONS] [-S|-K] ... [-- ARGS...]" diff --git a/debianutils/which.c b/debianutils/which.c index d50e7a0d3..c0f897809 100644 --- a/debianutils/which.c +++ b/debianutils/which.c @@ -5,6 +5,16 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config WHICH +//config: bool "which" +//config: default y +//config: help +//config: which is used to find programs in your PATH and +//config: print out their pathnames. + +//applet:IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_WHICH) += which.o //usage:#define which_trivial_usage //usage: "[COMMAND]..." diff --git a/include/applets.src.h b/include/applets.src.h index 9c4f9daa0..f49179996 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -230,7 +230,6 @@ IF_MKFS_VFAT(APPLET_ODDNAME(mkfs.vfat, mkfs_vfat, BB_DIR_SBIN, BB_SUID_DROP, mkf IF_MKNOD(APPLET_NOEXEC(mknod, mknod, BB_DIR_BIN, BB_SUID_DROP, mknod)) IF_CRYPTPW(APPLET_ODDNAME(mkpasswd, cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP, mkpasswd)) IF_MKSWAP(APPLET(mkswap, BB_DIR_SBIN, BB_SUID_DROP)) -IF_MKTEMP(APPLET(mktemp, BB_DIR_BIN, BB_SUID_DROP)) IF_MORE(APPLET(more, BB_DIR_BIN, BB_SUID_DROP)) /* On full-blown systems, requires suid for user mounts. * But it's not unthinkable to have it available in non-suid flavor on some systems, @@ -254,7 +253,6 @@ IF_OPENVT(APPLET(openvt, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_PASSWD(APPLET(passwd, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) IF_PGREP(APPLET(pgrep, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_PIDOF(APPLET(pidof, BB_DIR_BIN, BB_SUID_DROP)) -IF_PIPE_PROGRESS(APPLET(pipe_progress, BB_DIR_BIN, BB_SUID_DROP)) IF_PIVOT_ROOT(APPLET(pivot_root, BB_DIR_SBIN, BB_SUID_DROP)) IF_PKILL(APPLET_ODDNAME(pkill, pgrep, BB_DIR_USR_BIN, BB_SUID_DROP, pkill)) IF_POPMAILDIR(APPLET(popmaildir, BB_DIR_USR_SBIN, BB_SUID_DROP)) @@ -279,7 +277,6 @@ IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm)) IF_RMDIR(APPLET_NOFORK(rmdir, rmdir, BB_DIR_BIN, BB_SUID_DROP, rmdir)) IF_ROUTE(APPLET(route, BB_DIR_SBIN, BB_SUID_DROP)) IF_RTCWAKE(APPLET(rtcwake, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_RUN_PARTS(APPLET_ODDNAME(run-parts, run_parts, BB_DIR_BIN, BB_SUID_DROP, run_parts)) IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_RUNLEVEL(APPLET(runlevel, BB_DIR_SBIN, BB_SUID_DROP)) IF_RX(APPLET(rx, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -308,7 +305,6 @@ IF_SLATTACH(APPLET(slattach, BB_DIR_SBIN, BB_SUID_DROP)) IF_SLEEP(APPLET(sleep, BB_DIR_BIN, BB_SUID_DROP)) IF_SORT(APPLET_NOEXEC(sort, sort, BB_DIR_USR_BIN, BB_SUID_DROP, sort)) IF_SPLIT(APPLET(split, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_START_STOP_DAEMON(APPLET_ODDNAME(start-stop-daemon, start_stop_daemon, BB_DIR_SBIN, BB_SUID_DROP, start_stop_daemon)) IF_STAT(APPLET(stat, BB_DIR_BIN, BB_SUID_DROP)) IF_STRINGS(APPLET(strings, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_STTY(APPLET(stty, BB_DIR_BIN, BB_SUID_DROP)) @@ -362,7 +358,6 @@ IF_VOLNAME(APPLET(volname, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_WATCH(APPLET(watch, BB_DIR_BIN, BB_SUID_DROP)) IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP)) IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_WHOAMI(APPLET_NOFORK(whoami, whoami, BB_DIR_USR_BIN, BB_SUID_DROP, whoami)) IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes)) IF_ZCIP(APPLET(zcip, BB_DIR_SBIN, BB_SUID_DROP)) -- cgit v1.2.3-55-g6feb From 95dee81a465668151cff3ffd757456a9a10c1f1f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 01:20:36 +0200 Subject: loginutils/*: convert to new-style "one file" applets Signed-off-by: Denys Vlasenko --- include/applets.src.h | 17 --- loginutils/Config.src | 237 +----------------------------------------- loginutils/Kbuild.src | 12 --- loginutils/add-remove-shell.c | 13 ++- loginutils/addgroup.c | 25 +++++ loginutils/adduser.c | 51 +++++++++ loginutils/chpasswd.c | 20 +++- loginutils/cryptpw.c | 12 +++ loginutils/deluser.c | 26 ++++- loginutils/getty.c | 22 ++++ loginutils/login.c | 50 +++++++++ loginutils/passwd.c | 24 +++++ loginutils/su.c | 31 +++++- loginutils/sulogin.c | 12 +++ loginutils/vlock.c | 16 ++- 15 files changed, 290 insertions(+), 278 deletions(-) diff --git a/include/applets.src.h b/include/applets.src.h index f49179996..5b597202e 100644 --- a/include/applets.src.h +++ b/include/applets.src.h @@ -76,8 +76,6 @@ INSERT IF_TEST(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test)) IF_TEST(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test)) IF_ACPID(APPLET(acpid, BB_DIR_SBIN, BB_SUID_DROP)) -IF_ADDGROUP(APPLET(addgroup, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_ADDUSER(APPLET(adduser, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_ADJTIMEX(APPLET(adjtimex, BB_DIR_SBIN, BB_SUID_DROP)) IF_ARP(APPLET(arp, BB_DIR_SBIN, BB_SUID_DROP)) IF_ARPING(APPLET(arping, BB_DIR_USR_SBIN, BB_SUID_DROP)) @@ -94,7 +92,6 @@ IF_CHCON(APPLET(chcon, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp)) IF_CHMOD(APPLET_NOEXEC(chmod, chmod, BB_DIR_BIN, BB_SUID_DROP, chmod)) IF_CHOWN(APPLET_NOEXEC(chown, chown, BB_DIR_BIN, BB_SUID_DROP, chown)) -IF_CHPASSWD(APPLET(chpasswd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_CHROOT(APPLET(chroot, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_CHRT(APPLET(chrt, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CHVT(APPLET(chvt, BB_DIR_USR_BIN, BB_SUID_DROP)) @@ -104,13 +101,10 @@ IF_COMM(APPLET(comm, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp)) /* Needs to be run by root or be suid root - needs to change /var/spool/cron* files: */ IF_CRONTAB(APPLET(crontab, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) -IF_CRYPTPW(APPLET(cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_CUT(APPLET_NOEXEC(cut, cut, BB_DIR_USR_BIN, BB_SUID_DROP, cut)) IF_DC(APPLET(dc, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_DD(APPLET_NOEXEC(dd, dd, BB_DIR_BIN, BB_SUID_DROP, dd)) IF_DEALLOCVT(APPLET(deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP)) -IF_DELGROUP(APPLET_ODDNAME(delgroup, deluser, BB_DIR_USR_SBIN, BB_SUID_DROP, delgroup)) -IF_DELUSER(APPLET(deluser, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_DEVFSD(APPLET(devfsd, BB_DIR_SBIN, BB_SUID_DROP)) IF_DEVMEM(APPLET(devmem, BB_DIR_SBIN, BB_SUID_DROP)) IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP)) @@ -160,7 +154,6 @@ IF_FUSER(APPLET(fuser, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_GETENFORCE(APPLET(getenforce, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_GETOPT(APPLET(getopt, BB_DIR_BIN, BB_SUID_DROP)) IF_GETSEBOOL(APPLET(getsebool, BB_DIR_USR_SBIN, BB_SUID_DROP)) -IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP)) IF_HD(APPLET_NOEXEC(hd, hexdump, BB_DIR_USR_BIN, BB_SUID_DROP, hd)) IF_HDPARM(APPLET(hdparm, BB_DIR_SBIN, BB_SUID_DROP)) IF_HEAD(APPLET_NOEXEC(head, head, BB_DIR_USR_BIN, BB_SUID_DROP, head)) @@ -205,8 +198,6 @@ IF_LN(APPLET_NOEXEC(ln, ln, BB_DIR_BIN, BB_SUID_DROP, ln)) IF_LOAD_POLICY(APPLET(load_policy, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_LOADKMAP(APPLET(loadkmap, BB_DIR_SBIN, BB_SUID_DROP)) -/* Needs to be run by root or be suid root - needs to change uid and gid: */ -IF_LOGIN(APPLET(login, BB_DIR_BIN, BB_SUID_REQUIRE)) IF_LOGNAME(APPLET_NOFORK(logname, logname, BB_DIR_USR_BIN, BB_SUID_DROP, logname)) IF_LOSETUP(APPLET(losetup, BB_DIR_SBIN, BB_SUID_DROP)) IF_LS(APPLET_NOEXEC(ls, ls, BB_DIR_BIN, BB_SUID_DROP, ls)) @@ -228,7 +219,6 @@ IF_MKFS_MINIX(APPLET_ODDNAME(mkfs.minix, mkfs_minix, BB_DIR_SBIN, BB_SUID_DROP, IF_MKFS_REISER(APPLET_ODDNAME(mkfs.reiser, mkfs_reiser, BB_DIR_SBIN, BB_SUID_DROP, mkfs_reiser)) IF_MKFS_VFAT(APPLET_ODDNAME(mkfs.vfat, mkfs_vfat, BB_DIR_SBIN, BB_SUID_DROP, mkfs_vfat)) IF_MKNOD(APPLET_NOEXEC(mknod, mknod, BB_DIR_BIN, BB_SUID_DROP, mknod)) -IF_CRYPTPW(APPLET_ODDNAME(mkpasswd, cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP, mkpasswd)) IF_MKSWAP(APPLET(mkswap, BB_DIR_SBIN, BB_SUID_DROP)) IF_MORE(APPLET(more, BB_DIR_BIN, BB_SUID_DROP)) /* On full-blown systems, requires suid for user mounts. @@ -249,8 +239,6 @@ IF_NTPD(APPLET(ntpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) IF_OD(APPLET(od, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_OPENVT(APPLET(openvt, BB_DIR_USR_BIN, BB_SUID_DROP)) //IF_PARSE(APPLET(parse, BB_DIR_USR_BIN, BB_SUID_DROP)) -/* Needs to be run by root or be suid root - needs to change /etc/{passwd,shadow}: */ -IF_PASSWD(APPLET(passwd, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) IF_PGREP(APPLET(pgrep, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_PIDOF(APPLET(pidof, BB_DIR_BIN, BB_SUID_DROP)) IF_PIVOT_ROOT(APPLET(pivot_root, BB_DIR_SBIN, BB_SUID_DROP)) @@ -308,9 +296,6 @@ IF_SPLIT(APPLET(split, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_STAT(APPLET(stat, BB_DIR_BIN, BB_SUID_DROP)) IF_STRINGS(APPLET(strings, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_STTY(APPLET(stty, BB_DIR_BIN, BB_SUID_DROP)) -/* Needs to be run by root or be suid root - needs to change uid and gid: */ -IF_SU(APPLET(su, BB_DIR_BIN, BB_SUID_REQUIRE)) -IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP)) IF_SUM(APPLET(sum, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_SWAPONOFF(APPLET_ODDNAME(swapoff, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapoff)) IF_SWAPONOFF(APPLET_ODDNAME(swapon, swap_on_off, BB_DIR_SBIN, BB_SUID_DROP, swapon)) @@ -352,8 +337,6 @@ IF_USLEEP(APPLET_NOFORK(usleep, usleep, BB_DIR_BIN, BB_SUID_DROP, usleep)) IF_UUDECODE(APPLET(uudecode, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_UUENCODE(APPLET(uuencode, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_VCONFIG(APPLET(vconfig, BB_DIR_SBIN, BB_SUID_DROP)) -/* Needs to be run by root or be suid root - needs to change uid and gid: */ -IF_VLOCK(APPLET(vlock, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) IF_VOLNAME(APPLET(volname, BB_DIR_USR_BIN, BB_SUID_DROP)) IF_WATCH(APPLET(watch, BB_DIR_BIN, BB_SUID_DROP)) IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP)) diff --git a/loginutils/Config.src b/loginutils/Config.src index fa2b4f8c0..efb954b6c 100644 --- a/loginutils/Config.src +++ b/loginutils/Config.src @@ -5,8 +5,6 @@ menu "Login/Password Management Utilities" -INSERT - config FEATURE_SHADOWPASSWDS bool "Support for shadow passwords" default y @@ -93,239 +91,6 @@ config USE_BB_CRYPT_SHA With this option off, login will fail password check for any user which has password encrypted with these algorithms. -config ADDUSER - bool "adduser" - default y - help - Utility for creating a new user account. - -config FEATURE_ADDUSER_LONG_OPTIONS - bool "Enable long options" - default y - depends on ADDUSER && LONG_OPTS - help - Support long options for the adduser applet. - -config FEATURE_CHECK_NAMES - bool "Enable sanity check on user/group names in adduser and addgroup" - default n - depends on ADDUSER || ADDGROUP - help - Enable sanity check on user and group names in adduser and addgroup. - To avoid problems, the user or group name should consist only of - letters, digits, underscores, periods, at signs and dashes, - and not start with a dash (as defined by IEEE Std 1003.1-2001). - For compatibility with Samba machine accounts "$" is also supported - at the end of the user or group name. - -config LAST_ID - int "Last valid uid or gid for adduser and addgroup" - depends on ADDUSER || ADDGROUP - default 60000 - help - Last valid uid or gid for adduser and addgroup - -config FIRST_SYSTEM_ID - int "First valid system uid or gid for adduser and addgroup" - depends on ADDUSER || ADDGROUP - range 0 LAST_ID - default 100 - help - First valid system uid or gid for adduser and addgroup - -config LAST_SYSTEM_ID - int "Last valid system uid or gid for adduser and addgroup" - depends on ADDUSER || ADDGROUP - range FIRST_SYSTEM_ID LAST_ID - default 999 - help - Last valid system uid or gid for adduser and addgroup - -config ADDGROUP - bool "addgroup" - default y - help - Utility for creating a new group account. - -config FEATURE_ADDGROUP_LONG_OPTIONS - bool "Enable long options" - default y - depends on ADDGROUP && LONG_OPTS - help - Support long options for the addgroup applet. - -config FEATURE_ADDUSER_TO_GROUP - bool "Support for adding users to groups" - default y - depends on ADDGROUP - help - If called with two non-option arguments, - addgroup will add an existing user to an - existing group. - -config DELUSER - bool "deluser" - default y - help - Utility for deleting a user account. - -config DELGROUP - bool "delgroup" - default y - help - Utility for deleting a group account. - -config FEATURE_DEL_USER_FROM_GROUP - bool "Support for removing users from groups" - default y - depends on DELGROUP - help - If called with two non-option arguments, deluser - or delgroup will remove an user from a specified group. - -config GETTY - bool "getty" - default y - select FEATURE_SYSLOG - help - getty lets you log in on a tty. It is normally invoked by init. - - Note that you can save a few bytes by disabling it and - using login applet directly. - If you need to reset tty attributes before calling login, - this script approximates getty: - - exec /dev/$1 2>&1 || exit 1 - reset - stty sane; stty ispeed 38400; stty ospeed 38400 - printf "%s login: " "`hostname`" - read -r login - exec /bin/login "$login" - -config LOGIN - bool "login" - default y - select FEATURE_SYSLOG - help - login is used when signing onto a system. - - Note that Busybox binary must be setuid root for this applet to - work properly. - -config LOGIN_SESSION_AS_CHILD - bool "Run logged in session in a child process" - default y if PAM - depends on LOGIN - help - Run the logged in session in a child process. This allows - login to clean up things such as utmp entries or PAM sessions - when the login session is complete. If you use PAM, you - almost always would want this to be set to Y, else PAM session - will not be cleaned up. - -config LOGIN_SCRIPTS - bool "Support for login scripts" - depends on LOGIN - default y - help - Enable this if you want login to execute $LOGIN_PRE_SUID_SCRIPT - just prior to switching from root to logged-in user. - -config FEATURE_NOLOGIN - bool "Support for /etc/nologin" - default y - depends on LOGIN - help - The file /etc/nologin is used by (some versions of) login(1). - If it exists, non-root logins are prohibited. - -config FEATURE_SECURETTY - bool "Support for /etc/securetty" - default y - depends on LOGIN - help - The file /etc/securetty is used by (some versions of) login(1). - The file contains the device names of tty lines (one per line, - without leading /dev/) on which root is allowed to login. - -config PASSWD - bool "passwd" - default y - select FEATURE_SYSLOG - help - passwd changes passwords for user and group accounts. A normal user - may only change the password for his/her own account, the super user - may change the password for any account. The administrator of a group - may change the password for the group. - - Note that Busybox binary must be setuid root for this applet to - work properly. - -config FEATURE_PASSWD_WEAK_CHECK - bool "Check new passwords for weakness" - default y - depends on PASSWD - help - With this option passwd will refuse new passwords which are "weak". - -config CRYPTPW - bool "cryptpw" - default y - help - Encrypts the given password with the crypt(3) libc function - using the given salt. Debian has this utility under mkpasswd - name. Busybox provides mkpasswd as an alias for cryptpw. - -config CHPASSWD - bool "chpasswd" - default y - help - Reads a file of user name and password pairs from standard input - and uses this information to update a group of existing users. - -config FEATURE_DEFAULT_PASSWD_ALGO - string "Default password encryption method (passwd -a, cryptpw -m parameter)" - default "des" - depends on PASSWD || CRYPTPW - help - Possible choices are "d[es]", "m[d5]", "s[ha256]" or "sha512". - -config SU - bool "su" - default y - select FEATURE_SYSLOG - help - su is used to become another user during a login session. - Invoked without a username, su defaults to becoming the super user. - - Note that Busybox binary must be setuid root for this applet to - work properly. - -config FEATURE_SU_SYSLOG - bool "Enable su to write to syslog" - default y - depends on SU - -config FEATURE_SU_CHECKS_SHELLS - bool "Enable su to check user's shell to be listed in /etc/shells" - depends on SU - default y - -config SULOGIN - bool "sulogin" - default y - select FEATURE_SYSLOG - help - sulogin is invoked when the system goes into single user - mode (this is done through an entry in inittab). - -config VLOCK - bool "vlock" - default y - help - Build the "vlock" applet which allows you to lock (virtual) terminals. - - Note that Busybox binary must be setuid root for this applet to - work properly. +INSERT endmenu diff --git a/loginutils/Kbuild.src b/loginutils/Kbuild.src index ef416a76f..6b4fb7470 100644 --- a/loginutils/Kbuild.src +++ b/loginutils/Kbuild.src @@ -7,15 +7,3 @@ lib-y:= INSERT -lib-$(CONFIG_ADDGROUP) += addgroup.o -lib-$(CONFIG_ADDUSER) += adduser.o -lib-$(CONFIG_CRYPTPW) += cryptpw.o -lib-$(CONFIG_CHPASSWD) += chpasswd.o -lib-$(CONFIG_GETTY) += getty.o -lib-$(CONFIG_LOGIN) += login.o -lib-$(CONFIG_PASSWD) += passwd.o -lib-$(CONFIG_SU) += su.o -lib-$(CONFIG_SULOGIN) += sulogin.o -lib-$(CONFIG_VLOCK) += vlock.o -lib-$(CONFIG_DELUSER) += deluser.o -lib-$(CONFIG_DELGROUP) += deluser.o diff --git a/loginutils/add-remove-shell.c b/loginutils/add-remove-shell.c index 9419ff5e7..ce4a7bbd2 100644 --- a/loginutils/add-remove-shell.c +++ b/loginutils/add-remove-shell.c @@ -7,13 +7,6 @@ * Licensed under GPLv2 or later, see the LICENSE file in this source tree * for details. */ - -//applet:IF_ADD_SHELL( APPLET_ODDNAME(add-shell , add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, add_shell )) -//applet:IF_REMOVE_SHELL(APPLET_ODDNAME(remove-shell, add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, remove_shell)) - -//kbuild:lib-$(CONFIG_ADD_SHELL) += add-remove-shell.o -//kbuild:lib-$(CONFIG_REMOVE_SHELL) += add-remove-shell.o - //config:config ADD_SHELL //config: bool "add-shell" //config: default y if DESKTOP @@ -26,6 +19,12 @@ //config: help //config: Remove shells from /etc/shells. +//applet:IF_ADD_SHELL( APPLET_ODDNAME(add-shell , add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, add_shell )) +//applet:IF_REMOVE_SHELL(APPLET_ODDNAME(remove-shell, add_remove_shell, BB_DIR_USR_SBIN, BB_SUID_DROP, remove_shell)) + +//kbuild:lib-$(CONFIG_ADD_SHELL) += add-remove-shell.o +//kbuild:lib-$(CONFIG_REMOVE_SHELL) += add-remove-shell.o + //usage:#define add_shell_trivial_usage //usage: "SHELL..." //usage:#define add_shell_full_usage "\n\n" diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c index 260e337f3..4d4fc3f28 100644 --- a/loginutils/addgroup.c +++ b/loginutils/addgroup.c @@ -9,6 +9,31 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. * */ +//config:config ADDGROUP +//config: bool "addgroup" +//config: default y +//config: help +//config: Utility for creating a new group account. +//config: +//config:config FEATURE_ADDGROUP_LONG_OPTIONS +//config: bool "Enable long options" +//config: default y +//config: depends on ADDGROUP && LONG_OPTS +//config: help +//config: Support long options for the addgroup applet. +//config: +//config:config FEATURE_ADDUSER_TO_GROUP +//config: bool "Support for adding users to groups" +//config: default y +//config: depends on ADDGROUP +//config: help +//config: If called with two non-option arguments, +//config: addgroup will add an existing user to an +//config: existing group. + +//applet:IF_ADDGROUP(APPLET(addgroup, BB_DIR_USR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_ADDGROUP) += addgroup.o //usage:#define addgroup_trivial_usage //usage: "[-g GID] [-S] " IF_FEATURE_ADDUSER_TO_GROUP("[USER] ") "GROUP" diff --git a/loginutils/adduser.c b/loginutils/adduser.c index 605e3363f..608fb8437 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c @@ -7,6 +7,57 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config ADDUSER +//config: bool "adduser" +//config: default y +//config: help +//config: Utility for creating a new user account. +//config: +//config:config FEATURE_ADDUSER_LONG_OPTIONS +//config: bool "Enable long options" +//config: default y +//config: depends on ADDUSER && LONG_OPTS +//config: help +//config: Support long options for the adduser applet. +//config: +//config:config FEATURE_CHECK_NAMES +//config: bool "Enable sanity check on user/group names in adduser and addgroup" +//config: default n +//config: depends on ADDUSER || ADDGROUP +//config: help +//config: Enable sanity check on user and group names in adduser and addgroup. +//config: To avoid problems, the user or group name should consist only of +//config: letters, digits, underscores, periods, at signs and dashes, +//config: and not start with a dash (as defined by IEEE Std 1003.1-2001). +//config: For compatibility with Samba machine accounts "$" is also supported +//config: at the end of the user or group name. +//config: +//config:config LAST_ID +//config: int "Last valid uid or gid for adduser and addgroup" +//config: depends on ADDUSER || ADDGROUP +//config: default 60000 +//config: help +//config: Last valid uid or gid for adduser and addgroup +//config: +//config:config FIRST_SYSTEM_ID +//config: int "First valid system uid or gid for adduser and addgroup" +//config: depends on ADDUSER || ADDGROUP +//config: range 0 LAST_ID +//config: default 100 +//config: help +//config: First valid system uid or gid for adduser and addgroup +//config: +//config:config LAST_SYSTEM_ID +//config: int "Last valid system uid or gid for adduser and addgroup" +//config: depends on ADDUSER || ADDGROUP +//config: range FIRST_SYSTEM_ID LAST_ID +//config: default 999 +//config: help +//config: Last valid system uid or gid for adduser and addgroup + +//applet:IF_ADDUSER(APPLET(adduser, BB_DIR_USR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_ADDUSER) += adduser.o //usage:#define adduser_trivial_usage //usage: "[OPTIONS] USER [GROUP]" diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index 54ed73795..6c41d17be 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c @@ -5,7 +5,23 @@ * Written for SLIND (from passwd.c) by Alexander Shishkin * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -#include "libbb.h" +//config:config CHPASSWD +//config: bool "chpasswd" +//config: default y +//config: help +//config: Reads a file of user name and password pairs from standard input +//config: and uses this information to update a group of existing users. +//config: +//config:config FEATURE_DEFAULT_PASSWD_ALGO +//config: string "Default password encryption method (passwd -a, cryptpw -m parameter)" +//config: default "des" +//config: depends on PASSWD || CRYPTPW +//config: help +//config: Possible choices are "d[es]", "m[d5]", "s[ha256]" or "sha512". + +//applet:IF_CHPASSWD(APPLET(chpasswd, BB_DIR_USR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_CHPASSWD) += chpasswd.o //usage:#define chpasswd_trivial_usage //usage: IF_LONG_OPTS("[--md5|--encrypted]") IF_NOT_LONG_OPTS("[-m|-e]") @@ -22,6 +38,8 @@ //TODO: implement -c ALGO +#include "libbb.h" + #if ENABLE_LONG_OPTS static const char chpasswd_longopts[] ALIGN1 = "encrypted\0" No_argument "e" diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c index 29f0fbe91..55dcc2914 100644 --- a/loginutils/cryptpw.c +++ b/loginutils/cryptpw.c @@ -9,6 +9,18 @@ * * Licensed under GPLv2, see file LICENSE in this source tree. */ +//config:config CRYPTPW +//config: bool "cryptpw" +//config: default y +//config: help +//config: Encrypts the given password with the crypt(3) libc function +//config: using the given salt. Debian has this utility under mkpasswd +//config: name. Busybox provides mkpasswd as an alias for cryptpw. + +//applet:IF_CRYPTPW(APPLET(cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP)) +//applet:IF_CRYPTPW(APPLET_ODDNAME(mkpasswd, cryptpw, BB_DIR_USR_BIN, BB_SUID_DROP, mkpasswd)) + +//kbuild:lib-$(CONFIG_CRYPTPW) += cryptpw.o //usage:#define cryptpw_trivial_usage //usage: "[OPTIONS] [PASSWORD] [SALT]" diff --git a/loginutils/deluser.c b/loginutils/deluser.c index 110cd6310..7c3caf9e3 100644 --- a/loginutils/deluser.c +++ b/loginutils/deluser.c @@ -7,8 +7,32 @@ * Copyright (C) 2007 by Tito Ragusa * * Licensed under GPLv2, see file LICENSE in this source tree. - * */ +//config:config DELUSER +//config: bool "deluser" +//config: default y +//config: help +//config: Utility for deleting a user account. +//config: +//config:config DELGROUP +//config: bool "delgroup" +//config: default y +//config: help +//config: Utility for deleting a group account. +//config: +//config:config FEATURE_DEL_USER_FROM_GROUP +//config: bool "Support for removing users from groups" +//config: default y +//config: depends on DELGROUP +//config: help +//config: If called with two non-option arguments, deluser +//config: or delgroup will remove an user from a specified group. + +//applet:IF_DELUSER(APPLET(deluser, BB_DIR_USR_SBIN, BB_SUID_DROP)) +//applet:IF_DELGROUP(APPLET_ODDNAME(delgroup, deluser, BB_DIR_USR_SBIN, BB_SUID_DROP, delgroup)) + +//kbuild:lib-$(CONFIG_DELUSER) += deluser.o +//kbuild:lib-$(CONFIG_DELGROUP) += deluser.o //usage:#define deluser_trivial_usage //usage: IF_LONG_OPTS("[--remove-home] ") "USER" diff --git a/loginutils/getty.c b/loginutils/getty.c index 762d5c773..b10bdbdbf 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -21,6 +21,28 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config GETTY +//config: bool "getty" +//config: default y +//config: select FEATURE_SYSLOG +//config: help +//config: getty lets you log in on a tty. It is normally invoked by init. +//config: +//config: Note that you can save a few bytes by disabling it and +//config: using login applet directly. +//config: If you need to reset tty attributes before calling login, +//config: this script approximates getty: +//config: +//config: exec /dev/$1 2>&1 || exit 1 +//config: reset +//config: stty sane; stty ispeed 38400; stty ospeed 38400 +//config: printf "%s login: " "`hostname`" +//config: read -r login +//config: exec /bin/login "$login" + +//applet:IF_GETTY(APPLET(getty, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_GETTY) += getty.o #include "libbb.h" #include diff --git a/loginutils/login.c b/loginutils/login.c index 1700cfcb5..f1f04da19 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -2,6 +2,56 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config LOGIN +//config: bool "login" +//config: default y +//config: select FEATURE_SYSLOG +//config: help +//config: login is used when signing onto a system. +//config: +//config: Note that Busybox binary must be setuid root for this applet to +//config: work properly. +//config: +//config:config LOGIN_SESSION_AS_CHILD +//config: bool "Run logged in session in a child process" +//config: default y if PAM +//config: depends on LOGIN +//config: help +//config: Run the logged in session in a child process. This allows +//config: login to clean up things such as utmp entries or PAM sessions +//config: when the login session is complete. If you use PAM, you +//config: almost always would want this to be set to Y, else PAM session +//config: will not be cleaned up. +//config: +//config:config LOGIN_SCRIPTS +//config: bool "Support for login scripts" +//config: depends on LOGIN +//config: default y +//config: help +//config: Enable this if you want login to execute $LOGIN_PRE_SUID_SCRIPT +//config: just prior to switching from root to logged-in user. +//config: +//config:config FEATURE_NOLOGIN +//config: bool "Support for /etc/nologin" +//config: default y +//config: depends on LOGIN +//config: help +//config: The file /etc/nologin is used by (some versions of) login(1). +//config: If it exists, non-root logins are prohibited. +//config: +//config:config FEATURE_SECURETTY +//config: bool "Support for /etc/securetty" +//config: default y +//config: depends on LOGIN +//config: help +//config: The file /etc/securetty is used by (some versions of) login(1). +//config: The file contains the device names of tty lines (one per line, +//config: without leading /dev/) on which root is allowed to login. + +//applet:/* Needs to be run by root or be suid root - needs to change uid and gid: */ +//applet:IF_LOGIN(APPLET(login, BB_DIR_BIN, BB_SUID_REQUIRE)) + +//kbuild:lib-$(CONFIG_LOGIN) += login.o //usage:#define login_trivial_usage //usage: "[-p] [-h HOST] [[-f] USER]" diff --git a/loginutils/passwd.c b/loginutils/passwd.c index 150908932..73726d3e0 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -2,6 +2,30 @@ /* * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config PASSWD +//config: bool "passwd" +//config: default y +//config: select FEATURE_SYSLOG +//config: help +//config: passwd changes passwords for user and group accounts. A normal user +//config: may only change the password for his/her own account, the super user +//config: may change the password for any account. The administrator of a group +//config: may change the password for the group. +//config: +//config: Note that Busybox binary must be setuid root for this applet to +//config: work properly. +//config: +//config:config FEATURE_PASSWD_WEAK_CHECK +//config: bool "Check new passwords for weakness" +//config: default y +//config: depends on PASSWD +//config: help +//config: With this option passwd will refuse new passwords which are "weak". + +//applet:/* Needs to be run by root or be suid root - needs to change /etc/{passwd,shadow}: */ +//applet:IF_PASSWD(APPLET(passwd, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) + +//kbuild:lib-$(CONFIG_PASSWD) += passwd.o //usage:#define passwd_trivial_usage //usage: "[OPTIONS] [USER]" diff --git a/loginutils/su.c b/loginutils/su.c index f8125054a..3c0e8c100 100644 --- a/loginutils/su.c +++ b/loginutils/su.c @@ -4,9 +4,31 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -#include "libbb.h" -#include +//config:config SU +//config: bool "su" +//config: default y +//config: select FEATURE_SYSLOG +//config: help +//config: su is used to become another user during a login session. +//config: Invoked without a username, su defaults to becoming the super user. +//config: +//config: Note that Busybox binary must be setuid root for this applet to +//config: work properly. +//config: +//config:config FEATURE_SU_SYSLOG +//config: bool "Enable su to write to syslog" +//config: default y +//config: depends on SU +//config: +//config:config FEATURE_SU_CHECKS_SHELLS +//config: bool "Enable su to check user's shell to be listed in /etc/shells" +//config: depends on SU +//config: default y + +//applet:/* Needs to be run by root or be suid root - needs to change uid and gid: */ +//applet:IF_SU(APPLET(su, BB_DIR_BIN, BB_SUID_REQUIRE)) + +//kbuild:lib-$(CONFIG_SU) += su.o //usage:#define su_trivial_usage //usage: "[OPTIONS] [-] [USER]" @@ -17,6 +39,9 @@ //usage: "\n -c CMD Command to pass to 'sh -c'" //usage: "\n -s SH Shell to use instead of user's default" +#include "libbb.h" +#include + #if ENABLE_FEATURE_SU_CHECKS_SHELLS /* Return 1 if SHELL is a restricted shell (one not returned by * getusershell), else 0, meaning it is a standard shell. */ diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 2a2909937..19b1e304c 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -4,6 +4,18 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config SULOGIN +//config: bool "sulogin" +//config: default y +//config: select FEATURE_SYSLOG +//config: help +//config: sulogin is invoked when the system goes into single user +//config: mode (this is done through an entry in inittab). + +//applet:/* Needs to be run by root or be suid root - needs to change uid and gid: */ +//applet:IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o //usage:#define sulogin_trivial_usage //usage: "[-t N] [TTY]" diff --git a/loginutils/vlock.c b/loginutils/vlock.c index 44b14e6bc..52ae607c9 100644 --- a/loginutils/vlock.c +++ b/loginutils/vlock.c @@ -13,7 +13,21 @@ * minimalistic vlock. */ /* Fixed by Erik Andersen to do passwords the tinylogin way... - * It now works with md5, sha1, etc passwords. */ + * It now works with md5, sha1, etc passwords. + */ +//config:config VLOCK +//config: bool "vlock" +//config: default y +//config: help +//config: Build the "vlock" applet which allows you to lock (virtual) terminals. +//config: +//config: Note that Busybox binary must be setuid root for this applet to +//config: work properly. + +//applet:/* Needs to be run by root or be suid root - needs to change uid and gid: */ +//applet:IF_VLOCK(APPLET(vlock, BB_DIR_USR_BIN, BB_SUID_REQUIRE)) + +//kbuild:lib-$(CONFIG_VLOCK) += vlock.o //usage:#define vlock_trivial_usage //usage: "[-a]" -- cgit v1.2.3-55-g6feb From 36647abcc393daf2ddd7876e6f24d9497c2a84a1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 01:29:20 +0200 Subject: chattr,lsattr: shorten help message function old new delta packed_usage 30662 30645 -17 Signed-off-by: Denys Vlasenko --- e2fsprogs/chattr.c | 10 ++++------ e2fsprogs/lsattr.c | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c index c4e2415f8..043f39591 100644 --- a/e2fsprogs/chattr.c +++ b/e2fsprogs/chattr.c @@ -22,11 +22,9 @@ //usage:#define chattr_trivial_usage //usage: "[-R] [-+=AacDdijsStTu] [-v VERSION] [FILE]..." //usage:#define chattr_full_usage "\n\n" -//usage: "Change file attributes on an ext2 fs\n" +//usage: "Change ext2 file attributes\n" //usage: "\nModifiers:" -//usage: "\n - Remove attributes" -//usage: "\n + Add attributes" -//usage: "\n = Set attributes" +//usage: "\n -,+,= Remove/add/set attributes" //usage: "\nAttributes:" //usage: "\n A Don't track atime" //usage: "\n a Append mode only" @@ -36,11 +34,11 @@ //usage: "\n i Cannot be modified (immutable)" //usage: "\n j Write all data to journal first" //usage: "\n s Zero disk storage when deleted" -//usage: "\n S Write file contents synchronously" +//usage: "\n S Write synchronously" //usage: "\n t Disable tail-merging of partial blocks with other files" //usage: "\n u Allow file to be undeleted" //usage: "\n -R Recurse" -//usage: "\n -v Set the file's version/generation number" +//usage: "\n -v VER Set version/generation number" #include "libbb.h" #include "e2fs_lib.h" diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index 3a7dd6b56..d2348b5f7 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c @@ -23,12 +23,12 @@ //usage:#define lsattr_trivial_usage //usage: "[-Radlv] [FILE]..." //usage:#define lsattr_full_usage "\n\n" -//usage: "List file attributes on an ext2 fs\n" +//usage: "List ext2 file attributes\n" //usage: "\n -R Recurse" //usage: "\n -a Don't hide entries starting with ." //usage: "\n -d List directory entries instead of contents" //usage: "\n -l List long flag names" -//usage: "\n -v List the file's version/generation number" +//usage: "\n -v List version/generation number" #include "libbb.h" #include "e2fs_lib.h" -- cgit v1.2.3-55-g6feb From c4fb8c6ad52e8007c6fa07e40f043bb2e0c043d1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 02:24:14 +0200 Subject: fsck: do not use statics function old new delta fsck_main 1794 1812 +18 packed_usage 30662 30664 +2 kill_all_if_got_signal 60 62 +2 create_fs_device 158 160 +2 static.kill_sent 1 - -1 skip_root 1 - -1 serialize 1 - -1 parallel_root 1 - -1 noexecute 1 - -1 fs_type_negated 1 - -1 force_all_parallel 1 - -1 verbose 4 - -4 num_running 4 - -4 num_args 4 - -4 max_running 4 - -4 instance_list 4 - -4 fstype 4 - -4 fs_type_list 4 - -4 fs_type_flag 4 - -4 filesys_last 4 - -4 filesys_info 4 - -4 args 4 - -4 wait_one 309 300 -9 ignore 196 174 -22 ------------------------------------------------------------------------------ (add/remove: 0/18 grow/shrink: 4/2 up/down: 24/-82) Total: -58 bytes text data bss dec hex filename 938527 932 17448 956907 e99eb busybox_old 938487 932 17392 956811 e998b busybox_unstripped Signed-off-by: Denys Vlasenko --- e2fsprogs/fsck.c | 261 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 133 insertions(+), 128 deletions(-) diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index adaf0c538..627d2be31 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c @@ -46,7 +46,7 @@ //kbuild:lib-$(CONFIG_FSCK) += fsck.o //usage:#define fsck_trivial_usage -//usage: "[-ANPRTV] [-C FD] [-t FSTYPE] [FS_OPTS] [BLOCKDEV]..." +//usage: "[-ANPRTV] [-t FSTYPE] [FS_OPTS] [BLOCKDEV]..." //usage:#define fsck_full_usage "\n\n" //usage: "Check and repair filesystems\n" //usage: "\n -A Walk /etc/fstab and check all filesystems" @@ -55,7 +55,8 @@ //usage: "\n -R With -A, skip the root filesystem" //usage: "\n -T Don't show title on startup" //usage: "\n -V Verbose" -//usage: "\n -C n Write status information to specified filedescriptor" +//DO_PROGRESS_INDICATOR is off: +////usage: "\n -C FD Write status information to specified file descriptor" //usage: "\n -t TYPE List of filesystem types to check" #include "libbb.h" @@ -136,35 +137,42 @@ static const char really_wanted[] ALIGN1 = #define BASE_MD "/dev/md" -static char **args; -static int num_args; -static int verbose; +struct globals { + char **args; + int num_args; + int verbose; #define FS_TYPE_FLAG_NORMAL 0 #define FS_TYPE_FLAG_OPT 1 #define FS_TYPE_FLAG_NEGOPT 2 -static char **fs_type_list; -static uint8_t *fs_type_flag; -static smallint fs_type_negated; - -static smallint noexecute; -static smallint serialize; -static smallint skip_root; -/* static smallint like_mount; */ -static smallint parallel_root; -static smallint force_all_parallel; + char **fs_type_list; + uint8_t *fs_type_flag; + smallint fs_type_negated; + + smallint noexecute; + smallint serialize; + smallint skip_root; + /* smallint like_mount; */ + smallint parallel_root; + smallint force_all_parallel; + smallint kill_sent; #if DO_PROGRESS_INDICATOR -static smallint progress; -static int progress_fd; + smallint progress; + int progress_fd; #endif -static int num_running; -static int max_running; -static char *fstype; -static struct fs_info *filesys_info; -static struct fs_info *filesys_last; -static struct fsck_instance *instance_list; + int num_running; + int max_running; + char *fstype; + struct fs_info *filesys_info; + struct fs_info *filesys_last; + struct fsck_instance *instance_list; +} FIX_ALIASING; +#define G (*(struct globals*)&bb_common_bufsiz1) +#define INIT_G() do { \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ +} while (0) /* * Return the "base device" given a particular device; this is used to @@ -313,11 +321,11 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt, /*fs->flags = 0; */ /*fs->next = NULL; */ - if (!filesys_info) - filesys_info = fs; + if (!G.filesys_info) + G.filesys_info = fs; else - filesys_last->next = fs; - filesys_last = fs; + G.filesys_last->next = fs; + G.filesys_last = fs; return fs; } @@ -327,6 +335,7 @@ static void load_fs_info(const char *filename) { FILE *fstab; struct mntent mte; + char buf[1024]; fstab = setmntent(filename, "r"); if (!fstab) { @@ -335,7 +344,7 @@ static void load_fs_info(const char *filename) } // Loop through entries - while (getmntent_r(fstab, &mte, bb_common_bufsiz1, COMMON_BUFSIZE)) { + while (getmntent_r(fstab, &mte, buf, sizeof(buf))) { //bb_info_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir, // mte.mnt_type, mte.mnt_opts, // mte.mnt_passno); @@ -351,7 +360,7 @@ static struct fs_info *lookup(char *filesys) { struct fs_info *fs; - for (fs = filesys_info; fs; fs = fs->next) { + for (fs = G.filesys_info; fs; fs = fs->next) { if (strcmp(filesys, fs->device) == 0 || (fs->mountpt && strcmp(filesys, fs->mountpt) == 0) ) @@ -366,7 +375,7 @@ static int progress_active(void) { struct fsck_instance *inst; - for (inst = instance_list; inst; inst = inst->next) { + for (inst = G.instance_list; inst; inst = inst->next) { if (inst->flags & FLAG_DONE) continue; if (inst->flags & FLAG_PROGRESS) @@ -382,19 +391,17 @@ static int progress_active(void) */ static void kill_all_if_got_signal(void) { - static smallint kill_sent; - struct fsck_instance *inst; - if (!bb_got_signal || kill_sent) + if (!bb_got_signal || G.kill_sent) return; - for (inst = instance_list; inst; inst = inst->next) { + for (inst = G.instance_list; inst; inst = inst->next) { if (inst->flags & FLAG_DONE) continue; kill(inst->pid, SIGTERM); } - kill_sent = 1; + G.kill_sent = 1; } /* @@ -409,9 +416,9 @@ static int wait_one(int flags) struct fsck_instance *inst, *prev; pid_t pid; - if (!instance_list) + if (!G.instance_list) return -1; - /* if (noexecute) { already returned -1; } */ + /* if (G.noexecute) { already returned -1; } */ while (1) { pid = waitpid(-1, &status, flags); @@ -429,7 +436,7 @@ static int wait_one(int flags) continue; } prev = NULL; - inst = instance_list; + inst = G.instance_list; do { if (inst->pid == pid) goto child_died; @@ -439,9 +446,8 @@ static int wait_one(int flags) } child_died: - if (WIFEXITED(status)) - status = WEXITSTATUS(status); - else if (WIFSIGNALED(status)) { + status = WEXITSTATUS(status); + if (WIFSIGNALED(status)) { sig = WTERMSIG(status); status = EXIT_UNCORRECTED; if (sig != SIGINT) { @@ -450,16 +456,12 @@ static int wait_one(int flags) inst->prog, inst->device, sig); status = EXIT_ERROR; } - } else { - printf("%s %s: status is %x, should never happen\n", - inst->prog, inst->device, status); - status = EXIT_ERROR; } #if DO_PROGRESS_INDICATOR if (progress && (inst->flags & FLAG_PROGRESS) && !progress_active()) { struct fsck_instance *inst2; - for (inst2 = instance_list; inst2; inst2 = inst2->next) { + for (inst2 = G.instance_list; inst2; inst2 = inst2->next) { if (inst2->flags & FLAG_DONE) continue; if (strcmp(inst2->type, "ext2") != 0 @@ -486,11 +488,11 @@ static int wait_one(int flags) if (prev) prev->next = inst->next; else - instance_list = inst->next; - if (verbose > 1) + G.instance_list = inst->next; + if (G.verbose > 1) printf("Finished with %s (exit status %d)\n", inst->device, status); - num_running--; + G.num_running--; free_instance(inst); return status; @@ -526,51 +528,51 @@ static void execute(const char *type, const char *device, struct fsck_instance *inst; pid_t pid; - args[0] = xasprintf("fsck.%s", type); + G.args[0] = xasprintf("fsck.%s", type); #if DO_PROGRESS_INDICATOR if (progress && !progress_active()) { if (strcmp(type, "ext2") == 0 || strcmp(type, "ext3") == 0 ) { - args[XXX] = xasprintf("-C%d", progress_fd); /* 1 */ + G.args[XXX] = xasprintf("-C%d", progress_fd); /* 1 */ inst->flags |= FLAG_PROGRESS; } } #endif - args[num_args - 2] = (char*)device; - /* args[num_args - 1] = NULL; - already is */ + G.args[G.num_args - 2] = (char*)device; + /* G.args[G.num_args - 1] = NULL; - already is */ - if (verbose || noexecute) { - printf("[%s (%d) -- %s]", args[0], num_running, + if (G.verbose || G.noexecute) { + printf("[%s (%d) -- %s]", G.args[0], G.num_running, mntpt ? mntpt : device); - for (i = 0; args[i]; i++) - printf(" %s", args[i]); + for (i = 0; G.args[i]; i++) + printf(" %s", G.args[i]); bb_putchar('\n'); } /* Fork and execute the correct program. */ pid = -1; - if (!noexecute) { - pid = spawn(args); + if (!G.noexecute) { + pid = spawn(G.args); if (pid < 0) - bb_simple_perror_msg(args[0]); + bb_simple_perror_msg(G.args[0]); } #if DO_PROGRESS_INDICATOR - free(args[XXX]); + free(G.args[XXX]); #endif /* No child, so don't record an instance */ if (pid <= 0) { - free(args[0]); + free(G.args[0]); return; } inst = xzalloc(sizeof(*inst)); inst->pid = pid; - inst->prog = args[0]; + inst->prog = G.args[0]; inst->device = xstrdup(device); inst->base_device = base_device(device); #if DO_PROGRESS_INDICATOR @@ -579,8 +581,8 @@ static void execute(const char *type, const char *device, /* Add to the list of running fsck's. * (was adding to the end, but adding to the front is simpler...) */ - inst->next = instance_list; - instance_list = inst; + inst->next = G.instance_list; + G.instance_list = inst; } /* @@ -599,27 +601,27 @@ static void fsck_device(struct fs_info *fs /*, int interactive */) if (strcmp(fs->type, "auto") != 0) { type = fs->type; - if (verbose > 2) + if (G.verbose > 2) bb_info_msg("using filesystem type '%s' %s", type, "from fstab"); - } else if (fstype - && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */ - && !is_prefixed_with(fstype, "opts=") - && !is_prefixed_with(fstype, "loop") - && !strchr(fstype, ',') + } else if (G.fstype + && (G.fstype[0] != 'n' || G.fstype[1] != 'o') /* != "no" */ + && !is_prefixed_with(G.fstype, "opts=") + && !is_prefixed_with(G.fstype, "loop") + && !strchr(G.fstype, ',') ) { - type = fstype; - if (verbose > 2) + type = G.fstype; + if (G.verbose > 2) bb_info_msg("using filesystem type '%s' %s", type, "from -t"); } else { type = "auto"; - if (verbose > 2) + if (G.verbose > 2) bb_info_msg("using filesystem type '%s' %s", type, "(default)"); } - num_running++; + G.num_running++; execute(type, fs->device, fs->mountpt /*, interactive */); } @@ -632,13 +634,13 @@ static int device_already_active(char *device) struct fsck_instance *inst; char *base; - if (force_all_parallel) + if (G.force_all_parallel) return 0; #ifdef BASE_MD /* Don't check a soft raid disk with any other disk */ - if (instance_list - && (is_prefixed_with(instance_list->device, BASE_MD) + if (G.instance_list + && (is_prefixed_with(G.instance_list->device, BASE_MD) || is_prefixed_with(device, BASE_MD)) ) { return 1; @@ -651,9 +653,9 @@ static int device_already_active(char *device) * already active if there are any fsck instances running. */ if (!base) - return (instance_list != NULL); + return (G.instance_list != NULL); - for (inst = instance_list; inst; inst = inst->next) { + for (inst = G.instance_list; inst; inst = inst->next) { if (!inst->base_device || !strcmp(base, inst->base_device)) { free(base); return 1; @@ -698,17 +700,17 @@ static int fs_match(struct fs_info *fs) int n, ret, checked_type; char *cp; - if (!fs_type_list) + if (!G.fs_type_list) return 1; ret = 0; checked_type = 0; n = 0; while (1) { - cp = fs_type_list[n]; + cp = G.fs_type_list[n]; if (!cp) break; - switch (fs_type_flag[n]) { + switch (G.fs_type_flag[n]) { case FS_TYPE_FLAG_NORMAL: checked_type++; if (strcmp(cp, fs->type) == 0) @@ -728,7 +730,7 @@ static int fs_match(struct fs_info *fs) if (checked_type == 0) return 1; - return (fs_type_negated ? !ret : ret); + return (G.fs_type_negated ? !ret : ret); } /* Check if we should ignore this filesystem. */ @@ -764,7 +766,7 @@ static int check_all(void) smallint pass_done; int passno; - if (verbose) + if (G.verbose) puts("Checking all filesystems"); /* @@ -772,17 +774,17 @@ static int check_all(void) * which should be ignored as done, and resolve any "auto" * filesystem types (done as a side-effect of calling ignore()). */ - for (fs = filesys_info; fs; fs = fs->next) + for (fs = G.filesys_info; fs; fs = fs->next) if (ignore(fs)) fs->flags |= FLAG_DONE; /* * Find and check the root filesystem. */ - if (!parallel_root) { - for (fs = filesys_info; fs; fs = fs->next) { + if (!G.parallel_root) { + for (fs = G.filesys_info; fs; fs = fs->next) { if (LONE_CHAR(fs->mountpt, '/')) { - if (!skip_root && !ignore(fs)) { + if (!G.skip_root && !ignore(fs)) { fsck_device(fs /*, 1*/); status |= wait_many(FLAG_WAIT_ALL); if (status > EXIT_NONDESTRUCT) @@ -798,8 +800,8 @@ static int check_all(void) * filesystem listed twice. * "Skip root" will skip _all_ root entries. */ - if (skip_root) - for (fs = filesys_info; fs; fs = fs->next) + if (G.skip_root) + for (fs = G.filesys_info; fs; fs = fs->next) if (LONE_CHAR(fs->mountpt, '/')) fs->flags |= FLAG_DONE; @@ -809,7 +811,7 @@ static int check_all(void) not_done_yet = 0; pass_done = 1; - for (fs = filesys_info; fs; fs = fs->next) { + for (fs = G.filesys_info; fs; fs = fs->next) { if (bb_got_signal) break; if (fs->flags & FLAG_DONE) @@ -835,7 +837,7 @@ static int check_all(void) /* * Spawn off the fsck process */ - fsck_device(fs /*, serialize*/); + fsck_device(fs /*, G.serialize*/); fs->flags |= FLAG_DONE; /* @@ -843,8 +845,8 @@ static int check_all(void) * have a limit on the number of fsck's extant * at one time, apply that limit. */ - if (serialize - || (max_running && (num_running >= max_running)) + if (G.serialize + || (G.num_running >= G.max_running) ) { pass_done = 0; break; @@ -852,12 +854,12 @@ static int check_all(void) } if (bb_got_signal) break; - if (verbose > 1) + if (G.verbose > 1) printf("--waiting-- (pass %d)\n", passno); status |= wait_many(pass_done ? FLAG_WAIT_ALL : FLAG_WAIT_ATLEAST_ONE); if (pass_done) { - if (verbose > 1) + if (G.verbose > 1) puts("----------------------------------"); passno++; } else @@ -885,9 +887,9 @@ static void compile_fs_type(char *fs_type) s++; } - fs_type_list = xzalloc(num * sizeof(fs_type_list[0])); - fs_type_flag = xzalloc(num * sizeof(fs_type_flag[0])); - fs_type_negated = -1; /* not yet known is it negated or not */ + G.fs_type_list = xzalloc(num * sizeof(G.fs_type_list[0])); + G.fs_type_flag = xzalloc(num * sizeof(G.fs_type_flag[0])); + G.fs_type_negated = -1; /* not yet known is it negated or not */ num = 0; s = fs_type; @@ -909,18 +911,18 @@ static void compile_fs_type(char *fs_type) if (is_prefixed_with(s, "opts=")) { s += 5; loop_special_case: - fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT; + G.fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT; } else { - if (fs_type_negated == -1) - fs_type_negated = negate; - if (fs_type_negated != negate) + if (G.fs_type_negated == -1) + G.fs_type_negated = negate; + if (G.fs_type_negated != negate) bb_error_msg_and_die( "either all or none of the filesystem types passed to -t must be prefixed " "with 'no' or '!'"); } - comma = strchr(s, ','); - fs_type_list[num++] = comma ? xstrndup(s, comma-s) : xstrdup(s); - if (!comma) + comma = strchrnul(s, ','); + G.fs_type_list[num++] = xstrndup(s, comma-s); + if (*comma == '\0') break; s = comma + 1; } @@ -928,8 +930,8 @@ static void compile_fs_type(char *fs_type) static char **new_args(void) { - args = xrealloc_vector(args, 2, num_args); - return &args[num_args++]; + G.args = xrealloc_vector(G.args, 2, G.num_args); + return &G.args[G.num_args++]; } int fsck_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; @@ -946,6 +948,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) smallint doall; smallint notitle; + INIT_G(); + /* we want wait() to be interruptible */ signal_no_SA_RESTART_empty_mask(SIGINT, record_signo); signal_no_SA_RESTART_empty_mask(SIGTERM, record_signo); @@ -955,8 +959,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) opts_for_fsck = doall = notitle = 0; devices = NULL; num_devices = 0; - new_args(); /* args[0] = NULL, will be replaced by fsck. */ - /* instance_list = NULL; - in bss, so already zeroed */ + new_args(); /* G.args[0] = NULL, will be replaced by fsck. */ + /* G.instance_list = NULL; - in bss, so already zeroed */ while (*++argv) { int j; @@ -1005,13 +1009,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) goto next_arg; #endif case 'V': - verbose++; + G.verbose++; break; case 'N': - noexecute = 1; + G.noexecute = 1; break; case 'R': - skip_root = 1; + G.skip_root = 1; break; case 'T': notitle = 1; @@ -1020,13 +1024,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) like_mount = 1; break; */ case 'P': - parallel_root = 1; + G.parallel_root = 1; break; case 's': - serialize = 1; + G.serialize = 1; break; case 't': - if (fstype) + if (G.fstype) bb_show_usage(); if (arg[++j]) tmp = &arg[j]; @@ -1034,8 +1038,8 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) tmp = *argv; else bb_show_usage(); - fstype = xstrdup(tmp); - compile_fs_type(fstype); + G.fstype = xstrdup(tmp); + compile_fs_type(G.fstype); goto next_arg; case '?': bb_show_usage(); @@ -1056,12 +1060,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) } } if (getenv("FSCK_FORCE_ALL_PARALLEL")) - force_all_parallel = 1; + G.force_all_parallel = 1; tmp = getenv("FSCK_MAX_INST"); + G.max_running = INT_MAX; if (tmp) - max_running = xatoi(tmp); - new_args(); /* args[num_args - 2] will be replaced by */ - new_args(); /* args[num_args - 1] is the last, NULL element */ + G.max_running = xatoi(tmp); + new_args(); /* G.args[G.num_args - 2] will be replaced by */ + new_args(); /* G.args[G.num_args - 1] is the last, NULL element */ if (!notitle) puts("fsck (busybox "BB_VER", "BB_BT")"); @@ -1073,10 +1078,10 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) fstab = "/etc/fstab"; load_fs_info(fstab); - /*interactive = (num_devices == 1) | serialize;*/ + /*interactive = (num_devices == 1) | G.serialize;*/ if (num_devices == 0) - /*interactive =*/ serialize = doall = 1; + /*interactive =*/ G.serialize = doall = 1; if (doall) return check_all(); @@ -1092,13 +1097,13 @@ int fsck_main(int argc UNUSED_PARAM, char **argv) fs = create_fs_device(devices[i], "", "auto", NULL, -1); fsck_device(fs /*, interactive */); - if (serialize - || (max_running && (num_running >= max_running)) + if (G.serialize + || (G.num_running >= G.max_running) ) { int exit_status = wait_one(0); if (exit_status >= 0) status |= exit_status; - if (verbose > 1) + if (G.verbose > 1) puts("----------------------------------"); } } -- cgit v1.2.3-55-g6feb From f3d58a29be7cbf5c0bf94f1a12ac747f706b3d99 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 02:51:56 +0200 Subject: od: get rid of (almost all) statics function old new delta od_main 2565 2600 +35 check_and_close 113 115 +2 static.prev_pair_equal 1 - -1 static.first 1 - -1 exit_code 1 - -1 string_min 4 - -4 n_specs 4 - -4 in_stream 4 - -4 format_address 4 - -4 file_list 4 - -4 bytes_per_block 4 - -4 get_lcm 120 115 -5 pseudo_offset 8 - -8 ------------------------------------------------------------------------------ (add/remove: 0/10 grow/shrink: 2/1 up/down: 37/-40) Total: -3 bytes text data bss dec hex filename 938487 932 17392 956811 e998b busybox_old 938519 924 17360 956803 e9983 busybox_unstripped Signed-off-by: Denys Vlasenko --- coreutils/od_bloaty.c | 230 ++++++++++++++++++++++++++------------------------ 1 file changed, 122 insertions(+), 108 deletions(-) diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index ab7ea997d..f47f84b54 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -66,7 +66,7 @@ enum { /* -S was -s and also had optional parameter */ \ /* but in coreutils 6.3 it was renamed and now has */ \ /* _mandatory_ parameter */ \ - &str_A, &str_N, &str_j, &lst_t, &str_S, &bytes_per_block) + &str_A, &str_N, &str_j, &lst_t, &str_S, &G.bytes_per_block) /* Check for 0x7f is a coreutils 6.3 addition */ @@ -174,38 +174,52 @@ struct ERR_width_bytes_has_bad_size { char ERR_width_bytes_has_bad_size[ARRAY_SIZE(width_bytes) == N_SIZE_SPECS ? 1 : -1]; }; -static smallint exit_code; +struct globals { + smallint exit_code; -static unsigned string_min; + unsigned string_min; -/* An array of specs describing how to format each input block. */ -static size_t n_specs; -static struct tspec *spec; + /* An array of specs describing how to format each input block. */ + unsigned n_specs; + struct tspec *spec; -/* Function that accepts an address and an optional following char, - and prints the address and char to stdout. */ -static void (*format_address)(off_t, char); -/* The difference between the old-style pseudo starting address and - the number of bytes to skip. */ + /* Function that accepts an address and an optional following char, + and prints the address and char to stdout. */ + void (*format_address)(off_t, char); + + /* The difference between the old-style pseudo starting address and + the number of bytes to skip. */ #if ENABLE_LONG_OPTS -static off_t pseudo_offset; -#else -enum { pseudo_offset = 0 }; + off_t pseudo_offset; +# define G_pseudo_offset G.pseudo_offset #endif -/* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all - input is formatted. */ - -/* The number of input bytes formatted per output line. It must be - a multiple of the least common multiple of the sizes associated with - the specified output types. It should be as large as possible, but - no larger than 16 -- unless specified with the -w option. */ -static unsigned bytes_per_block = 32; /* have to use unsigned, not size_t */ - -/* A NULL-terminated list of the file-arguments from the command line. */ -static const char *const *file_list; + /* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all + input is formatted. */ + + /* The number of input bytes formatted per output line. It must be + a multiple of the least common multiple of the sizes associated with + the specified output types. It should be as large as possible, but + no larger than 16 -- unless specified with the -w option. */ + unsigned bytes_per_block; /* have to use unsigned, not size_t */ + + /* A NULL-terminated list of the file-arguments from the command line. */ + const char *const *file_list; + + /* The input stream associated with the current file. */ + FILE *in_stream; + + bool not_first; + bool prev_pair_equal; +} FIX_ALIASING; +#if !ENABLE_LONG_OPTS +enum { G_pseudo_offset = 0 }; +#endif +#define G (*(struct globals*)&bb_common_bufsiz1) +#define INIT_G() do { \ + BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ + G.bytes_per_block = 32; \ +} while (0) -/* The input stream associated with the current file. */ -static FILE *in_stream; #define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t) static const unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = { @@ -476,17 +490,17 @@ static void open_next_file(void) { while (1) { - if (!*file_list) + if (!*G.file_list) return; - in_stream = fopen_or_warn_stdin(*file_list++); - if (in_stream) { + G.in_stream = fopen_or_warn_stdin(*G.file_list++); + if (G.in_stream) { break; } - exit_code = 1; + G.exit_code = 1; } if ((option_mask32 & (OPT_N|OPT_S)) == OPT_N) - setbuf(in_stream, NULL); + setbuf(G.in_stream, NULL); } /* Test whether there have been errors on in_stream, and close it if @@ -499,16 +513,16 @@ open_next_file(void) static void check_and_close(void) { - if (in_stream) { - if (ferror(in_stream)) { - bb_error_msg("%s: read error", (in_stream == stdin) + if (G.in_stream) { + if (ferror(G.in_stream)) { + bb_error_msg("%s: read error", (G.in_stream == stdin) ? bb_msg_standard_input - : file_list[-1] + : G.file_list[-1] ); - exit_code = 1; + G.exit_code = 1; } - fclose_if_not_stdin(in_stream); - in_stream = NULL; + fclose_if_not_stdin(G.in_stream); + G.in_stream = NULL; } if (ferror(stdout)) { @@ -744,9 +758,9 @@ decode_format_string(const char *s) assert(s != next); s = next; - spec = xrealloc_vector(spec, 4, n_specs); - memcpy(&spec[n_specs], &tspec, sizeof(spec[0])); - n_specs++; + G.spec = xrealloc_vector(G.spec, 4, G.n_specs); + memcpy(&G.spec[G.n_specs], &tspec, sizeof(G.spec[0])); + G.n_specs++; } } @@ -763,7 +777,7 @@ skip(off_t n_skip) if (n_skip == 0) return; - while (in_stream) { /* !EOF */ + while (G.in_stream) { /* !EOF */ struct stat file_stats; /* First try seeking. For large offsets, this extra work is @@ -781,15 +795,15 @@ skip(off_t n_skip) If the number of bytes left to skip is at least as large as the size of the current file, we can decrement n_skip and go on to the next file. */ - if (fstat(fileno(in_stream), &file_stats) == 0 + if (fstat(fileno(G.in_stream), &file_stats) == 0 && S_ISREG(file_stats.st_mode) && file_stats.st_size > 0 ) { if (file_stats.st_size < n_skip) { n_skip -= file_stats.st_size; /* take "check & close / open_next" route */ } else { - if (fseeko(in_stream, n_skip, SEEK_CUR) != 0) - exit_code = 1; + if (fseeko(G.in_stream, n_skip, SEEK_CUR) != 0) + G.exit_code = 1; return; } } else { @@ -802,7 +816,7 @@ skip(off_t n_skip) while (n_skip > 0) { if (n_skip < n_bytes_to_read) n_bytes_to_read = n_skip; - n_bytes_read = fread(buf, 1, n_bytes_to_read, in_stream); + n_bytes_read = fread(buf, 1, n_bytes_to_read, G.in_stream); n_skip -= n_bytes_read; if (n_bytes_read != n_bytes_to_read) break; /* EOF on this file or error */ @@ -855,7 +869,7 @@ static void format_address_label(off_t address, char c) { format_address_std(address, ' '); - format_address_paren(address + pseudo_offset, c); + format_address_paren(address + G_pseudo_offset, c); } #endif @@ -886,36 +900,34 @@ static void write_block(off_t current_offset, size_t n_bytes, const char *prev_block, const char *curr_block) { - static char first = 1; - static char prev_pair_equal = 0; - size_t i; + unsigned i; if (!(option_mask32 & OPT_v) - && !first - && n_bytes == bytes_per_block - && memcmp(prev_block, curr_block, bytes_per_block) == 0 + && G.not_first + && n_bytes == G.bytes_per_block + && memcmp(prev_block, curr_block, G.bytes_per_block) == 0 ) { - if (prev_pair_equal) { + if (G.prev_pair_equal) { /* The two preceding blocks were equal, and the current block is the same as the last one, so print nothing. */ } else { puts("*"); - prev_pair_equal = 1; + G.prev_pair_equal = 1; } } else { - first = 0; - prev_pair_equal = 0; - for (i = 0; i < n_specs; i++) { + G.not_first = 1; + G.prev_pair_equal = 0; + for (i = 0; i < G.n_specs; i++) { if (i == 0) - format_address(current_offset, '\0'); + G.format_address(current_offset, '\0'); else printf("%*s", address_pad_len_char - '0', ""); - (*spec[i].print_function) (n_bytes, curr_block, spec[i].fmt_string); - if (spec[i].hexl_mode_trailer) { + (*G.spec[i].print_function) (n_bytes, curr_block, G.spec[i].fmt_string); + if (G.spec[i].hexl_mode_trailer) { /* space-pad out to full line width, then dump the trailer */ - unsigned datum_width = width_bytes[spec[i].size]; - unsigned blank_fields = (bytes_per_block - n_bytes) / datum_width; - unsigned field_width = spec[i].field_width + 1; + unsigned datum_width = width_bytes[G.spec[i].size]; + unsigned blank_fields = (G.bytes_per_block - n_bytes) / datum_width; + unsigned field_width = G.spec[i].field_width + 1; printf("%*s", blank_fields * field_width, ""); dump_hexl_mode_trailer(n_bytes, curr_block); } @@ -927,19 +939,19 @@ write_block(off_t current_offset, size_t n_bytes, static void read_block(size_t n, char *block, size_t *n_bytes_in_buffer) { - assert(0 < n && n <= bytes_per_block); + assert(0 < n && n <= G.bytes_per_block); *n_bytes_in_buffer = 0; if (n == 0) return; - while (in_stream != NULL) { /* EOF. */ + while (G.in_stream != NULL) { /* EOF. */ size_t n_needed; size_t n_read; n_needed = n - *n_bytes_in_buffer; - n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, in_stream); + n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, G.in_stream); *n_bytes_in_buffer += n_read; if (n_read == n_needed) break; @@ -958,8 +970,8 @@ get_lcm(void) size_t i; int l_c_m = 1; - for (i = 0; i < n_specs; i++) - l_c_m = lcm(l_c_m, width_bytes[(int) spec[i].size]); + for (i = 0; i < G.n_specs; i++) + l_c_m = lcm(l_c_m, width_bytes[(int) G.spec[i].size]); return l_c_m; } @@ -980,8 +992,8 @@ dump(off_t current_offset, off_t end_offset) int idx; size_t n_bytes_read; - block[0] = xmalloc(2 * bytes_per_block); - block[1] = block[0] + bytes_per_block; + block[0] = xmalloc(2 * G.bytes_per_block); + block[1] = block[0] + G.bytes_per_block; idx = 0; if (option_mask32 & OPT_N) { @@ -991,21 +1003,21 @@ dump(off_t current_offset, off_t end_offset) n_bytes_read = 0; break; } - n_needed = MIN(end_offset - current_offset, (off_t) bytes_per_block); + n_needed = MIN(end_offset - current_offset, (off_t) G.bytes_per_block); read_block(n_needed, block[idx], &n_bytes_read); - if (n_bytes_read < bytes_per_block) + if (n_bytes_read < G.bytes_per_block) break; - assert(n_bytes_read == bytes_per_block); + assert(n_bytes_read == G.bytes_per_block); write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]); current_offset += n_bytes_read; idx ^= 1; } } else { while (1) { - read_block(bytes_per_block, block[idx], &n_bytes_read); - if (n_bytes_read < bytes_per_block) + read_block(G.bytes_per_block, block[idx], &n_bytes_read); + if (n_bytes_read < G.bytes_per_block) break; - assert(n_bytes_read == bytes_per_block); + assert(n_bytes_read == G.bytes_per_block); write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]); current_offset += n_bytes_read; idx ^= 1; @@ -1028,7 +1040,7 @@ dump(off_t current_offset, off_t end_offset) current_offset += n_bytes_read; } - format_address(current_offset, '\n'); + G.format_address(current_offset, '\n'); if ((option_mask32 & OPT_N) && current_offset >= end_offset) check_and_close(); @@ -1059,16 +1071,16 @@ dump(off_t current_offset, off_t end_offset) static void dump_strings(off_t address, off_t end_offset) { - unsigned bufsize = MAX(100, string_min); + unsigned bufsize = MAX(100, G.string_min); unsigned char *buf = xmalloc(bufsize); while (1) { size_t i; int c; - /* See if the next 'string_min' chars are all printing chars. */ + /* See if the next 'G.string_min' chars are all printing chars. */ tryline: - if ((option_mask32 & OPT_N) && (end_offset - string_min <= address)) + if ((option_mask32 & OPT_N) && (end_offset - G.string_min <= address)) break; i = 0; while (!(option_mask32 & OPT_N) || address < end_offset) { @@ -1077,8 +1089,8 @@ dump_strings(off_t address, off_t end_offset) buf = xrealloc(buf, bufsize); } - while (in_stream) { /* !EOF */ - c = fgetc(in_stream); + while (G.in_stream) { /* !EOF */ + c = fgetc(G.in_stream); if (c != EOF) goto got_char; check_and_close(); @@ -1095,12 +1107,12 @@ dump_strings(off_t address, off_t end_offset) buf[i++] = c; /* String continues; store it all. */ } - if (i < string_min) /* Too short! */ + if (i < G.string_min) /* Too short! */ goto tryline; /* If we get here, the string is all printable and NUL-terminated */ buf[i] = 0; - format_address(address - i - 1, ' '); + G.format_address(address - i - 1, ' '); for (i = 0; (c = buf[i]); i++) { switch (c) { @@ -1118,7 +1130,7 @@ dump_strings(off_t address, off_t end_offset) } /* We reach this point only if we search through - (max_bytes_to_format - string_min) bytes before reaching EOF. */ + (max_bytes_to_format - G.string_min) bytes before reaching EOF. */ check_and_close(); ret: free(buf); @@ -1190,8 +1202,10 @@ int od_main(int argc UNUSED_PARAM, char **argv) /* The maximum number of bytes that will be formatted. */ off_t max_bytes_to_format = 0; - spec = NULL; - format_address = format_address_std; + INIT_G(); + + /*G.spec = NULL; - already is */ + G.format_address = format_address_std; address_base_char = 'o'; address_pad_len_char = '7'; @@ -1217,7 +1231,7 @@ int od_main(int argc UNUSED_PARAM, char **argv) bb_error_msg_and_die("bad output address radix " "'%c' (must be [doxn])", str_A[0]); pos = p - doxn; - if (pos == 3) format_address = format_address_none; + if (pos == 3) G.format_address = format_address_none; address_base_char = doxn_address_base_char[pos]; address_pad_len_char = doxn_address_pad_len_char[pos]; } @@ -1240,11 +1254,11 @@ int od_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_x) decode_format_string("x2"); if (opt & OPT_s) decode_format_string("d2"); if (opt & OPT_S) { - string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); + G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes); } // Bloat: - //if ((option_mask32 & OPT_S) && n_specs > 0) + //if ((option_mask32 & OPT_S) && G.n_specs > 0) // bb_error_msg_and_die("no type may be specified when dumping strings"); /* If the --traditional option is used, there may be from @@ -1300,14 +1314,14 @@ int od_main(int argc UNUSED_PARAM, char **argv) } if (pseudo_start >= 0) { - if (format_address == format_address_none) { + if (G.format_address == format_address_none) { address_base_char = 'o'; address_pad_len_char = '7'; - format_address = format_address_paren; + G.format_address = format_address_paren; } else { - format_address = format_address_label; + G.format_address = format_address_label; } - pseudo_offset = pseudo_start - n_bytes_to_skip; + G_pseudo_offset = pseudo_start - n_bytes_to_skip; } } /* else: od --traditional (without args) */ @@ -1320,45 +1334,45 @@ int od_main(int argc UNUSED_PARAM, char **argv) bb_error_msg_and_die("SKIP + SIZE is too large"); } - if (n_specs == 0) { + if (G.n_specs == 0) { decode_format_string("o2"); - /*n_specs = 1; - done by decode_format_string */ + /*G.n_specs = 1; - done by decode_format_string */ } /* If no files were listed on the command line, set the global pointer FILE_LIST so that it references the null-terminated list of one name: "-". */ - file_list = bb_argv_dash; + G.file_list = bb_argv_dash; if (argv[0]) { /* Set the global pointer FILE_LIST so that it references the first file-argument on the command-line. */ - file_list = (char const *const *) argv; + G.file_list = (char const *const *) argv; } /* Open the first input file */ open_next_file(); /* Skip over any unwanted header bytes */ skip(n_bytes_to_skip); - if (!in_stream) + if (!G.in_stream) return EXIT_FAILURE; /* Compute output block length */ l_c_m = get_lcm(); if (opt & OPT_w) { /* -w: width */ - if (!bytes_per_block || bytes_per_block % l_c_m != 0) { + if (!G.bytes_per_block || G.bytes_per_block % l_c_m != 0) { bb_error_msg("warning: invalid width %u; using %d instead", - (unsigned)bytes_per_block, l_c_m); - bytes_per_block = l_c_m; + (unsigned)G.bytes_per_block, l_c_m); + G.bytes_per_block = l_c_m; } } else { - bytes_per_block = l_c_m; + G.bytes_per_block = l_c_m; if (l_c_m < DEFAULT_BYTES_PER_BLOCK) - bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m; + G.bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m; } #ifdef DEBUG - for (i = 0; i < n_specs; i++) { + for (i = 0; i < G.n_specs; i++) { printf("%d: fmt=\"%s\" width=%d\n", i, spec[i].fmt_string, width_bytes[spec[i].size]); } @@ -1372,5 +1386,5 @@ int od_main(int argc UNUSED_PARAM, char **argv) if (fclose(stdin)) bb_perror_msg_and_die(bb_msg_standard_input); - return exit_code; + return G.exit_code; } -- cgit v1.2.3-55-g6feb From 526d85831e7480b9c7a3673d8dd356a438e6dd74 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 04:27:17 +0200 Subject: libbb: get_uidgid() always called with allow_numeric=1 function old new delta xget_uidgid 30 25 -5 make_device 2188 2183 -5 main 797 792 -5 get_uidgid 240 225 -15 Signed-off-by: Denys Vlasenko --- include/libbb.h | 7 +++---- libbb/appletlib.c | 2 +- libpwdgrp/uidgid_get.c | 42 +++++++++++++++++++----------------------- util-linux/mdev.c | 2 +- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index f04f555c0..1a3f6d8ce 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -920,14 +920,13 @@ long xuname2uid(const char *name) FAST_FUNC; long xgroup2gid(const char *name) FAST_FUNC; /* wrapper: allows string to contain numeric uid or gid */ unsigned long get_ug_id(const char *s, long FAST_FUNC (*xname2id)(const char *)) FAST_FUNC; -/* from chpst. Does not die, returns 0 on failure */ struct bb_uidgid_t { uid_t uid; gid_t gid; }; -/* always sets uid and gid */ -int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok) FAST_FUNC; -/* always sets uid and gid, allows numeric; exits on failure */ +/* always sets uid and gid; returns 0 on failure */ +int get_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC; +/* always sets uid and gid; exits on failure */ void xget_uidgid(struct bb_uidgid_t*, const char*) FAST_FUNC; /* chown-like handling of "user[:[group]" */ void parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_group) FAST_FUNC; diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 24253cf27..0f83eda4b 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -437,7 +437,7 @@ static void parse_config_file(void) goto pe_label; } *e = ':'; /* get_uidgid needs USER:GROUP syntax */ - if (get_uidgid(&sct->m_ugid, s, /*allow_numeric:*/ 1) == 0) { + if (get_uidgid(&sct->m_ugid, s) == 0) { errmsg = "unknown user/group"; goto pe_label; } diff --git a/libpwdgrp/uidgid_get.c b/libpwdgrp/uidgid_get.c index 8388be0da..eeb65191f 100644 --- a/libpwdgrp/uidgid_get.c +++ b/libpwdgrp/uidgid_get.c @@ -28,7 +28,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "libbb.h" /* Always sets uid and gid */ -int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) +int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug) { struct passwd *pwd; struct group *gr; @@ -43,18 +43,16 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) /* copies sz-1 bytes, stores terminating '\0' */ safe_strncpy(user, ug, sz); } - if (numeric_ok) { - n = bb_strtou(user, NULL, 10); - if (!errno) { - u->uid = n; - pwd = getpwuid(n); - /* If we have e.g. "500" string without user */ - /* with uid 500 in /etc/passwd, we set gid == uid */ - u->gid = pwd ? pwd->pw_gid : n; - goto skip; - } + n = bb_strtou(user, NULL, 10); + if (!errno) { + u->uid = n; + pwd = getpwuid(n); + /* If we have e.g. "500" string without user */ + /* with uid 500 in /etc/passwd, we set gid == uid */ + u->gid = pwd ? pwd->pw_gid : n; + goto skip; } - /* Either it is not numeric, or caller disallows numeric username */ + /* it is not numeric */ pwd = getpwnam(user); if (!pwd) return 0; @@ -63,12 +61,10 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) skip: if (group) { - if (numeric_ok) { - n = bb_strtou(group, NULL, 10); - if (!errno) { - u->gid = n; - return 1; - } + n = bb_strtou(group, NULL, 10); + if (!errno) { + u->gid = n; + return 1; } gr = getgrnam(group); if (!gr) @@ -79,7 +75,7 @@ int FAST_FUNC get_uidgid(struct bb_uidgid_t *u, const char *ug, int numeric_ok) } void FAST_FUNC xget_uidgid(struct bb_uidgid_t *u, const char *ug) { - if (!get_uidgid(u, ug, 1)) + if (!get_uidgid(u, ug)) bb_error_msg_and_die("unknown user/group %s", ug); } @@ -119,16 +115,16 @@ int main() { unsigned u; struct bb_uidgid_t ug; - u = get_uidgid(&ug, "apache", 0); + u = get_uidgid(&ug, "apache"); printf("%u = %u:%u\n", u, ug.uid, ug.gid); ug.uid = ug.gid = 1111; - u = get_uidgid(&ug, "apache", 0); + u = get_uidgid(&ug, "apache"); printf("%u = %u:%u\n", u, ug.uid, ug.gid); ug.uid = ug.gid = 1111; - u = get_uidgid(&ug, "apache:users", 0); + u = get_uidgid(&ug, "apache:users"); printf("%u = %u:%u\n", u, ug.uid, ug.gid); ug.uid = ug.gid = 1111; - u = get_uidgid(&ug, "apache:users", 0); + u = get_uidgid(&ug, "apache:users"); printf("%u = %u:%u\n", u, ug.uid, ug.gid); return 0; } diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 51781d597..37fa56827 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -400,7 +400,7 @@ static void parse_next_rule(void) } /* 2nd field: uid:gid - device ownership */ - if (get_uidgid(&G.cur_rule.ugid, tokens[1], /*allow_numeric:*/ 1) == 0) { + if (get_uidgid(&G.cur_rule.ugid, tokens[1]) == 0) { bb_error_msg("unknown user/group '%s' on line %d", tokens[1], G.parser->lineno); goto next_rule; } -- cgit v1.2.3-55-g6feb From 3d0805e9e7c45e6c0f9fb5e587d8b4a5a5f3c74c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 19 Oct 2015 04:37:19 +0200 Subject: libbb: make parse_chown_usergroup_or_die() set unspecified uid/gid to -1 function old new delta parse_chown_usergroup_or_die 102 115 +13 chown_main 190 175 -15 start_stop_daemon_main 1043 1027 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 13/-31) Total: -18 bytes Signed-off-by: Denys Vlasenko --- coreutils/chown.c | 4 ---- debianutils/start_stop_daemon.c | 8 ++++---- libpwdgrp/uidgid_get.c | 2 ++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/coreutils/chown.c b/coreutils/chown.c index eaa1ee2a3..247aa3bf1 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -112,10 +112,6 @@ int chown_main(int argc UNUSED_PARAM, char **argv) int opt, flags; struct param_t param; - /* Just -1 might not work: uid_t may be unsigned long */ - param.ugid.uid = -1L; - param.ugid.gid = -1L; - #if ENABLE_FEATURE_CHOWN_LONG_OPTIONS applet_long_options = chown_longopts; #endif diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 42f1943dd..d7c730f45 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -539,15 +539,15 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) write_pidfile(pidfile); } if (opt & OPT_c) { - struct bb_uidgid_t ugid = { -1, -1 }; + struct bb_uidgid_t ugid; parse_chown_usergroup_or_die(&ugid, chuid); - if (ugid.uid != (uid_t) -1) { + if (ugid.uid != (uid_t) -1L) { struct passwd *pw = xgetpwuid(ugid.uid); - if (ugid.gid != (gid_t) -1) + if (ugid.gid != (gid_t) -1L) pw->pw_gid = ugid.gid; /* initgroups, setgid, setuid: */ change_identity(pw); - } else if (ugid.gid != (gid_t) -1) { + } else if (ugid.gid != (gid_t) -1L) { xsetgid(ugid.gid); setgroups(1, &ugid.gid); } diff --git a/libpwdgrp/uidgid_get.c b/libpwdgrp/uidgid_get.c index eeb65191f..1199f23f9 100644 --- a/libpwdgrp/uidgid_get.c +++ b/libpwdgrp/uidgid_get.c @@ -90,6 +90,8 @@ void FAST_FUNC parse_chown_usergroup_or_die(struct bb_uidgid_t *u, char *user_gr { char *group; + u->uid = u->gid = (gid_t)-1L; + /* Check if there is a group name */ group = strchr(user_group, '.'); /* deprecated? */ if (!group) -- cgit v1.2.3-55-g6feb