Rewrite log_trace to be thread-safe and some cleanups

This commit is contained in:
2016-08-08 22:31:29 +03:00
parent e9f3673bfd
commit dcd58d8281
8 changed files with 127 additions and 74 deletions

View File

@@ -12,6 +12,7 @@ static int test_conf_perms();
static int test_conf_syntax();
struct conf_table conf = {
0, /* isvalid initial state */
{
"", /* db.type */
"", /* db.hostname */
@@ -22,7 +23,7 @@ struct conf_table conf = {
"7000", /* rmps.bind_on_port */
"/var/log/rmps/rmpsd.log",
"/var/log/rmps/rmpsd.err",
'1', /* rmps.loglevel */
'2', /* rmps.loglevel */
"/run/rmps/rmpsd.pid",
"/etc/rmps/cert.pem",
"/etc/rmps/key.pem",
@@ -82,8 +83,8 @@ static int fopen_and_mkdir(const char *dir) {
if(*p == '/') {
*p = 0;
if (mkdir(tmp, S_IRWXU) == -1 && errno != EEXIST) {
fprintf( stderr,
"Permission denied to create directory: %s\n",
log_trace( ERROR,
"Permission denied to create directory: %s",
tmp );
return 1;
}
@@ -91,7 +92,7 @@ static int fopen_and_mkdir(const char *dir) {
}
fd = fopen(dir, "a");
if (!fd) {
fprintf(stderr, "Permission denied to write into: %s\n", dir);
log_trace(ERROR, "Permission denied to write into: %s", dir);
return 1;
}
fclose(fd);
@@ -171,7 +172,6 @@ static int test_conf_perms()
log_trace(WARNING, confresult);
}
}
return 0; /* conf is readable */
}
@@ -198,8 +198,8 @@ static int test_conf_syntax()
if ((tmp = strstr(buf, "=")))
*tmp = '\0';
else {
fprintf( stderr,
"Bad entry in /etc/rmps/rmps.conf, line %d: %s\n",
log_trace( ERROR,
"Bad entry in /etc/rmps/rmps.conf, line %d: %s",
j, buf );
ok = 0;
failed = 1;
@@ -210,8 +210,8 @@ static int test_conf_syntax()
if (tmp[i] == '\n')
tmp[i] = '\0';
if (tmp[strspn(tmp + 1, " \t\v\r\n") + 1] == '\0') {
fprintf( stderr,
"Specified entry without value, line %d: %s\n",
log_trace( ERROR,
"Specified entry without value, line %d: %s",
j, buf );
failed = 1;
continue;
@@ -278,29 +278,28 @@ static int test_conf_syntax()
failed = 1;
} else if (!strcmp(buf, "rmps.certfile")) {
if (access(tmp + 1, F_OK) == -1) {
fprintf( stderr,
"%s is missing\n", tmp + 1);
log_trace( ERROR,
"%s is missing", tmp + 1);
failed = 1;
}
else if (access(tmp + 1, R_OK) == -1) {
fprintf( stderr,
"%s is not readable\n",
log_trace( ERROR,
"%s is not readable",
tmp + 1
);
failed = 1;
} else
strncpy(conf.rmps.certfile, tmp + 1, sizeof(conf.rmps.certfile));
}
else if (!strcmp(buf, "rmps.keyfile")) {
if (access(tmp + 1, F_OK) == -1) {
fprintf( stderr,
"%s is missing\n", conf.rmps.keyfile);
log_trace( ERROR,
"%s is missing", conf.rmps.keyfile);
failed = 1;
}
else if (access(tmp + 1, R_OK) == -1) {
fprintf( stderr,
"%s is not readable\n",
log_trace( ERROR,
"%s is not readable",
tmp + 1
);
failed = 1;
@@ -310,12 +309,12 @@ static int test_conf_syntax()
strncpy(conf.rmps.cipherlist, tmp + 1, sizeof(conf.rmps.cipherlist));
} else if (!strcmp(buf, "rmps.cafile")) {
if (access(tmp + 1, F_OK) == -1) {
fprintf( stderr,
"%s is missing\n", tmp + 1);
log_trace( ERROR,
"%s is missing", tmp + 1);
failed = 1;
}
else if (access(tmp + 1, R_OK) == -1) {
fprintf( stderr,
log_trace( ERROR,
"%s is not readable\n",
tmp + 1
);
@@ -323,12 +322,12 @@ static int test_conf_syntax()
} else
strncpy(conf.rmps.cafile, tmp + 1, sizeof(conf.rmps.cafile));
} else
fprintf( stderr,
"Unknown config entry on line %d: %s\n",
log_trace( ERROR,
"Unknown config entry on line %d: %s",
j, buf );
if (!ok) {
fprintf( stderr,
"Invalid value for \"%s\", line %d: \"%s\"\n",
log_trace( ERROR,
"Invalid value for \"%s\", line %d: \"%s\"",
buf, j, tmp + 1 );
ok = !ok;
}
@@ -337,6 +336,7 @@ static int test_conf_syntax()
if (failed)
return 1;
conf.isvalid = 1;
return 0;
}
@@ -351,6 +351,5 @@ int confparse()
result = test_conf_syntax();
if (result != 0)
return 1; /* Bad conf syntax */
return 0; /* seems legit */
}