]> git.eshelyaron.com Git - emacs.git/commitdiff
Adapt macOS defaults in Tramp's process-attributes implementation
authorMichael Albinus <michael.albinus@gmx.de>
Tue, 12 Apr 2022 07:41:11 +0000 (09:41 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Tue, 12 Apr 2022 07:41:11 +0000 (09:41 +0200)
* 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
lisp/net/tramp-integration.el
test/lisp/net/tramp-tests.el

index e4a586f817633b26ac44329826118a00d8892de7..3cc312d2f5e8e95bdb1d75bdcb1180b9b0795f12 100644 (file)
@@ -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
index 901826bfc185bd726304c7109dcb1c7b29c7509c..b7f82770c40547b91404f33ce92ae5956cab5b85 100644 (file)
@@ -430,8 +430,7 @@ See `tramp-process-attributes-ps-format'.")
  'tramp-connection-local-busybox-ps-profile
  tramp-connection-local-busybox-ps-variables)
 
-\f
-;; 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.
 
-\f
-;; 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)))
index c3b3f21d52875e3d65a4a9c18e975a7dc23641eb..e9ea758956a6c9484bc39ef22916e212ecac4a2c 100644 (file)
@@ -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.