bitwiseworks / libcx

kLIBC Extension Library
GNU Lesser General Public License v2.1
11 stars 1 forks source link

spawn2: Support deletion of environment variables #91

Closed dmik closed 3 years ago

dmik commented 3 years ago

Some apps, e.g. git (see https://github.com/bitwiseworks/git-os2/issues/4#issuecomment-808804069) want to not only add some environment variables to their own environment when passing it to the child process but also remove some of them. Adding is currently done by passing variables to add in envp and setting P_2_APPENDENV in mode. However, there is no way to perform removal.

I propose to go the same way git goes: treat variables w/o an = character (i.e. w/o a value specification) as ones to be removed. This makes sense as there is no need to pass variables in such a form otherwise. BTW, both LIBC __spawnve and DosExecPgm accept such variable specifications pretty well but it appears from the program POV as the respective variables are simply never set (getenv returns NULL for them, DosScanEnv returns error 203 — ERROR_ENVVAR_NOT_FOUND).

dmik commented 3 years ago

Note that after closing bitwiseworks/libc#102 the above commit was not strictly necessary as the effect would be the same in case of P_2_APPENDENV because the current (parent) process variables would be shadowed by those from envp w/o = and spawnve indirectly used by spawn2 would ignore them anyway.

However, spawnve may change in the future and e.g. refuse accepting variables w/o = so it's safer to not pass them from spawn2 at all.

Note that both appending and deletion is based using case sensitive comparison now as this is what POSIX requires for environment variables.