Index: src/sbin/sysctl/sysctl.8 =================================================================== RCS file: /home/ncvs/src/sbin/sysctl/sysctl.8,v retrieving revision 1.23.2.16 diff -u -r1.23.2.16 sysctl.8 --- src/sbin/sysctl/sysctl.8 1 May 2003 22:48:08 -0000 1.23.2.16 +++ src/sbin/sysctl/sysctl.8 7 May 2003 07:30:42 -0000 @@ -40,11 +40,11 @@ .Nd get or set kernel state .Sh SYNOPSIS .Nm -.Op Fl bdeNnox +.Op Fl bdemNnox .Ar name Ns Op = Ns Ar value .Ar ... .Nm -.Op Fl bdeNnox +.Op Fl bdemNnox .Fl a .Sh DESCRIPTION The @@ -84,6 +84,11 @@ or .Fl n is specified, or a variable is being set. +.It Fl m +Print the numerical OID of the MIB entry before the variable name. +This flag only takes effect if +.Fl n +is not specified. .It Fl N Show only variable names, not their values. This is particularly useful with shells that offer programmable Index: src/sbin/sysctl/sysctl.c =================================================================== RCS file: /home/ncvs/src/sbin/sysctl/sysctl.c,v retrieving revision 1.25.2.11 diff -u -r1.25.2.11 sysctl.c --- src/sbin/sysctl/sysctl.c 1 May 2003 22:48:08 -0000 1.25.2.11 +++ src/sbin/sysctl/sysctl.c 7 May 2003 07:32:52 -0000 @@ -63,10 +63,11 @@ #include #include -static int aflag, bflag, dflag, eflag, Nflag, nflag, oflag, xflag; +static int aflag, bflag, dflag, eflag, mflag, Nflag, nflag, oflag, xflag; static int oidfmt(int *, int, char *, u_int *); static void parse(char *); +static void show_varname(const char *, const int *, int, const char *); static int show_var(int *, int); static int sysctl_all (int *oid, int len); static int name2oid(char *, int *); @@ -78,8 +79,8 @@ { (void)fprintf(stderr, "%s\n%s\n", - "usage: sysctl [-bdeNnox] variable[=value] ...", - " sysctl [-bdeNnox] -a"); + "usage: sysctl [-bdemNnox] variable[=value] ...", + " sysctl [-bdemNnox] -a"); exit(1); } @@ -90,7 +91,7 @@ setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "AabdeNnowxX")) != -1) { + while ((ch = getopt(argc, argv, "AabdemNnowxX")) != -1) { switch (ch) { case 'A': /* compatibility */ @@ -108,6 +109,9 @@ case 'e': eflag = 1; break; + case 'm': + mflag = 1; + break; case 'N': Nflag = 1; break; @@ -457,6 +461,32 @@ #endif /* + * This formats and outputs the name of one variable. + * If the -m command-line flag was specified, the numerical OID + * of the MIB entry is also printed out. + */ + +static void +show_varname(const char *name, const int *oid, int len, const char *sep) +{ + int i; + + if (nflag) + return; + + if (mflag) { + for (i = 0; i < len-1; i++) + printf("%X.", oid[i]); + printf("%X ", oid[i]); + } + + if (!Nflag) + printf("%s%s", name, sep); + else + printf("%s", name); +} + +/* * This formats and outputs the value of one variable * * Returns zero if anything was actually output. @@ -468,7 +498,8 @@ show_var(int *oid, int nlen) { u_char buf[BUFSIZ], *val, *p; - char name[BUFSIZ], *fmt, *sep; + char name[BUFSIZ], *fmt; + const char *sep; int qoid[CTL_MAXNAME+2]; int i; size_t j, len; @@ -484,11 +515,6 @@ if (i || !j) err(1, "sysctl name %d %d %d", i, j, errno); - if (Nflag) { - printf("%s", name); - return (0); - } - if (eflag) sep = "="; else @@ -503,6 +529,11 @@ printf("%s", buf); return(0); } + if (Nflag) { + show_varname(name, oid, nlen, sep); + return (0); + } + /* find an estimate of how much we need for this var */ j = 0; i = sysctl(oid, nlen, 0, &j, 0, 0); @@ -525,14 +556,12 @@ p = val; switch (*fmt) { case 'A': - if (!nflag) - printf("%s%s", name, sep); + show_varname(name, oid, nlen, sep); printf("%.*s", len, p); return (0); case 'I': - if (!nflag) - printf("%s%s", name, sep); + show_varname(name, oid, nlen, sep); fmt++; val = ""; while (len >= sizeof(int)) { @@ -547,8 +576,7 @@ return (0); case 'L': - if (!nflag) - printf("%s%s", name, sep); + show_varname(name, oid, nlen, sep); fmt++; #ifdef __i386__ if (!strcmp(name, "machdep.guessed_bootdev")) @@ -567,8 +595,7 @@ return (0); case 'P': - if (!nflag) - printf("%s%s", name, sep); + show_varname(name, oid, nlen, sep); printf("%p", *(void **)p); return (0); @@ -586,16 +613,14 @@ else func = NULL; if (func) { - if (!nflag) - printf("%s%s", name, sep); + show_varname(name, oid, nlen, sep); return ((*func)(len, p)); } /* FALL THROUGH */ default: if (!oflag && !xflag) return (1); - if (!nflag) - printf("%s%s", name, sep); + show_varname(name, oid, nlen, sep); printf("Format:%s Length:%d Dump:0x", fmt, len); while (len-- && (xflag || p < val + 16)) printf("%02x", *p++);