summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2005-06-20 03:06:54 +0000
committergad <gad@FreeBSD.org>2005-06-20 03:06:54 +0000
commitcd436d6b803f08c5ec23a9512ebc13744b51e2af (patch)
tree9825d9744d7e872d9c7b142627021659dffe0015 /usr.bin
parentd96c7ef573c68c2ebb755a6505ed0fd7d670aaf6 (diff)
downloadFreeBSD-src-cd436d6b803f08c5ec23a9512ebc13744b51e2af.zip
FreeBSD-src-cd436d6b803f08c5ec23a9512ebc13744b51e2af.tar.gz
Add a '-v' option to `env', to make it easier to discover exactly what steps
it is doing, and what order it does them. This will be much more useful as more options are added. Approved by: re (blanket `env')
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/env/env.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c
index 26651f4..b4753b0 100644
--- a/usr.bin/env/env.c
+++ b/usr.bin/env/env.c
@@ -55,29 +55,50 @@ __FBSDID("$FreeBSD$");
extern char **environ;
+int env_verbosity;
+
static void usage(void);
int
main(int argc, char **argv)
{
- char **ep, *p;
+ char **ep, *p, **parg;
char *cleanenv[1];
int ch;
- while ((ch = getopt(argc, argv, "-i")) != -1)
+ while ((ch = getopt(argc, argv, "-iv")) != -1)
switch(ch) {
case '-':
case 'i':
environ = cleanenv;
cleanenv[0] = NULL;
+ if (env_verbosity)
+ fprintf(stderr, "#env clearing environ\n");
+ break;
+ case 'v':
+ env_verbosity++;
+ if (env_verbosity > 1)
+ fprintf(stderr, "#env verbosity now at %d\n",
+ env_verbosity);
break;
case '?':
default:
usage();
}
- for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv)
+ for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) {
+ if (env_verbosity)
+ fprintf(stderr, "#env setenv:\t%s\n", *argv);
(void)setenv(*argv, ++p, 1);
+ }
if (*argv) {
+ if (env_verbosity) {
+ fprintf(stderr, "#env executing:\t%s\n", *argv);
+ for (parg = argv, argc = 0; *parg; parg++, argc++)
+ fprintf(stderr, "#env arg[%d]=\t'%s'\n",
+ argc, *parg);
+ if (env_verbosity > 1)
+ sleep(1);
+ }
execvp(*argv, argv);
err(errno == ENOENT ? 127 : 126, "%s", *argv);
}
@@ -90,6 +111,6 @@ static void
usage(void)
{
(void)fprintf(stderr,
- "usage: env [-i] [name=value ...] [utility [argument ...]]\n");
+ "usage: env [-iv] [name=value ...] [utility [argument ...]]\n");
exit(1);
}
OpenPOWER on IntegriCloud