Subject: Re: bug#77707: [shepherd] chdir and invoke do not work as intended in services
From: Ludovic Courtès <[email-masked]>
To: Maxim Cournoyer <[email-masked]>
Cc: [email-masked]
Date: Sun, 13 Apr 2025 21:52:29 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

Maxim Cournoyer <[email-masked]> skribis:

> +                             (start #~(lambda _
> +                                        (mkdir "/etc/testdir")
> +                                        (chdir "/etc/testdir")
> +                                        (invoke #$(file-append coreutils "/bin/touch")
> +                                                "new-file.txt")

[...]

> You should see upon inspection that:
>
> root@komputilo ~# ls /new-file.txt 
> /new-file.txt                        # wrong place
> root@komputilo ~# ls /etc/testdir/   # empty

That’s because ‘invoke’ uses ‘system*’, which is in fact within the
‘shepherd’ process an alias for ‘spawn-command’.

This is fixed in 8d88024e0898dd7d4581c4e977c9786af734a855, which will be
in 1.0.4.

However generally speaking it’s a good idea to leave the current
directory of the ‘shepherd’ process unchanged as bad things could happen
otherwise (though ‘with-directory-excursion’ from (shepherd support)
should be safe.)

Thanks,
Ludo’.