From 124c3594cb65748ce858dcc55eadd7c831cee041 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 13 Mar 2016 20:21:00 +0200 Subject: Initial fix for use of closed end of two-way connection. --- builtin.c | 12 ++++++++++-- io.c | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builtin.c b/builtin.c index c3a3bb22..784c8190 100644 --- a/builtin.c +++ b/builtin.c @@ -1664,8 +1664,12 @@ do_printf(int nargs, int redirtype) if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); rp = redirect(redir_exp, redirtype, & errflg); - if (rp != NULL) + if (rp != NULL) { + if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + fatal(_("printf: attempt to write to closed write end of two-way pipe")); + } fp = rp->output.fp; + } } else if (do_debug) /* only the debugger can change the default output */ fp = output_fp; else @@ -2136,8 +2140,12 @@ do_print(int nargs, int redirtype) if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); rp = redirect(redir_exp, redirtype, & errflg); - if (rp != NULL) + if (rp != NULL) { + if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + fatal(_("print: attempt to write to closed write end of two-way pipe")); + } fp = rp->output.fp; + } } else if (do_debug) /* only the debugger can change the default output */ fp = output_fp; else diff --git a/io.c b/io.c index d4435684..de753973 100644 --- a/io.c +++ b/io.c @@ -2473,6 +2473,8 @@ do_getline_redir(int into_variable, enum redirval redirtype) update_ERRNO_int(redir_error); } return make_number((AWKNUM) -1.0); + } else if ((rp->flag & RED_TWOWAY) != 0 && rp->iop == NULL) { + fatal(_("getline: attempt to read from closed read end of two-way pipe")); } iop = rp->iop; if (iop == NULL) /* end of input */ -- cgit v1.2.3 From 1662deffd0ced2464647ebff013be4d5ad398594 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Tue, 22 Mar 2016 07:53:46 +0200 Subject: Add fatal error for print if 2 way pipe write end closed. --- builtin.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin.c b/builtin.c index 784c8190..c4d3d3a1 100644 --- a/builtin.c +++ b/builtin.c @@ -2208,8 +2208,12 @@ do_print_rec(int nargs, int redirtype) if (redirtype != 0) { redir_exp = TOP(); rp = redirect(redir_exp, redirtype, & errflg); - if (rp != NULL) + if (rp != NULL) { + if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + fatal(_("print: attempt to write to closed write end of two-way pipe")); + } fp = rp->output.fp; + } DEREF(redir_exp); decr_sp(); } else -- cgit v1.2.3 From 464aa113b70b30ab9b1b00d1de5ccf4b0230b720 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 2 Apr 2016 22:45:42 +0300 Subject: ChangeLog entries for errors on partially closed two-way pipes. --- ChangeLog | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7160c86b..fe98ed8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2016-04-02 Arnold D. Robbins + + * builtin.c (do_printf): If the redirection is two way but the + fp is NULL, it means we're writing to the closed write-end of + a two-way pipe. Issue a fatal error message. + (do_print): Ditto. + (do_print_rec): Ditto. + * io.c (do_getline_redir): Same thing for reading from a closed + read end of a two-way pipe. Fatal error. + 2016-03-14 Arnold D. Robbins * io.c (socketopen): For SOCK_DGRAM, set read_len to sizeof -- cgit v1.2.3 From b332053a160357e6c30c22f9ca90af9129e4550b Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 2 Apr 2016 22:52:11 +0300 Subject: Document about using closed end of two-way pipes. --- ChangeLog | 1 + NEWS | 4 + doc/ChangeLog | 5 + doc/gawk.info | 427 ++++++++++++++++++++++++++++---------------------------- doc/gawk.texi | 5 + doc/gawktexi.in | 5 + 6 files changed, 236 insertions(+), 211 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe98ed8e..7ba50e8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ (do_print_rec): Ditto. * io.c (do_getline_redir): Same thing for reading from a closed read end of a two-way pipe. Fatal error. + * NEWS: Updated. 2016-03-14 Arnold D. Robbins diff --git a/NEWS b/NEWS index 31c8471c..472b05e3 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,10 @@ Changes from 4.1.3 to 4.1.x 8. The return value of system() has been enhanced to convey more information. See the doc. +9. Attempting to write to the "to" end of a two-way pipe that has been + closed is now a fatal error. Similarly, so is reading from the "from" + end that has been closed. + Changes from 4.1.2 to 4.1.3 --------------------------- diff --git a/doc/ChangeLog b/doc/ChangeLog index 9380d248..0da0e7c7 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -3,6 +3,11 @@ * gawktexi.in, gawkinet.texi: Enable use of braces in indexes. Requires Texinfo 6.0 or later. +2016-04-02 Arnold D. Robbins + + * gawktexi.in (Two-way I/O): Document that closing the "to" + end waits for the process to exit, so it's not such a great idea. + 2016-03-21 Arnold D. Robbins * gawkinet.texi: Update UDP client and discussion, update diff --git a/doc/gawk.info b/doc/gawk.info index c0b58599..c3cb0896 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -19668,6 +19668,11 @@ the coprocess and exits. ensures traditional Unix (ASCII) sorting from 'sort'. This is not strictly necessary here, but it's good to know how to do this. + Be careful when closing the '"from"' end of a two-way pipe; in this +case 'gawk' waits for the child process to exit, which may cause your +program to hang. (Thus, this particular feature is of much less use in +practice than being able to close the '"to"' end.) + You may also use pseudo-ttys (ptys) for two-way communication instead of pipes, if your system supports them. This is done on a per-command basis, by setting a special element in the 'PROCINFO' array (*note @@ -33170,7 +33175,7 @@ Index * gawk, predefined variables and: Built-in Variables. (line 14) * gawk, PROCINFO array in: Auto-set. (line 129) * gawk, PROCINFO array in <1>: Time Functions. (line 47) -* gawk, PROCINFO array in <2>: Two-way I/O. (line 99) +* gawk, PROCINFO array in <2>: Two-way I/O. (line 104) * gawk, regexp constants and: Using Constant Regexps. (line 28) * gawk, regular expressions, case sensitivity: Case-sensitivity. @@ -33944,7 +33949,7 @@ Index * PROCINFO array: Auto-set. (line 129) * PROCINFO array <1>: Time Functions. (line 47) * PROCINFO array <2>: Passwd Functions. (line 6) -* PROCINFO array, and communications via ptys: Two-way I/O. (line 99) +* PROCINFO array, and communications via ptys: Two-way I/O. (line 104) * PROCINFO array, and group membership: Group Functions. (line 6) * PROCINFO array, and user and group ID numbers: Id Program. (line 15) * PROCINFO array, testing the field splitting: Passwd Functions. @@ -35009,214 +35014,214 @@ Ref: Controlling Array Traversal-Footnote-1790219 Node: Array Sorting Functions790337 Ref: Array Sorting Functions-Footnote-1795428 Node: Two-way I/O795624 -Ref: Two-way I/O-Footnote-1801444 -Ref: Two-way I/O-Footnote-2801631 -Node: TCP/IP Networking801713 -Node: Profiling804831 -Node: Advanced Features Summary812370 -Node: Internationalization814306 -Node: I18N and L10N815786 -Node: Explaining gettext816473 -Ref: Explaining gettext-Footnote-1821496 -Ref: Explaining gettext-Footnote-2821681 -Node: Programmer i18n821846 -Ref: Programmer i18n-Footnote-1826701 -Node: Translator i18n826750 -Node: String Extraction827544 -Ref: String Extraction-Footnote-1828676 -Node: Printf Ordering828762 -Ref: Printf Ordering-Footnote-1831548 -Node: I18N Portability831612 -Ref: I18N Portability-Footnote-1834068 -Node: I18N Example834131 -Ref: I18N Example-Footnote-1836937 -Node: Gawk I18N837010 -Node: I18N Summary837655 -Node: Debugger838996 -Node: Debugging840018 -Node: Debugging Concepts840459 -Node: Debugging Terms842268 -Node: Awk Debugging844843 -Node: Sample Debugging Session845749 -Node: Debugger Invocation846283 -Node: Finding The Bug847669 -Node: List of Debugger Commands854147 -Node: Breakpoint Control855480 -Node: Debugger Execution Control859174 -Node: Viewing And Changing Data862536 -Node: Execution Stack865910 -Node: Debugger Info867547 -Node: Miscellaneous Debugger Commands871618 -Node: Readline Support876706 -Node: Limitations877602 -Node: Debugging Summary879711 -Node: Arbitrary Precision Arithmetic880884 -Node: Computer Arithmetic882300 -Ref: table-numeric-ranges885891 -Ref: Computer Arithmetic-Footnote-1886613 -Node: Math Definitions886670 -Ref: table-ieee-formats889984 -Ref: Math Definitions-Footnote-1890587 -Node: MPFR features890692 -Node: FP Math Caution892409 -Ref: FP Math Caution-Footnote-1893481 -Node: Inexactness of computations893850 -Node: Inexact representation894810 -Node: Comparing FP Values896170 -Node: Errors accumulate897252 -Node: Getting Accuracy898685 -Node: Try To Round901395 -Node: Setting precision902294 -Ref: table-predefined-precision-strings902991 -Node: Setting the rounding mode904821 -Ref: table-gawk-rounding-modes905195 -Ref: Setting the rounding mode-Footnote-1908603 -Node: Arbitrary Precision Integers908782 -Ref: Arbitrary Precision Integers-Footnote-1911766 -Node: POSIX Floating Point Problems911915 -Ref: POSIX Floating Point Problems-Footnote-1915797 -Node: Floating point summary915835 -Node: Dynamic Extensions918025 -Node: Extension Intro919578 -Node: Plugin License920844 -Node: Extension Mechanism Outline921641 -Ref: figure-load-extension922080 -Ref: figure-register-new-function923645 -Ref: figure-call-new-function924737 -Node: Extension API Description926799 -Node: Extension API Functions Introduction928247 -Node: General Data Types933059 -Ref: General Data Types-Footnote-1939014 -Node: Memory Allocation Functions939313 -Ref: Memory Allocation Functions-Footnote-1942158 -Node: Constructor Functions942257 -Node: Registration Functions944002 -Node: Extension Functions944687 -Node: Exit Callback Functions946986 -Node: Extension Version String948236 -Node: Input Parsers948899 -Node: Output Wrappers958784 -Node: Two-way processors963296 -Node: Printing Messages965560 -Ref: Printing Messages-Footnote-1966634 -Node: Updating ERRNO966787 -Node: Requesting Values967526 -Ref: table-value-types-returned968263 -Node: Accessing Parameters969146 -Node: Symbol Table Access970381 -Node: Symbol table by name970893 -Node: Symbol table by cookie972914 -Ref: Symbol table by cookie-Footnote-1977063 -Node: Cached values977127 -Ref: Cached values-Footnote-1980628 -Node: Array Manipulation980719 -Ref: Array Manipulation-Footnote-1981818 -Node: Array Data Types981855 -Ref: Array Data Types-Footnote-1984513 -Node: Array Functions984605 -Node: Flattening Arrays988463 -Node: Creating Arrays995371 -Node: Extension API Variables1000142 -Node: Extension Versioning1000778 -Node: Extension API Informational Variables1002669 -Node: Extension API Boilerplate1003733 -Node: Finding Extensions1007547 -Node: Extension Example1008106 -Node: Internal File Description1008904 -Node: Internal File Ops1012984 -Ref: Internal File Ops-Footnote-11024746 -Node: Using Internal File Ops1024886 -Ref: Using Internal File Ops-Footnote-11027269 -Node: Extension Samples1027543 -Node: Extension Sample File Functions1029072 -Node: Extension Sample Fnmatch1036721 -Node: Extension Sample Fork1038208 -Node: Extension Sample Inplace1039426 -Node: Extension Sample Ord1042636 -Node: Extension Sample Readdir1043472 -Ref: table-readdir-file-types1044361 -Node: Extension Sample Revout1045166 -Node: Extension Sample Rev2way1045755 -Node: Extension Sample Read write array1046495 -Node: Extension Sample Readfile1048437 -Node: Extension Sample Time1049532 -Node: Extension Sample API Tests1050880 -Node: gawkextlib1051372 -Node: Extension summary1053796 -Node: Extension Exercises1057488 -Node: Language History1058985 -Node: V7/SVR3.11060641 -Node: SVR41062793 -Node: POSIX1064227 -Node: BTL1065606 -Node: POSIX/GNU1066335 -Node: Feature History1071856 -Node: Common Extensions1085185 -Node: Ranges and Locales1086468 -Ref: Ranges and Locales-Footnote-11091084 -Ref: Ranges and Locales-Footnote-21091111 -Ref: Ranges and Locales-Footnote-31091346 -Node: Contributors1091567 -Node: History summary1097136 -Node: Installation1098516 -Node: Gawk Distribution1099460 -Node: Getting1099944 -Node: Extracting1100905 -Node: Distribution contents1102543 -Node: Unix Installation1108294 -Node: Quick Installation1108910 -Node: Additional Configuration Options1111337 -Node: Configuration Philosophy1113141 -Node: Non-Unix Installation1115510 -Node: PC Installation1115968 -Node: PC Binary Installation1117288 -Node: PC Compiling1119140 -Ref: PC Compiling-Footnote-11122164 -Node: PC Testing1122273 -Node: PC Using1123453 -Node: Cygwin1127567 -Node: MSYS1128337 -Node: VMS Installation1128838 -Node: VMS Compilation1129629 -Ref: VMS Compilation-Footnote-11130858 -Node: VMS Dynamic Extensions1130916 -Node: VMS Installation Details1132601 -Node: VMS Running1134854 -Node: VMS GNV1139133 -Node: VMS Old Gawk1139868 -Node: Bugs1140339 -Node: Other Versions1144536 -Node: Installation summary1151120 -Node: Notes1152178 -Node: Compatibility Mode1153043 -Node: Additions1153825 -Node: Accessing The Source1154750 -Node: Adding Code1156185 -Node: New Ports1162404 -Node: Derived Files1166892 -Ref: Derived Files-Footnote-11172377 -Ref: Derived Files-Footnote-21172412 -Ref: Derived Files-Footnote-31173010 -Node: Future Extensions1173124 -Node: Implementation Limitations1173782 -Node: Extension Design1174965 -Node: Old Extension Problems1176119 -Ref: Old Extension Problems-Footnote-11177637 -Node: Extension New Mechanism Goals1177694 -Ref: Extension New Mechanism Goals-Footnote-11181058 -Node: Extension Other Design Decisions1181247 -Node: Extension Future Growth1183360 -Node: Old Extension Mechanism1184196 -Node: Notes summary1185959 -Node: Basic Concepts1187141 -Node: Basic High Level1187822 -Ref: figure-general-flow1188104 -Ref: figure-process-flow1188789 -Ref: Basic High Level-Footnote-11192090 -Node: Basic Data Typing1192275 -Node: Glossary1195603 -Node: Copying1227549 -Node: GNU Free Documentation License1265088 -Node: Index1290206 +Ref: Two-way I/O-Footnote-1801709 +Ref: Two-way I/O-Footnote-2801896 +Node: TCP/IP Networking801978 +Node: Profiling805096 +Node: Advanced Features Summary812635 +Node: Internationalization814571 +Node: I18N and L10N816051 +Node: Explaining gettext816738 +Ref: Explaining gettext-Footnote-1821761 +Ref: Explaining gettext-Footnote-2821946 +Node: Programmer i18n822111 +Ref: Programmer i18n-Footnote-1826966 +Node: Translator i18n827015 +Node: String Extraction827809 +Ref: String Extraction-Footnote-1828941 +Node: Printf Ordering829027 +Ref: Printf Ordering-Footnote-1831813 +Node: I18N Portability831877 +Ref: I18N Portability-Footnote-1834333 +Node: I18N Example834396 +Ref: I18N Example-Footnote-1837202 +Node: Gawk I18N837275 +Node: I18N Summary837920 +Node: Debugger839261 +Node: Debugging840283 +Node: Debugging Concepts840724 +Node: Debugging Terms842533 +Node: Awk Debugging845108 +Node: Sample Debugging Session846014 +Node: Debugger Invocation846548 +Node: Finding The Bug847934 +Node: List of Debugger Commands854412 +Node: Breakpoint Control855745 +Node: Debugger Execution Control859439 +Node: Viewing And Changing Data862801 +Node: Execution Stack866175 +Node: Debugger Info867812 +Node: Miscellaneous Debugger Commands871883 +Node: Readline Support876971 +Node: Limitations877867 +Node: Debugging Summary879976 +Node: Arbitrary Precision Arithmetic881149 +Node: Computer Arithmetic882565 +Ref: table-numeric-ranges886156 +Ref: Computer Arithmetic-Footnote-1886878 +Node: Math Definitions886935 +Ref: table-ieee-formats890249 +Ref: Math Definitions-Footnote-1890852 +Node: MPFR features890957 +Node: FP Math Caution892674 +Ref: FP Math Caution-Footnote-1893746 +Node: Inexactness of computations894115 +Node: Inexact representation895075 +Node: Comparing FP Values896435 +Node: Errors accumulate897517 +Node: Getting Accuracy898950 +Node: Try To Round901660 +Node: Setting precision902559 +Ref: table-predefined-precision-strings903256 +Node: Setting the rounding mode905086 +Ref: table-gawk-rounding-modes905460 +Ref: Setting the rounding mode-Footnote-1908868 +Node: Arbitrary Precision Integers909047 +Ref: Arbitrary Precision Integers-Footnote-1912031 +Node: POSIX Floating Point Problems912180 +Ref: POSIX Floating Point Problems-Footnote-1916062 +Node: Floating point summary916100 +Node: Dynamic Extensions918290 +Node: Extension Intro919843 +Node: Plugin License921109 +Node: Extension Mechanism Outline921906 +Ref: figure-load-extension922345 +Ref: figure-register-new-function923910 +Ref: figure-call-new-function925002 +Node: Extension API Description927064 +Node: Extension API Functions Introduction928512 +Node: General Data Types933324 +Ref: General Data Types-Footnote-1939279 +Node: Memory Allocation Functions939578 +Ref: Memory Allocation Functions-Footnote-1942423 +Node: Constructor Functions942522 +Node: Registration Functions944267 +Node: Extension Functions944952 +Node: Exit Callback Functions947251 +Node: Extension Version String948501 +Node: Input Parsers949164 +Node: Output Wrappers959049 +Node: Two-way processors963561 +Node: Printing Messages965825 +Ref: Printing Messages-Footnote-1966899 +Node: Updating ERRNO967052 +Node: Requesting Values967791 +Ref: table-value-types-returned968528 +Node: Accessing Parameters969411 +Node: Symbol Table Access970646 +Node: Symbol table by name971158 +Node: Symbol table by cookie973179 +Ref: Symbol table by cookie-Footnote-1977328 +Node: Cached values977392 +Ref: Cached values-Footnote-1980893 +Node: Array Manipulation980984 +Ref: Array Manipulation-Footnote-1982083 +Node: Array Data Types982120 +Ref: Array Data Types-Footnote-1984778 +Node: Array Functions984870 +Node: Flattening Arrays988728 +Node: Creating Arrays995636 +Node: Extension API Variables1000407 +Node: Extension Versioning1001043 +Node: Extension API Informational Variables1002934 +Node: Extension API Boilerplate1003998 +Node: Finding Extensions1007812 +Node: Extension Example1008371 +Node: Internal File Description1009169 +Node: Internal File Ops1013249 +Ref: Internal File Ops-Footnote-11025011 +Node: Using Internal File Ops1025151 +Ref: Using Internal File Ops-Footnote-11027534 +Node: Extension Samples1027808 +Node: Extension Sample File Functions1029337 +Node: Extension Sample Fnmatch1036986 +Node: Extension Sample Fork1038473 +Node: Extension Sample Inplace1039691 +Node: Extension Sample Ord1042901 +Node: Extension Sample Readdir1043737 +Ref: table-readdir-file-types1044626 +Node: Extension Sample Revout1045431 +Node: Extension Sample Rev2way1046020 +Node: Extension Sample Read write array1046760 +Node: Extension Sample Readfile1048702 +Node: Extension Sample Time1049797 +Node: Extension Sample API Tests1051145 +Node: gawkextlib1051637 +Node: Extension summary1054061 +Node: Extension Exercises1057753 +Node: Language History1059250 +Node: V7/SVR3.11060906 +Node: SVR41063058 +Node: POSIX1064492 +Node: BTL1065871 +Node: POSIX/GNU1066600 +Node: Feature History1072121 +Node: Common Extensions1085450 +Node: Ranges and Locales1086733 +Ref: Ranges and Locales-Footnote-11091349 +Ref: Ranges and Locales-Footnote-21091376 +Ref: Ranges and Locales-Footnote-31091611 +Node: Contributors1091832 +Node: History summary1097401 +Node: Installation1098781 +Node: Gawk Distribution1099725 +Node: Getting1100209 +Node: Extracting1101170 +Node: Distribution contents1102808 +Node: Unix Installation1108559 +Node: Quick Installation1109175 +Node: Additional Configuration Options1111602 +Node: Configuration Philosophy1113406 +Node: Non-Unix Installation1115775 +Node: PC Installation1116233 +Node: PC Binary Installation1117553 +Node: PC Compiling1119405 +Ref: PC Compiling-Footnote-11122429 +Node: PC Testing1122538 +Node: PC Using1123718 +Node: Cygwin1127832 +Node: MSYS1128602 +Node: VMS Installation1129103 +Node: VMS Compilation1129894 +Ref: VMS Compilation-Footnote-11131123 +Node: VMS Dynamic Extensions1131181 +Node: VMS Installation Details1132866 +Node: VMS Running1135119 +Node: VMS GNV1139398 +Node: VMS Old Gawk1140133 +Node: Bugs1140604 +Node: Other Versions1144801 +Node: Installation summary1151385 +Node: Notes1152443 +Node: Compatibility Mode1153308 +Node: Additions1154090 +Node: Accessing The Source1155015 +Node: Adding Code1156450 +Node: New Ports1162669 +Node: Derived Files1167157 +Ref: Derived Files-Footnote-11172642 +Ref: Derived Files-Footnote-21172677 +Ref: Derived Files-Footnote-31173275 +Node: Future Extensions1173389 +Node: Implementation Limitations1174047 +Node: Extension Design1175230 +Node: Old Extension Problems1176384 +Ref: Old Extension Problems-Footnote-11177902 +Node: Extension New Mechanism Goals1177959 +Ref: Extension New Mechanism Goals-Footnote-11181323 +Node: Extension Other Design Decisions1181512 +Node: Extension Future Growth1183625 +Node: Old Extension Mechanism1184461 +Node: Notes summary1186224 +Node: Basic Concepts1187406 +Node: Basic High Level1188087 +Ref: figure-general-flow1188369 +Ref: figure-process-flow1189054 +Ref: Basic High Level-Footnote-11192355 +Node: Basic Data Typing1192540 +Node: Glossary1195868 +Node: Copying1227814 +Node: GNU Free Documentation License1265353 +Node: Index1290471  End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 59e06a08..4b0ea40c 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -27507,6 +27507,11 @@ As a side note, the assignment @samp{LC_ALL=C} in the @command{sort} command ensures traditional Unix (ASCII) sorting from @command{sort}. This is not strictly necessary here, but it's good to know how to do this. +Be careful when closing the @code{"from"} end of a two-way pipe; in this +case @command{gawk} waits for the child process to exit, which may cause +your program to hang. (Thus, this particular feature is of much less +use in practice than being able to close the @code{"to"} end.) + @cindex @command{gawk}, @code{PROCINFO} array in @cindex @code{PROCINFO} array, and communications via ptys You may also use pseudo-ttys (ptys) for diff --git a/doc/gawktexi.in b/doc/gawktexi.in index cd240a43..4d2a76f3 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -26598,6 +26598,11 @@ As a side note, the assignment @samp{LC_ALL=C} in the @command{sort} command ensures traditional Unix (ASCII) sorting from @command{sort}. This is not strictly necessary here, but it's good to know how to do this. +Be careful when closing the @code{"from"} end of a two-way pipe; in this +case @command{gawk} waits for the child process to exit, which may cause +your program to hang. (Thus, this particular feature is of much less +use in practice than being able to close the @code{"to"} end.) + @cindex @command{gawk}, @code{PROCINFO} array in @cindex @code{PROCINFO} array, and communications via ptys You may also use pseudo-ttys (ptys) for -- cgit v1.2.3 From 6d22cdfde8a2136080efba406d980ecac537b07d Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 2 Apr 2016 22:56:52 +0300 Subject: Further doc on closing one end of a two-way pipe. --- doc/gawk.info | 426 ++++++++++++++++++++++++++++---------------------------- doc/gawk.texi | 6 + doc/gawktexi.in | 6 + 3 files changed, 227 insertions(+), 211 deletions(-) diff --git a/doc/gawk.info b/doc/gawk.info index c3cb0896..c773fb9e 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -19673,6 +19673,10 @@ case 'gawk' waits for the child process to exit, which may cause your program to hang. (Thus, this particular feature is of much less use in practice than being able to close the '"to"' end.) + CAUTION: It is a fatal error to write to the '"to"' end of a + two-way pipe which has been closed. It is also a fatal error to + read from the '"from"' end of a two-way pipe that has been closed. + You may also use pseudo-ttys (ptys) for two-way communication instead of pipes, if your system supports them. This is done on a per-command basis, by setting a special element in the 'PROCINFO' array (*note @@ -33175,7 +33179,7 @@ Index * gawk, predefined variables and: Built-in Variables. (line 14) * gawk, PROCINFO array in: Auto-set. (line 129) * gawk, PROCINFO array in <1>: Time Functions. (line 47) -* gawk, PROCINFO array in <2>: Two-way I/O. (line 104) +* gawk, PROCINFO array in <2>: Two-way I/O. (line 108) * gawk, regexp constants and: Using Constant Regexps. (line 28) * gawk, regular expressions, case sensitivity: Case-sensitivity. @@ -33949,7 +33953,7 @@ Index * PROCINFO array: Auto-set. (line 129) * PROCINFO array <1>: Time Functions. (line 47) * PROCINFO array <2>: Passwd Functions. (line 6) -* PROCINFO array, and communications via ptys: Two-way I/O. (line 104) +* PROCINFO array, and communications via ptys: Two-way I/O. (line 108) * PROCINFO array, and group membership: Group Functions. (line 6) * PROCINFO array, and user and group ID numbers: Id Program. (line 15) * PROCINFO array, testing the field splitting: Passwd Functions. @@ -35014,214 +35018,214 @@ Ref: Controlling Array Traversal-Footnote-1790219 Node: Array Sorting Functions790337 Ref: Array Sorting Functions-Footnote-1795428 Node: Two-way I/O795624 -Ref: Two-way I/O-Footnote-1801709 -Ref: Two-way I/O-Footnote-2801896 -Node: TCP/IP Networking801978 -Node: Profiling805096 -Node: Advanced Features Summary812635 -Node: Internationalization814571 -Node: I18N and L10N816051 -Node: Explaining gettext816738 -Ref: Explaining gettext-Footnote-1821761 -Ref: Explaining gettext-Footnote-2821946 -Node: Programmer i18n822111 -Ref: Programmer i18n-Footnote-1826966 -Node: Translator i18n827015 -Node: String Extraction827809 -Ref: String Extraction-Footnote-1828941 -Node: Printf Ordering829027 -Ref: Printf Ordering-Footnote-1831813 -Node: I18N Portability831877 -Ref: I18N Portability-Footnote-1834333 -Node: I18N Example834396 -Ref: I18N Example-Footnote-1837202 -Node: Gawk I18N837275 -Node: I18N Summary837920 -Node: Debugger839261 -Node: Debugging840283 -Node: Debugging Concepts840724 -Node: Debugging Terms842533 -Node: Awk Debugging845108 -Node: Sample Debugging Session846014 -Node: Debugger Invocation846548 -Node: Finding The Bug847934 -Node: List of Debugger Commands854412 -Node: Breakpoint Control855745 -Node: Debugger Execution Control859439 -Node: Viewing And Changing Data862801 -Node: Execution Stack866175 -Node: Debugger Info867812 -Node: Miscellaneous Debugger Commands871883 -Node: Readline Support876971 -Node: Limitations877867 -Node: Debugging Summary879976 -Node: Arbitrary Precision Arithmetic881149 -Node: Computer Arithmetic882565 -Ref: table-numeric-ranges886156 -Ref: Computer Arithmetic-Footnote-1886878 -Node: Math Definitions886935 -Ref: table-ieee-formats890249 -Ref: Math Definitions-Footnote-1890852 -Node: MPFR features890957 -Node: FP Math Caution892674 -Ref: FP Math Caution-Footnote-1893746 -Node: Inexactness of computations894115 -Node: Inexact representation895075 -Node: Comparing FP Values896435 -Node: Errors accumulate897517 -Node: Getting Accuracy898950 -Node: Try To Round901660 -Node: Setting precision902559 -Ref: table-predefined-precision-strings903256 -Node: Setting the rounding mode905086 -Ref: table-gawk-rounding-modes905460 -Ref: Setting the rounding mode-Footnote-1908868 -Node: Arbitrary Precision Integers909047 -Ref: Arbitrary Precision Integers-Footnote-1912031 -Node: POSIX Floating Point Problems912180 -Ref: POSIX Floating Point Problems-Footnote-1916062 -Node: Floating point summary916100 -Node: Dynamic Extensions918290 -Node: Extension Intro919843 -Node: Plugin License921109 -Node: Extension Mechanism Outline921906 -Ref: figure-load-extension922345 -Ref: figure-register-new-function923910 -Ref: figure-call-new-function925002 -Node: Extension API Description927064 -Node: Extension API Functions Introduction928512 -Node: General Data Types933324 -Ref: General Data Types-Footnote-1939279 -Node: Memory Allocation Functions939578 -Ref: Memory Allocation Functions-Footnote-1942423 -Node: Constructor Functions942522 -Node: Registration Functions944267 -Node: Extension Functions944952 -Node: Exit Callback Functions947251 -Node: Extension Version String948501 -Node: Input Parsers949164 -Node: Output Wrappers959049 -Node: Two-way processors963561 -Node: Printing Messages965825 -Ref: Printing Messages-Footnote-1966899 -Node: Updating ERRNO967052 -Node: Requesting Values967791 -Ref: table-value-types-returned968528 -Node: Accessing Parameters969411 -Node: Symbol Table Access970646 -Node: Symbol table by name971158 -Node: Symbol table by cookie973179 -Ref: Symbol table by cookie-Footnote-1977328 -Node: Cached values977392 -Ref: Cached values-Footnote-1980893 -Node: Array Manipulation980984 -Ref: Array Manipulation-Footnote-1982083 -Node: Array Data Types982120 -Ref: Array Data Types-Footnote-1984778 -Node: Array Functions984870 -Node: Flattening Arrays988728 -Node: Creating Arrays995636 -Node: Extension API Variables1000407 -Node: Extension Versioning1001043 -Node: Extension API Informational Variables1002934 -Node: Extension API Boilerplate1003998 -Node: Finding Extensions1007812 -Node: Extension Example1008371 -Node: Internal File Description1009169 -Node: Internal File Ops1013249 -Ref: Internal File Ops-Footnote-11025011 -Node: Using Internal File Ops1025151 -Ref: Using Internal File Ops-Footnote-11027534 -Node: Extension Samples1027808 -Node: Extension Sample File Functions1029337 -Node: Extension Sample Fnmatch1036986 -Node: Extension Sample Fork1038473 -Node: Extension Sample Inplace1039691 -Node: Extension Sample Ord1042901 -Node: Extension Sample Readdir1043737 -Ref: table-readdir-file-types1044626 -Node: Extension Sample Revout1045431 -Node: Extension Sample Rev2way1046020 -Node: Extension Sample Read write array1046760 -Node: Extension Sample Readfile1048702 -Node: Extension Sample Time1049797 -Node: Extension Sample API Tests1051145 -Node: gawkextlib1051637 -Node: Extension summary1054061 -Node: Extension Exercises1057753 -Node: Language History1059250 -Node: V7/SVR3.11060906 -Node: SVR41063058 -Node: POSIX1064492 -Node: BTL1065871 -Node: POSIX/GNU1066600 -Node: Feature History1072121 -Node: Common Extensions1085450 -Node: Ranges and Locales1086733 -Ref: Ranges and Locales-Footnote-11091349 -Ref: Ranges and Locales-Footnote-21091376 -Ref: Ranges and Locales-Footnote-31091611 -Node: Contributors1091832 -Node: History summary1097401 -Node: Installation1098781 -Node: Gawk Distribution1099725 -Node: Getting1100209 -Node: Extracting1101170 -Node: Distribution contents1102808 -Node: Unix Installation1108559 -Node: Quick Installation1109175 -Node: Additional Configuration Options1111602 -Node: Configuration Philosophy1113406 -Node: Non-Unix Installation1115775 -Node: PC Installation1116233 -Node: PC Binary Installation1117553 -Node: PC Compiling1119405 -Ref: PC Compiling-Footnote-11122429 -Node: PC Testing1122538 -Node: PC Using1123718 -Node: Cygwin1127832 -Node: MSYS1128602 -Node: VMS Installation1129103 -Node: VMS Compilation1129894 -Ref: VMS Compilation-Footnote-11131123 -Node: VMS Dynamic Extensions1131181 -Node: VMS Installation Details1132866 -Node: VMS Running1135119 -Node: VMS GNV1139398 -Node: VMS Old Gawk1140133 -Node: Bugs1140604 -Node: Other Versions1144801 -Node: Installation summary1151385 -Node: Notes1152443 -Node: Compatibility Mode1153308 -Node: Additions1154090 -Node: Accessing The Source1155015 -Node: Adding Code1156450 -Node: New Ports1162669 -Node: Derived Files1167157 -Ref: Derived Files-Footnote-11172642 -Ref: Derived Files-Footnote-21172677 -Ref: Derived Files-Footnote-31173275 -Node: Future Extensions1173389 -Node: Implementation Limitations1174047 -Node: Extension Design1175230 -Node: Old Extension Problems1176384 -Ref: Old Extension Problems-Footnote-11177902 -Node: Extension New Mechanism Goals1177959 -Ref: Extension New Mechanism Goals-Footnote-11181323 -Node: Extension Other Design Decisions1181512 -Node: Extension Future Growth1183625 -Node: Old Extension Mechanism1184461 -Node: Notes summary1186224 -Node: Basic Concepts1187406 -Node: Basic High Level1188087 -Ref: figure-general-flow1188369 -Ref: figure-process-flow1189054 -Ref: Basic High Level-Footnote-11192355 -Node: Basic Data Typing1192540 -Node: Glossary1195868 -Node: Copying1227814 -Node: GNU Free Documentation License1265353 -Node: Index1290471 +Ref: Two-way I/O-Footnote-1801918 +Ref: Two-way I/O-Footnote-2802105 +Node: TCP/IP Networking802187 +Node: Profiling805305 +Node: Advanced Features Summary812844 +Node: Internationalization814780 +Node: I18N and L10N816260 +Node: Explaining gettext816947 +Ref: Explaining gettext-Footnote-1821970 +Ref: Explaining gettext-Footnote-2822155 +Node: Programmer i18n822320 +Ref: Programmer i18n-Footnote-1827175 +Node: Translator i18n827224 +Node: String Extraction828018 +Ref: String Extraction-Footnote-1829150 +Node: Printf Ordering829236 +Ref: Printf Ordering-Footnote-1832022 +Node: I18N Portability832086 +Ref: I18N Portability-Footnote-1834542 +Node: I18N Example834605 +Ref: I18N Example-Footnote-1837411 +Node: Gawk I18N837484 +Node: I18N Summary838129 +Node: Debugger839470 +Node: Debugging840492 +Node: Debugging Concepts840933 +Node: Debugging Terms842742 +Node: Awk Debugging845317 +Node: Sample Debugging Session846223 +Node: Debugger Invocation846757 +Node: Finding The Bug848143 +Node: List of Debugger Commands854621 +Node: Breakpoint Control855954 +Node: Debugger Execution Control859648 +Node: Viewing And Changing Data863010 +Node: Execution Stack866384 +Node: Debugger Info868021 +Node: Miscellaneous Debugger Commands872092 +Node: Readline Support877180 +Node: Limitations878076 +Node: Debugging Summary880185 +Node: Arbitrary Precision Arithmetic881358 +Node: Computer Arithmetic882774 +Ref: table-numeric-ranges886365 +Ref: Computer Arithmetic-Footnote-1887087 +Node: Math Definitions887144 +Ref: table-ieee-formats890458 +Ref: Math Definitions-Footnote-1891061 +Node: MPFR features891166 +Node: FP Math Caution892883 +Ref: FP Math Caution-Footnote-1893955 +Node: Inexactness of computations894324 +Node: Inexact representation895284 +Node: Comparing FP Values896644 +Node: Errors accumulate897726 +Node: Getting Accuracy899159 +Node: Try To Round901869 +Node: Setting precision902768 +Ref: table-predefined-precision-strings903465 +Node: Setting the rounding mode905295 +Ref: table-gawk-rounding-modes905669 +Ref: Setting the rounding mode-Footnote-1909077 +Node: Arbitrary Precision Integers909256 +Ref: Arbitrary Precision Integers-Footnote-1912240 +Node: POSIX Floating Point Problems912389 +Ref: POSIX Floating Point Problems-Footnote-1916271 +Node: Floating point summary916309 +Node: Dynamic Extensions918499 +Node: Extension Intro920052 +Node: Plugin License921318 +Node: Extension Mechanism Outline922115 +Ref: figure-load-extension922554 +Ref: figure-register-new-function924119 +Ref: figure-call-new-function925211 +Node: Extension API Description927273 +Node: Extension API Functions Introduction928721 +Node: General Data Types933533 +Ref: General Data Types-Footnote-1939488 +Node: Memory Allocation Functions939787 +Ref: Memory Allocation Functions-Footnote-1942632 +Node: Constructor Functions942731 +Node: Registration Functions944476 +Node: Extension Functions945161 +Node: Exit Callback Functions947460 +Node: Extension Version String948710 +Node: Input Parsers949373 +Node: Output Wrappers959258 +Node: Two-way processors963770 +Node: Printing Messages966034 +Ref: Printing Messages-Footnote-1967108 +Node: Updating ERRNO967261 +Node: Requesting Values968000 +Ref: table-value-types-returned968737 +Node: Accessing Parameters969620 +Node: Symbol Table Access970855 +Node: Symbol table by name971367 +Node: Symbol table by cookie973388 +Ref: Symbol table by cookie-Footnote-1977537 +Node: Cached values977601 +Ref: Cached values-Footnote-1981102 +Node: Array Manipulation981193 +Ref: Array Manipulation-Footnote-1982292 +Node: Array Data Types982329 +Ref: Array Data Types-Footnote-1984987 +Node: Array Functions985079 +Node: Flattening Arrays988937 +Node: Creating Arrays995845 +Node: Extension API Variables1000616 +Node: Extension Versioning1001252 +Node: Extension API Informational Variables1003143 +Node: Extension API Boilerplate1004207 +Node: Finding Extensions1008021 +Node: Extension Example1008580 +Node: Internal File Description1009378 +Node: Internal File Ops1013458 +Ref: Internal File Ops-Footnote-11025220 +Node: Using Internal File Ops1025360 +Ref: Using Internal File Ops-Footnote-11027743 +Node: Extension Samples1028017 +Node: Extension Sample File Functions1029546 +Node: Extension Sample Fnmatch1037195 +Node: Extension Sample Fork1038682 +Node: Extension Sample Inplace1039900 +Node: Extension Sample Ord1043110 +Node: Extension Sample Readdir1043946 +Ref: table-readdir-file-types1044835 +Node: Extension Sample Revout1045640 +Node: Extension Sample Rev2way1046229 +Node: Extension Sample Read write array1046969 +Node: Extension Sample Readfile1048911 +Node: Extension Sample Time1050006 +Node: Extension Sample API Tests1051354 +Node: gawkextlib1051846 +Node: Extension summary1054270 +Node: Extension Exercises1057962 +Node: Language History1059459 +Node: V7/SVR3.11061115 +Node: SVR41063267 +Node: POSIX1064701 +Node: BTL1066080 +Node: POSIX/GNU1066809 +Node: Feature History1072330 +Node: Common Extensions1085659 +Node: Ranges and Locales1086942 +Ref: Ranges and Locales-Footnote-11091558 +Ref: Ranges and Locales-Footnote-21091585 +Ref: Ranges and Locales-Footnote-31091820 +Node: Contributors1092041 +Node: History summary1097610 +Node: Installation1098990 +Node: Gawk Distribution1099934 +Node: Getting1100418 +Node: Extracting1101379 +Node: Distribution contents1103017 +Node: Unix Installation1108768 +Node: Quick Installation1109384 +Node: Additional Configuration Options1111811 +Node: Configuration Philosophy1113615 +Node: Non-Unix Installation1115984 +Node: PC Installation1116442 +Node: PC Binary Installation1117762 +Node: PC Compiling1119614 +Ref: PC Compiling-Footnote-11122638 +Node: PC Testing1122747 +Node: PC Using1123927 +Node: Cygwin1128041 +Node: MSYS1128811 +Node: VMS Installation1129312 +Node: VMS Compilation1130103 +Ref: VMS Compilation-Footnote-11131332 +Node: VMS Dynamic Extensions1131390 +Node: VMS Installation Details1133075 +Node: VMS Running1135328 +Node: VMS GNV1139607 +Node: VMS Old Gawk1140342 +Node: Bugs1140813 +Node: Other Versions1145010 +Node: Installation summary1151594 +Node: Notes1152652 +Node: Compatibility Mode1153517 +Node: Additions1154299 +Node: Accessing The Source1155224 +Node: Adding Code1156659 +Node: New Ports1162878 +Node: Derived Files1167366 +Ref: Derived Files-Footnote-11172851 +Ref: Derived Files-Footnote-21172886 +Ref: Derived Files-Footnote-31173484 +Node: Future Extensions1173598 +Node: Implementation Limitations1174256 +Node: Extension Design1175439 +Node: Old Extension Problems1176593 +Ref: Old Extension Problems-Footnote-11178111 +Node: Extension New Mechanism Goals1178168 +Ref: Extension New Mechanism Goals-Footnote-11181532 +Node: Extension Other Design Decisions1181721 +Node: Extension Future Growth1183834 +Node: Old Extension Mechanism1184670 +Node: Notes summary1186433 +Node: Basic Concepts1187615 +Node: Basic High Level1188296 +Ref: figure-general-flow1188578 +Ref: figure-process-flow1189263 +Ref: Basic High Level-Footnote-11192564 +Node: Basic Data Typing1192749 +Node: Glossary1196077 +Node: Copying1228023 +Node: GNU Free Documentation License1265562 +Node: Index1290680  End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 4b0ea40c..d1b085f0 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -27512,6 +27512,12 @@ case @command{gawk} waits for the child process to exit, which may cause your program to hang. (Thus, this particular feature is of much less use in practice than being able to close the @code{"to"} end.) +@quotation CAUTION +It is a fatal error to write to the @code{"to"} end of a two-way +pipe which has been closed. It is also a fatal error to read +from the @code{"from"} end of a two-way pipe that has been closed. +@end quotation + @cindex @command{gawk}, @code{PROCINFO} array in @cindex @code{PROCINFO} array, and communications via ptys You may also use pseudo-ttys (ptys) for diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 4d2a76f3..e233a383 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -26603,6 +26603,12 @@ case @command{gawk} waits for the child process to exit, which may cause your program to hang. (Thus, this particular feature is of much less use in practice than being able to close the @code{"to"} end.) +@quotation CAUTION +It is a fatal error to write to the @code{"to"} end of a two-way +pipe which has been closed. It is also a fatal error to read +from the @code{"from"} end of a two-way pipe that has been closed. +@end quotation + @cindex @command{gawk}, @code{PROCINFO} array in @cindex @code{PROCINFO} array, and communications via ptys You may also use pseudo-ttys (ptys) for -- cgit v1.2.3 From 02e319635b2323361a5898e868e91058768bd39c Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 4 Apr 2016 06:49:59 +0300 Subject: Add new tests for read/write closed end of 2 way pipe. --- test/ChangeLog | 8 ++++++++ test/Makefile.am | 12 +++++++++++- test/Makefile.in | 32 +++++++++++++++++++++++++++++++- test/Maketests | 20 ++++++++++++++++++++ test/clos1way2.awk | 5 +++++ test/clos1way2.in | 1 + test/clos1way2.ok | 3 +++ test/clos1way3.awk | 7 +++++++ test/clos1way3.ok | 3 +++ test/clos1way4.awk | 7 +++++++ test/clos1way4.ok | 3 +++ test/clos1way5.awk | 9 +++++++++ test/clos1way5.ok | 3 +++ 13 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 test/clos1way2.awk create mode 100644 test/clos1way2.in create mode 100644 test/clos1way2.ok create mode 100644 test/clos1way3.awk create mode 100644 test/clos1way3.ok create mode 100644 test/clos1way4.awk create mode 100644 test/clos1way4.ok create mode 100644 test/clos1way5.awk create mode 100644 test/clos1way5.ok diff --git a/test/ChangeLog b/test/ChangeLog index 05f8e937..80b2c233 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,11 @@ +2016-04-04 Arnold D. Robbins + + * Makefile.am (clos1way2, clos1way3, clos1way4, clos1way5): + New tests. + * clos1way2.awk, clos1way2.in, clos1way2.ok, clos1way3.awk, + clos1way3.ok, clos1way4.awk, clos1way4.ok, clos1way5.awk, + clos1way5.ok: New files. + 2016-02-18 Arnold D. Robbins * profile2.ok, profile5.ok: Adjust after code changes. diff --git a/test/Makefile.am b/test/Makefile.am index 540e8d99..7be8d971 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -147,6 +147,15 @@ EXTRA_DIST = \ clobber.ok \ clos1way.awk \ clos1way.ok \ + clos1way2.awk \ + clos1way2.in \ + clos1way2.ok \ + clos1way3.awk \ + clos1way3.ok \ + clos1way4.awk \ + clos1way4.ok \ + clos1way5.awk \ + clos1way5.ok \ closebad.awk \ closebad.ok \ clsflnam.awk \ @@ -1075,7 +1084,8 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 binmode1 charasbytes \ - colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars exit \ + colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 \ + crlf dbugeval delsub devfd devfd1 devfd2 dumpvars exit \ fieldwdth fpat1 fpat2 fpat3 fpat4 fpat5 fpatnull fsfwfs funlen \ functab1 functab2 functab3 fwtest fwtest2 fwtest3 \ genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops \ diff --git a/test/Makefile.in b/test/Makefile.in index 723c39e1..b9b97de5 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -404,6 +404,15 @@ EXTRA_DIST = \ clobber.ok \ clos1way.awk \ clos1way.ok \ + clos1way2.awk \ + clos1way2.in \ + clos1way2.ok \ + clos1way3.awk \ + clos1way3.ok \ + clos1way4.awk \ + clos1way4.ok \ + clos1way5.awk \ + clos1way5.ok \ closebad.awk \ closebad.ok \ clsflnam.awk \ @@ -1331,7 +1340,8 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 binmode1 charasbytes \ - colonwarn clos1way crlf dbugeval delsub devfd devfd1 devfd2 dumpvars exit \ + colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 \ + crlf dbugeval delsub devfd devfd1 devfd2 dumpvars exit \ fieldwdth fpat1 fpat2 fpat3 fpat4 fpat5 fpatnull fsfwfs funlen \ functab1 functab2 functab3 fwtest fwtest2 fwtest3 \ genpot gensub gensub2 getlndir gnuops2 gnuops3 gnureops \ @@ -3559,6 +3569,26 @@ backw: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +clos1way2: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +clos1way3: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +clos1way4: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +clos1way5: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + crlf: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 214f5ddb..08d05952 100644 --- a/test/Maketests +++ b/test/Maketests @@ -997,6 +997,26 @@ backw: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +clos1way2: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +clos1way3: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +clos1way4: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + +clos1way5: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + crlf: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/clos1way2.awk b/test/clos1way2.awk new file mode 100644 index 00000000..7dab6a67 --- /dev/null +++ b/test/clos1way2.awk @@ -0,0 +1,5 @@ +{ + cmd = "cat - 1>&2; sleep 2" + print |& cmd; close(cmd, "to") + print |& cmd; print ERRNO +} diff --git a/test/clos1way2.in b/test/clos1way2.in new file mode 100644 index 00000000..9daeafb9 --- /dev/null +++ b/test/clos1way2.in @@ -0,0 +1 @@ +test diff --git a/test/clos1way2.ok b/test/clos1way2.ok new file mode 100644 index 00000000..22bd3e17 --- /dev/null +++ b/test/clos1way2.ok @@ -0,0 +1,3 @@ +gawk: clos1way2.awk:4: (FILENAME=- FNR=1) fatal: print: attempt to write to closed write end of two-way pipe +test +CODE: 2 diff --git a/test/clos1way3.awk b/test/clos1way3.awk new file mode 100644 index 00000000..f69f6675 --- /dev/null +++ b/test/clos1way3.awk @@ -0,0 +1,7 @@ +BEGIN { + cmd = "cat - 1>&2; sleep 2" + print "test1" |& cmd + close(cmd, "to") + print "test2" |& cmd + print ERRNO +} diff --git a/test/clos1way3.ok b/test/clos1way3.ok new file mode 100644 index 00000000..74f67738 --- /dev/null +++ b/test/clos1way3.ok @@ -0,0 +1,3 @@ +gawk: clos1way3.awk:5: fatal: print: attempt to write to closed write end of two-way pipe +test1 +ODE: 2 diff --git a/test/clos1way4.awk b/test/clos1way4.awk new file mode 100644 index 00000000..6c68c5c8 --- /dev/null +++ b/test/clos1way4.awk @@ -0,0 +1,7 @@ +BEGIN { + cmd = "cat - 1>&2; sleep 2" + printf "%s\n", "test1" |& cmd + close(cmd, "to") + printf "%s\n", "test2" |& cmd + print ERRNO +} diff --git a/test/clos1way4.ok b/test/clos1way4.ok new file mode 100644 index 00000000..707f9813 --- /dev/null +++ b/test/clos1way4.ok @@ -0,0 +1,3 @@ +gawk: clos1way4.awk:5: fatal: printf: attempt to write to closed write end of two-way pipe +test1 +ODE: 2 diff --git a/test/clos1way5.awk b/test/clos1way5.awk new file mode 100644 index 00000000..ca1bd94c --- /dev/null +++ b/test/clos1way5.awk @@ -0,0 +1,9 @@ +BEGIN { + cmd = "echo test1; echo test2; sleep 2" + cmd |& getline x + print x + close(cmd, "from") + cmd |& getline x + print x + print ERRNO +} diff --git a/test/clos1way5.ok b/test/clos1way5.ok new file mode 100644 index 00000000..1ff15402 --- /dev/null +++ b/test/clos1way5.ok @@ -0,0 +1,3 @@ +test1 +gawk: clos1way5.awk:6: fatal: getline: attempt to read from closed read end of two-way pipe +EXIT CODE: 2 -- cgit v1.2.3 From fae30f292fc0e2e67de188f8129d043f9909bd0b Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 4 Apr 2016 22:59:36 +0300 Subject: Braino fix in doc/ChangeLog. --- doc/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 0da0e7c7..d21d9af5 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -5,7 +5,7 @@ 2016-04-02 Arnold D. Robbins - * gawktexi.in (Two-way I/O): Document that closing the "to" + * gawktexi.in (Two-way I/O): Document that closing the "from" end waits for the process to exit, so it's not such a great idea. 2016-03-21 Arnold D. Robbins -- cgit v1.2.3 From 1b5d1b8870cb0ac1c4b99f6cf67e3277427df864 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 4 Apr 2016 23:11:19 +0300 Subject: Add warning for fflush of closed write end on 2-way pipe. --- ChangeLog | 6 ++++++ builtin.c | 3 +++ io.c | 3 ++- test/ChangeLog | 2 ++ test/clos1way2.awk | 1 + test/clos1way2.ok | 3 ++- 6 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ba50e8c..d34c136e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-04-04 Arnold D. Robbins + + * builtin.c (do_fflush): Add warning for flush to two-way + pipe where write end was closed. + * io.c (flush_io): Add some braces for the for loop. + 2016-04-02 Arnold D. Robbins * builtin.c (do_printf): If the redirection is two way but the diff --git a/builtin.c b/builtin.c index c4d3d3a1..a1c09d5a 100644 --- a/builtin.c +++ b/builtin.c @@ -237,6 +237,9 @@ do_fflush(int nargs) fp = rp->output.fp; if (fp != NULL) status = rp->output.gawk_fflush(fp, rp->output.opaque); + else if ((rp->flag & RED_TWOWAY) != 0) + warning(_("fflush: cannot flush: two-way pipe `%s' has closed write end"), + file); } else if ((fp = stdfile(tmp->stptr, tmp->stlen)) != NULL) { status = fflush(fp); } else { diff --git a/io.c b/io.c index de753973..fe1261aa 100644 --- a/io.c +++ b/io.c @@ -1328,7 +1328,7 @@ flush_io() warning(_("error writing standard error (%s)"), strerror(errno)); status++; } - for (rp = red_head; rp != NULL; rp = rp->next) + for (rp = red_head; rp != NULL; rp = rp->next) { /* flush both files and pipes, what the heck */ if ((rp->flag & RED_WRITE) != 0 && rp->output.fp != NULL) { if (rp->output.gawk_fflush(rp->output.fp, rp->output.opaque)) { @@ -1344,6 +1344,7 @@ flush_io() status++; } } + } if (status != 0) status = -1; /* canonicalize it */ return status; diff --git a/test/ChangeLog b/test/ChangeLog index 80b2c233..2867f6cb 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -5,6 +5,8 @@ * clos1way2.awk, clos1way2.in, clos1way2.ok, clos1way3.awk, clos1way3.ok, clos1way4.awk, clos1way4.ok, clos1way5.awk, clos1way5.ok: New files. + * clos1way2.awk: Add call to fflush() to test it too. + * clos1way2.ok: Updated after code change. 2016-02-18 Arnold D. Robbins diff --git a/test/clos1way2.awk b/test/clos1way2.awk index 7dab6a67..5794bec5 100644 --- a/test/clos1way2.awk +++ b/test/clos1way2.awk @@ -1,5 +1,6 @@ { cmd = "cat - 1>&2; sleep 2" print |& cmd; close(cmd, "to") + fflush(cmd) print |& cmd; print ERRNO } diff --git a/test/clos1way2.ok b/test/clos1way2.ok index 22bd3e17..063c4213 100644 --- a/test/clos1way2.ok +++ b/test/clos1way2.ok @@ -1,3 +1,4 @@ -gawk: clos1way2.awk:4: (FILENAME=- FNR=1) fatal: print: attempt to write to closed write end of two-way pipe +gawk: clos1way2.awk:4: (FILENAME=- FNR=1) warning: fflush: cannot flush: two-way pipe `cat - 1>&2; sleep 2' has closed write end +gawk: clos1way2.awk:5: (FILENAME=- FNR=1) fatal: print: attempt to write to closed write end of two-way pipe test CODE: 2 -- cgit v1.2.3 From cfb773bb093dadfa715816c75d438f97e387e71a Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 6 Apr 2016 05:54:19 +0300 Subject: Allow r/w for a partially closed two-way pipe to be nonfatal. --- ChangeLog | 9 ++ builtin.c | 12 ++ doc/ChangeLog | 6 + doc/gawk.info | 442 ++++++++++++++++++++++++++++---------------------------- doc/gawk.texi | 11 +- doc/gawktexi.in | 11 +- io.c | 4 + 7 files changed, 273 insertions(+), 222 deletions(-) diff --git a/ChangeLog b/ChangeLog index 025f88e9..a96375c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2016-04-06 Arnold D. Robbins + + * builtin.c (do_printf): Allow a write to the closed write-end of + a two-way pipe to be nonfatal if NONFATAL is set for it. + (do_print): Ditto. + (do_print_rec): Ditto. + * io.c (do_getline_redir): Same thing for reading from a closed + read end of a two-way pipe. Fatal error. + 2016-04-04 Arnold D. Robbins * builtin.c (do_fflush): Add warning for flush to two-way diff --git a/builtin.c b/builtin.c index b3756ebc..e07bdb53 100644 --- a/builtin.c +++ b/builtin.c @@ -1679,6 +1679,10 @@ do_printf(int nargs, int redirtype) rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) { if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + if (is_non_fatal_redirect(redir_exp->stptr)) { + update_ERRNO_int(EBADF); + return; + } fatal(_("printf: attempt to write to closed write end of two-way pipe")); } fp = rp->output.fp; @@ -2159,6 +2163,10 @@ do_print(int nargs, int redirtype) rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) { if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + if (is_non_fatal_redirect(redir_exp->stptr)) { + update_ERRNO_int(EBADF); + return; + } fatal(_("print: attempt to write to closed write end of two-way pipe")); } fp = rp->output.fp; @@ -2233,6 +2241,10 @@ do_print_rec(int nargs, int redirtype) rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) { if ((rp->flag & RED_TWOWAY) != 0 && rp->output.fp == NULL) { + if (is_non_fatal_redirect(redir_exp->stptr)) { + update_ERRNO_int(EBADF); + return; + } fatal(_("print: attempt to write to closed write end of two-way pipe")); } fp = rp->output.fp; diff --git a/doc/ChangeLog b/doc/ChangeLog index 7f789370..7ea2afe0 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2016-04-06 Arnold D. Robbins + + * gawktexi.in (Two-way I/O): Document that writing to the closed + write end of a two way pipe or reading from the closed read end + can be made nonfatal. + 2016-04-04 Arnold D. Robbins * gawktexi.in, gawkinet.texi: Enable use of braces in diff --git a/doc/gawk.info b/doc/gawk.info index c60bf429..16f06d4c 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -19943,9 +19943,15 @@ case 'gawk' waits for the child process to exit, which may cause your program to hang. (Thus, this particular feature is of much less use in practice than being able to close the '"to"' end.) - CAUTION: It is a fatal error to write to the '"to"' end of a - two-way pipe which has been closed. It is also a fatal error to - read from the '"from"' end of a two-way pipe that has been closed. + CAUTION: Normally, it is a fatal error to write to the '"to"' end + of a two-way pipe which has been closed, and it is also a fatal + error to read from the '"from"' end of a two-way pipe that has been + closed. + + You may set 'PROCINFO["COMMAND", "NONFATAL"]' to make such + operations become nonfatal, in which case you then need to check + 'ERRNO' after each 'print', 'printf', or 'getline'. *Note + Nonfatal::, for more information. You may also use pseudo-ttys (ptys) for two-way communication instead of pipes, if your system supports them. This is done on a per-command @@ -33747,7 +33753,7 @@ Index * gawk, predefined variables and: Built-in Variables. (line 14) * gawk, PROCINFO array in: Auto-set. (line 148) * gawk, PROCINFO array in <1>: Time Functions. (line 47) -* gawk, PROCINFO array in <2>: Two-way I/O. (line 108) +* gawk, PROCINFO array in <2>: Two-way I/O. (line 114) * gawk, regexp constants and: Using Constant Regexps. (line 28) * gawk, regular expressions, case sensitivity: Case-sensitivity. @@ -34525,7 +34531,7 @@ Index * PROCINFO array: Auto-set. (line 148) * PROCINFO array <1>: Time Functions. (line 47) * PROCINFO array <2>: Passwd Functions. (line 6) -* PROCINFO array, and communications via ptys: Two-way I/O. (line 108) +* PROCINFO array, and communications via ptys: Two-way I/O. (line 114) * PROCINFO array, and group membership: Group Functions. (line 6) * PROCINFO array, and user and group ID numbers: Id Program. (line 15) * PROCINFO array, testing the field splitting: Passwd Functions. @@ -35594,218 +35600,218 @@ Ref: Controlling Array Traversal-Footnote-1801827 Node: Array Sorting Functions801945 Ref: Array Sorting Functions-Footnote-1807036 Node: Two-way I/O807232 -Ref: Two-way I/O-Footnote-1813526 -Ref: Two-way I/O-Footnote-2813713 -Node: TCP/IP Networking813795 -Node: Profiling816913 -Ref: Profiling-Footnote-1825406 -Node: Advanced Features Summary825729 -Node: Internationalization827573 -Node: I18N and L10N829053 -Node: Explaining gettext829740 -Ref: Explaining gettext-Footnote-1834763 -Ref: Explaining gettext-Footnote-2834948 -Node: Programmer i18n835113 -Ref: Programmer i18n-Footnote-1839968 -Node: Translator i18n840017 -Node: String Extraction840811 -Ref: String Extraction-Footnote-1841943 -Node: Printf Ordering842029 -Ref: Printf Ordering-Footnote-1844815 -Node: I18N Portability844879 -Ref: I18N Portability-Footnote-1847335 -Node: I18N Example847398 -Ref: I18N Example-Footnote-1850204 -Node: Gawk I18N850277 -Node: I18N Summary850922 -Node: Debugger852263 -Node: Debugging853285 -Node: Debugging Concepts853726 -Node: Debugging Terms855535 -Node: Awk Debugging858110 -Node: Sample Debugging Session859016 -Node: Debugger Invocation859550 -Node: Finding The Bug860936 -Node: List of Debugger Commands867414 -Node: Breakpoint Control868747 -Node: Debugger Execution Control872441 -Node: Viewing And Changing Data875803 -Node: Execution Stack879177 -Node: Debugger Info880814 -Node: Miscellaneous Debugger Commands884885 -Node: Readline Support889973 -Node: Limitations890869 -Ref: Limitations-Footnote-1895100 -Node: Debugging Summary895151 -Node: Arbitrary Precision Arithmetic896430 -Node: Computer Arithmetic897846 -Ref: table-numeric-ranges901437 -Ref: Computer Arithmetic-Footnote-1902159 -Node: Math Definitions902216 -Ref: table-ieee-formats905530 -Ref: Math Definitions-Footnote-1906133 -Node: MPFR features906238 -Node: FP Math Caution907955 -Ref: FP Math Caution-Footnote-1909027 -Node: Inexactness of computations909396 -Node: Inexact representation910356 -Node: Comparing FP Values911716 -Node: Errors accumulate912798 -Node: Getting Accuracy914231 -Node: Try To Round916941 -Node: Setting precision917840 -Ref: table-predefined-precision-strings918537 -Node: Setting the rounding mode920367 -Ref: table-gawk-rounding-modes920741 -Ref: Setting the rounding mode-Footnote-1924149 -Node: Arbitrary Precision Integers924328 -Ref: Arbitrary Precision Integers-Footnote-1929245 -Node: POSIX Floating Point Problems929394 -Ref: POSIX Floating Point Problems-Footnote-1933276 -Node: Floating point summary933314 -Node: Dynamic Extensions935504 -Node: Extension Intro937057 -Node: Plugin License938323 -Node: Extension Mechanism Outline939120 -Ref: figure-load-extension939559 -Ref: figure-register-new-function941124 -Ref: figure-call-new-function942216 -Node: Extension API Description944278 -Node: Extension API Functions Introduction945810 -Node: General Data Types950669 -Ref: General Data Types-Footnote-1956624 -Node: Memory Allocation Functions956923 -Ref: Memory Allocation Functions-Footnote-1959768 -Node: Constructor Functions959867 -Node: Registration Functions961612 -Node: Extension Functions962297 -Node: Exit Callback Functions964596 -Node: Extension Version String965846 -Node: Input Parsers966509 -Node: Output Wrappers976394 -Node: Two-way processors980906 -Node: Printing Messages983170 -Ref: Printing Messages-Footnote-1984244 -Node: Updating ERRNO984397 -Node: Requesting Values985136 -Ref: table-value-types-returned985873 -Node: Accessing Parameters986756 -Node: Symbol Table Access987991 -Node: Symbol table by name988503 -Node: Symbol table by cookie990524 -Ref: Symbol table by cookie-Footnote-1994673 -Node: Cached values994737 -Ref: Cached values-Footnote-1998238 -Node: Array Manipulation998329 -Ref: Array Manipulation-Footnote-1999420 -Node: Array Data Types999457 -Ref: Array Data Types-Footnote-11002115 -Node: Array Functions1002207 -Node: Flattening Arrays1006065 -Node: Creating Arrays1012973 -Node: Redirection API1017744 -Node: Extension API Variables1020575 -Node: Extension Versioning1021208 -Node: Extension API Informational Variables1023099 -Node: Extension API Boilerplate1024163 -Node: Finding Extensions1027977 -Node: Extension Example1028536 -Node: Internal File Description1029334 -Node: Internal File Ops1033414 -Ref: Internal File Ops-Footnote-11045176 -Node: Using Internal File Ops1045316 -Ref: Using Internal File Ops-Footnote-11047699 -Node: Extension Samples1047973 -Node: Extension Sample File Functions1049502 -Node: Extension Sample Fnmatch1057151 -Node: Extension Sample Fork1058638 -Node: Extension Sample Inplace1059856 -Node: Extension Sample Ord1063066 -Node: Extension Sample Readdir1063902 -Ref: table-readdir-file-types1064791 -Node: Extension Sample Revout1065596 -Node: Extension Sample Rev2way1066185 -Node: Extension Sample Read write array1066925 -Node: Extension Sample Readfile1068867 -Node: Extension Sample Time1069962 -Node: Extension Sample API Tests1071310 -Node: gawkextlib1071802 -Node: Extension summary1074249 -Node: Extension Exercises1077941 -Node: Language History1079438 -Node: V7/SVR3.11081094 -Node: SVR41083246 -Node: POSIX1084680 -Node: BTL1086059 -Node: POSIX/GNU1086788 -Node: Feature History1092650 -Node: Common Extensions1107020 -Node: Ranges and Locales1108303 -Ref: Ranges and Locales-Footnote-11112919 -Ref: Ranges and Locales-Footnote-21112946 -Ref: Ranges and Locales-Footnote-31113181 -Node: Contributors1113402 -Node: History summary1118971 -Node: Installation1120351 -Node: Gawk Distribution1121295 -Node: Getting1121779 -Node: Extracting1122740 -Node: Distribution contents1124378 -Node: Unix Installation1130472 -Node: Quick Installation1131154 -Node: Shell Startup Files1133568 -Node: Additional Configuration Options1134646 -Node: Configuration Philosophy1136451 -Node: Non-Unix Installation1138820 -Node: PC Installation1139278 -Node: PC Binary Installation1140598 -Node: PC Compiling1142450 -Ref: PC Compiling-Footnote-11145474 -Node: PC Testing1145583 -Node: PC Using1146763 -Node: Cygwin1150877 -Node: MSYS1151647 -Node: VMS Installation1152148 -Node: VMS Compilation1152939 -Ref: VMS Compilation-Footnote-11154168 -Node: VMS Dynamic Extensions1154226 -Node: VMS Installation Details1155911 -Node: VMS Running1158164 -Node: VMS GNV1162443 -Node: VMS Old Gawk1163178 -Node: Bugs1163649 -Node: Other Versions1167846 -Node: Installation summary1174430 -Node: Notes1175488 -Node: Compatibility Mode1176353 -Node: Additions1177135 -Node: Accessing The Source1178060 -Node: Adding Code1179495 -Node: New Ports1185714 -Node: Derived Files1190202 -Ref: Derived Files-Footnote-11195687 -Ref: Derived Files-Footnote-21195722 -Ref: Derived Files-Footnote-31196320 -Node: Future Extensions1196434 -Node: Implementation Limitations1197092 -Node: Extension Design1198275 -Node: Old Extension Problems1199429 -Ref: Old Extension Problems-Footnote-11200947 -Node: Extension New Mechanism Goals1201004 -Ref: Extension New Mechanism Goals-Footnote-11204368 -Node: Extension Other Design Decisions1204557 -Node: Extension Future Growth1206670 -Node: Old Extension Mechanism1207506 -Node: Notes summary1209269 -Node: Basic Concepts1210451 -Node: Basic High Level1211132 -Ref: figure-general-flow1211414 -Ref: figure-process-flow1212099 -Ref: Basic High Level-Footnote-11215400 -Node: Basic Data Typing1215585 -Node: Glossary1218913 -Node: Copying1250859 -Node: GNU Free Documentation License1288398 -Node: Index1313516 +Ref: Two-way I/O-Footnote-1813782 +Ref: Two-way I/O-Footnote-2813969 +Node: TCP/IP Networking814051 +Node: Profiling817169 +Ref: Profiling-Footnote-1825662 +Node: Advanced Features Summary825985 +Node: Internationalization827829 +Node: I18N and L10N829309 +Node: Explaining gettext829996 +Ref: Explaining gettext-Footnote-1835019 +Ref: Explaining gettext-Footnote-2835204 +Node: Programmer i18n835369 +Ref: Programmer i18n-Footnote-1840224 +Node: Translator i18n840273 +Node: String Extraction841067 +Ref: String Extraction-Footnote-1842199 +Node: Printf Ordering842285 +Ref: Printf Ordering-Footnote-1845071 +Node: I18N Portability845135 +Ref: I18N Portability-Footnote-1847591 +Node: I18N Example847654 +Ref: I18N Example-Footnote-1850460 +Node: Gawk I18N850533 +Node: I18N Summary851178 +Node: Debugger852519 +Node: Debugging853541 +Node: Debugging Concepts853982 +Node: Debugging Terms855791 +Node: Awk Debugging858366 +Node: Sample Debugging Session859272 +Node: Debugger Invocation859806 +Node: Finding The Bug861192 +Node: List of Debugger Commands867670 +Node: Breakpoint Control869003 +Node: Debugger Execution Control872697 +Node: Viewing And Changing Data876059 +Node: Execution Stack879433 +Node: Debugger Info881070 +Node: Miscellaneous Debugger Commands885141 +Node: Readline Support890229 +Node: Limitations891125 +Ref: Limitations-Footnote-1895356 +Node: Debugging Summary895407 +Node: Arbitrary Precision Arithmetic896686 +Node: Computer Arithmetic898102 +Ref: table-numeric-ranges901693 +Ref: Computer Arithmetic-Footnote-1902415 +Node: Math Definitions902472 +Ref: table-ieee-formats905786 +Ref: Math Definitions-Footnote-1906389 +Node: MPFR features906494 +Node: FP Math Caution908211 +Ref: FP Math Caution-Footnote-1909283 +Node: Inexactness of computations909652 +Node: Inexact representation910612 +Node: Comparing FP Values911972 +Node: Errors accumulate913054 +Node: Getting Accuracy914487 +Node: Try To Round917197 +Node: Setting precision918096 +Ref: table-predefined-precision-strings918793 +Node: Setting the rounding mode920623 +Ref: table-gawk-rounding-modes920997 +Ref: Setting the rounding mode-Footnote-1924405 +Node: Arbitrary Precision Integers924584 +Ref: Arbitrary Precision Integers-Footnote-1929501 +Node: POSIX Floating Point Problems929650 +Ref: POSIX Floating Point Problems-Footnote-1933532 +Node: Floating point summary933570 +Node: Dynamic Extensions935760 +Node: Extension Intro937313 +Node: Plugin License938579 +Node: Extension Mechanism Outline939376 +Ref: figure-load-extension939815 +Ref: figure-register-new-function941380 +Ref: figure-call-new-function942472 +Node: Extension API Description944534 +Node: Extension API Functions Introduction946066 +Node: General Data Types950925 +Ref: General Data Types-Footnote-1956880 +Node: Memory Allocation Functions957179 +Ref: Memory Allocation Functions-Footnote-1960024 +Node: Constructor Functions960123 +Node: Registration Functions961868 +Node: Extension Functions962553 +Node: Exit Callback Functions964852 +Node: Extension Version String966102 +Node: Input Parsers966765 +Node: Output Wrappers976650 +Node: Two-way processors981162 +Node: Printing Messages983426 +Ref: Printing Messages-Footnote-1984500 +Node: Updating ERRNO984653 +Node: Requesting Values985392 +Ref: table-value-types-returned986129 +Node: Accessing Parameters987012 +Node: Symbol Table Access988247 +Node: Symbol table by name988759 +Node: Symbol table by cookie990780 +Ref: Symbol table by cookie-Footnote-1994929 +Node: Cached values994993 +Ref: Cached values-Footnote-1998494 +Node: Array Manipulation998585 +Ref: Array Manipulation-Footnote-1999676 +Node: Array Data Types999713 +Ref: Array Data Types-Footnote-11002371 +Node: Array Functions1002463 +Node: Flattening Arrays1006321 +Node: Creating Arrays1013229 +Node: Redirection API1018000 +Node: Extension API Variables1020831 +Node: Extension Versioning1021464 +Node: Extension API Informational Variables1023355 +Node: Extension API Boilerplate1024419 +Node: Finding Extensions1028233 +Node: Extension Example1028792 +Node: Internal File Description1029590 +Node: Internal File Ops1033670 +Ref: Internal File Ops-Footnote-11045432 +Node: Using Internal File Ops1045572 +Ref: Using Internal File Ops-Footnote-11047955 +Node: Extension Samples1048229 +Node: Extension Sample File Functions1049758 +Node: Extension Sample Fnmatch1057407 +Node: Extension Sample Fork1058894 +Node: Extension Sample Inplace1060112 +Node: Extension Sample Ord1063322 +Node: Extension Sample Readdir1064158 +Ref: table-readdir-file-types1065047 +Node: Extension Sample Revout1065852 +Node: Extension Sample Rev2way1066441 +Node: Extension Sample Read write array1067181 +Node: Extension Sample Readfile1069123 +Node: Extension Sample Time1070218 +Node: Extension Sample API Tests1071566 +Node: gawkextlib1072058 +Node: Extension summary1074505 +Node: Extension Exercises1078197 +Node: Language History1079694 +Node: V7/SVR3.11081350 +Node: SVR41083502 +Node: POSIX1084936 +Node: BTL1086315 +Node: POSIX/GNU1087044 +Node: Feature History1092906 +Node: Common Extensions1107276 +Node: Ranges and Locales1108559 +Ref: Ranges and Locales-Footnote-11113175 +Ref: Ranges and Locales-Footnote-21113202 +Ref: Ranges and Locales-Footnote-31113437 +Node: Contributors1113658 +Node: History summary1119227 +Node: Installation1120607 +Node: Gawk Distribution1121551 +Node: Getting1122035 +Node: Extracting1122996 +Node: Distribution contents1124634 +Node: Unix Installation1130728 +Node: Quick Installation1131410 +Node: Shell Startup Files1133824 +Node: Additional Configuration Options1134902 +Node: Configuration Philosophy1136707 +Node: Non-Unix Installation1139076 +Node: PC Installation1139534 +Node: PC Binary Installation1140854 +Node: PC Compiling1142706 +Ref: PC Compiling-Footnote-11145730 +Node: PC Testing1145839 +Node: PC Using1147019 +Node: Cygwin1151133 +Node: MSYS1151903 +Node: VMS Installation1152404 +Node: VMS Compilation1153195 +Ref: VMS Compilation-Footnote-11154424 +Node: VMS Dynamic Extensions1154482 +Node: VMS Installation Details1156167 +Node: VMS Running1158420 +Node: VMS GNV1162699 +Node: VMS Old Gawk1163434 +Node: Bugs1163905 +Node: Other Versions1168102 +Node: Installation summary1174686 +Node: Notes1175744 +Node: Compatibility Mode1176609 +Node: Additions1177391 +Node: Accessing The Source1178316 +Node: Adding Code1179751 +Node: New Ports1185970 +Node: Derived Files1190458 +Ref: Derived Files-Footnote-11195943 +Ref: Derived Files-Footnote-21195978 +Ref: Derived Files-Footnote-31196576 +Node: Future Extensions1196690 +Node: Implementation Limitations1197348 +Node: Extension Design1198531 +Node: Old Extension Problems1199685 +Ref: Old Extension Problems-Footnote-11201203 +Node: Extension New Mechanism Goals1201260 +Ref: Extension New Mechanism Goals-Footnote-11204624 +Node: Extension Other Design Decisions1204813 +Node: Extension Future Growth1206926 +Node: Old Extension Mechanism1207762 +Node: Notes summary1209525 +Node: Basic Concepts1210707 +Node: Basic High Level1211388 +Ref: figure-general-flow1211670 +Ref: figure-process-flow1212355 +Ref: Basic High Level-Footnote-11215656 +Node: Basic Data Typing1215841 +Node: Glossary1219169 +Node: Copying1251115 +Node: GNU Free Documentation License1288654 +Node: Index1313772  End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 77bec7d1..fd71dbc9 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -27859,9 +27859,16 @@ your program to hang. (Thus, this particular feature is of much less use in practice than being able to close the @code{"to"} end.) @quotation CAUTION -It is a fatal error to write to the @code{"to"} end of a two-way -pipe which has been closed. It is also a fatal error to read +Normally, +it is a fatal error to write to the @code{"to"} end of a two-way +pipe which has been closed, and it is also a fatal error to read from the @code{"from"} end of a two-way pipe that has been closed. + +You may set @code{PROCINFO["@var{command}", "NONFATAL"]} to +make such operations become nonfatal, in which case you then need +to check @code{ERRNO} after each @code{print}, @code{printf}, +or @code{getline}. +@xref{Nonfatal}, for more information. @end quotation @cindex @command{gawk}, @code{PROCINFO} array in diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 75381dc4..f47c8459 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -26950,9 +26950,16 @@ your program to hang. (Thus, this particular feature is of much less use in practice than being able to close the @code{"to"} end.) @quotation CAUTION -It is a fatal error to write to the @code{"to"} end of a two-way -pipe which has been closed. It is also a fatal error to read +Normally, +it is a fatal error to write to the @code{"to"} end of a two-way +pipe which has been closed, and it is also a fatal error to read from the @code{"from"} end of a two-way pipe that has been closed. + +You may set @code{PROCINFO["@var{command}", "NONFATAL"]} to +make such operations become nonfatal, in which case you then need +to check @code{ERRNO} after each @code{print}, @code{printf}, +or @code{getline}. +@xref{Nonfatal}, for more information. @end quotation @cindex @command{gawk}, @code{PROCINFO} array in diff --git a/io.c b/io.c index 719601c2..fafc1003 100644 --- a/io.c +++ b/io.c @@ -2604,6 +2604,10 @@ do_getline_redir(int into_variable, enum redirval redirtype) } return make_number((AWKNUM) -1.0); } else if ((rp->flag & RED_TWOWAY) != 0 && rp->iop == NULL) { + if (is_non_fatal_redirect(redir_exp->stptr)) { + update_ERRNO_int(EBADF); + return make_number((AWKNUM) -1.0); + } fatal(_("getline: attempt to read from closed read end of two-way pipe")); } iop = rp->iop; -- cgit v1.2.3 From 43a645fe05c57576d9d41a7f3b18bb55b1dbdc3e Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 6 Apr 2016 05:58:03 +0300 Subject: Test case for nonfatal close one end of two way pipe. --- test/ChangeLog | 5 +++++ test/Makefile.am | 4 +++- test/Makefile.in | 9 ++++++++- test/Maketests | 5 +++++ test/clos1way6.awk | 7 +++++++ test/clos1way6.ok | 3 +++ 6 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/clos1way6.awk create mode 100644 test/clos1way6.ok diff --git a/test/ChangeLog b/test/ChangeLog index eaeed87d..bfb05de6 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2016-04-06 Arnold D. Robbins + + * Makefile.am (clos1way6): New test. + * clos1way6.awk, clos1way6.ok: New files. + 2016-04-04 Arnold D. Robbins * Makefile.am (clos1way2, clos1way3, clos1way4, clos1way5): diff --git a/test/Makefile.am b/test/Makefile.am index 8e5d0c88..fdb163d7 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -156,6 +156,8 @@ EXTRA_DIST = \ clos1way4.ok \ clos1way5.awk \ clos1way5.ok \ + clos1way6.awk \ + clos1way6.ok \ closebad.awk \ closebad.ok \ clsflnam.awk \ @@ -1130,7 +1132,7 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 binmode1 charasbytes \ - colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 \ + colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 clos1way6 \ crlf dbugeval dbugeval2 dbugtypedre1 dbugtypedre2 delsub \ devfd devfd1 devfd2 dumpvars errno exit \ fieldwdth fpat1 fpat2 fpat3 fpat4 fpat5 fpatnull fsfwfs funlen \ diff --git a/test/Makefile.in b/test/Makefile.in index 9fec312d..3fa8fbc4 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -413,6 +413,8 @@ EXTRA_DIST = \ clos1way4.ok \ clos1way5.awk \ clos1way5.ok \ + clos1way6.awk \ + clos1way6.ok \ closebad.awk \ closebad.ok \ clsflnam.awk \ @@ -1386,7 +1388,7 @@ UNIX_TESTS = \ GAWK_EXT_TESTS = \ aadelete1 aadelete2 aarray1 aasort aasorti argtest arraysort \ backw badargs beginfile1 beginfile2 binmode1 charasbytes \ - colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 \ + colonwarn clos1way clos1way2 clos1way3 clos1way4 clos1way5 clos1way6 \ crlf dbugeval dbugeval2 dbugtypedre1 dbugtypedre2 delsub \ devfd devfd1 devfd2 dumpvars errno exit \ fieldwdth fpat1 fpat2 fpat3 fpat4 fpat5 fpatnull fsfwfs funlen \ @@ -3678,6 +3680,11 @@ clos1way5: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +clos1way6: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + crlf: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index e39f6c3c..3b4691d2 100644 --- a/test/Maketests +++ b/test/Maketests @@ -1017,6 +1017,11 @@ clos1way5: @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +clos1way6: + @echo $@ + @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + crlf: @echo $@ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/clos1way6.awk b/test/clos1way6.awk new file mode 100644 index 00000000..19779d73 --- /dev/null +++ b/test/clos1way6.awk @@ -0,0 +1,7 @@ +BEGIN { + cmd = "cat - 1>&2; sleep 2" + PROCINFO[cmd, "NONFATAL"] = 1 + print "test1" |& cmd; close(cmd, "to") + fflush(cmd) + print "test2" |& cmd; print ERRNO +} diff --git a/test/clos1way6.ok b/test/clos1way6.ok new file mode 100644 index 00000000..5768617d --- /dev/null +++ b/test/clos1way6.ok @@ -0,0 +1,3 @@ +gawk: clos1way6.awk:5: warning: fflush: cannot flush: two-way pipe `cat - 1>&2; sleep 2' has closed write end +test1 +Bad file descriptor -- cgit v1.2.3