summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-11-10 17:01:58 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-11-10 17:01:58 +0100
commitdc4b7df61e2b1f270223dad5161c6d95fc6cfd1e (patch)
treed1708f608504d1f91260882c61ba0a5e2f8546a0
parentf16f221a3de8fdb617195cdd5fbe1076bdcf096c (diff)
Lock calls to fgets().lastseen
-rw-r--r--parsing.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/parsing.c b/parsing.c
index ac99c82..54d6078 100644
--- a/parsing.c
+++ b/parsing.c
@@ -20,7 +20,7 @@
#define max(a, b) ((a) > (b) ? (a) : (b))
-static pthread_mutex_t user_mutex, word_mutex, channel_mutex, time_mutex;
+static pthread_mutex_t file_mutex, user_mutex, word_mutex, channel_mutex, time_mutex;
static struct user_t *last_user = NULL;
static int in_monolog = 0, monolog_len = 0;
@@ -40,6 +40,16 @@ static inline void add_word(struct user_t *user, wchar_t *word, int len) {
pthread_mutex_unlock(&word_mutex);
}
+static inline char *parse_getline(char *buffer, int bufsize, FILE *f) {
+ char *r;
+
+ pthread_mutex_lock(&file_mutex);
+ r = fgets(buffer, bufsize, f);
+ pthread_mutex_unlock(&file_mutex);
+
+ return r;
+}
+
static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *rs) {
char line[LINE_BUFFER_SIZE];
const char *log_date_format, *day_date_format;
@@ -61,7 +71,7 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
day_date_format = NULL;
}
- while(fgets(line, LINE_BUFFER_SIZE, f)) {
+ while(parse_getline(line, LINE_BUFFER_SIZE, f)) {
int rc;
int ovector[30];
@@ -373,6 +383,7 @@ static void *thread_func(void *arg) {
}
void process(int thread_n) {
+ pthread_mutex_init(&file_mutex, NULL);
pthread_mutex_init(&user_mutex, NULL);
pthread_mutex_init(&word_mutex, NULL);
pthread_mutex_init(&channel_mutex, NULL);
@@ -419,6 +430,7 @@ void process(int thread_n) {
user_free();
word_free();
}
+ pthread_mutex_destroy(&file_mutex);
pthread_mutex_destroy(&time_mutex);
pthread_mutex_destroy(&user_mutex);
pthread_mutex_destroy(&word_mutex);