summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-07 09:50:29 +0100
committerwm4 <wm4@nowhere>2014-11-07 09:50:29 +0100
commitc920a3920e34fe7b1e501bf8a513ab2a23769af6 (patch)
tree7f0a281b6cd2112c5786b13cbf762ab47168a5bd
parent97b4b4c8e029e407aba72b58aaadebc1318f5242 (diff)
downloadmpv-c920a3920e34fe7b1e501bf8a513ab2a23769af6.tar.bz2
mpv-c920a3920e34fe7b1e501bf8a513ab2a23769af6.tar.xz
ipc: make sure --input-file=/dev/stdin always works
It's not necessarily available on Unix systems other than Linux (sigh).
-rw-r--r--input/ipc.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/input/ipc.c b/input/ipc.c
index 5d470ac257..3ce37cbb24 100644
--- a/input/ipc.c
+++ b/input/ipc.c
@@ -58,6 +58,7 @@ struct client_arg {
char *client_name;
int client_fd;
+ bool close_client_fd;
bool writable;
@@ -616,7 +617,8 @@ static void *client_thread(void *p)
done:
talloc_free(client_msg.start);
- close(arg->client_fd);
+ if (arg->close_client_fd)
+ close(arg->client_fd);
mpv_detach_destroy(arg->client);
talloc_free(arg);
return NULL;
@@ -630,7 +632,8 @@ static void ipc_start_client(struct mp_ipc_ctx *ctx, struct client_arg *client)
pthread_t client_thr;
if (pthread_create(&client_thr, NULL, client_thread, client)) {
mpv_detach_destroy(client->client);
- close(client->client_fd);
+ if (client->close_client_fd)
+ close(client->client_fd);
talloc_free(client);
}
}
@@ -641,6 +644,7 @@ static void ipc_start_client_json(struct mp_ipc_ctx *ctx, int id, int fd)
*client = (struct client_arg){
.client_name = talloc_asprintf(client, "ipc-%d", id),
.client_fd = fd,
+ .close_client_fd = true,
.writable = true,
};
@@ -651,11 +655,19 @@ static void ipc_start_client_json(struct mp_ipc_ctx *ctx, int id, int fd)
static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path)
{
int mode = O_RDONLY;
- // Use RDWR for FIFOs to ensure they stay open over multiple accesses.
- struct stat st;
- if (stat(path, &st) == 0 && S_ISFIFO(st.st_mode))
- mode = O_RDWR;
- int client_fd = open(path, mode);
+ int client_fd = -1;
+ bool close_client_fd = true;
+
+ if (strcmp(path, "/dev/stdin") == 0) { // for symmetry with Linux
+ client_fd = STDIN_FILENO;
+ close_client_fd = false;
+ } else {
+ // Use RDWR for FIFOs to ensure they stay open over multiple accesses.
+ struct stat st;
+ if (stat(path, &st) == 0 && S_ISFIFO(st.st_mode))
+ mode = O_RDWR;
+ client_fd = open(path, mode);
+ }
if (client_fd < 0) {
MP_ERR(ctx, "Could not open pipe at '%s'\n", path);
return;
@@ -665,6 +677,7 @@ static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path)
*client = (struct client_arg){
.client_name = "input-file",
.client_fd = client_fd,
+ .close_client_fd = close_client_fd,
.writable = false,
};