From 2d68f8a0ec04b1f7700dce6bc0635c3bce516453 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Mon, 6 Sep 2021 10:24:19 +0000 Subject: #1061 add timeout to pending scheduled commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pending schedule commands can deny ogLive boot of clients due to filling of pending cmd queue with commands such as "Iniciar Sesión". For example: Using RemotePC to serve clients that do not boot into ogLive will fill up the pending command queue with "Iniciar Sesión". Introduce a safety timeout for pending (scheduled) commands to avoid this situation. --- src/core.c | 11 +++++++++++ src/rest.c | 1 + src/rest.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/core.c b/src/core.c index 6aa9b5c..9fe83bf 100644 --- a/src/core.c +++ b/src/core.c @@ -186,14 +186,25 @@ static void og_agent_reset_state(struct og_client *cli) memset(cli->buf, 0, sizeof(cli->buf)); } +#define OG_AGENT_CMD_TIMEOUT 900 + static void og_agent_deliver_pending_cmd(struct og_client *cli) { + struct timeval now, elapsed; const struct og_cmd *cmd; cmd = og_cmd_find(inet_ntoa(cli->addr.sin_addr)); if (!cmd) return; + gettimeofday(&now, NULL); + timersub(&now, &cmd->tv, &elapsed); + if (elapsed.tv_sec >= OG_AGENT_CMD_TIMEOUT) { + og_dbi_update_action(cmd->id, false); + og_cmd_free(cmd); + return; + } + og_send_request(cmd->method, cmd->type, &cmd->params, cmd->json); cli->last_cmd_id = cmd->id; diff --git a/src/rest.c b/src/rest.c index 41738ea..0835f68 100644 --- a/src/rest.c +++ b/src/rest.c @@ -2323,6 +2323,7 @@ static void og_cmd_init(struct og_cmd *cmd, enum og_rest_method method, cmd->params.ips_array[0] = strdup(cmd->ip); cmd->params.ips_array_len = 1; cmd->json = root; + gettimeofday(&cmd->tv, NULL); } static int og_cmd_legacy_wol(const char *input, struct og_cmd *cmd) diff --git a/src/rest.h b/src/rest.h index 43ddd66..9c4f5e8 100644 --- a/src/rest.h +++ b/src/rest.h @@ -2,6 +2,7 @@ #define OG_REST_H #include +#include extern struct ev_loop *og_loop; @@ -89,6 +90,7 @@ struct og_cmd { enum og_rest_method method; struct og_msg_params params; json_t *json; + struct timeval tv; }; const struct og_cmd *og_cmd_find(const char *client_ip); -- cgit v1.2.3-18-g5258