From e66cf821cf1e4bd8c1ef28445c0559269f69bab9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 18 May 2010 09:12:53 +0200 Subject: [PATCH] ash,hush: make bare "." set exitcode to 2 function old new delta dotcmd 300 305 +5 builtin_source 176 171 -5 Signed-off-by: Denys Vlasenko --- shell/ash.c | 45 +++++++++++++++++++++++++-------------------- shell/hush.c | 23 ++++++++++++++--------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index ea813e02f..641a14035 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12031,37 +12031,42 @@ find_dot_file(char *name) static int FAST_FUNC dotcmd(int argc, char **argv) { + char *fullname; struct strlist *sp; volatile struct shparam saveparam; for (sp = cmdenviron; sp; sp = sp->next) setvareq(ckstrdup(sp->text), VSTRFIXED | VTEXTFIXED); + if (!argv[1]) { + /* bash says: "bash: .: filename argument required" */ + return 2; /* bash compat */ + } + /* "false; . empty_file; echo $?" should print 0, not 1: */ exitstatus = 0; - if (argv[1]) { /* That's what SVR2 does */ - char *fullname = find_dot_file(argv[1]); + fullname = find_dot_file(argv[1]); - argv += 2; - argc -= 2; - if (argc) { /* argc > 0, argv[0] != NULL */ - saveparam = shellparam; - shellparam.malloced = 0; - shellparam.nparam = argc; - shellparam.p = argv; - }; - - setinputfile(fullname, INPUT_PUSH_FILE); - commandname = fullname; - cmdloop(0); - popfile(); + argv += 2; + argc -= 2; + if (argc) { /* argc > 0, argv[0] != NULL */ + saveparam = shellparam; + shellparam.malloced = 0; + shellparam.nparam = argc; + shellparam.p = argv; + }; + + setinputfile(fullname, INPUT_PUSH_FILE); + commandname = fullname; + cmdloop(0); + popfile(); + + if (argc) { + freeparam(&shellparam); + shellparam = saveparam; + }; - if (argc) { - freeparam(&shellparam); - shellparam = saveparam; - }; - } return exitstatus; } diff --git a/shell/hush.c b/shell/hush.c index e6c083f55..8baccf246 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -7870,21 +7870,26 @@ static int FAST_FUNC builtin_shift(char **argv) static int FAST_FUNC builtin_source(char **argv) { - char *arg_path; + char *arg_path, *filename; FILE *input; save_arg_t sv; #if ENABLE_HUSH_FUNCTIONS smallint sv_flg; #endif - if (*++argv == NULL) - return EXIT_FAILURE; - - if (strchr(*argv, '/') == NULL && (arg_path = find_in_path(*argv)) != NULL) { - input = fopen_for_read(arg_path); - free(arg_path); - } else - input = fopen_or_warn(*argv, "r"); + arg_path = NULL; + filename = *++argv; + if (!filename) { + /* bash says: "bash: .: filename argument required" */ + return 2; /* bash compat */ + } + if (!strchr(filename, '/')) { + arg_path = find_in_path(filename); + if (arg_path) + filename = arg_path; + } + input = fopen_or_warn(filename, "r"); + free(arg_path); if (!input) { /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */ return EXIT_FAILURE; -- 2.25.1