From 7b02c79a2367d0baf565f8550c65a5f4bcd92552 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 26 Feb 2015 22:04:43 +0100 Subject: input: allow passing FDs to --input-file --- DOCS/man/options.rst | 3 +++ input/ipc.c | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 2327817976..976e02a2e6 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -2318,6 +2318,9 @@ Input get replies or events. Use ``--input-unix-socket`` for something bi-directional. On MS Windows, JSON commands are not available. + This can also specify a direct file descriptor with ``fd://N`` (UNIX only). + In this case, JSON replies will be written if the FD is writable. + See also ``--slave-broken``. .. note:: diff --git a/input/ipc.c b/input/ipc.c index 486b9db011..d90922f80a 100644 --- a/input/ipc.c +++ b/input/ipc.c @@ -678,10 +678,20 @@ static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path) int mode = O_RDONLY; int client_fd = -1; bool close_client_fd = true; + bool writable = false; if (strcmp(path, "/dev/stdin") == 0) { // for symmetry with Linux client_fd = STDIN_FILENO; close_client_fd = false; + } else if (strncmp(path, "fd://", 5) == 0) { + char *end = NULL; + client_fd = strtol(path + 5, &end, 0); + if (!end || end == path + 5 || end[0]) { + MP_ERR(ctx, "Invalid FD: %s\n", path); + return; + } + close_client_fd = false; + writable = true; // maybe } else { // Use RDWR for FIFOs to ensure they stay open over multiple accesses. struct stat st; @@ -690,7 +700,7 @@ static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path) client_fd = open(path, mode); } if (client_fd < 0) { - MP_ERR(ctx, "Could not open pipe at '%s'\n", path); + MP_ERR(ctx, "Could not open '%s'\n", path); return; } @@ -699,8 +709,7 @@ static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path) .client_name = "input-file", .client_fd = client_fd, .close_client_fd = close_client_fd, - - .writable = false, + .writable = writable, }; ipc_start_client(ctx, client); -- cgit v1.2.3