summaryrefslogtreecommitdiff
path: root/src/file_list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/file_list.c')
-rw-r--r--src/file_list.c24
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_);