Go to the source code of this file.
Functions | |
void | inotifytools_cleanup () |
int | inotifytools_error () |
char * | inotifytools_event_to_str (int events) |
char * | inotifytools_event_to_str_sep (int events, char sep) |
char * | inotifytools_filename_from_wd (int wd) |
int | inotifytools_fprintf (FILE *file, struct inotify_event *event, char *fmt) |
int | inotifytools_get_max_queued_events () |
int | inotifytools_get_max_user_instances () |
int | inotifytools_get_max_user_watches () |
int | inotifytools_get_num_watches () |
int | inotifytools_get_stat_by_filename (char const *filename, int event) |
int | inotifytools_get_stat_by_wd (int wd, int event) |
int | inotifytools_get_stat_total (int event) |
int | inotifytools_ignore_events_by_regex (char const *pattern, int flags) |
int | inotifytools_initialize () |
void | inotifytools_initialize_stats () |
inotify_event * | inotifytools_next_event (int timeout) |
inotify_event * | inotifytools_next_events (int timeout, int num_events) |
int | inotifytools_printf (struct inotify_event *event, char *fmt) |
int | inotifytools_remove_watch_by_filename (char const *filename) |
int | inotifytools_remove_watch_by_wd (int wd) |
void | inotifytools_replace_filename (char const *oldname, char const *newname) |
void | inotifytools_set_filename_by_filename (char const *oldname, char const *newname) |
void | inotifytools_set_filename_by_wd (int wd, char const *filename) |
void | inotifytools_set_printf_timefmt (char *fmt) |
int | inotifytools_snprintf (char *out, int size, struct inotify_event *event, char *fmt) |
int | inotifytools_sprintf (char *out, struct inotify_event *event, char *fmt) |
int | inotifytools_str_to_event (char const *event) |
int | inotifytools_str_to_event_sep (char const *event, char sep) |
int | inotifytools_watch_file (char const *filename, int events) |
int | inotifytools_watch_files (char const *filenames[], int events) |
int | inotifytools_watch_recursively (char const *path, int events) |
int | inotifytools_watch_recursively_with_exclude (char const *path, int events, char const **exclude_list) |
int | inotifytools_wd_from_filename (char const *filename) |
To use this library, you must #include
the following headers accordingly:
<inotifytools/inotifytools
.h> - to use any functions declared in this file. <inotifytools/inotify
.h> - to have the inotify_event
type defined and the numeric IN_* event constants defined. If <sys/inotify
.h> was present on your system at compile time, this header simply includes that. Otherwise it includes <inotifytools/inotify-nosys
.h>.#include <stdio.h> #include <string.h> #include <inotifytools/inotifytools.h> #include <inotifytools/inotify.h> /* * libinotifytools example program. * Compile with gcc -linotifytools example.c */ int main() { // initialize and watch the entire directory tree from the current working // directory downwards for all events if ( !inotifytools_initialize() || !inotifytools_watch_recursively( ".", IN_ALL_EVENTS ) ) { fprintf(stderr, "%s\n", strerror( inotifytools_error() ) ); return -1; } // set time format to 24 hour time, HH:MM:SS inotifytools_set_printf_timefmt( "%T" ); // Output all events as "<timestamp> <path> <events>" struct inotify_event * event = inotifytools_next_event( -1 ); while ( event ) { inotifytools_printf( event, "%T %w%f %e\n" ); event = inotifytools_next_event( -1 ); } }
IN_ACCESS
- File was accessed (read) * IN_ATTRIB
- Metadata changed (permissions, timestamps, extended attributes, etc.) * IN_CLOSE_WRITE
- File opened for writing was closed * IN_CLOSE_NOWRITE
- File not opened for writing was closed * IN_CREATE
- File/directory created in watched directory * IN_DELETE
- File/directory deleted from watched directory * IN_DELETE_SELF
- Watched file/directory was itself deleted IN_MODIFY
- File was modified * IN_MOVE_SELF
- Watched file/directory was itself moved IN_MOVED_FROM
- File moved out of watched directory * IN_MOVED_TO
- File moved into watched directory * IN_OPEN
- File was opened * The IN_ALL_EVENTS macro is defined as a bit mask of all of the above events.
Two additional convenience macros are IN_MOVE, which equates to IN_MOVED_FROM|IN_MOVED_TO, and IN_CLOSE which equates to IN_CLOSE_WRITE|IN_CLOSE_NOWRITE.
The following bitmasks can also be provided when creating a new watch:
IN_DONT_FOLLOW
- Don't dereference pathname if it is a symbolic link IN_MASK_ADD
- Add (OR) events to watch mask for this pathname if it already exists (instead of replacing mask) IN_ONESHOT
- Monitor pathname for one event, then remove from watch list IN_ONLYDIR
- Only watch pathname if it is a directory
IN_IGNORED
- Watch was removed explicitly (inotifytools_remove_watch_*) or automatically (file was deleted, or file system was unmounted) IN_ISDIR
- Subject of this event is a directory IN_Q_OVERFLOW
- Event queue overflowed (wd is -1 for this event) IN_UNMOUNT
- File system containing watched object was unmountedDefinition in file inotifytools.h.
|
Close inotify and free the memory used by inotifytools. If you call this function, you must call inotifytools_initialize() again before any other functions can be used. Definition at line 326 of file inotifytools.c. References inotifytools_cleanup(). Referenced by inotifytools_cleanup(). |
|
Get the last error which occurred. When a function fails, call this to find out why. The returned value is a typical errno value, the meaning of which depends on context. For example, if inotifytools_watch_file() fails because you attempt to watch a file which doesn't exist, this function will return ENOENT.
Definition at line 1588 of file inotifytools.c. References inotifytools_error(). Referenced by inotifytools_error(). |
|
Convert event from integer form to string form (as in inotify.h). The returned string is from static storage; subsequent calls to this function or inotifytools_event_to_str_sep() will overwrite it. Don't free() it and make a copy if you want to keep it.
Exampleint eventnum == IN_MODIFY | IN_CLOSE | IN_CREATE; char * eventstr = inotifytools_event_to_str( eventnum ); printf( "%s\n", eventstr ); // outputs something like MODIFY,CLOSE,CREATE but order not guaranteed. Definition at line 628 of file inotifytools.c. References inotifytools_event_to_str(), and inotifytools_event_to_str_sep(). Referenced by inotifytools_event_to_str(), and inotifytools_snprintf(). |
|
Convert event from integer form to string form (as in inotify.h). The returned string is from static storage; subsequent calls to this function or inotifytools_event_to_str() will overwrite it. Don't free() it and make a copy if you want to keep it.
Exampleint eventnum == IN_MODIFY | IN_CLOSE | IN_CREATE; char * eventstr = inotifytools_event_to_str_sep( eventnum, '-' ); printf( "%s\n", eventstr ); // outputs something like MODIFY-CLOSE-CREATE but order not guaranteed. Definition at line 656 of file inotifytools.c. References inotifytools_event_to_str_sep(). Referenced by inotifytools_event_to_str(), inotifytools_event_to_str_sep(), and inotifytools_snprintf(). |
|
Get the filename used to establish a watch. inotifytools_initialize() must be called before this function can be used.
Definition at line 763 of file inotifytools.c. References inotifytools_filename_from_wd(). Referenced by inotifytools_filename_from_wd(), and inotifytools_snprintf(). |
|
Print a string to a file using an inotify_event and a printf-like syntax. The string written will only ever be up to 4096 characters in length.
Format string syntaxThe following tokens will be replaced with the specified string:
Example// suppose this is the only file watched. inotifytools_watch_file( "mydir/", IN_CLOSE ); // wait until an event occurs struct inotify_event * event = inotifytools_next_event( -1 ); inotifytools_fprintf(stderr, event, "in %w, file %f had event(s): %.e\n"); // suppose the file 'myfile' in mydir was read from and closed. Then, // this prints to standard error something like: // "in mydir/, file myfile had event(s): CLOSE_NOWRITE.CLOSE.ISDIR\n" Definition at line 1705 of file inotifytools.c. References inotifytools_fprintf(), and inotifytools_sprintf(). Referenced by inotifytools_fprintf(), and inotifytools_printf(). |
|
Get the event queue size. This setting can also be read or modified by accessing the file /proc/sys/fs/inotify/max_queued_events.
Definition at line 1953 of file inotifytools.c. References inotifytools_get_max_queued_events(). Referenced by inotifytools_get_max_queued_events(). |
|
Get the maximum number of user instances of inotify. This setting can also be read or modified by accessing the file /proc/sys/fs/inotify/max_user_instances.
Definition at line 1968 of file inotifytools.c. References inotifytools_get_max_user_instances(). Referenced by inotifytools_get_max_user_instances(). |
|
Get the maximum number of user watches. This setting can also be read or modified by accessing the file /proc/sys/fs/inotify/max_user_watches.
Definition at line 1983 of file inotifytools.c. References inotifytools_get_max_user_watches(). Referenced by inotifytools_get_max_user_watches(). |
|
Get the number of watches set up through libinotifytools.
Definition at line 1614 of file inotifytools.c. References inotifytools_get_num_watches(). Referenced by inotifytools_get_num_watches(). |
|
Get statistics by a particular filename. inotifytools_initialize_stats() must be called before this function can be used.
Definition at line 1572 of file inotifytools.c. References inotifytools_get_stat_by_filename(), inotifytools_get_stat_by_wd(), and inotifytools_wd_from_filename(). Referenced by inotifytools_get_stat_by_filename(). |
|
Get statistics by a particular watch descriptor. inotifytools_initialize_stats() must be called before this function can be used.
Definition at line 1495 of file inotifytools.c. References inotifytools_get_stat_by_wd(). Referenced by inotifytools_get_stat_by_filename(), and inotifytools_get_stat_by_wd(). |
|
Get statistics aggregated across all watches. inotifytools_initialize_stats() must be called before this function can be used.
Definition at line 1518 of file inotifytools.c. References inotifytools_get_stat_total(). Referenced by inotifytools_get_stat_total(). |
|
Ignore inotify events matching a particular regular expression. pattern is a regular expression and flags is a bitwise combination of POSIX regular expression flags. On future calls to inotifytools_next_events() or inotifytools_next_event(), the regular expression is executed on the filename of files on which events occur. If the regular expression matches, the matched event will be ignored. Definition at line 2000 of file inotifytools.c. References inotifytools_ignore_events_by_regex(). Referenced by inotifytools_ignore_events_by_regex(). |
|
Initialise inotify. You must call this function before using any function which adds or removes watches or attempts to access any information about watches.
Definition at line 281 of file inotifytools.c. References inotifytools_initialize(). Referenced by inotifytools_initialize(). |
|
Initialize or reset statistics. inotifytools_initialize() must be called before this function can be used. When this function is called, all subsequent events will be tallied. Statistics can then be obtained via the inotifytools_get_stat_* functions. After the first call, subsequent calls to this function will reset the event tallies to 0. Definition at line 418 of file inotifytools.c. References inotifytools_initialize_stats(). Referenced by inotifytools_initialize_stats(). |
|
Get the next inotify event to occur. inotifytools_initialize() must be called before this function can be used.
Definition at line 1038 of file inotifytools.c. References inotifytools_next_event(), and inotifytools_next_events(). Referenced by inotifytools_next_event(). |
|
Get the next inotify events to occur. inotifytools_initialize() must be called before this function can be used.
Definition at line 1092 of file inotifytools.c. References inotifytools_next_events(). Referenced by inotifytools_next_event(), and inotifytools_next_events(). |
|
Print a string to standard out using an inotify_event and a printf-like syntax. The string written will only ever be up to 4096 characters in length.
Format string syntaxThe following tokens will be replaced with the specified string:
Example// suppose this is the only file watched. inotifytools_watch_file( "mydir/", IN_CLOSE ); // wait until an event occurs struct inotify_event * event = inotifytools_next_event( -1 ); inotifytools_printf(stderr, event, "in %w, file %f had event(s): %.e\n"); // suppose the file 'myfile' in mydir was read from and closed. Then, // this prints to standard out something like: // "in mydir/, file myfile had event(s): CLOSE_NOWRITE.CLOSE.ISDIR\n" Definition at line 1660 of file inotifytools.c. References inotifytools_fprintf(), and inotifytools_printf(). Referenced by inotifytools_printf(). |
|
Remove a watch on a file specified by filename.
Definition at line 930 of file inotifytools.c. References inotifytools_remove_watch_by_filename(). Referenced by inotifytools_remove_watch_by_filename(). |
|
Remove a watch on a file specified by watch descriptor. inotifytools_initialize() must be called before this function can be used.
Definition at line 907 of file inotifytools.c. References inotifytools_remove_watch_by_wd(). Referenced by inotifytools_remove_watch_by_wd(). |
|
Replace a certain filename prefix on all watches. This function should be used to update filenames for an entire directory tree when a directory is known to have been moved or renamed. At the moment, libinotifytools does not automatically handle this situation. inotifytools_initialize() must be called before this function can be used.
Example// if /home/user1/original_dir is moved to /home/user2/new_dir, then to // update all watches: inotifytools_replace_filename( "/home/user1/original_dir", "/home/user2/new_dir" ); Definition at line 857 of file inotifytools.c. References inotifytools_replace_filename(). Referenced by inotifytools_replace_filename(). |
|
Set the filename for one or more watches with a particular existing filename. This function should be used to update a filename when a file is known to have been moved or renamed. At the moment, libinotifytools does not automatically handle this situation. inotifytools_initialize() must be called before this function can be used.
Definition at line 827 of file inotifytools.c. References inotifytools_set_filename_by_filename(). Referenced by inotifytools_set_filename_by_filename(). |
|
Set the filename for a particular watch descriptor. This function should be used to update a filename when a file is known to have been moved or renamed. At the moment, libinotifytools does not automatically handle this situation. inotifytools_initialize() must be called before this function can be used.
Definition at line 805 of file inotifytools.c. References inotifytools_set_filename_by_wd(). Referenced by inotifytools_set_filename_by_wd(). |
|
Set time format for printf functions.
Definition at line 1941 of file inotifytools.c. References inotifytools_set_printf_timefmt(). Referenced by inotifytools_set_printf_timefmt(). |
|
Construct a string using an inotify_event and a printf-like syntax. The string can only ever be up to 4096 characters in length.
Format string syntaxThe following tokens will be replaced with the specified string:
Example// suppose this is the only file watched. inotifytools_watch_file( "mydir/", IN_CLOSE ); // wait until an event occurs struct inotify_event * event = inotifytools_next_event( -1 ); char mystring[1024]; inotifytools_snprintf( mystring, 1024, event, "in %w, file %f had event(s): %.e\n" ); printf( mystring ); // suppose the file 'myfile' in mydir was written to and closed. Then, // this prints something like: // "in mydir/, file myfile had event(s): CLOSE_WRITE.CLOSE.ISDIR\n" Definition at line 1814 of file inotifytools.c. References inotifytools_event_to_str(), inotifytools_event_to_str_sep(), inotifytools_filename_from_wd(), and inotifytools_snprintf(). Referenced by inotifytools_snprintf(), and inotifytools_sprintf(). |
|
Construct a string using an inotify_event and a printf-like syntax. The string can only ever be up to 4096 characters in length. This function will keep writing until it reaches 4096 characters. If your allocated array is not large enough to hold the entire string, your program may crash. inotifytools_snprintf() is safer and you should use it where possible.
Format string syntaxThe following tokens will be replaced with the specified string:
Example// suppose this is the only file watched. inotifytools_watch_file( "mydir/", IN_CLOSE ); // wait until an event occurs struct inotify_event * event = inotifytools_next_event( -1 ); char mystring[1024]; // hope this doesn't crash - if filename is really long, might not fit into // mystring! inotifytools_sprintf(mystring, event, "in %w, file %f had event(s): %.e\n"); printf( mystring ); // suppose the file 'myfile' in mydir was written to and closed. Then, // this prints something like: // "in mydir/, file myfile had event(s): CLOSE_WRITE.CLOSE.ISDIR\n" Definition at line 1763 of file inotifytools.c. References inotifytools_snprintf(), and inotifytools_sprintf(). Referenced by inotifytools_fprintf(), and inotifytools_sprintf(). |
|
Convert comma-separated events from string form to integer form (as in inotify.h).
Examplechar * eventstr = "MODIFY,CLOSE,CREATE"; int eventnum = inotifytools_str_to_event( eventstr ); if ( eventnum == IN_MODIFY | IN_CLOSE | IN_CREATE ) { printf( "This code always gets executed!\n" ); } Definition at line 541 of file inotifytools.c. References inotifytools_str_to_event(), and inotifytools_str_to_event_sep(). Referenced by inotifytools_str_to_event(). |
|
Convert character separated events from string form to integer form (as in inotify.h).
Examplechar * eventstr = "MODIFY:CLOSE:CREATE"; int eventnum = inotifytools_str_to_event_sep( eventstr, ':' ); if ( eventnum == IN_MODIFY | IN_CLOSE | IN_CREATE ) { printf( "This code always gets executed!\n" ); } Definition at line 471 of file inotifytools.c. References inotifytools_str_to_event_sep(). Referenced by inotifytools_str_to_event(), and inotifytools_str_to_event_sep(). |
|
Set up a watch on a file.
Definition at line 953 of file inotifytools.c. References inotifytools_watch_file(), and inotifytools_watch_files(). Referenced by inotifytools_watch_file(), and inotifytools_watch_recursively_with_exclude(). |
|
Set up a watch on a list of files. inotifytools_initialize() must be called before this function can be used.
Definition at line 975 of file inotifytools.c. References inotifytools_watch_files(). Referenced by inotifytools_watch_file(), and inotifytools_watch_files(). |
|
Set up recursive watches on an entire directory tree. inotifytools_initialize() must be called before this function can be used.
Definition at line 1246 of file inotifytools.c. References inotifytools_watch_recursively(), and inotifytools_watch_recursively_with_exclude(). Referenced by inotifytools_watch_recursively(). |
|
Set up recursive watches on an entire directory tree, optionally excluding some directories. inotifytools_initialize() must be called before this function can be used.
Definition at line 1282 of file inotifytools.c. References inotifytools_watch_file(), and inotifytools_watch_recursively_with_exclude(). Referenced by inotifytools_watch_recursively(), and inotifytools_watch_recursively_with_exclude(). |
|
Get the watch descriptor for a particular filename. inotifytools_initialize() must be called before this function can be used.
Definition at line 784 of file inotifytools.c. References inotifytools_wd_from_filename(). Referenced by inotifytools_get_stat_by_filename(), and inotifytools_wd_from_filename(). |