mirror of https://github.com/mpv-player/mpv
f2c7c641b3
The previous method for this sucked: for every launched detached process, it started a thread, which then would leak if the launched process didn't end before the player uninitialized. This was very racy (although I bet the race condition wouldn't trigger in a 100 years), and wasteful (threads aren't a cheap resource). Implement it for POSIX directly. posix_spawn() has no direct support for this, so we need to do it ourselves with fork(). We could probably do it without fork(), and attempt to collect the PID in another thread. But then we'd either have a waiting thread again, or we'd need to do an unsafe waitpid(-1, ...) call. (POSIX process management sucks so badly, how did they even manage this. Hopefully I'm just missing something, but I'm not.) So now we depend on both posix_spawn() _and_ fork(), isn't it fun? Also call setsid(), to essentially detach the child process from the terminal. (Otherwise it can receive various signals from the terminal, which is probably not what you want.) posix_spawn() adds POSIX_SPAWN_SETSID in newer POSIX releases, but we don't want to rely on this yet. The posix_spawnp() call is duplicated, but this is better than somehow trying to unify the code paths. Only somewhat tested, so enjoy the bugs. |
||
---|---|---|
.. | ||
android | ||
macos | ||
win32 | ||
atomic.h | ||
compiler.h | ||
endian.h | ||
getpid.h | ||
glob-win.c | ||
io.c | ||
io.h | ||
macOS_swift_bridge.h | ||
macosx_application.h | ||
macosx_application.m | ||
macosx_application_objc.h | ||
macosx_compat.h | ||
macosx_events.h | ||
macosx_events.m | ||
macosx_events_objc.h | ||
macosx_menubar.h | ||
macosx_menubar.m | ||
macosx_menubar_objc.h | ||
macosx_touchbar.h | ||
macosx_touchbar.m | ||
macosx_versions.h | ||
main-fn-cocoa.c | ||
main-fn-unix.c | ||
main-fn-win.c | ||
main-fn.h | ||
mpv.exe.manifest | ||
mpv.rc | ||
path-macosx.m | ||
path-unix.c | ||
path-uwp.c | ||
path-win.c | ||
path.h | ||
polldev.c | ||
polldev.h | ||
posix-spawn.h | ||
semaphore.h | ||
semaphore_osx.c | ||
strnlen.h | ||
subprocess-dummy.c | ||
subprocess-posix.c | ||
subprocess-win.c | ||
subprocess.c | ||
subprocess.h | ||
terminal-dummy.c | ||
terminal-unix.c | ||
terminal-win.c | ||
terminal.h | ||
threads.c | ||
threads.h | ||
timer-darwin.c | ||
timer-linux.c | ||
timer-win2.c | ||
timer.c | ||
timer.h | ||
w32_keyboard.c | ||
w32_keyboard.h | ||
win32-console-wrapper.c | ||
windows_utils.c | ||
windows_utils.h |