From 5ebb498b7a41863c369c8fda49344e6f4a6d4203 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 15 May 2020 16:35:44 +0200 Subject: scripting: make socket FD number for subprocesses dynamic Before this, we pretty much guaranteed that --mpv-ipc-fd=3 would be passed. The FD was hardcoded, so scripts started by this mechanism didn't need to actually parse the argument. Change this to using a mostly random FD number instead. I decided to do this because posix_spawnp() and the current replacement cannot "guarantee" a FD layout. posix_spawn_file_actions_adddup2() just runs dup2() calls, so it may be hard to set FD 3/4 if they are already used by something else. For example imagine trying to map: {.fd = 3, .src_fd = 4}, {.fd = 4, .src_fd = 3}, Then it'd do dup2(4, 3), dup2(3, 4) (reminder: dup2(src, dst)), and the end result is that FD 4 really maps to the original FD 4. While this was not a problem in the present code, it's too messy that I don't want to pretend it can always done this way without an unholy mess. So my assumption is that FDs 0-2 can be freely assigned because they're never closed (probably...), while for all other FDs only pass-through is reasonable. --- DOCS/man/ipc.rst | 5 ----- 1 file changed, 5 deletions(-) (limited to 'DOCS') diff --git a/DOCS/man/ipc.rst b/DOCS/man/ipc.rst index fdf5daf9b6..4b808b9ff9 100644 --- a/DOCS/man/ipc.rst +++ b/DOCS/man/ipc.rst @@ -380,11 +380,6 @@ shebang and have the executable bit set. When executed, a socket (the IPC connection) is passed to them through file descriptor inheritance. The file descriptor is indicated as the special command line argument ``--mpv-ipc-fd=N``, where ``N`` is the numeric file descriptor. -Currently, this is hardcoded as ``--mpv-ipc-fd=3``, and the intention is that -it will always be ``3``. (This was a compromise between keeping it as simple as -possible, and not doing too much implicitly. Also, since there is a chance that -this will change anyway, you should at least validate that you got the expected -argument.) The rest is the same as with a normal ``--input-ipc-server`` IPC connection. mpv does not attempt to observe or other interact with the started script process. -- cgit v1.2.3