From cd436d6b803f08c5ec23a9512ebc13744b51e2af Mon Sep 17 00:00:00 2001 From: gad Date: Mon, 20 Jun 2005 03:06:54 +0000 Subject: 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') --- usr.bin/env/env.c | 29 +++++++++++++++++++++++++---- 1 file 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); } -- cgit v1.1