diff options
| author | Jim Porter | 2022-07-19 21:36:54 -0700 |
|---|---|---|
| committer | Jim Porter | 2022-08-05 17:58:54 -0700 |
| commit | 4e59830bc0ab17cdbd85748b133c97837bed99e3 (patch) | |
| tree | 1fc29e2e33f71d60915c2f15e52a97dd416773ed | |
| parent | d7b89ea4077d4fe677ba0577245328819ee79cdc (diff) | |
| download | emacs-4e59830bc0ab17cdbd85748b133c97837bed99e3.tar.gz emacs-4e59830bc0ab17cdbd85748b133c97837bed99e3.zip | |
Add STREAM argument to 'process-tty-name'
* src/process.c (process-tty-name): Add STREAM argument.
* lisp/eshell/esh-io.el (eshell-close-target): Only call
'process-send-eof' once if the process's stdin is a pipe.
* test/src/process-tests.el (make-process/test-connection-type): Check
behavior of 'process-tty-name'.
* doc/lispref/processes.texi (Process Information): Document the new
argument.
* etc/NEWS: Announce this change.
| -rw-r--r-- | doc/lispref/processes.texi | 21 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/eshell/esh-io.el | 27 | ||||
| -rw-r--r-- | src/process.c | 25 | ||||
| -rw-r--r-- | test/src/process-tests.el | 3 |
5 files changed, 58 insertions, 23 deletions
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index e253ab9de03..382053ab24a 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi | |||
| @@ -1243,15 +1243,24 @@ that are already closed, the value is either 0 or 256, depending on | |||
| 1243 | whether the connection was closed normally or abnormally. | 1243 | whether the connection was closed normally or abnormally. |
| 1244 | @end defun | 1244 | @end defun |
| 1245 | 1245 | ||
| 1246 | @defun process-tty-name process | 1246 | @defun process-tty-name process &optional stream |
| 1247 | This function returns the terminal name that @var{process} is using for | 1247 | This function returns the terminal name that @var{process} is using for |
| 1248 | its communication with Emacs---or @code{nil} if it is using pipes | 1248 | its communication with Emacs---or @code{nil} if it is using pipes |
| 1249 | instead of a pty (see @code{process-connection-type} in | 1249 | instead of a pty (see @code{process-connection-type} in |
| 1250 | @ref{Asynchronous Processes}). If @var{process} represents a program | 1250 | @ref{Asynchronous Processes}). By default, this function returns the |
| 1251 | running on a remote host, the terminal name used by that program on | 1251 | terminal name if any of @var{process}'s standard streams use a |
| 1252 | the remote host is provided as process property @code{remote-tty}. If | 1252 | terminal. If @var{stream} is one of @code{stdin}, @code{stdout}, or |
| 1253 | @var{process} represents a network, serial, or pipe connection, the | 1253 | @code{stderr}, this function returns the terminal name (or @code{nil}, |
| 1254 | value is @code{nil}. | 1254 | as above) that @var{process} uses for that stream specifically. You |
| 1255 | can use this to determine whether a particular stream uses a pipe or a | ||
| 1256 | pty. | ||
| 1257 | |||
| 1258 | If @var{process} represents a program running on a remote host, this | ||
| 1259 | function returns the @emph{local} terminal name that communicates with | ||
| 1260 | @var{process}; you can get the terminal name used by that program on | ||
| 1261 | the remote host with the process property @code{remote-tty}. If | ||
| 1262 | @var{process} represents a network, serial, or pipe connection, this | ||
| 1263 | function always returns @code{nil}. | ||
| 1255 | @end defun | 1264 | @end defun |
| 1256 | 1265 | ||
| 1257 | @defun process-coding-system process | 1266 | @defun process-coding-system process |
| @@ -3333,7 +3333,10 @@ invocation. Such shells are POSIX conformant by default. | |||
| 3333 | ** 'make-process' can set connection type independently for input and output. | 3333 | ** 'make-process' can set connection type independently for input and output. |
| 3334 | When calling 'make-process', communication via pty can be enabled | 3334 | When calling 'make-process', communication via pty can be enabled |
| 3335 | selectively for just input or output by passing a cons cell for | 3335 | selectively for just input or output by passing a cons cell for |
| 3336 | ':connection-type', e.g. '(pipe . pty)'. | 3336 | ':connection-type', e.g. '(pipe . pty)'. When examining a process |
| 3337 | later, you can determine whether a particular stream for a process | ||
| 3338 | uses a pty by passing one of 'stdin', 'stdout', or 'stderr' as the | ||
| 3339 | second argument to 'process-tty-name'. | ||
| 3337 | 3340 | ||
| 3338 | +++ | 3341 | +++ |
| 3339 | ** 'signal-process' now consults the list 'signal-process-functions'. | 3342 | ** 'signal-process' now consults the list 'signal-process-functions'. |
diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el index c035890ddf0..68e52a2c9c8 100644 --- a/lisp/eshell/esh-io.el +++ b/lisp/eshell/esh-io.el | |||
| @@ -276,18 +276,21 @@ STATUS should be non-nil on successful termination of the output." | |||
| 276 | ;; If we're redirecting to a process (via a pipe, or process | 276 | ;; If we're redirecting to a process (via a pipe, or process |
| 277 | ;; redirection), send it EOF so that it knows we're finished. | 277 | ;; redirection), send it EOF so that it knows we're finished. |
| 278 | ((eshell-processp target) | 278 | ((eshell-processp target) |
| 279 | ;; According to POSIX.1-2017, section 11.1.9, sending EOF causes | 279 | ;; According to POSIX.1-2017, section 11.1.9, when communicating |
| 280 | ;; all bytes waiting to be read to be sent to the process | 280 | ;; via terminal, sending EOF causes all bytes waiting to be read |
| 281 | ;; immediately. Thus, if there are any bytes waiting, we need to | 281 | ;; to be sent to the process immediately. Thus, if there are any |
| 282 | ;; send EOF twice: once to flush the buffer, and a second time to | 282 | ;; bytes waiting, we need to send EOF twice: once to flush the |
| 283 | ;; cause the next read() to return a size of 0, indicating | 283 | ;; buffer, and a second time to cause the next read() to return a |
| 284 | ;; end-of-file to the reading process. However, some platforms | 284 | ;; size of 0, indicating end-of-file to the reading process. |
| 285 | ;; (e.g. Solaris) actually require sending a *third* EOF. Since | 285 | ;; However, some platforms (e.g. Solaris) actually require sending |
| 286 | ;; sending extra EOFs while the process is running shouldn't break | 286 | ;; a *third* EOF. Since sending extra EOFs while the process is |
| 287 | ;; anything, we'll just send the maximum we'd ever need. See | 287 | ;; running are a no-op, we'll just send the maximum we'd ever |
| 288 | ;; bug#56025 for further details. | 288 | ;; need. See bug#56025 for further details. |
| 289 | (let ((i 0)) | 289 | (let ((i 0) |
| 290 | (while (and (<= (cl-incf i) 3) | 290 | ;; Only call `process-send-eof' once if communicating via a |
| 291 | ;; pipe (in truth, this just closes the pipe). | ||
| 292 | (max-attempts (if (process-tty-name target 'stdin) 3 1))) | ||
| 293 | (while (and (<= (cl-incf i) max-attempts) | ||
| 291 | (eq (process-status target) 'run)) | 294 | (eq (process-status target) 'run)) |
| 292 | (process-send-eof target)))) | 295 | (process-send-eof target)))) |
| 293 | 296 | ||
diff --git a/src/process.c b/src/process.c index 68dbd8b68bd..23479c06194 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -1243,14 +1243,31 @@ or t (process is stopped). */) | |||
| 1243 | return XPROCESS (process)->command; | 1243 | return XPROCESS (process)->command; |
| 1244 | } | 1244 | } |
| 1245 | 1245 | ||
| 1246 | DEFUN ("process-tty-name", Fprocess_tty_name, Sprocess_tty_name, 1, 1, 0, | 1246 | DEFUN ("process-tty-name", Fprocess_tty_name, Sprocess_tty_name, 1, 2, 0, |
| 1247 | doc: /* Return the name of the terminal PROCESS uses, or nil if none. | 1247 | doc: /* Return the name of the terminal PROCESS uses, or nil if none. |
| 1248 | This is the terminal that the process itself reads and writes on, | 1248 | This is the terminal that the process itself reads and writes on, |
| 1249 | not the name of the pty that Emacs uses to talk with that terminal. */) | 1249 | not the name of the pty that Emacs uses to talk with that terminal. |
| 1250 | (register Lisp_Object process) | 1250 | |
| 1251 | If STREAM is nil, return the terminal name if any of PROCESS's | ||
| 1252 | standard streams use a terminal for communication. If STREAM is one | ||
| 1253 | of `stdin', `stdout', or `stderr', return the name of the terminal | ||
| 1254 | PROCESS uses for that stream specifically, or nil if that stream | ||
| 1255 | communicates via a pipe. */) | ||
| 1256 | (register Lisp_Object process, Lisp_Object stream) | ||
| 1251 | { | 1257 | { |
| 1252 | CHECK_PROCESS (process); | 1258 | CHECK_PROCESS (process); |
| 1253 | return XPROCESS (process)->tty_name; | 1259 | register struct Lisp_Process *p = XPROCESS (process); |
| 1260 | |||
| 1261 | if (NILP (stream)) | ||
| 1262 | return p->tty_name; | ||
| 1263 | else if (EQ (stream, Qstdin)) | ||
| 1264 | return p->pty_in ? p->tty_name : Qnil; | ||
| 1265 | else if (EQ (stream, Qstdout)) | ||
| 1266 | return p->pty_out ? p->tty_name : Qnil; | ||
| 1267 | else if (EQ (stream, Qstderr)) | ||
| 1268 | return p->pty_out && NILP (p->stderrproc) ? p->tty_name : Qnil; | ||
| 1269 | else | ||
| 1270 | signal_error ("Unknown stream", stream); | ||
| 1254 | } | 1271 | } |
| 1255 | 1272 | ||
| 1256 | static void | 1273 | static void |
diff --git a/test/src/process-tests.el b/test/src/process-tests.el index b801563feb7..db8a5044783 100644 --- a/test/src/process-tests.el +++ b/test/src/process-tests.el | |||
| @@ -294,6 +294,9 @@ should be a TTY, respectively." | |||
| 294 | "if [ -t 2 ]; then echo stderr; fi")) | 294 | "if [ -t 2 ]; then echo stderr; fi")) |
| 295 | :buffer stdout-buffer | 295 | :buffer stdout-buffer |
| 296 | args))) | 296 | args))) |
| 297 | (should (eq (and (process-tty-name proc 'stdin) t) (nth 0 ttys))) | ||
| 298 | (should (eq (and (process-tty-name proc 'stdout) t) (nth 1 ttys))) | ||
| 299 | (should (eq (and (process-tty-name proc 'stderr) t) (nth 2 ttys))) | ||
| 297 | (process-test-wait-for-sentinel proc 0) | 300 | (process-test-wait-for-sentinel proc 0) |
| 298 | (should (equal (with-current-buffer stdout-buffer (buffer-string)) | 301 | (should (equal (with-current-buffer stdout-buffer (buffer-string)) |
| 299 | expected-output)))) | 302 | expected-output)))) |