watcher icon indicating copy to clipboard operation
watcher copied to clipboard

fix: Directly store inotify subscription paths

Open taratatach opened this issue 3 years ago • 0 comments

This fixes segmentations faults on Linux when using inotify and renaming both a directory (a.k.a the parent) and one of its sub-directories (a.k.a. the children).

When watching a new directory, the InotifyBackend will store a pointer to this directory's DirEntry to have access to its path. Also, when a directory is deleted, its DirEntry is erased as well as its content's entries. Finally, the InotifyBackend treats moves as a combination of a deletion and a creation, both in terms of events and entries.

Therefore, when processing a parent move followed by a child renaming, the InotifyBackend will follow these steps:

  1. process the parent deletion by removing its subscription, its associated DirEntry and the child DirEntry
  2. process the parent creation at its new path by creating a new subscription and a new DirEntry
  3. try to process the child deletion and crash because its associated DirEntry does not exist anymore and thus its pointer in the subscription cannot be dereferenced

We could prevent the segmentation fault by removing the children's subscriptions with the parent one when processing theparent deletion but this would mean missing the child renaming.

In the end, we solve the issue by directly storing the watched directory's path in the subscription rather than a pointer to a DirEntry. By doing so, even when the child DirEntry is deleted, the subscription for this directory will have access to its path and be able to process inotify events.

taratatach avatar Jun 24 '22 16:06 taratatach