diff options
author | James Byrne | 2019-07-02 11:35:03 +0200 |
---|---|---|
committer | Denys Vlasenko | 2019-07-02 11:35:03 +0200 |
commit | 6937487be73cd4563b876413277a295a5fe2f32c (patch) | |
tree | f16cc9999a7c827891e6ec8d99c699fc791008ee /networking/libiproute | |
parent | caecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff) | |
download | busybox-6937487be73cd4563b876413277a295a5fe2f32c.zip busybox-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz |
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/libiproute')
-rw-r--r-- | networking/libiproute/ipaddress.c | 10 | ||||
-rw-r--r-- | networking/libiproute/ipneigh.c | 8 | ||||
-rw-r--r-- | networking/libiproute/iproute.c | 12 | ||||
-rw-r--r-- | networking/libiproute/iptunnel.c | 10 | ||||
-rw-r--r-- | networking/libiproute/libnetlink.c | 30 | ||||
-rw-r--r-- | networking/libiproute/utils.c | 2 |
6 files changed, 36 insertions, 36 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 7b7e015..86cf3be 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -119,7 +119,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) //memset(tb, 0, sizeof(tb)); - parse_rtattr does this parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); if (tb[IFLA_IFNAME] == NULL) { - bb_error_msg("nil ifname"); + bb_simple_error_msg("nil ifname"); return -1; } if (G_filter.label @@ -205,7 +205,7 @@ static NOINLINE int print_linkinfo(const struct nlmsghdr *n) static int flush_update(void) { if (rtnl_send_check(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { - bb_perror_msg("can't send flush request"); + bb_simple_perror_msg("can't send flush request"); return -1; } G_filter.flushp = 0; @@ -439,7 +439,7 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) bb_error_msg_and_die(bb_msg_requires_arg, "flush"); } if (G_filter.family == AF_PACKET) { - bb_error_msg_and_die("can't flush link addresses"); + bb_simple_error_msg_and_die("can't flush link addresses"); } } @@ -700,7 +700,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) if (!d) { /* There was no "dev IFACE", but we need that */ - bb_error_msg_and_die("need \"dev IFACE\""); + bb_simple_error_msg_and_die("need \"dev IFACE\""); } if (l && !is_prefixed_with(l, d)) { bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l); @@ -717,7 +717,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) inet_prefix brd; int i; if (req.ifa.ifa_family != AF_INET) { - bb_error_msg_and_die("broadcast can be set only for IPv4 addresses"); + bb_simple_error_msg_and_die("broadcast can be set only for IPv4 addresses"); } brd = peer; if (brd.bitlen <= 30) { diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c index 984dd4b..b9b4f4b 100644 --- a/networking/libiproute/ipneigh.c +++ b/networking/libiproute/ipneigh.c @@ -49,7 +49,7 @@ typedef struct filter_t filter_t; static int flush_update(void) { if (rtnl_send_check(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { - bb_perror_msg("can't send flush request"); + bb_simple_perror_msg("can't send flush request"); return -1; } G_filter.flushp = 0; @@ -305,7 +305,7 @@ static int FAST_FUNC ipneigh_list_or_flush(char **argv, int flush) xrtnl_wilddump_request(&rth, G_filter.family, RTM_GETNEIGH); G_filter.flushed = 0; if (xrtnl_dump_filter(&rth, print_neigh, NULL) < 0) { - bb_perror_msg_and_die("flush terminated"); + bb_simple_perror_msg_and_die("flush terminated"); } if (G_filter.flushed == 0) { if (round == 0) @@ -325,11 +325,11 @@ static int FAST_FUNC ipneigh_list_or_flush(char **argv, int flush) 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"); + bb_simple_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"); + bb_simple_error_msg_and_die("dump terminated"); } return 0; diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index b11078e..5a972f8 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -57,7 +57,7 @@ typedef struct filter_t filter_t; static int flush_update(void) { if (rtnl_send_check(G_filter.rth, G_filter.flushb, G_filter.flushp) < 0) { - bb_perror_msg("can't send flush request"); + bb_simple_perror_msg("can't send flush request"); return -1; } G_filter.flushp = 0; @@ -756,7 +756,7 @@ static void iproute_flush_cache(void) } if (write(flush_fd, "-1", 2) < 2) { - bb_perror_msg("can't flush routing cache"); + bb_simple_perror_msg("can't flush routing cache"); return; } close(flush_fd); @@ -948,7 +948,7 @@ static int iproute_list_or_flush(char **argv, int flush) if (G_filter.tb != -1) { xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); } else if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { - bb_perror_msg_and_die("can't send dump request"); + bb_simple_perror_msg_and_die("can't send dump request"); } xrtnl_dump_filter(&rth, print_route, NULL); @@ -1041,7 +1041,7 @@ static int iproute_get(char **argv) } if (req.r.rtm_dst_len == 0) { - bb_error_msg_and_die("need at least destination address"); + bb_simple_error_msg_and_die("need at least destination address"); } xrtnl_open(&rth); @@ -1077,7 +1077,7 @@ static int iproute_get(char **argv) print_route(NULL, &req.n, NULL); if (req.n.nlmsg_type != RTM_NEWROUTE) { - bb_error_msg_and_die("not a route?"); + bb_simple_error_msg_and_die("not a route?"); } len -= NLMSG_LENGTH(sizeof(*r)); if (len < 0) { @@ -1091,7 +1091,7 @@ static int iproute_get(char **argv) tb[RTA_PREFSRC]->rta_type = RTA_SRC; r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]); } else if (!tb[RTA_SRC]) { - bb_error_msg_and_die("can't connect the route"); + bb_simple_error_msg_and_die("can't connect the route"); } if (!odev && tb[RTA_OIF]) { tb[RTA_OIF]->rta_type = 0; diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c index 4002feb..c9fa632 100644 --- a/networking/libiproute/iptunnel.c +++ b/networking/libiproute/iptunnel.c @@ -338,7 +338,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) { if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) { - bb_error_msg_and_die("keys are not allowed with ipip and sit"); + bb_simple_error_msg_and_die("keys are not allowed with ipip and sit"); } } @@ -355,7 +355,7 @@ static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p) p->o_flags |= GRE_KEY; } if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) { - bb_error_msg_and_die("broadcast tunnel requires a source address"); + bb_simple_error_msg_and_die("broadcast tunnel requires a source address"); } } @@ -367,7 +367,7 @@ static int do_add(int cmd, char **argv) parse_args(argv, cmd, &p); if (p.iph.ttl && p.iph.frag_off == 0) { - bb_error_msg_and_die("ttl != 0 and noptmudisc are incompatible"); + bb_simple_error_msg_and_die("ttl != 0 and noptmudisc are incompatible"); } switch (p.iph.protocol) { @@ -378,7 +378,7 @@ static int do_add(int cmd, char **argv) case IPPROTO_IPV6: return do_add_ioctl(cmd, "sit0", &p); default: - bb_error_msg_and_die("can't determine tunnel mode (ipip, gre or sit)"); + bb_simple_error_msg_and_die("can't determine tunnel mode (ipip, gre or sit)"); } } @@ -485,7 +485,7 @@ static void do_tunnels_list(struct ip_tunnel_parm *p) if (ptr == NULL || (*ptr++ = 0, sscanf(buf, "%s", name) != 1) ) { - bb_error_msg("wrong format of /proc/net/dev"); + bb_simple_error_msg("wrong format of /proc/net/dev"); return; } if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu", diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index b0d4166..7e3473a 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c @@ -79,7 +79,7 @@ int FAST_FUNC rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len) if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) - bb_error_msg("ERROR truncated"); + bb_simple_error_msg("ERROR truncated"); else errno = -err->error; return -1; @@ -149,11 +149,11 @@ static int rtnl_dump_filter(struct rtnl_handle *rth, if (status < 0) { if (errno == EINTR) continue; - bb_perror_msg("OVERRUN"); + bb_simple_perror_msg("OVERRUN"); continue; } if (status == 0) { - bb_error_msg("EOF on netlink"); + bb_simple_error_msg("EOF on netlink"); goto ret; } if (msg.msg_namelen != sizeof(nladdr)) { @@ -184,10 +184,10 @@ static int rtnl_dump_filter(struct rtnl_handle *rth, if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h); if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) { - bb_error_msg("ERROR truncated"); + bb_simple_error_msg("ERROR truncated"); } else { errno = -l_err->error; - bb_perror_msg("RTNETLINK answers"); + bb_simple_perror_msg("RTNETLINK answers"); } goto ret; } @@ -201,7 +201,7 @@ static int rtnl_dump_filter(struct rtnl_handle *rth, h = NLMSG_NEXT(h, status); } if (msg.msg_flags & MSG_TRUNC) { - bb_error_msg("message truncated"); + bb_simple_error_msg("message truncated"); continue; } if (status) { @@ -221,7 +221,7 @@ int FAST_FUNC xrtnl_dump_filter(struct rtnl_handle *rth, { int ret = rtnl_dump_filter(rth, filter, arg1/*, NULL, NULL*/); if (ret < 0) - bb_error_msg_and_die("dump terminated"); + bb_simple_error_msg_and_die("dump terminated"); return ret; } @@ -266,7 +266,7 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, status = sendmsg(rtnl->fd, &msg, 0); if (status < 0) { - bb_perror_msg("can't talk to rtnetlink"); + bb_simple_perror_msg("can't talk to rtnetlink"); goto ret; } @@ -280,11 +280,11 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, if (errno == EINTR) { continue; } - bb_perror_msg("OVERRUN"); + bb_simple_perror_msg("OVERRUN"); continue; } if (status == 0) { - bb_error_msg("EOF on netlink"); + bb_simple_error_msg("EOF on netlink"); goto ret; } if (msg.msg_namelen != sizeof(nladdr)) { @@ -297,7 +297,7 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, if (l < 0 || len > status) { if (msg.msg_flags & MSG_TRUNC) { - bb_error_msg("truncated message"); + bb_simple_error_msg("truncated message"); goto ret; } bb_error_msg_and_die("malformed message: len=%d!", len); @@ -320,7 +320,7 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); if (l < (int)sizeof(struct nlmsgerr)) { - bb_error_msg("ERROR truncated"); + bb_simple_error_msg("ERROR truncated"); } else { errno = - err->error; if (errno == 0) { @@ -329,7 +329,7 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, } goto ret_0; } - bb_perror_msg("RTNETLINK answers"); + bb_simple_perror_msg("RTNETLINK answers"); } goto ret; } @@ -338,13 +338,13 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, goto ret_0; } - bb_error_msg("unexpected reply!"); + bb_simple_error_msg("unexpected reply!"); status -= NLMSG_ALIGN(len); h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); } if (msg.msg_flags & MSG_TRUNC) { - bb_error_msg("message truncated"); + bb_simple_error_msg("message truncated"); continue; } if (status) { diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c index bf053a5..4ce2303 100644 --- a/networking/libiproute/utils.c +++ b/networking/libiproute/utils.c @@ -230,7 +230,7 @@ uint32_t FAST_FUNC get_addr32(char *name) char** FAST_FUNC next_arg(char **argv) { if (!*++argv) - bb_error_msg_and_die("command line is not complete, try \"help\""); + bb_simple_error_msg_and_die("command line is not complete, try \"help\""); return argv; } |