; ; @ANO_SCRIPT_NAME inotify_events ; @ANO_SCRIPT_VERSION 0.0.1 ; @ANO_SCRIPT_DESCRIPTION Simple inotify event example ; ; @ANO_FLAGS_USE_PROTOS [ ] ; @ANO_FLAGS_VAR_NAME_SUBS [ ] ; @ANO_FLAGS_VAR_WARN_UNUSED [ ] ; ; Copyright (c) 2016-2026, Jani Salonen ; All rights reserved. ; ; This example shows how to trigger inotify events when something happens with ; filesystem. ; ; Working inotify mechanism needs kernel support, this implementation does not ; support 3rd party libraries. ; main { ; Initialize inotify notifications if it is enabled... ; inotify_enabled { inotify_init (\ cb_notify: "in_notify") ; ...and register watch for /tmp directory. Callback runs when ; someone accesses or modifies the directory. ; _hnd = inotify_add_watch (\ watch: "/tmp", \ flags: INOTIFY_ACCESS | INOTIFY_MODIFY) print "Now go to /tmp and cd to some subdirectory to see" \ " callback to do its work.\n" print "Waiting for inotify events, " ; Watch can be removed manually when no longer needed. ; ;inotify_del_watch (handle: _hnd) } print "press to break.\n" } _INOTIFY_EVENT_ callback in_notify (_handle, _mask, _cookie, _path, _name) { dump _handle dump _mask dump _cookie dump _path dump _name print "\n" ; If watch is removed here, this callback does not run second time. ; ;inotify_del_watch (handle: _handle) }