From 3a0ccd3b3154af129ce087abf69e83af71f0c005 Mon Sep 17 00:00:00 2001 From: Bogomil Vasilev Date: Fri, 16 Feb 2018 14:23:41 +0200 Subject: [PATCH] Set atexit once. Next time, RTFM. --- rmps.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/rmps.c b/rmps.c index 7c7577d..8516cd9 100644 --- a/rmps.c +++ b/rmps.c @@ -141,6 +141,7 @@ static void spawn_pidfile(const char *pidfile) log(ERROR, "Could not create PID file %s - Exiting!", pidfile); exit(EXIT_FAILURE); } + atexit(cleanup); /* Try to lock file */ if (lockf(pid_file_handle, F_TLOCK, 0) == -1) { @@ -174,27 +175,23 @@ static int open_listener(int port) addr.sin_addr.s_addr = INADDR_ANY; sd = socket(addr.sin_family, SOCK_STREAM, 0); if (sd < 0) { - log(ERROR, "Failed to create socket"); - goto exit; + log(ERROR, "Failed to create socket - Aborting RMPS..."); + exit(EXIT_FAILURE); } if (set_reuse_addr(sd) < 0) { log(ERROR, - "Failed to set reuse on address - Aborting...", port); - goto exit; + "Failed to set reuse on address - Aborting RMPS...", port); + exit(EXIT_FAILURE); } if (bind(sd, (struct sockaddr *)&addr, sizeof(addr)) != 0) { - log(ERROR, "Failed to bind on port: %d - Aborting...", port); - goto exit; + log(ERROR, "Failed to bind on port: %d - Aborting RMPS...", port); + exit(EXIT_FAILURE); } if (listen(sd, 10) != 0) { - log(ERROR, "Failed to start listener on port %d - Aborting...", - port); - goto exit; + log(ERROR, "Failed to start listener on port %d - Aborting RMPS...", port); + exit(EXIT_FAILURE); } return sd; -exit: - log(INFO, "RMPS failed to start, shutting down..."); - atexit(cleanup); } /* Init server and create context */ @@ -238,21 +235,21 @@ void load_certificates(SSL_CTX *ctx, const char *certfile, log(ERROR, "Failed to load certfile! SSL error below:"); log_ssl(); log(INFO, "RMPS failed to start, shutting down..."); - atexit(cleanup); + exit(EXIT_FAILURE); } /* set the private key from KeyFile (may be the same as CertFile) */ if (SSL_CTX_use_PrivateKey_file(ctx, keyfile, SSL_FILETYPE_PEM) <= 0) { log(ERROR, "Failed to load keyfile! SSL error below:"); log_ssl(); log(INFO, "RMPS failed to start, shutting down..."); - atexit(cleanup); + exit(EXIT_FAILURE); } /* verify private key */ if (!SSL_CTX_check_private_key(ctx)) { log(ERROR, "Private key does not match the public certificate."); log(INFO, "RMPS failed to start, shutting down..."); - atexit(cleanup); + exit(EXIT_FAILURE); } if (cafile != NULL) { SSL_CTX_set_client_CA_list(ctx, @@ -308,8 +305,7 @@ void launch_rmps(struct conf_table *conf, int fork_flag) if (start_job_queue(conf->rmps.agent_poolsize) == FAIL) { log(ERROR, "On start_job_queue(), RMPS failed to start, shutting down..."); - atexit(cleanup); - return; + exit(EXIT_FAILURE); } pthread_join(pool[0], NULL); pthread_join(pool[1], NULL);