ioloop-notify-inotify.c revision fdb97244fa45c32c3593726c15aa69ce29bc7121
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen/* Copyright (c) 2005-2010 Dovecot authors, see the included COPYING file */
01cd9d4a8050a1dbf1da2c830f9755a45d6d004aTimo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainenstatic bool inotify_input_more(struct ioloop *ioloop)
01cd9d4a8050a1dbf1da2c830f9755a45d6d004aTimo Sirainen /* read as many events as there is available and fit into our buffer.
01cd9d4a8050a1dbf1da2c830f9755a45d6d004aTimo Sirainen only full events are returned by the kernel. */
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen ret = read(ctx->inotify_fd, event_buf, sizeof(event_buf));
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen /* nothing more to read */
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen event = (struct inotify_event *)(event_buf + pos);
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen io = io_notify_fd_find(&ctx->fd_ctx, event->wd);
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen /* calling inotify_rm_watch() would now give
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen i_error("read(inotify) returned partial event");
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainenstatic void inotify_input(struct ioloop *ioloop)
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainenenum io_notify_result io_add_notify(const char *path, io_callback_t *callback,
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen /* ESTALE could happen with NFS. Don't bother giving an error
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen message then. */
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen i_error("inotify_add_watch(%s) failed: %m", path);
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen i_warning("Inotify watch limit for user exceeded, "
1093de32efb2a231949566d4bd8aa55a8f43fb70Timo Sirainen "disabling. Increase "
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen ctx->event_io = io_add(ctx->inotify_fd, IO_READ,
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen *io_r = io_notify_fd_add(&ctx->fd_ctx, wd, callback, context);
b8cd2f2f99351605725b7260f5da89cff76d0a3aTimo Sirainen struct io_notify *io = (struct io_notify *)_io;
45155bb1250cf5a120278f349465aded513a100fTimo Sirainen /* ernro=EINVAL happens if the file itself is deleted and
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen kernel has sent IN_IGNORED event which we haven't read. */
8372fc7efb6d64dff2e5f55fb4a3822c56869cfeTimo Sirainen if (inotify_rm_watch(ctx->inotify_fd, io->fd) < 0 &&
ccef83820a01bb37ad48653a05a9c5aa6560826aTimo Sirainenstatic void ioloop_inotify_user_limit_exceeded(void)
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen name = t_strdup_printf("UID %s", dec2str(uid));
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen i_warning("Inotify instance limit for user %s exceeded, disabling. "
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen "Increase /proc/sys/fs/inotify/max_user_instances", name);
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainenstatic struct ioloop_notify_handler_context *io_loop_notify_handler_init(void)
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen i_new(struct ioloop_notify_handler_context, 1);