diff options
author | Kenny Levinsen <kl@kl.wtf> | 2020-08-31 22:44:02 +0200 |
---|---|---|
committer | Kenny Levinsen <kl@kl.wtf> | 2020-08-31 23:13:16 +0200 |
commit | 5b8117f3d4ad767e5ddb8e202c938bc2e0174ffb (patch) | |
tree | 33192ba1acf09f19ec7b9a35e3e96358ae25741d | |
parent | c9ce7c71aa80769033b556d1c486da81c2fda551 (diff) |
client: Do not leak idle clients on exit
-rw-r--r-- | include/server.h | 1 | ||||
-rw-r--r-- | libseat/backend/seatd.c | 2 | ||||
-rw-r--r-- | seatd/client.c | 2 | ||||
-rw-r--r-- | seatd/server.c | 7 |
4 files changed, 11 insertions, 1 deletions
diff --git a/include/server.h b/include/server.h index 587047e..488915c 100644 --- a/include/server.h +++ b/include/server.h @@ -13,6 +13,7 @@ struct server { struct poller poller; struct linked_list seats; + struct linked_list idle_clients; }; int server_init(struct server *server); diff --git a/libseat/backend/seatd.c b/libseat/backend/seatd.c index 400b357..fd424b5 100644 --- a/libseat/backend/seatd.c +++ b/libseat/backend/seatd.c @@ -599,7 +599,7 @@ static struct libseat *builtin_open_seat(struct libseat_seat_listener *listener, if (poller_poll(&server.poller) == -1) { log_errorf("Could not poll server socket: %s", strerror(errno)); res = 1; - goto server_error; + break; } } server_error: diff --git a/seatd/client.c b/seatd/client.c index d658454..bd46a86 100644 --- a/seatd/client.c +++ b/seatd/client.c @@ -138,6 +138,7 @@ static int handle_open_seat(struct client *client) { return -1; } + linked_list_remove(&client->link); if (seat_add_client(seat, client) == -1) { log_errorf("unable to add client to target seat: %s", strerror(errno)); return -1; @@ -174,6 +175,7 @@ static int handle_close_seat(struct client *client) { log_error("unable to remove client from seat"); return -1; } + linked_list_insert(&client->server->idle_clients, &client->link); struct proto_header header = { .opcode = SERVER_SEAT_CLOSED, diff --git a/seatd/server.c b/seatd/server.c index 9a71d66..1da8041 100644 --- a/seatd/server.c +++ b/seatd/server.c @@ -26,6 +26,7 @@ int server_init(struct server *server) { poller_init(&server->poller); linked_list_init(&server->seats); + linked_list_init(&server->idle_clients); if (poller_add_signal(&server->poller, SIGUSR1, server_handle_vt_rel, server) == NULL || poller_add_signal(&server->poller, SIGUSR2, server_handle_vt_acq, server) == NULL || @@ -51,6 +52,11 @@ int server_init(struct server *server) { void server_finish(struct server *server) { assert(server); + while (!linked_list_empty(&server->idle_clients)) { + struct client *client = (struct client *)server->idle_clients.next; + linked_list_remove(&client->link); + client_destroy(client); + } while (!linked_list_empty(&server->seats)) { struct seat *seat = (struct seat *)server->seats.next; linked_list_remove(&seat->link); @@ -131,6 +137,7 @@ int server_add_client(struct server *server, int fd) { } 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; } |