Skip to content

win32: spawn: add vlc_spawn(), vlc_spawnp(), vlc_waitpid() wrappers

Louis Régnier requested to merge louis/vlc:vlc_spawn_win32 into master

Implement vlc_spawn(), vlc_spawnp(), vlc_waitpid() for Windows using Win32 API.

This will be required by the future preparse process in order to be invoked on Windows platforms.

Version 22/06/2022:

  1. Drop use of SetHandleInformation() in favor of DuplicateHandle()
  2. Build process path and command line using vlc_memstream()
  3. Use SearchPathA() to find executable in Windows Path, instead of command line behaviors of CreateProcess() which was preventing the use of argv[0] as binary name by child processes
  4. Use a list to define inheritable handles by child processes
  5. Drop UWP support, SearchPathA() / UpdateProcThreadAttribute() not available

Differences posix/win32 vlc_spawnp()

The behavior to find executables in PATH differ between Windows and Posix systems with this implementation.
I've tried to reproduce posix behaviors using SearchPathA() and SetSearchPathMode()
Using this feature of SearchPathA() basically search executable in system path first, then in the current directory.

This scenario differ:
Windows Path="C:\directory\:remaining windows variables"

C:\directory
├───test.exe
└───subdirectory
    ├───test.exe
    └───SearchTestBinary.exe

I've tested using search mode as "system path" first, then current directory. Which I assume is $PATH:..

When I execute SearchTestBinary.exe it always find C:\directory\subdirectory\test.exe unconditionally. Instead of C:\directory\test.exe indicated by Path.

I don't understand why this implementation doesn't produce the excepted result. So I suppose "system path" from the Microsoft documentation means "$PathOfBinarySearcher:$Path:$current_directory"

Any ideas regarding this ? If the code is correct and the excepted behavior not feasible using thoses functions. Maybe I could implement a custom search_path() using char *envp[] to match posix vlc_spawnp() if needed.

Version 27/06/2022:

  1. Remove vlc_stat() used in vlc_spawn(), CreateProcess() return gracefully when the executable is not found
  2. Cleaner use of vlc_memstream()
  3. Fix potential issue when argv[] = { NULL }; during command line creation
  4. vlc_waitpid() get exit code of the terminated process

Version 01/07/2022:

  1. Fix an edge case when first call vlc_memstream_open() was successful and the second fail, ressources wasn't freed correctly
  2. Make allow_hstd_inherit() and dup_handle_from_fd() return objects they create instead of an error code
  3. Use pointer to StartupInfo when spawning the process instead of casting StartupInfoEx
  4. Adjust order of allocated / freed ressources, to fit better the execution order of the function
Edited by Louis Régnier

Merge request reports