summaryrefslogtreecommitdiff
path: root/rhdropbox.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2009-11-20 02:11:28 (GMT)
committerChristian Pointner <equinox@helsinki.at>2009-11-20 02:11:28 (GMT)
commit440f0502990098326b2d8e4935da35809a0532a8 (patch)
tree049523d9d2bb299dd5dfd9c4f29f3fe77b64874b /rhdropbox.c
parent45a56fdac919977e22d8ad4bc73d5d223520b338 (diff)
add and remove should work now
Diffstat (limited to 'rhdropbox.c')
-rw-r--r--rhdropbox.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/rhdropbox.c b/rhdropbox.c
index bc8eaf5..1fbd56f 100644
--- a/rhdropbox.c
+++ b/rhdropbox.c
@@ -81,13 +81,21 @@ int process_watch(int inotify_fd)
return 0;
}
-int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotify_fd)
+int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotify_fd, watch_list_t* watch_lst)
{
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 if(cmd_id == REMOVE) {
+ int fd = watch_list_find_fd(watch_lst, path);
+ if(fd >= 0)
+ wd = inotify_rm_watch(inotify_fd, fd);
+ else {
+ log_printf(ERROR, "cmd_add_remove path not found in watch list");
+ send_response(fd, "Error: path not found in watch list");
+ return 0;
+ }
+ }
else {
log_printf(WARNING, "cmd_add_remove ignoring wrong cmd_id");
return 0;
@@ -98,11 +106,22 @@ int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotif
return 0;
}
- // add/remove path to/from list
+ int ret = 0;
+ if(cmd_id == ADD) {
+ 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 wath list");
+ }
+ }
+ else {
+ watch_list_rm(watch_lst, path);
+ }
- log_printf(ERROR, "inotify %s '%s'", cmd_id == ADD ? "added" : "removed", path);
+ if(!ret)
+ log_printf(ERROR, "inotify %s '%s'", cmd_id == ADD ? "added" : "removed", path);
- return 0;
+ return ret;
}
void process_cmd_listen(const char* param, int fd, client_t* client_lst)
@@ -131,12 +150,13 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
log_printf(DEBUG, "listener %d requests %s messages", fd, param ? param:"all");
}
else {
+
log_printf(ERROR, "unable to add listener %d", fd);
send_response(fd, "Error: listen: client not found in client list?!");
}
}
-int process_cmd(const char* cmd, int fd, int inotify_fd, client_t* client_lst, options_t* opt)
+int process_cmd(const char* cmd, int fd, int inotify_fd, watch_list_t* watch_lst, client_t* client_lst, options_t* opt)
{
log_printf(DEBUG, "processing command from %d", fd);
@@ -186,7 +206,7 @@ int process_cmd(const char* cmd, int fd, int inotify_fd, client_t* client_lst, o
switch(cmd_id) {
case ADD:
case REMOVE: {
- int ret = process_cmd_add_remove(cmd_id, param, fd, inotify_fd);
+ int ret = process_cmd_add_remove(cmd_id, param, fd, inotify_fd, watch_lst);
if(ret)
return ret;
break;
@@ -219,6 +239,9 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt)
read_buffer_t switch_buffer;
switch_buffer.offset = 0;
+ watch_list_t watch_lst;
+ watch_list_init(&watch_lst);
+
int sig_fd = signal_init();
if(sig_fd < 0)
return -1;
@@ -268,7 +291,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, inotify_fd, client_lst, opt);
+ return_value = nonblock_recvline(&(lst->buffer), lst->fd, inotify_fd, &watch_lst, client_lst, opt);
if(return_value == 2) {
log_printf(DEBUG, "removing closed command connection (fd=%d)", lst->fd);
client_t* deletee = lst;
@@ -286,6 +309,7 @@ int main_loop(int cmd_listen_fd, int inotify_fd, options_t* opt)
}
}
+ watch_list_clear(&watch_lst);
client_clear(&client_lst);
signal_stop();
return return_value;