Implementation of configuration files

Submitted by Veronika Kabatova on May 22, 2017, 3 p.m.


Reviewer None
Submitted May 22, 2017, 3 p.m.
Last Updated June 21, 2017, 3:03 p.m.
Revision 5

Cover Letter

From: Veronika Kabatova <>

This patchset addresses GitHub issue #278 - add support for configuration files.
Configuration files allow users to write their most used options into a file
and reuse them instead of typing them all the time on the command line. Two
methods for configuration file usage are introduced:
    -- passing a specific file with --config FILEPATH
    -- configuration files /etc/criu/default.conf and $HOME/.criu/default.conf
       are parsed (in this order) by default if present (can be disabled by
       --no-default-config option)

Configuration file hierarchy aims to be consistent with command line usage (no
difference between using configuration files and command line with the right
order of options), which allows overriding of boolean options and partial
specification when using options which can be used more times.

Configuration file format allows comments and uses long options syntax,
therefore a long version for verbosity option needed to be introduced first for
users who would wish to specify verbosity settings in the configuration files.

The test suite was modified to use --no-default-config to not break when run
on system which would be using default configuration files and a simple test
is added to check option parsing is working properly.

Changes since v1:
   - code cleanup (mostly variable naming and indexing)
   - move #defines from header
   - fix bug with comparison branching
   - add comment to explain allocation of config init value
   - remove default switch branch
   - move all declaration to beginning of functions
   - move most of config-related stuff to separate functions and keep only
     minimum of code in main()

Changes since v2:
   - implementation of fscanf() on my machine does not trigger warning about
     ignored return value (glibc-headers-2.23.1-11.fc24.x86_64)

Changes since v3:
   - address avagin's comments
     - rework parser to accept arguments with spaces
     - rename configuration directories to criu and .criu instead of criu.d
       and .criu.d, respectively
     - merge functions for --help and --no-default-config detection to reduce
       number of iterations through argv (merging with --config NAME retrieval
       is not really possible due to the type of return value)
     - minor code changes (static function, move of xmalloc call, error
       reporting and fail)
     - removal of code for memory cleanup

Changes since v4:
   - modify tcp-close option to have it's negation for configuration overriding
     since this option was added only now and without the negation support

Veronika Kabatova (5):
  Add long option for verbosity changes
  Change tcp-close option to negated style
  Add support for configuration files
  Add documentation for configuration files
  Modify and add test for configuration file functionality

 Documentation/criu.txt                     |  44 +++++-
 criu/Makefile                              |   7 +
 criu/crtools.c                             | 237 +++++++++++++++++++++++++++--
 criu/include/cr_options.h                  |   2 +-
 test/Makefile                              |   2 +-
 test/                               |   7 +-
 test/zdtm/static/Makefile                  |   1 +
 test/zdtm/static/config_inotify_irmap.c    |  91 +++++++++++
 test/zdtm/static/config_inotify_irmap.desc |   3 +
 9 files changed, 374 insertions(+), 20 deletions(-)
 create mode 100644 test/zdtm/static/config_inotify_irmap.c
 create mode 100644 test/zdtm/static/config_inotify_irmap.desc