Skip to content

Conversation

@mgoulish
Copy link
Contributor

Please see large comment at start of file that describes approach.

I will remove that comment -- as well as all the "1956" comments -- before this code goes to main.

@ChugR
Copy link
Contributor

ChugR commented Jun 16, 2021

The two fedora asan builds melted down and hardly any tests passed. This PR branch runs all tests fine for me.

src/log.c Outdated




Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just stating the obvious - we'll need to either pull this comment or move it after the license header once this patch is in the final form.

src/log.c Outdated
//If file is not there, return 0.
// We are not logging an error here since we are already holding the log_source_lock
// Writing a log message will try to re-obtain the log_source_lock lock and cause a deadlock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now I'd leave this as-is. We can change that in a follow up patch if necessary.

src/log.c Outdated
bool syslog;
log_sink_t *sink;
uint64_t severity_histogram[N_LEVEL_INDICES];
sys_mutex_t * sink_lock; // 1956: This lock protects operations on this source's sink.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting: no space between * and sink_lock

src/log.c Outdated
static qd_log_source_t *qd_log_source_lh(const char *module)
static bool log_initialized = false;

static qd_log_source_t *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting: return type and function signature on the same line please.

src/log.c Outdated

qd_log_source_t *log_source = NEW(qd_log_source_t);
ZERO(log_source);
log_source->module = (char*) malloc(strlen(module) + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at it, we should move away from the malloc+strcpy pattern to simply using qd_strdup()

src/log.c Outdated
void qd_log_initialize(void)
{
if(log_initialized) {
// TODO -- log something here?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just assert(!log_initialized) here - it's a coding bug to call it twice.

src/log.c Outdated
// Previously, we needed to obtain these attributes outside of the lock, because
// of a deadlock issue.

sys_mutex_lock(src->sink_lock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct: we shouldn't be protecting the sink because the sink is not changing. The source is being modified - and if any sink attributes need to be modified we simply create a new one and drop the reference to the old sink (which can still be in use by other sources).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this I think maybe a per-source read/write lock would be a better choice: take the read lock while logging. Take the write lock during this call.

entry->level = level;
entry->file = file ? strdup(file) : 0;
entry->line = line;
gettimeofday(&entry->time, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to move the gettimeofday into write_log so we're holding the lock while the timestamp is taken to reduce likelyhood of re-ordering log events.

@mgoulish mgoulish closed this Jul 15, 2021
@mgoulish mgoulish deleted the mick-log-rewrite branch July 15, 2021 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants