The data structure used by tmpfiles is changed: instead of hashmaps
mapping {path → Item*} we now have hashmaps containing
{path - ItemArray}, where ItemArray contains a pointer
to an array of Items.
For current code it doesn't matter much, but when we add new types it
is easier to simply add a new Item for a given path, then to coalesce
multiple lines into one Item.
In the future, this change will also make it possible to remember the
file and line where each Item originates, and use that in reporting
errors. Currently this is not possible, since each Item can be created
from multiple lines.
---
man/tmpfiles.d.xml | 13 +-
src/tmpfiles/tmpfiles.c | 308
2 files changed, 160 insertions(+), 161 deletions(-)
diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml
index 9fd5913d83..8d806a41ea 100644
--- a/man/tmpfiles.d.xml
+++ b/man/tmpfiles.d.xml
@@ -288,16 +288,9 @@
varlistentry
termvarnamet/varname/term
- listitemparaSet extended attributes on item. It may be
- used in conjunction with other types (only
- varnamed/varname, varnameD/varname,
- varnamef/varname, varnameF/varname,
- varnameL/varname, varnamep/varname,
- varnamec/varname, varnameb/varname, makes sense).
- If used as a standalone line, then
- commandsystemd-tmpfiles/command will try to set extended
- attributes on specified path. This can be especially used
- to set SMACK labels. /para/listitem
+ listitemparaSet extended attributes on the specified
+ path. This can be useful for setting SMACK labels.
+ /para/listitem
/varlistentry
/variablelist
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 84d778a08f..c44dfaf1d2 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -4,6 +4,7 @@
This file is part of systemd.
Copyright 2010 Lennart Poettering, Kay Sievers
+ Copyright 2015 Zbigniew Jędrzejewski-Szmek
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
@@ -113,6 +114,12 @@ typedef struct Item {
bool done:1;
} Item;
+typedef struct ItemArray {
+Item *items;
+size_t count;
+size_t size;
+} ItemArray;
+
static bool arg_create = false;
static bool arg_clean = false;
static bool arg_remove = false;
@@ -141,13 +148,40 @@ static bool needs_glob(ItemType t) {
RECURSIVE_RELABEL_PATH);
}
+static bool takes_ownership(ItemType t) {
+return IN_SET(t,
+ CREATE_FILE,
+ TRUNCATE_FILE,
+ CREATE_DIRECTORY,
+ TRUNCATE_DIRECTORY,
+ CREATE_SUBVOLUME,
+ CREATE_FIFO,
+ CREATE_SYMLINK,
+ CREATE_CHAR_DEVICE,
+ CREATE_BLOCK_DEVICE,
+ COPY_FILES,
+
+ WRITE_FILE,
+ IGNORE_PATH,
+ IGNORE_DIRECTORY_PATH,
+ REMOVE_PATH,
+ RECURSIVE_REMOVE_PATH);
+}
+
static struct Item* find_glob(Hashmap *h, const char *match) {
-Item *j;
+ItemArray *j;
Iterator i;
-HASHMAP_FOREACH(j, h, i)
-if (fnmatch(j-path, match, FNM_PATHNAME|FNM_PERIOD) == 0)
-return j;
+HASHMAP_FOREACH(j, h, i) {
+unsigned n;
+
+for (n = 0; n j-count; n++) {
+Item *item = j-items + n;
+
+if (fnmatch(item-path, match,
FNM_PATHNAME|FNM_PERIOD) == 0)
+return item;
+}
+}
return NULL;
}
@@ -604,10 +638,6 @@ static int write_one_file(Item *i, const char *path) {
if (r 0)
return r;
-r = item_set_xattrs(i, i-path);
-if (r 0)
-return r;
-
return 0;
}
@@ -790,10 +820,6 @@ static int create_item(Item *i) {
if (r 0)
return r;
-r = item_set_xattrs(i, i-path);
-if (r 0)
-return r;
-
break;
case CREATE_FIFO:
@@ -834,10 +860,6 @@ static int create_item(Item *i) {
if (r 0)
return r;
-r = item_set_xattrs(i, i-path);
-if (r 0)
-return r;
-
break;
case CREATE_SYMLINK:
@@ -869,10 +891,6 @@ static int create_item(Item *i) {
}
}
-r = item_set_xattrs(i, i-path);
-if (r 0)
- return r;
-
break;
case CREATE_BLOCK_DEVICE:
@@ -933,10