diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file_list.c | 26 | ||||
-rw-r--r-- | src/file_list.h | 4 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/file_list.c b/src/file_list.c index ea176ab..b71a863 100644 --- a/src/file_list.c +++ b/src/file_list.c @@ -86,7 +86,7 @@ file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, cons } log_printf(INFO, "%s filename is: %s(.?)", type, tmp->path_); - tmp->fd_ = -1; + tmp->fd_ = FILE_CLOSED; tmp->mode_ = mode; g_mutex_lock(list->mutex_); @@ -130,6 +130,9 @@ int file_list_call_post_process(file_list_t* list, int fd) 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; + // ((file_t*)tmp->data_)->pp_pid_ = ... break; } tmp = tmp->next_; @@ -141,12 +144,28 @@ int file_list_call_post_process(file_list_t* list, int fd) int file_list_waitpid(file_list_t* list) { + if(!list || !(list->mutex_)) + return -1; + + g_mutex_lock(list->mutex_); + slist_element_t* tmp = list->list_.first_; + while(tmp) { + if(((file_t*)tmp->data_)->fd_ == FILE_POST_PROCESS) { + // int status; + // int ret = waitpid(((file_t*)tmp->data_)->pp_pid_, &status, WHOHANG); + // ... + slist_remove(&(list->list_), tmp->data_); + } + tmp = tmp->next_; + } + g_mutex_unlock(list->mutex_); + return 0; } int open_file(file_t* file) { - if(!file || file->fd_ > 0) // file already open! + if(!file || file->fd_ != FILE_CLOSED) // file already open! return -1; char* orig_path = file->path_; @@ -159,8 +178,9 @@ int open_file(file_t* file) log_printf(ERROR, "can't open file '%s': %s", file->path_, strerror(errno)); if(orig_path != file->path_) free(orig_path); + file->fd_ = FILE_CLOSED; return -1; - } + } cnt++; char* tmp; asprintf(&tmp, "%s.%d", orig_path, cnt); diff --git a/src/file_list.h b/src/file_list.h index 5dd30d1..daed7ad 100644 --- a/src/file_list.h +++ b/src/file_list.h @@ -35,10 +35,14 @@ #include "slist.h" +#define FILE_CLOSED -1 +#define FILE_POST_PROCESS -2 + struct file_struct { int fd_; char* path_; mode_t mode_; + pid_t pp_pid_; }; typedef struct file_struct file_t; |