Skip to content

Commit

Permalink
Handle FSE_CLOSE and FSE_CLOSE_WRITABLE inotify events
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jul 8, 2020
1 parent 3beb6de commit ed6f29a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/devfsev.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ typedef struct kfs_event_arg {
#define FSE_XATTR_REMOVED 10
#define FSE_MAX_EVENTS 11

#define FSE_CLOSE 20
#define FSE_CLOSE_WRITABLE 21

/* linux specific */
#define FSE_OPEN -2
#define FSE_UNKNOWN -3
Expand Down
23 changes: 23 additions & 0 deletions backend/inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,30 @@ static bool parseEvent(FileMonitor *fm, struct inotify_event *ie, FileMonitorEve
} else if (ie->mask & IN_MOVED_FROM) {
ev->type = FSE_RENAME;
} else if (ie->mask & IN_MOVED_TO) {
// rename in the same directory
ev->type = FSE_RENAME;
} else if (ie->mask & IN_CLOSE) {
ev->type = FSE_CLOSE;
} else if (ie->mask & IN_CLOSE_NOWRITE) {
ev->type = FSE_CLOSE;
} else if (ie->mask & IN_CLOSE_WRITE) {
ev->type = FSE_CLOSE_WRITABLE;
} else if (ie->mask & IN_IGNORED) {
ev->type = FSE_UNKNOWN;
eprintf ("Warning: ignored event\n");
} else if (ie->mask & IN_UNMOUNT) {
ev->type = FSE_CLOSE_WRITABLE;
eprintf ("Warning: filesystem was unmounted\n");
} else if (ie->mask == IN_Q_OVERFLOW) {
char cmd[512];
snprintf (cmd, sizeof (cmd) - 1, "sysctl -w fs.inotify.max_queued_events=%d",
max_queued_events);
max_queued_events += 32768;
eprintf ("Warning: inotify event queue is full.\n");
eprintf ("Running: %s\n", cmd);
system (cmd);
} else {
eprintf ("Unknown event 0x%04x\n", ie->mask);
}
#if 0
if (i->mask & IN_IGNORED) printf("IN_IGNORED ");
Expand Down
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <signal.h>
#include <getopt.h>
#include <unistd.h>
Expand Down
2 changes: 2 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const char *fm_typestr(int type) {
switch (type) {
case FSE_ARG_DONE: return "FSE_ARG_DONE";
case FSE_OPEN: return "FSE_OPEN";
case FSE_CLOSE: return "FSE_CLOSE";
case FSE_CLOSE_WRITABLE: return "FSE_CLOSE_WRITABLE";
case FSE_UNKNOWN: return "FSE_UNKNOWN";
}
return (type >= 0 && type < FSE_MAX_EVENTS && types[type])? types[type]: "";
Expand Down

0 comments on commit ed6f29a

Please sign in to comment.