37#include <sys/inotify.h>
45#ifndef HAVE_INOTIFY_INIT1
60#define INOTIFY_MASK_DIR (IN_MOVED_TO | IN_ATTRIB | IN_CLOSE_WRITE | IN_ISDIR)
61#define INOTIFY_MASK_FILE IN_CLOSE_WRITE
63#define EVENT_BUFLEN MAX(4096, sizeof(struct inotify_event) + NAME_MAX + 1)
161#ifdef HAVE_INOTIFY_INIT1
162 INotifyFd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
211 monitor->
desc = descriptor;
227 memset(info, 0,
sizeof(*info));
260 monitor = monitor->
next;
275 struct stat st = { 0 };
277 while (iter && (iter->
desc != desc))
296 iter->
desc = new_desc;
332 struct stat st = { 0 };
363 fmt =
"%s/.mh_sequences";
370 if (stat(info->
path, &st) != 0)
374 while (iter && ((iter->
st_ino != st.st_ino) || (iter->
st_dev != st.st_dev)))
401 char buf[
EVENT_BUFLEN] __attribute__((aligned(__alignof__(
struct inotify_event))));
419 bool input_ready =
false;
434 const struct inotify_event *
event = NULL;
438 int len = read(
INotifyFd, buf,
sizeof(buf));
444 errno, strerror(errno));
449 while (ptr < (buf + len))
451 event = (
const struct inotify_event *) ptr;
453 event->wd, event->mask);
454 if (event->mask & IN_IGNORED)
458 ptr +=
sizeof(
struct inotify_event) + event->len;
497 ((desc = inotify_add_watch(
INotifyFd, info.
path, mask)) == -1))
500 info.
path, errno, strerror(errno));
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Convenience wrapper for the core headers.
int MuttGetchTimeout
Timeout in ms for mutt_getch()
#define mutt_debug(LEVEL,...)
Convenience wrapper for the gui headers.
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.
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
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 MonitorContextDescriptor
static int mutt_poll_fd_remove(int fd)
Remove a file from the watch list.
static int monitor_handle_ignore(int desc)
Listen for when a backup file is closed.
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
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
true after a monitored file has changed
static void monitor_check_free(void)
Close down file monitoring.
static int monitor_init(void)
Set up file monitoring.
static struct Monitor * Monitor
bool MonitorContextChanged
true after the current mailbox has changed
static void monitor_info_init(struct MonitorInfo *info)
Set up a file monitor.
#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 struct pollfd * PollFds
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.