summaryrefslogtreecommitdiffstats
path: root/src/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c
index 5842372..bc66b4b 100644
--- a/src/client.c
+++ b/src/client.c
@@ -1274,8 +1274,49 @@ static int og_agent_http_response_code(const char *buf)
return -1;
}
+static int og_clear_image_placeholder()
+{
+ uint32_t image_id = 0;
+ struct og_dbi *dbi;
+ dbi_result result;
+
+ dbi = og_dbi_open(&ogconfig.db);
+ if (!dbi) {
+ syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
+ __func__, __LINE__);
+ return -1;
+ }
+
+ result = dbi_conn_queryf(dbi->conn,
+ "SELECT idimagen FROM imagenes WHERE fechacreacion IS NULL");
+ if (!result) {
+ syslog(LOG_ERR, "failed to query database\n");
+ return -1;
+ }
+
+ if (!dbi_result_next_row(result)) {
+ dbi_result_free(result);
+ og_dbi_close(dbi);
+ return 0;
+ }
+
+ image_id = dbi_result_get_uint(result, "idimagen");
+ dbi_result_free(result);
+
+ syslog(LOG_INFO, "Trying to delete uninitialized image with id %d\n", image_id);
+
+ if (og_dbi_delete_image(dbi, image_id) < 0) {
+ og_dbi_close(dbi);
+ return -1;
+ }
+
+ og_dbi_close(dbi);
+ return 0;
+}
+
int og_agent_state_process_response(struct og_client *cli)
{
+ enum og_cmd_type cmd_type = cli->last_cmd;
int ret, err = -1, code;
json_error_t json_err;
bool success;
@@ -1326,6 +1367,9 @@ int og_agent_state_process_response(struct og_client *cli)
else
cli->last_cmd_result = OG_FAILURE;
+ if (!success && cmd_type == OG_CMD_IMAGE_CREATE)
+ og_clear_image_placeholder();
+
if (code != 200 && code != 103) {
cli->last_cmd_id = 0;
return ret;