all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Sending EOF to process as part of comint-simple-send
Date: Sat, 14 Jan 2023 21:27:56 -0800	[thread overview]
Message-ID: <1c1a3086-1c0a-e4c0-0bd6-6c48cd0efaa3@gmail.com> (raw)
In-Reply-To: <83v8l971id.fsf@gnu.org>

On 1/14/2023 4:18 AM, Eli Zaretskii wrote:
> In comint-simple-send, we have:
> 
>      (comint-send-string proc send-string))
>    (if (and comint-input-sender-no-newline
> 	   (not (string-equal string "")))
>        (process-send-eof)))
> 
> Thus, if we send sub-process input without a newline, we then send EOF
> to the sub-process, except when the string we send is empty.
> 
> I can only understand this logic if it assumes a Posix shell or other
> Posix process with which we communicate via a PTY.  Because in that
> case, we just send C-d to the process, and AFAIK that will not cause
> the sub-process to finish except when C-d is the only character we
> send.
[snip]
> So I think comint-simple-send should only send EOF if the
> communications with the process are via a PTY, at least if the
> sub-process is a real process (as opposed to a network or serial or
> pipe process).  Or maybe we should only refrain from sending EOF on
> MS-Windows?

I agree with this: I think we should only call 'process-send-eof' here 
when communicating via PTY. (To be precise, whenever the process's 
*stdin* is a PTY; as of Emacs 29, a process's stdin can be a PTY even if 
its stdout isn't, or vice versa. See commit d7b89ea407.)

I imagine you've looked into the relevant POSIX specs already, but just 
to explain my reasoning for why I agree... my reading of the POSIX 
spec[1] for EOF is that the code above is using it as a way to flush the 
I/O buffer for the PTY, which makes sense to me:

> EOF: Special character on input, which is recognized if the
> ICANON flag is set. When received, all the bytes waiting to be
> read are immediately passed to the process without waiting for a
> <newline>, and the EOF is discarded. Thus, if there are no bytes
> waiting (that is, the EOF occurred at the beginning of a line), a
> byte count of zero shall be returned from the read(),
> representing an end-of-file indication. If ICANON is set, the EOF
> character shall be discarded when processed.

However, that logic would only apply for PTYs, since a) this 
documentation is about the POSIX terminal interface, and b) as you said 
in your message, 'process-send-eof' doesn't actually send an EOF 
character when communicating via a pipe at all; it closes the file 
descriptor!

[1] 
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11_01_09



  reply	other threads:[~2023-01-15  5:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-14 12:18 Sending EOF to process as part of comint-simple-send Eli Zaretskii
2023-01-15  5:27 ` Jim Porter [this message]
2023-01-15  7:20   ` Eli Zaretskii
2023-01-15  8:40     ` Andreas Schwab
2023-01-15  9:08       ` Eli Zaretskii
2023-01-15 10:08         ` Andreas Schwab
2023-01-15 10:25           ` Eli Zaretskii
2023-01-15 10:32             ` Andreas Schwab
2023-01-15 10:57               ` Eli Zaretskii

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

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

  git send-email \
    --in-reply-to=1c1a3086-1c0a-e4c0-0bd6-6c48cd0efaa3@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.