From f16f221a3de8fdb617195cdd5fbe1076bdcf096c Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 9 Nov 2010 23:32:09 +0100 Subject: Temporary workaround for race condition in early parsing. Parsing the date in log_opened and day_changed takes its time, so other threads might set the time and use that before the initial date is set. This only really matters for seen_first as of now. --- parsing.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/parsing.c b/parsing.c index 3f38681..ac99c82 100644 --- a/parsing.c +++ b/parsing.c @@ -280,12 +280,17 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t * } pcre_copy_named_substring(rs->log_opened, line, ovector, rc, "date", date, DATE_BUFFER_SIZE); + + /* TODO: Find a better way around this. + * Locking early to allow setting of correct date before any other threads start setting time + * before date is set. */ + pthread_mutex_lock(&time_mutex); if(!strptime(date, log_date_format, &now)) { fprintf(stderr, "log fail: %s\n", date); + pthread_mutex_unlock(&time_mutex); continue; } - pthread_mutex_lock(&time_mutex); now_global = now; pthread_mutex_unlock(&time_mutex); @@ -302,12 +307,15 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t * } pcre_copy_named_substring(rs->day_changed, line, ovector, rc, "date", date, DATE_BUFFER_SIZE); + + /* See comment in log_opened parsing. */ + pthread_mutex_lock(&time_mutex); if(!strptime(date, day_date_format, &now)) { fprintf(stderr, "day fail: %s\n", date); + pthread_mutex_unlock(&time_mutex); continue; } - pthread_mutex_lock(&time_mutex); now_global = now; pthread_mutex_unlock(&time_mutex); -- cgit v1.2.3