feature request: control environment of external processes
Tuesday, 16 July 2024 · 2 messages
HB
Hauke Brandes16 Jul 2024 08:41 #
Hello list,
I would like to suggest an enhancement for the
proc:system/execute/fork family of functions: it should be possible to control the environment variables of the external process. At the moment, the environment is always inherited from the calling basex process, as far as I can tell.
There are several reasons why it is desirable to control the environment of external processes:
* set variables to values that are not known statically when starting basex
* avoid information leaking (restrict environment to the minimal required subset)
* control the PATH of the external process
It would be great to have an additional, optional entry in the $options map (maybe named "env" or "environment") that contains a map of environment variables for the external process. If absent, the current behavior (inherited environment) should be used. If the option is given, **only** the environment variables in the map should be used for the external process.
Effectively, the "env"/"environment" option would behave as if it had a default value of map:merge( available-environment-variables() ! map:entry(., environment-variable(.)) )
The ProcessBuilder in Java should allow for a straightforward implementation.
What do you think?
Cheers,
HaukeCG
Christian Grün16 Jul 2024 11:48 #
Hi Hauke,
Thanks for the feature request, which was straightforward to implement. It has been added to the latest snapshot and will be officially supported with BaseX 12 [1, 2].
Best,
Christian
[1] https://files.basex.org/releases/latest/
[2] https://docs.basex.org/12/Process_Functions
Quoted text · Hauke Brandes · 36 lines
On Tue, Jul 16, 2024 at 8:41 AM Hauke Brandes <hauke.brandes at parsqube.de> wrote: > Hello list, > > I would like to suggest an enhancement for the proc:system/execute/fork > family of functions: it should be possible to control the environment > variables of the external process. At the moment, the environment is > always inherited from the calling basex process, as far as I can tell. > > There are several reasons why it is desirable to control the environment > of external processes: > > * set variables to values that are not known statically when starting basex > * avoid information leaking (restrict environment to the minimal > required subset) > * control the PATH of the external process > > It would be great to have an additional, optional entry in the $options > map (maybe named "env" or "environment") that contains a map of > environment variables for the external process. If absent, the current > behavior (inherited environment) should be used. If the option is given, > **only** the environment variables in the map should be used for the > external process. > > Effectively, the "env"/"environment" option would behave as if it had a > default value of `map:merge( available-environment-variables() ! > map:entry(., environment-variable(.)) )` > > The ProcessBuilder in Java should allow for a straightforward > implementation. > > What do you think? > Cheers, > Hauke > >
Written for BaseX 11.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery