ioloop-notify-inotify.c revision 70afae43cc78ea6ecca83f6c587072c442a15ec1
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 */
86b61156743b7ebdc049450a6f88452890fd9a61Jakub Hrozek event = (struct inotify_event *)(event_buf + pos);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher io = io_notify_fd_find(&ctx->fd_ctx, event->wd);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* calling inotify_rm_watch() would now give
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher i_error("read(inotify) returned partial event");
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher return (size_t)ret >= sizeof(event_buf)-512;
327127bb7fcc07f882209f029e14026de1b23c94Maximenum io_notify_result io_add_notify(const char *path, io_callback_t *callback,
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher wd = inotify_add_watch(ctx->inotify_fd, path,
4b6a0d0b3d42e5fdb457f47d9adfa5e66b160256Stephen Gallagher /* ESTALE could happen with NFS. Don't bother giving an error
90fd1bbd6035cdab46faa3a695a2fb2be6508b17Sumit Bose message then. */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher i_error("inotify_add_watch(%s) failed: %m", path);
98ce3c3e85a4bb2e1822bf8ab2a1c2ab9e3dd61dJakub Hrozek i_warning("Inotify watch limit for user exceeded, "
be65f065fef1d387281096ef095a2acef39ecc12Jakub Hrozek "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);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher struct ioloop_notify_handler_context *ctx =
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher struct io_notify *io = (struct io_notify *)_io;
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher /* ernro=EINVAL happens if the file itself is deleted and
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher kernel has sent IN_IGNORED event which we haven't read. */
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher if (inotify_rm_watch(ctx->inotify_fd, io->fd) < 0 &&
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagherstatic void ioloop_inotify_user_limit_exceeded(void)
b32159300fea63222d8dd9200ed634087704ea74Stephen Gallagher name = t_strdup_printf("UID %s", dec2str(uid));
e6e26182d58c05d896f72f2925426658a6dc70b5Jakub Hrozek i_warning("Inotify instance limit for user %s exceeded, disabling. "
e6e26182d58c05d896f72f2925426658a6dc70b5Jakub Hrozek "Increase /proc/sys/fs/inotify/max_user_instances", name);
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagherstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void)
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher struct ioloop_notify_handler_context *ctx;
551aa6c36797ed720487f5974dcadabf19e6ff9fStephen Gallagher i_new(struct ioloop_notify_handler_context, 1);