ioloop-notify-inotify.c revision c7398cd92a003144358c121bdea63fba35b884ae
/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
#define _GNU_SOURCE
#include "lib.h"
#ifdef IOLOOP_NOTIFY_INOTIFY
#include "fd-close-on-exec.h"
#include "fd-set-nonblock.h"
#include "ioloop-internal.h"
#include "ioloop-notify-fd.h"
#include "buffer.h"
#include "network.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
struct ioloop_notify_handler_context {
struct ioloop_notify_fd_context fd_ctx;
int inotify_fd;
bool disabled;
};
static struct ioloop_notify_handler_context *io_loop_notify_handler_init(void);
{
struct ioloop_notify_handler_context *ctx =
const struct inotify_event *event;
unsigned char event_buf[INOTIFY_BUFLEN];
/* read as many events as there is available and fit into our buffer.
only full events are returned by the kernel. */
if (ret <= 0) {
if (ret == 0) {
/* nothing more to read */
return FALSE;
}
i_fatal("read(inotify) failed: %m");
}
i_fatal("gettimeofday(): %m");
break;
/* calling inotify_rm_watch() would now give
EINVAL */
}
}
}
i_error("read(inotify) returned partial event");
}
{
while (inotify_input_more(ioloop)) ;
}
{
struct ioloop_notify_handler_context *ctx =
int wd;
return IO_NOTIFY_NOSUPPORT;
if (wd < 0) {
/* ESTALE could happen with NFS. Don't bother giving an error
message then. */
return IO_NOTIFY_NOTFOUND;
else {
i_warning("Inotify watch limit for user exceeded, "
"disabling. Increase "
"/proc/sys/fs/inotify/max_user_watches");
}
return IO_NOTIFY_NOSUPPORT;
}
}
return IO_NOTIFY_ADDED;
}
{
struct ioloop_notify_handler_context *ctx =
/* ernro=EINVAL happens if the file itself is deleted and
kernel has sent IN_IGNORED event which we haven't read. */
i_error("inotify_rm_watch() failed: %m");
}
}
static struct ioloop_notify_handler_context *io_loop_notify_handler_init(void)
{
struct ioloop_notify_handler_context *ctx;
i_error("inotify_init() failed: %m");
else {
i_warning("Inotify instance limit for user exceeded, "
"disabling. Increase "
"/proc/sys/fs/inotify/max_user_instances");
}
} else {
}
return ctx;
}
{
struct ioloop_notify_handler_context *ctx =
i_error("close(inotify) failed: %m");
}
}
#endif