summaryrefslogtreecommitdiff
path: root/rhdropbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'rhdropbox.c')
-rw-r--r--rhdropbox.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/rhdropbox.c b/rhdropbox.c
index 5a6c2ee..0f0ef32 100644
--- a/rhdropbox.c
+++ b/rhdropbox.c
@@ -120,7 +120,36 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst
return 0;
}
-int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotify_fd, watch_list_t* watch_lst)
+void send_status_watch_list(int fd, watch_list_t* watch_lst, client_t* client_lst)
+{
+ if(!watch_lst || !watch_lst->first_) {
+ if(fd > 0)
+ send_response(fd, "currently no paths in watch list");
+ return;
+ }
+
+ char buf[100];
+ int listener_cnt;
+ watch_list_element_t* tmp = watch_lst->first_;
+ while(tmp) {
+ snprintf(buf, 100, "%3d: %s", tmp->watch_fd_, tmp->path_);
+ if(fd > 0)
+ send_response(fd, buf);
+ listener_cnt = 0;
+ client_t* client;
+ for(client = client_lst; client; client = client->next)
+ if(client->status_listener && client->fd != fd) {
+ send_response(client->fd, buf);
+ listener_cnt++;
+ }
+ tmp = tmp->next_;
+ }
+ log_printf(DEBUG, "sent status to %d additional listeners", listener_cnt);
+
+ return;
+}
+
+int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotify_fd, watch_list_t* watch_lst, client_t* client_lst)
{
int wd = 0;
int tmp_fd = watch_list_find_fd(watch_lst, path);
@@ -163,28 +192,17 @@ int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotif
watch_list_rm(watch_lst, path);
}
- if(!ret)
+ if(!ret) {
+ send_status_watch_list(-1, watch_lst, client_lst);
log_printf(ERROR, "inotify %s '%s'", cmd_id == ADD ? "added" : "removed", path);
+ }
return ret;
}
-void process_cmd_status(int fd, watch_list_t* watch_lst)
+void process_cmd_status(int fd, watch_list_t* watch_lst, client_t* client_lst)
{
- if(!watch_lst || !watch_lst->first_) {
- send_response(fd, "currently no paths in watch list");
- return;
- }
-
- char buf[100];
- watch_list_element_t* tmp = watch_lst->first_;
- while(tmp) {
- snprintf(buf, 100, "%3d: %s", tmp->watch_fd_, tmp->path_);
- send_response(fd, buf);
- tmp = tmp->next_;
- }
-
- return;
+ send_status_watch_list(fd, watch_lst, client_lst);
}
void process_cmd_listen(const char* param, int fd, client_t* client_lst)
@@ -269,12 +287,12 @@ int process_cmd(const char* cmd, int fd, int inotify_fd, watch_list_t* watch_lst
switch(cmd_id) {
case ADD:
case REMOVE: {
- int ret = process_cmd_add_remove(cmd_id, param, fd, inotify_fd, watch_lst);
+ int ret = process_cmd_add_remove(cmd_id, param, fd, inotify_fd, watch_lst, client_lst);
if(ret)
return ret;
break;
}
- case STATUS: process_cmd_status(fd, watch_lst); break;
+ case STATUS: process_cmd_status(fd, watch_lst, client_lst); break;
case LOG: {
if(param && param[0])
log_printf(NOTICE, "ext msg: %s", param);