diff options
author | wm4 <wm4@nowhere> | 2020-05-15 16:35:44 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-05-15 16:37:41 +0200 |
commit | 5ebb498b7a41863c369c8fda49344e6f4a6d4203 (patch) | |
tree | ec0b476bd0c2cdf331bb833d1939bf3cfc40219d /player/scripting.c | |
parent | c4d0d7a194bee56b4cc4b0b7fec4a81261decd01 (diff) | |
download | mpv-5ebb498b7a41863c369c8fda49344e6f4a6d4203.tar.bz2 mpv-5ebb498b7a41863c369c8fda49344e6f4a6d4203.tar.xz |
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.
Diffstat (limited to 'player/scripting.c')
-rw-r--r-- | player/scripting.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/player/scripting.c b/player/scripting.c index bb4c93b60e..7b3f9afb3c 100644 --- a/player/scripting.c +++ b/player/scripting.c @@ -335,8 +335,8 @@ static int load_run(struct mp_script_args *args) // Hardcode them (according to opts.fds[]), because we want to allow clients // to hardcode them if they want. Sue me. - char *fdopt = fds[1] >= 0 ? "--mpv-ipc-fd=3:4" - : "--mpv-ipc-fd=3"; + char *fdopt = fds[1] >= 0 ? mp_tprintf(80, "--mpv-ipc-fd=%d:%d", fds[0], fds[1]) + : mp_tprintf(80, "--mpv-ipc-fd=%d", fds[0]); struct mp_subprocess_opts opts = { .exe = (char *)args->filename, @@ -348,8 +348,8 @@ static int load_run(struct mp_script_args *args) {.fd = 2, .src_fd = 2,}, // Just hope these don't step over each other (e.g. fds[1] is not // below 4, if the std FDs are missing). - {.fd = 3, .src_fd = fds[0], }, - {.fd = 4, .src_fd = fds[1], }, + {.fd = fds[0], .src_fd = fds[0], }, + {.fd = fds[1], .src_fd = fds[1], }, }, .num_fds = fds[1] >= 0 ? 5 : 4, .detach = true, |