Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inotify watch on config file should include IN_CREATE #2210

Closed
atalii opened this issue Mar 13, 2024 · 3 comments
Closed

inotify watch on config file should include IN_CREATE #2210

atalii opened this issue Mar 13, 2024 · 3 comments
Labels

Comments

@atalii
Copy link
Contributor

atalii commented Mar 13, 2024

Describe the bug

Currently, Wayfire will fail to automatically reload the config if that config is replaced by a new file (e.g., if it's a symlink). This causes difficulty specifically with NixOS and home-manager, where, to keep the config reproducible, it's symlinked in from the nix store. This is likely caused by inotify only watching the config for IN_CLOSE_WRITE events when a more liberal selection would be more appropriate.

To Reproduce

Write a config file, and symlink it to ~/.config/wayfire.ini or similar. Start wayfire. Write a new config file, and symlink (-f) that new file into ~/.config/wayfire.ini. Observe that wayfire does not reload the config.

Expected behavior

Wayfire should reload the config regardless of how it's updated.

Wayfire version

0.8.0. A cursory glance at git makes me think that this is still an issue.


Thanks so much! (By the way, my apologies if I've made a mistake reporting this; it's late here!)

@atalii atalii added the bug label Mar 13, 2024
@ammen99
Copy link
Member

ammen99 commented Mar 13, 2024

When the config file does not exist, we have a watch on the containing directory - have you been able to figure out why this is not enough?

@killown
Copy link
Contributor

killown commented Mar 13, 2024

correct if I am wrong but a symlink does not directly overwrite or modify the file system in the sense of overwriting data on disk, it updates the symbolic link to point the new target file, in most cases inotify monitors the file descriptor not the filename, so symlink for a new file is like no changes

@soreau
Copy link
Member

soreau commented Mar 13, 2024

I think @ammen99 is referring to this.

atalii added a commit to atalii/wayfire that referenced this issue Mar 13, 2024
If the config file is a symlink, wayfire attempts to watch the parent
directory so that, if replaced via a subsequent `ln -sf`, it'll still
be notified. When notified, however, wayfire doesn't immediately
reload the config file. Rather, as this event may be triggered by any
file creation in the directory, we first make sure that the config file
really is the one being created anew.

The filename from inotify is stored as a flexible array member in the
event struct, though, and this was somehow causing problems when
compared with the known std::string basename.

Fixes WayfireWM#2210.
atalii added a commit to atalii/wayfire that referenced this issue Mar 17, 2024
If the config file is a symlink, wayfire attempts to watch the parent
directory so that, if replaced via a subsequent `ln -sf`, it'll still
be notified. When notified, however, wayfire doesn't immediately
reload the config file. Rather, as this event may be triggered by any
file creation in the directory, we first make sure that the config file
really is the one being created anew.

Unfortunately, ln -sf is special: It'll create a randomly named file in
the directory before renameat(2)ing it to the proper location. So it
does generate an IN_CREATE event, but to know that the file was changed,
we need to additionally monitor for IN_MOVED_TO.

Fixes WayfireWM#2210.
atalii added a commit to atalii/wayfire that referenced this issue Mar 18, 2024
If the config file is a symlink, wayfire attempts to watch the parent
directory so that, if replaced via a subsequent `ln -sf`, it'll still
be notified. When notified, however, wayfire doesn't immediately
reload the config file. Rather, as this event may be triggered by any
file creation in the directory, we first make sure that the config file
really is the one being created anew.

Unfortunately, ln -sf is special: It'll create a randomly named file in
the directory before renameat(2)ing it to the proper location. So it
does generate an IN_CREATE event, but to know that the file was changed,
we need to additionally monitor for IN_MOVED_TO.

Fixes WayfireWM#2210.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants