ioloop-notify-kqueue.c revision f6c0407545ee77d4647c8cd912e3156b0a48e2f1
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen * BSD kqueue() based ioloop notify handler.
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen * Copyright (c) 2005 Vaclav Haisman <v.haisman@sh.cvut.cz>
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen * This library is free software; you can redistribute it and/or modify
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen * it under the terms of the GNU Lesser General Public License as published
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen * by the Free Software Foundation; either version 2 of the License, or
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen * (at your option) any later version.
f6c0407545ee77d4647c8cd912e3156b0a48e2f1Timo Sirainen/* kevent.udata's type just has to be different in NetBSD than in
f6c0407545ee77d4647c8cd912e3156b0a48e2f1Timo Sirainen FreeBSD and OpenBSD.. */
f6c0407545ee77d4647c8cd912e3156b0a48e2f1Timo Sirainen# define MY_EV_SET(a, b, c, d, e, f, g) \
f6c0407545ee77d4647c8cd912e3156b0a48e2f1Timo Sirainen# define MY_EV_SET(a, b, c, d, e, f, g) \
f6c0407545ee77d4647c8cd912e3156b0a48e2f1Timo Sirainen EV_SET(a, b, c, d, e, f, g)
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen struct ioloop_notify_handler_context *ctx = context;
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen if (gettimeofday(&ioloop_timeval, &ioloop_timezone) < 0)
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenvoid io_loop_notify_handler_init(struct ioloop *ioloop)
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainen p_new(ioloop->pool, struct ioloop_notify_handler_context, 1);
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenvoid io_loop_notify_handler_deinit(struct ioloop *ioloop)
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenstruct io *io_loop_notify_add(struct ioloop *ioloop, const char *path,
35565557e05721a761132cec2ba1d93acacb6c14Timo Sirainen i_error("open(%s) for kq notify failed: %m", path);
a40f21e8239a87a8fab2648955b0f568908ca8b5Timo Sirainen i_error("fstat(%d, %s) for kq notify failed: %m", fd, path);
4dc5662260a63669054cd0dc1bac2ccab3fa2ae7Timo Sirainen /* EV_CLEAR flag is needed because the EVFILT_VNODE filter reports
4dc5662260a63669054cd0dc1bac2ccab3fa2ae7Timo Sirainen event state transitions and not the current state. With this flag,
4dc5662260a63669054cd0dc1bac2ccab3fa2ae7Timo Sirainen the same event is only returned once. */
f6c0407545ee77d4647c8cd912e3156b0a48e2f1Timo Sirainen MY_EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR,
f6c0407545ee77d4647c8cd912e3156b0a48e2f1Timo Sirainen NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_REVOKE, 0, io);
a40f21e8239a87a8fab2648955b0f568908ca8b5Timo Sirainen if (kevent(ctx->kq, &ev, 1, NULL, 0, NULL) < 0) {
a40f21e8239a87a8fab2648955b0f568908ca8b5Timo Sirainen i_error("kevent(%d, %s) for notify failed: %m", fd, path);
6a029ebed745994ce2e5f64182d8b5c8f10d53d6Timo Sirainenvoid io_loop_notify_remove(struct ioloop *ioloop, struct io *io)
f6c0407545ee77d4647c8cd912e3156b0a48e2f1Timo Sirainen MY_EV_SET(&ev, io->fd, EVFILT_VNODE, EV_DELETE, 0, 0, NULL);
a40f21e8239a87a8fab2648955b0f568908ca8b5Timo Sirainen i_error("kevent(%d) for notify remove failed: %m", io->fd);
35565557e05721a761132cec2ba1d93acacb6c14Timo Sirainen i_error("close(%d) for notify remove failed: %m", io->fd);