diff options
author | Kenny Levinsen <kl@kl.wtf> | 2022-02-21 11:37:26 +0100 |
---|---|---|
committer | Kenny Levinsen <kl@kl.wtf> | 2022-02-21 12:02:31 +0100 |
commit | 0864f6a3ac8ca8263490269ecc7fdf4c1cd59850 (patch) | |
tree | 530f1de759a1b8eed1019e03df8d9e14265bf0f2 | |
parent | 157ce685658c19b51caa091601240940267c0940 (diff) |
seatd: Ensure socket gets unlinked on error
-rw-r--r-- | seatd/seatd.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/seatd/seatd.c b/seatd/seatd.c index 8480350..c2ce411 100644 --- a/seatd/seatd.c +++ b/seatd/seatd.c @@ -145,22 +145,21 @@ int main(int argc, char *argv[]) { struct server server = {0}; if (server_init(&server) == -1) { - log_errorf("server_create failed: %s", strerror(errno)); + log_errorf("server_init failed: %s", strerror(errno)); return 1; } + int ret = 1; int socket_fd = open_socket(socket_path, uid, gid); if (socket_fd == -1) { log_error("Could not create server socket"); - server_finish(&server); - return 1; + goto error_server; } if (poller_add_fd(&server.poller, socket_fd, EVENT_READABLE, server_handle_connection, &server) == NULL) { log_errorf("Could not add socket to poller: %s", strerror(errno)); close(socket_fd); - server_finish(&server); - return 1; + goto error_socket; } log_info("seatd started"); @@ -175,12 +174,16 @@ int main(int argc, char *argv[]) { while (server.running) { if (poller_poll(&server.poller) == -1) { log_errorf("Poller failed: %s", strerror(errno)); - return 1; + goto error_socket; } } - server_finish(&server); + ret = 0; + +error_socket: unlink(socket_path); +error_server: + server_finish(&server); log_info("seatd stopped"); - return 0; + return ret; } |