]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve connection type `pipe' for remote processes
authorMichael Albinus <michael.albinus@gmx.de>
Thu, 12 Aug 2021 18:09:48 +0000 (20:09 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Thu, 12 Aug 2021 18:09:48 +0000 (20:09 +0200)
* doc/misc/tramp.texi (Remote processes): New subsection "Remote
process connection type".

* lisp/net/tramp-adb.el (tramp-adb-handle-make-process):
Use `tramp-process-connection-type' as default connection type.
Improve check for `:connection-type'.

* lisp/net/tramp-sh.el (tramp-sh-handle-make-process):
Use `tramp-process-connection-type' as default connection type.
Improve check for `:connection-type'.  Send "stty -icrnl" when
connection type is a pipe.

* lisp/net/tramp.el (tramp-process-connection-type): Allow all
possible values.
(tramp-handle-make-process): Use `tramp-process-connection-type'
as default connection type.  Improve check for `:connection-type'.

* test/lisp/net/tramp-tests.el (tramp-test30-make-process): Extend test.

doc/misc/tramp.texi
lisp/net/tramp-adb.el
lisp/net/tramp-sh.el
lisp/net/tramp.el
test/lisp/net/tramp-tests.el

index 38c20de62a28e445accf70cbd151309fee9fb89c..bd9bd998dfb38f43a96f4d84339a78487193e433 100644 (file)
@@ -3734,6 +3734,32 @@ To open @command{powershell} as a remote shell, use this:
 @end lisp
 
 
+@subsection Remote process connection type
+@vindex process-connection-type
+@cindex tramp-process-connection-type
+
+Asynchronous processes differ in the way, whether they use a pseudo
+tty, or not.  This is controlled by the variable
+@code{process-connection-type}, which can be @code{t} or @code{pty}
+(use a pseudo tty), or @code{nil} or @code{pipe} (don't use it).
+@value{tramp} is based on running shells on the remote host, which
+require a pseudo tty.  Therefore, it declares the variable
+@code{tramp-process-connection-type}, which carries this information
+for remote processes.  Per default, its value is @code{t}.  The name
+of the remote pseudo tty is returned by the function
+@code{process-tty-name}.
+
+If a remote process, started by @code{start-file-process}, shouldn't
+use a pseudo tty, this is emulated by let-binding this variable to
+@code{nil} or @code{pipe}.  There is still a pseudo tty for the
+started process, but some terminal properties are changed, like
+suppressing translation of carriage return characters into newline.
+
+The function @code{make-process} allows an explicit setting by the
+@code{:connection-type} keyword.  If this keyword is not used, the
+value of @code{tramp-process-connection-type} is applied instead.
+
+
 @anchor{Improving performance of asynchronous remote processes}
 @subsection Improving performance of asynchronous remote processes
 @cindex Asynchronous remote processes
index 2f84312f07752aa7263a2f8e34021389a8e35e53..c16e232c6d5c4abd22e4c4f90c41f022209536c2 100644 (file)
@@ -924,7 +924,10 @@ implementation will be used."
              (command (plist-get args :command))
              (coding (plist-get args :coding))
              (noquery (plist-get args :noquery))
-             (connection-type (plist-get args :connection-type))
+             (connection-type
+              (if (plist-member args :connection-type)
+                  (plist-get args :connection-type)
+                tramp-process-connection-type))
              (filter (plist-get args :filter))
              (sentinel (plist-get args :sentinel))
              (stderr (plist-get args :stderr)))
@@ -940,7 +943,7 @@ implementation will be used."
                           (memq (car coding) coding-system-list)
                           (memq (cdr coding) coding-system-list)))
            (signal 'wrong-type-argument (list #'symbolp coding)))
-         (unless (or (null connection-type) (memq connection-type '(pipe pty)))
+         (unless (memq connection-type '(nil pipe t pty))
            (signal 'wrong-type-argument (list #'symbolp connection-type)))
          (unless (or (null filter) (functionp filter))
            (signal 'wrong-type-argument (list #'functionp filter)))
index fad07d87c51352c2d04cc3ae64612fc5fb629dfc..f00434c1468318ca85086f6d47c749e3f8ba3b44 100644 (file)
@@ -2752,7 +2752,10 @@ implementation will be used."
              (command (plist-get args :command))
              (coding (plist-get args :coding))
              (noquery (plist-get args :noquery))
-             (connection-type (plist-get args :connection-type))
+             (connection-type
+              (if (plist-member args :connection-type)
+                  (plist-get args :connection-type)
+                tramp-process-connection-type))
              (filter (plist-get args :filter))
              (sentinel (plist-get args :sentinel))
              (stderr (plist-get args :stderr)))
@@ -2768,7 +2771,7 @@ implementation will be used."
                           (memq (car coding) coding-system-list)
                           (memq (cdr coding) coding-system-list)))
            (signal 'wrong-type-argument (list #'symbolp coding)))
-         (unless (or (null connection-type) (memq connection-type '(pipe pty)))
+         (unless (memq connection-type '(nil pipe t pty))
            (signal 'wrong-type-argument (list #'symbolp connection-type)))
          (unless (or (null filter) (functionp filter))
            (signal 'wrong-type-argument (list #'functionp filter)))
@@ -2916,6 +2919,9 @@ implementation will be used."
                            (setq p (tramp-get-connection-process v))
                            (process-put p 'remote-pid pid)
                            (tramp-set-connection-property p "remote-pid" pid))
+                         ;; Disable carriage return to newline translation.
+                         (when (memq connection-type '(nil pipe))
+                           (tramp-send-command v "stty -icrnl"))
                          ;; `tramp-maybe-open-connection' and
                          ;; `tramp-send-command-and-read' could have
                          ;; trashed the connection buffer.  Remove this.
index 6fc0ac8e1ef7f96d1c61cba3a0bb89d9f7fa72c9..83df05c24b7e1c960dfab49c25270712f6911dbe 100644 (file)
@@ -1264,14 +1264,14 @@ this variable to be set as well."
   :type '(choice (const nil) integer))
 
 ;; Logging in to a remote host normally requires obtaining a pty.  But
-;; Emacs on macOS has process-connection-type set to nil by default,
+;; Emacs on macOS has `process-connection-type' set to nil by default,
 ;; so on those systems Tramp doesn't obtain a pty.  Here, we allow
 ;; for an override of the system default.
 (defcustom tramp-process-connection-type t
   "Overrides `process-connection-type' for connections from Tramp.
 Tramp binds `process-connection-type' to the value given here before
 opening a connection to a remote host."
-  :type '(choice (const nil) (const t) (const pty)))
+  :type '(choice (const nil) (const t) (const pipe) (const pty)))
 
 (defcustom tramp-connection-timeout 60
   "Defines the max time to wait for establishing a connection (in seconds).
@@ -4093,7 +4093,10 @@ substitution.  SPEC-LIST is a list of char/value pairs used for
            (command (plist-get args :command))
            (coding (plist-get args :coding))
            (noquery (plist-get args :noquery))
-           (connection-type (plist-get args :connection-type))
+           (connection-type
+            (if (plist-member args :connection-type)
+                (plist-get args :connection-type)
+              tramp-process-connection-type))
            (filter (plist-get args :filter))
            (sentinel (plist-get args :sentinel))
            (stderr (plist-get args :stderr)))
@@ -4109,7 +4112,7 @@ substitution.  SPEC-LIST is a list of char/value pairs used for
                         (memq (car coding) coding-system-list)
                         (memq (cdr coding) coding-system-list)))
          (signal 'wrong-type-argument (list #'symbolp coding)))
-       (unless (or (null connection-type) (memq connection-type '(pipe pty)))
+       (unless (memq connection-type '(nil pipe t pty))
          (signal 'wrong-type-argument (list #'symbolp connection-type)))
        (unless (or (null filter) (functionp filter))
          (signal 'wrong-type-argument (list #'functionp filter)))
index 052c03029fd6025fa682cfaa8bd6318b31fa08ad..3008861f22b54b73503a28b9d7f1c1fa34675b8c 100644 (file)
@@ -4749,7 +4749,45 @@ If UNSTABLE is non-nil, the test is tagged as `:unstable'."
 
          ;; Cleanup.
          (ignore-errors (delete-process proc))
-         (ignore-errors (delete-file tmp-name)))))))
+         (ignore-errors (delete-file tmp-name))))
+
+      ;; Process connection type.
+      (when (and (tramp--test-sh-p)
+                ;; `executable-find' has changed the number of
+                ;; parameters in Emacs 27.1, so we use `apply' for
+                ;; older Emacsen.
+                (ignore-errors
+                  (with-no-warnings
+                    (apply #'executable-find '("hexdump" remote)))))
+       (dolist (connection-type '(nil pipe t pty))
+         (unwind-protect
+             (with-temp-buffer
+               (setq proc
+                     (with-no-warnings
+                       (make-process
+                        :name (format "test7-%s" connection-type)
+                        :buffer (current-buffer)
+                        :connection-type connection-type
+                        :command '("hexdump" "-v" "-e" "/1 \"%02X\n\"")
+                        :file-handler t)))
+               (should (processp proc))
+               (should (equal (process-status proc) 'run))
+               (process-send-string proc "foo\r\n")
+               (process-send-eof proc)
+               ;; Read output.
+               (with-timeout (10 (tramp--test-timeout-handler))
+                 (while (< (- (point-max) (point-min))
+                           (length "66\n6F\n6F\n0D\n0A\n"))
+                   (while (accept-process-output proc 0 nil t))))
+               (should
+                (string-match-p
+                 (if (memq connection-type '(nil pipe))
+                     "66\n6F\n6F\n0D\n0A\n"
+                   "66\n6F\n6F\n0A\n0A\n")
+                 (buffer-string))))
+
+           ;; Cleanup.
+           (ignore-errors (delete-process proc))))))))
 
 (tramp--test--deftest-direct-async-process tramp-test30-make-process
   "Check direct async `make-process'.")