Add a "-q" quiet flag to kenv so that warnings can be suppressed.
MFC after: 1 week
This commit is contained in:
parent
e88c48fefc
commit
af2b8e58cc
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user