mirror of https://github.com/mpv-player/mpv
ipc: make sure --input-file=/dev/stdin always works
It's not necessarily available on Unix systems other than Linux (sigh).
This commit is contained in:
parent
97b4b4c8e0
commit
c920a3920e
27
input/ipc.c
27
input/ipc.c
|
@ -58,6 +58,7 @@ struct client_arg {
|
||||||
|
|
||||||
char *client_name;
|
char *client_name;
|
||||||
int client_fd;
|
int client_fd;
|
||||||
|
bool close_client_fd;
|
||||||
|
|
||||||
bool writable;
|
bool writable;
|
||||||
|
|
||||||
|
@ -616,7 +617,8 @@ static void *client_thread(void *p)
|
||||||
|
|
||||||
done:
|
done:
|
||||||
talloc_free(client_msg.start);
|
talloc_free(client_msg.start);
|
||||||
close(arg->client_fd);
|
if (arg->close_client_fd)
|
||||||
|
close(arg->client_fd);
|
||||||
mpv_detach_destroy(arg->client);
|
mpv_detach_destroy(arg->client);
|
||||||
talloc_free(arg);
|
talloc_free(arg);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -630,7 +632,8 @@ static void ipc_start_client(struct mp_ipc_ctx *ctx, struct client_arg *client)
|
||||||
pthread_t client_thr;
|
pthread_t client_thr;
|
||||||
if (pthread_create(&client_thr, NULL, client_thread, client)) {
|
if (pthread_create(&client_thr, NULL, client_thread, client)) {
|
||||||
mpv_detach_destroy(client->client);
|
mpv_detach_destroy(client->client);
|
||||||
close(client->client_fd);
|
if (client->close_client_fd)
|
||||||
|
close(client->client_fd);
|
||||||
talloc_free(client);
|
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 = (struct client_arg){
|
||||||
.client_name = talloc_asprintf(client, "ipc-%d", id),
|
.client_name = talloc_asprintf(client, "ipc-%d", id),
|
||||||
.client_fd = fd,
|
.client_fd = fd,
|
||||||
|
.close_client_fd = true,
|
||||||
|
|
||||||
.writable = 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)
|
static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path)
|
||||||
{
|
{
|
||||||
int mode = O_RDONLY;
|
int mode = O_RDONLY;
|
||||||
// Use RDWR for FIFOs to ensure they stay open over multiple accesses.
|
int client_fd = -1;
|
||||||
struct stat st;
|
bool close_client_fd = true;
|
||||||
if (stat(path, &st) == 0 && S_ISFIFO(st.st_mode))
|
|
||||||
mode = O_RDWR;
|
if (strcmp(path, "/dev/stdin") == 0) { // for symmetry with Linux
|
||||||
int client_fd = open(path, mode);
|
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) {
|
if (client_fd < 0) {
|
||||||
MP_ERR(ctx, "Could not open pipe at '%s'\n", path);
|
MP_ERR(ctx, "Could not open pipe at '%s'\n", path);
|
||||||
return;
|
return;
|
||||||
|
@ -665,6 +677,7 @@ static void ipc_start_client_text(struct mp_ipc_ctx *ctx, const char *path)
|
||||||
*client = (struct client_arg){
|
*client = (struct client_arg){
|
||||||
.client_name = "input-file",
|
.client_name = "input-file",
|
||||||
.client_fd = client_fd,
|
.client_fd = client_fd,
|
||||||
|
.close_client_fd = close_client_fd,
|
||||||
|
|
||||||
.writable = false,
|
.writable = false,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue