Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/env/env.c
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
int env_verbosity; | int env_verbosity; | ||||
static void usage(void); | static void usage(void); | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
char *altpath, **ep, *p, **parg; | char *altpath, **ep, *p, **parg, term; | ||||
char *cleanenv[1]; | char *cleanenv[1]; | ||||
int ch, want_clear; | int ch, want_clear; | ||||
int rtrn; | int rtrn; | ||||
altpath = NULL; | altpath = NULL; | ||||
want_clear = 0; | want_clear = 0; | ||||
while ((ch = getopt(argc, argv, "-iP:S:u:v")) != -1) | term = '\n'; | ||||
while ((ch = getopt(argc, argv, "-0iP:S:u:v")) != -1) | |||||
switch(ch) { | switch(ch) { | ||||
case '-': | case '-': | ||||
case 'i': | case 'i': | ||||
want_clear = 1; | want_clear = 1; | ||||
break; | break; | ||||
case '0': | |||||
term = '\0'; | |||||
break; | |||||
case 'P': | case 'P': | ||||
altpath = strdup(optarg); | altpath = strdup(optarg); | ||||
break; | break; | ||||
case 'S': | case 'S': | ||||
/* | /* | ||||
* The -S option, for "split string on spaces, with | * The -S option, for "split string on spaces, with | ||||
* support for some simple substitutions"... | * support for some simple substitutions"... | ||||
*/ | */ | ||||
Show All 27 Lines | if (env_verbosity) | ||||
fprintf(stderr, "#env setenv:\t%s\n", *argv); | fprintf(stderr, "#env setenv:\t%s\n", *argv); | ||||
*p = '\0'; | *p = '\0'; | ||||
rtrn = setenv(*argv, p + 1, 1); | rtrn = setenv(*argv, p + 1, 1); | ||||
*p = '='; | *p = '='; | ||||
if (rtrn == -1) | if (rtrn == -1) | ||||
err(EXIT_FAILURE, "setenv %s", *argv); | err(EXIT_FAILURE, "setenv %s", *argv); | ||||
} | } | ||||
if (*argv) { | if (*argv) { | ||||
if (term == '\0') | |||||
fprintf(stderr, "Command ignored with -0.\n"); | |||||
swills: I think maybe this should call `exit()`, perhaps with a non-zero exit, perhaps with 125 instead. | |||||
Not Done Inline Actionswhat's a 125? imp: what's a 125?
| |||||
else { | |||||
if (altpath) | if (altpath) | ||||
search_paths(altpath, argv); | search_paths(altpath, argv); | ||||
if (env_verbosity) { | if (env_verbosity) { | ||||
fprintf(stderr, "#env executing:\t%s\n", *argv); | fprintf(stderr, "#env executing:\t%s\n", *argv); | ||||
for (parg = argv, argc = 0; *parg; parg++, argc++) | for (parg = argv, argc = 0; *parg; parg++, argc++) | ||||
fprintf(stderr, "#env arg[%d]=\t'%s'\n", | fprintf(stderr, "#env arg[%d]=\t'%s'\n", | ||||
argc, *parg); | argc, *parg); | ||||
if (env_verbosity > 1) | if (env_verbosity > 1) | ||||
sleep(1); | sleep(1); | ||||
} | } | ||||
execvp(*argv, argv); | execvp(*argv, argv); | ||||
err(errno == ENOENT ? 127 : 126, "%s", *argv); | err(errno == ENOENT ? 127 : 126, "%s", *argv); | ||||
} | } | ||||
} | |||||
for (ep = environ; *ep; ep++) | for (ep = environ; *ep; ep++) | ||||
(void)printf("%s\n", *ep); | (void)printf("%s%c", *ep, term); | ||||
exit(0); | exit(0); | ||||
} | } | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
(void)fprintf(stderr, | (void)fprintf(stderr, | ||||
"usage: env [-iv] [-P utilpath] [-S string] [-u name]\n" | "usage: env [-0iv] [-P utilpath] [-S string] [-u name]\n" | ||||
" [name=value ...] [utility [argument ...]]\n"); | " [name=value ...] [utility [argument ...]]\n"); | ||||
exit(1); | exit(1); | ||||
} | } |
I think maybe this should call exit(), perhaps with a non-zero exit, perhaps with 125 instead.