bug#29149: Tramp shell uses local shell setting in windows

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Shuguang Sun
Hi,

The tramp shell uses local shell setting (explicit-shell-file-name and shell-file-name) in Windows. However, according to the documents, for example, in tramp-handle-shell-command:
;; We cannot use `shell-file-name' and `shell-command-switch',
;; they are variables of the local host.
Instead, it uses the arguments tramp-remote-shell and tramp-remote-shell-args from the variable tramp-methods.

Windows7,
GNU Emacs 27.0.50 (build 1, x86_64-w64-mingw32) of 2017-10-21
explicit-shell-file-name = nil
shell-file-name = "C:/Users/username/emacs/libexec/emacs/27.0.50/x86_64-w64-mingw32/cmdproxy.exe"

- Problem 1: tramp and dired-do-shell-command:  start: Unknown job: /b
Why "start /b" is called remote side?

When I run tramp (plink) and go to a remote buffer (dired mode), run dired-do-shell-command (!) on marked file (for example, /opt/bin/R CMD BATCH * &). It popup the buffer of * Async Shell Command *, and the command is not run but a message "start: Unknown job: /b" which looks it runs the windows-like command "start /b ..." on the remote shell.

A test without "&" (non-ascync):
11:07:06.340383 tramp-handle-insert-directory (0) # Opening directory /plink:user@host:/opt/user/test/...done
11:07:35.748442 tramp-send-command (6) # ( cd /opt/user/test/ && /bin/sh -c start\ /b\ /opt/bin/R\ CMD\ BATCH\ --no-restore\ --no-save\ \"coxph.r\" </dev/null; echo tramp_exit_status $? )
11:07:36.033413 tramp-wait-for-regexp (6) #
start: invalid option: --no-restore
Try `start --help' for more information.
tramp_exit_status 1

It doen't help if (setq explicit-shell-file-name "/bin/sh"). It looks like due to the construction of the command which concats shell-file-name and args even if it is for tramp and remote host.

- Problem 2: tramp and shell: env: c:/bin/sh : No such file or directory
where "c:/" comes? Does it comes from some feature of completion of read-file-name?

In a tramp dried buffer, call shell which suppose to raise the shell buffer on remote server. However, I got error messge in the * shell * buffer that "env: c:/bin/sh : No such file or directory". I don't know where the "c:/" comes from. When shell is called, it reads the remote path in the minibufer with promotes (for remote shell path) "/plink:user@host:/path/to/dired/C:/Users/username/emacs/libexec/emacs/27.0.50/x86_64-w64-mingw32/cmdproxy.exe", and I change it to "/plink:user@host:/bin/", and then I got error message above. Below is the tracking:

12:00:20.871919 tramp-send-command (6) # cd /opt/user/test/ &&  exec  env PS1\=/plink\:user\@host\:/opt/user/test/\ \#\$\  TERM\=emacs TERMCAP\=emacs\:co\#135\:tc\=unknown\: INSIDE_EMACS\=27.0.50\,comint c\:/bin/sh -i

"c\"/bin/sh" is because I change the remote path to /plink:user@host:/bin/ when it asked in the minibuffer.

It opens the shell remotely if (setq explicit-shell-file-name "/bin/sh").
11:50:36.476919 tramp-send-command (6) # cd /opt/user/test/ &&  exec  env PS1\=/plink\:user\@host\:/opt/user/test/\ \#\$\  TERM\=emacs TERMCAP\=emacs\:co\#135\:tc\=unknown\: INSIDE_EMACS\=27.0.50\,comint /bin/sh -i
The remote shell path is not asked in this case.
Shoud it get tramp-remote-shell from tramp-methods or remote-shell from tramp-connection-properties directly?

- Problem 3: as in problem 2, shell-file-name is used in the complete of promote for remote path. It should not do in this way because shell-file-name is for local.
It triggered lots of try in hos side for completion:
11:16:47.779920 tramp-send-command (6) # test -d /opt/bee/user/test/C\:/Users/username/emacs/libexec/emacs/27.0.50/x86_64-w64-mingw32 2>/dev/null; echo tramp_exit_status $?
I have set ido-mode or icomplete-mode to nil.

The only tramp setting I used:
  (push '("plink"
           (tramp-login-program        "plink")
           (tramp-login-args           (("-l" "%u") ("-P" "%p") ("-ssh") ("%h")))
           (tramp-remote-shell         "/bin/sh")
           (tramp-remote-shell-args    ("-c"))
           (tramp-copy-program         "pscp")
           (tramp-copy-args            (("-l" "%u") ("-P" "%p") ("-scp") ("-p" "%k") ("-q") ("-r")))
           (tramp-copy-keep-date t)
           (tramp-copy-recursive t)
           (tramp-default-port         22))
        tramp-methods)




Best Regards,
Shuguang Sun
Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Shuguang Sun
Hi,

Local: Emacs on Windows 7.
Host:  Linux
Tramp from Windows 7 to linux

A further information: it is about backup. When I setup tramp-backup-directory-alist which will make it backup serverside. However, It concat !driver_c to the backup file name.

I have setting ("\\.md$" . "~/.emacs.d/backup-tramp/mdfiles") in tramp-backup-directory-alist. The backup file in the server is
"!drive_c!plink!!user@host!!!opt!host!path!Ava!_summary.md.~1~"

The "!drive_c" comes very strange.

Best Regards,
Shuguang
Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Eli Zaretskii
> From: Shuguang Sun <[hidden email]>
> Date: Thu, 9 Nov 2017 17:27:51 +0800
>
> Local: Emacs on Windows 7.
> Host:  Linux
> Tramp from Windows 7 to linux
>
> A further information: it is about backup. When I setup tramp-backup-directory-alist which will make it backup
> serverside. However, It concat !driver_c to the backup file name.
>
> I have setting ("\\.md$" . "~/.emacs.d/backup-tramp/mdfiles") in tramp-backup-directory-alist. The backup file
> in the server is
> "!drive_c!plink!!user@host!!!opt!host!path!Ava!_summary.md.~1~"
>
> The "!drive_c" comes very strange.

Michael, any advice on this one?  Do you understand where did
!drive_c! come from?  AFAIU, it should only be used for backups of
local files.



Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Michael Albinus
In reply to this post by Shuguang Sun
Hi Eli,

My laptop crashed last night. If I cannot recover over the weekend, it might take some days before I could react. Sorry.

Best regards, Michael.



Von meinem Samsung Galaxy Smartphone gesendet.
Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Eli Zaretskii
> Date: Sat, 11 Nov 2017 10:10:45 +0100
> From: "michael.albinus" <[hidden email]>
> Cc: [hidden email]
>
> My laptop crashed last night. If I cannot recover over the weekend, it might take some days before I could
> react. Sorry.

Sorry to hear about that, and hope you will recover soon without
losing any precious stuff.

In any case, there's no urgency to this.  Hope to hear from you when
this problem is behind you.

Thanks.



Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Michael Albinus
In reply to this post by Eli Zaretskii
Eli Zaretskii <[hidden email]> writes:

>> A further information: it is about backup. When I setup
>> tramp-backup-directory-alist which will make it backup
>> serverside. However, It concat !driver_c to the backup file name.
>>
>> I have setting ("\\.md$" . "~/.emacs.d/backup-tramp/mdfiles") in
>> tramp-backup-directory-alist. The backup file
>> in the server is
>> "!drive_c!plink!!user@host!!!opt!host!path!Ava!_summary.md.~1~"
>>
>> The "!drive_c" comes very strange.
>
> Michael, any advice on this one?  Do you understand where did
> !drive_c! come from?  AFAIU, it should only be used for backups of
> local files.

Since I cannot test under MS Windows, I need traces. Shuguang, could
you, pls, apply the settings as described in the Tramp manual, at the
bottom of (info "(tramp) Traces and Profiles") . Rerun your tests,
provoking a remote backup file. This produces a buffer *trace-output*,
which should tell us where the mysterious !drive_c! is prepended.

Best regards, Michael.



Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Shuguang Sun
Hi Michael,

I attached the trace log which has actions: open the file coxph_bench.r, and edit it, and save it. If you need the full log, please let me know.


Occur: c:/\|drive my help.

Looks like something of "| | | | | | 7 -> (tramp-drop-volume-letter "c:/opt/home/username/test/coxph_bench.r")" was not applied.



On Tue, Nov 14, 2017 at 11:44 PM, Michael Albinus <[hidden email]> wrote:
Eli Zaretskii <[hidden email]> writes:

>> A further information: it is about backup. When I setup
>> tramp-backup-directory-alist which will make it backup
>> serverside. However, It concat !driver_c to the backup file name.
>>
>> I have setting ("\\.md$" . "~/.emacs.d/backup-tramp/mdfiles") in
>> tramp-backup-directory-alist. The backup file
>> in the server is
>> "!drive_c!plink!!user@host!!!opt!host!path!Ava!_summary.md.~1~"
>>
>> The "!drive_c" comes very strange.
>
> Michael, any advice on this one?  Do you understand where did
> !drive_c! come from?  AFAIU, it should only be used for backups of
> local files.

Since I cannot test under MS Windows, I need traces. Shuguang, could
you, pls, apply the settings as described in the Tramp manual, at the
bottom of (info "(tramp) Traces and Profiles") . Rerun your tests,
provoking a remote backup file. This produces a buffer *trace-output*,
which should tell us where the mysterious !drive_c! is prepended.

Best regards, Michael.


tramp_backup_trace_small.txt (2M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Michael Albinus
Shuguang Sun <[hidden email]> writes:

> Hi Michael,

Hi Shuguang,

> I attached the trace log which has actions: open the file
> coxph_bench.r, and edit it, and save it. If you need the full log,
> please let me know.

Thanks!

I'll show the most interesting lines here, which tell us the flow

======================================================================
1 -> (tramp-file-name-handler find-backup-file-name "/plink:[hidden email]:/opt/home/username/test/coxph_bench.r")

The function `find-backup-file-name' has called the Tramp file name
handler due to the remote nature of the file name.

| 2 -> (tramp-sh-file-name-handler find-backup-file-name "/plink:[hidden email]:/opt/home/username/test/coxph_bench.r")
| | 3 -> (tramp-handle-find-backup-file-name "/plink:[hidden email]:/opt/home/username/test/coxph_bench.r")

Some Tramp internal flow in order to find the correct funtion. It is
`tramp-handle-find-backup-file-name'.

| | | 4 -> (tramp-run-real-handler find-backup-file-name ("/plink:[hidden email]:/opt/home/username/test/coxph_bench.r"))

`tramp-handle-find-backup-file-name' calls again
`find-backup-file-name', but suppressing file name handlers. This is
intended in order to ensure proper encoding of "/", ":" "!" and alike.

| | | | 5 -> (tramp-file-name-handler file-exists-p "/plink:[hidden email]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles")
| | | | 5 <- tramp-file-name-handler: t

Some other file name operations are called in `find-backup-file-name',
which work fine. I've removed them from the trace. The last such
operation is `file-exists-p'.

| | | | 5 -> (tramp-file-name-handler expand-file-name "/plink![hidden email]!/opt/home/username/test/coxph_bench.r" "/plink:[hidden email]:/opt/home/username/test/")

`find-backup-file-name' has finished the encoding of the file name (it
is "/plink![hidden email]!/opt/home/username/test/coxph_bench.r").
Due to the encoding, it looks like a local file name.

Now, `expand-file-name' is called with the encoded file name. Due to the
leading "/", it is regarded as absolute file name. Tramp is involved due
to the remote default-directory.

| | | | 5 <- tramp-file-name-handler: "c:/plink![hidden email]!/opt/home/username/test/coxph_bench.r"

... And this is the problem. Since Tramp sees the local absolute file,
it doesn't do anything, but let the default `expand-file-name' do the
job. This prefixes the file name with "c:/".

The rest is not surprising. The leading "c:" is transformed into
"!drive_c!", and here we are.

| | | | 5 -> (tramp-file-name-handler expand-file-name "!drive_c!plink!![hidden email]!!!opt!bee!home_nas!username!test!coxph_bench.r" "/plink:[hidden email]:~/.emacs.d/backup-tramp/Rfiles")
| | | | 5 <- tramp-file-name-handler: "/plink:[hidden email]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/!drive_c!plink!![hidden email]!!!opt!bee!home_nas!username!test!coxph_bench.r"
| | | | 5 -> (tramp-file-name-handler expand-file-name "/plink:[hidden email]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/" nil)
| | | | 5 -> (tramp-file-name-handler file-name-all-completions "!drive_c!plink!![hidden email]!!!opt!bee!home_nas!username!test!coxph_bench.r.~" "/plink:[hidden email]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/")
| | | | 5 <- tramp-file-name-handler: ("!drive_c!plink!![hidden email]!!!opt!bee!home_nas!username!test!coxph_bench.r.~1~")
| | | 4 <- tramp-run-real-handler: ("/plink:[hidden email]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/!drive_c!plink!![hidden email]!!!opt!bee!home_nas!username!test!coxph_bench.r.~2~")
| | 3 <- tramp-handle-find-backup-file-name: ("/plink:[hidden email]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/!drive_c!plink!![hidden email]!!!opt!bee!home_nas!username!test!coxph_bench.r.~2~")
| 2 <- tramp-sh-file-name-handler: ("/plink:[hidden email]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/!drive_c!plink!![hidden email]!!!opt!bee!home_nas!username!test!coxph_bench.r.~2~")
1 <- tramp-file-name-handler: ("/plink:[hidden email]:/home/bceuser/username/.emacs.d/backup-tramp/Rfiles/!drive_c!plink!![hidden email]!!!opt!bee!home_nas!username!test!coxph_bench.r.~2~")

I have no clue yet how to fix. Pls give me some days to think about.

Best regards, Michael.



Reply | Threaded
Open this post in threaded view
|

bug#29149: Tramp shell uses local shell setting in windows

Michael Albinus
Michael Albinus <[hidden email]> writes:

Hi Shuguang,

> I have no clue yet how to fix. Pls give me some days to think about.

I have committed a patch to the emacs-26 branch of the Emacs git
repository. Could you, pls, check whether it works for you?

Best regards, Michael.