Skip to content

Commit

Permalink
Indentation fixes and enable fanotify on linux by default
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae committed Jul 1, 2016
1 parent 4ed7895 commit 663a84a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ ifeq ($(shell uname),Linux)
# /| \\
# '| ||
# _\_):,_
CFLAGS+=-DHAVE_FANOTIFY=1
FANOTIFY_CFLAGS+=-DHAVE_FANOTIFY=1
FANOTIFY_CFLAGS+=-DHAVE_SYS_FANOTIFY=1

all: fsmon

fsmon:
$(CC) -o fsmon $(CFLAGS) $(LDFLAGS) $(SOURCES)
$(CC) -o fsmon $(CFLAGS) $(FANOTIFY_CFLAGS) $(LDFLAGS) $(SOURCES)

DESTDIR?=
PREFIX?=/usr
Expand Down
2 changes: 1 addition & 1 deletion backend/fanotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static bool fm_begin (FileMonitor *fm) {
goto fail;

if (fanotify_mark (fan_fd, mark_flags, fan_mask, AT_FDCWD, fm->root) != 0) {
perror("fanotify_mark");
perror ("fanotify_mark");
return -1;
}

Expand Down
10 changes: 5 additions & 5 deletions backend/inotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ static void freePathForFd() {
pidpathn = 0;
}

static void parseEvent(FileMonitor *fm, struct inotify_event *ie, FileMonitorEvent *ev) {
static bool parseEvent(FileMonitor *fm, struct inotify_event *ie, FileMonitorEvent *ev) {
static char absfile[PATH_MAX];
ev->type = FSE_INVALID;
if (ie->mask & IN_ACCESS) {
if (ie->mask & IN_ISDIR) {
return;
return false;
}
ev->type = FSE_STAT_CHANGED;
} else if (ie->mask & IN_MODIFY) {
Expand All @@ -106,7 +106,7 @@ static void parseEvent(FileMonitor *fm, struct inotify_event *ie, FileMonitorEve
ev->type = FSE_STAT_CHANGED;
} else if (ie->mask & IN_OPEN) {
if (ie->mask & IN_ISDIR) {
return;
return false;
}
ev->type = FSE_OPEN;
} else if (ie->mask & IN_CREATE) {
Expand Down Expand Up @@ -147,6 +147,7 @@ static void parseEvent(FileMonitor *fm, struct inotify_event *ie, FileMonitorEve
} else {
ev->file = "."; // directory itself
}
return true;
}

static void fm_inotify_add_dirtree(int fd, const char *name) {
Expand Down Expand Up @@ -208,8 +209,7 @@ static bool fm_loop (FileMonitor *fm, FileMonitorCallback cb) {
}
for (p = buf; p < buf + c; ) {
event = (struct inotify_event *) p;
parseEvent (fm, event, &ev);
if (ev.type != -1 && ev.file) {
if (parseEvent (fm, event, &ev)) {
cb (fm, &ev);
}
memset (&ev, 0, sizeof (ev));
Expand Down
12 changes: 8 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,29 @@ static bool setup_signals() {
static bool callback(FileMonitor *fm, FileMonitorEvent *ev) {
if (fm->child) {
if (fm->pid && ev->pid != fm->pid) {
if (ev->ppid != fm->pid)
if (ev->ppid != fm->pid) {
return false;
}
}
} else {
if (fm->pid && ev->pid != fm->pid) {
return false;
}
}
if (fm->root && ev->file) {
if (strncmp (ev->file, fm->root, strlen (fm->root)))
if (strncmp (ev->file, fm->root, strlen (fm->root))) {
return false;
}
}
if (fm->link && ev->file) {
if (!strncmp (ev->file, fm->link, strlen (fm->link)))
if (!strncmp (ev->file, fm->link, strlen (fm->link))) {
return false;
}
}
if (fm->proc && ev->proc) {
if (!strstr (ev->proc, fm->proc))
if (!strstr (ev->proc, fm->proc)) {
return false;
}
}
if (fm->json) {
char *filename = fmu_jsonfilter (ev->file);
Expand Down
24 changes: 17 additions & 7 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ void hexdump(const uint8_t *buf, unsigned int len, int w) {
for (i = 0; i < len; i += w) {
printf ("0x%08x: ", i);
for (j = i; j < i + w; j++) {
if (j<len) printf (j%2?"%02x ":"%02x", buf[j]);
else printf (j%2?" ":" ");
if (j < len) {
printf (j%2 ? "%02x ":"%02x", buf[j]);
} else {
printf (j%2 ? " " : " ");
}
}
printf (" ");
for (j = i; j < i + w; j++)
for (j = i; j < i + w; j++) {
printf ("%c", isprint (buf[j])? buf[j]: '.');
}
printf ("\n");
}
}
Expand Down Expand Up @@ -158,9 +162,15 @@ const char *get_proc_name(int pid, int *ppid) {

bool is_directory (const char *str) {
struct stat buf = {0};
if (!str || !*str) return false;
if (stat (str, &buf) == -1) return false;
if ((S_IFBLK & buf.st_mode) == S_IFBLK) return false;
if (!str || !*str) {
return false;
}
if (stat (str, &buf) == -1) {
return false;
}
if ((S_IFBLK & buf.st_mode) == S_IFBLK) {
return false;
}
return S_IFDIR == (S_IFDIR & buf.st_mode);
}

Expand All @@ -179,7 +189,7 @@ bool copy_file(const char *src, const char *dst) {
}
fd_dst = open (dst, O_RDWR | O_CREAT | O_TRUNC, mode);
if (fd_dst == -1) {
close (fd_src);
(void) close (fd_src);
return false;
}
for (;;) {
Expand Down

0 comments on commit 663a84a

Please sign in to comment.