sysctl(8): make WARNS=3 clean

Fixes inspired by work done in DragonflyBSD.

PR:		bin/140016
Approved by:	ed (Co-mentor)
This commit is contained in:
Ulrich Spörlein 2010-02-15 14:08:06 +00:00
parent 2b6974bf61
commit 6d7a8f6cba
2 changed files with 18 additions and 12 deletions

View File

@ -2,7 +2,7 @@
# $FreeBSD$
PROG= sysctl
WARNS?= 0
WARNS?= 3
MAN= sysctl.8
.include <bsd.prog.mk>

View File

@ -279,7 +279,10 @@ parse(char *string)
case CTLTYPE_STRING:
break;
case CTLTYPE_QUAD:
sscanf(newval, "%qd", &quadval);
quadval = strtoq(newval, &endptr, 0);
if (endptr == newval || *endptr != '\0')
errx(1, "invalid quad integer"
" '%s'", (char *)newval);
newval = &quadval;
newsize = sizeof(quadval);
break;
@ -334,7 +337,7 @@ S_clockinfo(int l2, void *p)
struct clockinfo *ci = (struct clockinfo*)p;
if (l2 != sizeof(*ci)) {
warnx("S_clockinfo %d != %d", l2, sizeof(*ci));
warnx("S_clockinfo %d != %zu", l2, sizeof(*ci));
return (1);
}
printf(hflag ? "{ hz = %'d, tick = %'d, profhz = %'d, stathz = %'d }" :
@ -349,7 +352,7 @@ S_loadavg(int l2, void *p)
struct loadavg *tv = (struct loadavg*)p;
if (l2 != sizeof(*tv)) {
warnx("S_loadavg %d != %d", l2, sizeof(*tv));
warnx("S_loadavg %d != %zu", l2, sizeof(*tv));
return (1);
}
printf(hflag ? "{ %'.2f %'.2f %'.2f }" : "{ %.2f %.2f %.2f }",
@ -367,7 +370,7 @@ S_timeval(int l2, void *p)
char *p1, *p2;
if (l2 != sizeof(*tv)) {
warnx("S_timeval %d != %d", l2, sizeof(*tv));
warnx("S_timeval %d != %zu", l2, sizeof(*tv));
return (1);
}
printf(hflag ? "{ sec = %'jd, usec = %'ld } " :
@ -389,7 +392,7 @@ S_vmtotal(int l2, void *p)
int pageKilo = getpagesize() / 1024;
if (l2 != sizeof(*v)) {
warnx("S_vmtotal %d != %d", l2, sizeof(*v));
warnx("S_vmtotal %d != %zu", l2, sizeof(*v));
return (1);
}
@ -421,7 +424,7 @@ T_dev_t(int l2, void *p)
dev_t *d = (dev_t *)p;
if (l2 != sizeof(*d)) {
warnx("T_dev_T %d != %d", l2, sizeof(*d));
warnx("T_dev_T %d != %zu", l2, sizeof(*d));
return (1);
}
printf("%s", devname(*d, S_IFCHR));
@ -518,7 +521,7 @@ oidfmt(int *oid, int len, char *fmt, u_int *kind)
j = sizeof(buf);
i = sysctl(qoid, len + 2, buf, &j, 0, 0);
if (i)
err(1, "sysctl fmt %d %d %d", i, j, errno);
err(1, "sysctl fmt %d %zu %d", i, j, errno);
if (kind)
*kind = *(u_int *)buf;
@ -551,6 +554,9 @@ show_var(int *oid, int nlen)
u_int kind;
int (*func)(int, void *);
/* Silence GCC. */
umv = mv = intlen = 0;
bzero(buf, BUFSIZ);
bzero(name, BUFSIZ);
qoid[0] = 0;
@ -560,7 +566,7 @@ show_var(int *oid, int nlen)
j = sizeof(name);
i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
if (i || !j)
err(1, "sysctl name %d %d %d", i, j, errno);
err(1, "sysctl name %d %zu %d", i, j, errno);
if (Nflag) {
printf("%s", name);
@ -611,7 +617,7 @@ show_var(int *oid, int nlen)
case 'A':
if (!nflag)
printf("%s%s", name, sep);
printf("%.*s", len, p);
printf("%.*s", (int)len, p);
free(oval);
return (0);
@ -698,7 +704,7 @@ show_var(int *oid, int nlen)
}
if (!nflag)
printf("%s%s", name, sep);
printf("Format:%s Length:%d Dump:0x", fmt, len);
printf("Format:%s Length:%zu Dump:0x", fmt, len);
while (len-- && (xflag || p < val + 16))
printf("%02x", *p++);
if (!xflag && len > 16)
@ -734,7 +740,7 @@ sysctl_all(int *oid, int len)
if (errno == ENOENT)
return (0);
else
err(1, "sysctl(getnext) %d %d", j, l2);
err(1, "sysctl(getnext) %d %zu", j, l2);
}
l2 /= sizeof(int);