summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-24 21:52:16 +0200
committerwm4 <wm4@nowhere>2014-10-24 21:57:02 +0200
commit55e3dab7ebd707a94995696aa1098725f3c35521 (patch)
tree3b0bc9c4bde577869468d4e76e90fcda5c1567a4 /player/command.c
parentb330f16fed152ea401c13b3b453604392aaf6bc5 (diff)
downloadmpv-55e3dab7ebd707a94995696aa1098725f3c35521.tar.bz2
mpv-55e3dab7ebd707a94995696aa1098725f3c35521.tar.xz
command: finish hook execution if client fails
Translation: if the (to be added) youtube-dl Lua script crashes, don't wait forever when opening something.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/player/command.c b/player/command.c
index 1109e7ac7f..7584ef024e 100644
--- a/player/command.c
+++ b/player/command.c
@@ -112,13 +112,26 @@ static int edit_filters(struct MPContext *mpctx, enum stream_type mediatype,
static int set_filters(struct MPContext *mpctx, enum stream_type mediatype,
struct m_obj_settings *new_chain);
+static void hook_remove(struct MPContext *mpctx, int index)
+{
+ struct command_ctx *cmd = mpctx->command_ctx;
+ assert(index >= 0 && index < cmd->num_hooks);
+ talloc_free(cmd->hooks[index]);
+ MP_TARRAY_REMOVE_AT(cmd->hooks, cmd->num_hooks, index);
+}
+
bool mp_hook_test_completion(struct MPContext *mpctx, char *type)
{
struct command_ctx *cmd = mpctx->command_ctx;
for (int n = 0; n < cmd->num_hooks; n++) {
struct hook_handler *h = cmd->hooks[n];
- if (h->active && strcmp(h->type, type) == 0)
+ if (h->active && strcmp(h->type, type) == 0) {
+ if (!mp_client_exists(mpctx, h->client)) {
+ hook_remove(mpctx, n);
+ break;
+ }
return false;
+ }
}
return true;
}
@@ -142,8 +155,8 @@ static bool send_hook_msg(struct MPContext *mpctx, struct hook_handler *h,
void mp_hook_run(struct MPContext *mpctx, char *client, char *type)
{
struct command_ctx *cmd = mpctx->command_ctx;
- struct hook_handler *next = NULL;
bool found_current = !client;
+ int index = -1;
for (int n = 0; n < cmd->num_hooks; n++) {
struct hook_handler *h = cmd->hooks[n];
if (!found_current) {
@@ -152,15 +165,19 @@ void mp_hook_run(struct MPContext *mpctx, char *client, char *type)
found_current = true;
}
} else if (strcmp(h->type, type) == 0) {
- next = h;
+ index = n;
break;
}
}
- if (!next)
+ if (index < 0)
return;
+ struct hook_handler *next = cmd->hooks[index];
MP_VERBOSE(mpctx, "Running hook: %s/%s\n", next->client, type);
next->active = true;
- send_hook_msg(mpctx, next, "hook_run");
+ if (!send_hook_msg(mpctx, next, "hook_run")) {
+ hook_remove(mpctx, index);
+ mp_input_wakeup(mpctx->input); // repeat next iteration to finish
+ }
}
static int compare_hook(const void *pa, const void *pb)