Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed log lock from 'quick' to 'basic' because this is an I/O lock. #124

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions util/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int key_created = 0;
static ub_thread_key_type logkey;
#ifndef THREADS_DISABLED
/** pthread mutex to protect FILE* */
static lock_quick_type log_lock;
static lock_basic_type log_lock;
#endif
/** the identity of this executable/process */
static const char* ident="unbound";
Expand All @@ -88,18 +88,18 @@ log_init(const char* filename, int use_syslog, const char* chrootdir)
if(!key_created) {
key_created = 1;
ub_thread_key_create(&logkey, NULL);
lock_quick_init(&log_lock);
lock_basic_init(&log_lock);
}
lock_quick_lock(&log_lock);
lock_basic_lock(&log_lock);
if(logfile
#if defined(HAVE_SYSLOG_H) || defined(UB_ON_WINDOWS)
|| logging_to_syslog
#endif
) {
lock_quick_unlock(&log_lock); /* verbose() needs the lock */
lock_basic_unlock(&log_lock); /* verbose() needs the lock */
verbose(VERB_QUERY, "switching log to %s",
use_syslog?"syslog":(filename&&filename[0]?filename:"stderr"));
lock_quick_lock(&log_lock);
lock_basic_lock(&log_lock);
}
if(logfile && logfile != stderr) {
FILE* cl = logfile;
Expand All @@ -119,7 +119,7 @@ log_init(const char* filename, int use_syslog, const char* chrootdir)
* --with-syslog-facility=LOCAL[0-7] can override it */
openlog(ident, LOG_NDELAY, UB_SYSLOG_FACILITY);
logging_to_syslog = 1;
lock_quick_unlock(&log_lock);
lock_basic_unlock(&log_lock);
return;
}
#elif defined(UB_ON_WINDOWS)
Expand All @@ -128,13 +128,13 @@ log_init(const char* filename, int use_syslog, const char* chrootdir)
}
if(use_syslog) {
logging_to_syslog = 1;
lock_quick_unlock(&log_lock);
lock_basic_unlock(&log_lock);
return;
}
#endif /* HAVE_SYSLOG_H */
if(!filename || !filename[0]) {
logfile = stderr;
lock_quick_unlock(&log_lock);
lock_basic_unlock(&log_lock);
return;
}
/* open the file for logging */
Expand All @@ -143,7 +143,7 @@ log_init(const char* filename, int use_syslog, const char* chrootdir)
filename += strlen(chrootdir);
f = fopen(filename, "a");
if(!f) {
lock_quick_unlock(&log_lock);
lock_basic_unlock(&log_lock);
log_err("Could not open logfile %s: %s", filename,
strerror(errno));
return;
Expand All @@ -153,14 +153,14 @@ log_init(const char* filename, int use_syslog, const char* chrootdir)
setvbuf(f, NULL, (int)_IOLBF, 0);
#endif
logfile = f;
lock_quick_unlock(&log_lock);
lock_basic_unlock(&log_lock);
}

void log_file(FILE *f)
{
lock_quick_lock(&log_lock);
lock_basic_lock(&log_lock);
logfile = f;
lock_quick_unlock(&log_lock);
lock_basic_unlock(&log_lock);
}

void log_thread_set(int* num)
Expand Down Expand Up @@ -245,9 +245,9 @@ log_vmsg(int pri, const char* type,
return;
}
#endif /* HAVE_SYSLOG_H */
lock_quick_lock(&log_lock);
lock_basic_lock(&log_lock);
if(!logfile) {
lock_quick_unlock(&log_lock);
lock_basic_unlock(&log_lock);
return;
}
now = (time_t)time(NULL);
Expand All @@ -272,7 +272,7 @@ log_vmsg(int pri, const char* type,
/* line buffering does not work on windows */
fflush(logfile);
#endif
lock_quick_unlock(&log_lock);
lock_basic_unlock(&log_lock);
}

/**
Expand Down