diff options
Diffstat (limited to 'rhdropbox.c')
-rw-r--r-- | rhdropbox.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/rhdropbox.c b/rhdropbox.c index 90694f7..234d24d 100644 --- a/rhdropbox.c +++ b/rhdropbox.c @@ -111,10 +111,10 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst char* const argv[] = { opt->script_, path, event->len > 0 ? event->name : "", buf, NULL }; char* const evp[] = { NULL }; - rh_exec(opt->script_, argv, evp, child_lst); + rh_exec(opt->script_, argv, evp, child_lst, opt); snprintf(buf, 100, "new file in '%s', name='%s'", path, event->len > 0 ? event->name : ""); - log_printf(NOTICE, "%s, executed script %s", buf, opt->script_); + log_printf(NOTICE, "%s, executing script %s", buf, opt->script_); client_t* client; int listener_cnt = 0; for(client = client_lst; client; client = client->next) @@ -142,6 +142,9 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst void send_status_watch_list(int fd, watch_list_t* watch_lst, client_t* client_lst) { + if(fd <= 0 && !client_lst) + return; + if(!watch_lst || !watch_lst->first_) { if(fd > 0) send_response(fd, "currently no paths in watch list"); @@ -191,7 +194,8 @@ void process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inoti wd = inotify_rm_watch(inotify_fd, tmp_fd); else { log_printf(ERROR, "cmd_add_remove path not found in watch list"); - send_response(fd, "Error: path not found in watch list"); + if(fd > 0) + send_response(fd, "Error: path not found in watch list"); return; } } @@ -201,7 +205,8 @@ void process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inoti } if(wd < 0) { log_printf(ERROR, "inotify %s '%s' failed: %s", cmd_id == ADD ? "adding" : "removing", path, strerror(errno)); - send_response(fd, "Error: add/remove failed"); + if(fd > 0) + send_response(fd, "Error: add/remove failed"); return; } @@ -210,7 +215,8 @@ void process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inoti ret = watch_list_add(watch_lst, wd, path); if(ret) { log_printf(ERROR, "can't add path to watch list"); - send_response(fd, "Error: can't add path to watch list"); + if(fd > 0) + send_response(fd, "Error: can't add path to watch list"); } } else { @@ -350,6 +356,10 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt) FD_SET(sig_fd, &readfds); max_fd = (max_fd < sig_fd) ? sig_fd : max_fd; + string_list_element_t* dir = opt->dirs_.first_; + for(;dir;dir=dir->next_) + process_cmd_add_remove(ADD, dir->string_, -1, inotify_fd, &watch_lst, client_lst); + struct timeval timeout; int return_value = 0; while(!return_value) { @@ -366,7 +376,7 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt) if(ret == -1) continue; if(!ret) { - rh_waitpid(&child_lst); + rh_waitpid(&child_lst, opt); continue; } |