aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2019-03-22 14:38:06 +0100
committerMichael Albinus2019-03-22 14:38:06 +0100
commit3375d08299bbc1e224d19a871012cdbbf5d787ee (patch)
tree8b97fff7350b084dfda07955ed9c75791f7666da
parent4174409c53d85a0def138f92d3e71901380c907a (diff)
downloademacs-3375d08299bbc1e224d19a871012cdbbf5d787ee.tar.gz
emacs-3375d08299bbc1e224d19a871012cdbbf5d787ee.zip
Fix Bug#24394, Bug#34172
* lisp/subr.el (process-file-shell-command): Use `with-connection-local-variables'. Do not set "/bin/sh" for remote buffers, trust settings of `shell-file-name'. * lisp/net/tramp-adb.el (tramp-methods) <adb>: * lisp/net/tramp-smb.el (tramp-methods) <smb>: Remove `tramp-remote-shell' and `tramp-remote-shell-args'. * lisp/net/tramp-sh.el (tramp-sh-handle-file-notify-add-watch) (tramp-maybe-open-connection): Use proper read syntax for function names. * lisp/net/tramp.el (tramp-handle-shell-command): Do not use shell file names from `tramp-methods'. Respect `async-shell-command-buffer'. (Bug#24394, Bug#34172) Use `start-file-process-shell-command' and `process-file-shell-command'. * test/lisp/net/tramp-tests.el (tramp-test32-shell-command): Let it run partly for tramp-adb.
-rw-r--r--lisp/net/tramp-adb.el3
-rw-r--r--lisp/net/tramp-sh.el4
-rw-r--r--lisp/net/tramp-smb.el4
-rw-r--r--lisp/net/tramp.el72
-rw-r--r--lisp/subr.el10
-rw-r--r--test/lisp/net/tramp-tests.el16
6 files changed, 66 insertions, 43 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 632ad12667d..8eeaa8be415 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -78,9 +78,6 @@ It is used for TCP/IP devices."
78(tramp--with-startup 78(tramp--with-startup
79 (add-to-list 'tramp-methods 79 (add-to-list 'tramp-methods
80 `(,tramp-adb-method 80 `(,tramp-adb-method
81 ;; Used in `tramp-handle-shell-command'.
82 (tramp-remote-shell "/system/bin/sh")
83 (tramp-remote-shell-args ("-c"))
84 (tramp-tmpdir "/data/local/tmp") 81 (tramp-tmpdir "/data/local/tmp")
85 (tramp-default-port 5555))) 82 (tramp-default-port 5555)))
86 83
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index d9edcb14198..2b4399f8de7 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3619,7 +3619,7 @@ Fall back to normal file name handler if no Tramp handler exists."
3619 sequence `(,command "monitor" ,localname))) 3619 sequence `(,command "monitor" ,localname)))
3620 ;; "gvfs-monitor-dir". 3620 ;; "gvfs-monitor-dir".
3621 ((setq command (tramp-get-remote-gvfs-monitor-dir v)) 3621 ((setq command (tramp-get-remote-gvfs-monitor-dir v))
3622 (setq filter 'tramp-sh-gvfs-monitor-dir-process-filter 3622 (setq filter #'tramp-sh-gvfs-monitor-dir-process-filter
3623 events 3623 events
3624 (cond 3624 (cond
3625 ((and (memq 'change flags) (memq 'attribute-change flags)) 3625 ((and (memq 'change flags) (memq 'attribute-change flags))
@@ -4886,7 +4886,7 @@ connection if a previous connection has died for some reason."
4886 (list tramp-encoding-shell)))))) 4886 (list tramp-encoding-shell))))))
4887 4887
4888 ;; Set sentinel and query flag. Initialize variables. 4888 ;; Set sentinel and query flag. Initialize variables.
4889 (set-process-sentinel p 'tramp-process-sentinel) 4889 (set-process-sentinel p #'tramp-process-sentinel)
4890 (process-put p 'vector vec) 4890 (process-put p 'vector vec)
4891 (process-put p 'adjust-window-size-function #'ignore) 4891 (process-put p 'adjust-window-size-function #'ignore)
4892 (set-process-query-on-exit-flag p nil) 4892 (set-process-query-on-exit-flag p nil)
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index e6e2485ea0f..66476305c2b 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -41,10 +41,6 @@
41 (tramp--with-startup 41 (tramp--with-startup
42 (add-to-list 'tramp-methods 42 (add-to-list 'tramp-methods
43 `(,tramp-smb-method 43 `(,tramp-smb-method
44 ;; We define an empty command, because
45 ;; `tramp-smb-call-winexe' opens already the powershell.
46 ;; Used in `tramp-handle-shell-command'.
47 (tramp-remote-shell "")
48 ;; This is just a guess. We don't know whether the share "C$" 44 ;; This is just a guess. We don't know whether the share "C$"
49 ;; is available for public use, and whether the user has write 45 ;; is available for public use, and whether the user has write
50 ;; access. 46 ;; access.
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 97ec5e174b4..48c363a873a 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3569,17 +3569,7 @@ support symbolic links."
3569 (command &optional output-buffer error-buffer) 3569 (command &optional output-buffer error-buffer)
3570 "Like `shell-command' for Tramp files." 3570 "Like `shell-command' for Tramp files."
3571 (let* ((asynchronous (string-match-p "[ \t]*&[ \t]*\\'" command)) 3571 (let* ((asynchronous (string-match-p "[ \t]*&[ \t]*\\'" command))
3572 ;; We cannot use `shell-file-name' and `shell-command-switch', 3572 (command (substring command 0 asynchronous))
3573 ;; they are variables of the local host.
3574 (args (append
3575 (cons
3576 (tramp-get-method-parameter
3577 (tramp-dissect-file-name default-directory)
3578 'tramp-remote-shell)
3579 (tramp-get-method-parameter
3580 (tramp-dissect-file-name default-directory)
3581 'tramp-remote-shell-args))
3582 (list (substring command 0 asynchronous))))
3583 current-buffer-p 3573 current-buffer-p
3584 (output-buffer 3574 (output-buffer
3585 (cond 3575 (cond
@@ -3596,19 +3586,48 @@ support symbolic links."
3596 (cond 3586 (cond
3597 ((bufferp error-buffer) error-buffer) 3587 ((bufferp error-buffer) error-buffer)
3598 ((stringp error-buffer) (get-buffer-create error-buffer)))) 3588 ((stringp error-buffer) (get-buffer-create error-buffer))))
3599 (buffer 3589 (bname (buffer-name output-buffer))
3600 (if (and (not asynchronous) error-buffer) 3590 (p (get-buffer-process output-buffer))
3601 (with-parsed-tramp-file-name default-directory nil 3591 buffer)
3602 (list output-buffer (tramp-make-tramp-temp-file v))) 3592
3603 output-buffer)) 3593 ;; The following code is taken from `shell-command', slightly
3604 (p (get-buffer-process output-buffer))) 3594 ;; adapted. Shouldn't it be factored out?
3605
3606 ;; Check whether there is another process running. Tramp does not
3607 ;; support 2 (asynchronous) processes in parallel.
3608 (when p 3595 (when p
3609 (if (yes-or-no-p "A command is running. Kill it? ") 3596 (cond
3610 (ignore-errors (kill-process p)) 3597 ((eq async-shell-command-buffer 'confirm-kill-process)
3611 (tramp-user-error p "Shell command in progress"))) 3598 ;; If will kill a process, query first.
3599 (if (yes-or-no-p
3600 "A command is running in the default buffer. Kill it? ")
3601 (kill-process p)
3602 (tramp-user-error p "Shell command in progress")))
3603 ((eq async-shell-command-buffer 'confirm-new-buffer)
3604 ;; If will create a new buffer, query first.
3605 (if (yes-or-no-p
3606 "A command is running in the default buffer. Use a new buffer? ")
3607 (setq output-buffer (generate-new-buffer bname))
3608 (tramp-user-error p "Shell command in progress")))
3609 ((eq async-shell-command-buffer 'new-buffer)
3610 ;; It will create a new buffer.
3611 (setq output-buffer (generate-new-buffer bname)))
3612 ((eq async-shell-command-buffer 'confirm-rename-buffer)
3613 ;; If will rename the buffer, query first.
3614 (if (yes-or-no-p
3615 "A command is running in the default buffer. Rename it? ")
3616 (progn
3617 (with-current-buffer output-buffer
3618 (rename-uniquely))
3619 (setq output-buffer (get-buffer-create bname)))
3620 (tramp-user-error p "Shell command in progress")))
3621 ((eq async-shell-command-buffer 'rename-buffer)
3622 ;; It will rename the buffer.
3623 (with-current-buffer output-buffer
3624 (rename-uniquely))
3625 (setq output-buffer (get-buffer-create bname)))))
3626
3627 (setq buffer (if (and (not asynchronous) error-buffer)
3628 (with-parsed-tramp-file-name default-directory nil
3629 (list output-buffer (tramp-make-tramp-temp-file v)))
3630 output-buffer))
3612 3631
3613 (if current-buffer-p 3632 (if current-buffer-p
3614 (progn 3633 (progn
@@ -3621,18 +3640,19 @@ support symbolic links."
3621 (if (and (not current-buffer-p) (integerp asynchronous)) 3640 (if (and (not current-buffer-p) (integerp asynchronous))
3622 (prog1 3641 (prog1
3623 ;; Run the process. 3642 ;; Run the process.
3624 (setq p (apply #'start-file-process "*Async Shell*" buffer args)) 3643 (setq p (start-file-process-shell-command
3644 "*Async Shell*" buffer command))
3625 ;; Display output. 3645 ;; Display output.
3626 (with-current-buffer output-buffer 3646 (with-current-buffer output-buffer
3627 (display-buffer output-buffer '(nil (allow-no-window . t))) 3647 (display-buffer output-buffer '(nil (allow-no-window . t)))
3628 (setq mode-line-process '(":%s")) 3648 (setq mode-line-process '(":%s"))
3629 (shell-mode) 3649 (shell-mode)
3630 (set-process-sentinel p #'shell-command-sentinel) 3650 (set-process-sentinel p #'shell-command-sentinel)
3631 (set-process-filter p 'comint-output-filter))) 3651 (set-process-filter p #'comint-output-filter)))
3632 3652
3633 (prog1 3653 (prog1
3634 ;; Run the process. 3654 ;; Run the process.
3635 (apply #'process-file (car args) nil buffer nil (cdr args)) 3655 (process-file-shell-command command nil buffer nil)
3636 ;; Insert error messages if they were separated. 3656 ;; Insert error messages if they were separated.
3637 (when (listp buffer) 3657 (when (listp buffer)
3638 (with-current-buffer error-buffer 3658 (with-current-buffer error-buffer
diff --git a/lisp/subr.el b/lisp/subr.el
index f48ca545c9d..6dc53cd7201 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3233,11 +3233,11 @@ discouraged."
3233Similar to `call-process-shell-command', but calls `process-file'." 3233Similar to `call-process-shell-command', but calls `process-file'."
3234 (declare (advertised-calling-convention 3234 (declare (advertised-calling-convention
3235 (command &optional infile buffer display) "24.5")) 3235 (command &optional infile buffer display) "24.5"))
3236 (process-file 3236 ;; On remote hosts, the local `shell-file-name' might be useless.
3237 (if (file-remote-p default-directory) "/bin/sh" shell-file-name) 3237 (with-connection-local-variables
3238 infile buffer display 3238 (process-file
3239 (if (file-remote-p default-directory) "-c" shell-command-switch) 3239 shell-file-name infile buffer display shell-command-switch
3240 (mapconcat 'identity (cons command args) " "))) 3240 (mapconcat 'identity (cons command args) " "))))
3241 3241
3242(defun call-shell-region (start end command &optional delete buffer) 3242(defun call-shell-region (start end command &optional delete buffer)
3243 "Send text from START to END as input to an inferior shell running COMMAND. 3243 "Send text from START to END as input to an inferior shell running COMMAND.
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index bf7cdfafabe..34b676ee324 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -4065,7 +4065,10 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4065 "Check `shell-command'." 4065 "Check `shell-command'."
4066 :tags '(:expensive-test) 4066 :tags '(:expensive-test)
4067 (skip-unless (tramp--test-enabled)) 4067 (skip-unless (tramp--test-enabled))
4068 (skip-unless (tramp--test-sh-p)) 4068 ;; Prior Emacs 27, `shell-file-name' was hard coded as "/bin/sh" for
4069 ;; remote processes in Emacs. That doesn't work for tramp-adb.el.
4070 (skip-unless (or (and (tramp--test-adb-p) (tramp--test-emacs27-p))
4071 (tramp--test-sh-p)))
4069 4072
4070 (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) 4073 (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil)))
4071 (let ((tmp-name (tramp--test-make-temp-name nil quoted)) 4074 (let ((tmp-name (tramp--test-make-temp-name nil quoted))
@@ -4093,6 +4096,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4093 ;; Cleanup. 4096 ;; Cleanup.
4094 (ignore-errors (delete-file tmp-name))) 4097 (ignore-errors (delete-file tmp-name)))
4095 4098
4099 ;; tramp-adb.el is not fit yet for asynchronous processes.
4100 (unless (tramp--test-adb-p)
4096 (unwind-protect 4101 (unwind-protect
4097 (with-temp-buffer 4102 (with-temp-buffer
4098 (write-region "foo" nil tmp-name) 4103 (write-region "foo" nil tmp-name)
@@ -4119,8 +4124,10 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4119 (buffer-string)))) 4124 (buffer-string))))
4120 4125
4121 ;; Cleanup. 4126 ;; Cleanup.
4122 (ignore-errors (delete-file tmp-name))) 4127 (ignore-errors (delete-file tmp-name))))
4123 4128
4129 ;; tramp-adb.el is not fit yet for asynchronous processes.
4130 (unless (tramp--test-adb-p)
4124 (unwind-protect 4131 (unwind-protect
4125 (with-temp-buffer 4132 (with-temp-buffer
4126 (write-region "foo" nil tmp-name) 4133 (write-region "foo" nil tmp-name)
@@ -4148,7 +4155,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4148 (buffer-string)))) 4155 (buffer-string))))
4149 4156
4150 ;; Cleanup. 4157 ;; Cleanup.
4151 (ignore-errors (delete-file tmp-name)))))) 4158 (ignore-errors (delete-file tmp-name)))))))
4152 4159
4153(defun tramp--test-shell-command-to-string-asynchronously (command) 4160(defun tramp--test-shell-command-to-string-asynchronously (command)
4154 "Like `shell-command-to-string', but for asynchronous processes." 4161 "Like `shell-command-to-string', but for asynchronous processes."
@@ -5705,6 +5712,9 @@ Since it unloads Tramp, it shall be the last test to run."
5705;; do not work properly for `nextcloud'. 5712;; do not work properly for `nextcloud'.
5706;; * Fix `tramp-test29-start-file-process' and 5713;; * Fix `tramp-test29-start-file-process' and
5707;; `tramp-test30-make-process' on MS Windows (`process-send-eof'?). 5714;; `tramp-test30-make-process' on MS Windows (`process-send-eof'?).
5715;; * Fix `tramp-test29-start-file-process',
5716;; `tramp-test30-make-process' and `tramp-test32-shell-command' for
5717;; `adb' (see comment in `tramp-adb-send-command').
5708;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'. 5718;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'.
5709 5719
5710(provide 'tramp-tests) 5720(provide 'tramp-tests)