From d9a5267fceca6f46ee3005f7624fa92786a3c9b1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 18 Oct 2015 01:00:42 +0200 Subject: status: ensure that the status socket is unlinked when fastd exits with an error --- src/status.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/status.c b/src/status.c index 988b46f..80ce203 100644 --- a/src/status.c +++ b/src/status.c @@ -208,6 +208,14 @@ static void dump_status(int fd) { } } +static void unlink_status_socket(void) { + if (!conf.status_socket || ctx.status_fd.fd < 0) + return; + + if (unlink(conf.status_socket)) + pr_warn_errno("fastd_status_cleanup: unlink"); +} + /** Initialized the status socket */ void fastd_status_init(void) { if (!conf.status_socket) { @@ -252,6 +260,12 @@ void fastd_status_init(void) { } } + if (atexit(unlink_status_socket)) { + pr_error_errno("atexit"); + unlink_status_socket(); + exit(1); + } + if (listen(ctx.status_fd.fd, 4)) exit_errno("fastd_status_init: listen"); @@ -268,14 +282,15 @@ void fastd_status_init(void) { /** Closes the status socket */ void fastd_status_close(void) { - if (!conf.status_socket) + if (!conf.status_socket || ctx.status_fd.fd < 0) return; if (!fastd_poll_fd_close(&ctx.status_fd)) pr_warn_errno("fastd_status_cleanup: close"); - if (unlink(conf.status_socket)) - pr_warn_errno("fastd_status_cleanup: unlink"); + unlink_status_socket(); + + ctx.status_fd.fd = -1; } /** Handles a single connection on the status socket */ -- cgit v1.2.3