From 238c8fac48fc9cfcdf9a72e53de3a200fababda3 Mon Sep 17 00:00:00 2001 From: Bogomil Vasilev Date: Tue, 3 Jul 2018 18:26:36 +0300 Subject: [PATCH] Fit in 80 symbols per line --- src/confparser.c | 38 +++++++++++++++++++++++++------------- src/confparser.h | 2 +- src/rmps.c | 14 ++++++++++---- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/confparser.c b/src/confparser.c index f23ba71..70a7bfe 100644 --- a/src/confparser.c +++ b/src/confparser.c @@ -113,11 +113,13 @@ static int fopen_and_mkdir(const char *dir) struct stat st = {0}; *p = 0; if (stat(tmp, &st) == -1) - log(VERBOSE, "Directory \"%s\" doesn't exist. Creating...", tmp); + log(VERBOSE, + "Path \"%s\" doesn't exist. Creating...", + tmp); if (mkdir(tmp, 0700) == -1 && errno != EEXIST) { log(ERROR, - "Permission denied to create directory: %s", - tmp); + "Permission denied to create dir: %s", + tmp); return 1; } *p = '/'; @@ -252,16 +254,19 @@ static int test_conf_syntax(void) if (!strcmp(tmp + 1, "mysql")) { /* || !strcmp(tmp[1], "postgresql") */ /* || !strcmp(tmp[1], "oracle") */ - strncpy(conf.db.type, tmp + 1, sizeof(conf.db.type) - 1); + strncpy(conf.db.type, tmp + 1, + sizeof(conf.db.type) - 1); if (conf.db.port[0] == '\0') - strncpy(conf.db.port, "3306", sizeof(conf.db.port) - 1); + strncpy(conf.db.port, "3306", + sizeof(conf.db.port) - 1); } else { ok = 0; failed = 1; } } else if (!strcmp(buf, "db.hostname")) /* Just save it, launch_rmps will check it */ - strncpy(conf.db.hostname, tmp + 1, sizeof(conf.db.hostname) - 1); + strncpy(conf.db.hostname, tmp + 1, + sizeof(conf.db.hostname) - 1); else if (!strcmp(buf, "db.port")) { i = strlen(tmp + 1); if (i < 6) { /* max 5 digits for network port */ @@ -269,7 +274,8 @@ static int test_conf_syntax(void) "1234567890") == i) { i = atoi(tmp + 1); if (i > 0 && i < 65536) { - strncpy(conf.db.port, tmp + 1, sizeof(conf.db.port) - 1); + strncpy(conf.db.port, tmp + 1, + sizeof(conf.db.port)-1); continue; } } @@ -277,7 +283,8 @@ static int test_conf_syntax(void) ok = 0; failed = 1; } else if (!strcmp(buf, "db.pass")) - strncpy(conf.db.pass, tmp + 1, sizeof(conf.db.pass) - 1); + strncpy(conf.db.pass, tmp + 1, + sizeof(conf.db.pass) - 1); else if (!strcmp(buf, "rmps.agent_ip")) { /* TODO */ } else if (!strcmp(buf, "rmps.agent_port")) { @@ -288,7 +295,8 @@ static int test_conf_syntax(void) i = atoi(tmp + 1); if (i > 0 && i < 65536) { strncpy(conf.rmps.agent_port, - tmp + 1, sizeof(conf.rmps.agent_port) - 1); + tmp + 1, + sizeof(conf.rmps.agent_port) - 1); continue; } } @@ -305,7 +313,8 @@ static int test_conf_syntax(void) i = atoi(tmp + 1); if (i > 0 && i < 65536) { strncpy(conf.rmps.client_port, - tmp + 1, sizeof(conf.rmps.client_port) - 1); + tmp + 1, + sizeof(conf.rmps.client_port) - 1); continue; } } @@ -313,15 +322,18 @@ static int test_conf_syntax(void) ok = 0; failed = 1; } else if (!strcmp(buf, "rmps.logfile")) { - strncpy(conf.rmps.logfile, tmp + 1, sizeof(conf.rmps.logfile) - 1); + strncpy(conf.rmps.logfile, tmp + 1, + sizeof(conf.rmps.logfile) - 1); if (fopen_and_mkdir(conf.rmps.logfile) != 0) failed = 1; } else if (!strcmp(buf, "rmps.errlog")) { - strncpy(conf.rmps.errlog, tmp + 1, sizeof(conf.rmps.errlog) - 1); + strncpy(conf.rmps.errlog, tmp + 1, + sizeof(conf.rmps.errlog) - 1); if (fopen_and_mkdir(conf.rmps.errlog) != 0) failed = 1; } else if (!strcmp(buf, "rmps.pidfile")) { - strncpy(conf.rmps.pidfile, tmp + 1, sizeof(conf.rmps.pidfile) - 1); + strncpy(conf.rmps.pidfile, tmp + 1, + sizeof(conf.rmps.pidfile) - 1); if (fopen_and_mkdir(conf.rmps.pidfile) != 0) failed = 1; } else if (!strcmp(buf, "rmps.loglevel")) { diff --git a/src/confparser.h b/src/confparser.h index 4d09695..0bb991d 100644 --- a/src/confparser.h +++ b/src/confparser.h @@ -5,7 +5,7 @@ #include "log.h" #define HOSTNAMESIZE 128 -#define CFGLINESIZE PATH_MAX + NAME_MAX + 30 /* 30 is pretty random */ +#define CFGLINESIZE (PATH_MAX + NAME_MAX + 30) /* 30 is pretty random */ struct conf_db { char type[15]; diff --git a/src/rmps.c b/src/rmps.c index 8516cd9..ef35284 100644 --- a/src/rmps.c +++ b/src/rmps.c @@ -180,15 +180,20 @@ static int open_listener(int port) } if (set_reuse_addr(sd) < 0) { log(ERROR, - "Failed to set reuse on address - Aborting RMPS...", port); + "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 RMPS...", port); + 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 RMPS...", port); + log(ERROR, + "Failed to start listener on port %d - Aborting RMPS...", + port); exit(EXIT_FAILURE); } return sd; @@ -231,7 +236,8 @@ void load_certificates(SSL_CTX *ctx, const char *certfile, const char *keyfile, const char *cafile) { /* set the local certificate from certfile */ - if (SSL_CTX_use_certificate_file(ctx, certfile, SSL_FILETYPE_PEM) <= 0) { + if (SSL_CTX_use_certificate_file(ctx, certfile, + SSL_FILETYPE_PEM) <= 0) { log(ERROR, "Failed to load certfile! SSL error below:"); log_ssl(); log(INFO, "RMPS failed to start, shutting down...");