diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-10-18 01:00:42 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-10-18 01:00:42 +0200 |
commit | d9a5267fceca6f46ee3005f7624fa92786a3c9b1 (patch) | |
tree | 0a4b802923116de816b1b16bfa9cafa6c9284a09 /src | |
parent | e9b472dc9e31def5c8559c6d007fdf770d99d308 (diff) | |
download | fastd-d9a5267fceca6f46ee3005f7624fa92786a3c9b1.tar fastd-d9a5267fceca6f46ee3005f7624fa92786a3c9b1.zip |
status: ensure that the status socket is unlinked when fastd exits with an error
Diffstat (limited to 'src')
-rw-r--r-- | src/status.c | 21 |
1 files 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 */ |