GNU Direvent (split by chapter):   Section:   Chapter:FastBack: Invocation   Up: Top   FastForward: System dependencies   Contents: Table of ContentsIndex: Concept Index

5 Configuration

5.1 Configuration Syntax

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 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.

5.1.2 Pragmatic Comments

Pragmatic comments are similar to 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.

Include search path is formed by two directory sets: the user-defined search path, as defined by eventual -I (see include option) command line options, and the standard include search path, defined at compile time. The latter can be inspected using the --help option.

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. If file is not found in any of them, the standard include search path is scanned. It is defined at the compile time and by default consists of two directories:

  • prefix/share/direvent/5.2/include
  • prefix/share/direvent/include

where prefix is the installation prefix. The default can be changed when configuring the package. To inspect the actual standard include search path at the runtime, run direvent --help, and look for the string ‘Include search path:’ in its output.

#include_once <file>
#include_once file

Same as #include, except that, if the file 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 #line statement, understood for compatibility with the C preprocessor.

5.1.3 Statements

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:

standalone yes;
pidfile /var/run/;

A keyword begins with a letter and may contain letters, decimal digits, underscores (‘_’) and dashes (‘-’). Examples of keywords are: ‘expression’, ‘output-file’.

A value can be one of the following:


A number is a sequence of decimal digits.


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:

SequenceReplaced with
\aAudible bell character (ASCII 7)
\bBackspace character (ASCII 8)
\fForm-feed character (ASCII 12)
\nNewline character (ASCII 10)
\rCarriage return character (ASCII 13)
\tHorizontal tabulation character (ASCII 9)
\vVertical tabulation character (ASCII 11)
\\A single backslash (‘\’)
\"A double-quote.

Table 5.1: Backslash escapes

In addition, the sequence ‘\newline’ is removed from the string. This allows 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.

Two or more adjacent quoted strings are concatenated, which gives another way to split long strings over several lines to improve readability. The following fragment produces the same result as the example above:

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

A here-document is a special construct that allows 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:

A multiline

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, if - is followed by a single space, all leading whitespace is stripped from them. This allows to indent here-documents in a natural fashion. For example:

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

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.

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

option (stdout,stderr);

In any case 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);

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

syslog {
  facility local0;
  tag "direvent";

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

5.2 Macro Expansion

Arguments of some statements undergo macro expansion before use. During the macro expansion any occurrence of ‘$name’ is replaced by the value of the macro variable name. Variable names follow the usual convention: they begin with a letter and contain letters, digits and underscores. Curly braces around the name are optional. They are required only if the macro reference is followed by a character that is not to be interpreted as part of its name, as in ‘${command}string’.

The following macros are defined:


Name of the file that triggered the event.


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


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’.


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


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


A 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 System dependencies, for a list of system-dependent event names.

5.3 General Settings

Config: user name

Sets the user to run as. The name argument must be a name of an existing user.

Config: foreground bool

Run in foreground.

Config: pidfile file

Upon successful startup store the PID of the daemon process in file.

Config: debug number

Set debug level. Valid number values are ‘0’ (no debug) to ‘3’ (maximum verbosity).

5.4 Syslog

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:

Config: facility string

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

Config: tag string

Tag syslog messages with ‘string’. Normally the messages are tagged with the program name.

Config: print-priority bool

Prefix each message with its priority.

An example syslog statement:

syslog {
    facility local0;
    print-priority yes;

5.5 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 of them declaring a separate watcher.

watcher {
    path pathname [recursive [level]];
    file regexp-list;
    event event-list;
    command command-line;
    user name;
    timeout number;
    environ env-spec;
    option string-list;

The statements within a watcher block are:

Config: path pathname [recursive [number]]

Defines a pathname to watch. The pathname argument must be the name of a directory or file in the file system. If pathname refers to a directory, 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.

If pathname refers to a regular file, the changes to that file will be monitored. Obviously, in that case the ‘recursive’ keyword makes no sense. If present, it will be silently ignored.

If the pathname does not exist, GNU direvent will defer setting up the watcher until it is created. In order to do so, it will find the longest directory prefix that exists in the file system and will construct a sentinel watcher to monitor creation of the next directory component. When this component is created, the sentinel wakes up to set up a similar watcher for the next directory component. Once it is done, the sentinel removes itself. This process continues until the pathname is eventually created. When it happens, the last sentinel will activate the configured watcher.

These actions are performed in reverse order upon removal of pathname or any of its trailing directory components.

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

Config: file regexp-list

Selects which files are eligible for monitoring. The argument is a list of globbing patterns (in the sense of see fnmatch in fnmatch(3)) or extended regular expressions (see Extended regular expressions in GNU sed) one of which must match the file name in order for the watcher to act on it. A ‘!’ in front of a pattern or regular expression indicates negation. Such construct matches if the file name doesn’t match the pattern. Regular expressions must be surrounded by a pair of slashes, optionally followed by the following flags:


Use basic regular expressions.


Enable case-insensitive matching.

For example:

file ("*.cfg", "/.*\\.jpg/i");

In this statement, the first string (‘*.cfg’) is treated as a shell globbing pattern. The second one is a case-sensitive extended regular expression.

Config: 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 namess are allowed. Multiple event statements accumulate.

A missing event statement means “watch all events”.

For example:

event (open,delete);
Config: command string

Defines a command to execute on event. The string is a command line just as you would type it in sh. It may contain macro variables (see macro expansion), which will be expanded prior to execution.

For example:

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

By default, the command is executed directly via execve system call. If ‘shell’ option is set, the command is executed via /bin/sh.

See handler environment, for a detailed discussion of how the command is executed.

Config: user string

Run command as this user.

Config: timeout number

Terminate the command if it runs longer than number seconds. The default is 5 seconds.

Config: option string-list

A list of additional options. The following options are defined:


Invoke the handler command as /bin/sh -c "command".


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


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


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

Config: environ env-spec

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


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


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


The generic event code (see the $genev_code variable).


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


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

The environ statement allows for trimming the environment. Its argument is a list of environment modification directives. Before applying, each directive undergoes macro expansion (see macro expansion). The following directives are available:

-’ (a single dash)

Clear the inherited environment, but retain the variables added by direvent itself. The removed environment variables can be selectively restored using the directives discussed below.

If used, this must be the first directive in the list.

--’ (double-dash)

Clear the entire environment, including the variables added by direvent.

If used, this must be the first directive in the list.


Unset the variable name.


Unset the environment variable name only if its value is val.


Restore the environment variable name. This directive is useful after ‘-’ or ‘--’ to retain some variables from the environment.


Define environment variable name to have given value.


Retain variable name and append value to its existing value. If no such variable is present in the environment, it is created and value is assigned to it. However, if value begins with a punctuation character, this character is removed from it before the assignment. This is convenient for using this construct with environment variables like PATH, e.g.:


In this example, if PATH exists, ‘:/sbin’ will be appended to it. Otherwise, it will be created and ‘/sbin’ will be assigned to it.


Retain variable name and prepend value to its existing value. If no such variable is present in the environment, it is created and value is assigned to it. However, if value ends with a punctuation character, this character is removed from it before assignment.

Multiple environ statements accumulate.

GNU Direvent (split by chapter):   Section:   Chapter:FastBack: Configuration   Up: Configuration   FastForward: System dependencies   Contents: Table of ContentsIndex: Concept Index