40#include <sys/inotify.h>
48#ifndef HAVE_INOTIFY_INIT1
70#define INOTIFY_MASK_DIR (IN_MOVED_TO | IN_ATTRIB | IN_CLOSE_WRITE | IN_ISDIR)
71#define INOTIFY_MASK_FILE IN_CLOSE_WRITE
73#define EVENT_BUFLEN MAX(4096, sizeof(struct inotify_event) + NAME_MAX + 1)
173#ifdef HAVE_INOTIFY_INIT1
174 INotifyFd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
223 monitor->
desc = descriptor;
263 monitor = monitor->
next;
278 struct stat st = { 0 };
280 while (iter && (iter->
desc != desc))
299 iter->
desc = new_desc;
335 struct stat st = { 0 };
366 fmt =
"%s/.mh_sequences";
373 if (stat(info->
path, &st) != 0)
377 while (iter && ((iter->
st_ino != st.st_ino) || (iter->
st_dev != st.st_dev)))
405 __attribute__((aligned(__alignof__(
struct inotify_event)))) = { 0 };
423 bool input_ready =
false;
438 const struct inotify_event *
event = NULL;
442 int len = read(
INotifyFd, buf,
sizeof(buf));
448 errno, strerror(errno));
453 while (ptr < (buf + len))
455 event = (
const struct inotify_event *) ptr;
457 event->wd, event->mask);
458 if (event->mask & IN_IGNORED)
462 ptr +=
sizeof(
struct inotify_event) + event->len;
500 ((desc = inotify_add_watch(
INotifyFd, info.
path, mask)) == -1))
503 info.
path, errno, strerror(errno));
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Convenience wrapper for the core headers.
struct Mailbox * mailbox_find(const char *path)
Find the mailbox with a given path.
MailboxType
Supported mailbox formats.
@ MUTT_MH
'MH' Mailbox type
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
@ MUTT_MAILDIR
'Maildir' Mailbox type
#define mutt_debug(LEVEL,...)
GUI manage the main index (list of emails)
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
@ LL_DEBUG3
Log at debug level 3.
@ LL_DEBUG2
Log at debug level 2.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
static void monitor_delete(struct Monitor *monitor)
Free a file monitor.
static int mutt_poll_fd_remove(int fd)
Remove a file from the watch list.
static int INotifyFd
Inotify file descriptor.
static int monitor_handle_ignore(int desc)
Listen for when a backup file is closed.
static int MonitorCurMboxDescriptor
Monitor file descriptor of the current mailbox.
static enum ResolveResult monitor_resolve(struct MonitorInfo *info, struct Mailbox *m)
Get the monitor for a mailbox.
static struct Monitor * monitor_new(struct MonitorInfo *info, int descriptor)
Create a new file monitor.
int mutt_monitor_poll(void)
Check for filesystem changes.
static size_t PollFdsCount
Number of used entries in the PollFds array.
static void mutt_poll_fd_add(int fd, short events)
Add a file to the watch list.
ResolveResult
Results for the Monitor functions.
@ RESOLVE_RES_FAIL_NOTYPE
Can't identify Mailbox type.
@ RESOLVE_RES_FAIL_STAT
Can't stat() the Mailbox file.
@ RESOLVE_RES_OK_NOTEXISTING
File exists, no monitor is attached.
@ RESOLVE_RES_FAIL_NOMAILBOX
No Mailbox to work on.
@ RESOLVE_RES_OK_EXISTING
File exists, monitor is already attached.
bool MonitorFilesChanged
Set to true when a monitored file has changed.
static int monitor_init(void)
Set up file monitoring.
bool MonitorCurMboxChanged
Set to true when the current mailbox has changed.
static void monitor_check_cleanup(void)
Close down file monitoring.
#define INOTIFY_MASK_FILE
static void monitor_info_free(struct MonitorInfo *info)
Shutdown a file monitor.
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
static size_t PollFdsLen
Size of PollFds array.
static struct pollfd * PollFds
Array of monitored file descriptors.
Monitor files for changes.
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
String manipulation buffer.
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
enum MailboxType type
Mailbox type.
Information about a monitored file.
struct Buffer path_buf
access via path only (maybe not initialized)
struct Monitor * next
Linked list.