summaryrefslogtreecommitdiff
path: root/rhdropbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'rhdropbox.c')
-rw-r--r--rhdropbox.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/rhdropbox.c b/rhdropbox.c
index 5c3ca2d..1049fd1 100644
--- a/rhdropbox.c
+++ b/rhdropbox.c
@@ -59,7 +59,7 @@ int send_response(int fd, const char* response)
return ret;
}
-int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst, options_t* opt, client_t* client_lst)
+int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst, options_t* opt, client_t* client_lst, child_list_t* child_lst)
{
log_printf(DEBUG, "something changed on watch descriptor '%d'", inotify_fd);
@@ -96,7 +96,7 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst
else {
char* const argv[] = { opt->script_, path, event->len > 0 ? event->name : "", NULL };
char* const evp[] = { NULL };
- uanytun_exec(opt->script_, argv, evp);
+ rh_exec(opt->script_, argv, evp, child_lst);
char buf[100];
snprintf(buf, 100, "new file in '%s', name='%s'", path, event->len > 0 ? event->name : "");
@@ -328,24 +328,34 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt)
watch_list_t watch_lst;
watch_list_init(&watch_lst);
+ child_list_t child_lst;
+ child_list_init(&child_lst);
+
int sig_fd = signal_init();
if(sig_fd < 0)
return -1;
FD_SET(sig_fd, &readfds);
max_fd = (max_fd < sig_fd) ? sig_fd : max_fd;
+ struct timeval timeout;
int return_value = 0;
while(!return_value) {
memcpy(&tmpfds, &readfds, sizeof(tmpfds));
- int ret = select(max_fd+1, &tmpfds, NULL, NULL, NULL);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 200000;
+ int ret = select(max_fd+1, &tmpfds, NULL, NULL, &timeout);
if(ret == -1 && errno != EINTR) {
log_printf(ERROR, "select returned with error: %s", strerror(errno));
return_value = -1;
break;
}
- if(ret == -1 || !ret)
+ if(ret == -1)
+ continue;
+ if(!ret) {
+ rh_waitpid(&child_lst);
continue;
+ }
if(FD_ISSET(sig_fd, &tmpfds)) {
if(signal_handle()) {
@@ -355,7 +365,7 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt)
}
if(FD_ISSET(inotify_fd, &tmpfds)) {
- return_value = process_watch(inotify_fd, &event_buffer, &watch_lst, opt, client_lst);
+ return_value = process_watch(inotify_fd, &event_buffer, &watch_lst, opt, client_lst, &child_lst);
if(return_value)
break;
}
@@ -395,6 +405,7 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt)
}
}
+ child_list_clear(&child_lst);
watch_list_clear(&watch_lst);
client_clear(&client_lst);
signal_stop();