From 6b6b665bfdd753de0ebf4d7408849ee429f9267d Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Mon, 11 Jun 2007 13:02:15 +0000 Subject: [PATCH] When we return from a "show" function without printing anything except a warning, return 1 instead of 0 to indicate that we didn't print anything, so that top-level callers don't print a spurious newline. This is mainly to fix output formatting when stderr is redirected. It also helps in some cases when stderr is interleaved with stdout, depending on the details of the interleaving (this program has the usual null explicit support for syncing stderr with stdout). Return 1 instead of -1 after printing the "malloc failed" warning, since the return value is boolean. --- sbin/sysctl/sysctl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index f84b47b55985..9dcfcb06bfd9 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -327,7 +327,7 @@ S_clockinfo(int l2, void *p) if (l2 != sizeof(*ci)) { warnx("S_clockinfo %d != %d", l2, sizeof(*ci)); - return (0); + return (1); } printf(hflag ? "{ hz = %'d, tick = %'d, profhz = %'d, stathz = %'d }" : "{ hz = %d, tick = %d, profhz = %d, stathz = %d }", @@ -342,7 +342,7 @@ S_loadavg(int l2, void *p) if (l2 != sizeof(*tv)) { warnx("S_loadavg %d != %d", l2, sizeof(*tv)); - return (0); + return (1); } printf(hflag ? "{ %'.2f %'.2f %'.2f }" : "{ %.2f %.2f %.2f }", (double)tv->ldavg[0]/(double)tv->fscale, @@ -360,7 +360,7 @@ S_timeval(int l2, void *p) if (l2 != sizeof(*tv)) { warnx("S_timeval %d != %d", l2, sizeof(*tv)); - return (0); + return (1); } printf(hflag ? "{ sec = %'ld, usec = %'ld } " : "{ sec = %ld, usec = %ld } ", @@ -382,7 +382,7 @@ S_vmtotal(int l2, void *p) if (l2 != sizeof(*v)) { warnx("S_vmtotal %d != %d", l2, sizeof(*v)); - return (0); + return (1); } printf( @@ -414,7 +414,7 @@ T_dev_t(int l2, void *p) if (l2 != sizeof(*d)) { warnx("T_dev_T %d != %d", l2, sizeof(*d)); - return (0); + return (1); } if ((int)(*d) != -1) { if (minor(*d) > 255 || minor(*d) < 0) @@ -588,7 +588,7 @@ show_var(int *oid, int nlen) val = oval = malloc(j + 1); if (val == NULL) { warnx("malloc failed"); - return (-1); + return (1); } len = j; i = sysctl(oid, nlen, val, &len, 0, 0);