unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: the_wurfkreuz <the_wurfkreuz@proton.me>, 72117@debbugs.gnu.org
Subject: bug#72117: Command doesn't execute correctly in eshell
Date: Mon, 15 Jul 2024 20:09:26 -0700	[thread overview]
Message-ID: <b38a2499-00f7-4baa-cb59-834357758bbd@gmail.com> (raw)
In-Reply-To: <f1513d3b-e98b-408c-78cb-b3526684722a@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1113 bytes --]

On 7/14/2024 6:01 PM, Jim Porter wrote:
> On 7/14/2024 12:33 PM, the_wurfkreuz via Bug reports for GNU Emacs, the 
> Swiss army knife of text editors wrote:
>> First of all, i can't execute 'sudo lsof | grep delete | head -10' in
>> eshell.
> 
> 'sudo -S' should help here: it'll output the sudo password prompt on 
> stderr so that Eshell can see it and handle password entry. (You should 
> be able to enter your password anyway, but without the -S it would just 
> be echoed to the screen.)
> 
>   But that's not the most interesting part. I can execute the
>> command with 'eshell/sudo'. But after the command execution emacs will
>> take the whole CPU processing time if i have 
>> '(global-display-line-numbers-mode 1)'
>> option enabled.
> 
> I can't reproduce this particular issue, but I can reproduce *an* issue. 
> It seems to be due to "head -10" exiting early (as it should), which 
> results in a broken pipe. However, Eshell's broken pipe handling wasn't 
> properly cleaning up the process ("grep" in this example).

Here's a better patch, based on the recent improvements to Tramp in 
bug#72013.

[-- Attachment #2: 0001-Handle-broken-pipes-in-a-better-way-in-Eshell.patch --]
[-- Type: text/plain, Size: 2871 bytes --]

From fca40724de45d72d7309ec722399f7e0ce13d09f Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
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


  reply	other threads:[~2024-07-16  3:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-14 19:33 bug#72117: Command doesn't execute correctly in eshell the_wurfkreuz via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-15  1:01 ` Jim Porter
2024-07-16  3:09   ` Jim Porter [this message]
     [not found]     ` <uDv8zx2ccT4dsHYBueowwgc6Hjuz4gs3wLRNNOXllaD4ifNUqW2-7eEYYJDjsG5VzBWGHQGoIJ1aFnbQxMLoacZR71w8v11rIb7GTfhQuus=@proton.me>
2024-07-17  2:09       ` Jim Porter
2024-07-18  5:05         ` Jim Porter
2024-07-18  9:31           ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-18 15:38             ` Jim Porter
2024-07-18 16:49               ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-07-18 18:26                 ` Jim Porter
2024-07-27  5:18   ` Jim Porter
2024-07-27  6:40     ` Eli Zaretskii
2024-07-27 19:14       ` Jim Porter
2024-07-28  7:59         ` Jim Porter
2024-07-28 16:21           ` Jim Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b38a2499-00f7-4baa-cb59-834357758bbd@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=72117@debbugs.gnu.org \
    --cc=the_wurfkreuz@proton.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).