tree-wide: make specifier expansion --root= aware

This fixes repart's, systemctl's, sysusers' and tmpfiles' specifier
expansion to honour the root dir specified with --root=. This is
relevant for specifiers such as %m, %o, … which are directly sourced
from files on disk.

This doesn't try to be overly smart: specifiers referring to runtime
concepts (i.e. boot ID, architecture, hostname) rather than files on the
medium are left as is. There's certainly a point to be made that they
should fail in case --root= is specified, but I am not entirely convinced
about that, and it's certainly something we can look into later if
there's reason to.

I wondered for a while how to hook this up best, but given that quite a
large number of specifiers resolve to data from files on disks, and most
of our tools needs this, I ultimately decided to make the root dir a
first class parameter to specifier_printf().

Replaces: #16187
Fixes: #16183
This commit is contained in:
Lennart Poettering
2021-06-24 22:30:14 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 0c651d32d4
commit de61a04b18
16 changed files with 181 additions and 136 deletions
+6 -5
View File
@@ -4,10 +4,11 @@
#include "install.h"
#include "unit-name.h"
int install_full_printf_internal(const UnitFileInstallInfo *i, const char *format, size_t max_length, char **ret);
static inline int install_name_printf(const UnitFileInstallInfo *i, const char *format, char **ret) {
return install_full_printf_internal(i, format, UNIT_NAME_MAX, ret);
int install_full_printf_internal(const UnitFileInstallInfo *i, const char *format, size_t max_length, const char *root, char **ret);
static inline int install_name_printf(const UnitFileInstallInfo *i, const char *format, const char *root, char **ret) {
return install_full_printf_internal(i, format, UNIT_NAME_MAX, root, ret);
}
static inline int install_path_printf(const UnitFileInstallInfo *i, const char *format, char **ret) {
return install_full_printf_internal(i, format, PATH_MAX-1, ret);
static inline int install_path_printf(const UnitFileInstallInfo *i, const char *format, const char *root, char **ret) {
return install_full_printf_internal(i, format, PATH_MAX-1, root, ret);
}