diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index 6ff1de5b5fec0e5f52b3c51cfad951e1f2b49d78..c82b61fd14cec1efa94cc1172e348f6b5cf47caa 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -379,6 +379,8 @@ static bool notifyd_apply_rec_change( size_t num_instances; size_t i; struct notifyd_instance *instance; + struct notifyd_instance *inst; + void *sys_watch; TDB_DATA value; NTSTATUS status; bool ok = false; @@ -460,24 +462,52 @@ static bool notifyd_apply_rec_change( if ((instance->instance.filter != 0) || (instance->instance.subdir_filter != 0)) { int ret; + sys_watch = NULL; - TALLOC_FREE(instance->sys_watch); + for (i=0; iinstance.filter == inst->instance.filter && + instance->instance.subdir_filter == inst->instance.subdir_filter) { + sys_watch = inst->sys_watch; + break; + } + } + if(sys_watch != NULL) { + /* reuse sys_watch */ + instance->sys_watch = sys_watch; + } else { + TALLOC_FREE(instance->sys_watch); - ret = sys_notify_watch(entries, sys_notify_ctx, path, + ret = sys_notify_watch(entries, sys_notify_ctx, path, &instance->internal_filter, &instance->internal_subdir_filter, notifyd_sys_callback, msg_ctx, &instance->sys_watch); - if (ret != 0) { - DBG_WARNING("sys_notify_watch for [%s] returned %s\n", + if (ret != 0) { + DBG_WARNING("sys_notify_watch for [%s] returned %s\n", path, strerror(errno)); + } } } if ((instance->instance.filter == 0) && (instance->instance.subdir_filter == 0)) { - /* This is a delete request */ - TALLOC_FREE(instance->sys_watch); + bool found = false; + for (i=0; isys_watch == inst->sys_watch) { + found = true; + break; + } + } + if(!found) { + /* This is a delete request */ + TALLOC_FREE(instance->sys_watch); + } *instance = instances[num_instances-1]; num_instances -= 1; }