25 #define _GNU_SOURCE // enable ppoll
27 #define _POSIX_C_SOURCE 200809L // enable nanosleep
38 #include <sys/types.h>
81 mfd = open(
"/proc/mounts", O_RDONLY, 0);
83 std::stringstream msg;
84 msg <<
"Failure to open /proc/mounts: "
85 << strerror_r(errno, errbuf,
sizeof(errbuf));
92 fds.events = POLLERR | POLLPRI;
100 ret = poll(&fds, nfds, 1);
102 if (fds.revents & POLLERR) {
106 }
else if (ret < 0) {
107 if (errno != EINTR) {
108 std::stringstream msg;
109 msg <<
"Failure to poll /proc/mounts: "
110 << strerror_r(errno, errbuf,
sizeof(errbuf));
130 StringSet::iterator pos;
149 for (pos = cbmounts->begin(); pos != cbmounts->end(); ++pos) {
150 if (0 ==
mounts->count(*pos)) {
156 for (pos =
mounts->begin(); pos !=
mounts->end(); ++pos) {
157 if (0 == cbmounts->count(*pos)) {
184 && (type[4] ==
'.' || type[4] ==
'\0')) {
199 struct timespec waiting_time_rem;
200 struct timespec waiting_time_req;
211 if (this->
mounts == NULL) {
217 ret = pthread_attr_init(&attr);
219 std::stringstream msg;
220 msg <<
"Failure to set thread attributes: "
221 << strerror_r(errno, errbuf,
sizeof(errbuf));
225 ret = pthread_create(&
thread, &attr,
run, (
void *)
this);
227 std::stringstream msg;
228 msg <<
"Failure to create thread: "
229 << strerror_r(errno, errbuf,
sizeof(errbuf));
233 waiting_time_req.tv_sec = 0;
234 waiting_time_req.tv_nsec = 100;
236 nanosleep(&waiting_time_req, &waiting_time_rem);
260 StringSet::iterator pos;
261 for (pos =
mounts->begin(); pos !=
mounts->end(); ++pos) {
271 ret = (int) pthread_join(
thread, &result);
273 std::stringstream msg;
275 msg <<
"Failure to join thread: "
276 << strerror_r(errno, errbuf,
sizeof(errbuf));
282 "Ending thread signals failure.\n");
static void * run(void *)
Thread listening to mount events.
static int markMount(int fd, const char *mount)
Marks a mount for polling fanotify events.
static pthread_t thread
thread.
Error, e.g. malfunction of the code, malware detected.
int fd
Fanotify file descriptor.
void add(const char *value)
Adds entry to string set.
Set of pointers to strings.
int find(const char *value)
Finds entry in string set.
int isFuse(const char *)
Checks if a mount is using a filesystem in userspace (fuse).
void clear()
Removes all entries from the cache.
void callback()
Tracks mountevents.
StringSet * getNoMarkMounts()
Gets the list of mounts not to be scanned.
static void message(const enum Level, const std::string &)
Sends message.
static int unmarkMount(int fd, const char *mount)
Removes a mount from polling fanotify events.
~MountPolling()
Deletes mount polling object.
MountPolling(int ffd, Environment *)
Polls mount and unmout events.
Cache for virus scanning results.
ScanCache * getScanCache()
Gets the scan cache.
StringSet * getNoMarkFileSystems()
Gets the list of file systems that shall not be scanned.
StringSet * nomarkmnt
Mount points that shall not be tracked.
sig_atomic_t status
Status of thread.
Poll /proc/mounts to detect mount events.
StringSet * nomarkfs
File systems that shall not be tracked.
StringSet * mounts
Mounts.
The environment holds variables that are shared by instances of multiple classes. ...
Environment * env
Environment.
int listmountnext(const char **dir, const char **type)