summaryrefslogtreecommitdiff
path: root/lisp/eshell/esh-io.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/eshell/esh-io.el')
-rw-r--r--lisp/eshell/esh-io.el16
1 files changed, 14 insertions, 2 deletions
diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el
index 3644c1a18b5..c035890ddf0 100644
--- a/lisp/eshell/esh-io.el
+++ b/lisp/eshell/esh-io.el
@@ -276,8 +276,20 @@ STATUS should be non-nil on successful termination of the output."
;; If we're redirecting to a process (via a pipe, or process
;; redirection), send it EOF so that it knows we're finished.
((eshell-processp target)
- (if (eq (process-status target) 'run)
- (process-send-eof target)))
+ ;; According to POSIX.1-2017, section 11.1.9, sending EOF causes
+ ;; all bytes waiting to be read to be sent to the process
+ ;; immediately. Thus, if there are any bytes waiting, we need to
+ ;; send EOF twice: once to flush the buffer, and a second time to
+ ;; cause the next read() to return a size of 0, indicating
+ ;; end-of-file to the reading process. However, some platforms
+ ;; (e.g. Solaris) actually require sending a *third* EOF. Since
+ ;; sending extra EOFs while the process is running shouldn't break
+ ;; anything, we'll just send the maximum we'd ever need. See
+ ;; bug#56025 for further details.
+ (let ((i 0))
+ (while (and (<= (cl-incf i) 3)
+ (eq (process-status target) 'run))
+ (process-send-eof target))))
;; A plain function redirection needs no additional arguments
;; passed.