win32: spawn: add vlc_spawn(), vlc_spawnp(), vlc_waitpid() wrappers
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:
- Drop use of
SetHandleInformation()
in favor ofDuplicateHandle()
- Build process path and command line using
vlc_memstream()
- Use
SearchPathA()
to find executable in Windows Path, instead of command line behaviors ofCreateProcess()
which was preventing the use ofargv[0]
as binary name by child processes - Use a list to define inheritable handles by child processes
- 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:
- Remove
vlc_stat()
used invlc_spawn()
,CreateProcess()
return gracefully when the executable is not found - Cleaner use of
vlc_memstream()
- Fix potential issue when
argv[] = { NULL };
during command line creation -
vlc_waitpid()
get exit code of the terminated process
Version 01/07/2022:
- Fix an edge case when first call
vlc_memstream_open()
was successful and the second fail, ressources wasn't freed correctly - Make
allow_hstd_inherit()
anddup_handle_from_fd()
return objects they create instead of an error code - Use pointer to
StartupInfo
when spawning the process instead of castingStartupInfoEx
- Adjust order of allocated / freed ressources, to fit better the execution order of the function