diff options
author | Christian Pointner <equinox@helsinki.at> | 2011-04-24 22:01:25 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2011-04-24 22:01:25 (GMT) |
commit | 20ae6e2cc2bf30432333c036a0efd551f125caf4 (patch) | |
tree | c9c4fe55e4c185d369802bb19e8ab7d7611e29a4 /src/file_list.c | |
parent | 44c4330ebf74fb57205a5e1d73436f3c06f2b033 (diff) |
added exec for post processing
Diffstat (limited to 'src/file_list.c')
-rw-r--r-- | src/file_list.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/file_list.c b/src/file_list.c index 00b8b12..bced939 100644 --- a/src/file_list.c +++ b/src/file_list.c @@ -45,6 +45,7 @@ static void delete_file(void* element) log_printf(INFO, "removing/closing file '%s' -> %d", deletee->path_, deletee->fd_); if(deletee->path_) free(deletee->path_); if(deletee->fd_ >= 0) close(deletee->fd_); + if(deletee->pp_child_) free_child(deletee->pp_child_); } int file_list_init(file_list_t* list) @@ -85,6 +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_ = FILE_CLOSED; tmp->mode_ = mode; + tmp->pp_child_ = NULL; g_mutex_lock(list->mutex_); if(slist_add(&(list->list_), tmp) == NULL) { @@ -117,7 +119,7 @@ int file_list_remove(file_list_t* list, int fd) return 0; } -int file_list_call_post_process(file_list_t* list, int fd) +int file_list_call_post_process(file_list_t* list, int fd, const char* script) { if(!list || !(list->mutex_)) return -1; @@ -129,7 +131,13 @@ int file_list_call_post_process(file_list_t* list, int 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_ = ... + + 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); + if(!((file_t*)tmp->data_)->pp_child_) + slist_remove(&(list->list_), tmp->data_); + break; } tmp = tmp->next_; @@ -148,12 +156,14 @@ int file_list_waitpid(file_list_t* list) 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_); + int ret = rh_waitpid(((file_t*)tmp->data_)->pp_child_, NULL); + file_t* deletee = tmp->data_; + tmp = tmp->next_; + if(ret) + slist_remove(&(list->list_), deletee); } - tmp = tmp->next_; + else + tmp = tmp->next_; } g_mutex_unlock(list->mutex_); |