From fca40724de45d72d7309ec722399f7e0ce13d09f Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 14 Jul 2024 22:43:54 -0700 Subject: [PATCH] Handle broken pipes in a better way in Eshell * lisp/eshell/esh-proc.el (eshell-insertion-filter): Send SIGPIPE, falling back to SIGTERM (bug#72117). --- lisp/eshell/esh-proc.el | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lisp/eshell/esh-proc.el b/lisp/eshell/esh-proc.el index 2ff41c3d409..65537cf6adb 100644 --- a/lisp/eshell/esh-proc.el +++ b/lisp/eshell/esh-proc.el @@ -479,22 +479,22 @@ eshell-insertion-filter "forwarding output from process `%s'\n\n%s" proc data) (condition-case nil (eshell-output-object data index handles) - ;; FIXME: We want to send SIGPIPE to the process - ;; here. However, remote processes don't currently - ;; support that, and not all systems have SIGPIPE in - ;; the first place (e.g. MS Windows). In these - ;; cases, just delete the process; this is - ;; reasonably close to the right behavior, since the - ;; default action for SIGPIPE is to terminate the - ;; process. For use cases where SIGPIPE is truly - ;; needed, using an external pipe operator (`*|') - ;; may work instead (e.g. when working with remote - ;; processes). + ;; We want to send SIGPIPE to the process here. + ;; However, MS-Windows doesn't support that, so send + ;; SIGTERM there instead; this is reasonably close to + ;; the right behavior, since the default action for + ;; SIGPIPE is to terminate the process. NOTE: Due to + ;; the additional indirection of Emacs process + ;; filters, the process will likely see the SIGPIPE + ;; later than it would in a regular shell, which could + ;; cause problems. For cases where this matters, + ;; using an external pipe operator (`*|') may work + ;; instead. (eshell-pipe-broken - (if (or (process-get proc 'remote-pid) - (eq system-type 'windows-nt)) - (delete-process proc) - (signal-process proc 'SIGPIPE)))))) + (signal-process + proc (if (or (not (eq system-type 'windows-nt)) + (process-get proc 'remote-pid)) + 'SIGPIPE 'SIGTERM)))))) (process-put proc :eshell-busy nil)))))) (defun eshell-sentinel (proc string) -- 2.25.1