From 9530331b4f04015eb65341c97940f68774ab210b Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sun, 19 Sep 2010 19:20:33 +0000 Subject: 28268: I/O to a terminated (or never created) coprocess emits a "no coprocess" diagnostic, instead of either nothing or "bad file number". --- Src/builtin.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'Src/builtin.c') 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; -- cgit v1.2.3