seat: Destroy all clients on teardown

This commit is contained in:
Kenny Levinsen 2020-08-29 23:49:22 +02:00
parent b7b28f0628
commit 5470c48113
3 changed files with 5 additions and 17 deletions

View file

@ -28,7 +28,6 @@ struct client {
}; };
struct client *client_create(struct server *server, int client_fd); struct client *client_create(struct server *server, int client_fd);
void client_kill(struct client *client);
void client_destroy(struct client *client); void client_destroy(struct client *client);
int client_handle_connection(int fd, uint32_t mask, void *data); int client_handle_connection(int fd, uint32_t mask, void *data);

View file

@ -72,19 +72,13 @@ struct client *client_create(struct server *server, int client_fd) {
return client; return client;
} }
void client_kill(struct client *client) {
assert(client);
if (client->connection.fd != -1) {
shutdown(client->connection.fd, SHUT_RDWR);
};
if (client->seat != NULL) {
seat_remove_client(client);
}
}
void client_destroy(struct client *client) { void client_destroy(struct client *client) {
assert(client); assert(client);
client->server = NULL; client->server = NULL;
if (client->connection.fd != -1) {
close(client->connection.fd);
client->connection.fd = -1;
}
if (client->seat != NULL) { if (client->seat != NULL) {
// This should also close and remove all devices // This should also close and remove all devices
seat_remove_client(client); seat_remove_client(client);
@ -93,10 +87,6 @@ void client_destroy(struct client *client) {
event_source_fd_destroy(client->event_source); event_source_fd_destroy(client->event_source);
client->event_source = NULL; client->event_source = NULL;
} }
if (client->connection.fd != -1) {
close(client->connection.fd);
client->connection.fd = -1;
}
connection_close_fds(&client->connection); connection_close_fds(&client->connection);
assert(linked_list_empty(&client->devices)); assert(linked_list_empty(&client->devices));
free(client); free(client);

View file

@ -39,9 +39,8 @@ void seat_destroy(struct seat *seat) {
assert(seat); assert(seat);
while (!linked_list_empty(&seat->clients)) { while (!linked_list_empty(&seat->clients)) {
struct client *client = (struct client *)seat->clients.next; struct client *client = (struct client *)seat->clients.next;
// This will cause the client to remove itself from the seat
assert(client->seat == seat); assert(client->seat == seat);
client_kill(client); client_destroy(client);
} }
assert(seat->curttyfd == -1); assert(seat->curttyfd == -1);