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>
This commit is contained in:
parent
a1db8b8415
commit
e66cf821cf
43
shell/ash.c
43
shell/ash.c
@ -12031,37 +12031,42 @@ find_dot_file(char *name)
|
|||||||
static int FAST_FUNC
|
static int FAST_FUNC
|
||||||
dotcmd(int argc, char **argv)
|
dotcmd(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
char *fullname;
|
||||||
struct strlist *sp;
|
struct strlist *sp;
|
||||||
volatile struct shparam saveparam;
|
volatile struct shparam saveparam;
|
||||||
|
|
||||||
for (sp = cmdenviron; sp; sp = sp->next)
|
for (sp = cmdenviron; sp; sp = sp->next)
|
||||||
setvareq(ckstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
|
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: */
|
/* "false; . empty_file; echo $?" should print 0, not 1: */
|
||||||
exitstatus = 0;
|
exitstatus = 0;
|
||||||
|
|
||||||
if (argv[1]) { /* That's what SVR2 does */
|
fullname = find_dot_file(argv[1]);
|
||||||
char *fullname = find_dot_file(argv[1]);
|
|
||||||
|
|
||||||
argv += 2;
|
argv += 2;
|
||||||
argc -= 2;
|
argc -= 2;
|
||||||
if (argc) { /* argc > 0, argv[0] != NULL */
|
if (argc) { /* argc > 0, argv[0] != NULL */
|
||||||
saveparam = shellparam;
|
saveparam = shellparam;
|
||||||
shellparam.malloced = 0;
|
shellparam.malloced = 0;
|
||||||
shellparam.nparam = argc;
|
shellparam.nparam = argc;
|
||||||
shellparam.p = argv;
|
shellparam.p = argv;
|
||||||
};
|
};
|
||||||
|
|
||||||
setinputfile(fullname, INPUT_PUSH_FILE);
|
setinputfile(fullname, INPUT_PUSH_FILE);
|
||||||
commandname = fullname;
|
commandname = fullname;
|
||||||
cmdloop(0);
|
cmdloop(0);
|
||||||
popfile();
|
popfile();
|
||||||
|
|
||||||
|
if (argc) {
|
||||||
|
freeparam(&shellparam);
|
||||||
|
shellparam = saveparam;
|
||||||
|
};
|
||||||
|
|
||||||
if (argc) {
|
|
||||||
freeparam(&shellparam);
|
|
||||||
shellparam = saveparam;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return exitstatus;
|
return exitstatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
shell/hush.c
23
shell/hush.c
@ -7870,21 +7870,26 @@ static int FAST_FUNC builtin_shift(char **argv)
|
|||||||
|
|
||||||
static int FAST_FUNC builtin_source(char **argv)
|
static int FAST_FUNC builtin_source(char **argv)
|
||||||
{
|
{
|
||||||
char *arg_path;
|
char *arg_path, *filename;
|
||||||
FILE *input;
|
FILE *input;
|
||||||
save_arg_t sv;
|
save_arg_t sv;
|
||||||
#if ENABLE_HUSH_FUNCTIONS
|
#if ENABLE_HUSH_FUNCTIONS
|
||||||
smallint sv_flg;
|
smallint sv_flg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (*++argv == NULL)
|
arg_path = NULL;
|
||||||
return EXIT_FAILURE;
|
filename = *++argv;
|
||||||
|
if (!filename) {
|
||||||
if (strchr(*argv, '/') == NULL && (arg_path = find_in_path(*argv)) != NULL) {
|
/* bash says: "bash: .: filename argument required" */
|
||||||
input = fopen_for_read(arg_path);
|
return 2; /* bash compat */
|
||||||
free(arg_path);
|
}
|
||||||
} else
|
if (!strchr(filename, '/')) {
|
||||||
input = fopen_or_warn(*argv, "r");
|
arg_path = find_in_path(filename);
|
||||||
|
if (arg_path)
|
||||||
|
filename = arg_path;
|
||||||
|
}
|
||||||
|
input = fopen_or_warn(filename, "r");
|
||||||
|
free(arg_path);
|
||||||
if (!input) {
|
if (!input) {
|
||||||
/* bb_perror_msg("%s", *argv); - done by fopen_or_warn */
|
/* bb_perror_msg("%s", *argv); - done by fopen_or_warn */
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user