Renamed log_trace() to log()

This commit is contained in:
2016-08-10 20:21:54 +03:00
parent 65b923cba8
commit dcd7a46d0a
10 changed files with 100 additions and 97 deletions

68
rmps.c
View File

@@ -1,4 +1,4 @@
#include "log_trace.h"
#include "log.h"
#include "confparser.h"
#include "thread_pool.h"
#include "rmps.h"
@@ -27,9 +27,9 @@ static int pid_file_handle;
static void cleanup(void)
{
log_trace(VERBOSE, "Deleting pidfile %s", conf.rmps.pidfile);
log(VERBOSE, "Deleting pidfile %s", conf.rmps.pidfile);
if (unlink(conf.rmps.pidfile) != 0)
log_trace( WARNING,
log( WARNING,
"Failed to delete pidfile %s. Reason code: %d",
conf.rmps.pidfile, errno );
}
@@ -38,18 +38,18 @@ static void signal_handler(int sig)
{
switch (sig) {
case SIGHUP:
log_trace(WARNING, "Received SIGHUP signal. Ignoring...");
log(WARNING, "Received SIGHUP signal. Ignoring...");
break;
case SIGINT:
case SIGTERM:
log_trace(INFO, "Received SIGTERM signal.");
log_trace(INFO, "RMPS is shutting down...");
log(INFO, "Received SIGTERM signal.");
log(INFO, "RMPS is shutting down...");
rmps_shutdown();
log_trace(INFO, "RMPS has been stopped properly.");
log(INFO, "RMPS has been stopped properly.");
_exit(EXIT_SUCCESS);
break;
default:
log_trace(WARNING, "Unhandled signal %s", strsignal(sig));
log(WARNING, "Unhandled signal %s", strsignal(sig));
break;
}
}
@@ -97,12 +97,12 @@ static void daemonize(const char *rundir)
pid = fork();
if (pid < 0) {
/* Could not fork */
log_trace(ERROR, "Failed to fork the parent process. Exiting!");
log(ERROR, "Failed to fork the parent process. Exiting!");
exit(EXIT_FAILURE);
}
if (pid > 0) {
/* Child created ok, so exit parent process */
log_trace(INFO, "Child process created: %d", pid);
log(INFO, "Child process created: %d", pid);
exit(EXIT_SUCCESS);
}
/* Child continues */
@@ -110,7 +110,7 @@ static void daemonize(const char *rundir)
/* Get a new process group */
sid = setsid();
if (sid < 0) {
log_trace(ERROR, "Failed to create a process group. Exiting!");
log(ERROR, "Failed to create a process group. Exiting!");
exit(EXIT_FAILURE);
}
/* Close all file descriptors because we fork */
@@ -134,14 +134,14 @@ static void spawn_pidfile(const char *pidfile)
pid_file_handle = open(pidfile, O_RDWR|O_CREAT, 0600);
if (pid_file_handle == -1) {
/* Couldn't open lock file */
log_trace(ERROR, "Could not create PID file %s - Exiting!", pidfile);
log(ERROR, "Could not create PID file %s - Exiting!", pidfile);
exit(EXIT_FAILURE);
}
/* Try to lock file */
if (lockf(pid_file_handle, F_TLOCK, 0) == -1) {
/* Couldn't get lock on lock file */
log_trace(ERROR, "Could not lock PID file %s - Exiting!", pidfile);
log(ERROR, "Could not lock PID file %s - Exiting!", pidfile);
exit(EXIT_FAILURE);
}
@@ -169,23 +169,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_trace(ERROR, "Failed to create socket");
log_trace(INFO, "RMPS failed to start, shutting down...");
log(ERROR, "Failed to create socket");
log(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}
if (set_reuse_addr(sd) < 0) {
log_trace(ERROR, "Failed to set reuse on address - Aborting...", port);
log_trace(INFO, "RMPS failed to start, shutting down...");
log(ERROR, "Failed to set reuse on address - Aborting...", port);
log(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}
if (bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
log_trace(ERROR, "Failed to bind on port: %d - Aborting...", port);
log_trace(INFO, "RMPS failed to start, shutting down...");
log(ERROR, "Failed to bind on port: %d - Aborting...", port);
log(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}
if (listen(sd, 10) != 0) {
log_trace(ERROR, "Failed to start listener on port %d - Aborting...", port);
log_trace(INFO, "RMPS failed to start, shutting down...");
log(ERROR, "Failed to start listener on port %d - Aborting...", port);
log(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}
return sd;
@@ -204,8 +204,8 @@ static SSL_CTX* init_server_ctx(const char *cipherlist)
ctx = SSL_CTX_new(TLSv1_2_method()); /* create new context from method */
if (ctx == NULL) {
log_trace(ERROR, "SSL_CTX_new() returned NULL - Aborting...");
log_trace(ERROR, "RMPS failed to start, shutting down...");
log(ERROR, "SSL_CTX_new() returned NULL - Aborting...");
log(ERROR, "RMPS failed to start, shutting down...");
exit(EXIT_FAILURE);
}
SSL_CTX_set_verify( ctx, SSL_VERIFY_PEER |
@@ -218,7 +218,7 @@ static SSL_CTX* init_server_ctx(const char *cipherlist)
strcat(ciphers, cipherlist);
/* This is very delicate, try to understand the ciphers */
SSL_CTX_set_cipher_list(ctx, cipherlist);
log_trace(VERBOSE, "cipherlist = %s", cipherlist);
log(VERBOSE, "cipherlist = %s", cipherlist);
return ctx;
}
@@ -231,22 +231,22 @@ void load_certificates(SSL_CTX* ctx, const char *certfile,
{
/* set the local certificate from certfile */
if (SSL_CTX_use_certificate_file(ctx, certfile, SSL_FILETYPE_PEM) <= 0) {
log_trace(ERROR, "Failed to load certfile! SSL error below:");
log(ERROR, "Failed to load certfile! SSL error below:");
log_ssl();
log_trace(INFO, "RMPS failed to start, shutting down...");
log(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}
/* 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_trace(ERROR, "Failed to load keyfile! SSL error below:");
log(ERROR, "Failed to load keyfile! SSL error below:");
log_ssl();
log_trace(INFO, "RMPS failed to start, shutting down...");
log(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}
/* verify private key */
if (!SSL_CTX_check_private_key(ctx)) {
log_trace(ERROR, "Private key does not match the public certificate.");
log_trace(INFO, "RMPS failed to start, shutting down...");
log(ERROR, "Private key does not match the public certificate.");
log(INFO, "RMPS failed to start, shutting down...");
atexit(cleanup);
}
if (cafile != NULL) {
@@ -260,7 +260,7 @@ void load_certificates(SSL_CTX* ctx, const char *certfile,
int launch_rmps(struct conf_table *conf, int fork_flag)
{
int server;
log_trace(INFO, "Starting up RMPS...");
log(INFO, "Starting up RMPS...");
/* Set signal handling */
set_env();
@@ -276,13 +276,13 @@ int launch_rmps(struct conf_table *conf, int fork_flag)
* -nodes is for not protecing with a passphrase
* http://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl
*/
log_trace(VERBOSE, "Loading crypto certs and keys.");
log(VERBOSE, "Loading crypto certs and keys.");
load_certificates(ctx, conf->rmps.certfile, conf->rmps.keyfile, conf->rmps.cafile);
log_trace(VERBOSE, "Starting listener on port: %d", atoi(conf->rmps.bind_on_port));
log(VERBOSE, "Starting listener on port: %d", atoi(conf->rmps.bind_on_port));
server = open_listener(atoi(conf->rmps.bind_on_port));
log_trace(VERBOSE, "Creating mutex for thread pool.");
log(VERBOSE, "Creating mutex for thread pool.");
ssl_pt_mutex(server, ctx, conf->rmps.threadpoolsize);
return 0;