Monitor files for changes. More...
#include "config.h"
#include <errno.h>
#include <limits.h>
#include <poll.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <sys/inotify.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "monitor.h"
#include "index/lib.h"
#include <fcntl.h>
Go to the source code of this file.
Data Structures | |
struct | Monitor |
A watch on a file. More... | |
struct | MonitorInfo |
Information about a monitored file. More... | |
Macros | |
#define | INOTIFY_MASK_DIR (IN_MOVED_TO | IN_ATTRIB | IN_CLOSE_WRITE | IN_ISDIR) |
#define | INOTIFY_MASK_FILE IN_CLOSE_WRITE |
#define | EVENT_BUFLEN MAX(4096, sizeof(struct inotify_event) + NAME_MAX + 1) |
Enumerations | |
enum | ResolveResult { RESOLVE_RES_FAIL_NOMAILBOX = -3 , RESOLVE_RES_FAIL_NOTYPE = -2 , RESOLVE_RES_FAIL_STAT = -1 , RESOLVE_RES_OK_NOTEXISTING = 0 , RESOLVE_RES_OK_EXISTING = 1 } |
Results for the Monitor functions. More... | |
Functions | |
static void | mutt_poll_fd_add (int fd, short events) |
Add a file to the watch list. | |
static int | mutt_poll_fd_remove (int fd) |
Remove a file from the watch list. | |
static int | monitor_init (void) |
Set up file monitoring. | |
static void | monitor_check_cleanup (void) |
Close down file monitoring. | |
static struct Monitor * | monitor_new (struct MonitorInfo *info, int descriptor) |
Create a new file monitor. | |
static void | monitor_info_free (struct MonitorInfo *info) |
Shutdown a file monitor. | |
static void | monitor_delete (struct Monitor *monitor) |
Free a file monitor. | |
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. | |
int | mutt_monitor_poll (void) |
Check for filesystem changes. | |
int | mutt_monitor_add (struct Mailbox *m) |
Add a watch for a mailbox. | |
int | mutt_monitor_remove (struct Mailbox *m) |
Remove a watch for a mailbox. | |
Variables | |
bool | MonitorFilesChanged = false |
Set to true when a monitored file has changed. | |
bool | MonitorCurMboxChanged = false |
Set to true when the current mailbox has changed. | |
static int | INotifyFd = -1 |
Inotify file descriptor. | |
static struct Monitor * | Monitor = NULL |
Linked list of monitored Mailboxes. | |
static size_t | PollFdsCount = 0 |
Number of used entries in the PollFds array. | |
static size_t | PollFdsLen = 0 |
Size of PollFds array. | |
static struct pollfd * | PollFds = NULL |
Array of monitored file descriptors. | |
static int | MonitorCurMboxDescriptor = -1 |
Monitor file descriptor of the current mailbox. | |
Monitor files for changes.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file monitor.c.
#define INOTIFY_MASK_DIR (IN_MOVED_TO | IN_ATTRIB | IN_CLOSE_WRITE | IN_ISDIR) |
#define EVENT_BUFLEN MAX(4096, sizeof(struct inotify_event) + NAME_MAX + 1) |
enum ResolveResult |
Results for the Monitor functions.
Enumerator | |
---|---|
RESOLVE_RES_FAIL_NOMAILBOX | No Mailbox to work on. |
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_OK_EXISTING | File exists, monitor is already attached. |
Definition at line 78 of file monitor.c.
|
static |
Add a file to the watch list.
fd | File to watch |
events | Events to listen for, e.g. POLLIN |
Definition at line 119 of file monitor.c.
|
static |
Remove a file from the watch list.
fd | File to remove |
0 | Success |
-1 | Error |
Definition at line 148 of file monitor.c.
|
static |
Set up file monitoring.
0 | Success |
-1 | Error |
Definition at line 168 of file monitor.c.
|
static |
Close down file monitoring.
Definition at line 200 of file monitor.c.
|
static |
Create a new file monitor.
info | Details of file to monitor |
descriptor | Watch descriptor |
ptr | Newly allocated Monitor |
Definition at line 217 of file monitor.c.
|
static |
Shutdown a file monitor.
info | Monitor to shut down |
Definition at line 237 of file monitor.c.
|
static |
Free a file monitor.
monitor | Monitor to free |
Definition at line 246 of file monitor.c.
|
static |
Listen for when a backup file is closed.
desc | Watch descriptor |
>=0 | New descriptor |
-1 | Error |
Definition at line 274 of file monitor.c.
|
static |
Get the monitor for a mailbox.
[out] | info | Details of the mailbox's monitor |
[in] | m | Mailbox |
>=0 | mailbox is valid and locally accessible: 0: no monitor / 1: preexisting monitor |
-3 | no mailbox (MonitorInfo: no fields set) |
-2 | type not set |
-1 | stat() failed (see errno; MonitorInfo fields: type, is_dir, path) |
If m is NULL, try to get the current mailbox from the Index.
Definition at line 332 of file monitor.c.
int mutt_monitor_poll | ( | void | ) |
Check for filesystem changes.
-3 | unknown/unexpected events: poll timeout / fds not handled by us |
-2 | monitor detected changes, no STDIN input |
-1 | error (see errno) |
0 | (1) input ready from STDIN, or (2) monitoring inactive -> no poll() |
Wait for I/O ready file descriptors or signals.
MonitorFilesChanged also reflects changes to monitored files.
Only STDIN and INotify file handles currently expected/supported. More would ask for common infrastructure (sockets?).
Definition at line 401 of file monitor.c.
int mutt_monitor_add | ( | struct Mailbox * | m | ) |
Add a watch for a mailbox.
m | Mailbox to watch |
0 | success: new or already existing monitor |
-1 | failed: no mailbox, inaccessible file, create monitor/watcher failed |
If m is NULL, try to get the current mailbox from the Index.
Definition at line 484 of file monitor.c.
int mutt_monitor_remove | ( | struct Mailbox * | m | ) |
Remove a watch for a mailbox.
m | Mailbox |
0 | monitor removed (not shared) |
1 | monitor not removed (shared) |
2 | no monitor |
If m is NULL, try to get the current mailbox from the Index.
Definition at line 528 of file monitor.c.
bool MonitorFilesChanged = false |
bool MonitorCurMboxChanged = false |
|
static |
|
static |