dovecot-2.2: lib: Added io_loop_extract_notify_fd()
dovecot at dovecot.org
dovecot at dovecot.org
Mon Aug 24 11:05:20 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/3083424cafcd
changeset: 18994:3083424cafcd
user: Timo Sirainen <tss at iki.fi>
date: Mon Aug 24 14:02:52 2015 +0300
description:
lib: Added io_loop_extract_notify_fd()
diffstat:
src/lib/ioloop-notify-inotify.c | 29 ++++++++++++++++++++++++++++-
src/lib/ioloop-notify-kqueue.c | 27 +++++++++++++++++++++++++++
src/lib/ioloop-notify-none.c | 5 +++++
src/lib/ioloop.h | 8 ++++++++
4 files changed, 68 insertions(+), 1 deletions(-)
diffs (110 lines):
diff -r 4673b93b04c6 -r 3083424cafcd src/lib/ioloop-notify-inotify.c
--- a/src/lib/ioloop-notify-inotify.c Mon Aug 24 14:01:04 2015 +0300
+++ b/src/lib/ioloop-notify-inotify.c Mon Aug 24 14:02:52 2015 +0300
@@ -146,7 +146,7 @@
io_notify_fd_free(&ctx->fd_ctx, io);
- if (ctx->fd_ctx.notifies == NULL)
+ if (ctx->fd_ctx.notifies == NULL && ctx->event_io != NULL)
io_remove(&ctx->event_io);
}
@@ -211,4 +211,31 @@
i_free(ctx);
}
+int io_loop_extract_notify_fd(struct ioloop *ioloop)
+{
+ struct ioloop_notify_handler_context *ctx =
+ ioloop->notify_handler_context;
+ struct io_notify *io;
+ int fd, new_inotify_fd;
+
+ if (ctx->inotify_fd == -1)
+ return -1;
+
+ new_inotify_fd = inotify_init();
+ if (new_inotify_fd == -1) {
+ if (errno != EMFILE)
+ i_error("inotify_init() failed: %m");
+ else
+ ioloop_inotify_user_limit_exceeded();
+ return -1;
+ }
+ for (io = ctx->fd_ctx.notifies; io != NULL; io = io->next)
+ io->fd = -1;
+ if (ctx->event_io != NULL)
+ io_remove(&ctx->event_io);
+ fd = ctx->inotify_fd;
+ ctx->inotify_fd = new_inotify_fd;
+ return fd;
+}
+
#endif
diff -r 4673b93b04c6 -r 3083424cafcd src/lib/ioloop-notify-kqueue.c
--- a/src/lib/ioloop-notify-kqueue.c Mon Aug 24 14:01:04 2015 +0300
+++ b/src/lib/ioloop-notify-kqueue.c Mon Aug 24 14:02:52 2015 +0300
@@ -197,4 +197,31 @@
io_loop_notify_free(ctx, io);
}
+int io_loop_extract_notify_fd(struct ioloop *ioloop)
+{
+ struct ioloop_notify_handler_context *ctx =
+ ioloop->notify_handler_context;
+ struct io_notify *io;
+ int fd, new_kq;
+
+ if (ctx->kq == -1)
+ return -1;
+
+ new_kq = inotify_init();
+ if (new_kq == -1) {
+ if (errno != EMFILE)
+ i_error("inotify_init() failed: %m");
+ else
+ ioloop_inotify_user_limit_exceeded();
+ return -1;
+ }
+ for (io = ctx->fd_ctx.notifies; io != NULL; io = io->next)
+ io->fd = -1;
+ if (ctx->event_io != NULL)
+ io_remove(&ctx->event_io);
+ fd = ctx->kq;
+ ctx->kq = new_kq;
+ return fd;
+}
+
#endif
diff -r 4673b93b04c6 -r 3083424cafcd src/lib/ioloop-notify-none.c
--- a/src/lib/ioloop-notify-none.c Mon Aug 24 14:01:04 2015 +0300
+++ b/src/lib/ioloop-notify-none.c Mon Aug 24 14:02:52 2015 +0300
@@ -24,4 +24,9 @@
{
}
+int io_loop_extract_notify_fd(struct ioloop *ioloop ATTR_UNUSED)
+{
+ return -1;
+}
+
#endif
diff -r 4673b93b04c6 -r 3083424cafcd src/lib/ioloop.h
--- a/src/lib/ioloop.h Mon Aug 24 14:01:04 2015 +0300
+++ b/src/lib/ioloop.h Mon Aug 24 14:02:52 2015 +0300
@@ -167,6 +167,14 @@
/* Returns the current context set to ioloop. */
struct ioloop_context *io_loop_get_current_context(struct ioloop *ioloop);
+/* Returns fd, which contains all of the ioloop's current notifications.
+ When it becomes readable, there is a new notification. Calling this function
+ stops the existing notifications in the ioloop from working anymore.
+ This function's main idea is that the fd can be passed to another process,
+ which can use it to find out if an interesting notification happens.
+ Returns fd on success, -1 on error. */
+int io_loop_extract_notify_fd(struct ioloop *ioloop);
+
/* Move the given I/O into the current I/O loop if it's not already
there. New I/O is returned, while the old one is freed. */
struct io *io_loop_move_io(struct io **io);
More information about the dovecot-cvs
mailing list