diff options
Diffstat (limited to 'rhdropbox.c')
-rw-r--r-- | rhdropbox.c | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/rhdropbox.c b/rhdropbox.c index a7b3681..bc8eaf5 100644 --- a/rhdropbox.c +++ b/rhdropbox.c @@ -68,10 +68,6 @@ int process_watch(int inotify_fd) return ret; } - log_printf(DEBUG, "received %d bytes from watch", ret); - return 0; -} - /* client_t* client; */ /* int listener_cnt = 0; */ /* for(client = client_lst; client; client = client->next) */ @@ -81,6 +77,34 @@ int process_watch(int inotify_fd) /* } */ /* log_printf(DEBUG, "sent status to %d additional listeners", listener_cnt); */ + log_printf(DEBUG, "received %d bytes from watch", ret); + return 0; +} + +int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotify_fd) +{ + int wd = 0; + if(cmd_id == ADD) + wd = inotify_add_watch(inotify_fd, path, IN_CLOSE_WRITE); + else if(cmd_id == REMOVE) + wd = inotify_rm_watch(inotify_fd, -1); // lookup wd from path list + else { + log_printf(WARNING, "cmd_add_remove ignoring wrong cmd_id"); + return 0; + } + 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"); + return 0; + } + + // add/remove path to/from list + + log_printf(ERROR, "inotify %s '%s'", cmd_id == ADD ? "added" : "removed", path); + + return 0; +} + void process_cmd_listen(const char* param, int fd, client_t* client_lst) { client_t* listener = client_find(client_lst, fd); @@ -112,7 +136,7 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst) } } -int process_cmd(const char* cmd, int fd, client_t* client_lst, options_t* opt) +int process_cmd(const char* cmd, int fd, int inotify_fd, client_t* client_lst, options_t* opt) { log_printf(DEBUG, "processing command from %d", fd); @@ -160,8 +184,13 @@ int process_cmd(const char* cmd, int fd, client_t* client_lst, options_t* opt) } switch(cmd_id) { - case ADD: break; - case REMOVE: break; + case ADD: + case REMOVE: { + int ret = process_cmd_add_remove(cmd_id, param, fd, inotify_fd); + if(ret) + return ret; + break; + } case STATUS: break; case LOG: { if(param && param[0]) @@ -239,7 +268,7 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt) client_t* lst = client_lst; while(lst) { if(FD_ISSET(lst->fd, &tmpfds)) { - return_value = nonblock_recvline(&(lst->buffer), lst->fd, client_lst, opt); + return_value = nonblock_recvline(&(lst->buffer), lst->fd, inotify_fd, client_lst, opt); if(return_value == 2) { log_printf(DEBUG, "removing closed command connection (fd=%d)", lst->fd); client_t* deletee = lst; |