summaryrefslogtreecommitdiff
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-26 21:19:36 +0200
committerLennart Poettering <lennart@poettering.net>2018-11-08 09:52:16 +0100
commit64adb37968748d6708e209919a6c1e176a9dd81b (patch)
tree65c798f597b7e48538a56c522d1a1fe61741fed1 /src/tmpfiles
parent21af33863fcfc9f3699d12ce4c65ee52807fefe8 (diff)
downloadsystemd-64adb37968748d6708e209919a6c1e176a9dd81b.tar.gz
tmpfiles: always remove/clean-up before creating
Let's always clean the platform before we build something new. Fixes: #9508
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/tmpfiles.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index af8c12e06e..ce9146c1d1 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -3162,11 +3162,11 @@ static int link_parent(ItemArray *a) {
}
int main(int argc, char *argv[]) {
- int r, k, r_process = 0;
- ItemArray *a;
- Iterator iterator;
_cleanup_strv_free_ char **config_dirs = NULL;
+ int r, k, r_process = 0, phase;
bool invalid_config = false;
+ Iterator iterator;
+ ItemArray *a;
r = parse_argv(argc, argv);
if (r <= 0)
@@ -3242,20 +3242,34 @@ int main(int argc, char *argv[]) {
goto finish;
}
- /* The non-globbing ones usually create things, hence we apply
- * them first */
- ORDERED_HASHMAP_FOREACH(a, items, iterator) {
- k = process_item_array(a, arg_operation);
- if (k < 0 && r_process == 0)
- r_process = k;
- }
+ /* If multiple operations are requested, let's first run the remove/clean operations, and only then the create
+ * operations. i.e. that we first clean out the platform we then build on. */
+ for (phase = 0; phase < 2; phase++) {
+ OperationMask op;
- /* The globbing ones usually alter things, hence we apply them
- * second. */
- ORDERED_HASHMAP_FOREACH(a, globs, iterator) {
- k = process_item_array(a, arg_operation);
- if (k < 0 && r_process == 0)
- r_process = k;
+ if (phase == 0)
+ op = arg_operation & (OPERATION_REMOVE|OPERATION_CLEAN);
+ else if (phase == 1)
+ op = arg_operation & OPERATION_CREATE;
+ else
+ assert_not_reached("unexpected phase");
+
+ if (op == 0) /* Nothing requested in this phase */
+ continue;
+
+ /* The non-globbing ones usually create things, hence we apply them first */
+ ORDERED_HASHMAP_FOREACH(a, items, iterator) {
+ k = process_item_array(a, op);
+ if (k < 0 && r_process == 0)
+ r_process = k;
+ }
+
+ /* The globbing ones usually alter things, hence we apply them second. */
+ ORDERED_HASHMAP_FOREACH(a, globs, iterator) {
+ k = process_item_array(a, op);
+ if (k < 0 && r_process == 0)
+ r_process = k;
+ }
}
finish: