diff options
author | wm4 <wm4@nowhere> | 2020-04-09 01:05:51 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-04-09 01:05:51 +0200 |
commit | 1bdc3bed001168d8d2039955e57fead1ecc68144 (patch) | |
tree | 4f123328b736715219f161bb5e1597fbaeedf879 /input/ipc-unix.c | |
parent | fd3caa264ea0848e7e30db94390063c87e247003 (diff) | |
download | mpv-1bdc3bed001168d8d2039955e57fead1ecc68144.tar.bz2 mpv-1bdc3bed001168d8d2039955e57fead1ecc68144.tar.xz |
ipc: add --input-ipc-client option
While --input-file was removed for justified reasons, wanting to pass
down socket FDs this way is legitimate, useful, and easy to implement.
One odd thing is that
Fixes: #7592
Diffstat (limited to 'input/ipc-unix.c')
-rw-r--r-- | input/ipc-unix.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/input/ipc-unix.c b/input/ipc-unix.c index e047c30145..ef9f26e5c0 100644 --- a/input/ipc-unix.c +++ b/input/ipc-unix.c @@ -18,7 +18,7 @@ #include <pthread.h> #include <errno.h> #include <unistd.h> - +#include <limits.h> #include <poll.h> #include <signal.h> #include <sys/types.h> @@ -248,9 +248,10 @@ static void ipc_start_client_json(struct mp_ipc_ctx *ctx, int id, int fd) { struct client_arg *client = talloc_ptrtype(NULL, client); *client = (struct client_arg){ - .client_name = talloc_asprintf(client, "ipc-%d", id), - .client_fd = fd, - .close_client_fd = true, + .client_name = + id >= 0 ? talloc_asprintf(client, "ipc-%d", id) : "ipc", + .client_fd = fd, + .close_client_fd = id >= 0, .writable = true, }; @@ -384,6 +385,21 @@ struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api, .death_pipe = {-1, -1}, }; + if (opts->ipc_client && opts->ipc_client[0]) { + int fd = -1; + if (strncmp(opts->ipc_client, "fd://", 5) == 0) { + char *end; + unsigned long l = strtoul(opts->ipc_client + 5, &end, 0); + if (!end[0] && l <= INT_MAX) + fd = l; + } + if (fd < 0) { + MP_ERR(arg, "Invalid IPC client argument: '%s'\n", opts->ipc_client); + } else { + ipc_start_client_json(arg, -1, fd); + } + } + talloc_free(opts); if (!arg->path || !arg->path[0]) |