From: Michael Albinus Date: Wed, 13 May 2020 12:11:18 +0000 (+0200) Subject: Fix some oddities, uncovered by Tramp tests X-Git-Tag: emacs-28.0.90~7366 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f8a9edce7339273f9c56d27cc6999a22907638e7;p=emacs.git Fix some oddities, uncovered by Tramp tests * lisp/net/tramp-gvfs.el (tramp-gvfs-enabled): Prevent crash for older Emacsen. * lisp/net/tramp.el (tramp-process-running-p): Simplify. * test/lisp/net/tramp-tests.el (tramp-test28-process-file): Adapt test. (tramp-test33-environment-variables): Unset "INSIDE_EMACS" initially. --- diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index f19e510eb67..704d65cd55e 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -125,7 +125,10 @@ (autoload 'zeroconf-init "zeroconf") (tramp-compat-funcall 'dbus-get-unique-name :system) (tramp-compat-funcall 'dbus-get-unique-name :session) - (or (tramp-process-running-p "gvfs-fuse-daemon") + (or ;; Until Emacs 25, `process-attributes' could crash Emacs + ;; for some processes. Better we don't check. + (<= emacs-major-version 25) + (tramp-process-running-p "gvfs-fuse-daemon") (tramp-process-running-p "gvfsd-fuse")))) "Non-nil when GVFS is available.") diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index c8fdc5d7285..70fb46bb4cb 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3783,7 +3783,8 @@ support symbolic links." (defun tramp-handle-start-file-process (name buffer program &rest args) "Like `start-file-process' for Tramp files. BUFFER might be a list, in this case STDERR is separated." - ;; `make-process' knows the `:file-handler' argument since Emacs 27.1 only. + ;; `make-process' knows the `:file-handler' argument since Emacs + ;; 27.1 only. Therefore, we invoke it via `tramp-file-name-handler'. (tramp-file-name-handler 'make-process :name name @@ -4857,13 +4858,13 @@ verbosity of 6." "Return t if system process PROCESS-NAME is running for `user-login-name'." (when (stringp process-name) (catch 'result - (dolist (pid (tramp-compat-funcall 'list-system-processes)) - (let ((attributes (process-attributes pid))) + (dolist (pid (list-system-processes)) + (when-let ((attributes (process-attributes pid)) + (comm (cdr (assoc 'comm attributes)))) (and (string-equal (cdr (assoc 'user attributes)) (user-login-name)) - (when-let ((comm (cdr (assoc 'comm attributes)))) - ;; The returned command name could be truncated to 15 - ;; characters. Therefore, we cannot check for `string-equal'. - (string-prefix-p comm process-name)) + ;; The returned command name could be truncated to 15 + ;; characters. Therefore, we cannot check for `string-equal'. + (string-prefix-p comm process-name) (throw 'result t))))))) (defun tramp-read-passwd (proc &optional prompt) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 8c3cb8e2e8f..de85f83982c 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4208,10 +4208,19 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (should (zerop (process-file "true"))) (should-not (zerop (process-file "false"))) (should-not (zerop (process-file "binary-does-not-exist"))) - (should (= (if (getenv "EMACS_HYDRA_CI") 127 42) - (process-file "sh" nil nil nil "-c" "exit 42"))) + (should + (= 42 + (process-file + (if (tramp--test-adb-p) "/system/bin/sh" "/bin/sh") + nil nil nil "-c" "exit 42"))) ;; Return string in case the process is interrupted. - (should (stringp (process-file "sh" nil nil nil "-c" "kill -2 $$"))) + (should + (string-equal + "Signal 2" + (process-file + (if (tramp--test-adb-p) "/system/bin/sh" "/bin/sh") + nil nil nil "-c" "kill -2 $$"))) + (with-temp-buffer (write-region "foo" nil tmp-name) (should (file-exists-p tmp-name)) @@ -4874,6 +4883,7 @@ INPUT, if non-nil, is a string sent to the process." kill-buffer-query-functions) ;; Check INSIDE_EMACS. + (setenv "INSIDE_EMACS") (should (string-equal (format "%s,tramp:%s" emacs-version tramp-version)