access config via a pointer, not a hardcoded struct address
this is required so we can elegantly swap out an old config for a new one in the future and remove lots of boilerplate from config initialization code. unfortunately this is a quite intrusive change as the config struct was accessed in numerous places, but frankly it should have been done via a pointer right from the start. right now, we simply point to a static struct in main.c, so there shouldn't be any noticeable changes in behaviour.
This commit is contained in:
1 parent
bffa705005
commit
c63d5d26b4
11 files changed
+107
-103
No files matched your search
@@ -129,7 +129,7 @@ void log_message (int level, const char *fmt, ...)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (config.syslog && level == LOG_CONN)
|
||||
if (config && config->syslog && level == LOG_CONN)
|
||||
level = LOG_INFO;
|
||||
|
||||
va_start (args, fmt);
|
||||
@@ -161,10 +161,10 @@ void log_message (int level, const char *fmt, ...)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(!config.syslog && log_file_fd == -1)
|
||||
if(!config->syslog && log_file_fd == -1)
|
||||
goto out;
|
||||
|
||||
if (config.syslog) {
|
||||
if (config->syslog) {
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
#ifdef HAVE_VSYSLOG_H
|
||||
vsyslog (level, fmt, args);
|
||||
@@ -203,11 +203,11 @@ void log_message (int level, const char *fmt, ...)
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
|
||||
if (ret == -1) {
|
||||
config.syslog = TRUE;
|
||||
config->syslog = TRUE;
|
||||
|
||||
log_message(LOG_CRIT, "ERROR: Could not write to log "
|
||||
"file %s: %s.",
|
||||
config.logf_name, strerror(errno));
|
||||
config->logf_name, strerror(errno));
|
||||
log_message(LOG_CRIT,
|
||||
"Falling back to syslog logging");
|
||||
}
|
||||
@@ -272,23 +272,23 @@ static void send_stored_logs (void)
|
||||
*/
|
||||
int setup_logging (void)
|
||||
{
|
||||
if (!config.syslog) {
|
||||
if (open_log_file (config.logf_name) < 0) {
|
||||
if (!config->syslog) {
|
||||
if (open_log_file (config->logf_name) < 0) {
|
||||
/*
|
||||
* If opening the log file fails, we try
|
||||
* to fall back to syslog logging...
|
||||
*/
|
||||
config.syslog = TRUE;
|
||||
config->syslog = TRUE;
|
||||
|
||||
log_message (LOG_CRIT, "ERROR: Could not create log "
|
||||
"file %s: %s.",
|
||||
config.logf_name, strerror (errno));
|
||||
config->logf_name, strerror (errno));
|
||||
log_message (LOG_CRIT,
|
||||
"Falling back to syslog logging.");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.syslog) {
|
||||
if (config->syslog) {
|
||||
openlog ("tinyproxy", LOG_PID, LOG_USER);
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ void shutdown_logging (void)
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.syslog) {
|
||||
if (config->syslog) {
|
||||
closelog ();
|
||||
} else {
|
||||
close_log_file ();
|
||||
|
||||
Reference in new issue
Block a user