Subject: Re: bug#76888: 31.0.50; start-process: Spawning child process: Invalid argument

From: Eli Zaretskii <[email-masked]>
Date: Sun, 16 Mar 2025 12:24:54 +0200

> From: Richard Copley <[email-masked]>
> Date: Sun, 16 Mar 2025 09:39:32 +0000
> Cc: [email-masked], [email-masked]
> 
> On Sun, 16 Mar 2025 at 09:07, Eli Zaretskii <[email-masked]> wrote:
> >
> > > The first factor is that the value of shell-file-name sometimes gets
> > > set buffer-locally in the "*Async Shell Command*" buffer. (This is
> > > true for the Tramp code, when the buffer is reused. I don't know if it
> > > is meaningful to ask whether it is true for the non-Tramp code.)
> >
> > If Tramp sets the buffer-local value in the "*Async Shell Command*"
> > buffer, it should also set default-directory in that buffer.
> >
> > > The second factor is that 'async-shell-command' sometimes uses the
> > > value of shell-file-name from the "*Async Shell Command*" buffer.
> > > (This is true for the non-Tramp code. I don't know if it is true for
> > > the Tramp code.)
> >
> > Please point out the code which uses the value of shell-file-name
> > local to the "*Async Shell Command*" buffer.
> 
> In 'shell-command' in "simple.el", 'start-process-shell-command'
> is called after changing to the "*Async Shell Command*" buffer.
> 
>         (let* ((buffer (get-buffer-create
>                 (or output-buffer shell-command-buffer-name-async)))
>                 [...])
>           [...]
>           (with-current-buffer buffer
>         [...]
>           (setq proc
>             (start-process-shell-command "Shell" buffer command)))
> 
> Then in the body of 'start-process-shell-command',
> 
>   (start-process name buffer shell-file-name shell-command-switch command)

That's a mistake: at least for local commands, the values of
shell-file-name and shell-command-switch should come from the buffer
that is current when the command is invoked.

Let's wait for Michael to chime in and explain how these variables
should be populated for remote shell commands; I guess
connection-local variables should be consulted, but the relevant
connection should be taken again from the buffer that is current when
the command is invoked.

> > Buffer-local values should matter only when commands are invoked with
> > that buffer the current buffer.  Which part(s) of your recipe do that?
> 
> The recipe does not do that. The command 'async-shell-command' is
> invoked three times from dired buffers and never from the "*Async
> Shell Command*" buffer.

Then it's a clear bug.  I'm guessing the code in question never
expected shell-command to have a buffer-local value (which is indeed
an unusual and strange situation).  So maybe a simpler solution is to
never make shell-command's value be buffer-local.