Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

inotify

  1. Outdated egg!
  2. inotify
    1. Introduction
    2. Author
    3. Repository
    4. Current state of the bindings
    5. Requirements
    6. Common API
      1. Events
    7. Low-level API
      1. Setup and Teardown
      2. Watches
      3. Events
    8. High-level API
      1. Setup and Teardown
      2. Watches
      3. Events
      4. /proc Interface
    9. Examples
    10. License
    11. Version History
      1. 0.2
      2. 0.1

Introduction

This egg provides a nearly complete set of bindings to the Linux inotify API for watching file events. The authoritative source on its behavior is inotify(7).

Author

Vasilij Schneidermann

Repository

https://github.com/wasamasa/inotify

Current state of the bindings

Requirements

This library requires a sufficiently recent Linux kernel, but has been tested on Linux 4.8.13 only. Please report any incompatibilities you run into with older Linux versions.

Common API

Events

[procedure] (event? X)
[procedure] (event-wd EVENT)
[procedure] (event-flags EVENT)
[procedure] (event-cookie EVENT)
[procedure] (event-name EVENT)

Event predicate and accessors for event records. An event has a watch descriptor for associating it with a watch, a list of flags associated with the event, a cookie that is set for rename events to allow connecting the old and new file name and a name that is set for file events inside a watched directory.

The event flag list consists of at least one of the following symbols:

Low-level API

Setup and Teardown

[procedure] (%init!)

Initializes an user instance and returns its file descriptor.

[procedure] (%clean-up! FD)

Frees the user instance associated with FD and all associated watches.

Watches

[procedure] (%add-watch! FD PATH FLAGS)

Adds a watch for PATH which must be an absolute or relative path pointing to a file or directory. FLAGS is a list of at least one symbol describing the events one is interested in. Returns a watch descriptor associated with the watch.

The event flag list consists of at least one of the following event type symbols:

Further convenience flags:

Further options:

[procedure] (%remove-watch! FD WD)

Removes a watch as identified by the given watch descriptor WD.

Events

[procedure] (%next-events! FD)

Blocks the current thread to wait for events and returns a list of at least one event record. Note that calling this procedure does not block other SRFI-18 threads. In other words, it is possible to have a background thread reacting to file events while other threads proceed normally.

High-level API

Setup and Teardown

[procedure] (init!)

Initializes an user instance, returning #t when successful and #f if it has been initialized before. This procedure must be called before manipulating watches and fetching events.

[procedure] (clean-up!)

Frees the user instance and all associated watches, returning #t when successful and #f on subsequent attempts.

[parameter] (%fd)
[parameter] (%fd FD)

Parameter holding the user instance file descriptor. You shouldn't need to mess with this unless you insist on using more than one user instance for watching events.

Watches

[procedure] (add-watch! PATH FLAGS)

Adds a watch for PATH which must be an absolute or relative path pointing to a file or directory. FLAGS is a list of at least one symbol describing the events one is interested in. Returns a watch descriptor associated with the watch.

The event flag list consists of at least one of the following event type symbols:

Further convenience flags:

Further options:

[procedure] (remove-watch! WD)

Removes a watch as identified by the given watch descriptor WD.

[procedure] (add-watch-recursively! PATH FLAGS)

Adds a watch for PATH and traverses it recursively to add watches for any directories found in it. Each watch is applied with FLAGS, refer to the documentation of add-watch! for further details. Returns a list of watch descriptors associated with each established watch. Note that this procedure does not work in an atomic manner, it cannot be guaranteed that all directories in PATH will receive watches.

[procedure] (wd->path WD)

Returns the path the watch associated with WD was created with.

[procedure] (wd-list)

Returns a list of all known watch descriptors.

[procedure] (path-list)

Returns a list of all watched paths.

Events

[procedure] (next-events!)

Blocks the current thread to wait for events and returns a list of at least one event record. Note that calling this procedure does not block other SRFI-18 threads. In other words, it is possible to have a background thread reacting to file events while other threads proceed normally.

[parameter] (%events)
[procedure] (next-event!)

Convenience procedure for fetching one event at a time. This calls next-events! internally for filling up an event queue and returns one event from it. The event queue itself is available under %events and can be manipulated with the queue procedures from the data-structures unit.

[procedure] (event->pathname EVENT)

Convenience procedure for reconstructing the full path name from an event.

/proc Interface

[procedure] (max-queued-events)
[procedure] (max-user-instances)
[procedure] (max-user-watches)

Convenience procedures for querying usage limits from /proc/sys/fs/inotify.

Examples

(use inotify)

(init!)
(on-exit clean-up!)
(add-watch! "." '(all-events))

(let loop ()
  (print (next-event!))
  (loop))

More realistic examples can be found in the repository.

License

Copyright (c) 2017, Vasilij Schneidermann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version History

0.2

0.1