mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
tmpfiles.d: only 'w+' can have multiple lines for the same path
Since d0ea5c5e39dce60efbce6d86534eb9ca253440b0, all lines specifying actions that recreate a file system object (such as 'f+, 'L+', etc ...) on the same path were allowed. This had the bad side effect to break the tmpfiles configuration file sorting for files defining such lines. For example: # cat /etc/tmpfiles.d/a.conf f+ /tmp/file - - - - a.conf # cat /etc/tmpfiles.d/z.conf f+ /tmp/file - - - - z.conf # systemd-tmpfiles --create /etc/tmpfiles.d/{a,z}.conf # cat /tmp/file z.conf Even though "a.conf" sorts lexicographically before "z.conf", the content of /tmp/file was the result of the action defined in "z.conf" This patch restores the old logic - if multiple files specify the same path, the entry in the file with the lexicographically earliest name will be applied.
This commit is contained in:
parent
20742f92c1
commit
9af74e0f59
@ -2896,6 +2896,26 @@ static int parse_age_by_from_arg(const char *age_by_str, Item *item) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool is_duplicated_item(ItemArray *existing, Item *i) {
|
||||
|
||||
assert(existing);
|
||||
assert(i);
|
||||
|
||||
for (size_t n = 0; n < existing->n_items; n++) {
|
||||
Item *e = existing->items + n;
|
||||
|
||||
if (item_compatible(e, i))
|
||||
continue;
|
||||
|
||||
/* Only multiple 'w+' lines for the same path are allowed. */
|
||||
if (e->type != WRITE_FILE || !e->append_or_force ||
|
||||
i->type != WRITE_FILE || !i->append_or_force)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int parse_line(
|
||||
const char *fname,
|
||||
unsigned line,
|
||||
@ -3247,13 +3267,10 @@ static int parse_line(
|
||||
|
||||
existing = ordered_hashmap_get(h, i.path);
|
||||
if (existing) {
|
||||
size_t n;
|
||||
|
||||
for (n = 0; n < existing->n_items; n++) {
|
||||
if (!item_compatible(existing->items + n, &i) && !i.append_or_force) {
|
||||
log_syntax(NULL, LOG_NOTICE, fname, line, 0, "Duplicate line for path \"%s\", ignoring.", i.path);
|
||||
return 0;
|
||||
}
|
||||
if (is_duplicated_item(existing, &i)) {
|
||||
log_syntax(NULL, LOG_NOTICE, fname, line, 0,
|
||||
"Duplicate line for path \"%s\", ignoring.", i.path);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
existing = new0(ItemArray, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user