summaryrefslogtreecommitdiffstats
path: root/discover/discover-server.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-10-15 10:25:23 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-10-15 11:19:55 +0800
commiteb2e788746da67787e1a43d7fccfa11ca26efae5 (patch)
treea513b77dbea1c02c34e928eec9837b334e57bd61 /discover/discover-server.c
parent2312c424d516862877c45a9566816acfe2da0f06 (diff)
downloadpetitboot-eb2e788746da67787e1a43d7fccfa11ca26efae5.zip
petitboot-eb2e788746da67787e1a43d7fccfa11ca26efae5.tar.gz
discover: Don't free clients on write failure
Currently, if we see an error when writing to a client, we free the client immediately. This means that any pending reads will be discarded. Additionally, if a client disconnects before we have finished the writes in discover_server_process_connection, we won't register the waiter to read from the socket. Instead of freeing the client on write failure, this change sets a flag (se we don't continue to write), and we rely on the read EOF to free the client. This means we don't drop incoming messages. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/discover-server.c')
-rw-r--r--discover/discover-server.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/discover/discover-server.c b/discover/discover-server.c
index 25dbd14..2467e33 100644
--- a/discover/discover-server.c
+++ b/discover/discover-server.c
@@ -34,6 +34,7 @@ struct client {
struct list_item list;
struct waiter *waiter;
int fd;
+ bool remote_closed;
};
@@ -89,9 +90,12 @@ static int client_write_message(
{
int rc;
+ if (client->remote_closed)
+ return -1;
+
rc = pb_protocol_write_message(client->fd, message);
if (rc)
- talloc_free(client);
+ client->remote_closed = true;
return rc;
}
@@ -250,6 +254,9 @@ static int discover_server_process_connection(void *arg)
client->fd = fd;
client->server = server;
+ client->waiter = waiter_register_io(server->waitset, client->fd,
+ WAIT_IN, discover_server_process_message,
+ client);
/* send sysinfo to client */
rc = write_system_info_message(server, client, system_info_get());
@@ -275,10 +282,6 @@ static int discover_server_process_connection(void *arg)
}
}
- client->waiter = waiter_register_io(server->waitset, client->fd,
- WAIT_IN, discover_server_process_message,
- client);
-
return 0;
}
OpenPOWER on IntegriCloud