diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-07-28 07:42:19 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-07-28 07:42:19 +0000 |
commit | 05df91a3ac5801fc1f12101ab09f56626b296e83 (patch) | |
tree | 8b02085050bb1cbe105bc4cd1d74d8e696bfdc81 | |
parent | 35e643b39f6cc77b702c714cfa8e70f1e10601a9 (diff) | |
download | busybox-w32-05df91a3ac5801fc1f12101ab09f56626b296e83.tar.gz busybox-w32-05df91a3ac5801fc1f12101ab09f56626b296e83.tar.bz2 busybox-w32-05df91a3ac5801fc1f12101ab09f56626b296e83.zip |
last_patch98 from vodz:
Denis,
># ./busybox env - echo zzz
>zzz
># ./busybox echo -n zzz
>zzz
># ./busybox env - echo -n zzz
>env: invalid option -- n
>
> obviously, env tried to understand -n as env's option
> instead of blindly passing it to echo...
>
>BusyBox v1.00-pre1 (2003.07.16-07:53+0000) multi-call binary
>
>Usage: env [-iu] [-] [name=value]... [command]
Ah, you found very old problem.
Last patch also have:
- multiple "-u unsetenv" support
- GNU long option support
- save errno after exec failed before bb_perror_msg()
--w
vodz
-rw-r--r-- | coreutils/env.c | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/coreutils/env.c b/coreutils/env.c index a07bd324c..d8a76e364 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -33,32 +33,58 @@ | |||
33 | * output error checking. | 33 | * output error checking. |
34 | */ | 34 | */ |
35 | 35 | ||
36 | /* | ||
37 | * Modified by Vladimir Oleynik <andersen@codepoet.org> (C) 2003 | ||
38 | * - corretion "-" option usage | ||
39 | * - multiple "-u unsetenv" support | ||
40 | * - GNU long option support | ||
41 | * - save errno after exec failed before bb_perror_msg() | ||
42 | */ | ||
43 | |||
44 | |||
36 | #include <stdio.h> | 45 | #include <stdio.h> |
37 | #include <string.h> | 46 | #include <string.h> |
38 | #include <stdlib.h> | 47 | #include <stdlib.h> |
39 | #include <errno.h> | 48 | #include <errno.h> |
40 | #include <unistd.h> | 49 | #include <unistd.h> |
50 | #include <getopt.h> | ||
41 | #include "busybox.h" | 51 | #include "busybox.h" |
42 | 52 | ||
53 | |||
54 | static const struct option env_long_options[] = { | ||
55 | { "ignore-environment", 0, NULL, 'i' }, | ||
56 | { "unset", 1, NULL, 'u' }, | ||
57 | { 0, 0, 0, 0 } | ||
58 | }; | ||
59 | |||
43 | extern int env_main(int argc, char** argv) | 60 | extern int env_main(int argc, char** argv) |
44 | { | 61 | { |
45 | char **ep, *p; | 62 | char **ep, *p; |
46 | char *cleanenv[1] = { NULL }; | 63 | char *cleanenv[1] = { NULL }; |
47 | unsigned long opt; | 64 | unsigned long opt; |
65 | llist_t *unset_env; | ||
66 | extern char **environ; | ||
48 | 67 | ||
49 | opt = bb_getopt_ulflags(argc, argv, "iu:", &p); | 68 | bb_opt_complementaly = "u*"; |
50 | if(opt & 1) | 69 | bb_applet_long_options = env_long_options; |
51 | environ = cleanenv; | ||
52 | if(opt & 2) | ||
53 | unsetenv(p); | ||
54 | 70 | ||
55 | argv += optind; | 71 | opt = bb_getopt_ulflags(argc, argv, "+iu:", &unset_env); |
56 | 72 | ||
73 | argv += optind; | ||
57 | if (*argv && (argv[0][0] == '-') && !argv[0][1]) { | 74 | if (*argv && (argv[0][0] == '-') && !argv[0][1]) { |
58 | environ = cleanenv; | 75 | opt |= 1; |
59 | ++argv; | 76 | ++argv; |
60 | } | 77 | } |
61 | 78 | ||
79 | if(opt & 1) | ||
80 | environ = cleanenv; | ||
81 | else if(opt & 2) { | ||
82 | while(unset_env) { | ||
83 | unsetenv(unset_env->data); | ||
84 | unset_env = unset_env->link; | ||
85 | } | ||
86 | } | ||
87 | |||
62 | while (*argv && ((p = strchr(*argv, '=')) != NULL)) { | 88 | while (*argv && ((p = strchr(*argv, '=')) != NULL)) { |
63 | if (putenv(*argv) < 0) { | 89 | if (putenv(*argv) < 0) { |
64 | bb_perror_msg_and_die("putenv"); | 90 | bb_perror_msg_and_die("putenv"); |
@@ -67,9 +93,12 @@ extern int env_main(int argc, char** argv) | |||
67 | } | 93 | } |
68 | 94 | ||
69 | if (*argv) { | 95 | if (*argv) { |
96 | int er; | ||
97 | |||
70 | execvp(*argv, argv); | 98 | execvp(*argv, argv); |
71 | bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ | 99 | er = errno; |
72 | return (errno == ENOENT) ? 127 : 126; /* SUSv3-mandated exit codes. */ | 100 | bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ |
101 | return (er == ENOENT) ? 127 : 126; /* SUSv3-mandated exit codes. */ | ||
73 | } | 102 | } |
74 | 103 | ||
75 | for (ep = environ; *ep; ep++) { | 104 | for (ep = environ; *ep; ep++) { |
@@ -81,7 +110,7 @@ extern int env_main(int argc, char** argv) | |||
81 | 110 | ||
82 | /* | 111 | /* |
83 | * Copyright (c) 1988, 1993, 1994 | 112 | * Copyright (c) 1988, 1993, 1994 |
84 | * The Regents of the University of California. All rights reserved. | 113 | * The Regents of the University of California. All rights reserved. |
85 | * | 114 | * |
86 | * Redistribution and use in source and binary forms, with or without | 115 | * Redistribution and use in source and binary forms, with or without |
87 | * modification, are permitted provided that the following conditions | 116 | * modification, are permitted provided that the following conditions |
@@ -92,8 +121,8 @@ extern int env_main(int argc, char** argv) | |||
92 | * notice, this list of conditions and the following disclaimer in the | 121 | * notice, this list of conditions and the following disclaimer in the |
93 | * documentation and/or other materials provided with the distribution. | 122 | * documentation and/or other materials provided with the distribution. |
94 | * | 123 | * |
95 | * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change | 124 | * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change |
96 | * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> | 125 | * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> |
97 | * | 126 | * |
98 | * 4. Neither the name of the University nor the names of its contributors | 127 | * 4. Neither the name of the University nor the names of its contributors |
99 | * may be used to endorse or promote products derived from this software | 128 | * may be used to endorse or promote products derived from this software |