inotify_init(), inotify_init1()

QNX SDP8.0C Library ReferenceAPIDeveloper

Initialize the filesystem event notification system

Synopsis:

#include <sys/inotify.h>

int inotify_init( void );

int inotify_init1( const int flags );

Arguments:

flags
(inotify_init1() only) Flags to control the event notifications file descriptor returned by the function. If this argument is 0, then inotify_init1() is equivalent to inotify_init().

Library:

libfsnotify

Use the -l fsnotify option to qcc to link against this library.

Description:

The inotify_init() function initializes the filesystem event notification system. The inotify_init1() function is similar but it takes the flags argument which controls the returned file descriptor. This argument accepts the following values:
  • IN_NONBLOCK — Return a file descriptor that can be used for non-blocking I/O (e.g., you can call read() and it won't block).
  • IN_CLOEXEC — Close the file descriptor if the program calls one of the exec*(), posix_spawn*(), or spawn*() functions.
Note:
These functions open the file /dev/fsnotify, which fsevmgr (the filesystem event manager) creates and owns. If your process doesn't have read permission for this path or fsevmgr is not running, these functions fail.

To start receiving notifications from the filesystem event notification system, which is also known by its legacy name of inotify, do the following:

  1. Initialize the inotify system by calling inotify_init() or inotify_init1(), saving the file descriptor that it returns.
  2. Use inotify_add_watch() to add or modify a watch for a given file or directory.
  3. Read the filesystem events (of type struct inotify_event) from the file descriptor returned by inotify_init() or inotify_init1().

To stop receiving notifications from inotify, you can do the following:

  • Remove a watch, by calling inotify_rm_watch().
  • Remove all watches and shut down the inotify system, by closing the file descriptor returned by the initialization function.

For a detailed description of inotify, see http://www.linuxjournal.com/article/8478?page=0,0 in the Linux Journal, but note that there are differences between the Linux and QNX OS implementations. Currently, only io-blk.so-based filesystems and devf-ram-based filesystems support inotify.

Returns:

A file descriptor for the inotify mailbox, or -1 if an error occurred (errno is set).

Errors:

EINVAL
(inotify_init1() only) The flags argument contains unknown values.
EMFILE
The maximum number of inotify client instances have been created.
ENAMETOOLONG
The length of the FSNOTIFY_PREFIX environment variable exceeds PATH_MAX.
ENFILE
The system-wide limit on file descriptors has been reached.
ENOSYS
The fsevmgr process is not running.

Environment variables:

FSNOTIFY_PREFIX
Prefix for the filesystem event manager, fsevmgr, to use in the paths of the interfaces that it registers in the system namespace. Client programs and resource managers also prepend this variable's value to the paths they use for connecting to the fsevmgr service for reading and writing data. If you don't define FSNOTIFY_PREFIX, the default prefix is /dev, meaning the service registers its interfaces under this path. If you do define the variable, you must set it to the same value for fsevmgr and any programs that use this service.

Classification:

Linux

Safety:
Cancellation pointNo
Signal handlerNo
ThreadYes
Page updated: