[pmg-devel] [PATCH pmg-api] cli utils: chdir to / before running

Thomas Lamprecht t.lamprecht at proxmox.com
Tue Nov 30 13:17:29 CET 2021


On 29.11.21 20:15, Stoiko Ivanov wrote:
> some of PMG's CLI invocations switch user to postgres and run `psql`
> (through `PMG::Utils::postgres_admin_cmd()`)
> 
> When running a command in `/root` (or any other directory not
> accessible by the postgres user this causes:
> `could not change directory to "/root": Permission denied`
> to be printed multiple times on stderr for those invocations, which is
> confusing and has caused quite a few support requests.
> 
> grepping through the code-base setup_default_cli_env seems the
> appropriate place for chdir to /, since it's only called once per cli
> utility.
> 

can be fine, but do we have any path params where this could break passing
from CWD relative paths?

> quickly tested with `pmgconfig sync`
> 
> Reported-by: Oguz Bektas <o.bektas at proxmox.com>
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
>  src/PMG/RESTEnvironment.pm | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/PMG/RESTEnvironment.pm b/src/PMG/RESTEnvironment.pm
> index 3875720..49dd8e8 100644
> --- a/src/PMG/RESTEnvironment.pm
> +++ b/src/PMG/RESTEnvironment.pm
> @@ -50,6 +50,7 @@ sub setup_default_cli_env {
>  
>      my $rest_env = $class->get();
>      $rest_env->set_role('root');
> +    chdir('/');
>  }
>  
>  sub set_format {
> 





More information about the pmg-devel mailing list