diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-07 16:05:04 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-07 16:05:04 +0200 |
commit | 764b2f0ec0b1ac8c7617d732c1a015a9e8598820 (patch) | |
tree | 760353e451e9ba7a1c2081f1a7432c9500d2f883 | |
parent | df5131cf3dd2c3d4e53c64b8b73f6cd18b46f6d3 (diff) | |
download | busybox-w32-764b2f0ec0b1ac8c7617d732c1a015a9e8598820.tar.gz busybox-w32-764b2f0ec0b1ac8c7617d732c1a015a9e8598820.tar.bz2 busybox-w32-764b2f0ec0b1ac8c7617d732c1a015a9e8598820.zip |
hush: drop REDIRECT_INVALID; other minor tweaks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/shell/hush.c b/shell/hush.c index 6c20615fa..9ecb60293 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -173,23 +173,6 @@ typedef struct nommu_save_t { | |||
173 | } nommu_save_t; | 173 | } nommu_save_t; |
174 | #endif | 174 | #endif |
175 | 175 | ||
176 | /* The descrip member of this structure is only used to make | ||
177 | * debugging output pretty */ | ||
178 | static const struct { | ||
179 | int mode; | ||
180 | signed char default_fd; | ||
181 | char descrip[3]; | ||
182 | } redir_table[] = { | ||
183 | { 0, 0, "??" }, | ||
184 | { O_RDONLY, 0, "<" }, | ||
185 | { O_CREAT|O_TRUNC|O_WRONLY, 1, ">" }, | ||
186 | { O_CREAT|O_APPEND|O_WRONLY, 1, ">>" }, | ||
187 | { O_RDONLY, 0, "<<" }, | ||
188 | { O_CREAT|O_RDWR, 1, "<>" }, | ||
189 | /* Should not be needed. Bogus default_fd helps in debugging */ | ||
190 | /* { O_RDONLY, 77, "<<" }, */ | ||
191 | }; | ||
192 | |||
193 | typedef enum reserved_style { | 176 | typedef enum reserved_style { |
194 | RES_NONE = 0, | 177 | RES_NONE = 0, |
195 | #if ENABLE_HUSH_IF | 178 | #if ENABLE_HUSH_IF |
@@ -262,6 +245,22 @@ typedef struct in_str { | |||
262 | #define i_getch(input) ((input)->get(input)) | 245 | #define i_getch(input) ((input)->get(input)) |
263 | #define i_peek(input) ((input)->peek(input)) | 246 | #define i_peek(input) ((input)->peek(input)) |
264 | 247 | ||
248 | /* The descrip member of this structure is only used to make | ||
249 | * debugging output pretty */ | ||
250 | static const struct { | ||
251 | int mode; | ||
252 | signed char default_fd; | ||
253 | char descrip[3]; | ||
254 | } redir_table[] = { | ||
255 | { O_RDONLY, 0, "<" }, | ||
256 | { O_CREAT|O_TRUNC|O_WRONLY, 1, ">" }, | ||
257 | { O_CREAT|O_APPEND|O_WRONLY, 1, ">>" }, | ||
258 | { O_CREAT|O_RDWR, 1, "<>" }, | ||
259 | { O_RDONLY, 0, "<<" }, | ||
260 | /* Should not be needed. Bogus default_fd helps in debugging */ | ||
261 | /* { O_RDONLY, 77, "<<" }, */ | ||
262 | }; | ||
263 | |||
265 | struct redir_struct { | 264 | struct redir_struct { |
266 | struct redir_struct *next; | 265 | struct redir_struct *next; |
267 | char *rd_filename; /* filename */ | 266 | char *rd_filename; /* filename */ |
@@ -271,18 +270,17 @@ struct redir_struct { | |||
271 | smallint rd_type; /* (enum redir_type) */ | 270 | smallint rd_type; /* (enum redir_type) */ |
272 | /* note: for heredocs, rd_filename contains heredoc delimiter, | 271 | /* note: for heredocs, rd_filename contains heredoc delimiter, |
273 | * and subsequently heredoc itself; and rd_dup is a bitmask: | 272 | * and subsequently heredoc itself; and rd_dup is a bitmask: |
274 | * 1: do we need to trim leading tabs? | 273 | * bit 0: do we need to trim leading tabs? |
275 | * 2: is heredoc quoted (<<'delim' syntax) ? | 274 | * bit 1: is heredoc quoted (<<'delim' syntax) ? |
276 | */ | 275 | */ |
277 | }; | 276 | }; |
278 | typedef enum redir_type { | 277 | typedef enum redir_type { |
279 | REDIRECT_INVALID = 0, | 278 | REDIRECT_INPUT = 0, |
280 | REDIRECT_INPUT = 1, | 279 | REDIRECT_OVERWRITE = 1, |
281 | REDIRECT_OVERWRITE = 2, | 280 | REDIRECT_APPEND = 2, |
282 | REDIRECT_APPEND = 3, | 281 | REDIRECT_IO = 3, |
283 | REDIRECT_HEREDOC = 4, | 282 | REDIRECT_HEREDOC = 4, |
284 | REDIRECT_IO = 5, | 283 | REDIRECT_HEREDOC2 = 5, /* REDIRECT_HEREDOC after heredoc is loaded */ |
285 | REDIRECT_HEREDOC2 = 6, /* REDIRECT_HEREDOC after heredoc is loaded */ | ||
286 | 284 | ||
287 | REDIRFD_CLOSE = -3, | 285 | REDIRFD_CLOSE = -3, |
288 | REDIRFD_SYNTAX_ERR = -2, | 286 | REDIRFD_SYNTAX_ERR = -2, |
@@ -3093,13 +3091,13 @@ static void unset_func(const char *name) | |||
3093 | } | 3091 | } |
3094 | 3092 | ||
3095 | # if BB_MMU | 3093 | # if BB_MMU |
3096 | #define exec_function(nommu_save, funcp, argv) \ | 3094 | #define exec_function(to_free, funcp, argv) \ |
3097 | exec_function(funcp, argv) | 3095 | exec_function(funcp, argv) |
3098 | # endif | 3096 | # endif |
3099 | static void exec_function(nommu_save_t *nommu_save, | 3097 | static void exec_function(char ***to_free, |
3100 | const struct function *funcp, | 3098 | const struct function *funcp, |
3101 | char **argv) NORETURN; | 3099 | char **argv) NORETURN; |
3102 | static void exec_function(nommu_save_t *nommu_save, | 3100 | static void exec_function(char ***to_free, |
3103 | const struct function *funcp, | 3101 | const struct function *funcp, |
3104 | char **argv) | 3102 | char **argv) |
3105 | { | 3103 | { |
@@ -3116,7 +3114,7 @@ static void exec_function(nommu_save_t *nommu_save, | |||
3116 | fflush(NULL); | 3114 | fflush(NULL); |
3117 | _exit(n); | 3115 | _exit(n); |
3118 | # else | 3116 | # else |
3119 | re_execute_shell(&nommu_save->argv_from_re_execing, | 3117 | re_execute_shell(to_free, |
3120 | funcp->body_as_string, | 3118 | funcp->body_as_string, |
3121 | G.global_argv[0], | 3119 | G.global_argv[0], |
3122 | argv + 1, | 3120 | argv + 1, |
@@ -3185,16 +3183,16 @@ static int run_function(const struct function *funcp, char **argv) | |||
3185 | 3183 | ||
3186 | 3184 | ||
3187 | # if BB_MMU | 3185 | # if BB_MMU |
3188 | #define exec_builtin(nommu_save, x, argv) \ | 3186 | #define exec_builtin(to_free, x, argv) \ |
3189 | exec_builtin(x, argv) | 3187 | exec_builtin(x, argv) |
3190 | # else | 3188 | # else |
3191 | #define exec_builtin(nommu_save, x, argv) \ | 3189 | #define exec_builtin(to_free, x, argv) \ |
3192 | exec_builtin(nommu_save, argv) | 3190 | exec_builtin(to_free, argv) |
3193 | # endif | 3191 | # endif |
3194 | static void exec_builtin(nommu_save_t *nommu_save, | 3192 | static void exec_builtin(char ***to_free, |
3195 | const struct built_in_command *x, | 3193 | const struct built_in_command *x, |
3196 | char **argv) NORETURN; | 3194 | char **argv) NORETURN; |
3197 | static void exec_builtin(nommu_save_t *nommu_save, | 3195 | static void exec_builtin(char ***to_free, |
3198 | const struct built_in_command *x, | 3196 | const struct built_in_command *x, |
3199 | char **argv) | 3197 | char **argv) |
3200 | { | 3198 | { |
@@ -3206,7 +3204,7 @@ static void exec_builtin(nommu_save_t *nommu_save, | |||
3206 | /* On NOMMU, we must never block! | 3204 | /* On NOMMU, we must never block! |
3207 | * Example: { sleep 99 | read line; } & echo Ok | 3205 | * Example: { sleep 99 | read line; } & echo Ok |
3208 | */ | 3206 | */ |
3209 | re_execute_shell(&nommu_save->argv_from_re_execing, | 3207 | re_execute_shell(to_free, |
3210 | argv[0], | 3208 | argv[0], |
3211 | G.global_argv[0], | 3209 | G.global_argv[0], |
3212 | G.global_argv + 1, | 3210 | G.global_argv + 1, |
@@ -3277,7 +3275,7 @@ static void pseudo_exec_argv(nommu_save_t *nommu_save, | |||
3277 | const struct built_in_command *x; | 3275 | const struct built_in_command *x; |
3278 | x = BB_MMU ? find_builtin(argv[0]) : find_builtin1(argv[0]); | 3276 | x = BB_MMU ? find_builtin(argv[0]) : find_builtin1(argv[0]); |
3279 | if (x) { | 3277 | if (x) { |
3280 | exec_builtin(nommu_save, x, argv); | 3278 | exec_builtin(&nommu_save->argv_from_re_execing, x, argv); |
3281 | } | 3279 | } |
3282 | } | 3280 | } |
3283 | #if ENABLE_HUSH_FUNCTIONS | 3281 | #if ENABLE_HUSH_FUNCTIONS |
@@ -3285,7 +3283,7 @@ static void pseudo_exec_argv(nommu_save_t *nommu_save, | |||
3285 | { | 3283 | { |
3286 | const struct function *funcp = find_function(argv[0]); | 3284 | const struct function *funcp = find_function(argv[0]); |
3287 | if (funcp) { | 3285 | if (funcp) { |
3288 | exec_function(nommu_save, funcp, argv); | 3286 | exec_function(&nommu_save->argv_from_re_execing, funcp, argv); |
3289 | } | 3287 | } |
3290 | } | 3288 | } |
3291 | #endif | 3289 | #endif |
@@ -5025,7 +5023,7 @@ static int fetch_heredocs(int heredoc_cnt, struct parse_context *ctx, struct in_ | |||
5025 | char *p; | 5023 | char *p; |
5026 | 5024 | ||
5027 | redir->rd_type = REDIRECT_HEREDOC2; | 5025 | redir->rd_type = REDIRECT_HEREDOC2; |
5028 | /* redir->dup is (ab)used to indicate <<- */ | 5026 | /* redir->rd_dup is (ab)used to indicate <<- */ |
5029 | p = fetch_till_str(&ctx->as_string, input, | 5027 | p = fetch_till_str(&ctx->as_string, input, |
5030 | redir->rd_filename, redir->rd_dup & HEREDOC_SKIPTABS); | 5028 | redir->rd_filename, redir->rd_dup & HEREDOC_SKIPTABS); |
5031 | if (!p) { | 5029 | if (!p) { |
@@ -6122,10 +6120,8 @@ static struct pipe *parse_stream(char **pstring, | |||
6122 | IF_HAS_KEYWORDS(struct parse_context *p2;) | 6120 | IF_HAS_KEYWORDS(struct parse_context *p2;) |
6123 | 6121 | ||
6124 | /* Clean up allocated tree. | 6122 | /* Clean up allocated tree. |
6125 | * Samples for finding leaks on syntax error recovery path. | 6123 | * Sample for finding leaks on syntax error recovery path. |
6126 | * Run them from interactive shell, watch pmap `pidof hush`. | 6124 | * Run it from interactive shell, watch pmap `pidof hush`. |
6127 | * while if false; then false; fi do break; done | ||
6128 | * (bash accepts it) | ||
6129 | * while if false; then false; fi; do break; fi | 6125 | * while if false; then false; fi; do break; fi |
6130 | * Samples to catch leaks at execution: | 6126 | * Samples to catch leaks at execution: |
6131 | * while if (true | {true;}); then echo ok; fi; do break; done | 6127 | * while if (true | {true;}); then echo ok; fi; do break; done |