From 17f0900d7bd783375e07f642cf8740c3e1dbaa8f Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Tue, 12 Apr 2022 09:41:11 +0200 Subject: [PATCH] Adapt macOS defaults in Tramp's process-attributes implementation * doc/misc/tramp.texi (Remote processes): Mention tramp-connection-local-darwin-ps-* constants. * lisp/net/tramp-integration.el (tramp-connection-local-darwin-ps-variables): Fix docstring. (top): Simplify setting local profiles. * test/lisp/net/tramp-tests.el (tramp-test31-list-system-processes) (tramp-test31-process-attributes): New tests. --- doc/misc/tramp.texi | 15 ++++++------ lisp/net/tramp-integration.el | 35 +++++++++++---------------- test/lisp/net/tramp-tests.el | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 29 deletions(-) diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index e4a586f8176..3cc312d2f5e 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -4097,6 +4097,8 @@ The corresponding @code{tramp-process-attributes-ps-format} has the value @vindex tramp-connection-local-bsd-ps-variables @vindex tramp-connection-local-busybox-ps-profile @vindex tramp-connection-local-busybox-ps-variables +@vindex tramp-connection-local-darwin-ps-profile +@vindex tramp-connection-local-darwin-ps-variables The default values for @code{tramp-process-attributes-ps-args} and @code{tramp-process-attributes-ps-format} can be overwritten by connection-local variables. @@ -4107,14 +4109,11 @@ This is already done by @value{tramp} for the @option{adb} method, see @code{tramp-adb-connection-local-default-ps-profile} and @code{tramp-adb-connection-local-default-ps-variables}. -There are two further predefined sets of connection-local variables -for remote BSD systems, and for a remote @command{ps} command -implemented with @command{busybox}. These are called -@code{tramp-connection-local-bsd-ps-profile}, -@code{tramp-connection-local-bsd-ps-variables}, -@code{tramp-connection-local-busybox-ps-profile}, and -@code{tramp-connection-local-busybox-ps-variables}. Use them -like +There are three further predefined sets of connection-local variables +for remote BSD systems, for remote macOS systems, and for a remote +@command{ps} command implemented with @command{busybox}. These are +called @code{tramp-connection-local-*-ps-profile} and +@code{tramp-connection-local-*-ps-variables}. Use them like @lisp @group diff --git a/lisp/net/tramp-integration.el b/lisp/net/tramp-integration.el index 901826bfc18..b7f82770c40 100644 --- a/lisp/net/tramp-integration.el +++ b/lisp/net/tramp-integration.el @@ -430,8 +430,7 @@ See `tramp-process-attributes-ps-format'.") 'tramp-connection-local-busybox-ps-profile tramp-connection-local-busybox-ps-variables) - -;; Darwin (macOS) +;; Darwin (macOS). (defconst tramp-darwin-process-attributes-ps-args `("-acxww" "-o" @@ -498,31 +497,25 @@ See `tramp-process-attributes-ps-format'.") . ,tramp-darwin-process-attributes-ps-args) (tramp-process-attributes-ps-format . ,tramp-darwin-process-attributes-ps-format)) - "Default connection-local ps variables for remote Darwin -connections.") + "Default connection-local ps variables for remote Darwin connections.") (connection-local-set-profile-variables 'tramp-connection-local-darwin-ps-profile tramp-connection-local-darwin-ps-variables) +;; Preset default "ps" profile for local hosts, based on system type. - -;; Preset default "ps" profile for the case of local sudo, based on -;; system type. - -(let ((local-sudo-profile - (cond ((eq system-type 'darwin) - 'tramp-connection-local-darwin-ps-profile) - ;; ...add other system types here - ))) - (when local-sudo-profile - (connection-local-set-profiles - `(:application tramp :protocol "sudo" :user "root" :machine ,(system-name)) - local-sudo-profile) - (connection-local-set-profiles - '(:application tramp :protocol "sudo" :user "root" :machine "localhost") - local-sudo-profile))) - +(when-let ((local-profile + (cond ((eq system-type 'darwin) + 'tramp-connection-local-darwin-ps-profile) + ;; ... Add other system types here. + ))) + (connection-local-set-profiles + `(:application tramp :machine ,(system-name)) + local-profile) + (connection-local-set-profiles + '(:application tramp :machine "localhost") + local-profile)) (add-hook 'tramp-unload-hook (lambda () (unload-feature 'tramp-integration 'force))) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index c3b3f21d528..e9ea758956a 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -5090,6 +5090,51 @@ If UNSTABLE is non-nil, the test is tagged as `:unstable'." (ignore-errors (kill-process proc)) (ignore-errors (delete-process proc)))))) +(ert-deftest tramp-test31-list-system-processes () + "Check `list-system-processes'." + :tags '(:expensive-test) + (skip-unless (tramp--test-enabled)) + (skip-unless (tramp--test-supports-processes-p)) + ;; `list-system-processes' is supported since Emacs 29.1. + (skip-unless (tramp--test-emacs29-p)) + + (let ((default-directory tramp-test-temporary-file-directory)) + (skip-unless (consp (list-system-processes))) + (should (not (equal (list-system-processes) + (let ((default-directory temporary-file-directory)) + (list-system-processes))))))) + +(ert-deftest tramp-test31-process-attributes () + "Check `process-attributes'." + :tags '(:expensive-test :tramp-asynchronous-processes) + (skip-unless (tramp--test-enabled)) + (skip-unless (tramp--test-supports-processes-p)) + ;; `process-attributes' is supported since Emacs 29.1. + (skip-unless (tramp--test-emacs29-p)) + + ;; We must use `file-truename' for the temporary directory, in + ;; order to establish the connection prior running an asynchronous + ;; process. + (let ((default-directory (file-truename tramp-test-temporary-file-directory)) + (delete-exited-processes t) + kill-buffer-query-functions command proc) + (skip-unless (consp (list-system-processes))) + + (unwind-protect + (progn + (setq command '("sleep" "100") + proc (apply #'start-file-process "test" nil command)) + (while (accept-process-output proc 0)) + (when-let ((pid (process-get proc 'remote-pid)) + (attributes (process-attributes pid))) + ;; (tramp--test-message "%s" attributes) + (should (equal (cdr (assq 'comm attributes)) (car command))) + (should (equal (cdr (assq 'args attributes)) + (mapconcat #'identity command " "))))) + + ;; Cleanup. + (ignore-errors (delete-process proc))))) + (defun tramp--test-async-shell-command (command output-buffer &optional error-buffer input) "Like `async-shell-command', reading the output. -- 2.39.5