summaryrefslogtreecommitdiffstats
path: root/discover/discover-server.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-05-16 16:09:37 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-05-21 15:28:33 +0800
commit556e622653c72de9b3eda70995e9f8619ee1c9a1 (patch)
treea74d8ba085941497f8d494ad0c9bdf74b07b0cb2 /discover/discover-server.c
parentd28c07b5e23237a97387435e157e248e19128598 (diff)
downloadtalos-petitboot-556e622653c72de9b3eda70995e9f8619ee1c9a1.tar.gz
talos-petitboot-556e622653c72de9b3eda70995e9f8619ee1c9a1.zip
discover: destroy client if message read failed
When a client disconnects, the read from the client's fd will return EOF. We should destroy the client in this situation. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/discover-server.c')
-rw-r--r--discover/discover-server.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/discover/discover-server.c b/discover/discover-server.c
index ca20113..138551a 100644
--- a/discover/discover-server.c
+++ b/discover/discover-server.c
@@ -31,6 +31,7 @@ struct discover_server {
struct client {
struct discover_server *server;
struct list_item list;
+ struct waiter *waiter;
int fd;
};
@@ -55,6 +56,9 @@ static int client_destructor(void *arg)
if (client->fd >= 0)
close(client->fd);
+ if (client->waiter)
+ waiter_remove(client->waiter);
+
list_remove(&client->list);
return 0;
@@ -172,8 +176,11 @@ static int discover_server_process_message(void *arg)
message = pb_protocol_read_message(client, client->fd);
- if (!message)
+ if (!message) {
+ talloc_free(client);
return 0;
+ }
+
if (message->action != PB_PROTOCOL_ACTION_BOOT) {
pb_log("%s: invalid action %d\n", __func__, message->action);
@@ -207,7 +214,7 @@ static int discover_server_process_connection(void *arg)
}
/* add to our list of clients */
- client = talloc(server, struct client);
+ client = talloc_zero(server, struct client);
list_add(&server->clients, &client->list);
talloc_set_destructor(client, client_destructor);
@@ -229,8 +236,8 @@ static int discover_server_process_connection(void *arg)
opt->option);
}
- waiter_register(server->waitset, client->fd, WAIT_IN,
- discover_server_process_message, client);
+ client->waiter = waiter_register(server->waitset, client->fd, WAIT_IN,
+ discover_server_process_message, client);
return 0;
}
OpenPOWER on IntegriCloud