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