Skip to content

Commit

Permalink
Fix infinite loop with 1 mount point
Browse files Browse the repository at this point in the history
The patch changes the fanotify_update function to properly
handle deleting nodes when updating mount points. This should
take care of issue #253.
  • Loading branch information
stevegrubb committed Nov 17, 2023
1 parent fddcde1 commit d9029f8
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/daemon/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,34 +167,45 @@ void fanotify_update(mlist *m)
if (fd < 0)
return;

mnode *prev = m->head;
mlist_first(m);
while (m->cur) {
if (m->cur->status == ADD) {
if (m->head == NULL)
return;

mnode *cur = m->head, *prev = NULL, *temp;

while (cur) {
if (cur->status == ADD) {
// We will trust that the mask was set correctly
if (fanotify_mark(fd, FAN_MARK_ADD | mark_flag,
mask, -1, m->cur->path) == -1) {
mask, -1, cur->path) == -1) {
msg(LOG_ERR,
"Error (%s) adding fanotify mark for %s",
strerror(errno), m->cur->path);
strerror(errno), cur->path);
} else {
msg(LOG_DEBUG, "Added %s mount point",
m->cur->path);
cur->path);
}
}

// Now remove the deleted mount point
if (m->cur->status == DELETE) {
msg(LOG_DEBUG, "Deleted %s mount point", m->cur->path);
prev->next = m->cur->next;
free((void *)m->cur->path);
free((void *)m->cur);
m->cur = prev->next;
if (cur->status == DELETE) {
msg(LOG_DEBUG, "Deleted %s mount point", cur->path);
temp = cur->next;

if (cur == m->head)
m->head = temp;
else
prev->next = temp;

free((void *)cur->path);
free((void *)cur);

cur = temp;
} else {
prev = m->cur;
mlist_next(m);
prev = cur;
cur = cur->next;
}
}
m->cur = m->head; // Leave cur pointing to something valid
}

void shutdown_fanotify(mlist *m)
Expand Down

0 comments on commit d9029f8

Please sign in to comment.