From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#47861: Starting `jsonrpc-process-connection' over Tramp fails if the process writes to stderr Date: Sat, 15 May 2021 19:32:59 +0200 Message-ID: <87mtsvgawk.fsf@gmx.de> References: <87y2cyaiwh.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29348"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 47861@debbugs.gnu.org To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 15 19:34:28 2021 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 1lhyBI-0007Qc-6f for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 15 May 2021 19:34:28 +0200 Original-Received: from localhost ([::1]:54156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhyBH-0006Iy-8a for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 15 May 2021 13:34:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhyAs-0005NW-4b for bug-gnu-emacs@gnu.org; Sat, 15 May 2021 13:34:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lhyAr-0003U5-TM for bug-gnu-emacs@gnu.org; Sat, 15 May 2021 13:34:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lhyAr-0006d0-Oc for bug-gnu-emacs@gnu.org; Sat, 15 May 2021 13:34:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 15 May 2021 17:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47861 X-GNU-PR-Package: emacs Original-Received: via spool by 47861-submit@debbugs.gnu.org id=B47861.162109999025420 (code B ref 47861); Sat, 15 May 2021 17:34:01 +0000 Original-Received: (at 47861) by debbugs.gnu.org; 15 May 2021 17:33:10 +0000 Original-Received: from localhost ([127.0.0.1]:49174 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhyA2-0006bw-7P for submit@debbugs.gnu.org; Sat, 15 May 2021 13:33:10 -0400 Original-Received: from mout.gmx.net ([212.227.15.18]:58779) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhy9z-0006bj-SC for 47861@debbugs.gnu.org; Sat, 15 May 2021 13:33:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1621099981; bh=7I47ImtRR7qGBj18qcJabHeb+js7GzvJqQTBAdVcCxg=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=GaGPyDoawzFu/k8UuH3/mevrpHuOHSISqOhyUUDsrxqmG1dAsE9lC6XEuiPqsrHfZ uSRHLVfEjCO/EGc1NhCaw3CuhH433SjmBlj47XYuX/BL33OSXsTB0Fxg3Np+Ep/X70 kBieVTud7Asw+hqo9lTUGOdXnvelEC832E6JGoZg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([212.91.243.135]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTAFh-1lv0Al39p9-00UeHo; Sat, 15 May 2021 19:33:00 +0200 In-Reply-To: <87y2cyaiwh.fsf@gmx.de> (Michael Albinus's message of "Sat, 01 May 2021 11:43:42 +0200") X-Provags-ID: V03:K1:RBM8ZXa+LsYfMz6mbg7o2xdC/xYd/LZj5/Z3NdHT+oMhJhfJr5s KZb/cZRT8dHnzIT2WUGXtEwnmRhYAWQNXP0+me9czS1MqpK0Y+Y9AlmUO6fRlSkYcGiaAYS JgmicY2BK0c1nYXH1UNWHsirKijyde0vzoriCjV/68D41KEFgFymleP/QGtsyZW8KVB1TuA nNehzsMdvYI1l4WMG5J/w== X-UI-Out-Filterresults: notjunk:1;V03:K0:/T2lUxMGv+M=:KLNc8O1JutIUN5tBYidPGI ujxyyPDPTm2zCxJNNVyQe133vd182eARMSfHx3ZeVXe3JY32aiew+jGIaaBQ9aCo/cgZ2OthJ ev88s01yf+1f2gXWoSVvOEAM+p5Sj3cNrRj2C4hUdWPF1PkrJxWhlGWcIWmUwohtP3IcIM2mZ Re/DcY/SoYdyzPlFWFOPMl4v4u1anchcYu5ozfMpO/PhZLA/1dzipkF9RT+4/V7SBKZ6nSFHQ 1NM1c8aIjGlLmRFcPMLYlRLg77RvQf/Q/7Ess73vN5ft93jLGLd3jdxlXL7IQVoyWCSXJxXt1 cQMQPenYR7U5g6Lsthp61nMQ6vFnTZT9wY6ftMhQVjJLn7e/PmGUlMxIKy8AIEt0jhVWoBwHM uishMub2NcYlf3QGoNHui4T/Ki5JgXm413rKMLrACCMs9v3caV+bfBzK8zZjIjVf/yH+DFw/I fWwXQPaSb+rx75KwLEFADMEPMtRgNBis4aSB2OisfCxreWIDQF02LLA16bw92dtLCep0SUEY1 RLzAuW85/tp2TTrlbW8AJOQTE94zExu7uncCeSWqzWO765KkEBb72DiYgy2GYHlvoirKcVZus 6lhXlTlNBult9NWI4U+fi06R8ywDwozOk6+3ShNybJFFeDfwnpN+BDhglMbiMr8Qx/PKwUsV/ k5rX7kZ4nwqCzSXHYMOOCMJ/DhYfgWavaJ3leYewBeZTK5WxLiAysCiTnF4kwRUWaaVbiDGka mwlgqUnI0kbL3cQDJrEZjbw1xNqNC6s7x5h8chaJ99to5UV3i0GX74Xg8Sidjy7UQmrwCn7u 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:206614 Archived-At: --=-=-= Content-Type: text/plain Michael Albinus writes: Hi Jim, > However, handling stderr buffers in Tramp's make-process is still a > mess. So I've started to reimplement this, using a named pipe on the > remote machine. make-pipe-process, the natural choice, does not work for > remote processes. I've finished a first shot on this, see the appended patch. Would you mind to test this in your environment, for example with eglot? Thanks, and best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Transfer-Encoding: quoted-printable diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el index 60090d31..22d31f82 100644 =2D-- a/lisp/tramp-sh.el +++ b/lisp/tramp-sh.el @@ -2723,13 +2723,12 @@ the result will be a local, non-Tramp, file name." ;; We use BUFFER also as connection buffer during setup. Because of ;; this, its original contents must be saved, and restored once ;; connection has been setup. -;; The complete STDERR buffer is available only when the process has -;; terminated. (defun tramp-sh-handle-make-process (&rest args) "Like `make-process' for Tramp files. -STDERR can also be a file name. If method parameter `tramp-direct-async' -and connection property \"direct-async-process\" are non-nil, an -alternative implementation will be used." +STDERR can also be a remote file name. If method parameter +`tramp-direct-async' and connection property +\"direct-async-process\" are non-nil, an alternative +implementation will be used." (if (tramp-direct-async-process-p args) (apply #'tramp-handle-make-process args) (when args @@ -2763,7 +2762,7 @@ alternative implementation will be used." (signal 'wrong-type-argument (list #'functionp sentinel))) (unless (or (null stderr) (bufferp stderr) (stringp stderr)) (signal 'wrong-type-argument (list #'bufferp stderr))) - (when (and (stringp stderr) (tramp-tramp-file-p stderr) + (when (and (stringp stderr) (not (tramp-equal-remote default-directory stderr))) (signal 'file-error (list "Wrong stderr" stderr))) @@ -2775,9 +2774,9 @@ alternative implementation will be used." ;; STDERR can also be a file name. (tmpstderr (and stderr - (if (and (stringp stderr) (tramp-tramp-file-p stderr)) - (tramp-unquote-file-local-name stderr) - (tramp-make-tramp-temp-file v)))) + (tramp-unquote-file-local-name + (if (stringp stderr) + stderr (tramp-make-tramp-temp-name v))))) (remote-tmpstderr (and tmpstderr (tramp-make-tramp-file-name v tmpstderr))) (program (car command)) @@ -2786,7 +2785,8 @@ alternative implementation will be used." ;; "-c", it might be that the arguments exceed the ;; command line length. Therefore, we modify the ;; command. - (heredoc (and (stringp program) + (heredoc (and (not (bufferp stderr)) + (stringp program) (string-match-p "sh$" program) (=3D (length args) 2) (string-equal "-c" (car args)) @@ -2850,6 +2850,23 @@ alternative implementation will be used." tramp-current-connection p) + ;; Handle error buffer. + (when (bufferp stderr) + (with-current-buffer stderr + (setq buffer-read-only nil)) + ;; Create named pipe. + (tramp-send-command v (format "mknod %s p" tmpstderr)) + ;; Create stderr process. + (make-process + :name (buffer-name stderr) + :buffer stderr + :command `("cat" ,tmpstderr) + :coding coding + :noquery t + :filter nil + :sentinel #'ignore + :file-handler t)) + (while (get-process name1) ;; NAME must be unique as process name. (setq i (1+ i) @@ -2912,38 +2929,16 @@ alternative implementation will be used." (ignore-errors (set-process-query-on-exit-flag p (null noquery)) (set-marker (process-mark p) (point))) - ;; We must flush them here already; otherwise - ;; `rename-file', `delete-file' or - ;; `insert-file-contents' will fail. - (tramp-flush-connection-property v "process-name") - (tramp-flush-connection-property v "process-buffer") - ;; Copy tmpstderr file. - (when (and (stringp stderr) - (not (tramp-tramp-file-p stderr))) - (add-function - :after (process-sentinel p) - (lambda (_proc _msg) - (rename-file remote-tmpstderr stderr)))) - ;; Provide error buffer. This shows only - ;; initial error messages; messages arriving - ;; later on will be inserted when the process - ;; is deleted. The temporary file will exist - ;; until the process is deleted. + ;; Kill stderr process and named pipe. (when (bufferp stderr) - (with-current-buffer stderr - ;; There's a mysterious error, see - ;; . - (ignore-errors - (insert-file-contents-literally remote-tmpstderr))) - ;; Delete tmpstderr file. (add-function :after (process-sentinel p) (lambda (_proc _msg) - (when (file-exists-p remote-tmpstderr) - (with-current-buffer stderr - (ignore-errors - (insert-file-contents-literally - remote-tmpstderr nil nil nil 'replace))) + (ignore-errors + (while (accept-process-output + (get-buffer-process stderr) 0 nil t)) + (delete-process (get-buffer-process stderr))) + (ignore-errors (delete-file remote-tmpstderr))))) ;; Return process. p))) @@ -4834,10 +4829,12 @@ connection if a previous connection has died for s= ome reason." (with-tramp-progress-reporter vec 3 (if (zerop (length (tramp-file-name-user vec))) - (format "Opening connection for %s using %s" + (format "Opening connection %s for %s using %s" + process-name (tramp-file-name-host vec) (tramp-file-name-method vec)) - (format "Opening connection for %s@%s using %s" + (format "Opening connection %s for %s@%s using %s" + process-name (tramp-file-name-user vec) (tramp-file-name-host vec) (tramp-file-name-method vec))) @@ -5937,8 +5934,6 @@ function cell is returned to be applied on a buffer.= " ;; session could be reused after a connection loss. Use dtach, or ;; screen, or tmux, or mosh. ;; -;; * Implement `:stderr' of `make-process' as pipe process. - ;; * One interesting solution (with other applications as well) would ;; be to stipulate, as a directory or connection-local variable, an ;; additional rc file on the remote machine that is sourced every --=-=-=--