sh: Send the "xyz: not found" message to redirected fd 2.
This also fixes that trying to execute a non-regular file with a command name without '/' returns 127 instead of 126. The fix is rather simplistic: treat CMDUNKNOWN as if the command were found as an external program. The resulting fork is a bit wasteful but executing unknown commands should not be very frequent. PR: bin/137659
This commit is contained in:
parent
e6b112e274
commit
640b70e414
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=197820
@ -713,12 +713,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
||||
do_clearcmdentry = 1;
|
||||
}
|
||||
|
||||
find_command(argv[0], &cmdentry, 1, path);
|
||||
if (cmdentry.cmdtype == CMDUNKNOWN) { /* command not found */
|
||||
exitstatus = 127;
|
||||
flushout(&errout);
|
||||
return;
|
||||
}
|
||||
find_command(argv[0], &cmdentry, 0, path);
|
||||
/* implement the bltin builtin here */
|
||||
if (cmdentry.cmdtype == CMDBUILTIN && cmdentry.u.index == BLTINCMD) {
|
||||
for (;;) {
|
||||
@ -740,7 +735,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
||||
|
||||
/* Fork off a child process if necessary. */
|
||||
if (cmd->ncmd.backgnd
|
||||
|| (cmdentry.cmdtype == CMDNORMAL
|
||||
|| ((cmdentry.cmdtype == CMDNORMAL || cmdentry.cmdtype == CMDUNKNOWN)
|
||||
&& ((flags & EV_EXIT) == 0 || have_traps()))
|
||||
|| ((flags & EV_BACKCMD) != 0
|
||||
&& (cmdentry.cmdtype != CMDBUILTIN
|
||||
|
@ -429,6 +429,7 @@ find_command(char *name, struct cmdentry *entry, int printerr, char *path)
|
||||
outfmt(out2, "%s: %s\n", name, strerror(e));
|
||||
}
|
||||
entry->cmdtype = CMDUNKNOWN;
|
||||
entry->u.index = 0;
|
||||
return;
|
||||
|
||||
success:
|
||||
|
29
tools/regression/bin/sh/execution/unknown1.0
Normal file
29
tools/regression/bin/sh/execution/unknown1.0
Normal file
@ -0,0 +1,29 @@
|
||||
# $FreeBSD$
|
||||
|
||||
nosuchtool 2>/dev/null
|
||||
[ $? -ne 127 ] && exit 1
|
||||
/var/empty/nosuchtool 2>/dev/null
|
||||
[ $? -ne 127 ] && exit 1
|
||||
(nosuchtool) 2>/dev/null
|
||||
[ $? -ne 127 ] && exit 1
|
||||
(/var/empty/nosuchtool) 2>/dev/null
|
||||
[ $? -ne 127 ] && exit 1
|
||||
/ 2>/dev/null
|
||||
[ $? -ne 126 ] && exit 1
|
||||
PATH=/usr bin 2>/dev/null
|
||||
[ $? -ne 126 ] && exit 1
|
||||
|
||||
dummy=$(nosuchtool 2>/dev/null)
|
||||
[ $? -ne 127 ] && exit 1
|
||||
dummy=$(/var/empty/nosuchtool 2>/dev/null)
|
||||
[ $? -ne 127 ] && exit 1
|
||||
dummy=$( (nosuchtool) 2>/dev/null)
|
||||
[ $? -ne 127 ] && exit 1
|
||||
dummy=$( (/var/empty/nosuchtool) 2>/dev/null)
|
||||
[ $? -ne 127 ] && exit 1
|
||||
dummy=$(/ 2>/dev/null)
|
||||
[ $? -ne 126 ] && exit 1
|
||||
dummy=$(PATH=/usr bin 2>/dev/null)
|
||||
[ $? -ne 126 ] && exit 1
|
||||
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user