Mercurial > dovecot > core-2.2
changeset 18994:3083424cafcd
lib: Added io_loop_extract_notify_fd()
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 24 Aug 2015 14:02:52 +0300 |
parents | 4673b93b04c6 |
children | 4da6efa3fd91 |
files | src/lib/ioloop-notify-inotify.c src/lib/ioloop-notify-kqueue.c src/lib/ioloop-notify-none.c src/lib/ioloop.h |
diffstat | 4 files changed, 68 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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
--- 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
--- 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);