summaryrefslogtreecommitdiff
path: root/source3/smbd/notify_inotify.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-10-27 13:15:12 +0000
committerJeremy Allison <jra@samba.org>2014-12-09 04:12:09 +0100
commit01a167818d0d927dc9190e4c4b196a701110207e (patch)
tree3c080960ff3bafca3f734d768a5fe44741738bc1 /source3/smbd/notify_inotify.c
parenteb10a36a96f5b4da4ab4677761b8dab7ceeec7b0 (diff)
downloadsamba-01a167818d0d927dc9190e4c4b196a701110207e.tar.gz
notify_inotify: Slightly simplify inotify_watch
tallocing first avoids having to call inotify_rm_watch This even fixes a real error: We share inotifies between different instances, so the rm_watch in the error paths destroys other legitimate watches Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/smbd/notify_inotify.c')
-rw-r--r--source3/smbd/notify_inotify.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/source3/smbd/notify_inotify.c b/source3/smbd/notify_inotify.c
index 613b0387d72..b141b921168 100644
--- a/source3/smbd/notify_inotify.c
+++ b/source3/smbd/notify_inotify.c
@@ -355,7 +355,6 @@ NTSTATUS inotify_watch(struct sys_notify_context *ctx,
void *handle_p)
{
struct inotify_private *in;
- int wd;
uint32_t mask;
struct inotify_watch_context *w;
uint32_t orig_filter = *filter;
@@ -382,38 +381,37 @@ NTSTATUS inotify_watch(struct sys_notify_context *ctx,
watch descriptor for multiple watches on the same path */
mask |= (IN_MASK_ADD | IN_ONLYDIR);
- /* get a new watch descriptor for this path */
- wd = inotify_add_watch(in->fd, path, mask);
- if (wd == -1) {
- *filter = orig_filter;
- DEBUG(1, ("inotify_add_watch returned %s\n", strerror(errno)));
- return map_nt_error_from_unix(errno);
- }
-
- DEBUG(10, ("inotify_add_watch for %s mask %x returned wd %d\n",
- path, mask, wd));
-
w = talloc(in, struct inotify_watch_context);
if (w == NULL) {
- inotify_rm_watch(in->fd, wd);
*filter = orig_filter;
return NT_STATUS_NO_MEMORY;
}
w->in = in;
- w->wd = wd;
w->callback = callback;
w->private_data = private_data;
w->mask = mask;
w->filter = orig_filter;
w->path = talloc_strdup(w, path);
if (w->path == NULL) {
- inotify_rm_watch(in->fd, wd);
*filter = orig_filter;
TALLOC_FREE(w);
return NT_STATUS_NO_MEMORY;
}
+ /* get a new watch descriptor for this path */
+ w->wd = inotify_add_watch(in->fd, path, mask);
+ if (w->wd == -1) {
+ int err = errno;
+ *filter = orig_filter;
+ TALLOC_FREE(w);
+ DEBUG(1, ("inotify_add_watch returned %s\n", strerror(err)));
+ return map_nt_error_from_unix(err);
+ }
+
+ DEBUG(10, ("inotify_add_watch for %s mask %x returned wd %d\n",
+ path, mask, w->wd));
+
(*handle) = w;
DLIST_ADD(in->watches, w);