mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-26 18:01:03 +02:00
42465: Pass up error status from readoutput().
This improves the consistency of error reporting from $(...) constructs.
This commit is contained in:
parent
7fd8e380bf
commit
1219eae829
3 changed files with 21 additions and 4 deletions
|
@ -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>
|
||||
|
||||
* 42453: Src/jobs.c: fix race looking up status of just
|
||||
|
|
|
@ -197,8 +197,9 @@ get_contents(char *fname)
|
|||
val = NULL;
|
||||
if ((fd = open(fname, O_RDONLY | O_NOCTTY)) >= 0) {
|
||||
LinkList ll;
|
||||
int readerror;
|
||||
|
||||
if ((ll = readoutput(fd, 1)))
|
||||
if ((ll = readoutput(fd, 1, &readerror)))
|
||||
val = peekfirst(ll);
|
||||
}
|
||||
#endif /* USE_MMAP */
|
||||
|
|
16
Src/exec.c
16
Src/exec.c
|
@ -4507,6 +4507,8 @@ getoutput(char *cmd, int qt)
|
|||
if ((s = simple_redir_name(prog, REDIR_READ))) {
|
||||
/* $(< word) */
|
||||
int stream;
|
||||
LinkList retval;
|
||||
int readerror;
|
||||
|
||||
singsub(&s);
|
||||
if (errflag)
|
||||
|
@ -4514,9 +4516,15 @@ getoutput(char *cmd, int qt)
|
|||
untokenize(s);
|
||||
if ((stream = open(unmeta(s), O_RDONLY | O_NOCTTY)) == -1) {
|
||||
zwarn("%e: %s", errno, s);
|
||||
lastval = cmdoutval = 1;
|
||||
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) {
|
||||
errflag |= ERRFLAG_ERROR;
|
||||
|
@ -4537,7 +4545,7 @@ getoutput(char *cmd, int qt)
|
|||
LinkList retval;
|
||||
|
||||
zclose(pipes[1]);
|
||||
retval = readoutput(pipes[0], qt);
|
||||
retval = readoutput(pipes[0], qt, NULL);
|
||||
fdtable[pipes[0]] = FDT_UNUSED;
|
||||
waitforpid(pid, 0); /* unblocks */
|
||||
lastval = cmdoutval;
|
||||
|
@ -4562,7 +4570,7 @@ getoutput(char *cmd, int qt)
|
|||
|
||||
/**/
|
||||
mod_export LinkList
|
||||
readoutput(int in, int qt)
|
||||
readoutput(int in, int qt, int *readerror)
|
||||
{
|
||||
LinkList ret;
|
||||
char *buf, *ptr;
|
||||
|
@ -4591,6 +4599,8 @@ readoutput(int in, int qt)
|
|||
}
|
||||
*ptr++ = c;
|
||||
}
|
||||
if (readerror && ferror(fin))
|
||||
*readerror = errno;
|
||||
fclose(fin);
|
||||
while (cnt && ptr[-1] == '\n')
|
||||
ptr--, cnt--;
|
||||
|
|
Loading…
Reference in a new issue