diff options
Diffstat (limited to 'source3/smbd/notify_kernel.c')
-rw-r--r-- | source3/smbd/notify_kernel.c | 109 |
1 files changed, 38 insertions, 71 deletions
diff --git a/source3/smbd/notify_kernel.c b/source3/smbd/notify_kernel.c index 8454917163..19ea41e195 100644 --- a/source3/smbd/notify_kernel.c +++ b/source3/smbd/notify_kernel.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. change notify handling - linux kernel based implementation Copyright (C) Andrew Tridgell 2000 @@ -23,9 +22,9 @@ #if HAVE_KERNEL_CHANGE_NOTIFY -#define FD_PENDING_SIZE 20 -static SIG_ATOMIC_T fd_pending_array[FD_PENDING_SIZE]; -static SIG_ATOMIC_T signals_received; +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 */ @@ -54,114 +53,84 @@ static SIG_ATOMIC_T signals_received; This is the structure to keep the information needed to determine if a directory has changed. *****************************************************************************/ - struct change_data { int directory_handle; }; /**************************************************************************** - The signal handler for change notify. - The Linux kernel has a bug in that we should be able to block any - further delivery of RT signals until the kernel_check_notify() function - unblocks them, but it seems that any signal mask we're setting here is - being overwritten on exit from this handler. I should create a standalone - test case for the kernel hackers. JRA. +the signal handler for change notify *****************************************************************************/ - static void signal_handler(int sig, siginfo_t *info, void *unused) { - if (signals_received < FD_PENDING_SIZE - 1) { - fd_pending_array[signals_received] = (SIG_ATOMIC_T)info->si_fd; - signals_received++; - } /* Else signal is lost. */ + BlockSignals(True, sig); + fd_pending = (sig_atomic_t)info->si_fd; + signals_received++; sys_select_signal(); } + + /**************************************************************************** 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; - int i; - BOOL ret = False; if (t) return False; - BlockSignals(True, RT_SIGNAL_NOTIFY); - for (i = 0; i < signals_received; i++) { - if (data->directory_handle == (int)fd_pending_array[i]) { - DEBUG(3,("kernel_check_notify: kernel change notify on %s fd[%d]=%d (signals_received=%d)\n", - path, i, (int)fd_pending_array[i], (int)signals_received )); - - close((int)fd_pending_array[i]); - fd_pending_array[i] = (SIG_ATOMIC_T)-1; - if (signals_received - i - 1) { - memmove((void *)&fd_pending_array[i], (void *)&fd_pending_array[i+1], - sizeof(SIG_ATOMIC_T)*(signals_received-i-1)); - } - data->directory_handle = -1; - signals_received--; - ret = True; - break; - } - } + if (data->directory_handle != (int)fd_pending) return False; + + 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 ret; + return True; } /**************************************************************************** - Remove a change notify data structure. +remove a change notify data structure *****************************************************************************/ - static void kernel_remove_notify(void *datap) { struct change_data *data = (struct change_data *)datap; int fd = data->directory_handle; if (fd != -1) { - int i; - BlockSignals(True, RT_SIGNAL_NOTIFY); - for (i = 0; i < signals_received; i++) { - if (fd == (int)fd_pending_array[i]) { - close(fd); - fd_pending_array[i] = (SIG_ATOMIC_T)-1; - if (signals_received - i - 1) { - memmove((void *)&fd_pending_array[i], (void *)&fd_pending_array[i+1], - sizeof(SIG_ATOMIC_T)*(signals_received-i-1)); - } - data->directory_handle = -1; - signals_received--; - break; - } + if (fd == (int)fd_pending) { + fd_pending = (sig_atomic_t)-1; + signals_processed++; + BlockSignals(False, RT_SIGNAL_NOTIFY); } - BlockSignals(False, RT_SIGNAL_NOTIFY); + close(fd); } SAFE_FREE(data); - DEBUG(3,("kernel_remove_notify: fd=%d\n", fd)); + DEBUG(3,("removed kernel change notify fd=%d\n", fd)); } + /**************************************************************************** - Register a change notify request. +register a change notify request *****************************************************************************/ - static void *kernel_register_notify(connection_struct *conn, char *path, uint32 flags) { struct change_data data; int fd; unsigned long kernel_flags; - fd = sys_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)); return NULL; } - if (sys_fcntl_long(fd, F_SETSIG, RT_SIGNAL_NOTIFY) == -1) { + if (fcntl(fd, F_SETSIG, RT_SIGNAL_NOTIFY) == -1) { DEBUG(3,("Failed to set signal handler for change notify\n")); return NULL; } @@ -178,7 +147,7 @@ static void *kernel_register_notify(connection_struct *conn, char *path, uint32 if (flags & FILE_NOTIFY_CHANGE_EA) kernel_flags |= DN_ATTRIB; if (flags & FILE_NOTIFY_CHANGE_FILE_NAME) kernel_flags |= DN_RENAME|DN_DELETE; - if (sys_fcntl_long(fd, F_NOTIFY, kernel_flags) == -1) { + if (fcntl(fd, F_NOTIFY, kernel_flags) == -1) { DEBUG(3,("Failed to set async flag for change notify\n")); return NULL; } @@ -192,24 +161,22 @@ static void *kernel_register_notify(connection_struct *conn, char *path, uint32 } /**************************************************************************** - See if the kernel supports change notify. +see if the kernel supports change notify ****************************************************************************/ - static BOOL kernel_notify_available(void) { int fd, ret; fd = open("/tmp", O_RDONLY); - if (fd == -1) - return False; /* uggh! */ - ret = sys_fcntl_long(fd, F_NOTIFY, 0); + if (fd == -1) return False; /* uggh! */ + ret = fcntl(fd, F_NOTIFY, 0); close(fd); return ret == 0; } + /**************************************************************************** - Setup kernel based change notify. +setup kernel based change notify ****************************************************************************/ - struct cnotify_fns *kernel_notify_init(void) { static struct cnotify_fns cnotify; @@ -223,8 +190,7 @@ struct cnotify_fns *kernel_notify_init(void) return NULL; } - if (!kernel_notify_available()) - return NULL; + if (!kernel_notify_available()) return NULL; cnotify.register_notify = kernel_register_notify; cnotify.check_notify = kernel_check_notify; @@ -234,6 +200,7 @@ struct cnotify_fns *kernel_notify_init(void) return &cnotify; } + #else void notify_kernel_dummy(void) {} #endif /* HAVE_KERNEL_CHANGE_NOTIFY */ |