diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-02 03:16:00 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-02 03:16:00 +0200 |
commit | 0cdb7ea380887053946664650673ff6f57310994 (patch) | |
tree | 45962c743602a8457b1e82135adb68e405c57160 | |
parent | 0aaaa50b4551ab5912ccd95d66d633844eac6d85 (diff) | |
download | busybox-w32-0cdb7ea380887053946664650673ff6f57310994.tar.gz busybox-w32-0cdb7ea380887053946664650673ff6f57310994.tar.bz2 busybox-w32-0cdb7ea380887053946664650673ff6f57310994.zip |
ash: support "--" in "source" builtin
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c index 4f6ba0c70..c358c5f85 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -12405,32 +12405,38 @@ find_dot_file(char *name) | |||
12405 | } | 12405 | } |
12406 | 12406 | ||
12407 | static int FAST_FUNC | 12407 | static int FAST_FUNC |
12408 | dotcmd(int argc, char **argv) | 12408 | dotcmd(int argc_ UNUSED_PARAM, char **argv_ UNUSED_PARAM) |
12409 | { | 12409 | { |
12410 | /* "false; . empty_file; echo $?" should print 0, not 1: */ | ||
12411 | int status = 0; | ||
12410 | char *fullname; | 12412 | char *fullname; |
12413 | char **argv; | ||
12411 | struct strlist *sp; | 12414 | struct strlist *sp; |
12412 | volatile struct shparam saveparam; | 12415 | volatile struct shparam saveparam; |
12413 | 12416 | ||
12414 | for (sp = cmdenviron; sp; sp = sp->next) | 12417 | for (sp = cmdenviron; sp; sp = sp->next) |
12415 | setvareq(ckstrdup(sp->text), VSTRFIXED | VTEXTFIXED); | 12418 | setvareq(ckstrdup(sp->text), VSTRFIXED | VTEXTFIXED); |
12416 | 12419 | ||
12417 | if (!argv[1]) { | 12420 | nextopt(nullstr); /* handle possible "--" */ |
12421 | argv = argptr; | ||
12422 | |||
12423 | if (!argv[0]) { | ||
12418 | /* bash says: "bash: .: filename argument required" */ | 12424 | /* bash says: "bash: .: filename argument required" */ |
12419 | return 2; /* bash compat */ | 12425 | return 2; /* bash compat */ |
12420 | } | 12426 | } |
12421 | 12427 | ||
12422 | /* "false; . empty_file; echo $?" should print 0, not 1: */ | ||
12423 | exitstatus = 0; | ||
12424 | |||
12425 | /* This aborts if file isn't found, which is POSIXly correct. | 12428 | /* This aborts if file isn't found, which is POSIXly correct. |
12426 | * bash returns exitcode 1 instead. | 12429 | * bash returns exitcode 1 instead. |
12427 | */ | 12430 | */ |
12428 | fullname = find_dot_file(argv[1]); | 12431 | fullname = find_dot_file(argv[0]); |
12429 | argv += 2; | 12432 | argv++; |
12430 | argc -= 2; | 12433 | if (argv[0]) { /* . FILE ARGS, ARGS exist */ |
12431 | if (argc) { /* argc > 0, argv[0] != NULL */ | 12434 | int argc; |
12432 | saveparam = shellparam; | 12435 | saveparam = shellparam; |
12433 | shellparam.malloced = 0; | 12436 | shellparam.malloced = 0; |
12437 | argc = 1; | ||
12438 | while (argv[argc]) | ||
12439 | argc++; | ||
12434 | shellparam.nparam = argc; | 12440 | shellparam.nparam = argc; |
12435 | shellparam.p = argv; | 12441 | shellparam.p = argv; |
12436 | }; | 12442 | }; |
@@ -12440,15 +12446,15 @@ dotcmd(int argc, char **argv) | |||
12440 | */ | 12446 | */ |
12441 | setinputfile(fullname, INPUT_PUSH_FILE); | 12447 | setinputfile(fullname, INPUT_PUSH_FILE); |
12442 | commandname = fullname; | 12448 | commandname = fullname; |
12443 | cmdloop(0); | 12449 | status = cmdloop(0); |
12444 | popfile(); | 12450 | popfile(); |
12445 | 12451 | ||
12446 | if (argc) { | 12452 | if (argv[0]) { |
12447 | freeparam(&shellparam); | 12453 | freeparam(&shellparam); |
12448 | shellparam = saveparam; | 12454 | shellparam = saveparam; |
12449 | }; | 12455 | }; |
12450 | 12456 | ||
12451 | return exitstatus; | 12457 | return status; |
12452 | } | 12458 | } |
12453 | 12459 | ||
12454 | static int FAST_FUNC | 12460 | static int FAST_FUNC |