diff --git a/usr.bin/netstat/bpf.c b/usr.bin/netstat/bpf.c --- a/usr.bin/netstat/bpf.c +++ b/usr.bin/netstat/bpf.c @@ -42,7 +42,6 @@ #include #include -#include #include #include #include diff --git a/usr.bin/netstat/common.c b/usr.bin/netstat/common.c --- a/usr.bin/netstat/common.c +++ b/usr.bin/netstat/common.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include "netstat.h" #include "common.h" @@ -103,7 +102,7 @@ * since we need #ifindex -> if_xname match */ if (getifaddrs(&ifap) != 0) - err(EX_OSERR, "getifaddrs"); + xo_err(EX_OSERR, "getifaddrs"); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { @@ -117,7 +116,7 @@ size = roundup2(ifindex + 1, 32) * sizeof(struct ifmap_entry); if ((ifmap = realloc(ifmap, size)) == NULL) - errx(2, "realloc(%d) failed", size); + xo_errx(EX_OSERR, "realloc(%d) failed", size); memset(&ifmap[ifmap_size], 0, size - ifmap_size * sizeof(struct ifmap_entry)); diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -57,7 +57,6 @@ #include #endif -#include #include #include #include @@ -378,9 +377,9 @@ return sidewaysintpr(); if (getifaddrs(&ifap) != 0) - err(EX_OSERR, "getifaddrs"); + xo_err(EX_OSERR, "getifaddrs"); if (aflag && getifmaddrs(&ifmap) != 0) - err(EX_OSERR, "getifmaddrs"); + xo_err(EX_OSERR, "getifmaddrs"); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (interface != NULL && diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -72,7 +72,6 @@ #include #include -#include #include #include #include diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c --- a/usr.bin/netstat/inet6.c +++ b/usr.bin/netstat/inet6.c @@ -62,7 +62,6 @@ #include #include -#include #include #include #include diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -58,7 +58,6 @@ #endif #include -#include #include #include #include @@ -250,7 +249,7 @@ argc = xo_parse_args(argc, argv); if (argc < 0) - exit(EXIT_FAILURE); + exit(1); while ((ch = getopt(argc, argv, "46AaBbCcdF:f:ghI:iLlM:mN:nOoPp:Qq:RrSTsuWw:xz")) != -1) @@ -455,7 +454,8 @@ if (!live) usage(); bpf_stats(interface); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } if (mflag) { @@ -464,7 +464,8 @@ mbpr(kvmd, nl[N_SFSTAT].n_value); } else mbpr(NULL, 0); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } if (Qflag) { @@ -473,7 +474,8 @@ netisr_stats(); } else netisr_stats(); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } #if 0 @@ -494,7 +496,8 @@ xo_open_container("statistics"); intpr(NULL, af); xo_close_container("statistics"); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } if (rflag) { @@ -507,21 +510,24 @@ } else routepr(fib, af); xo_close_container("statistics"); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } if (oflag) { xo_open_container("statistics"); nhops_print(fib, af); xo_close_container("statistics"); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } if (Oflag) { xo_open_container("statistics"); nhgrp_print(fib, af); xo_close_container("statistics"); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } @@ -545,7 +551,8 @@ #endif } xo_close_container("statistics"); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } @@ -555,7 +562,8 @@ if (!first) xo_close_list("socket"); xo_close_container("statistics"); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } @@ -586,7 +594,8 @@ if (!first) xo_close_list("socket"); xo_close_container("statistics"); - xo_finish(); + if (xo_finish() < 0) + xo_err(1, "stdout"); exit(0); } @@ -889,7 +898,7 @@ static void usage(void) { - (void)xo_error("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", + xo_error("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", "usage: netstat [-46AaCcLnRSTWx] [-f protocol_family | -p protocol]\n" " [-M core] [-N system]", " netstat -i | -I interface [-46abdhnW] [-f address_family]\n" @@ -908,6 +917,6 @@ " netstat -g [-46W] [-f address_family] [-M core] [-N system]", " netstat -gs [-46s] [-f address_family] [-M core] [-N system]", " netstat -Q"); - xo_finish(); + exit(1); } diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c --- a/usr.bin/netstat/mbuf.c +++ b/usr.bin/netstat/mbuf.c @@ -52,7 +52,6 @@ #include #include -#include #include #include #include diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c --- a/usr.bin/netstat/mroute.c +++ b/usr.bin/netstat/mroute.c @@ -66,7 +66,6 @@ #include #undef _NETSTAT_ -#include #include #include #include diff --git a/usr.bin/netstat/mroute6.c b/usr.bin/netstat/mroute6.c --- a/usr.bin/netstat/mroute6.c +++ b/usr.bin/netstat/mroute6.c @@ -85,7 +85,6 @@ #include -#include #include #include #include diff --git a/usr.bin/netstat/netgraph.c b/usr.bin/netstat/netgraph.c --- a/usr.bin/netstat/netgraph.c +++ b/usr.bin/netstat/netgraph.c @@ -56,7 +56,6 @@ #include #include #include -#include #include #include "netstat.h" diff --git a/usr.bin/netstat/netisr.c b/usr.bin/netstat/netisr.c --- a/usr.bin/netstat/netisr.c +++ b/usr.bin/netstat/netisr.c @@ -43,7 +43,6 @@ #include #include -#include #include #include #include @@ -234,7 +233,7 @@ } proto_array = calloc(protocount, sizeof(*proto_array)); if (proto_array == NULL) - err(-1, "malloc"); + xo_err(-1, "malloc"); protocount = 0; for (i = 0; i < maxprot; i++) { npp = &np_array[i]; diff --git a/usr.bin/netstat/nhgrp.c b/usr.bin/netstat/nhgrp.c --- a/usr.bin/netstat/nhgrp.c +++ b/usr.bin/netstat/nhgrp.c @@ -47,7 +47,6 @@ #include #include #include -#include #include #include "netstat.h" #include "common.h" @@ -211,12 +210,12 @@ mib[5] = 0; mib[6] = fibnum; if (sysctl(mib, nitems(mib), NULL, &needed, NULL, 0) < 0) - err(EX_OSERR, "sysctl: net.route.0.%d.nhgrpdump.%d estimate", + xo_err(EX_OSERR, "sysctl: net.route.0.%d.nhgrpdump.%d estimate", af, fibnum); if ((buf = malloc(needed)) == NULL) - errx(2, "malloc(%lu)", (unsigned long)needed); + xo_errx(EX_OSERR, "malloc(%lu)", (unsigned long)needed); if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0) - err(1, "sysctl: net.route.0.%d.nhgrpdump.%d", af, fibnum); + xo_err(EX_OSERR, "sysctl: net.route.0.%d.nhgrpdump.%d", af, fibnum); lim = buf + needed; /* @@ -339,7 +338,7 @@ if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) numfibs = 1; if (fibnum < 0 || fibnum > numfibs - 1) - errx(EX_USAGE, "%d: invalid fib", fibnum); + xo_errx(EX_USAGE, "%d: invalid fib", fibnum); ifmap = prepare_ifmap(&ifmap_size); prepare_nh_map(fibnum, af); diff --git a/usr.bin/netstat/nhops.c b/usr.bin/netstat/nhops.c --- a/usr.bin/netstat/nhops.c +++ b/usr.bin/netstat/nhops.c @@ -61,7 +61,6 @@ #include #include #include -#include #include #include "netstat.h" #include "common.h" @@ -217,7 +216,7 @@ sz = new_size * (sizeof(struct nhop_entry)); if ((map->ptr = realloc(map->ptr, sz)) == NULL) - errx(2, "realloc(%zu) failed", sz); + xo_errx(EX_OSERR, "realloc(%zu) failed", sz); memset(&map->ptr[map->size], 0, (new_size - map->size) * sizeof(struct nhop_entry)); map->size = new_size; @@ -356,12 +355,12 @@ mib[5] = 0; mib[6] = fibnum; if (sysctl(mib, nitems(mib), NULL, &needed, NULL, 0) < 0) - err(EX_OSERR, "sysctl: net.route.0.%d.nhdump.%d estimate", af, + xo_err(EX_OSERR, "sysctl: net.route.0.%d.nhdump.%d estimate", af, fibnum); if ((buf = malloc(needed)) == NULL) - errx(2, "malloc(%lu)", (unsigned long)needed); + xo_errx(EX_OSERR, "malloc(%lu)", (unsigned long)needed); if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0) - err(1, "sysctl: net.route.0.%d.nhdump.%d", af, fibnum); + xo_err(EX_OSERR, "sysctl: net.route.0.%d.nhdump.%d", af, fibnum); lim = buf + needed; /* @@ -467,7 +466,7 @@ if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) numfibs = 1; if (fibnum < 0 || fibnum > numfibs - 1) - errx(EX_USAGE, "%d: invalid fib", fibnum); + xo_errx(EX_USAGE, "%d: invalid fib", fibnum); ifmap = prepare_ifmap(&ifmap_size); diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -66,7 +66,6 @@ #include #include #include -#include #include #include "netstat.h" #include "common.h" @@ -133,14 +132,14 @@ if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) numfibs = 1; if (fibnum < 0 || fibnum > numfibs - 1) - errx(EX_USAGE, "%d: invalid fib", fibnum); + xo_errx(EX_USAGE, "%d: invalid fib", fibnum); /* * Since kernel & userland use different timebase * (time_uptime vs time_second) and we are reading kernel memory * directly we should do rt_expire --> expire_time conversion. */ if (clock_gettime(CLOCK_UPTIME, &uptime) < 0) - err(EX_OSERR, "clock_gettime() failed"); + xo_err(EX_OSERR, "clock_gettime() failed"); xo_open_container("route-information"); xo_emit("{T:Routing tables}"); @@ -269,12 +268,12 @@ mib[5] = 0; mib[6] = fibnum; if (sysctl(mib, nitems(mib), NULL, &needed, NULL, 0) < 0) - err(EX_OSERR, "sysctl: net.route.0.%d.dump.%d estimate", af, + xo_err(EX_OSERR, "sysctl: net.route.0.%d.dump.%d estimate", af, fibnum); if ((buf = malloc(needed)) == NULL) - errx(2, "malloc(%lu)", (unsigned long)needed); + xo_errx(EX_OSERR, "malloc(%lu)", (unsigned long)needed); if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0) - err(1, "sysctl: net.route.0.%d.dump.%d", af, fibnum); + xo_err(EX_OSERR, "sysctl: net.route.0.%d.dump.%d", af, fibnum); lim = buf + needed; xo_open_container("route-table"); xo_open_list("rt-family"); diff --git a/usr.bin/netstat/route_netlink.c b/usr.bin/netstat/route_netlink.c --- a/usr.bin/netstat/route_netlink.c +++ b/usr.bin/netstat/route_netlink.c @@ -65,7 +65,6 @@ #include #include #include -#include #include #include "netstat.h" #include "common.h" @@ -107,7 +106,7 @@ if (link.ifi_index >= ifmap_size) { size_t size = roundup2(link.ifi_index + 1, 32) * sizeof(struct ifmap_entry); if ((ifmap = realloc(ifmap, size)) == NULL) - errx(2, "realloc(%zu) failed", size); + xo_errx(EX_OSERR, "realloc(%zu) failed", size); memset(&ifmap[ifmap_size], 0, size - ifmap_size * sizeof(struct ifmap_entry)); diff --git a/usr.bin/netstat/sctp.c b/usr.bin/netstat/sctp.c --- a/usr.bin/netstat/sctp.c +++ b/usr.bin/netstat/sctp.c @@ -53,7 +53,6 @@ #include #include -#include #include #include #include diff --git a/usr.bin/netstat/unix.c b/usr.bin/netstat/unix.c --- a/usr.bin/netstat/unix.c +++ b/usr.bin/netstat/unix.c @@ -56,7 +56,6 @@ #include #include -#include #include #include #include