ioloop-notify-inotify.c revision d347e6fe2a08ec1514980f5bc4a958d6c01b4720
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (c) 2005-2008 Dovecot authors, see the included COPYING file */
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void);
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainenstatic bool inotify_input_more(struct ioloop *ioloop)
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainen /* read as many events as there is available and fit into our buffer.
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainen only full events are returned by the kernel. */
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainen ret = read(ctx->inotify_fd, event_buf, sizeof(event_buf));
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* nothing more to read */
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainen if (gettimeofday(&ioloop_timeval, &ioloop_timezone) < 0)
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainen event = (struct inotify_event *)(event_buf + pos);
94a8cb0ee1d85569ad1a2acacd92d3ce22f8a1cbTimo Sirainen io = io_notify_fd_find(&ctx->fd_ctx, event->wd);
94a8cb0ee1d85569ad1a2acacd92d3ce22f8a1cbTimo Sirainen /* calling inotify_rm_watch() would now give
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainen i_error("read(inotify) returned partial event");
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainenstatic void inotify_input(struct ioloop *ioloop)
b032dc80e358f09893f09999f172ff12f5dbbb8eTimo Sirainenenum io_notify_result io_add_notify(const char *path, io_callback_t *callback,
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen /* ESTALE could happen with NFS. Don't bother giving an error
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen message then. */
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen i_error("inotify_add_watch(%s) failed: %m", path);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen ctx->event_io = io_add(ctx->inotify_fd, IO_READ,
e3689d0f073341e844638f34e1e4d0b7bb053cc8Timo Sirainen *io_r = io_notify_fd_add(&ctx->fd_ctx, wd, callback, context);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenvoid io_loop_notify_remove(struct ioloop *ioloop, struct io *_io)
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen struct io_notify *io = (struct io_notify *)_io;
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen /* ernro=EINVAL happens if the file itself is deleted and
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen kernel has sent IN_IGNORED event which we haven't read. */
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen if (inotify_rm_watch(ctx->inotify_fd, io->fd) < 0 &&
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void)
659fe5d24825b160cae512538088020d97a60239Timo Sirainen i_new(struct ioloop_notify_handler_context, 1);
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen i_warning("Inotify instance limit for user exceeded, "
659fe5d24825b160cae512538088020d97a60239Timo Sirainen "disabling. Increase "