From 1bdc3bed001168d8d2039955e57fead1ecc68144 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 9 Apr 2020 01:05:51 +0200 Subject: 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 --- input/ipc-unix.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'input') 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 #include #include - +#include #include #include #include @@ -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]) -- cgit v1.2.3