diff options
author | stefanf <stefanf@FreeBSD.org> | 2006-04-09 12:21:20 +0000 |
---|---|---|
committer | stefanf <stefanf@FreeBSD.org> | 2006-04-09 12:21:20 +0000 |
commit | 968438f2fcefda39356b35981197656400d90f0f (patch) | |
tree | b2e9e5bfdcae5d9e40672127fa23de6d02ac47ee /bin/sh/exec.c | |
parent | 209025405d1718f956439567f56fb8504bbfc6cf (diff) | |
download | FreeBSD-src-968438f2fcefda39356b35981197656400d90f0f.zip FreeBSD-src-968438f2fcefda39356b35981197656400d90f0f.tar.gz |
Implement some of the differences between special built-ins and other builtins
demanded by POSIX.
- A redirection error is only fatal (meaning the execution of a shell script is
terminated) for special built-ins. Previously it was fatal for all shell
builtins, causing problems like the one reported in PR 88845.
- Variable assignments remain in effect for special built-ins.
- Option or operand errors are only fatal for special built-ins.
This change also makes errors from 'fc' non-fatal (I could not find any reasons
for this behaviour).
Somewhat independently from the above down-grade the error handling in the
shift built-in if the operand is bigger than $# from an error() call (which is
now fatal) to a return 1. I'm not sure if this should be considered a POSIX
"operand error", however this change is needed for now as we trigger that error
while building libncurses. Comparing with other shells, zsh does the same as
our sh before this change (write a diagnostic, return 1), bash behaves as our
sh after this commit (no diagnostic, return 1) and ksh93 and NetBSD's sh treat
it as a fatal error.
Diffstat (limited to 'bin/sh/exec.c')
-rw-r--r-- | bin/sh/exec.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/bin/sh/exec.c b/bin/sh/exec.c index d983849..85794d9 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -84,6 +84,7 @@ __FBSDID("$FreeBSD$"); struct tblentry { struct tblentry *next; /* next entry in hash chain */ union param param; /* definition of builtin function */ + int special; /* flag for special builtin commands */ short cmdtype; /* index identifying command */ char rehash; /* if set, cd done since entry created */ char cmdname[ARB]; /* name of command */ @@ -317,6 +318,7 @@ find_command(char *name, struct cmdentry *entry, int printerr, char *path) struct stat statb; int e; int i; + int spec; /* If name contains a slash, don't use the hash table */ if (strchr(name, '/') != NULL) { @@ -330,11 +332,12 @@ find_command(char *name, struct cmdentry *entry, int printerr, char *path) goto success; /* If %builtin not in path, check for builtin next */ - if (builtinloc < 0 && (i = find_builtin(name)) >= 0) { + if (builtinloc < 0 && (i = find_builtin(name, &spec)) >= 0) { INTOFF; cmdp = cmdlookup(name, 1); cmdp->cmdtype = CMDBUILTIN; cmdp->param.index = i; + cmdp->special = spec; INTON; goto success; } @@ -356,12 +359,13 @@ loop: index++; if (pathopt) { if (prefix("builtin", pathopt)) { - if ((i = find_builtin(name)) < 0) + if ((i = find_builtin(name, &spec)) < 0) goto loop; INTOFF; cmdp = cmdlookup(name, 1); cmdp->cmdtype = CMDBUILTIN; cmdp->param.index = i; + cmdp->special = spec; INTON; goto success; } else if (prefix("func", pathopt)) { @@ -430,6 +434,7 @@ success: cmdp->rehash = 0; entry->cmdtype = cmdp->cmdtype; entry->u = cmdp->param; + entry->special = cmdp->special; } @@ -439,13 +444,15 @@ success: */ int -find_builtin(char *name) +find_builtin(char *name, int *special) { const struct builtincmd *bp; for (bp = builtincmd ; bp->name ; bp++) { - if (*bp->name == *name && equal(bp->name, name)) + if (*bp->name == *name && equal(bp->name, name)) { + *special = bp->special; return bp->code; + } } return -1; } |