diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2021-07-21 12:52:23 +0000 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2021-07-21 17:55:55 +0200 |
commit | 33d8cecfe1ce64c517fe995875397b32e534bdb0 (patch) | |
tree | 3a244bd33cb987d1992e719cf0f3739a836b5fcd | |
parent | 7325a8629ebd718fe3546fc4105ffeeacd83232a (diff) |
#1051 Fix command schedule for several clients
A single command can be schedule for several clients.
Commit 141b0797e1 introduces a regression when scheduling a command for
several clients, the command only executes successfuly for the first
one.
Fix it by reintroducing the usage of the 'session' column to group
a single command into several actions (one for each client), the web
console interface already expects this 'session' column to be set
accordingly.
-rw-r--r-- | src/rest.c | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -2979,7 +2979,7 @@ static int og_dbi_queue_command(struct og_dbi *dbi, uint32_t task_id, result = dbi_conn_queryf(dbi->conn, "SELECT idaccion, idcentro, idordenador, parametros " "FROM acciones " - "WHERE idaccion = %u", task_id); + "WHERE sesion = %u", task_id); if (!result) { dbi_conn_error(dbi->conn, &msglog); syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", @@ -4701,13 +4701,13 @@ static int og_cmd_post_schedule_command(json_t *element, "INNER JOIN aulas AS a ON o.idaula = a.idaula " "INNER JOIN centros AS c ON a.idcentro = c.idcentro " "WHERE o.ip = '%s';"; + uint32_t sequence, session = 0; int center_id, client_id, len; struct og_cmd_json cmd = {}; const char *legacy_params; const char *key, *msglog; struct og_dbi *dbi; char task_id[128]; - uint32_t sequence; bool when = false; dbi_result result; json_t *value; @@ -4819,6 +4819,26 @@ static int og_cmd_post_schedule_command(json_t *element, dbi_result_free(result); sequence = dbi_conn_sequence_last(dbi->conn, NULL); + + /* This 'session' ID allows us to correlate the schedule with + * the commands after expansion. + */ + if (!session) + session = dbi_conn_sequence_last(dbi->conn, NULL); + + result = dbi_conn_queryf(dbi->conn, "UPDATE acciones SET idordenador=%d, " + "idcentro=%d, parametros='%s', sesion=%d" + "WHERE idaccion=%d", + client_id, center_id, legacy_params, + session, sequence); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + goto err_dbi_result; + } + dbi_result_free(result); + len = snprintf(task_id, sizeof(sequence), "%d", sequence); if (len >= (int)sizeof(task_id)) { syslog(LOG_ERR, "truncated snprintf (%s:%d)\n", @@ -4826,9 +4846,10 @@ static int og_cmd_post_schedule_command(json_t *element, goto err_dbi; } params->task_id = task_id; - og_task_schedule_create(params); } + og_task_schedule_create(params); + free((char *)legacy_params); og_dbi_close(dbi); return 0; |