ioloop-notify-inotify.c revision fdb97244fa45c32c3593726c15aa69ce29bc7121
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2005-2010 Dovecot authors, see the included COPYING file */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstatic bool inotify_input_more(struct ioloop *ioloop)
d92f33f13830ba23d814342bf3ea8db721a15bb1Timo Sirainen /* read as many events as there is available and fit into our buffer.
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen only full events are returned by the kernel. */
61e84692827b6a64912343f515c984853021483aTimo Sirainen ret = read(ctx->inotify_fd, event_buf, sizeof(event_buf));
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* nothing more to read */
91b203fd2132510a47a4b34252c0ae0efd688a19Timo Sirainen event = (struct inotify_event *)(event_buf + pos);
91b203fd2132510a47a4b34252c0ae0efd688a19Timo Sirainen io = io_notify_fd_find(&ctx->fd_ctx, event->wd);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* calling inotify_rm_watch() would now give
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen i_error("read(inotify) returned partial event");
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenstatic void inotify_input(struct ioloop *ioloop)
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainenenum io_notify_result io_add_notify(const char *path, io_callback_t *callback,
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen /* ESTALE could happen with NFS. Don't bother giving an error
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen message then. */
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen i_error("inotify_add_watch(%s) failed: %m", path);
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen i_warning("Inotify watch limit for user exceeded, "
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "disabling. Increase "
4366a21968093172d9b757fe6894b1ee8916434eTimo Sirainen ctx->event_io = io_add(ctx->inotify_fd, IO_READ,
4366a21968093172d9b757fe6894b1ee8916434eTimo Sirainen *io_r = io_notify_fd_add(&ctx->fd_ctx, wd, callback, context);
8a0ad174adb1eb5108511b90e97f4e5f9089b0eeTimo Sirainen struct io_notify *io = (struct io_notify *)_io;
adb6413686e52e00dded4932babcc08ff041876bTimo Sirainen /* ernro=EINVAL happens if the file itself is deleted and
96f2533c48ce5def0004931606a2fdf275578880Timo Sirainen kernel has sent IN_IGNORED event which we haven't read. */
4645cc6c911a95991d7af43b40f88e99506ea5e9Timo Sirainen if (inotify_rm_watch(ctx->inotify_fd, io->fd) < 0 &&
96f2533c48ce5def0004931606a2fdf275578880Timo Sirainenstatic void ioloop_inotify_user_limit_exceeded(void)
ff7056842f14fd3b30a2d327dfab165b9d15dd30Timo Sirainen name = t_strdup_printf("UID %s", dec2str(uid));
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen i_warning("Inotify instance limit for user %s exceeded, disabling. "
a27e065f1a1f91c7fbdf7c2ea1c387441af0cbb3Timo Sirainen "Increase /proc/sys/fs/inotify/max_user_instances", name);
return ctx;