Elektra
0.9.6
|
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:
See the constants of this plugin for further information, they are:
The built-in resolving considers following cases:
KDB_DB_SPEC
+ pathpwd
+ path (or above when path is found)pwd
+ KDB_DB_DIR
+ path (or above when path is found)~
+ path~
+ KDB_DB_USER
+ pathKDB_DB_SYSTEM
+ path(~ and pwd
are resolved from system)
For an absolute path /example.ini
, you might get following values:
/example.ini
$PWD/example.ini
~/example.ini
/example.ini
For an relative path example.ini, you might get following values:
/usr/share/elektra/specification/example.ini
$PWD/.dir/example.ini
~/.config/example.ini
/etc/kdb/example.ini
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.
See installation. The default variant of this plugin resolver_fm_hpu_b
is part of the libelektra5
package. All other variants are part of the libelektra5-extra
package.
The resolver is fully XDG compatible if configured with the variant:
xp
, xh
or xu
for user (either using passwd
, HOME
or USER
as fallback or any combination of these fallbacks)x
for system, no fallback necessaryAdditionally KDB_DB_USER
needs to be left unchanged as .config
.
XDG_CONFIG_DIRS
will be used to resolve system paths the following way:
/etc/xdg
will be used instead#ifdef ELEKTRA_LOCK_MUTEX
#endif
#ifdef ELEKTRA_LOCK_FILE
#endif
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:
relPath
: contains the path relative to the namespace.dirname
: contains the parent directory of the resolved file.fullPath
: contains the full path of the resolved file.tmpFile
: contains the full path of the created temporary file.ElektraResolveTempfile
dictates if and where a temporary file should be created. Possible values:
ELEKTRA_RESOLVER_TEMPFILE_NONE
: don't create a temporary file.ELEKTRA_RESOLVER_TEMPFILE_SAMEDIR
: create a temporary file in the same directory as the resolved file.ELEKTRA_RESOLVER_TEMPFILE_TMPDIR
: create a temporary file in /tmp
.frees the handle returned by filename
.
Signature: void * freeHandle (ElektraResolved * handle)
where handle
is the handle returned by filename
.
kdbOpen
. This happens, for example, with the default resolver (ELEKTRA_VARIANT_USER hpu
) if neither: $HOME
, $USER
, nor any home directory in /etc/passwd
is set.