partial merge and full RCS ID sync with oksh
merged: • new regression tests • check.pl (tests/th) better tmpfile handling • exec.c 1.50: POSIX specifies that for an AND/OR list, only the last command's exit status matters for "set -e" • ksh.1 1.147: document the above • eval.c 1.39: “Make $(< /nonexistent) have the same behaviour as $(cat /nonexistent) wrt. errors (do not unwind and do not treat this as fatal if set -e is used).” ‣ additionally make shf_open() return errno and actually show the error message from the system • regression-39 test: remove the “maybe” marker ‣ but decide on correct POSIX behaviour already been fixed in mksh: • check.pl (tests/th) exit 1 if tests fail not merged: • main.c 1.52: run traps in unwind() before exiting; I’m pretty sure this is already working as-should in mksh • eval.c 1.38: “Commands executed via `foo` or $( bar ) should not inherit "set -e" status.” As discussed in IRC, this is just plainly WRONG.
This commit is contained in:
8
shf.c
8
shf.c
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.60 2013/06/01 20:34:01 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.61 2013/07/21 18:36:03 tg Exp $");
|
||||
|
||||
/* flags to shf_emptybuf() */
|
||||
#define EB_READSW 0x01 /* about to switch to reading */
|
||||
@@ -52,7 +52,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
||||
ssize_t bsize =
|
||||
/* at most 512 */
|
||||
sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE;
|
||||
int fd;
|
||||
int fd, eno;
|
||||
|
||||
/* Done before open so if alloca fails, fd won't be lost. */
|
||||
shf = alloc(sizeof(struct shf) + bsize, ATEMP);
|
||||
@@ -64,16 +64,20 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
||||
|
||||
fd = open(name, oflags, mode);
|
||||
if (fd < 0) {
|
||||
eno = errno;
|
||||
afree(shf, shf->areap);
|
||||
errno = eno;
|
||||
return (NULL);
|
||||
}
|
||||
if ((sflags & SHF_MAPHI) && fd < FDBASE) {
|
||||
int nfd;
|
||||
|
||||
nfd = fcntl(fd, F_DUPFD, FDBASE);
|
||||
eno = errno;
|
||||
close(fd);
|
||||
if (nfd < 0) {
|
||||
afree(shf, shf->areap);
|
||||
errno = eno;
|
||||
return (NULL);
|
||||
}
|
||||
fd = nfd;
|
||||
|
Reference in New Issue
Block a user