From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#54062: 29.0.50; [PATCH] Eshell should inform processes when a pipe is broken Date: Sun, 20 Feb 2022 09:27:08 +0200 Message-ID: <83a6emxak3.fsf@gnu.org> References: <7da3e8b2-7400-dca6-6d92-0a60e3d9c215@gmail.com> <83mtinz222.fsf@gnu.org> <83ley6y5gx.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40227"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 54062@debbugs.gnu.org To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 20 08:28:24 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 1nLgdr-000ADM-Hf for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Feb 2022 08:28:23 +0100 Original-Received: from localhost ([::1]:51316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nLgdq-0006v2-At for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Feb 2022 02:28:22 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:60058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nLgdX-0006us-QD for bug-gnu-emacs@gnu.org; Sun, 20 Feb 2022 02:28:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37135) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nLgdW-0006Y7-Ff for bug-gnu-emacs@gnu.org; Sun, 20 Feb 2022 02:28:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nLgdW-0003oP-CS for bug-gnu-emacs@gnu.org; Sun, 20 Feb 2022 02:28:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Feb 2022 07:28:02 +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.164534203814602 (code B ref 54062); Sun, 20 Feb 2022 07:28:02 +0000 Original-Received: (at 54062) by debbugs.gnu.org; 20 Feb 2022 07:27:18 +0000 Original-Received: from localhost ([127.0.0.1]:59265 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nLgcn-0003nR-NP for submit@debbugs.gnu.org; Sun, 20 Feb 2022 02:27:18 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:53292) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nLgcl-0003nC-7U for 54062@debbugs.gnu.org; Sun, 20 Feb 2022 02:27:15 -0500 Original-Received: from [2001:470:142:3::e] (port=51736 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nLgcf-0006UR-Uv; Sun, 20 Feb 2022 02:27:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Y7nBsFUHd6thGk+I0R5ZJ4xbTDkWVdyd920Mac0BH1E=; b=E+aLTgLHwemz dMbGunegYkeBJKCxVSCYvzvWnHxKuWLEoeacTBl1kWDtVOUjbObhbws2M8FmoWlB/qNklzuwgeqef GsJmSswocHIGlKcxoLR8gTuOJaahm7OBr5UIT3drg/qejry+mqunleLTSF9NY+PKmtlxULjImsy6M QgBwF1dWyNjEcuwZTrV8mIscWUeUonG9tt3vX+RiFT7EBsxKokpNEURwsjrZUWRIXRVorBX+28tDH sZSCx9xwpvRF+22YsH3BDrTR390am7boPGMY5pl5d6Z536SujiSvsM95ccdK3stYidfcORXUCyKG1 AnjmJYKFy7VU7xn/7iU+8A==; Original-Received: from [87.69.77.57] (port=3862 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nLgcc-0005S4-Fn; Sun, 20 Feb 2022 02:27:09 -0500 In-Reply-To: (message from Jim Porter on Sat, 19 Feb 2022 13:18:16 -0800) 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:227213 Archived-At: > Cc: 54062@debbugs.gnu.org > From: Jim Porter > Date: Sat, 19 Feb 2022 13:18:16 -0800 > > > Many console programs catch SIGINT, though. > > > > Can't we terminate ("kill") the process instead? Or maybe deleting > > the process object is enough? > > That might work; it would definitely be better than `interrupt-process'. > On the other hand, I think it would be nice to handle this case by > breaking the pipe if possible, since that would be closer to how it > works in regular shells, as I understand it. I meant killing the process as fallback for when SIGPIPE is not supported. > >> 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. > > > > You mean, delete the process object? That's how we close our end of > > the pipe, no? > > Do you mean using `delete-process'? That works differently from how I'm > imagining things. From reading the code, `delete-process' sends SIGKILL > to the process group, but that means that a process that wants to do > something special in response to SIGPIPE (or EPIPE, or ERROR_BROKEN_PIPE > on Win32) wouldn't be able to, since that's not the signal/error it > receives. How else can you close the pipe without deleting the process? How can Emacs have a process whose I/O channels aren't ready to be used? I thought you were talking about a pipe process (make-pipe-process), in which case deleting it closes the pipe. But you seem to mean something else, so now I'm not sure I understand. > In my patch, `process-break-pipe' just closes the file descriptor for > the read end of the process's stdout pipe, but otherwise doesn't do > anything to the process. I don't think this is a good idea. A process isn't supposed to be in this state. > Then, when the process tries to write to stdout > again, the OS will report (via a signal and/or an error code) that the > pipe is broken. Since Win32's WriteFile[1] API returns ERROR_BROKEN_PIPE > in this case, that would let MS Windows programs detect and respond to > broken pipes in the usual way for that platform. We don't use WriteFile directly, and I wouldn't rely on EPIPE being in errno in this case without extensive testing. Anyway, the proposal to close the pipe of a live process object is problematic, see above. I hope we can come up with something simpler. We are talking about a niche feature here, so it is IMO better to find a simple solution for that.