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