about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Src/Modules/mapfile.c3
-rw-r--r--Src/exec.c16
3 files changed, 21 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 97e23e456..155bfe29e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/Src/Modules/mapfile.c b/Src/Modules/mapfile.c
index 2503b361e..771e5b5fc 100644
--- a/Src/Modules/mapfile.c
+++ b/Src/Modules/mapfile.c
@@ -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 */
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--;