Removed version number from file header.
[ira/wip.git] / source3 / smbd / notify_kernel.c
index c7fb5ca0dd878a5b79548cb99ad4f16ed3974e52..19ea41e19568b750c321bf91716cf9ed5cdbc02c 100644 (file)
@@ -1,7 +1,5 @@
-#define OLD_NTDOMAIN 1
 /*
-   Unix SMB/Netbios implementation.
-   Version 3.0
+   Unix SMB/CIFS implementation.
    change notify handling - linux kernel based implementation
    Copyright (C) Andrew Tridgell 2000
 
 
 #if HAVE_KERNEL_CHANGE_NOTIFY
 
-extern int DEBUGLEVEL;
-static int fd_pending;
-static unsigned signals_received;
-static unsigned signals_processed;
+static VOLATILE sig_atomic_t fd_pending;
+static VOLATILE sig_atomic_t signals_received;
+static VOLATILE sig_atomic_t signals_processed;
 
 #ifndef DN_ACCESS
 #define DN_ACCESS       0x00000001      /* File accessed in directory */
@@ -63,10 +60,10 @@ struct change_data {
 /****************************************************************************
 the signal handler for change notify
 *****************************************************************************/
-static void signal_handler(int signal, siginfo_t *info, void *unused)
+static void signal_handler(int sig, siginfo_t *info, void *unused)
 {
-       BlockSignals(True, signal);
-       fd_pending = info->si_fd;
+       BlockSignals(True, sig);
+       fd_pending = (sig_atomic_t)info->si_fd;
        signals_received++;
        sys_select_signal();
 }
@@ -74,18 +71,24 @@ static void signal_handler(int signal, siginfo_t *info, void *unused)
 
 
 /****************************************************************************
-check if a change notify should be issued 
+ Check if a change notify should be issued.
+ time non-zero means timeout check (used for hash). Ignore this (async method
+ where time is zero will be used instead).
 *****************************************************************************/
 static BOOL kernel_check_notify(connection_struct *conn, uint16 vuid, char *path, uint32 flags, void *datap, time_t t)
 {
        struct change_data *data = (struct change_data *)datap;
 
-       if (data->directory_handle != fd_pending) return False;
+       if (t)
+               return False;
 
-       DEBUG(3,("kernel change notify on %s fd=%d\n", path, fd_pending));
+       if (data->directory_handle != (int)fd_pending) return False;
 
-       close(fd_pending);
-       data->directory_handle = fd_pending = -1;
+       DEBUG(3,("kernel change notify on %s fd=%d\n", path, (int)fd_pending));
+
+       close((int)fd_pending);
+       fd_pending = (sig_atomic_t)-1;
+       data->directory_handle = -1;
        signals_processed++;
        BlockSignals(False, RT_SIGNAL_NOTIFY);
        return True;
@@ -99,14 +102,14 @@ static void kernel_remove_notify(void *datap)
        struct change_data *data = (struct change_data *)datap;
        int fd = data->directory_handle;
        if (fd != -1) {
-               if (fd == fd_pending) {
-                       fd_pending = -1;
+               if (fd == (int)fd_pending) {
+                       fd_pending = (sig_atomic_t)-1;
                        signals_processed++;
                        BlockSignals(False, RT_SIGNAL_NOTIFY);
                }
                close(fd);
        }
-       free(data);
+       SAFE_FREE(data);
        DEBUG(3,("removed kernel change notify fd=%d\n", fd));
 }
 
@@ -120,7 +123,7 @@ static void *kernel_register_notify(connection_struct *conn, char *path, uint32
        int fd;
        unsigned long kernel_flags;
        
-       fd = dos_open(path, O_RDONLY, 0);
+       fd = conn->vfs_ops.open(conn, path, O_RDONLY, 0);
 
        if (fd == -1) {
                DEBUG(3,("Failed to open directory %s for change notify\n", path));
@@ -167,7 +170,7 @@ static BOOL kernel_notify_available(void)
        if (fd == -1) return False; /* uggh! */
        ret = fcntl(fd, F_NOTIFY, 0);
        close(fd);
-       return ret == 0 || errno != EINVAL;
+       return ret == 0;
 }
 
 
@@ -179,8 +182,6 @@ struct cnotify_fns *kernel_notify_init(void)
        static struct cnotify_fns cnotify;
         struct sigaction act;
 
-       if (!kernel_notify_available()) return NULL;
-
         act.sa_handler = NULL;
         act.sa_sigaction = signal_handler;
         act.sa_flags = SA_SIGINFO;
@@ -189,9 +190,12 @@ struct cnotify_fns *kernel_notify_init(void)
                return NULL;
         }
 
+       if (!kernel_notify_available()) return NULL;
+
        cnotify.register_notify = kernel_register_notify;
        cnotify.check_notify = kernel_check_notify;
        cnotify.remove_notify = kernel_remove_notify;
+       cnotify.select_time = -1;
 
        return &cnotify;
 }
@@ -200,5 +204,3 @@ struct cnotify_fns *kernel_notify_init(void)
 #else
  void notify_kernel_dummy(void) {}
 #endif /* HAVE_KERNEL_CHANGE_NOTIFY */
-
-#undef OLD_NTDOMAIN