From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jim Porter Newsgroups: gmane.emacs.bugs Subject: bug#54062: 29.0.50; [PATCH] Eshell should inform processes when a pipe is broken Date: Sat, 19 Feb 2022 12:02:45 -0800 Message-ID: References: <7da3e8b2-7400-dca6-6d92-0a60e3d9c215@gmail.com> <83mtinz222.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------AE4EE568D2E254636385C365" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18986"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 54062@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 19 21:03:11 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nLVwl-0004iP-1S for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Feb 2022 21:03:11 +0100 Original-Received: from localhost ([::1]:37680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nLVwj-0005mn-KI for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Feb 2022 15:03:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:45752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nLVwc-0005mQ-J8 for bug-gnu-emacs@gnu.org; Sat, 19 Feb 2022 15:03:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36645) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nLVwc-0000xx-9q for bug-gnu-emacs@gnu.org; Sat, 19 Feb 2022 15:03:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nLVwc-0007Ef-0i for bug-gnu-emacs@gnu.org; Sat, 19 Feb 2022 15:03:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 19 Feb 2022 20:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54062 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 54062-submit@debbugs.gnu.org id=B54062.164530097527800 (code B ref 54062); Sat, 19 Feb 2022 20:03:01 +0000 Original-Received: (at 54062) by debbugs.gnu.org; 19 Feb 2022 20:02:55 +0000 Original-Received: from localhost ([127.0.0.1]:58775 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nLVwU-0007EK-W9 for submit@debbugs.gnu.org; Sat, 19 Feb 2022 15:02:55 -0500 Original-Received: from mail-pj1-f53.google.com ([209.85.216.53]:35422) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nLVwT-0007E4-2u for 54062@debbugs.gnu.org; Sat, 19 Feb 2022 15:02:53 -0500 Original-Received: by mail-pj1-f53.google.com with SMTP id a11-20020a17090a740b00b001b8b506c42fso15329748pjg.0 for <54062@debbugs.gnu.org>; Sat, 19 Feb 2022 12:02:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-language; bh=wwcehHi7Q+lr+auYIlghnEQbKKaZUSise4yJoyu+gcg=; b=OyDszSUN9ZumvAZ0et4CWlcQoAX8po26WC1NxcB44rcpkE1xnggnZ2HiMtiYTck/u6 3tgN20kSSk9hNhetiWllkLSydoHALRqu+pt4n7uJheHFurOTOf6YyuwtTTdUtPVqSAWs A+Al4BsihI9emBSyter4M/d+GQjTqZpPP8EL+gmLzDftiVTg/SDgmnMndp+6TmMOvNVB oX7epamEpYHxSu4/8+uYhpELSBMGhHAY/j+raPOO3sikxH3L51ED0nHY2d+1tXdnanoG fZdSs5OHi/1hdvuJmlQ6Xmkqc5HSw2NRg8POQ+Y6wewWqLsdQUEcsXO0oqPLRmATLbLf nDZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-language; bh=wwcehHi7Q+lr+auYIlghnEQbKKaZUSise4yJoyu+gcg=; b=JhXSOXf7ln9ala+6DoWOA9pA1+VzCnLWR00cJPyz/+WeUYBrsBVMD2O+7vUvZl0+WR 9X9CgeeHvli8CRtkfxPQ8/Y5iop2xNudUzCLd2degFdWf2/dstTB2xy7K7o0GGT9ETkx Jx0Ctji69k1OdyfteaBt6DvFrHDwrWN0UQrCHfRm6l/J93+EtxOsJNFcwVKqbF5zrEeC uWsw/tZgXesrNnEU49aV+/IJmhxx4BHap6AFzhd5OffTbTPvO/mUPQEcM//vtOqdv2Jl FeHjdSW5nUYK0JtAkQqpoFZWJRvwa/t1j5j1edK1MubQL0tGtW6hlieimN6jSqnGr+YF 0w1g== X-Gm-Message-State: AOAM530th4tTmGLh1OE6+KNYzGK80/ATPilgVpnydAi1Kpgeex07UaGi mFL97gyoK1gf93wZXSo8lig5xN6l8uM= X-Google-Smtp-Source: ABdhPJwkoOHtixiUDPE7ddD7C3JJsrupu1IrTVa83ftS+jBuSilusNRhUWV46vyZPDKm3ZaPXV6pGA== X-Received: by 2002:a17:903:283:b0:14d:6e68:27cb with SMTP id j3-20020a170903028300b0014d6e6827cbmr12704009plr.80.1645300967039; Sat, 19 Feb 2022 12:02:47 -0800 (PST) Original-Received: from [192.168.1.2] (cpe-76-168-148-233.socal.res.rr.com. [76.168.148.233]) by smtp.googlemail.com with ESMTPSA id m14sm7476953pfc.170.2022.02.19.12.02.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 19 Feb 2022 12:02:46 -0800 (PST) In-Reply-To: <83mtinz222.fsf@gnu.org> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:227204 Archived-At: This is a multi-part message in MIME format. --------------AE4EE568D2E254636385C365 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 2/19/2022 12:35 AM, Eli Zaretskii wrote: >> From: Jim Porter >> Date: Fri, 18 Feb 2022 20:20:10 -0800 >> >> Consider the following shell command: >> >> yes | sh -c 'read NAME' >> >> Ordinarily, you'd expect that `sh' reads a single "y", exits, and then >> the next time `yes' tries to write, it finds that the pipe was broken. >> However, that's not what happens in Eshell. Running the above and then >> calling `M-x list-processes' will show that `yes' is still running. >> >> Attached is a patch (with a test) to fix this by telling Eshell to >> signal SIGPIPE at the appropriate time. > > SIGPIPE isn't supported on MS-Windows, so I think we should have a > fallback there for platforms that don't support SIGPIPE. Hmm, good point. Thinking about this some more, this also won't work for Tramp (which only supports `interrupt-process' as far as I can tell). I can think of a couple possible solutions. One option would be to call `interrupt-process' instead, since that works in all cases I'm aware of. This isn't quite as nice as sending SIGPIPE (or equivalent) to let the process handle it how it wants, but at least `interrupt-process' has the same default behavior as SIGPIPE (i.e. terminate the process). Another way would be to add a function like `process-break-pipe' (it could probably use a better name) that would close the read end of the process's output pipe, which - if I understand the Win32 API here - should trigger the right behavior on MS Windows too. It should work for Tramp too, although Tramp might need a bit of tweaking to handle this case. I've attached an outline of what this could look like; it applies on top of my previous patches. One caveat is that the head process (`yes' in the example), would only see the "broken pipe" error on the *next* write after the one where Eshell detected the broken pipe. That's easy enough to fix for cases where we can signal SIGPIPE directly, but it's probably ok in general too: after all, processes don't generally know exactly when a SIGPIPE might occur, so it occurring slightly later shouldn't cause problems. (In theory, the tail process should call `process-break-pipe' as soon as it closes, but in Eshell, the tail process doesn't know what's feeding it input, so it can't easily do this.) What do you think? Is this a sensible avenue to go down? There's probably room to discuss what the API should look like, but I wanted to be sure I was on the right track before I went too far. --------------AE4EE568D2E254636385C365 Content-Type: text/plain; charset=UTF-8; name="process-break-pipe.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="process-break-pipe.patch" ZGlmZiAtLWdpdCBhL2xpc3AvZXNoZWxsL2VzaC1wcm9jLmVsIGIvbGlzcC9lc2hlbGwvZXNo LXByb2MuZWwKaW5kZXggODZhZTY5OTc4Zi4uYjgzMzY1N2M0NiAxMDA2NDQKLS0tIGEvbGlz cC9lc2hlbGwvZXNoLXByb2MuZWwKKysrIGIvbGlzcC9lc2hlbGwvZXNoLXByb2MuZWwKQEAg LTM4OSw3ICszODksMTIgQEAgZXNoZWxsLWluc2VydGlvbi1maWx0ZXIKICAgICAgICAgICAg ICAgICAodW53aW5kLXByb3RlY3QKICAgICAgICAgICAgICAgICAgICAgKGNvbmRpdGlvbi1j YXNlIG5pbAogICAgICAgICAgICAgICAgICAgICAgICAgKGVzaGVsbC1vdXRwdXQtb2JqZWN0 IGRhdGEgbmlsIChjYWRyIGVudHJ5KSkKLSAgICAgICAgICAgICAgICAgICAgICAoZXNoZWxs LXBpcGUtYnJva2VuIChzaWduYWwtcHJvY2VzcyBwcm9jICdTSUdQSVBFKSkpCisgICAgICAg ICAgICAgICAgICAgICAgKGVzaGVsbC1waXBlLWJyb2tlbgorICAgICAgICAgICAgICAgICAg ICAgICA7OyBOb3RlOiB0aGlzIHdpbGwgdHJpZ2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