aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2022-04-12 09:41:11 +0200
committerMichael Albinus2022-04-12 09:41:11 +0200
commit17f0900d7bd783375e07f642cf8740c3e1dbaa8f (patch)
treec9895f9fe46477e4f8cb8a97ba4bc97fa5bf1361
parente258e582768a6f974ab1da198e894408d9933cd1 (diff)
downloademacs-17f0900d7bd783375e07f642cf8740c3e1dbaa8f.tar.gz
emacs-17f0900d7bd783375e07f642cf8740c3e1dbaa8f.zip
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.
-rw-r--r--doc/misc/tramp.texi15
-rw-r--r--lisp/net/tramp-integration.el35
-rw-r--r--test/lisp/net/tramp-tests.el45
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
4097@vindex tramp-connection-local-bsd-ps-variables 4097@vindex tramp-connection-local-bsd-ps-variables
4098@vindex tramp-connection-local-busybox-ps-profile 4098@vindex tramp-connection-local-busybox-ps-profile
4099@vindex tramp-connection-local-busybox-ps-variables 4099@vindex tramp-connection-local-busybox-ps-variables
4100@vindex tramp-connection-local-darwin-ps-profile
4101@vindex tramp-connection-local-darwin-ps-variables
4100The default values for @code{tramp-process-attributes-ps-args} and 4102The default values for @code{tramp-process-attributes-ps-args} and
4101@code{tramp-process-attributes-ps-format} can be overwritten by 4103@code{tramp-process-attributes-ps-format} can be overwritten by
4102connection-local variables. 4104connection-local variables.
@@ -4107,14 +4109,11 @@ This is already done by @value{tramp} for the @option{adb} method, see
4107@code{tramp-adb-connection-local-default-ps-profile} and 4109@code{tramp-adb-connection-local-default-ps-profile} and
4108@code{tramp-adb-connection-local-default-ps-variables}. 4110@code{tramp-adb-connection-local-default-ps-variables}.
4109 4111
4110There are two further predefined sets of connection-local variables 4112There are three further predefined sets of connection-local variables
4111for remote BSD systems, and for a remote @command{ps} command 4113for remote BSD systems, for remote macOS systems, and for a remote
4112implemented with @command{busybox}. These are called 4114@command{ps} command implemented with @command{busybox}. These are
4113@code{tramp-connection-local-bsd-ps-profile}, 4115called @code{tramp-connection-local-*-ps-profile} and
4114@code{tramp-connection-local-bsd-ps-variables}, 4116@code{tramp-connection-local-*-ps-variables}. Use them like
4115@code{tramp-connection-local-busybox-ps-profile}, and
4116@code{tramp-connection-local-busybox-ps-variables}. Use them
4117like
4118 4117
4119@lisp 4118@lisp
4120@group 4119@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'.")
430 'tramp-connection-local-busybox-ps-profile 430 'tramp-connection-local-busybox-ps-profile
431 tramp-connection-local-busybox-ps-variables) 431 tramp-connection-local-busybox-ps-variables)
432 432
433 433;; Darwin (macOS).
434;; Darwin (macOS)
435(defconst tramp-darwin-process-attributes-ps-args 434(defconst tramp-darwin-process-attributes-ps-args
436 `("-acxww" 435 `("-acxww"
437 "-o" 436 "-o"
@@ -498,31 +497,25 @@ See `tramp-process-attributes-ps-format'.")
498 . ,tramp-darwin-process-attributes-ps-args) 497 . ,tramp-darwin-process-attributes-ps-args)
499 (tramp-process-attributes-ps-format 498 (tramp-process-attributes-ps-format
500 . ,tramp-darwin-process-attributes-ps-format)) 499 . ,tramp-darwin-process-attributes-ps-format))
501 "Default connection-local ps variables for remote Darwin 500 "Default connection-local ps variables for remote Darwin connections.")
502connections.")
503 501
504(connection-local-set-profile-variables 502(connection-local-set-profile-variables
505 'tramp-connection-local-darwin-ps-profile 503 'tramp-connection-local-darwin-ps-profile
506 tramp-connection-local-darwin-ps-variables) 504 tramp-connection-local-darwin-ps-variables)
507 505
506;; Preset default "ps" profile for local hosts, based on system type.
508 507
509 508(when-let ((local-profile
510;; Preset default "ps" profile for the case of local sudo, based on 509 (cond ((eq system-type 'darwin)
511;; system type. 510 'tramp-connection-local-darwin-ps-profile)
512 511 ;; ... Add other system types here.
513(let ((local-sudo-profile 512 )))
514 (cond ((eq system-type 'darwin) 513 (connection-local-set-profiles
515 'tramp-connection-local-darwin-ps-profile) 514 `(:application tramp :machine ,(system-name))
516 ;; ...add other system types here 515 local-profile)
517 ))) 516 (connection-local-set-profiles
518 (when local-sudo-profile 517 '(:application tramp :machine "localhost")
519 (connection-local-set-profiles 518 local-profile))
520 `(:application tramp :protocol "sudo" :user "root" :machine ,(system-name))
521 local-sudo-profile)
522 (connection-local-set-profiles
523 '(:application tramp :protocol "sudo" :user "root" :machine "localhost")
524 local-sudo-profile)))
525
526 519
527(add-hook 'tramp-unload-hook 520(add-hook 'tramp-unload-hook
528 (lambda () (unload-feature 'tramp-integration 'force))) 521 (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'."
5090 (ignore-errors (kill-process proc)) 5090 (ignore-errors (kill-process proc))
5091 (ignore-errors (delete-process proc)))))) 5091 (ignore-errors (delete-process proc))))))
5092 5092
5093(ert-deftest tramp-test31-list-system-processes ()
5094 "Check `list-system-processes'."
5095 :tags '(:expensive-test)
5096 (skip-unless (tramp--test-enabled))
5097 (skip-unless (tramp--test-supports-processes-p))
5098 ;; `list-system-processes' is supported since Emacs 29.1.
5099 (skip-unless (tramp--test-emacs29-p))
5100
5101 (let ((default-directory tramp-test-temporary-file-directory))
5102 (skip-unless (consp (list-system-processes)))
5103 (should (not (equal (list-system-processes)
5104 (let ((default-directory temporary-file-directory))
5105 (list-system-processes)))))))
5106
5107(ert-deftest tramp-test31-process-attributes ()
5108 "Check `process-attributes'."
5109 :tags '(:expensive-test :tramp-asynchronous-processes)
5110 (skip-unless (tramp--test-enabled))
5111 (skip-unless (tramp--test-supports-processes-p))
5112 ;; `process-attributes' is supported since Emacs 29.1.
5113 (skip-unless (tramp--test-emacs29-p))
5114
5115 ;; We must use `file-truename' for the temporary directory, in
5116 ;; order to establish the connection prior running an asynchronous
5117 ;; process.
5118 (let ((default-directory (file-truename tramp-test-temporary-file-directory))
5119 (delete-exited-processes t)
5120 kill-buffer-query-functions command proc)
5121 (skip-unless (consp (list-system-processes)))
5122
5123 (unwind-protect
5124 (progn
5125 (setq command '("sleep" "100")
5126 proc (apply #'start-file-process "test" nil command))
5127 (while (accept-process-output proc 0))
5128 (when-let ((pid (process-get proc 'remote-pid))
5129 (attributes (process-attributes pid)))
5130 ;; (tramp--test-message "%s" attributes)
5131 (should (equal (cdr (assq 'comm attributes)) (car command)))
5132 (should (equal (cdr (assq 'args attributes))
5133 (mapconcat #'identity command " ")))))
5134
5135 ;; Cleanup.
5136 (ignore-errors (delete-process proc)))))
5137
5093(defun tramp--test-async-shell-command 5138(defun tramp--test-async-shell-command
5094 (command output-buffer &optional error-buffer input) 5139 (command output-buffer &optional error-buffer input)
5095 "Like `async-shell-command', reading the output. 5140 "Like `async-shell-command', reading the output.