diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index c447cd0638..f7a6af7059 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -2302,6 +2302,11 @@ Credentials directory This is the value of the $CREDENTIALS_DIRECTORY environment variable if available. See section "Credentials" in systemd.exec5 for more information. + + %D + Shared data directory + This is either /usr/share/ (for the system manager) or the path $XDG_DATA_HOME resolves to (for user managers). + %E Configuration directory root diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 9f95984eb6..be4cb139e9 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -4,6 +4,7 @@ #include "cgroup-util.h" #include "format-util.h" #include "macro.h" +#include "sd-path.h" #include "specifier.h" #include "string-util.h" #include "strv.h" @@ -164,6 +165,14 @@ static int specifier_credentials_dir(char specifier, const void *data, const cha return 0; } +static int specifier_shared_data_dir(char specifier, const void *data, const char *root, const void *userdata, char **ret) { + const Unit *u = ASSERT_PTR(userdata); + + assert(ret); + + return sd_path_lookup(MANAGER_IS_SYSTEM(u->manager) ? SD_PATH_SYSTEM_SHARED : SD_PATH_USER_SHARED, NULL, ret); +} + int unit_name_printf(const Unit *u, const char* format, char **ret) { /* * This will use the passed string as format string and replace the following specifiers (which should all be @@ -208,6 +217,7 @@ int unit_full_printf_full(const Unit *u, const char *format, size_t max_length, * * %C: the cache directory root (e.g. /var/cache or $XDG_CACHE_HOME) * %d: the credentials directory ($CREDENTIALS_DIRECTORY) + * %D: the shared data root (e.g. /usr/share or $XDG_DATA_HOME) * %E: the configuration directory root (e.g. /etc or $XDG_CONFIG_HOME) * %L: the log directory root (e.g. /var/log or $XDG_STATE_HOME/log) * %S: the state directory root (e.g. /var/lib or $XDG_STATE_HOME) @@ -245,6 +255,7 @@ int unit_full_printf_full(const Unit *u, const char *format, size_t max_length, { 'C', specifier_special_directory, UINT_TO_PTR(EXEC_DIRECTORY_CACHE) }, { 'd', specifier_credentials_dir, NULL }, + { 'D', specifier_shared_data_dir, NULL }, { 'E', specifier_special_directory, UINT_TO_PTR(EXEC_DIRECTORY_CONFIGURATION) }, { 'L', specifier_special_directory, UINT_TO_PTR(EXEC_DIRECTORY_LOGS) }, { 'S', specifier_special_directory, UINT_TO_PTR(EXEC_DIRECTORY_STATE) },