summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2010-09-19 19:20:33 +0000
committerBart Schaefer <barts@users.sourceforge.net>2010-09-19 19:20:33 +0000
commit9530331b4f04015eb65341c97940f68774ab210b (patch)
tree05b9073dd36835c93eb6cbeaaf2fc7d8753aa1dc /Src
parentdd061dc2ce8aed2145c00c620a541be2b0d92784 (diff)
downloadzsh-9530331b4f04015eb65341c97940f68774ab210b.tar.gz
zsh-9530331b4f04015eb65341c97940f68774ab210b.tar.xz
zsh-9530331b4f04015eb65341c97940f68774ab210b.zip
28268: I/O to a terminated (or never created) coprocess emits a
"no coprocess" diagnostic, instead of either nothing or "bad file number".
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 6dbd1597f..f80269846 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3720,13 +3720,21 @@ bin_print(char *name, char **args, Options ops, int func)
     if (OPT_HASARG(ops,'u') || OPT_ISSET(ops,'p')) {
 	int fd;
 
-	if (OPT_ISSET(ops, 'p'))
+	if (OPT_ISSET(ops, 'p')) {
 	    fd = coprocout;
-	else {
+	    if (fd < 0) {
+		zwarnnam(name, "-p: no coprocess");
+		return 1;
+	    }
+	} else {
 	    char *argptr = OPT_ARG(ops,'u'), *eptr;
 	    /* Handle undocumented feature that -up worked */
 	    if (!strcmp(argptr, "p")) {
 		fd = coprocout;
+		if (fd < 0) {
+		    zwarnnam(name, "-p: no coprocess");
+		    return 1;
+		}
 	    } else {
 		fd = (int)zstrtol(argptr, &eptr, 10);
 		if (*eptr) {
@@ -5091,6 +5099,10 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
 	/* The old code handled -up, but that was never documented. Still...*/
 	if (!strcmp(argptr, "p")) {
 	    readfd = coprocin;
+	    if (readfd < 0) {
+		zwarnnam(name, "-p: no coprocess");
+		return 1;
+	    }
 	} else {
 	    readfd = (int)zstrtol(argptr, &eptr, 10);
 	    if (*eptr) {
@@ -5105,6 +5117,10 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
 	izle = 0;
     } else if (OPT_ISSET(ops,'p')) {
 	readfd = coprocin;
+	if (readfd < 0) {
+	    zwarnnam(name, "-p: no coprocess");
+	    return 1;
+	}
 	izle = 0;
     } else
 	readfd = izle = 0;