2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2006
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 this is the change notify database. It implements mechanisms for
22 storing current change notify waiters in a tdb, and checking if a
23 given event matches any of the stored notify waiiters.
27 #include "librpc/gen_ndr/ndr_notify.h"
29 struct notify_context {
30 struct db_context *db_recursive;
31 struct db_context *db_onelevel;
32 struct server_id server;
33 struct messaging_context *messaging_ctx;
34 struct notify_list *list;
35 struct notify_array *array;
37 struct sys_notify_context *sys_notify_ctx;
43 struct notify_list *next, *prev;
45 void (*callback)(void *, const struct notify_event *);
46 void *sys_notify_handle;
50 #define NOTIFY_KEY "notify array"
52 #define NOTIFY_ENABLE "notify:enable"
53 #define NOTIFY_ENABLE_DEFAULT True
55 static NTSTATUS notify_remove_all(struct notify_context *notify,
56 const struct server_id *server);
57 static void notify_handler(struct messaging_context *msg_ctx, void *private_data,
58 uint32_t msg_type, struct server_id server_id, DATA_BLOB *data);
61 destroy the notify context
63 static int notify_destructor(struct notify_context *notify)
65 messaging_deregister(notify->messaging_ctx, MSG_PVFS_NOTIFY, notify);
67 if (notify->list != NULL) {
68 notify_remove_all(notify, ¬ify->server);
75 Open up the notify.tdb database. You should close it down using
76 talloc_free(). We need the messaging_ctx to allow for notifications
79 struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
80 struct messaging_context *messaging_ctx,
81 struct event_context *ev,
82 connection_struct *conn)
84 struct notify_context *notify;
86 if (!lp_change_notify(conn->params)) {
90 notify = talloc(mem_ctx, struct notify_context);
95 notify->db_recursive = db_open(notify, lock_path("notify.tdb"),
96 0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
97 O_RDWR|O_CREAT, 0644);
98 if (notify->db_recursive == NULL) {
103 notify->db_onelevel = db_open(notify, lock_path("notify_onelevel.tdb"),
104 0, TDB_CLEAR_IF_FIRST,
105 O_RDWR|O_CREAT, 0644);
106 if (notify->db_onelevel == NULL) {
111 notify->server = server;
112 notify->messaging_ctx = messaging_ctx;
114 notify->array = NULL;
115 notify->seqnum = notify->db_recursive->get_seqnum(
116 notify->db_recursive);
117 notify->key = string_term_tdb_data(NOTIFY_KEY);
119 talloc_set_destructor(notify, notify_destructor);
121 /* register with the messaging subsystem for the notify
123 messaging_register(notify->messaging_ctx, notify,
124 MSG_PVFS_NOTIFY, notify_handler);
126 notify->sys_notify_ctx = sys_notify_context_create(conn, notify, ev);
131 bool notify_internal_parent_init(void)
133 struct tdb_wrap *db1, *db2;
135 if (lp_clustering()) {
140 * Open the tdbs in the parent process (smbd) so that our
141 * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly
145 db1 = tdb_wrap_open(talloc_autofree_context(), lock_path("notify.tdb"),
146 0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
147 O_RDWR|O_CREAT, 0644);
149 DEBUG(1, ("could not open notify.tdb: %s\n", strerror(errno)));
152 db2 = tdb_wrap_open(talloc_autofree_context(),
153 lock_path("notify_onelevel.tdb"),
154 0, TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0644);
156 DEBUG(1, ("could not open notify_onelevel.tdb: %s\n",
165 lock and fetch the record
167 static NTSTATUS notify_fetch_locked(struct notify_context *notify, struct db_record **rec)
169 *rec = notify->db_recursive->fetch_locked(notify->db_recursive,
170 notify, notify->key);
172 return NT_STATUS_INTERNAL_DB_CORRUPTION;
178 load the notify array
180 static NTSTATUS notify_load(struct notify_context *notify, struct db_record *rec)
187 seqnum = notify->db_recursive->get_seqnum(notify->db_recursive);
189 if (seqnum == notify->seqnum && notify->array != NULL) {
193 notify->seqnum = seqnum;
195 talloc_free(notify->array);
196 notify->array = TALLOC_ZERO_P(notify, struct notify_array);
197 NT_STATUS_HAVE_NO_MEMORY(notify->array);
200 if (notify->db_recursive->fetch(notify->db_recursive, notify,
201 notify->key, &dbuf) != 0) {
202 return NT_STATUS_INTERNAL_DB_CORRUPTION;
208 blob.data = (uint8 *)dbuf.dptr;
209 blob.length = dbuf.dsize;
211 status = NT_STATUS_OK;
212 if (blob.length > 0) {
213 enum ndr_err_code ndr_err;
214 ndr_err = ndr_pull_struct_blob(&blob, notify->array, NULL, notify->array,
215 (ndr_pull_flags_fn_t)ndr_pull_notify_array);
216 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
217 /* 1. log that we got a corrupt notify_array
218 * 2. clear the variable the garbage was stored into to not trip
219 * over it next time this method is entered with the same seqnum
220 * 3. delete it from the database */
221 DEBUG(2, ("notify_array is corrupt, discarding it\n"));
223 ZERO_STRUCTP(notify->array);
225 rec->delete_rec(rec);
229 if (DEBUGLEVEL >= 10) {
230 DEBUG(10, ("notify_load:\n"));
231 NDR_PRINT_DEBUG(notify_array, notify->array);
238 talloc_free(dbuf.dptr);
245 compare notify entries for sorting
247 static int notify_compare(const void *p1, const void *p2)
249 const struct notify_entry *e1 = (const struct notify_entry *)p1;
250 const struct notify_entry *e2 = (const struct notify_entry *)p2;
251 return strcmp(e1->path, e2->path);
255 save the notify array
257 static NTSTATUS notify_save(struct notify_context *notify, struct db_record *rec)
262 enum ndr_err_code ndr_err;
265 /* if possible, remove some depth arrays */
266 while (notify->array->num_depths > 0 &&
267 notify->array->depth[notify->array->num_depths-1].num_entries == 0) {
268 notify->array->num_depths--;
271 /* we might just be able to delete the record */
272 if (notify->array->num_depths == 0) {
273 return rec->delete_rec(rec);
276 tmp_ctx = talloc_new(notify);
277 NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
279 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, notify->array,
280 (ndr_push_flags_fn_t)ndr_push_notify_array);
281 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
282 talloc_free(tmp_ctx);
283 return ndr_map_error2ntstatus(ndr_err);
286 if (DEBUGLEVEL >= 10) {
287 DEBUG(10, ("notify_save:\n"));
288 NDR_PRINT_DEBUG(notify_array, notify->array);
291 dbuf.dptr = blob.data;
292 dbuf.dsize = blob.length;
294 status = rec->store(rec, dbuf, TDB_REPLACE);
295 talloc_free(tmp_ctx);
302 handle incoming notify messages
304 static void notify_handler(struct messaging_context *msg_ctx, void *private_data,
305 uint32_t msg_type, struct server_id server_id, DATA_BLOB *data)
307 struct notify_context *notify = talloc_get_type(private_data, struct notify_context);
308 enum ndr_err_code ndr_err;
309 struct notify_event ev;
310 TALLOC_CTX *tmp_ctx = talloc_new(notify);
311 struct notify_list *listel;
313 if (tmp_ctx == NULL) {
317 ndr_err = ndr_pull_struct_blob(data, tmp_ctx, NULL, &ev,
318 (ndr_pull_flags_fn_t)ndr_pull_notify_event);
319 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
320 talloc_free(tmp_ctx);
324 for (listel=notify->list;listel;listel=listel->next) {
325 if (listel->private_data == ev.private_data) {
326 listel->callback(listel->private_data, &ev);
331 talloc_free(tmp_ctx);
335 callback from sys_notify telling us about changes from the OS
337 static void sys_notify_callback(struct sys_notify_context *ctx,
338 void *ptr, struct notify_event *ev)
340 struct notify_list *listel = talloc_get_type(ptr, struct notify_list);
341 ev->private_data = listel;
342 DEBUG(10, ("sys_notify_callback called with action=%d, for %s\n",
343 ev->action, ev->path));
344 listel->callback(listel->private_data, ev);
348 add an entry to the notify array
350 static NTSTATUS notify_add_array(struct notify_context *notify, struct db_record *rec,
351 struct notify_entry *e,
352 void *private_data, int depth)
355 struct notify_depth *d;
356 struct notify_entry *ee;
358 /* possibly expand the depths array */
359 if (depth >= notify->array->num_depths) {
360 d = talloc_realloc(notify->array, notify->array->depth,
361 struct notify_depth, depth+1);
362 NT_STATUS_HAVE_NO_MEMORY(d);
363 for (i=notify->array->num_depths;i<=depth;i++) {
366 notify->array->depth = d;
367 notify->array->num_depths = depth+1;
369 d = ¬ify->array->depth[depth];
371 /* expand the entries array */
372 ee = talloc_realloc(notify->array->depth, d->entries, struct notify_entry,
374 NT_STATUS_HAVE_NO_MEMORY(ee);
377 d->entries[d->num_entries] = *e;
378 d->entries[d->num_entries].private_data = private_data;
379 d->entries[d->num_entries].server = notify->server;
380 d->entries[d->num_entries].path_len = strlen(e->path);
383 d->max_mask |= e->filter;
384 d->max_mask_subdir |= e->subdir_filter;
386 if (d->num_entries > 1) {
387 qsort(d->entries, d->num_entries, sizeof(d->entries[0]), notify_compare);
390 /* recalculate the maximum masks */
392 d->max_mask_subdir = 0;
394 for (i=0;i<d->num_entries;i++) {
395 d->max_mask |= d->entries[i].filter;
396 d->max_mask_subdir |= d->entries[i].subdir_filter;
399 return notify_save(notify, rec);
403 Add a non-recursive watch
406 static void notify_add_onelevel(struct notify_context *notify,
407 struct notify_entry *e, void *private_data)
409 struct notify_entry_array *array;
410 struct db_record *rec;
413 enum ndr_err_code ndr_err;
416 array = talloc_zero(talloc_tos(), struct notify_entry_array);
421 rec = notify->db_onelevel->fetch_locked(
422 notify->db_onelevel, talloc_tos(),
423 make_tdb_data((uint8_t *)&e->dir_id, sizeof(e->dir_id)));
425 DEBUG(10, ("notify_add_onelevel: fetch_locked for %s failed"
426 "\n", file_id_string_tos(&e->dir_id)));
431 blob.data = (uint8_t *)rec->value.dptr;
432 blob.length = rec->value.dsize;
434 if (blob.length > 0) {
435 ndr_err = ndr_pull_struct_blob(
436 &blob, array, NULL, array,
437 (ndr_pull_flags_fn_t)ndr_pull_notify_entry_array);
438 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
439 DEBUG(10, ("ndr_pull_notify_entry_array failed: %s\n",
440 ndr_errstr(ndr_err)));
444 if (DEBUGLEVEL >= 10) {
445 DEBUG(10, ("notify_add_onelevel:\n"));
446 NDR_PRINT_DEBUG(notify_entry_array, array);
450 array->entries = talloc_realloc(array, array->entries,
452 array->num_entries+1);
453 if (array->entries == NULL) {
457 array->entries[array->num_entries] = *e;
458 array->entries[array->num_entries].private_data = private_data;
459 array->entries[array->num_entries].server = notify->server;
460 array->num_entries += 1;
462 ndr_err = ndr_push_struct_blob(
463 &blob, rec, NULL, array,
464 (ndr_push_flags_fn_t)ndr_push_notify_entry_array);
465 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
466 DEBUG(10, ("ndr_push_notify_entry_array failed: %s\n",
467 ndr_errstr(ndr_err)));
472 if (DEBUGLEVEL >= 10) {
473 DEBUG(10, ("notify_add_onelevel:\n"));
474 NDR_PRINT_DEBUG(notify_entry_array, array);
477 dbuf.dptr = blob.data;
478 dbuf.dsize = blob.length;
480 status = rec->store(rec, dbuf, TDB_REPLACE);
482 if (!NT_STATUS_IS_OK(status)) {
483 DEBUG(10, ("notify_add_onelevel: store failed: %s\n",
493 add a notify watch. This is called when a notify is first setup on a open
496 NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
497 void (*callback)(void *, const struct notify_event *),
500 struct notify_entry e = *e0;
502 char *tmp_path = NULL;
503 struct notify_list *listel;
506 struct db_record *rec;
508 /* see if change notify is enabled at all */
509 if (notify == NULL) {
510 return NT_STATUS_NOT_IMPLEMENTED;
513 status = notify_fetch_locked(notify, &rec);
514 NT_STATUS_NOT_OK_RETURN(status);
516 status = notify_load(notify, rec);
517 if (!NT_STATUS_IS_OK(status)) {
522 /* cope with /. on the end of the path */
523 len = strlen(e.path);
524 if (len > 1 && e.path[len-1] == '.' && e.path[len-2] == '/') {
525 tmp_path = talloc_strndup(notify, e.path, len-2);
526 if (tmp_path == NULL) {
527 status = NT_STATUS_NO_MEMORY;
533 depth = count_chars(e.path, '/');
535 listel = TALLOC_ZERO_P(notify, struct notify_list);
536 if (listel == NULL) {
537 status = NT_STATUS_NO_MEMORY;
541 listel->private_data = private_data;
542 listel->callback = callback;
543 listel->depth = depth;
544 DLIST_ADD(notify->list, listel);
546 /* ignore failures from sys_notify */
547 if (notify->sys_notify_ctx != NULL) {
549 this call will modify e.filter and e.subdir_filter
550 to remove bits handled by the backend
552 status = sys_notify_watch(notify->sys_notify_ctx, &e,
553 sys_notify_callback, listel,
554 &listel->sys_notify_handle);
555 if (NT_STATUS_IS_OK(status)) {
556 talloc_steal(listel, listel->sys_notify_handle);
561 notify_add_onelevel(notify, &e, private_data);
562 status = NT_STATUS_OK;
565 /* if the system notify handler couldn't handle some of the
566 filter bits, or couldn't handle a request for recursion
567 then we need to install it in the array used for the
568 intra-samba notify handling */
569 if (e.filter != 0 || e.subdir_filter != 0) {
570 status = notify_add_array(notify, rec, &e, private_data, depth);
575 talloc_free(tmp_path);
580 NTSTATUS notify_remove_onelevel(struct notify_context *notify,
581 const struct file_id *fid,
584 struct notify_entry_array *array;
585 struct db_record *rec;
588 enum ndr_err_code ndr_err;
592 if (notify == NULL) {
593 return NT_STATUS_NOT_IMPLEMENTED;
596 array = talloc_zero(talloc_tos(), struct notify_entry_array);
598 return NT_STATUS_NO_MEMORY;
601 rec = notify->db_onelevel->fetch_locked(
602 notify->db_onelevel, array,
603 make_tdb_data((uint8_t *)fid, sizeof(*fid)));
605 DEBUG(10, ("notify_remove_onelevel: fetch_locked for %s failed"
606 "\n", file_id_string_tos(fid)));
608 return NT_STATUS_INTERNAL_DB_CORRUPTION;
611 blob.data = (uint8_t *)rec->value.dptr;
612 blob.length = rec->value.dsize;
614 if (blob.length > 0) {
615 ndr_err = ndr_pull_struct_blob(
616 &blob, array, NULL, array,
617 (ndr_pull_flags_fn_t)ndr_pull_notify_entry_array);
618 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
619 DEBUG(10, ("ndr_pull_notify_entry_array failed: %s\n",
620 ndr_errstr(ndr_err)));
622 return ndr_map_error2ntstatus(ndr_err);
624 if (DEBUGLEVEL >= 10) {
625 DEBUG(10, ("notify_remove_onelevel:\n"));
626 NDR_PRINT_DEBUG(notify_entry_array, array);
630 for (i=0; i<array->num_entries; i++) {
631 if ((private_data == array->entries[i].private_data) &&
632 cluster_id_equal(¬ify->server,
633 &array->entries[i].server)) {
638 if (i == array->num_entries) {
640 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
643 array->entries[i] = array->entries[array->num_entries-1];
644 array->num_entries -= 1;
646 if (array->num_entries == 0) {
647 rec->delete_rec(rec);
652 ndr_err = ndr_push_struct_blob(
653 &blob, rec, NULL, array,
654 (ndr_push_flags_fn_t)ndr_push_notify_entry_array);
655 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
656 DEBUG(10, ("ndr_push_notify_entry_array failed: %s\n",
657 ndr_errstr(ndr_err)));
659 return ndr_map_error2ntstatus(ndr_err);
662 if (DEBUGLEVEL >= 10) {
663 DEBUG(10, ("notify_add_onelevel:\n"));
664 NDR_PRINT_DEBUG(notify_entry_array, array);
667 dbuf.dptr = blob.data;
668 dbuf.dsize = blob.length;
670 status = rec->store(rec, dbuf, TDB_REPLACE);
672 if (!NT_STATUS_IS_OK(status)) {
673 DEBUG(10, ("notify_add_onelevel: store failed: %s\n",
681 remove a notify watch. Called when the directory handle is closed
683 NTSTATUS notify_remove(struct notify_context *notify, void *private_data)
686 struct notify_list *listel;
688 struct notify_depth *d;
689 struct db_record *rec;
691 /* see if change notify is enabled at all */
692 if (notify == NULL) {
693 return NT_STATUS_NOT_IMPLEMENTED;
696 for (listel=notify->list;listel;listel=listel->next) {
697 if (listel->private_data == private_data) {
698 DLIST_REMOVE(notify->list, listel);
702 if (listel == NULL) {
703 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
706 depth = listel->depth;
710 status = notify_fetch_locked(notify, &rec);
711 NT_STATUS_NOT_OK_RETURN(status);
713 status = notify_load(notify, rec);
714 if (!NT_STATUS_IS_OK(status)) {
719 if (depth >= notify->array->num_depths) {
721 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
724 /* we only have to search at the depth of this element */
725 d = ¬ify->array->depth[depth];
727 for (i=0;i<d->num_entries;i++) {
728 if (private_data == d->entries[i].private_data &&
729 cluster_id_equal(¬ify->server, &d->entries[i].server)) {
733 if (i == d->num_entries) {
735 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
738 if (i < d->num_entries-1) {
739 memmove(&d->entries[i], &d->entries[i+1],
740 sizeof(d->entries[i])*(d->num_entries-(i+1)));
744 status = notify_save(notify, rec);
752 remove all notify watches for a messaging server
754 static NTSTATUS notify_remove_all(struct notify_context *notify,
755 const struct server_id *server)
758 int i, depth, del_count=0;
759 struct db_record *rec;
761 status = notify_fetch_locked(notify, &rec);
762 NT_STATUS_NOT_OK_RETURN(status);
764 status = notify_load(notify, rec);
765 if (!NT_STATUS_IS_OK(status)) {
770 /* we have to search for all entries across all depths, looking for matches
772 for (depth=0;depth<notify->array->num_depths;depth++) {
773 struct notify_depth *d = ¬ify->array->depth[depth];
774 for (i=0;i<d->num_entries;i++) {
775 if (cluster_id_equal(server, &d->entries[i].server)) {
776 if (i < d->num_entries-1) {
777 memmove(&d->entries[i], &d->entries[i+1],
778 sizeof(d->entries[i])*(d->num_entries-(i+1)));
788 status = notify_save(notify, rec);
798 send a notify message to another messaging server
800 static NTSTATUS notify_send(struct notify_context *notify, struct notify_entry *e,
801 const char *path, uint32_t action)
803 struct notify_event ev;
806 enum ndr_err_code ndr_err;
811 ev.private_data = e->private_data;
813 tmp_ctx = talloc_new(notify);
815 ndr_err = ndr_push_struct_blob(&data, tmp_ctx, NULL, &ev,
816 (ndr_push_flags_fn_t)ndr_push_notify_event);
817 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
818 talloc_free(tmp_ctx);
819 return ndr_map_error2ntstatus(ndr_err);
822 status = messaging_send(notify->messaging_ctx, e->server,
823 MSG_PVFS_NOTIFY, &data);
824 talloc_free(tmp_ctx);
828 void notify_onelevel(struct notify_context *notify, uint32_t action,
829 uint32_t filter, struct file_id fid, const char *name)
831 struct notify_entry_array *array;
834 bool have_dead_entries = false;
837 if (notify == NULL) {
841 array = talloc_zero(talloc_tos(), struct notify_entry_array);
846 if (notify->db_onelevel->fetch(
847 notify->db_onelevel, array,
848 make_tdb_data((uint8_t *)&fid, sizeof(fid)),
854 blob.data = (uint8 *)dbuf.dptr;
855 blob.length = dbuf.dsize;
857 if (blob.length > 0) {
858 enum ndr_err_code ndr_err;
859 ndr_err = ndr_pull_struct_blob(
860 &blob, array, NULL, array,
861 (ndr_pull_flags_fn_t)ndr_pull_notify_entry_array);
862 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
863 DEBUG(10, ("ndr_pull_notify_entry_array failed: %s\n",
864 ndr_errstr(ndr_err)));
868 if (DEBUGLEVEL >= 10) {
869 DEBUG(10, ("notify_onelevel:\n"));
870 NDR_PRINT_DEBUG(notify_entry_array, array);
874 for (i=0; i<array->num_entries; i++) {
875 struct notify_entry *e = &array->entries[i];
877 if ((e->filter & filter) != 0) {
880 status = notify_send(notify, e, name, action);
882 status, NT_STATUS_INVALID_HANDLE)) {
884 * Mark the entry as dead. All entries have a
885 * path set. The marker used here is setting
889 have_dead_entries = true;
894 if (!have_dead_entries) {
899 for (i=0; i<array->num_entries; i++) {
900 struct notify_entry *e = &array->entries[i];
901 if (e->path != NULL) {
904 DEBUG(10, ("Deleting notify entries for process %s because "
905 "it's gone\n", procid_str_static(&e->server)));
907 * Potential TODO: This might need optimizing,
908 * notify_remove_onelevel() does a fetch_locked() operation at
909 * every call. But this would only matter if a process with
910 * MANY notifies has died without shutting down properly.
912 notify_remove_onelevel(notify, &e->dir_id, e->private_data);
920 trigger a notify message for anyone waiting on a matching event
922 This function is called a lot, and needs to be very fast. The unusual data structure
923 and traversal is designed to be fast in the average case, even for large numbers of
926 void notify_trigger(struct notify_context *notify,
927 uint32_t action, uint32_t filter, const char *path)
931 const char *p, *next_p;
933 DEBUG(10, ("notify_trigger called action=0x%x, filter=0x%x, "
934 "path=%s\n", (unsigned)action, (unsigned)filter, path));
936 /* see if change notify is enabled at all */
937 if (notify == NULL) {
942 status = notify_load(notify, NULL);
943 if (!NT_STATUS_IS_OK(status)) {
947 /* loop along the given path, working with each directory depth separately */
949 p && depth < notify->array->num_depths;
951 int p_len = p - path;
953 struct notify_depth *d = ¬ify->array->depth[depth];
954 next_p = strchr(p+1, '/');
956 /* see if there are any entries at this depth */
957 if (d->num_entries == 0) continue;
959 /* try to skip based on the maximum mask. If next_p is
960 NULL then we know it will be a 'this directory'
961 match, otherwise it must be a subdir match */
962 if (next_p != NULL) {
963 if (0 == (filter & d->max_mask_subdir)) {
967 if (0 == (filter & d->max_mask)) {
972 /* we know there is an entry here worth looking
973 for. Use a bisection search to find the first entry
974 with a matching path */
976 max_i = d->num_entries-1;
978 while (min_i < max_i) {
979 struct notify_entry *e;
983 cmp = strncmp(path, e->path, p_len);
985 if (p_len == e->path_len) {
990 } else if (cmp < 0) {
997 if (min_i != max_i) {
1002 /* we now know that the entries start at min_i */
1003 for (i=min_i;i<d->num_entries;i++) {
1004 struct notify_entry *e = &d->entries[i];
1005 if (p_len != e->path_len ||
1006 strncmp(path, e->path, p_len) != 0) break;
1007 if (next_p != NULL) {
1008 if (0 == (filter & e->subdir_filter)) {
1012 if (0 == (filter & e->filter)) {
1016 status = notify_send(notify, e, path + e->path_len + 1,
1019 if (NT_STATUS_EQUAL(
1020 status, NT_STATUS_INVALID_HANDLE)) {
1021 struct server_id server = e->server;
1023 DEBUG(10, ("Deleting notify entries for "
1024 "process %s because it's gone\n",
1025 procid_str_static(&e->server)));
1026 notify_remove_all(notify, &server);