From 3b28b9c8194d24580bd1bf543ea157cec83826d8 Mon Sep 17 00:00:00 2001 From: rwatson Date: Tue, 13 Sep 2005 19:01:53 +0000 Subject: Add a "-q" quiet flag to kenv so that warnings can be suppressed. MFC after: 1 week --- bin/kenv/kenv.1 | 9 ++++++++- bin/kenv/kenv.c | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'bin/kenv') diff --git a/bin/kenv/kenv.1 b/bin/kenv/kenv.1 index cb7b377..d9cdf8b 100644 --- a/bin/kenv/kenv.1 +++ b/bin/kenv/kenv.1 @@ -32,10 +32,12 @@ .Nd dump or modify the kernel environment .Sh SYNOPSIS .Nm -.Op Fl h +.Op Fl hq .Nm +.Op Fl q .Ar variable Ns Op = Ns Ar value .Nm +.Op Fl q .Fl u .Ar variable .Sh DESCRIPTION @@ -60,6 +62,11 @@ If the environment variable is followed by an optional .Ar value , .Nm will set the environment variable to this value. +.Pp +If the +.Fl q +option is set, warnings normally printed as a result of being unable to +perform the requested operation will be suppressed. .Sh SEE ALSO .Xr kenv 2 , .Xr loader 8 diff --git a/bin/kenv/kenv.c b/bin/kenv/kenv.c index ced3832..dc86ba8 100644 --- a/bin/kenv/kenv.c +++ b/bin/kenv/kenv.c @@ -42,15 +42,16 @@ static int ksetenv(char *, char *); static int kunsetenv(char *); static int hflag = 0; +static int qflag = 0; static int uflag = 0; static void usage(void) { (void)fprintf(stderr, "%s\n%s\n%s\n", - "usage: kenv [-h]", - " kenv variable[=value]", - " kenv -u variable"); + "usage: kenv [-hq]", + " kenv [-q] variable[=value]", + " kenv [-q] -u variable"); exit(1); } @@ -63,11 +64,14 @@ main(int argc, char **argv) error = 0; val = NULL; env = NULL; - while ((ch = getopt(argc, argv, "hu")) != -1) { + while ((ch = getopt(argc, argv, "hqu")) != -1) { switch (ch) { case 'h': hflag++; break; + case 'q': + qflag++; + break; case 'u': uflag++; break; @@ -93,21 +97,21 @@ main(int argc, char **argv) usage(); if (env == NULL) { error = kdumpenv(); - if (error) + if (error && !qflag) warn("kdumpenv"); } else if (val == NULL) { if (uflag) { error = kunsetenv(env); - if (error) + if (error && !qflag) warnx("unable to unset %s", env); } else { error = kgetenv(env); - if (error) + if (error && !qflag) warnx("unable to get %s", env); } } else { error = ksetenv(env, val); - if (error) + if (error && !qflag) warnx("unable to set %s to %s", env, val); } return (error); -- cgit v1.1