Inotify event example
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.
Compilation
Easiest way to get this example running is to go to examples directory in package root, and run:
$ ./build.sh inotify_events
build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.
Preview
; ------------------------------------------------------------------------------
; inotify_events.ano
;
; To compile:
;
; $ ./build/ano ./examples/inotify_events/inotify_events.ano > \
; engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
; @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 © 2016-2026, Jani Salonen <salojan@goto10.co>
; 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 <ctrl-c> 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)
}
; ------------------------------------------------------------------------------ ; inotify_events.w2c ; ; To compile: ; ; $ ./build/widget ./examples/inotify_events/inotify_events.w2c > \ ; engine/widget_defs.h ; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------ ; inotify_events.m2c ; ; To compile: ; ; $ ./build/menu ./examples/inotify_events/inotify_events.m2c > \ ; engine/menu_defs.h ; ------------------------------------------------------------------------------
Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.