Index: kenv.1 =================================================================== RCS file: /usr/cvs/src/bin/kenv/kenv.1,v retrieving revision 1.13 diff -u -r1.13 kenv.1 --- kenv.1 17 Nov 2005 12:15:22 -0000 1.13 +++ kenv.1 14 Jan 2006 20:49:40 -0000 @@ -32,7 +32,11 @@ .Nd dump or modify the kernel environment .Sh SYNOPSIS .Nm -.Op Fl hq +.Op Fl hqs +.Nm +.Fl p +.Ar prefix +.Op Fl qs .Nm .Op Fl q .Ar variable Ns Op = Ns Ar value @@ -48,6 +52,23 @@ If the .Fl h option is specified, it will limit the report to kernel probe hints. +If the +.Fl p +option is specified, it will limit the report to kernel environment variables +that begin with the string +.Ar prefix . +If the +.Fl s +option is specified, then the specified +.Ar prefix +will be removed from the environment variable names that are output. +If both the +.Fl h +and +.Fl s +options are specified, the string +.Dq hint. +will be removed from the environment variable names. If an optional .Ar variable name is specified, Index: kenv.c =================================================================== RCS file: /usr/cvs/src/bin/kenv/kenv.c,v retrieving revision 1.8 diff -u -r1.8 kenv.c --- kenv.c 13 Sep 2005 19:01:53 -0000 1.8 +++ kenv.c 6 Oct 2005 22:50:25 -0000 @@ -36,20 +36,21 @@ #include static void usage(void); -static int kdumpenv(void); +static int kdumpenv(const char *); static int kgetenv(char *); static int ksetenv(char *, char *); static int kunsetenv(char *); -static int hflag = 0; static int qflag = 0; +static int sflag = 0; static int uflag = 0; static void usage(void) { - (void)fprintf(stderr, "%s\n%s\n%s\n", - "usage: kenv [-hq]", + (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", + "usage: kenv [-hqs]", + " kenv [-p prefix] [-sq]", " kenv [-q] variable[=value]", " kenv [-q] -u variable"); exit(1); @@ -59,15 +60,17 @@ main(int argc, char **argv) { char *env, *eq, *val; + const char *prefix; int ch, error; error = 0; val = NULL; env = NULL; - while ((ch = getopt(argc, argv, "hqu")) != -1) { + prefix = NULL; + while ((ch = getopt(argc, argv, "hqusp:")) != -1) { switch (ch) { case 'h': - hflag++; + prefix = "hint."; break; case 'q': qflag++; @@ -75,6 +78,12 @@ case 'u': uflag++; break; + case 's': + sflag++; + break; + case 'p': + prefix = optarg; + break; default: usage(); } @@ -91,12 +100,12 @@ argv++; argc--; } - if (hflag && (env != NULL)) + if ((prefix != NULL) && (env != NULL)) usage(); if ((argc > 0) || (uflag && (env == NULL))) usage(); if (env == NULL) { - error = kdumpenv(); + error = kdumpenv(prefix); if (error && !qflag) warn("kdumpenv"); } else if (val == NULL) { @@ -118,11 +127,17 @@ } static int -kdumpenv() +kdumpenv(const char *prefix) { char *buf, *cp; - int buflen, envlen; + int buflen, envlen, prefixlen; + if (prefix != NULL) { + prefixlen = strlen(prefix); + if (prefixlen == 0) + return (-1); + } else + prefixlen = 0; envlen = kenv(KENV_DUMP, NULL, NULL, 0); if (envlen < 0) return (-1); @@ -144,9 +159,11 @@ } for (; *buf != '\0'; buf += strlen(buf) + 1) { - if (hflag) { - if (strncmp(buf, "hint.", 5) != 0) - continue; + if (prefix != NULL) { + if (strncmp(buf, prefix, prefixlen) != 0) + continue; + if (sflag) + buf += prefixlen; } cp = strchr(buf, '='); if (cp == NULL)