From 55e3dab7ebd707a94995696aa1098725f3c35521 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 24 Oct 2014 21:52:16 +0200 Subject: 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. --- player/command.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'player/command.c') 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) -- cgit v1.2.3