Elektra  0.9.5
Plugin: resolver

The @PLUGIN_SHORT_NAME@ handles operating system dependent tasks. One task is the resolving of the filenames for user and system (hence its name).

Use following command to see to which file is resolved to:

kdb file <Elektra path you are interested in>

See the constants of this plugin for further information, they are:

system:/elektra/modules/@PLUGIN_SHORT_NAME@/constants
system:/elektra/modules/@PLUGIN_SHORT_NAME@/constants/ELEKTRA_VARIANT_SYSTEM
system:/elektra/modules/@PLUGIN_SHORT_NAME@/constants/ELEKTRA_VARIANT_USER
system:/elektra/modules/@PLUGIN_SHORT_NAME@/constants/KDB_DB_HOME
system:/elektra/modules/@PLUGIN_SHORT_NAME@/constants/KDB_DB_SYSTEM
system:/elektra/modules/@PLUGIN_SHORT_NAME@/constants/KDB_DB_USER
system:/elektra/modules/@PLUGIN_SHORT_NAME@/constants/KDB_DB_SPEC
system:/elektra/modules/@PLUGIN_SHORT_NAME@/constants/KDB_DB_DIR

The built-in resolving considers following cases:

(~ and pwd are resolved from system)

For an absolute path /example.ini, you might get following values:

For an relative path example.ini, you might get following values:

See the mount tutorial for more examples.

Many variants exist that additionally influence the resolving process, typically by using environment variables.

Environment variables are very simple for one-time usage but their maintenance in start-up scripts is problematic. Additionally, they are controlled by the user, so they cannot be trusted. So it is not recommended to use environment variables.

Note that the file permissions apply, so it might be possible for non-root to modify keys in system.

See COMPILE.md for a documentation of possible variants.

The resolver is fully XDG compatible if configured with the variant:

Additionally KDB_DB_USER needs to be left unchanged as .config.

XDG_CONFIG_DIRS will be used to resolve system paths the following way:

  1. If no update needed (unchanged modification time): quit successfully
  2. Otherwise call (storage) plugin(s) to read configuration
  3. remember the last stat time (last update)
  1. On unchanged configuration: quit successfully
  2. On empty configuration: remove the configuration file and quit successfully
  3. Otherwise, open the configuration file If not available recursively create directories and retry.

#ifdef ELEKTRA_LOCK_MUTEX

  1. Try to lock a global mutex, if not possible -> conflict

#endif

#ifdef ELEKTRA_LOCK_FILE

  1. Try to lock the configuration file, if not possible -> conflict

#endif

  1. Check the update time -> might lead to conflict
  2. Update the update time (in order to not self-conflict)

We have an optimistic approach. Locking is only used to detect concurrent cooperative processes in the short moment between prepare and commit. A conflict will be raised in that situation. When processes do not lock the file it might be overwritten. This is, however, very unlikely on file systems with nanosecond precision.

The resolver provides 2 functions for other plugins to use.

resolves path in with namespace namespace, creates a temporary file to work on and returns a struct containing the resolved data.

Signature: ElektraResolved * filename (elektraNamespace namespace, const char * path, ElektraResolveTempfile tempFile, Key * warningsKey)

ElektraResolved and ElektraResolveTempfile are both defined in shared.h.

ElektraResolved is a struct with the following members:

ElektraResolveTempfile dictates if and where a temporary file should be created. Possible values:

frees the handle returned by filename.

Signature: void * freeHandle (ElektraResolved * handle)

where handle is the handle returned by filename.