summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-11-09 23:32:09 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-11-09 23:32:09 +0100
commitf16f221a3de8fdb617195cdd5fbe1076bdcf096c (patch)
tree4c982f4a3853b8b495f9a7708070fe39f974793e
parent678f9ce8939c672cb473c75b8b56f48b146957c6 (diff)
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.
-rw-r--r--parsing.c12
1 files 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);