ioloop-notify-inotify.c revision 85e2264f7d3b1a336ac5066c99130414dfc77902
183bea41fa640dc8117f3eb45ff935cd81377a84Timo Sirainen/* Copyright (c) 2005-2015 Dovecot authors, see the included COPYING file */
542e28b384a6b26695f3e8de38fd5727d06f3333Timo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void);
c3a636e4c9ae776e0eed06b6d7ad1ccfb6003afdTimo Sirainenstatic bool inotify_input_more(struct ioloop *ioloop)
fa2433aebcf3fccfa30ca9eed9b1a9166cf92ee2Timo Sirainen /* read as many events as there is available and fit into our buffer.
fa2433aebcf3fccfa30ca9eed9b1a9166cf92ee2Timo Sirainen only full events are returned by the kernel. */
4da8c6cdefabd31262318c32da3c13de1d9ea953Timo Sirainen ret = read(ctx->inotify_fd, event_buf, sizeof(event_buf));
5d03d9f439e41c90215a3c938ffebe4c2a8ae257Timo Sirainen /* nothing more to read */
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen event = (struct inotify_event *)(event_buf + pos);
38f227941bcf673e0e523c1ac7267bca9cbcd2c4Timo Sirainen io = io_notify_fd_find(&ctx->fd_ctx, event->wd);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen /* calling inotify_rm_watch() would now give
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen i_error("read(inotify) returned partial event");
2eb2cf8eeb763bd5ca9b6848dce32f0303e88ec1Timo Sirainenstatic void inotify_input(struct ioloop *ioloop)
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainenenum io_notify_result io_add_notify(const char *path, io_callback_t *callback,
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen /* ESTALE could happen with NFS. Don't bother giving an error
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen message then. */
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen i_error("inotify_add_watch(%s) failed: %m", path);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen i_warning("Inotify watch limit for user exceeded, "
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen "disabling. Increase "
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainen ctx->event_io = io_add(ctx->inotify_fd, IO_READ,
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen *io_r = io_notify_fd_add(&ctx->fd_ctx, wd, callback, context);
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen struct io_notify *io = (struct io_notify *)_io;
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen /* ernro=EINVAL happens if the file itself is deleted and
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen kernel has sent IN_IGNORED event which we haven't read. */
1f5597beba229acd914e30a6da3c0e62d83b6e8fTimo Sirainen if (inotify_rm_watch(ctx->inotify_fd, io->fd) < 0 &&
47569a4b2b4d3cc55e786177798c922c3c44233dTimo Sirainenstatic void ioloop_inotify_user_limit_exceeded(void)
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen name = t_strdup_printf("UID %s", dec2str(uid));
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen i_warning("Inotify instance limit for user %s exceeded, disabling. "
c07d7eb3ca9754367697c98f5e66a3982a45d142Timo Sirainen "Increase /proc/sys/fs/inotify/max_user_instances", name);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen i_new(struct ioloop_notify_handler_context, 1);