Skip to content

Commit 1f3f8ea

Browse files
committed
Fix warnings
1 parent 7eb1fe2 commit 1f3f8ea

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

backend/fanotify.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,20 @@ static int handle_perm(int fan_fd, struct fanotify_event_metadata *metadata) {
7878
}
7979

8080
static bool parseFaEvent(FileMonitor *fm, struct fanotify_event_metadata *metadata, FileMonitorEvent *ev) {
81-
char path[PATH_MAX];
82-
int path_len;
81+
char opath[PATH_MAX];
8382

8483
if (metadata->fd >= 0) {
84+
char path[PATH_MAX];
8585
sprintf (path, "/proc/self/fd/%d", metadata->fd);
86-
path_len = readlink (path, path, sizeof(path)-1);
86+
size_t path_len = readlink (path, opath, sizeof (opath) - 1);
8787
if (path_len < 0) {
8888
return false;
8989
}
90-
path[path_len] = '\0';
91-
//printf ("%s:", path);
90+
opath[path_len] = '\0';
9291
} else {
93-
strcpy (path, ".");
92+
strcpy (opath, ".");
9493
}
95-
ev->file = path;
94+
ev->file = opath;
9695
ev->pid = metadata->pid;
9796
ev->proc = get_proc_name (ev->pid, &ev->ppid);
9897
if (metadata->mask & FAN_ACCESS) {

backend/inotify.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* fsmon -- MIT - Copyright NowSecure 2016-2020 - pancake@nowsecure.com */
1+
/* fsmon -- MIT - Copyright NowSecure 2016-2025 - pancake@nowsecure.com */
22

33
#if __linux__
44

@@ -18,6 +18,8 @@
1818
#include <sys/syscall.h>
1919
#include "fsmon.h"
2020

21+
#define USE_LSOF 0
22+
2123
/* INOTIFY */
2224
static int fd = -1;
2325
#define BUF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1))
@@ -94,6 +96,7 @@ static void freePathForFd(void) {
9496
pidpathn = 0;
9597
}
9698

99+
#if USE_LSOF
97100
/* this is very slow, better not to enable it */
98101
static void lsof(const char *filename) {
99102
DIR *d = opendir ("/proc");
@@ -132,6 +135,7 @@ static void lsof(const char *filename) {
132135
}
133136
closedir (d);
134137
}
138+
#endif
135139

136140
static bool uidofpath(const char *str, FileMonitorEvent *ev) {
137141
struct stat buf = {0};
@@ -195,7 +199,7 @@ static int pidofuid(int uid, FileMonitorEvent *ev) {
195199
}
196200
// stat /proc/*/cwd | grep uid == st_uid
197201
DIR *d = opendir ("/proc");
198-
struct dirent *entry, *entry2;
202+
struct dirent *entry;
199203
while ((entry = readdir (d))) {
200204
int pid = atoi (entry->d_name);
201205
if (pid == 0) {
@@ -327,8 +331,8 @@ static bool parseEvent(FileMonitor *fm, struct inotify_event *ie, FileMonitorEve
327331
if (uidofpath (absfile, ev)) {
328332
pidofuid (ev->uid, ev);
329333
}
330-
#if 0
331-
// lsof (absfile);
334+
#if USE_LSOF
335+
lsof (absfile);
332336
#endif
333337
} else {
334338
static char fdpath[64];

0 commit comments

Comments
 (0)