SCCS-vsn: usr.sbin/sysctl/sysctl.c 5.2
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)sysctl.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)sysctl.c 5.2 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#endif /* not lint */
#include <sys/types.h>
{ 0, 0 }, /* CTL_MACHDEP */
};
{ 0, 0 }, /* CTL_MACHDEP */
};
-int Aflag, aflag, wflag;
+int Aflag, aflag, nflag, wflag;
{
extern char *optarg;
extern int optind;
{
extern char *optarg;
extern int optind;
- while ((ch = getopt(argc, argv, "Aaw")) != EOF) {
+ while ((ch = getopt(argc, argv, "Aanw")) != EOF) {
+ case 'n':
+ nflag = 1;
+ break;
+
case 'w':
wflag = 1;
break;
case 'w':
wflag = 1;
break;
argv += optind;
if (Aflag || aflag) {
argv += optind;
if (Aflag || aflag) {
+ for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++)
+ listall(lvl1);
exit(0);
}
if (argc == 0)
exit(0);
}
if (argc == 0)
/*
* List all variables known to the system.
*/
/*
* List all variables known to the system.
*/
+listall(lvl1)
+ int lvl1;
- for (lvl1 = 1; lvl1 < CTL_MAXID; lvl1++) {
- lp = &secondlevel[lvl1];
- if (lp->list == 0)
- continue;
- strcpy(name, topname[lvl1]);
- cp = &name[strlen(name)];
- *cp++ = '.';
- for (lvl2 = 1; lvl2 < lp->size; lvl2++) {
- strcpy(cp, lp->list[lvl2]);
- parse(name, Aflag);
- }
+ lp = &secondlevel[lvl1];
+ if (lp->list == 0)
+ return;
+ strcpy(name, topname[lvl1]);
+ cp = &name[strlen(name)];
+ *cp++ = '.';
+ for (lvl2 = 1; lvl2 < lp->size; lvl2++) {
+ strcpy(cp, lp->list[lvl2]);
+ parse(name, Aflag);
topname[indx]);
return;
}
topname[indx]);
return;
}
+ if (bufp == NULL) {
+ listall(indx);
+ return;
+ }
if ((indx = findname(string, "second", &bufp, lp)) == -1)
return;
mib[1] = indx;
if ((indx = findname(string, "second", &bufp, lp)) == -1)
return;
mib[1] = indx;
double loads[3];
getloadavg(loads, 3);
double loads[3];
getloadavg(loads, 3);
- fprintf(stdout, "%s: %.2f %.2f %.2f\n", string,
+ if (!nflag)
+ fprintf(stdout, "%s: ", string);
+ fprintf(stdout, "%.2f %.2f %.2f\n",
loads[0], loads[1], loads[2]);
return;
}
loads[0], loads[1], loads[2]);
return;
}
if (isclockrate) {
struct clockinfo *clkp = (struct clockinfo *)buf;
if (isclockrate) {
struct clockinfo *clkp = (struct clockinfo *)buf;
+ if (!nflag)
+ fprintf(stdout, "%s: ", string);
- "%s: hz = %d, tick = %d, profhz = %d, stathz = %d\n",
- string, clkp->hz, clkp->tick, clkp->profhz, clkp->stathz);
+ "hz = %d, tick = %d, profhz = %d, stathz = %d\n",
+ clkp->hz, clkp->tick, clkp->profhz, clkp->stathz);
- if (size == sizeof(int) && !isprint(buf[0]))
- if (newsize == 0)
- fprintf(stdout, "%s = %d\n", string, *(int *)buf);
- else
- fprintf(stdout, "%s: %d -> %d\n", string, *(int *)buf,
- *(int *)newval);
+ if (size == sizeof(int) && !(isprint(buf[0]) && isprint(buf[1]) &&
+ isprint(buf[2]) && isprint(buf[3])))
+ if (newsize == 0) {
+ if (!nflag)
+ fprintf(stdout, "%s = ", string);
+ fprintf(stdout, "%d\n", *(int *)buf);
+ } else {
+ if (!nflag)
+ fprintf(stdout, "%s: %d -> ", string,
+ *(int *)buf);
+ fprintf(stdout, "%d\n", *(int *)newval);
+ }
- if (newsize == 0)
- fprintf(stdout, "%s = %s\n", string, buf);
- else
- fprintf(stdout, "%s: %s -> %s\n", string, buf, newval);
+ if (newsize == 0) {
+ if (!nflag)
+ fprintf(stdout, "%s = ", string);
+ fprintf(stdout, "%s\n", buf);
+ } else {
+ if (!nflag)
+ fprintf(stdout, "%s: %s -> ", string, buf);
+ fprintf(stdout, "%s\n", newval);
+ }