aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-05-18 09:12:53 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-05-18 09:12:53 +0200
commite66cf821cf1e4bd8c1ef28445c0559269f69bab9 (patch)
tree3ab9c437fccd1b613570c5af054c6145278677f0
parenta1db8b8415cbac40c679a1ac11f90e97bf5a95f9 (diff)
downloadbusybox-w32-e66cf821cf1e4bd8c1ef28445c0559269f69bab9.tar.gz
busybox-w32-e66cf821cf1e4bd8c1ef28445c0559269f69bab9.tar.bz2
busybox-w32-e66cf821cf1e4bd8c1ef28445c0559269f69bab9.zip
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 <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c45
-rw-r--r--shell/hush.c23
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)
12031static int FAST_FUNC 12031static int FAST_FUNC
12032dotcmd(int argc, char **argv) 12032dotcmd(int argc, char **argv)
12033{ 12033{
12034 char *fullname;
12034 struct strlist *sp; 12035 struct strlist *sp;
12035 volatile struct shparam saveparam; 12036 volatile struct shparam saveparam;
12036 12037
12037 for (sp = cmdenviron; sp; sp = sp->next) 12038 for (sp = cmdenviron; sp; sp = sp->next)
12038 setvareq(ckstrdup(sp->text), VSTRFIXED | VTEXTFIXED); 12039 setvareq(ckstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
12039 12040
12041 if (!argv[1]) {
12042 /* bash says: "bash: .: filename argument required" */
12043 return 2; /* bash compat */
12044 }
12045
12040 /* "false; . empty_file; echo $?" should print 0, not 1: */ 12046 /* "false; . empty_file; echo $?" should print 0, not 1: */
12041 exitstatus = 0; 12047 exitstatus = 0;
12042 12048
12043 if (argv[1]) { /* That's what SVR2 does */ 12049 fullname = find_dot_file(argv[1]);
12044 char *fullname = find_dot_file(argv[1]);
12045 12050
12046 argv += 2; 12051 argv += 2;
12047 argc -= 2; 12052 argc -= 2;
12048 if (argc) { /* argc > 0, argv[0] != NULL */ 12053 if (argc) { /* argc > 0, argv[0] != NULL */
12049 saveparam = shellparam; 12054 saveparam = shellparam;
12050 shellparam.malloced = 0; 12055 shellparam.malloced = 0;
12051 shellparam.nparam = argc; 12056 shellparam.nparam = argc;
12052 shellparam.p = argv; 12057 shellparam.p = argv;
12053 }; 12058 };
12054 12059
12055 setinputfile(fullname, INPUT_PUSH_FILE); 12060 setinputfile(fullname, INPUT_PUSH_FILE);
12056 commandname = fullname; 12061 commandname = fullname;
12057 cmdloop(0); 12062 cmdloop(0);
12058 popfile(); 12063 popfile();
12064
12065 if (argc) {
12066 freeparam(&shellparam);
12067 shellparam = saveparam;
12068 };
12059 12069
12060 if (argc) {
12061 freeparam(&shellparam);
12062 shellparam = saveparam;
12063 };
12064 }
12065 return exitstatus; 12070 return exitstatus;
12066} 12071}
12067 12072
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)
7870 7870
7871static int FAST_FUNC builtin_source(char **argv) 7871static int FAST_FUNC builtin_source(char **argv)
7872{ 7872{
7873 char *arg_path; 7873 char *arg_path, *filename;
7874 FILE *input; 7874 FILE *input;
7875 save_arg_t sv; 7875 save_arg_t sv;
7876#if ENABLE_HUSH_FUNCTIONS 7876#if ENABLE_HUSH_FUNCTIONS
7877 smallint sv_flg; 7877 smallint sv_flg;
7878#endif 7878#endif
7879 7879
7880 if (*++argv == NULL) 7880 arg_path = NULL;
7881 return EXIT_FAILURE; 7881 filename = *++argv;
7882 7882 if (!filename) {
7883 if (strchr(*argv, '/') == NULL && (arg_path = find_in_path(*argv)) != NULL) { 7883 /* bash says: "bash: .: filename argument required" */
7884 input = fopen_for_read(arg_path); 7884 return 2; /* bash compat */
7885 free(arg_path); 7885 }
7886 } else 7886 if (!strchr(filename, '/')) {
7887 input = fopen_or_warn(*argv, "r"); 7887 arg_path = find_in_path(filename);
7888 if (arg_path)
7889 filename = arg_path;
7890 }
7891 input = fopen_or_warn(filename, "r");
7892 free(arg_path);
7888 if (!input) { 7893 if (!input) {
7889 /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */ 7894 /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */
7890 return EXIT_FAILURE; 7895 return EXIT_FAILURE;