summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-26 22:04:43 +0100
committerwm4 <wm4@nowhere>2015-02-26 22:09:00 +0100
commit7b02c79a2367d0baf565f8550c65a5f4bcd92552 (patch)
tree403b1140b6efd1ed335cf757326b1636ce032393
parenta22de99544af562ffa431ab4864b07ec3729088a (diff)
downloadmpv-7b02c79a2367d0baf565f8550c65a5f4bcd92552.tar.bz2
mpv-7b02c79a2367d0baf565f8550c65a5f4bcd92552.tar.xz
input: allow passing FDs to --input-file
-rw-r--r--DOCS/man/options.rst3
-rw-r--r--input/ipc.c15
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);