ioloop-notify-inotify.c revision 8d6a6eccd3f2e34df967b90bb45e20755241bdbb
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher/* Copyright (c) 2005-2011 Dovecot authors, see the included COPYING file */
1183d29d87c5c7439cf2364b7d7324d4a13b6e35Stephen Gallagherstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic bool inotify_input_more(struct ioloop *ioloop)
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher struct ioloop_notify_handler_context *ctx =
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* read as many events as there is available and fit into our buffer.
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher only full events are returned by the kernel. */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ret = read(ctx->inotify_fd, event_buf, sizeof(event_buf));
c89589fa349f38214c9cb8d9389c0fd557e5dca2Simo Sorce /* nothing more to read */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher if (gettimeofday(&ioloop_timeval, NULL) < 0)
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher event = (struct inotify_event *)(event_buf + pos);
d921c1eba437662437847279f251a0a5d8f70127Maxim /* calling inotify_rm_watch() would now give
d3da1c165cdb4c1ec126a8f4b6b544ca415b9d20Pavel Březina i_error("read(inotify) returned partial event");
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher return (size_t)ret >= sizeof(event_buf)-512;
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic void inotify_input(struct ioloop *ioloop)
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherenum io_notify_result io_add_notify(const char *path, io_callback_t *callback,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher struct ioloop_notify_handler_context *ctx =
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* ESTALE could happen with NFS. Don't bother giving an error
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher message then. */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher i_error("inotify_add_watch(%s) failed: %m", path);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher i_warning("Inotify watch limit for user exceeded, "
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher "disabling. Increase "
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher ctx->event_io = io_add(ctx->inotify_fd, IO_READ,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher *io_r = io_notify_fd_add(&ctx->fd_ctx, wd, callback, context);
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher struct ioloop_notify_handler_context *ctx =
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher struct io_notify *io = (struct io_notify *)_io;
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher /* ernro=EINVAL happens if the file itself is deleted and
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher kernel has sent IN_IGNORED event which we haven't read. */
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher if (inotify_rm_watch(ctx->inotify_fd, io->fd) < 0 &&
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic void ioloop_inotify_user_limit_exceeded(void)
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher name = t_strdup_printf("UID %s", dec2str(uid));
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher i_warning("Inotify instance limit for user %s exceeded, disabling. "
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher "Increase /proc/sys/fs/inotify/max_user_instances", name);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void)
4d81fe27ced3d2e96866aeaf61661a925cb8edf1Jakub Hrozek i_new(struct ioloop_notify_handler_context, 1);