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

entr and improper inotify events #2507

Closed
Folo23 opened this issue Sep 18, 2017 · 9 comments
Closed

entr and improper inotify events #2507

Folo23 opened this issue Sep 18, 2017 · 9 comments

Comments

@Folo23
Copy link

Folo23 commented Sep 18, 2017

  • Microsoft Windows [Version 10.0.16278.1000]

entr is a small, unix-y utility that runs programs in response to changes in files.

Behavior of entr

While entr is notified when a change is made to a file from a Linux program within WSL, it isn't when the change is made from Windows.

For example, if I run entr on a small file, test.txt: $ echo "test.txt" | entr -p echo "changed", then open the file in Notepad, make some changes, and save it, nothing happens. If I open the same file in Vim in another WSL bash terminal, "changed" will be printed several times.

$ echo "test.txt" | entr -p echo "changed"
changed
changed
changed
changed

It also seems that entr doesn't pick up text appended to a file. If in the other terminal I append to the file: $ echo "Test String." >> test.txt. Nothing happens either.

Output of inotifywait

If I run inotifywait -m test.txt and then in another terminal echo "Test String." >> test.txt, the following output appears below inotifywait:

$ inotifywait -m test.txt
Setting up watches.
Watches established.
test.txt MODIFY
test.txt ATTRIB

Performing the same test on Linux shows the expected behavior:

$ inotifywait -m test.txt
Setting up watches.
Watches established.
test.txt OPEN
test.txt MODIFY
test.txt CLOSE_WRITE,CLOSE

Opening a file in Notepad and saving several changes reveals the following:

$ inotifywait -m test.txt
Setting up watches.
Watches established.
test.txt MODIFY
test.txt ATTRIB
test.txt MODIFY
test.txt ATTRIB
test.txt MODIFY
test.txt ATTRIB
test.txt MODIFY
test.txt ATTRIB

Making changes to a file in Linux that inotifywait is monitoring reveals the following:

~ inotifywait -m test.txt
Setting up watches.
Watches established.
test.txt MOVE_SELF
test.txt ATTRIB
test.txt DELETE_SELF

Tentative Conclusion

It seems like WSL isn't sending the proper inotify events when changes happen to a file, like indicating that a file has been closed. This causes programs like entr to fail.

@therealkenc
Copy link
Collaborator

therealkenc commented Sep 18, 2017

From #216 (message): [edit- better link and quote]

One thing to note about Phase 2 regarding inotify for DriveFs files changed from Windows is that we are relying on an internal API similar to the user-mode ReadDirectoryChangesW, so we cannot return all 12 Linux inotify events. Events such as IN_OPEN and IN_ACCESS will never be reported, since NT cannot return the equivalent events.

@eradman
Copy link

eradman commented Sep 22, 2017

The Build 14926 release notes seem to indicate that that IN_CLOSE_WRITE and IN_MOVE_SELF were implemented, but the examples that @Folo23 posted show that this is not the case.

What is the current list of supported events?

@therealkenc
Copy link
Collaborator

therealkenc commented Sep 22, 2017

The release notes for 14926 say "Inotify support for files modified through WSL". In Folo's post, the files were not modified though WSL; they were modified with notepad.exe. You can glean what notifications are supported from ReadDirectoryChangesW. Notice the absence of a close event, for example.

That said, regarding the statement from the devs: "...NT cannot return the equivalent events"

cant-or-wont

@eradman
Copy link

eradman commented Sep 23, 2017

@therealkenc, thanks for pointing out that this is not WSL.

Not having a close event is a problem, for this this application that still might be okay if there was a mapping from. NOTIFY_CHANGE_FILE_NAME from MOVE_SELF since editors nearly always write a temporary file and then swap it in to make the save operation atomic.

@poizan42
Copy link

@therealkenc Seeing that a filesystem filter driver can receive IRP_MJ_CLOSE I would say that there is no inherent limitations that prevents this from being implemented.

@therealkenc
Copy link
Collaborator

filesystem filter driver can receive IRP_MJ_CLOSE

Indeed. But you would have to convince the user of NOTEPAD.EXE to be operating on that filesystem filter driver, not NTFS on C:\. Which, I think is exactly what they have their top men looking at.

For now it appears, based on incomplete information, that they are limited to Zw* etc calls, just like the rest of us. You see this in the WSL networking stuff too. They don't have their own net filter driver either. They are limited to whatever WSK gives them.

Nothing prevents anything from being implemented, natch. They p0wn ring zero. Hence the Archer quote.

eradman added a commit to eradman/entr that referenced this issue Mar 27, 2018
Open problems with inotify support are detailed at
microsoft/WSL#2507
skomanduri pushed a commit to skomanduri/entr-wsl that referenced this issue Dec 10, 2018
Open problems with inotify support are detailed at
microsoft/WSL#2507
skomanduri pushed a commit to skomanduri/entr-wsl that referenced this issue Dec 10, 2018
Open problems with inotify support are detailed at
microsoft/WSL#2507
jwerle pushed a commit to clibs/entr that referenced this issue Oct 20, 2020
Open problems with inotify support are detailed at
microsoft/WSL#2507
@benhillis
Copy link
Member

Closing out old issues, if you're still having issues on newer versions of Windows please open a new issue.

@therealkenc
Copy link
Collaborator

The OP ask was addressed in WSL2 (by way of ext4). The entr application (a small, unix-y utility that runs programs in response to changes in files) will be fine there. For 9p (aka /mnt/c) the new landing zone is #4739.

@CervEdin
Copy link

@therealkenc but not on NTFS filesystems?

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

No branches or pull requests

6 participants