1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-30 07:10:58 +02:00

42465: Pass up error status from readoutput().

This improves the consistency of error reporting from $(...) constructs.
This commit is contained in:
Stephane Chazelas 2018-03-14 14:42:48 +00:00 committed by Peter Stephenson
parent 7fd8e380bf
commit 1219eae829
3 changed files with 21 additions and 4 deletions

View file

@ -1,3 +1,9 @@
2018-03-15 Peter Stephenson <p.stephenson@samsung.com>
* Stephane: 42465: Src/exec.c, Src/Modules/mapfile.c: pass error
status from readoutput, causing more consistent reporting
from $(...) constructs.
2018-03-12 Peter Stephenson <p.stephenson@samsung.com> 2018-03-12 Peter Stephenson <p.stephenson@samsung.com>
* 42453: Src/jobs.c: fix race looking up status of just * 42453: Src/jobs.c: fix race looking up status of just

View file

@ -197,8 +197,9 @@ get_contents(char *fname)
val = NULL; val = NULL;
if ((fd = open(fname, O_RDONLY | O_NOCTTY)) >= 0) { if ((fd = open(fname, O_RDONLY | O_NOCTTY)) >= 0) {
LinkList ll; LinkList ll;
int readerror;
if ((ll = readoutput(fd, 1))) if ((ll = readoutput(fd, 1, &readerror)))
val = peekfirst(ll); val = peekfirst(ll);
} }
#endif /* USE_MMAP */ #endif /* USE_MMAP */

View file

@ -4507,6 +4507,8 @@ getoutput(char *cmd, int qt)
if ((s = simple_redir_name(prog, REDIR_READ))) { if ((s = simple_redir_name(prog, REDIR_READ))) {
/* $(< word) */ /* $(< word) */
int stream; int stream;
LinkList retval;
int readerror;
singsub(&s); singsub(&s);
if (errflag) if (errflag)
@ -4514,9 +4516,15 @@ getoutput(char *cmd, int qt)
untokenize(s); untokenize(s);
if ((stream = open(unmeta(s), O_RDONLY | O_NOCTTY)) == -1) { if ((stream = open(unmeta(s), O_RDONLY | O_NOCTTY)) == -1) {
zwarn("%e: %s", errno, s); zwarn("%e: %s", errno, s);
lastval = cmdoutval = 1;
return newlinklist(); return newlinklist();
} }
return readoutput(stream, qt); retval = readoutput(stream, qt, &readerror);
if (readerror) {
zwarn("error when reading %s: %e", s, readerror);
lastval = cmdoutval = 1;
}
return retval;
} }
if (mpipe(pipes) < 0) { if (mpipe(pipes) < 0) {
errflag |= ERRFLAG_ERROR; errflag |= ERRFLAG_ERROR;
@ -4537,7 +4545,7 @@ getoutput(char *cmd, int qt)
LinkList retval; LinkList retval;
zclose(pipes[1]); zclose(pipes[1]);
retval = readoutput(pipes[0], qt); retval = readoutput(pipes[0], qt, NULL);
fdtable[pipes[0]] = FDT_UNUSED; fdtable[pipes[0]] = FDT_UNUSED;
waitforpid(pid, 0); /* unblocks */ waitforpid(pid, 0); /* unblocks */
lastval = cmdoutval; lastval = cmdoutval;
@ -4562,7 +4570,7 @@ getoutput(char *cmd, int qt)
/**/ /**/
mod_export LinkList mod_export LinkList
readoutput(int in, int qt) readoutput(int in, int qt, int *readerror)
{ {
LinkList ret; LinkList ret;
char *buf, *ptr; char *buf, *ptr;
@ -4591,6 +4599,8 @@ readoutput(int in, int qt)
} }
*ptr++ = c; *ptr++ = c;
} }
if (readerror && ferror(fin))
*readerror = errno;
fclose(fin); fclose(fin);
while (cnt && ptr[-1] == '\n') while (cnt && ptr[-1] == '\n')
ptr--, cnt--; ptr--, cnt--;