Fit in 80 symbols per line

This commit is contained in:
2018-07-03 18:26:36 +03:00
parent 43550b2c5a
commit 238c8fac48
3 changed files with 36 additions and 18 deletions

View File

@@ -113,10 +113,12 @@ static int fopen_and_mkdir(const char *dir)
struct stat st = {0}; struct stat st = {0};
*p = 0; *p = 0;
if (stat(tmp, &st) == -1) 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) { if (mkdir(tmp, 0700) == -1 && errno != EEXIST) {
log(ERROR, log(ERROR,
"Permission denied to create directory: %s", "Permission denied to create dir: %s",
tmp); tmp);
return 1; return 1;
} }
@@ -252,16 +254,19 @@ static int test_conf_syntax(void)
if (!strcmp(tmp + 1, "mysql")) { if (!strcmp(tmp + 1, "mysql")) {
/* || !strcmp(tmp[1], "postgresql") */ /* || !strcmp(tmp[1], "postgresql") */
/* || !strcmp(tmp[1], "oracle") */ /* || !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') 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 { } else {
ok = 0; ok = 0;
failed = 1; failed = 1;
} }
} else if (!strcmp(buf, "db.hostname")) } else if (!strcmp(buf, "db.hostname"))
/* Just save it, launch_rmps will check it */ /* 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")) { else if (!strcmp(buf, "db.port")) {
i = strlen(tmp + 1); i = strlen(tmp + 1);
if (i < 6) { /* max 5 digits for network port */ if (i < 6) { /* max 5 digits for network port */
@@ -269,7 +274,8 @@ static int test_conf_syntax(void)
"1234567890") == i) { "1234567890") == i) {
i = atoi(tmp + 1); i = atoi(tmp + 1);
if (i > 0 && i < 65536) { 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; continue;
} }
} }
@@ -277,7 +283,8 @@ static int test_conf_syntax(void)
ok = 0; ok = 0;
failed = 1; failed = 1;
} else if (!strcmp(buf, "db.pass")) } 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")) { else if (!strcmp(buf, "rmps.agent_ip")) {
/* TODO */ /* TODO */
} else if (!strcmp(buf, "rmps.agent_port")) { } else if (!strcmp(buf, "rmps.agent_port")) {
@@ -288,7 +295,8 @@ static int test_conf_syntax(void)
i = atoi(tmp + 1); i = atoi(tmp + 1);
if (i > 0 && i < 65536) { if (i > 0 && i < 65536) {
strncpy(conf.rmps.agent_port, strncpy(conf.rmps.agent_port,
tmp + 1, sizeof(conf.rmps.agent_port) - 1); tmp + 1,
sizeof(conf.rmps.agent_port) - 1);
continue; continue;
} }
} }
@@ -305,7 +313,8 @@ static int test_conf_syntax(void)
i = atoi(tmp + 1); i = atoi(tmp + 1);
if (i > 0 && i < 65536) { if (i > 0 && i < 65536) {
strncpy(conf.rmps.client_port, strncpy(conf.rmps.client_port,
tmp + 1, sizeof(conf.rmps.client_port) - 1); tmp + 1,
sizeof(conf.rmps.client_port) - 1);
continue; continue;
} }
} }
@@ -313,15 +322,18 @@ static int test_conf_syntax(void)
ok = 0; ok = 0;
failed = 1; failed = 1;
} else if (!strcmp(buf, "rmps.logfile")) { } 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) if (fopen_and_mkdir(conf.rmps.logfile) != 0)
failed = 1; failed = 1;
} else if (!strcmp(buf, "rmps.errlog")) { } 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) if (fopen_and_mkdir(conf.rmps.errlog) != 0)
failed = 1; failed = 1;
} else if (!strcmp(buf, "rmps.pidfile")) { } 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) if (fopen_and_mkdir(conf.rmps.pidfile) != 0)
failed = 1; failed = 1;
} else if (!strcmp(buf, "rmps.loglevel")) { } else if (!strcmp(buf, "rmps.loglevel")) {

View File

@@ -5,7 +5,7 @@
#include "log.h" #include "log.h"
#define HOSTNAMESIZE 128 #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 { struct conf_db {
char type[15]; char type[15];

View File

@@ -180,15 +180,20 @@ static int open_listener(int port)
} }
if (set_reuse_addr(sd) < 0) { if (set_reuse_addr(sd) < 0) {
log(ERROR, log(ERROR,
"Failed to set reuse on address - Aborting RMPS...", port); "Failed to set reuse on address - Aborting RMPS...",
port);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (bind(sd, (struct sockaddr *)&addr, sizeof(addr)) != 0) { 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); exit(EXIT_FAILURE);
} }
if (listen(sd, 10) != 0) { 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); exit(EXIT_FAILURE);
} }
return sd; return sd;
@@ -231,7 +236,8 @@ void load_certificates(SSL_CTX *ctx, const char *certfile,
const char *keyfile, const char *cafile) const char *keyfile, const char *cafile)
{ {
/* set the local certificate from certfile */ /* 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(ERROR, "Failed to load certfile! SSL error below:");
log_ssl(); log_ssl();
log(INFO, "RMPS failed to start, shutting down..."); log(INFO, "RMPS failed to start, shutting down...");