DIREVENT.CONF(5)

NAME
direvent.conf - configuration file for direvent(8).

DESCRIPTION
The configuration file consists of statements and comments.

There are three classes of lexical tokens: keywords, values, and separators. Blanks, tabs, newlines and comments, collectively called white space are ignored except as they serve to separate tokens. Some white space is required to separate otherwise adjacent keywords and values.

COMMENTS
Comments may appear anywhere where white space may appear in the configuration file. There are two kinds of comments: single-line and multi-line comments. Single-line comments start with # or // and continue to the end of the line:

    # This is a comment
    // This too is a comment

Multi-line or C-style comments start with the two characters /* (slash, star) and continue until the first occurrence of */ (star, slash).

Multi-line comments cannot be nested. However, single-line comments may well appear within multi-line ones.

  Pragmatic Comments
Pragmatic comments are similar to the usual single-line comments, except that they cause some changes in the way the configuration is parsed. Pragmatic comments begin with a # sign and end with the next physical newline character.

#include <FILE>
#include FILE
    Include the contents of the file FILE. If FILE is an absolute file name, the named file is included. An error message will be issued if it does not exist.

    If FILE contains wildcard characters (*, [, ], or ?), it is interpreted as a shell globbing pattern and all files matching that pattern are included, in lexicographical order. If no matching files are found, the directive is replaced with an empty line.

    Otherwise, the form with angle brackets searches for file in the include search path, while the second one looks for it in the current working directory first, and, if not found there, in the include search path. If the file is not found, an error message will be issued.

    The order of directories is as follows. First, direvent scans any directories given with -I options, in the same order as given on the command line, and then the directories in the standard include search path. The latter is defined at compile time and can be inspected in the output of the --help option.

#include_once <FILE>
#include_once FILE
    Same as #include, except that, if the FILE (or any of the files it expands to) has already been included, it will not be included again.

#line num
#line num "FILE"
    This line causes the parser to believe, for purposes of error diagnostics, that the line number of the next source line is given by num and the current input file is named by FILE. If the latter is absent, the remembered file name does not change.

# num "FILE"
    This is a special form of the #line statement, understood for compatibility with the C preprocessor.

STATEMENTS

  Simple statement
A simple statement consists of a keyword and value separated by any amount of whitespace. Simple statement is terminated with a semicolon (;).

The following is a simple statement:

    pidfile /var/run/direvent.pid;

See below for a list of valid simple statements.

A value can be one of the following:

number
    A number is a sequence of decimal digits.

boolean
    A boolean value is one of the following: yes, true, t or 1, meaning true, and no, false, nil, 0 meaning false.

unquoted string
    An unquoted string may contain letters, digits, and any of the following characters: _, -, ., /, @, *, :.

quoted string
    A quoted string is any sequence of characters enclosed in double-quotes ("). A backslash appearing within a quoted string introduces an escape sequence, which is replaced with a single character according to the following rules:

    	Sequence	Expansion	ASCII
    	\\	\	134
    	\"	"	042
    	\a	audible bell	007
    	\b	backspace	010
    	\f	form-feed	014
    	\n	new line	012
    	\r	carriage return	015
    	\t	horizontal tabulation	011
    	\v	vertical tabulation	013

    In addition, the sequence \newline is removed from the string. This allows one to split long strings over several physical lines, e.g.:

    "a long string may be\
     split over several lines"

    If the character following a backslash is not one of those specified above, the backslash is ignored and a warning is issued.

Here-document
    A here-document is a special construct that allows one to introduce strings of text containing embedded newlines.

    The <<word construct instructs the parser to read all the following lines up to the line containing only word, with possible trailing blanks. Any lines thus read are concatenated together into a single string. For example:

    <<EOT
    A multiline
    string
    EOT

    The body of a here-document is interpreted the same way as a double-quoted string, unless word is preceded by a backslash (e.g. <<\EOT) or enclosed in double-quotes, in which case the text is read as is, without interpretation of escape sequences.

    If word is prefixed with - (a dash), then all leading tab characters are stripped from input lines and the line containing word. Furthermore, - is followed by a single space, all leading whitespace is stripped from them. This allows one to indent here-documents in a natural fashion. For example:

    <<- TEXT
        The leading whitespace will be
        ignored when reading these lines.
    TEXT

    It is important that the terminating delimiter be the only token on its line. The only exception to this rule is allowed if a here-document appears as the last element of a statement. In this case a semicolon can be placed on the same line with its terminating delimiter, as in:

    help-text <<-EOT
        A sample help text.
    EOT;

list
    A comma-separated list of values, enclosed in parentheses. The following example shows a statement whose value is a list of strings:

    option (wait, stderr);

    In any context where a list is appropriate, a single value is allowed without being a member of a list: it is equivalent to a list with a single member. This means that, e.g.

    option wait;

    is equivalent to

    option (wait);

  Block Statement
A block statement introduces a logical group of statements. It consists of a keyword, followed by an optional value, called a tag, and a sequence of statements enclosed in curly braces, as shown in the example below:

watcher {
    path /etc;
    event create;
}

The closing curly brace may be followed by a semicolon, although this is not required.

VARIABLE EXPANSION
Arguments of some statements undergo variable expansion before use. During variable expansion, variable references found in string are replaced with the actual values of the corresponding variables.

A variable reference has the form $VAR or ${VAR}, where VAR is the variable name. The two forms are entirely equivalent. The form with curly braces is normally used if the variable name is immediately followed by an alphanumeric symbol, which will otherwise be considered part of it. This form also allows for specifying the action to take if the variable is undefined or expands to an empty value:

${VARIABLE:-WORD}
    Use Default Values. If VARIABLE is unset or null, the expansion of WORD is substituted. Otherwise, the value of VARIABLE is substituted.

${VARIABLE:=WORD}
    Assign Default Values. If VARIABLE is unset or null, the expansion of WORD is assigned to the variable. The value of VARIABLE is then substituted.

${VARIABLE:?WORD}
    Display Error if Null or Unset. If VARIABLE is null or unset, the expansion of WORD (or a message to that effect if WORD is not present) is output to the current logging channel. Otherwise, the value of VARIABLE is substituted.

${VARIABLE:+WORD}
    Use Alternate Value. If VARIABLE is null or unset, nothing is substituted, otherwise the expansion of WORD is substituted.

Two kinds of variables take part in variable expansion: environment variables and macro variables. The latter are special variable-like entities defined by direvent to carry information about the event and its target file:

file
    Name of the file covered by the event.

genev_code
    Generic (system-independent) event code. It is a bitwise OR of the event codes represented as a decimal number.

genev_name
    Generic event name. If several generic events are reported simultaneously, the value of this variable is a list of event names separated by space characters. Each name corresponds to a bit in genev_code.

self_test_pid
    The PID of the external command started with the --self-test (-T) option. If direvent is started without this option, this variable is not defined.

sysev_code
    System-dependent event code. It is a bitwise OR of the event codes represented as a decimal number.

sysev_name
    System-dependent event name. If several events are reported, the value of this variable is a list of event names separated by space characters. Each name corresponds to a bit in sysev_code. See the section SYSTEM DEPENDENCIES in direvent(8), for a list of system-dependent event names.

GENERAL SETTINGS

user NAME;
    Sets the user to run as. NAME must be a name of an existing user.

foreground BOOL;
    Run in foreground.

pidfile FILE;
    Upon successful startup store the PID of the daemon process in FILE.

debug NUMBER;
    Set debug level. Valid NUMBER values are 0 (no debug) to 3 (maximum verbosity).

shutdown-timeout NUMBER
    Sets the time to wait for all subprocesses to terminate before exiting the program, in seconds. Any process that remains running after this timeout expires will be forcefully terminated.

    NUMBER is a floating-point number. The default is 1 second.

LOGGING
While connected to the terminal direvent outputs its diagnostics and debugging messages to the standard error. After disconnecting from the controlling terminal it closes the first three file descriptors and directs all its output to the syslog. When running in foreground mode, its messages are sent both to the standard error and to the syslog.

The following configuration statement controls the syslog output:

syslog {
facility STRING;
tag STRING;
print-priority BOOL;
}

The statements are:

facility STRING;
    Set syslog facility. STRING is one of the following: user, daemon, auth or authpriv, mail, cron, local0 through local7 (case-insensitive), or a facility number.

tag STRING;
    Tag syslog messages with STRING. Normally the messages are tagged with the program name.

print-priority BOOL;
    Prefix each message with its priority.

An example syslog statement:

syslog {
    facility local0;
    print-priority yes;
}

ENVIRONMENT
By default the command inherits the environment of direvent augmented with the following variables:

DIREVENT_SYSEV_CODE
    The system-dependent event code (see the sysev_code macro variable).

DIREVENT_SYSEV_NAME
    The system-dependent event name or names (see the sysev_name macro variable).

DIREVENT_GENEV_CODE
    The generic event code (see the genev_code macro variable).

DIREVENT_GENEV_NAME
    The generic event name or names (see the genev_name macro variable).

DIREVENT_FILE
    The name of the affected file relative to the current working directory (see the file macro variable).

This environment can be further modified, using the environ configuration statement:

environ {
clear;
keep PATTERN;
keep"NAME=VALUE";
set "NAME=VALUE";
eval EXPR;
unset PATTERN;
unset "NAME=VALUE";
}

Statements inside the environ block define operations that modify the environment. Their arguments undergo variable expansion. The clear statement is executed first. Then, keep statements are applied, in order of their appearance. Finally, set and unset statements are applied in order of their appearance in the configuration.

clear
    Clears the environment by removing (unsetting) all variables, except those listed in keep statements, if such are given (see below). This statement is always executed first.

keep PATTERN
    Declares variables matching PATTERN (a globbing pattern) as exempt from clearing. This statement implies clear.

keep "NAME=VALUE"
    Retains NAME in the environment only if it has the value VALUE. Notice double-quotes.

set "NAME=VALUE"
    Assigns VALUE to the environment variable NAME. The value is subject to variable expansion using the same syntax as in shell. The set, eval, and unset (see below) statements are executed in order of their appearance.

eval EXPR
    Perform variable expansion on EXPR and discard the result. This is useful for side-effects.

unset PATTERN
    Unset environment variables matching PATTERN.

unset "NAME=VALUE"
    Unset environment variable NAME if it has the given VALUE.

WATCHER
The watcher statement configures a single event watcher. A watcher can control several events in multiple pathnames. Any number of watcher statements is allowed in the configuration file, each one of them declaring a separate watcher.

watcher {
path PATHNAME [recursive [NUMBER]];
file STRING-LIST;
event STRING-LIST;
command STRING;
user NAME;
timeout NUMBER;
option STRING-LIST;
environ {ENV-SPEC}
}

The statements within a watcher block are:

path PATHNAME [recursive [NUMBER]];
    Defines a pathname to watch. PATHNAME must be the name of an existing directory in the file system. The watcher will watch events occurring for all files within that directory. If the optional recursive clause is specified, this directory will be watched recursively, i.e. when any subdirectory is created in it, direvent will set up a watcher for files in this subdirectory. This new watcher will be an exact copy of the parent watcher, excepting for the pathnames. The optional NUMBER parameter defines a cut-off nesting level for recursive watching. If supplied, the recursive behaviour will apply only to the directories that are nested below that level.

    Any number of path statements can appear in a watcher block. At least one path must be defined.

file STRING-LIST;
    Selects which files are eligible for monitoring. The argument is a list of globbing patterns (in the sense of fnmatch(3)) and/or extended regular expressions ( regex(7)) one of which the file name must match in order for the watcher to act on it. Regular expressions must be surrounded by a pair of slashes, optionally followed by the following flags:

    b   Use basic regular expressions.

    i   Enable case-insensitive matching.

        A pattern or regular expression prefixed with ! matches file names that don't match the pattern without !.

event STRING-LIST;
    Configures the filesystem events to watch for in the directories declared by the path statements. The argument is a list of event names. Both generic and system-dependent event names are allowed. Multiple event statements accumulate. A missing event statements means watch all events. For example:

    event (open,delete);

command STRING;
    Defines a command to execute on event. STRING is a command line just as you would type it in sh(1). It may contain macro variables, which will be expanded prior to execution. For example:

    command "/bin/prog -event $genev_name -file $file";

    See the section HANDLER ENVIRONMENT in direvent(8), for a detailed discussion of how the command is executed.

user STRING;
    Run command as this user.

timeout NUMBER;
    Terminate the command if it runs longer than NUMBER seconds. The default is 5 seconds.

option STRING-LIST;
    A list of additional options. The following options are defined:

    shell
        Invoke the handler command as $SHELL -c "command".

    wait
        Wait for the program to terminate before handling next event from the event queue. Normally the program runs asynchronously.

    stdout
        Capture the standard output of the command and redirect it to the syslog with the LOG_INFO priority.

    stderr
        Capture the standard error of the command and redirect it to the syslog with the LOG_ERR priority.

environ {ENV-SPEC}
    Modify command environment. See the section ENVIRONMENT, for a discussion of sub-statements in ENV-SPEC. This statement applies to the environment, modified by the global environ statement, if any.

SEE ALSO
direvent(8).

COPYRIGHT
Copyright © 2012-2026 Sergey Poznyakoff
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.