about summary refs log tree commit diff
path: root/Src/exec.c
diff options
context:
space:
mode:
authorStephane Chazelas <stephane.chazelas@gmail.com>2018-03-14 14:42:48 +0000
committerPeter Stephenson <p.stephenson@samsung.com>2018-03-15 09:21:47 +0000
commit1219eae82938c918f5183e89af4a54296256372f (patch)
tree821e910f05856411a1b82deafea3c390e4dd85ae /Src/exec.c
parent7fd8e380bfc36013acf157de82dbf39e314d3dc4 (diff)
downloadzsh-1219eae82938c918f5183e89af4a54296256372f.tar.gz
zsh-1219eae82938c918f5183e89af4a54296256372f.tar.xz
zsh-1219eae82938c918f5183e89af4a54296256372f.zip
42465: Pass up error status from readoutput().
This improves the consistency of error reporting from $(...) constructs.
Diffstat (limited to 'Src/exec.c')
-rw-r--r--Src/exec.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/Src/exec.c b/Src/exec.c
index e5c64555c..ce8cf8c55 100644
--- a/Src/exec.c
+++ b/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--;