summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rhdropbox.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/rhdropbox.c b/rhdropbox.c
index 0f0ef32..0226c2f 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)
+int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst, options_t* opt, client_t* client_lst)
{
log_printf(DEBUG, "something changed on watch descriptor '%d'", inotify_fd);
@@ -82,11 +82,11 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst
event = (struct inotify_event*)buffer->buf;
u_int32_t len = sizeof(struct inotify_event) + event->len;
if(buffer->offset >= len) {
+ char* path = watch_list_find_path(watch_lst, event->wd);
log_printf(INFO, "received event for %d (mask=0x%08X, cookie=0x%08X name[%u]='%s')",
event->wd, event->mask, event->cookie, event->len, event->len > 0 ? event->name : "");
if(event->mask & IN_DELETE_SELF || event->mask & IN_MOVE_SELF) {
- char* path = watch_list_find_path(watch_lst, event->wd);
log_printf(NOTICE, "removing deleted or moved directory ('%s') from watch list", path);
watch_list_rm(watch_lst, path);
}
@@ -95,14 +95,16 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst
}
else {
/* call script here */
-/* client_t* client; */
-/* int listener_cnt = 0; */
-/* for(client = client_lst; client; client = client->next) */
-/* if(client->status_listener && client->fd != fd) { */
-/* send_response(client->fd, buf); */
-/* listener_cnt++; */
-/* } */
-/* log_printf(DEBUG, "sent status to %d additional listeners", listener_cnt); */
+ char buf[100];
+ snprintf(buf, 100, "new file in '%s', name='%s'", path, event->len > 0 ? event->name : "");
+ client_t* client;
+ int listener_cnt = 0;
+ for(client = client_lst; client; client = client->next)
+ if(client->status_listener) {
+ send_response(client->fd, buf);
+ listener_cnt++;
+ }
+ log_printf(DEBUG, "sent status to %d additional listeners", listener_cnt);
}
if(buffer->offset > len) {
@@ -350,7 +352,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);
+ return_value = process_watch(inotify_fd, &event_buffer, &watch_lst, opt, client_lst);
if(return_value)
break;
}