summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rhdropbox.c24
-rw-r--r--watch_list.c2
2 files changed, 19 insertions, 7 deletions
diff --git a/rhdropbox.c b/rhdropbox.c
index 2478616..3c16ba6 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, options_t* opt)
+int process_watch(int inotify_fd, read_buffer_t* buffer, watch_list_t* watch_lst, options_t* opt)
{
log_printf(DEBUG, "something changed on watch descriptor '%d'", inotify_fd);
@@ -82,6 +82,19 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, options_t* opt)
event = (struct inotify_event*)buffer->buf;
u_int32_t len = sizeof(struct inotify_event) + event->len;
if(buffer->offset >= len) {
+ 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);
+ }
+ else if(event->mask & IN_IGNORED) {
+ log_printf(DEBUG, "ignoring inotify_rm_watch based events");
+ }
+ else {
+/* call script here */
/* client_t* client; */
/* int listener_cnt = 0; */
/* for(client = client_lst; client; client = client->next) */
@@ -90,9 +103,8 @@ int process_watch(int inotify_fd, read_buffer_t* buffer, options_t* opt)
/* listener_cnt++; */
/* } */
/* log_printf(DEBUG, "sent status to %d additional listeners", listener_cnt); */
- log_printf(DEBUG, "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(buffer->offset > len) {
memmove(buffer->buf, &buffer->buf[len], buffer->offset - len);
buffer->offset -= len;
@@ -112,7 +124,7 @@ int process_cmd_add_remove(cmd_id_t cmd_id, const char* path, int fd, int inotif
{
int wd = 0;
if(cmd_id == ADD)
- wd = inotify_add_watch(inotify_fd, path, IN_CLOSE_WRITE);
+ wd = inotify_add_watch(inotify_fd, path, IN_CLOSE_WRITE | IN_DELETE_SELF | IN_MOVE_SELF | IN_ONLYDIR);
else if(cmd_id == REMOVE) {
int fd = watch_list_find_fd(watch_lst, path);
if(fd >= 0)
@@ -314,7 +326,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, opt);
+ return_value = process_watch(inotify_fd, &event_buffer, &watch_lst, opt);
if(return_value)
break;
}
diff --git a/watch_list.c b/watch_list.c
index 28ca97d..7e23b93 100644
--- a/watch_list.c
+++ b/watch_list.c
@@ -90,7 +90,7 @@ int watch_list_add(watch_list_t* list, int watch_fd, const char* string)
void watch_list_rm(watch_list_t* list, const char* path)
{
- if(!list)
+ if(!list || !path)
return;
watch_list_element_t* tmp = NULL;