ioloop-notify-inotify.c revision fefe9afdb0fb4cfc70afe3006ec88ba09ab3762d
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2005-2015 Dovecot authors, see the included COPYING file */
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void);
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainenstatic bool inotify_input_more(struct ioloop *ioloop)
6a262c9bd8f57cf1e57112e0522dbdab28ae8c29Timo Sirainen /* read as many events as there is available and fit into our buffer.
6a262c9bd8f57cf1e57112e0522dbdab28ae8c29Timo Sirainen only full events are returned by the kernel. */
6a262c9bd8f57cf1e57112e0522dbdab28ae8c29Timo Sirainen ret = read(ctx->inotify_fd, event_buf, sizeof(event_buf));
6a262c9bd8f57cf1e57112e0522dbdab28ae8c29Timo Sirainen /* nothing more to read */
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen event = (struct inotify_event *)(event_buf + pos);
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen io = io_notify_fd_find(&ctx->fd_ctx, event->wd);
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen /* calling inotify_rm_watch() would now give
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen i_error("read(inotify) returned partial event");
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainenstatic void inotify_input(struct ioloop *ioloop)
6a262c9bd8f57cf1e57112e0522dbdab28ae8c29Timo Sirainenio_add_notify(const char *path, unsigned int source_linenum,
6a262c9bd8f57cf1e57112e0522dbdab28ae8c29Timo Sirainen io_callback_t *callback, void *context, struct io **io_r)
ecf44c74416ffa4e7c331e49a1e283be6b1aa668Timo Sirainen /* ESTALE could happen with NFS. Don't bother giving an error
ecf44c74416ffa4e7c331e49a1e283be6b1aa668Timo Sirainen message then. */
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen i_error("inotify_add_watch(%s) failed: %m", path);
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen i_warning("Inotify watch limit for user exceeded, "
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen "disabling. Increase "
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen ctx->event_io = io_add(ctx->inotify_fd, IO_READ,
643a81fff9003cba13deb49a565a3c8171da524dTimo Sirainen *io_r = io_notify_fd_add(&ctx->fd_ctx, wd, callback, context);
643a81fff9003cba13deb49a565a3c8171da524dTimo Sirainen struct io_notify *io = (struct io_notify *)_io;
0950aed81d1e9618264e6aa4d214d89e005ec8d6Timo Sirainen /* ernro=EINVAL happens if the file itself is deleted and
0950aed81d1e9618264e6aa4d214d89e005ec8d6Timo Sirainen kernel has sent IN_IGNORED event which we haven't read. */
0950aed81d1e9618264e6aa4d214d89e005ec8d6Timo Sirainen if (inotify_rm_watch(ctx->inotify_fd, io->fd) < 0 &&
6c00502d4ece417ead501db8f0ee3e8287ba4459Timo Sirainenstatic void ioloop_inotify_user_limit_exceeded(void)
6c00502d4ece417ead501db8f0ee3e8287ba4459Timo Sirainen name = t_strdup_printf("UID %s", dec2str(uid));
6c00502d4ece417ead501db8f0ee3e8287ba4459Timo Sirainen i_warning("Inotify instance limit for user %s exceeded, disabling. "
d03a871a77f8ec36f48f5fea98d810e51b186fdbTimo Sirainen "Increase /proc/sys/fs/inotify/max_user_instances", name);
6c00502d4ece417ead501db8f0ee3e8287ba4459Timo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void)
643a81fff9003cba13deb49a565a3c8171da524dTimo Sirainen i_new(struct ioloop_notify_handler_context, 1);
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainenvoid io_loop_notify_handler_deinit(struct ioloop *ioloop)
402e999a878e0cc41a0afb830fea0a93afc75f0dTimo Sirainen i_warning("I/O notify leak: %p (line %u, fd %d)",