diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file_list.c | 55 | ||||
-rw-r--r-- | src/file_list.h | 2 | ||||
-rw-r--r-- | src/log.c | 25 | ||||
-rw-r--r-- | src/log.h | 2 | ||||
-rw-r--r-- | src/sig_handler.c | 2 | ||||
-rw-r--r-- | src/writer.c | 2 |
6 files changed, 42 insertions, 46 deletions
diff --git a/src/file_list.c b/src/file_list.c index 44a4949..deb6337 100644 --- a/src/file_list.c +++ b/src/file_list.c @@ -52,31 +52,28 @@ static void delete_file(void* element) int file_list_init(file_list_t* list) { - list->mutex_ = g_mutex_new(); - if(!list->mutex_) - return -2; - + g_mutex_init(&(list->mutex_)); return slist_init(&(list->list_), &delete_file); } void file_list_clear(file_list_t* list) { - g_mutex_lock(list->mutex_); + g_mutex_lock(&(list->mutex_)); slist_clear(&(list->list_)); - g_mutex_unlock(list->mutex_); + g_mutex_unlock(&(list->mutex_)); } file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, const char* format, const char* dir, mode_t mode) { - if(!list || !(list->mutex_)) + if(!list || !(&(list->mutex_))) return NULL; - + file_t* tmp = malloc(sizeof(file_t)); if(!tmp) return NULL; log_printf(INFO, "%s time: %02d:%02d:%02d on %d.%d.%d%s", type, time->tm_hour, time->tm_min, time->tm_sec, time->tm_mday, time->tm_mon+1, time->tm_year+1900, time->tm_isdst > 0 ? " (DST)": ""); - + char name[256]; strftime(name, sizeof(name), format, time); int len = asprintf(&(tmp->path_), "%s/%s", dir, name); @@ -90,24 +87,24 @@ file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, cons tmp->mode_ = mode; tmp->pp_child_ = NULL; - g_mutex_lock(list->mutex_); + g_mutex_lock(&(list->mutex_)); if(slist_add(&(list->list_), tmp) == NULL) { - g_mutex_unlock(list->mutex_); + g_mutex_unlock(&(list->mutex_)); free(tmp->path_); free(tmp); return NULL; } - g_mutex_unlock(list->mutex_); + g_mutex_unlock(&(list->mutex_)); return tmp; } int file_list_remove(file_list_t* list, int fd) { - if(!list || !(list->mutex_)) + if(!list || !(&(list->mutex_))) return -1; - - g_mutex_lock(list->mutex_); + + g_mutex_lock(&(list->mutex_)); slist_element_t* tmp = list->list_.first_; while(tmp) { if(((file_t*)tmp->data_)->fd_ == fd) { @@ -116,24 +113,24 @@ int file_list_remove(file_list_t* list, int fd) } tmp = tmp->next_; } - g_mutex_unlock(list->mutex_); - + g_mutex_unlock(&(list->mutex_)); + return 0; } int file_list_call_post_process(file_list_t* list, int fd, char* script) { - if(!list || !(list->mutex_)) + if(!list || !(&(list->mutex_))) return -1; - - g_mutex_lock(list->mutex_); + + g_mutex_lock(&(list->mutex_)); slist_element_t* tmp = list->list_.first_; while(tmp) { if(((file_t*)tmp->data_)->fd_ == fd) { log_printf(INFO, "calling post processing for '%s'", ((file_t*)tmp->data_)->path_); close(((file_t*)tmp->data_)->fd_); ((file_t*)tmp->data_)->fd_ = FILE_POST_PROCESS; - + char* const argv[] = { script, ((file_t*)tmp->data_)->path_, NULL }; char* const evp[] = { NULL }; ((file_t*)tmp->data_)->pp_child_ = rh_exec(script, argv, evp); @@ -144,17 +141,17 @@ int file_list_call_post_process(file_list_t* list, int fd, char* script) } tmp = tmp->next_; } - g_mutex_unlock(list->mutex_); - + g_mutex_unlock(&(list->mutex_)); + return 0; } int file_list_waitpid(file_list_t* list) { - if(!list || !(list->mutex_)) + if(!list || !(&(list->mutex_))) return -1; - - g_mutex_lock(list->mutex_); + + g_mutex_lock(&(list->mutex_)); slist_element_t* tmp = list->list_.first_; while(tmp) { if(((file_t*)tmp->data_)->fd_ == FILE_POST_PROCESS) { @@ -167,8 +164,8 @@ int file_list_waitpid(file_list_t* list) else tmp = tmp->next_; } - g_mutex_unlock(list->mutex_); - + g_mutex_unlock(&(list->mutex_)); + return 0; } @@ -198,7 +195,7 @@ int open_file(file_t* file) free(orig_path); return -2; } - + if(file->path_ != orig_path) free(file->path_); file->path_ = tmp; diff --git a/src/file_list.h b/src/file_list.h index 1132327..82931a9 100644 --- a/src/file_list.h +++ b/src/file_list.h @@ -46,7 +46,7 @@ typedef struct file_struct file_t; struct file_list_struct { slist_t list_; - GMutex* mutex_; + GMutex mutex_; }; typedef struct file_list_struct file_list_t; @@ -76,7 +76,7 @@ int log_targets_target_exists(log_targets_t* targets, log_target_type_t type) if(tmp->type_ == type) return 1; tmp = tmp->next_; - } + } return 0; } @@ -139,7 +139,7 @@ int log_targets_add(log_targets_t* targets, const char* conf) log_target_t* tmp = targets->first_; while(tmp->next_) tmp = tmp->next_; - + tmp->next_ = new_target; } return 0; @@ -180,15 +180,14 @@ void log_init() { stdlog.max_prio_ = 0; stdlog.targets_.first_ = NULL; - g_thread_init(NULL); - stdlog.log_mutex_ = g_mutex_new(); + g_mutex_init(&(stdlog.log_mutex_)); } void log_close() { - g_mutex_lock(stdlog.log_mutex_); + g_mutex_lock(&(stdlog.log_mutex_)); log_targets_clear(&stdlog.targets_); - g_mutex_unlock(stdlog.log_mutex_); + g_mutex_unlock(&(stdlog.log_mutex_)); } void update_max_prio() @@ -207,10 +206,10 @@ int log_add_target(const char* conf) if(!conf) return -1; - g_mutex_lock(stdlog.log_mutex_); + g_mutex_lock(&(stdlog.log_mutex_)); int ret = log_targets_add(&stdlog.targets_, conf); if(!ret) update_max_prio(); - g_mutex_unlock(stdlog.log_mutex_); + g_mutex_unlock(&(stdlog.log_mutex_)); return ret; } @@ -226,9 +225,9 @@ void log_printf(log_prio_t prio, const char* fmt, ...) vsnprintf(msg, MSG_LENGTH_MAX, fmt, args); va_end(args); - g_mutex_lock(stdlog.log_mutex_); + g_mutex_lock(&(stdlog.log_mutex_)); log_targets_log(&stdlog.targets_, prio, msg); - g_mutex_unlock(stdlog.log_mutex_); + g_mutex_unlock(&(stdlog.log_mutex_)); } void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len) @@ -247,7 +246,7 @@ void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len) if(offset < 0) return; char* ptr = &msg[offset]; - + for(i=0; i < len; i++) { if(((i+1)*3) >= (MSG_LENGTH_MAX - offset)) break; @@ -255,7 +254,7 @@ void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len) ptr+=3; } } - g_mutex_lock(stdlog.log_mutex_); + g_mutex_lock(&(stdlog.log_mutex_)); log_targets_log(&stdlog.targets_, prio, msg); - g_mutex_unlock(stdlog.log_mutex_); + g_mutex_unlock(&(stdlog.log_mutex_)); } @@ -68,7 +68,7 @@ void log_targets_clear(log_targets_t* targets); struct log_struct { log_prio_t max_prio_; log_targets_t targets_; - GMutex* log_mutex_; + GMutex log_mutex_; }; typedef struct log_struct log_t; diff --git a/src/sig_handler.c b/src/sig_handler.c index 59fc461..916580c 100644 --- a/src/sig_handler.c +++ b/src/sig_handler.c @@ -95,7 +95,7 @@ int signal_start(GMainLoop *loop) { g_assert(!signal_thread); - signal_thread = g_thread_create_full(signal_thread_func, loop, 8192, FALSE, TRUE, G_THREAD_PRIORITY_HIGH, NULL); + signal_thread = g_thread_new("sig_handler", signal_thread_func, loop); if(!signal_thread) return -1; diff --git a/src/writer.c b/src/writer.c index 192dea9..d7875de 100644 --- a/src/writer.c +++ b/src/writer.c @@ -211,7 +211,7 @@ int writer_start(writer_t* writer) log_printf(ERROR, "clock id could not be created"); return -1; } - writer->thread_ = g_thread_create(writer_thread_func, writer, TRUE, NULL); + writer->thread_ = g_thread_new("writer", writer_thread_func, writer); if(!writer->thread_) { log_printf(ERROR, "writer thread could not be started"); return -1; |