mathstodon.xyz is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance for maths people. We have LaTeX rendering in the web interface!

Server stats:

2.7K
active users

#inotify

0 posts0 participants0 posts today
Replied in thread

@feld @pertho Doesn't feel like something I'd like to try though. It would be pretty much #FreeBSD-specific, but worse than that, you shouldn't rely on dtrace availability, as it's an optionally loadable profiling tool (so, it would also be a "misuse" regarding purpose). Related to that, I'm pretty sure it requires superuser privileges for everything, which would be another issue for some general-purpose application software.

No, the "canonical" solution for filesystem watching on a BSD system is indeed #kqueue. And unfortunately, it does fall short a bit compared to #Linux' #inotify. For my #xmoji tool, I wanted notifications about any change on the runtime configuration file, and additionally to the pure #POSIX solution of periodically calling stat() (which is stupid, but still works for a single file), I implemented backends for both inotify and kqueue. For just a single file, kqueue's requirement of having an open file descriptor is just a minor annoyance, but you can deal with that. Note it's not as simple as it sounds in any case, e.g. when the file is deleted, you want to watch the directory of course, so you learn when it's re-created ... which with kqueue requires opendir() 🙈 ... still doable. But for scenarios where you want to watch a whole tree with potentially lots of files and directories, this is really bad and #inotify really shines.

Replied in thread

@pertho The only little drawback compared to epoll is the lack of atomic signal mask setting, so you need a bit more code and a thoughtful structure to handle signals in the same loop. Apart from that, indeed much better than #epoll.

Unfortunately, it's not beter than inotify (for a completely different purpose, #file #monitoring ... kqueue covers them all). With #inotify, you can for example set a #watch by path, while #kqueue requires opened file descriptors. 😞

A small useful tool, based on inotify as a systemd service that checks directories for changes and outputs messages.

  • Real time monitoring: Observe designated paths for various file system activities, such as opening, closing, creating, deleting, reading, and writing files.
  • Notifications: File warden utilizes libnotify to deliver desktop alerts whenever a monitoring path experiences a files system event.
  • Logging: Records all file system events to Journal alongside the desktop notifications

#^https://github.com/AntoninoAdornetto/file-warden

#linux #systemd #inotify
Systemd-managed file monitoring service/daemon w/ notificiations - AntoninoAdornetto/file-warden
GitHubGitHub - AntoninoAdornetto/file-warden: Systemd-managed file monitoring service/daemon w/ notificiationsSystemd-managed file monitoring service/daemon w/ notificiations - AntoninoAdornetto/file-warden

is there a low-power "detect the computer is idle" api in #linux? i've attempted to use #inotify against input devices (following the example of aur.archlinux.org/packages/bri) but that's somewhat cpu intensive ...

i could do tricks by sleeping say 25 sec and then set up the inotify and select on it with a 5 sec timer, or so... then it's low power for 25 sec and the user has to be active in the 5 sec...

this tradeoff between the "resolution" of idle detection and the power usage seems regrettable

aur.archlinux.orgAUR (en) - brightd

Today's lesson is that #inotify is a Linux 🐧 construct and in BSD land 👹 monitoring the file system is part of #kqueues turf. Oh man there sure are alot of man pages and long docs to read ... or are there. Thank you watchdog (github.com/gorakhargosh/watchd) and thank you Mickaël Schoentgen and Yesudeep Mangalapilly

#Python to the rescue 🐍 🐍 🐍
python-watchdog.readthedocs.io

GitHubGitHub - gorakhargosh/watchdog: Python library and shell utilities to monitor filesystem events.Python library and shell utilities to monitor filesystem events. - gorakhargosh/watchdog

Podman 下的 inotify 問題

手上有個前端專案的開發環境是在 Linux container 上跑起來,有支援修改時 auto reload,我在 Linux Desktop 上面跑起來沒有問題,但在 MacBook (M 系列) 上開發就發現不會 auto reload,這樣改起來頗麻煩...

馬上有在猜是不是 inotify 的問題,先翻了一下資料,發現 inotify 在 Podman 上沒有被完整支援:「file changes not registered by inotifywait inside podm

blog.gslin.org/archives/2024/0

Gea-Suan Lin's BLOG · Podman 下的 inotify 問題
Continued thread

Found and fixed, the issue was with my compiler tests, compiling to stdout fails with GCC 🤯

github.com/Zirias/xmoji/commit

Now my CI build on github fails, and that's expected because #inotify is finally enabled in the build while most of the implementation is still missing 😂

GitHubmake: Avoid stdout for compiler tests · Zirias/xmoji@15a6f1aCompiling to stdout fails at least with gcc 12 on Linux. Compile directly to /dev/null instead.

minor news on my #Xmoji (#X11 #emoji #keyboad): The #kqueue backend for watching the config file now works on #FreeBSD (as far as I can tell, hard to test every possible edge case).

I also want to add #inotify for #Linux. I just realized I'll need a Linux machine to properly do that. So, installing Debian in bhyve. Joined my samba domain, mounted my #kerberos-encrypted #NFS homedirs, couldn't login, no idea where to find diagnostic output with dreaded systemd ... but right now I found the solution to the problem:

# ln -s /usr/bin/zsh /usr/local/bin/zsh

😂🤪

General thoughts about configuration of "modern" X11 desktop apps:

Next step for my #Xmoji #X11 #emoji #keyboard will be adding runtime configuration. Sending fake key-press events has some parameters (how long to wait before restoring the keymap, which hacks/workarounds to enable for sending the events ...) that should be configurable at runtime. A history of recently used emojis should be available and persisted. There may be more things to add here later (allow multiple instances? show and use a "tray icon"?).

I already have configurations for rendering and appearance aspects. For these, I use classic #Xresources. Even if they aren't that popular any more nowadays, they're IMHO the perfect place for such things: The configuration is tied to the currently running X server. They also offer a fine-grained scheme to match settings to classes and instances (e.g. individual widgets). So, learn about them and enjoy! 😄

Runtime configuration is a different beast. Back in the days, you had these dialogs with the typical three buttons, "apply" made changes effective without persisting them, "ok" persisted them and "cancel" reverted anything not persisted yet. There was also often some action available to re-load the currently persisted configuration.

Well, not any more. Nowadays, the predominant user experience is applying and persisting any change instantly. This is nice, but it creates an interesting issue, which most applications choose to just ignore. If either multiple instances of the same app are allowed to run for the same user on the same host, or the configuration is stored on some network share used by multiple hosts, inconsistencies are easily possible, with multiple instances of the app having a different idea about the "current" configuration and just persisting that on any change, overwriting what a different instance might have changed.

I came to the conclusion that I shouldn't ignore that issue for Xmoji. At least for persisting the emoji history, it would be unacceptable.

So, the obvious solution is that the configuration file must be monitored, so that any "remote" change can also be applied immediately in every running instance. The naive and portable solution for monitoring is to periodically stat() the file to check the modification timestamp. On network filesystems, that's the only thing that will work. I'll probably start with implementing just that.

For local files, there are platform-specific ways to obtain notifications from the OS (or kernel), which is better (immediate notification) and more efficient. #Linux has #inotify, #FreeBSD has #kqueue. I'm currently exploring docs and doing a few pocs for these interfaces as well ... this might really take a while, let's see. 🙈

Please comment with your thoughts about that if you have any! 😉