r14918: cleaner handling of systems without inotify
authorAndrew Tridgell <tridge@samba.org>
Wed, 5 Apr 2006 04:50:08 +0000 (04:50 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:00:16 +0000 (14:00 -0500)
(This used to be commit cf17ff15b15942f0ce068dd0a94b3b565a9b93cb)

source4/ntvfs/common/notify.c
source4/ntvfs/sysdep/inotify.c
source4/ntvfs/sysdep/sys_notify.c

index 595a0f65668866b82d1d476f78c5d12fab163120..9ea024f2fcffd154dd8c19623a661bcf81429aec 100644 (file)
@@ -267,6 +267,25 @@ static void sys_notify_callback(struct sys_notify_context *ctx,
        listel->callback(listel->private, ev);
 }
 
+/*
+  add an entry to the notify array
+*/
+static NTSTATUS notify_add_array(struct notify_context *notify, struct notify_entry *e,
+                                const char *path, void *private)
+{
+       notify->array->entries[notify->array->num_entries] = *e;
+       notify->array->entries[notify->array->num_entries].private = private;
+       notify->array->entries[notify->array->num_entries].server = notify->server;
+       
+       if (path) {
+               notify->array->entries[notify->array->num_entries].path = path;
+       }
+
+       notify->array->num_entries++;
+       
+       return notify_save(notify);
+}
+
 /*
   add a notify watch. This is called when a notify is first setup on a open
   directory handle.
@@ -312,33 +331,23 @@ NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e,
        DLIST_ADD(notify->list, listel);
 
        /* ignore failures from sys_notify */
-       status = sys_notify_watch(notify->sys_notify_ctx, e->path, e->filter, 
-                                 sys_notify_callback, listel, 
-                                 &listel->sys_notify_handle);
-       if (NT_STATUS_IS_OK(status)) {
-               talloc_steal(listel, listel->sys_notify_handle);
-               notify_unlock(notify);
-       } else {
-               notify->array->entries[notify->array->num_entries] = *e;
-               notify->array->entries[notify->array->num_entries].private = private;
-               notify->array->entries[notify->array->num_entries].server = notify->server;
-
-               if (path) {
-                       notify->array->entries[notify->array->num_entries].path = path;
+       if (notify->sys_notify_ctx != NULL) {
+               status = sys_notify_watch(notify->sys_notify_ctx, e->path, e->filter, 
+                                         sys_notify_callback, listel, 
+                                         &listel->sys_notify_handle);
+               if (NT_STATUS_IS_OK(status)) {
+                       /* if the kernel handler has said it can handle this notify then
+                          we don't need to add it to the array */
+                       talloc_steal(listel, listel->sys_notify_handle);
+                       goto done;
                }
-
-               notify->array->num_entries++;
-
-               status = notify_save(notify);
-
-               notify_unlock(notify);
-
-               NT_STATUS_NOT_OK_RETURN(status);
        }
 
-       if (path) {
-               talloc_free(path);
-       }
+       status = notify_add_array(notify, e, path, private);
+
+done:
+       notify_unlock(notify);
+       talloc_free(path);
 
        return status;
 }
index 31c408d11253f1c00ecc12dbf21eecfc9e265a55..ec8669306e3764a386b54a0c474334e12282a64a 100644 (file)
@@ -239,7 +239,7 @@ static int watch_destructor(void *ptr)
 
 /*
   add a watch. The watch is removed when the caller calls
-  talloc_free() on handle
+  talloc_free() on *handle
 */
 static NTSTATUS inotify_watch(struct sys_notify_context *ctx, const char *dirpath,
                              uint32_t filter, sys_notify_callback_t callback,
index fd29f42a0eff3bef42b4e341e234a3f013006962..1927ac61cec87e1e1496ccfc79a08131f415e709 100644 (file)
@@ -44,6 +44,10 @@ struct sys_notify_context *sys_notify_init(int snum,
        const char *bname;
        struct sys_notify_backend *b;
 
+       if (backends == NULL) {
+               return NULL;
+       }
+
        if (ev == NULL) {
                ev = event_context_find(mem_ctx);
        }