client: More robust handling of client links
This commit is contained in:
parent
df8494af61
commit
e0782a825e
3 changed files with 6 additions and 14 deletions
|
@ -70,6 +70,7 @@ struct client *client_create(struct server *server, int client_fd) {
|
|||
client->server = server;
|
||||
client->connection.fd = client_fd;
|
||||
linked_list_init(&client->devices);
|
||||
linked_list_insert(&server->idle_clients, &client->link);
|
||||
return client;
|
||||
}
|
||||
|
||||
|
@ -80,14 +81,9 @@ void client_destroy(struct client *client) {
|
|||
close(client->connection.fd);
|
||||
client->connection.fd = -1;
|
||||
}
|
||||
if (client->seat != NULL) {
|
||||
// This should also close and remove all devices. This unlinks
|
||||
// the client.
|
||||
seat_remove_client(client);
|
||||
} else {
|
||||
// If we are not a member of a seat, we will be on the idle
|
||||
// clients list, so unlink the client manually.
|
||||
linked_list_remove(&client->link);
|
||||
if (client->seat != NULL) {
|
||||
seat_remove_client(client);
|
||||
}
|
||||
if (client->event_source != NULL) {
|
||||
event_source_fd_destroy(client->event_source);
|
||||
|
@ -149,6 +145,7 @@ static int handle_open_seat(struct client *client) {
|
|||
log_errorf("unable to add client to target seat: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
linked_list_insert(&seat->clients, &client->link);
|
||||
|
||||
size_t seat_name_len = strlen(seat_name);
|
||||
|
||||
|
@ -177,6 +174,7 @@ static int handle_close_seat(struct client *client) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
linked_list_remove(&client->link);
|
||||
if (seat_remove_client(client) == -1) {
|
||||
log_error("unable to remove client from seat");
|
||||
return -1;
|
||||
|
|
|
@ -149,9 +149,8 @@ int seat_add_client(struct seat *seat, struct client *client) {
|
|||
log_debugf("registered client %p as session %d", (void *)client, client->session);
|
||||
|
||||
client->seat = seat;
|
||||
|
||||
linked_list_insert(&seat->clients, &client->link);
|
||||
log_debug("added client");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -160,10 +159,6 @@ int seat_remove_client(struct client *client) {
|
|||
assert(client->seat);
|
||||
|
||||
struct seat *seat = client->seat;
|
||||
|
||||
// We must first remove the client to avoid reactivation
|
||||
linked_list_remove(&client->link);
|
||||
|
||||
if (seat->next_client == client) {
|
||||
seat->next_client = NULL;
|
||||
}
|
||||
|
|
|
@ -132,13 +132,12 @@ int server_add_client(struct server *server, int fd) {
|
|||
client->event_source =
|
||||
poller_add_fd(&server->poller, fd, EVENT_READABLE, client_handle_connection, client);
|
||||
if (client->event_source == NULL) {
|
||||
client_destroy(client);
|
||||
log_errorf("could not add client socket to poller: %s", strerror(errno));
|
||||
client_destroy(client);
|
||||
return -1;
|
||||
}
|
||||
log_infof("new client connected (pid: %d, uid: %d, gid: %d)", client->pid, client->uid,
|
||||
client->gid);
|
||||
linked_list_insert(&server->idle_clients, &client->link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue