summaryrefslogtreecommitdiff
path: root/event-httpd.c
diff options
context:
space:
mode:
authorRussell King <rmk@armlinux.org.uk>2021-09-11 13:57:42 +0100
committerRussell King <rmk@armlinux.org.uk>2021-09-11 13:57:42 +0100
commit2f45bcf78b77193ad6107fbb92ad0f93eb1ad4fc (patch)
tree18b115356a92e67e2276a2dbe97139d2237c0f24 /event-httpd.c
parentacc52e700121120726b42a6dadd8c12f030ba349 (diff)
Restrict updates to the newest updater
Prevent old update connections from providing updates, closing them if they attempt an update. In doing so, this also limits resource usage when we have multiple updaters connected (which should never happen.) Signed-off-by: Russell King <rmk@armlinux.org.uk>
Diffstat (limited to 'event-httpd.c')
-rw-r--r--event-httpd.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/event-httpd.c b/event-httpd.c
index 27590dd..865f82f 100644
--- a/event-httpd.c
+++ b/event-httpd.c
@@ -97,19 +97,28 @@ static void update(GObject *source, GAsyncResult *res, gpointer user_data)
GError *error = NULL;
char *line;
gsize len;
+ int r;
line = g_data_input_stream_read_line_finish(c->data, res, &len, &error);
if (error || !line) {
+ if (c->resource->ops->update_close)
+ c->resource->ops->update_close(c, c->resource);
+
if (error)
g_free(error);
close_client(c);
return;
}
- c->resource->ops->update(c, c->resource, line);
+ r = c->resource->ops->update(c, c->resource, line);
g_free(line);
+ // If the update function returns an error, close this connection.
+ // This could be because we have a "newer" updater, or an error.
+ if (r == -1)
+ close_client(c);
+
g_data_input_stream_read_line_async(c->data, 0, NULL, update, c);
}
@@ -257,6 +266,9 @@ static void receive(GObject *source, GAsyncResult *res, gpointer user_data)
return;
}
+ if (resource->ops->update_open)
+ resource->ops->update_open(c, resource);
+
g_data_input_stream_read_line_async(c->data, 0, NULL,
update, c);
break;