summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-04-20 15:05:17 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-04-20 15:05:17 (GMT)
commit82de6030aca7a060c4141f180ec7beebd12ed3a3 (patch)
tree474b57cd61fe2698ccc358218a4a3b87fff320bc /src
parent50eeab7d41466ec0360457b676271fb7a9337d16 (diff)
file list waitpid added
Diffstat (limited to 'src')
-rw-r--r--src/file_list.c26
-rw-r--r--src/file_list.h4
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;