1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-16 20:14:57 +00:00
mpv/osdep
wm4 f2c7c641b3 subprocess: implement proper detached processes on POSIX
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.
2020-02-16 22:08:48 +01:00
..
android
macos mac: report playback state to the MediaPlayer Command Center 2020-01-26 12:09:55 +01:00
win32
atomic.h atomic: add mp_atomic_uint64 2019-11-29 12:14:43 +01:00
compiler.h
endian.h
getpid.h
glob-win.c
io.c io: remove Windows tmpfile() emulation 2019-09-19 20:37:05 +02:00
io.h player: Optionally validate st_mtime when restoring playback state 2019-11-20 15:11:33 +01:00
macOS_swift_bridge.h mac: replace old event tap for media key support with MediaPlayer 2019-12-15 20:07:31 +01:00
macosx_application_objc.h mac: replace old event tap for media key support with MediaPlayer 2019-12-15 20:07:31 +01:00
macosx_application.h cocoa-cb: add support for forcing the dedicated GPU for rendering 2020-01-26 12:12:22 +01:00
macosx_application.m mac: remove stdout and stderr redirect for logging 2020-02-08 10:55:07 +01:00
macosx_compat.h
macosx_events_objc.h mac: replace old event tap for media key support with MediaPlayer 2019-12-15 20:07:31 +01:00
macosx_events.h mac: remove Apple Remote support 2019-12-15 20:07:31 +01:00
macosx_events.m mac: replace old event tap for media key support with MediaPlayer 2019-12-15 20:07:31 +01:00
macosx_menubar_objc.h
macosx_menubar.h
macosx_menubar.m mac: activate logging when started from the bundle 2020-02-08 10:55:07 +01:00
macosx_touchbar.h
macosx_touchbar.m
macosx_versions.h
main-fn-cocoa.c
main-fn-unix.c
main-fn-win.c win32: remove -municode from mpv binary 2019-09-19 20:37:05 +02:00
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_osx.c
semaphore.h
strnlen.h
subprocess-dummy.c
subprocess-posix.c subprocess: implement proper detached processes on POSIX 2020-02-16 22:08:48 +01:00
subprocess-win.c
subprocess.c subprocess: implement proper detached processes on POSIX 2020-02-16 22:08:48 +01:00
subprocess.h subprocess: implement proper detached processes on POSIX 2020-02-16 22:08:48 +01:00
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