klenin / Spawner

Cross-platform sandbox runner
4 stars 8 forks source link

Windows: Work with environment variables properly. #69

Closed cher-nov closed 7 years ago

cher-nov commented 7 years ago

Currently this works as follows:

  1. Change environment variables of spawner process by variables that new process should use.
  2. Create process. It inherits all environment from the parent process.
  3. Restore original environment.

Here we reinventing the wheel because in Windows CreateProcess() and similar functions have nice lpEnvironment argument exactly for this purpose.

So the proposal is in removing current bulky code and use this feature.

cher-nov commented 7 years ago

As it turned out, it's a common approach in WinAPI. See Example 2 here: https://msdn.microsoft.com/en-us/library/ms682009(v=vs.85).aspx