That hangs for me too. I set tramp-verbose to 10, then did a C-g, got this
trace:

  backtrace()
  tramp-error(nil quit "")
  tramp-signal-hook-function(quit (""))
  signal(quit (""))
  tramp-maybe-open-connection((tramp-file-name "sudo" #("root" 0 4
(tramp-default t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix"
nil))
  tramp-send-command((tramp-file-name "sudo" #("root" 0 4 (tramp-default
t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix" nil) "test 0
2>/dev/null; echo tramp_exit_status $?")
  tramp-send-command-and-check((tramp-file-name "sudo" #("root" 0 4
(tramp-default t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix"
nil) "test 0")
  tramp-get-test-command((tramp-file-name "sudo" #("root" 0 4
(tramp-default t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix"
nil))
  tramp-run-test("-d" #("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  
tramp-sh-handle-file-directory-p(#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  tramp-sh-file-name-handler(file-directory-p
#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  apply(tramp-sh-file-name-handler file-directory-p
#("/sudo:root@192.168.68.65:/etc/nixos/configuration...." 6 10
(tramp-default t)))
  tramp-file-name-handler(file-directory-p
#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  file-directory-p(#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  find-file-noselect(#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)) nil nil nil)
  find-alternate-file(#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  (cond ((buffer-file-name) (find-alternate-file (tramp-file-name-with-sudo
(buffer-name)))) ((derived-mode-p 'dired-mode) (progn (setq
default-directory (tramp-file-name-with-sudo default-directory)) (setq
list-buffers-directory (tramp-file-name-with-sudo list-buffers-directory)))
(if (consp dired-directory) (setcar dired-directory
(tramp-file-name-with-sudo (car dired-directory))) (setq dired-directory
(tramp-file-name-with-sudo dired-directory))) (revert-buffer)))
  tramp-revert-buffer-with-sudo()
  funcall-interactively(tramp-revert-buffer-with-sudo)
  command-execute(tramp-revert-buffer-with-sudo record)
  execute-extended-command(nil "tramp-revert-buffer-with-sudo" nil)
  funcall-interactively(execute-extended-command nil
"tramp-revert-buffer-with-sudo" nil)
  command-execute(execute-extended-command)

Then there are two traces, one for regular user for ssh and one for
root/sudo:

*debug tramp/ssh yyyyyyy@192.168.68.65*:
;; Emacs: 29.1 Tramp: 2.6.0.29.1 -*- mode: outline; coding: utf-8; -*-
;; Location: /home/xxxxx/opt/share/emacs/29.1/lisp/net/tramp.elc Git: /
13:24:39.376731 tramp-get-connection-property (7) # copy-program undef;
cache used: nil
13:24:39.379152 tramp-get-file-property (8) # /etc/nixos/configuration.nix
file-readable-p undef; inhibit: 10; cache used: nil; cached at: 13:23:31
13:24:39.379492 tramp-get-file-property (8) # /etc/nixos/configuration.nix
file-attributes undef; inhibit: 10; cache used: nil; cached at: nil
13:24:39.379846 tramp-get-connection-property (7) # test test; cache used: t
13:24:39.380220 tramp-get-connection-property (7) # null-device /dev/null;
cache used: t
13:24:39.380930 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:39.381183 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:39.381375 tramp-get-connection-property (7) # process-buffer nil;
cache used: t
13:24:39.381602 tramp-get-connection-property (7) # last-cmd-time (25854
2467 344203 758000); cache used: t
13:24:39.381883 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:39.382074 tramp-get-connection-property (7) # remote-echo nil; cache
used: nil
13:24:39.382245 tramp-send-command (6) # echo are you awake
13:24:39.382425 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:39.382607 tramp-get-connection-property (7) # chunksize 0; cache
used: t
13:24:39.382844 tramp-set-connection-property (7) # last-cmd-time (25854
2535 382731 433000)
13:24:39.383054 tramp-send-string (10) # echo are you awake
13:24:39.383232 tramp-get-connection-property (7) # process-buffer nil;
cache used: t
13:24:39.383429 tramp-get-connection-property (7) # locked nil; cache used:
nil
13:24:39.383584 tramp-set-connection-property (7) # locked t
13:24:39.383801 tramp-flush-connection-property (7) # locked
13:24:39.383984 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:39.384133 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:39.384385 tramp-get-connection-property (7) # locked nil; cache used:
nil
13:24:39.384538 tramp-set-connection-property (7) # locked t
13:24:39.397129 tramp-accept-process-output (10) # *tramp/ssh
teamslice@192.168.68.65* nil run t
are you awake
///49ac1ebb7bfa52e7b505074be6ce7f5b#$
13:24:39.397394 tramp-flush-connection-property (7) # locked
13:24:39.397567 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:39.397720 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:39.398039 tramp-wait-for-regexp (6) #
are you awake
///49ac1ebb7bfa52e7b505074be6ce7f5b#$
13:24:39.398440 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:39.398638 tramp-get-connection-property (7) # remote-echo nil; cache
used: nil
13:24:39.398814 tramp-send-command (6) # test -r
/etc/nixos/configuration.nix 2>/dev/null; echo tramp_exit_status $?
13:24:39.399058 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:39.399302 tramp-get-connection-property (7) # chunksize 0; cache
used: t
13:24:39.399527 tramp-set-connection-property (7) # last-cmd-time (25854
2535 399441 751000)
13:24:39.399734 tramp-send-string (10) # test -r
/etc/nixos/configuration.nix 2>/dev/null; echo tramp_exit_status $?
13:24:39.399921 tramp-get-connection-property (7) # process-buffer nil;
cache used: t
13:24:39.400135 tramp-get-connection-property (7) # locked nil; cache used:
nil
13:24:39.400287 tramp-set-connection-property (7) # locked t
13:24:39.400475 tramp-flush-connection-property (7) # locked
13:24:39.400705 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:39.400859 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:39.401026 tramp-get-connection-property (7) # locked nil; cache used:
nil
13:24:39.401178 tramp-set-connection-property (7) # locked t
13:24:39.412166 tramp-accept-process-output (10) # *tramp/ssh
teamslice@192.168.68.65* nil run t
tramp_exit_status 0
///49ac1ebb7bfa52e7b505074be6ce7f5b#$
13:24:39.412532 tramp-flush-connection-property (7) # locked
13:24:39.412746 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:39.412903 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:39.413110 tramp-wait-for-regexp (6) #
tramp_exit_status 0
///49ac1ebb7bfa52e7b505074be6ce7f5b#$
13:24:39.413422 tramp-get-connection-property (7) # process-buffer nil;
cache used: t
13:24:39.413795 tramp-set-file-property (8) # /etc/nixos/configuration.nix
file-readable-p t
13:24:39.417499 tramp-get-connection-property (7) # case-insensitive nil;
cache used: t
13:24:39.417725 tramp-get-connection-property (7) # case-insensitive nil;
cache used: t
13:24:39.417928 tramp-get-connection-property (7) # case-insensitive nil;
cache used: t
13:24:54.801837 tramp-get-connection-property (7) # case-insensitive nil;
cache used: t
13:24:54.801906 tramp-get-connection-property (7) # case-insensitive nil;
cache used: t
13:24:54.801968 tramp-get-connection-property (7) # case-insensitive nil;
cache used: t
13:24:54.802086 tramp-get-connection-property (7) # ~ /home/teamslice;
cache used: t
13:24:54.802875 tramp-get-file-property (8) # /etc/nixos/configuration.nix
file-readable-p undef; inhibit: 10; cache used: nil; cached at: nil
13:24:54.802982 tramp-get-file-property (8) # /etc/nixos/configuration.nix
file-attributes undef; inhibit: 10; cache used: nil; cached at: nil
13:24:54.803073 tramp-get-connection-property (7) # test test; cache used: t
13:24:54.803184 tramp-get-connection-property (7) # null-device /dev/null;
cache used: t
13:24:54.803246 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:54.803298 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:54.803352 tramp-get-connection-property (7) # process-buffer nil;
cache used: t
13:24:54.803423 tramp-get-connection-property (7) # last-cmd-time (25854
2535 399441 751000); cache used: t
13:24:54.803501 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:54.803558 tramp-get-connection-property (7) # remote-echo nil; cache
used: nil
13:24:54.803606 tramp-send-command (6) # test -r
/etc/nixos/configuration.nix 2>/dev/null; echo tramp_exit_status $?
13:24:54.803657 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:54.803708 tramp-get-connection-property (7) # chunksize 0; cache
used: t
13:24:54.803767 tramp-set-connection-property (7) # last-cmd-time (25854
2550 803744 139000)
13:24:54.803822 tramp-send-string (10) # test -r
/etc/nixos/configuration.nix 2>/dev/null; echo tramp_exit_status $?
13:24:54.803872 tramp-get-connection-property (7) # process-buffer nil;
cache used: t
13:24:54.803930 tramp-get-connection-property (7) # locked nil; cache used:
nil
13:24:54.803972 tramp-set-connection-property (7) # locked t
13:24:54.804036 tramp-flush-connection-property (7) # locked
13:24:54.804089 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:54.804130 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:54.804179 tramp-get-connection-property (7) # locked nil; cache used:
nil
13:24:54.804222 tramp-set-connection-property (7) # locked t
13:24:54.819582 tramp-accept-process-output (10) # *tramp/ssh
teamslice@192.168.68.65* nil run t
tramp_exit_status 0
///49ac1ebb7bfa52e7b505074be6ce7f5b#$
13:24:54.819673 tramp-flush-connection-property (7) # locked
13:24:54.819726 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:54.819772 tramp-get-connection-property (7) # check-remote-echo nil;
cache used: nil
13:24:54.819827 tramp-wait-for-regexp (6) #
tramp_exit_status 0
///49ac1ebb7bfa52e7b505074be6ce7f5b#$
13:24:54.819923 tramp-get-connection-property (7) # process-buffer nil;
cache used: t
13:24:54.820029 tramp-set-file-property (8) # /etc/nixos/configuration.nix
file-readable-p t

*debug tramp/sudo root@192.168.68.65*
;; Emacs: 29.1 Tramp: 2.6.0.29.1 -*- mode: outline; coding: utf-8; -*-
;; Location: /home/xxxxx/opt/share/emacs/29.1/lisp/net/tramp.elc Git: /
13:24:39.458070 tramp-get-connection-property (7) # case-insensitive undef;
cache used: nil
13:24:39.458316 tramp-get-connection-property (7) # ~ nil; cache used: nil
13:24:39.458900 tramp-get-file-property (8) # /etc/nixos/configuration.nix
file-directory-p undef; inhibit: 10; cache used: nil; cached at: nil
13:24:39.459022 tramp-get-file-property (8) # /etc/nixos/configuration.nix
file-truename nil; inhibit: 10; cache used: nil; cached at: nil
13:24:39.459132 tramp-get-connection-property (7) # test undef; cache used:
nil
13:24:39.459193 tramp-get-test-command (5) # Finding a suitable ‘test’
command
13:24:39.459267 tramp-get-connection-property (7) # null-device undef;
cache used: nil
13:24:39.459894 tramp-set-connection-property (7) # null-device /dev/null
13:24:39.459976 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:39.460042 tramp-get-connection-property (7) # process-name nil; cache
used: nil
13:24:39.460106 tramp-get-connection-property (7) # process-buffer nil;
cache used: nil
13:24:39.460332 tramp-get-connection-property (7) # process-buffer nil;
cache used: nil
13:24:39.460384 tramp-set-connection-property (7) # process-buffer nil
13:24:39.460900 tramp-maybe-open-connection (3) # Opening connection nil
for root@192.168.68.65 using sudo...
13:24:54.799738 tramp-compute-multi-hops (10) #
  backtrace()
  tramp-error((tramp-file-name "sudo" #("root" 0 4 (tramp-default t)) nil
"192.168.68.65" nil "/etc/nixos/configuration.nix" nil) quit "")
  tramp-signal-hook-function(quit nil)
  format-spec(#("/sudo:root@192.168.68.65:" 0 6 (tramp-ad-hoc t) 6 10
(tramp-ad-hoc t tramp-default t) 10 25 (tramp-ad-hoc t)) ((117 . #("root" 0
4 (tramp-default t tramp-ad-hoc t))) (104 . #("192.168.68.65" 0 13
(tramp-ad-hoc t)))))
  tramp-compute-multi-hops((tramp-file-name "sudo" #("root" 0 4
(tramp-default t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix"
nil))
  tramp-maybe-open-connection((tramp-file-name "sudo" #("root" 0 4
(tramp-default t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix"
nil))
  tramp-send-command((tramp-file-name "sudo" #("root" 0 4 (tramp-default
t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix" nil) "test 0
2>/dev/null; echo tramp_exit_status $?")
  tramp-send-command-and-check((tramp-file-name "sudo" #("root" 0 4
(tramp-default t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix"
nil) "test 0")
  tramp-get-test-command((tramp-file-name "sudo" #("root" 0 4
(tramp-default t)) nil "192.168.68.65" nil "/etc/nixos/configuration.nix"
nil))
  tramp-run-test("-d" #("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  
tramp-sh-handle-file-directory-p(#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  tramp-sh-file-name-handler(file-directory-p
#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  apply(tramp-sh-file-name-handler file-directory-p
#("/sudo:root@192.168.68.65:/etc/nixos/configuration...." 6 10
(tramp-default t)))
  tramp-file-name-handler(file-directory-p
#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  file-directory-p(#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  find-file-noselect(#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)) nil nil nil)
  find-alternate-file(#("/sudo:root@192.168.68.65:/etc/nixos/configuration...."
6 10 (tramp-default t)))
  (cond ((buffer-file-name) (find-alternate-file (tramp-file-name-with-sudo
(buffer-name)))) ((derived-mode-p 'dired-mode) (progn (setq
default-directory (tramp-file-name-with-sudo default-directory)) (setq
list-buffers-directory (tramp-file-name-with-sudo list-buffers-directory)))
(if (consp dired-directory) (setcar dired-directory
(tramp-file-name-with-sudo (car dired-directory))) (setq dired-directory
(tramp-file-name-with-sudo dired-directory))) (revert-buffer)))
  tramp-revert-buffer-with-sudo()
  funcall-interactively(tramp-revert-buffer-with-sudo)
  command-execute(tramp-revert-buffer-with-sudo record)
  execute-extended-command(nil "tramp-revert-buffer-with-sudo" nil)
  funcall-interactively(execute-extended-command nil
"tramp-revert-buffer-with-sudo" nil)
  command-execute(execute-extended-command)
13:24:54.799900 tramp-compute-multi-hops (1) # Quit: "Quit", ""
13:24:54.800315 tramp-maybe-open-connection (3) # Opening connection nil
for root@192.168.68.65 using sudo...failed
13:24:54.800438 tramp-get-connection-property (7) # process-buffer nil;
cache used: t
13:24:54.800736 tramp-get-file-property (8) # / file-truename nil; inhibit:
10; cache used: nil; cached at: nil
13:24:54.800807 tramp-flush-directory-properties (8) # /
13:24:54.800900 tramp-flush-connection-properties (7) # (tramp-file-name
sudo root nil 192.168.68.65 nil nil nil) (process-buffer null-device)

On Sun, Sep 10, 2023 at 1:02 PM Michael Albinus <michael.albi...@gmx.de>
wrote:

> Joseph Garvin <k04j...@gmail.com> writes:
>
> Hi Joseph,
>
> > Yeah, I haven't tried automating tramp much before so I'm not super
> > familiar with what best practice is here. I'm on 29.1.
>
> OK, so I've used the opportunity to write a more stable command
> `tramp-revert-buffer-with-sudo'. Works for buffers visitng a file, and
> for dired buffers. Could you pls check?
>
> --8<---------------cut here---------------start------------->8---
> (defcustom tramp-file-name-with-method "sudo"
>   "Which method to be used in `tramp-file-name-with-sudo'."
>   :group 'tramp
>   :type '(choice (const "su")
>                  (const "sudo")
>                  (const "doas")
>                  (const "ksu")))
>
> (defun tramp-file-name-with-sudo (filename)
>   "Convert FILENAME into a multi-hop file name with \"sudo\".
> An alternative method could be chosen with `tramp-file-name-with-method'."
>   (setq filename (expand-file-name filename))
>   (if (tramp-tramp-file-p filename)
>       (with-parsed-tramp-file-name filename nil
>         (if (and (tramp-multi-hop-p v)
>                  (not (string-equal method tramp-file-name-with-method)))
>             (tramp-make-tramp-file-name
>              (make-tramp-file-name
>               :method (tramp-find-method tramp-file-name-with-method nil
> host)
>               :user (tramp-find-user tramp-file-name-with-method nil host)
>               :host (tramp-find-host tramp-file-name-with-method nil host)
>               :localname localname :hop (tramp-make-tramp-hop-name v)))
>           (tramp-user-error v "Multi-hop with `%s' not applicable"
> method)))
>     (tramp-make-tramp-file-name
>      (make-tramp-file-name
>       :method tramp-file-name-with-method :localname filename))))
>
> (defun tramp-revert-buffer-with-sudo ()
>   "Revert current buffer to visit with \"sudo\" permissions.
> An alternative method could be chosen with `tramp-file-name-with-method'.
> If the buffer visits a file, the file is replaced.
> If the buffer runs `dired', the buffer is reverted."
>   (interactive)
>   (cond
>    ((buffer-file-name)
>     (find-alternate-file (tramp-file-name-with-sudo (buffer-name))))
>    ((derived-mode-p 'dired-mode)
>     (setq default-directory (tramp-file-name-with-sudo default-directory)
>           list-buffers-directory
>           (tramp-file-name-with-sudo list-buffers-directory))
>     (if (consp dired-directory)
>         (setcar
>          dired-directory (tramp-file-name-with-sudo (car dired-directory)))
>       (setq dired-directory (tramp-file-name-with-sudo dired-directory)))
>     (revert-buffer))))
> --8<---------------cut here---------------end--------------->8---
>
> Best regards, Michael.
>

Reply via email to