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"
28 #include "librpc/gen_ndr/messaging.h"
30 struct notify_context {
31 struct db_context *db_recursive;
32 struct db_context *db_onelevel;
33 struct server_id server;
34 struct messaging_context *messaging_ctx;
35 struct notify_list *list;
36 struct notify_array *array;
38 struct sys_notify_context *sys_notify_ctx;
44 struct notify_list *next, *prev;
46 void (*callback)(void *, const struct notify_event *);
47 void *sys_notify_handle;
51 #define NOTIFY_KEY "notify array"
53 #define NOTIFY_ENABLE "notify:enable"
54 #define NOTIFY_ENABLE_DEFAULT True
56 static NTSTATUS notify_remove_all(struct notify_context *notify,
57 const struct server_id *server);
58 static void notify_handler(struct messaging_context *msg_ctx, void *private_data,
59 uint32_t msg_type, struct server_id server_id, DATA_BLOB *data);
62 destroy the notify context
64 static int notify_destructor(struct notify_context *notify)
66 messaging_deregister(notify->messaging_ctx, MSG_PVFS_NOTIFY, notify);
68 if (notify->list != NULL) {
69 notify_remove_all(notify, ¬ify->server);
76 Open up the notify.tdb database. You should close it down using
77 talloc_free(). We need the messaging_ctx to allow for notifications
80 struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
81 struct messaging_context *messaging_ctx,
82 struct event_context *ev,
83 connection_struct *conn)
85 struct notify_context *notify;
87 if (!lp_change_notify(conn->params)) {
91 notify = talloc(mem_ctx, struct notify_context);
96 notify->db_recursive = db_open(notify, lock_path("notify.tdb"),
97 0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
98 O_RDWR|O_CREAT, 0644);
99 if (notify->db_recursive == NULL) {
104 notify->db_onelevel = db_open(notify, lock_path("notify_onelevel.tdb"),
105 0, TDB_CLEAR_IF_FIRST,
106 O_RDWR|O_CREAT, 0644);
107 if (notify->db_onelevel == NULL) {
112 notify->server = server;
113 notify->messaging_ctx = messaging_ctx;
115 notify->array = NULL;
116 notify->seqnum = notify->db_recursive->get_seqnum(
117 notify->db_recursive);
118 notify->key = string_term_tdb_data(NOTIFY_KEY);
120 talloc_set_destructor(notify, notify_destructor);
122 /* register with the messaging subsystem for the notify
124 messaging_register(notify->messaging_ctx, notify,
125 MSG_PVFS_NOTIFY, notify_handler);
127 notify->sys_notify_ctx = sys_notify_context_create(conn, notify, ev);
132 bool notify_internal_parent_init(void)
134 struct tdb_wrap *db1, *db2;
136 if (lp_clustering()) {
141 * Open the tdbs in the parent process (smbd) so that our
142 * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly
146 db1 = tdb_wrap_open(talloc_autofree_context(), lock_path("notify.tdb"),
147 0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
148 O_RDWR|O_CREAT, 0644);
150 DEBUG(1, ("could not open notify.tdb: %s\n", strerror(errno)));
153 db2 = tdb_wrap_open(talloc_autofree_context(),
154 lock_path("notify_onelevel.tdb"),
155 0, TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0644);
157 DEBUG(1, ("could not open notify_onelevel.tdb: %s\n",
166 lock and fetch the record
168 static NTSTATUS notify_fetch_locked(struct notify_context *notify, struct db_record **rec)
170 *rec = notify->db_recursive->fetch_locked(notify->db_recursive,
171 notify, notify->key);
173 return NT_STATUS_INTERNAL_DB_CORRUPTION;
179 load the notify array
181 static NTSTATUS notify_load(struct notify_context *notify, struct db_record *rec)
188 seqnum = notify->db_recursive->get_seqnum(notify->db_recursive);
190 if (seqnum == notify->seqnum && notify->array != NULL) {
194 notify->seqnum = seqnum;
196 talloc_free(notify->array);
197 notify->array = TALLOC_ZERO_P(notify, struct notify_array);
198 NT_STATUS_HAVE_NO_MEMORY(notify->array);
201 if (notify->db_recursive->fetch(notify->db_recursive, notify,
202 notify->key, &dbuf) != 0) {
203 return NT_STATUS_INTERNAL_DB_CORRUPTION;
209 blob.data = (uint8 *)dbuf.dptr;
210 blob.length = dbuf.dsize;
212 status = NT_STATUS_OK;
213 if (blob.length > 0) {
214 enum ndr_err_code ndr_err;
215 ndr_err = ndr_pull_struct_blob(&blob, notify->array, NULL, notify->array,
216 (ndr_pull_flags_fn_t)ndr_pull_notify_array);
217 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
218 /* 1. log that we got a corrupt notify_array
219 * 2. clear the variable the garbage was stored into to not trip
220 * over it next time this method is entered with the same seqnum
221 * 3. delete it from the database */
222 DEBUG(2, ("notify_array is corrupt, discarding it\n"));
224 ZERO_STRUCTP(notify->array);
226 rec->delete_rec(rec);
230 if (DEBUGLEVEL >= 10) {
231 DEBUG(10, ("notify_load:\n"));
232 NDR_PRINT_DEBUG(notify_array, notify->array);
239 talloc_free(dbuf.dptr);
246 compare notify entries for sorting
248 static int notify_compare(const struct notify_entry *e1, const struct notify_entry *e2)
250 return strcmp(e1->path, e2->path);
254 save the notify array
256 static NTSTATUS notify_save(struct notify_context *notify, struct db_record *rec)
261 enum ndr_err_code ndr_err;
264 /* if possible, remove some depth arrays */
265 while (notify->array->num_depths > 0 &&
266 notify->array->depth[notify->array->num_depths-1].num_entries == 0) {
267 notify->array->num_depths--;
270 /* we might just be able to delete the record */
271 if (notify->array->num_depths == 0) {
272 return rec->delete_rec(rec);
275 tmp_ctx = talloc_new(notify);
276 NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
278 ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, notify->array,
279 (ndr_push_flags_fn_t)ndr_push_notify_array);
280 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
281 talloc_free(tmp_ctx);
282 return ndr_map_error2ntstatus(ndr_err);
285 if (DEBUGLEVEL >= 10) {
286 DEBUG(10, ("notify_save:\n"));
287 NDR_PRINT_DEBUG(notify_array, notify->array);
290 dbuf.dptr = blob.data;
291 dbuf.dsize = blob.length;
293 status = rec->store(rec, dbuf, TDB_REPLACE);
294 talloc_free(tmp_ctx);
301 handle incoming notify messages
303 static void notify_handler(struct messaging_context *msg_ctx, void *private_data,
304 uint32_t msg_type, struct server_id server_id, DATA_BLOB *data)
306 struct notify_context *notify = talloc_get_type(private_data, struct notify_context);
307 enum ndr_err_code ndr_err;
308 struct notify_event ev;
309 TALLOC_CTX *tmp_ctx = talloc_new(notify);
310 struct notify_list *listel;
312 if (tmp_ctx == NULL) {
316 ndr_err = ndr_pull_struct_blob(data, tmp_ctx, NULL, &ev,
317 (ndr_pull_flags_fn_t)ndr_pull_notify_event);
318 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
319 talloc_free(tmp_ctx);
323 for (listel=notify->list;listel;listel=listel->next) {
324 if (listel->private_data == ev.private_data) {
325 listel->callback(listel->private_data, &ev);
330 talloc_free(tmp_ctx);
334 callback from sys_notify telling us about changes from the OS
336 static void sys_notify_callback(struct sys_notify_context *ctx,
337 void *ptr, struct notify_event *ev)
339 struct notify_list *listel = talloc_get_type(ptr, struct notify_list);
340 ev->private_data = listel;
341 DEBUG(10, ("sys_notify_callback called with action=%d, for %s\n",
342 ev->action, ev->path));
343 listel->callback(listel->private_data, ev);
347 add an entry to the notify array
349 static NTSTATUS notify_add_array(struct notify_context *notify, struct db_record *rec,
350 struct notify_entry *e,
351 void *private_data, int depth)
354 struct notify_depth *d;
355 struct notify_entry *ee;
357 /* possibly expand the depths array */
358 if (depth >= notify->array->num_depths) {
359 d = talloc_realloc(notify->array, notify->array->depth,
360 struct notify_depth, depth+1);
361 NT_STATUS_HAVE_NO_MEMORY(d);
362 for (i=notify->array->num_depths;i<=depth;i++) {
365 notify->array->depth = d;
366 notify->array->num_depths = depth+1;
368 d = ¬ify->array->depth[depth];
370 /* expand the entries array */
371 ee = talloc_realloc(notify->array->depth, d->entries, struct notify_entry,
373 NT_STATUS_HAVE_NO_MEMORY(ee);
376 d->entries[d->num_entries] = *e;
377 d->entries[d->num_entries].private_data = private_data;
378 d->entries[d->num_entries].server = notify->server;
379 d->entries[d->num_entries].path_len = strlen(e->path);
382 d->max_mask |= e->filter;
383 d->max_mask_subdir |= e->subdir_filter;
385 TYPESAFE_QSORT(d->entries, d->num_entries, notify_compare);
387 /* recalculate the maximum masks */
389 d->max_mask_subdir = 0;
391 for (i=0;i<d->num_entries;i++) {
392 d->max_mask |= d->entries[i].filter;
393 d->max_mask_subdir |= d->entries[i].subdir_filter;
396 return notify_save(notify, rec);
400 Add a non-recursive watch
403 static void notify_add_onelevel(struct notify_context *notify,
404 struct notify_entry *e, void *private_data)
406 struct notify_entry_array *array;
407 struct db_record *rec;
410 enum ndr_err_code ndr_err;
413 array = talloc_zero(talloc_tos(), struct notify_entry_array);
418 rec = notify->db_onelevel->fetch_locked(
419 notify->db_onelevel, talloc_tos(),
420 make_tdb_data((uint8_t *)&e->dir_id, sizeof(e->dir_id)));
422 DEBUG(10, ("notify_add_onelevel: fetch_locked for %s failed"
423 "\n", file_id_string_tos(&e->dir_id)));
428 blob.data = (uint8_t *)rec->value.dptr;
429 blob.length = rec->value.dsize;
431 if (blob.length > 0) {
432 ndr_err = ndr_pull_struct_blob(
433 &blob, array, NULL, array,
434 (ndr_pull_flags_fn_t)ndr_pull_notify_entry_array);
435 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
436 DEBUG(10, ("ndr_pull_notify_entry_array failed: %s\n",
437 ndr_errstr(ndr_err)));
441 if (DEBUGLEVEL >= 10) {
442 DEBUG(10, ("notify_add_onelevel:\n"));
443 NDR_PRINT_DEBUG(notify_entry_array, array);
447 array->entries = talloc_realloc(array, array->entries,
449 array->num_entries+1);
450 if (array->entries == NULL) {
454 array->entries[array->num_entries] = *e;
455 array->entries[array->num_entries].private_data = private_data;
456 array->entries[array->num_entries].server = notify->server;
457 array->num_entries += 1;
459 ndr_err = ndr_push_struct_blob(
460 &blob, rec, NULL, array,
461 (ndr_push_flags_fn_t)ndr_push_notify_entry_array);
462 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
463 DEBUG(10, ("ndr_push_notify_entry_array failed: %s\n",
464 ndr_errstr(ndr_err)));
469 if (DEBUGLEVEL >= 10) {
470 DEBUG(10, ("notify_add_onelevel:\n"));
471 NDR_PRINT_DEBUG(notify_entry_array, array);
474 dbuf.dptr = blob.data;
475 dbuf.dsize = blob.length;
477 status = rec->store(rec, dbuf, TDB_REPLACE);
479 if (!NT_STATUS_IS_OK(status)) {
480 DEBUG(10, ("notify_add_onelevel: store failed: %s\n",
490 add a notify watch. This is called when a notify is first setup on a open
493 NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
494 void (*callback)(void *, const struct notify_event *),
497 struct notify_entry e = *e0;
499 char *tmp_path = NULL;
500 struct notify_list *listel;
503 struct db_record *rec;
505 /* see if change notify is enabled at all */
506 if (notify == NULL) {
507 return NT_STATUS_NOT_IMPLEMENTED;
510 status = notify_fetch_locked(notify, &rec);
511 NT_STATUS_NOT_OK_RETURN(status);
513 status = notify_load(notify, rec);
514 if (!NT_STATUS_IS_OK(status)) {
519 /* cope with /. on the end of the path */
520 len = strlen(e.path);
521 if (len > 1 && e.path[len-1] == '.' && e.path[len-2] == '/') {
522 tmp_path = talloc_strndup(notify, e.path, len-2);
523 if (tmp_path == NULL) {
524 status = NT_STATUS_NO_MEMORY;
530 depth = count_chars(e.path, '/');
532 listel = TALLOC_ZERO_P(notify, struct notify_list);
533 if (listel == NULL) {
534 status = NT_STATUS_NO_MEMORY;
538 listel->private_data = private_data;
539 listel->callback = callback;
540 listel->depth = depth;
541 DLIST_ADD(notify->list, listel);
543 /* ignore failures from sys_notify */
544 if (notify->sys_notify_ctx != NULL) {
546 this call will modify e.filter and e.subdir_filter
547 to remove bits handled by the backend
549 status = sys_notify_watch(notify->sys_notify_ctx, &e,
550 sys_notify_callback, listel,
551 &listel->sys_notify_handle);
552 if (NT_STATUS_IS_OK(status)) {
553 talloc_steal(listel, listel->sys_notify_handle);
558 notify_add_onelevel(notify, &e, private_data);
559 status = NT_STATUS_OK;
562 /* if the system notify handler couldn't handle some of the
563 filter bits, or couldn't handle a request for recursion
564 then we need to install it in the array used for the
565 intra-samba notify handling */
566 if (e.filter != 0 || e.subdir_filter != 0) {
567 status = notify_add_array(notify, rec, &e, private_data, depth);
572 talloc_free(tmp_path);
577 NTSTATUS notify_remove_onelevel(struct notify_context *notify,
578 const struct file_id *fid,
581 struct notify_entry_array *array;
582 struct db_record *rec;
585 enum ndr_err_code ndr_err;
589 if (notify == NULL) {
590 return NT_STATUS_NOT_IMPLEMENTED;
593 array = talloc_zero(talloc_tos(), struct notify_entry_array);
595 return NT_STATUS_NO_MEMORY;
598 rec = notify->db_onelevel->fetch_locked(
599 notify->db_onelevel, array,
600 make_tdb_data((uint8_t *)fid, sizeof(*fid)));
602 DEBUG(10, ("notify_remove_onelevel: fetch_locked for %s failed"
603 "\n", file_id_string_tos(fid)));
605 return NT_STATUS_INTERNAL_DB_CORRUPTION;
608 blob.data = (uint8_t *)rec->value.dptr;
609 blob.length = rec->value.dsize;
611 if (blob.length > 0) {
612 ndr_err = ndr_pull_struct_blob(
613 &blob, array, NULL, array,
614 (ndr_pull_flags_fn_t)ndr_pull_notify_entry_array);
615 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
616 DEBUG(10, ("ndr_pull_notify_entry_array failed: %s\n",
617 ndr_errstr(ndr_err)));
619 return ndr_map_error2ntstatus(ndr_err);
621 if (DEBUGLEVEL >= 10) {
622 DEBUG(10, ("notify_remove_onelevel:\n"));
623 NDR_PRINT_DEBUG(notify_entry_array, array);
627 for (i=0; i<array->num_entries; i++) {
628 if ((private_data == array->entries[i].private_data) &&
629 cluster_id_equal(¬ify->server,
630 &array->entries[i].server)) {
635 if (i == array->num_entries) {
637 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
640 array->entries[i] = array->entries[array->num_entries-1];
641 array->num_entries -= 1;
643 if (array->num_entries == 0) {
644 rec->delete_rec(rec);
649 ndr_err = ndr_push_struct_blob(
650 &blob, rec, NULL, array,
651 (ndr_push_flags_fn_t)ndr_push_notify_entry_array);
652 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
653 DEBUG(10, ("ndr_push_notify_entry_array failed: %s\n",
654 ndr_errstr(ndr_err)));
656 return ndr_map_error2ntstatus(ndr_err);
659 if (DEBUGLEVEL >= 10) {
660 DEBUG(10, ("notify_add_onelevel:\n"));
661 NDR_PRINT_DEBUG(notify_entry_array, array);
664 dbuf.dptr = blob.data;
665 dbuf.dsize = blob.length;
667 status = rec->store(rec, dbuf, TDB_REPLACE);
669 if (!NT_STATUS_IS_OK(status)) {
670 DEBUG(10, ("notify_add_onelevel: store failed: %s\n",
678 remove a notify watch. Called when the directory handle is closed
680 NTSTATUS notify_remove(struct notify_context *notify, void *private_data)
683 struct notify_list *listel;
685 struct notify_depth *d;
686 struct db_record *rec;
688 /* see if change notify is enabled at all */
689 if (notify == NULL) {
690 return NT_STATUS_NOT_IMPLEMENTED;
693 for (listel=notify->list;listel;listel=listel->next) {
694 if (listel->private_data == private_data) {
695 DLIST_REMOVE(notify->list, listel);
699 if (listel == NULL) {
700 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
703 depth = listel->depth;
707 status = notify_fetch_locked(notify, &rec);
708 NT_STATUS_NOT_OK_RETURN(status);
710 status = notify_load(notify, rec);
711 if (!NT_STATUS_IS_OK(status)) {
716 if (depth >= notify->array->num_depths) {
718 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
721 /* we only have to search at the depth of this element */
722 d = ¬ify->array->depth[depth];
724 for (i=0;i<d->num_entries;i++) {
725 if (private_data == d->entries[i].private_data &&
726 cluster_id_equal(¬ify->server, &d->entries[i].server)) {
730 if (i == d->num_entries) {
732 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
735 if (i < d->num_entries-1) {
736 memmove(&d->entries[i], &d->entries[i+1],
737 sizeof(d->entries[i])*(d->num_entries-(i+1)));
741 status = notify_save(notify, rec);
749 remove all notify watches for a messaging server
751 static NTSTATUS notify_remove_all(struct notify_context *notify,
752 const struct server_id *server)
755 int i, depth, del_count=0;
756 struct db_record *rec;
758 status = notify_fetch_locked(notify, &rec);
759 NT_STATUS_NOT_OK_RETURN(status);
761 status = notify_load(notify, rec);
762 if (!NT_STATUS_IS_OK(status)) {
767 /* we have to search for all entries across all depths, looking for matches
769 for (depth=0;depth<notify->array->num_depths;depth++) {
770 struct notify_depth *d = ¬ify->array->depth[depth];
771 for (i=0;i<d->num_entries;i++) {
772 if (cluster_id_equal(server, &d->entries[i].server)) {
773 if (i < d->num_entries-1) {
774 memmove(&d->entries[i], &d->entries[i+1],
775 sizeof(d->entries[i])*(d->num_entries-(i+1)));
785 status = notify_save(notify, rec);
795 send a notify message to another messaging server
797 static NTSTATUS notify_send(struct notify_context *notify, struct notify_entry *e,
798 const char *path, uint32_t action)
800 struct notify_event ev;
803 enum ndr_err_code ndr_err;
808 ev.private_data = e->private_data;
810 tmp_ctx = talloc_new(notify);
812 ndr_err = ndr_push_struct_blob(&data, tmp_ctx, NULL, &ev,
813 (ndr_push_flags_fn_t)ndr_push_notify_event);
814 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
815 talloc_free(tmp_ctx);
816 return ndr_map_error2ntstatus(ndr_err);
819 status = messaging_send(notify->messaging_ctx, e->server,
820 MSG_PVFS_NOTIFY, &data);
821 talloc_free(tmp_ctx);
825 void notify_onelevel(struct notify_context *notify, uint32_t action,
826 uint32_t filter, struct file_id fid, const char *name)
828 struct notify_entry_array *array;
831 bool have_dead_entries = false;
834 if (notify == NULL) {
838 array = talloc_zero(talloc_tos(), struct notify_entry_array);
843 if (notify->db_onelevel->fetch(
844 notify->db_onelevel, array,
845 make_tdb_data((uint8_t *)&fid, sizeof(fid)),
851 blob.data = (uint8 *)dbuf.dptr;
852 blob.length = dbuf.dsize;
854 if (blob.length > 0) {
855 enum ndr_err_code ndr_err;
856 ndr_err = ndr_pull_struct_blob(
857 &blob, array, NULL, array,
858 (ndr_pull_flags_fn_t)ndr_pull_notify_entry_array);
859 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
860 DEBUG(10, ("ndr_pull_notify_entry_array failed: %s\n",
861 ndr_errstr(ndr_err)));
865 if (DEBUGLEVEL >= 10) {
866 DEBUG(10, ("notify_onelevel:\n"));
867 NDR_PRINT_DEBUG(notify_entry_array, array);
871 for (i=0; i<array->num_entries; i++) {
872 struct notify_entry *e = &array->entries[i];
874 if ((e->filter & filter) != 0) {
877 status = notify_send(notify, e, name, action);
879 status, NT_STATUS_INVALID_HANDLE)) {
881 * Mark the entry as dead. All entries have a
882 * path set. The marker used here is setting
886 have_dead_entries = true;
891 if (!have_dead_entries) {
896 for (i=0; i<array->num_entries; i++) {
897 struct notify_entry *e = &array->entries[i];
898 if (e->path != NULL) {
901 DEBUG(10, ("Deleting notify entries for process %s because "
902 "it's gone\n", procid_str_static(&e->server)));
904 * Potential TODO: This might need optimizing,
905 * notify_remove_onelevel() does a fetch_locked() operation at
906 * every call. But this would only matter if a process with
907 * MANY notifies has died without shutting down properly.
909 notify_remove_onelevel(notify, &e->dir_id, e->private_data);
917 trigger a notify message for anyone waiting on a matching event
919 This function is called a lot, and needs to be very fast. The unusual data structure
920 and traversal is designed to be fast in the average case, even for large numbers of
923 void notify_trigger(struct notify_context *notify,
924 uint32_t action, uint32_t filter, const char *path)
928 const char *p, *next_p;
930 DEBUG(10, ("notify_trigger called action=0x%x, filter=0x%x, "
931 "path=%s\n", (unsigned)action, (unsigned)filter, path));
933 /* see if change notify is enabled at all */
934 if (notify == NULL) {
939 status = notify_load(notify, NULL);
940 if (!NT_STATUS_IS_OK(status)) {
944 /* loop along the given path, working with each directory depth separately */
946 p && depth < notify->array->num_depths;
948 int p_len = p - path;
950 struct notify_depth *d = ¬ify->array->depth[depth];
951 next_p = strchr(p+1, '/');
953 /* see if there are any entries at this depth */
954 if (d->num_entries == 0) continue;
956 /* try to skip based on the maximum mask. If next_p is
957 NULL then we know it will be a 'this directory'
958 match, otherwise it must be a subdir match */
959 if (next_p != NULL) {
960 if (0 == (filter & d->max_mask_subdir)) {
964 if (0 == (filter & d->max_mask)) {
969 /* we know there is an entry here worth looking
970 for. Use a bisection search to find the first entry
971 with a matching path */
973 max_i = d->num_entries-1;
975 while (min_i < max_i) {
976 struct notify_entry *e;
980 cmp = strncmp(path, e->path, p_len);
982 if (p_len == e->path_len) {
987 } else if (cmp < 0) {
994 if (min_i != max_i) {
999 /* we now know that the entries start at min_i */
1000 for (i=min_i;i<d->num_entries;i++) {
1001 struct notify_entry *e = &d->entries[i];
1002 if (p_len != e->path_len ||
1003 strncmp(path, e->path, p_len) != 0) break;
1004 if (next_p != NULL) {
1005 if (0 == (filter & e->subdir_filter)) {
1009 if (0 == (filter & e->filter)) {
1013 status = notify_send(notify, e, path + e->path_len + 1,
1016 if (NT_STATUS_EQUAL(
1017 status, NT_STATUS_INVALID_HANDLE)) {
1018 struct server_id server = e->server;
1020 DEBUG(10, ("Deleting notify entries for "
1021 "process %s because it's gone\n",
1022 procid_str_static(&e->server)));
1023 notify_remove_all(notify, &server);