Commit c8a2079e49ee15dde10278865425ec9c36215f31
Committed by
Wolfgang Denk
1 parent
b41bc5a82d
Exists in
master
and in
54 other branches
common: add run_command2 for running simple or hush commands
Signed-off-by: Jason Hobbs <jason.hobbs@calxeda.com> Cc: Mike Frysinger <vapier@gentoo.org> Acked-by: Mike Frysinger <vapier@gentoo.org>
Showing 3 changed files with 29 additions and 31 deletions Side-by-side Diff
common/hush.c
... | ... | @@ -3217,7 +3217,7 @@ |
3217 | 3217 | #ifndef __U_BOOT__ |
3218 | 3218 | static int parse_string_outer(const char *s, int flag) |
3219 | 3219 | #else |
3220 | -int parse_string_outer(char *s, int flag) | |
3220 | +int parse_string_outer(const char *s, int flag) | |
3221 | 3221 | #endif /* __U_BOOT__ */ |
3222 | 3222 | { |
3223 | 3223 | struct in_str input; |
common/main.c
... | ... | @@ -83,8 +83,7 @@ |
83 | 83 | |
84 | 84 | /*************************************************************************** |
85 | 85 | * Watch for 'delay' seconds for autoboot stop or autoboot delay string. |
86 | - * returns: 0 - no key string, allow autoboot | |
87 | - * 1 - got key string, abort | |
86 | + * returns: 0 - no key string, allow autoboot 1 - got key string, abort | |
88 | 87 | */ |
89 | 88 | #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) |
90 | 89 | # if defined(CONFIG_AUTOBOOT_KEYED) |
... | ... | @@ -266,6 +265,26 @@ |
266 | 265 | # endif /* CONFIG_AUTOBOOT_KEYED */ |
267 | 266 | #endif /* CONFIG_BOOTDELAY >= 0 */ |
268 | 267 | |
268 | +/* | |
269 | + * Return 0 on success, or != 0 on error. | |
270 | + */ | |
271 | +static inline | |
272 | +int run_command2(const char *cmd, int flag) | |
273 | +{ | |
274 | +#ifndef CONFIG_SYS_HUSH_PARSER | |
275 | + /* | |
276 | + * run_command can return 0 or 1 for success, so clean up its result. | |
277 | + */ | |
278 | + if (run_command(cmd, flag) == -1) | |
279 | + return 1; | |
280 | + | |
281 | + return 0; | |
282 | +#else | |
283 | + return parse_string_outer(cmd, | |
284 | + FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP); | |
285 | +#endif | |
286 | +} | |
287 | + | |
269 | 288 | /****************************************************************************/ |
270 | 289 | |
271 | 290 | void main_loop (void) |
... | ... | @@ -332,12 +351,7 @@ |
332 | 351 | int prev = disable_ctrlc(1); /* disable Control C checking */ |
333 | 352 | # endif |
334 | 353 | |
335 | -# ifndef CONFIG_SYS_HUSH_PARSER | |
336 | - run_command (p, 0); | |
337 | -# else | |
338 | - parse_string_outer(p, FLAG_PARSE_SEMICOLON | | |
339 | - FLAG_EXIT_FROM_LOOP); | |
340 | -# endif | |
354 | + run_command2(p, 0); | |
341 | 355 | |
342 | 356 | # ifdef CONFIG_AUTOBOOT_KEYED |
343 | 357 | disable_ctrlc(prev); /* restore Control C checking */ |
... | ... | @@ -382,12 +396,7 @@ |
382 | 396 | int prev = disable_ctrlc(1); /* disable Control C checking */ |
383 | 397 | # endif |
384 | 398 | |
385 | -# ifndef CONFIG_SYS_HUSH_PARSER | |
386 | - run_command (s, 0); | |
387 | -# else | |
388 | - parse_string_outer(s, FLAG_PARSE_SEMICOLON | | |
389 | - FLAG_EXIT_FROM_LOOP); | |
390 | -# endif | |
399 | + run_command2(s, 0); | |
391 | 400 | |
392 | 401 | # ifdef CONFIG_AUTOBOOT_KEYED |
393 | 402 | disable_ctrlc(prev); /* restore Control C checking */ |
... | ... | @@ -397,14 +406,8 @@ |
397 | 406 | # ifdef CONFIG_MENUKEY |
398 | 407 | if (menukey == CONFIG_MENUKEY) { |
399 | 408 | s = getenv("menucmd"); |
400 | - if (s) { | |
401 | -# ifndef CONFIG_SYS_HUSH_PARSER | |
402 | - run_command(s, 0); | |
403 | -# else | |
404 | - parse_string_outer(s, FLAG_PARSE_SEMICOLON | | |
405 | - FLAG_EXIT_FROM_LOOP); | |
406 | -# endif | |
407 | - } | |
409 | + if (s) | |
410 | + run_command2(s, 0); | |
408 | 411 | } |
409 | 412 | #endif /* CONFIG_MENUKEY */ |
410 | 413 | #endif /* CONFIG_BOOTDELAY */ |
411 | 414 | |
... | ... | @@ -1403,14 +1406,9 @@ |
1403 | 1406 | printf ("## Error: \"%s\" not defined\n", argv[i]); |
1404 | 1407 | return 1; |
1405 | 1408 | } |
1406 | -#ifndef CONFIG_SYS_HUSH_PARSER | |
1407 | - if (run_command (arg, flag) == -1) | |
1409 | + | |
1410 | + if (run_command2(arg, flag) != 0) | |
1408 | 1411 | return 1; |
1409 | -#else | |
1410 | - if (parse_string_outer(arg, | |
1411 | - FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0) | |
1412 | - return 1; | |
1413 | -#endif | |
1414 | 1412 | } |
1415 | 1413 | return 0; |
1416 | 1414 | } |
include/hush.h
... | ... | @@ -29,7 +29,7 @@ |
29 | 29 | #define FLAG_REPARSING (1 << 2) /* >=2nd pass */ |
30 | 30 | |
31 | 31 | extern int u_boot_hush_start(void); |
32 | -extern int parse_string_outer(char *, int); | |
32 | +extern int parse_string_outer(const char *, int); | |
33 | 33 | extern int parse_file_outer(void); |
34 | 34 | |
35 | 35 | int set_local_var(const char *s, int flg_export); |