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
+1 -1
View File
@@ -255,7 +255,7 @@ int config_parse_dnssd_service_name(
return 0;
}
r = specifier_printf(rvalue, DNS_LABEL_MAX, specifier_table, NULL, &name);
r = specifier_printf(rvalue, DNS_LABEL_MAX, specifier_table, NULL, NULL, &name);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid service instance name template '%s', ignoring assignment: %m", rvalue);
+2 -2
View File
@@ -135,7 +135,7 @@ static int dnssd_service_load(Manager *manager, const char *filename) {
return 0;
}
static int specifier_dnssd_host_name(char specifier, const void *data, const void *userdata, char **ret) {
static int specifier_dnssd_host_name(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
DnssdService *s = (DnssdService *) userdata;
char *n;
@@ -170,7 +170,7 @@ int dnssd_render_instance_name(DnssdService *s, char **ret_name) {
assert(s);
assert(s->name_template);
r = specifier_printf(s->name_template, DNS_LABEL_MAX, specifier_table, s, &name);
r = specifier_printf(s->name_template, DNS_LABEL_MAX, specifier_table, NULL, s, &name);
if (r < 0)
return log_debug_errno(r, "Failed to replace specifiers: %m");