chiark / gitweb /
tmpfiles: don't warn if two identical lines are configured
authorLennart Poettering <lennart@poettering.net>
Fri, 8 Apr 2011 02:49:43 +0000 (04:49 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 9 Apr 2011 23:27:19 +0000 (01:27 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=690253

TODO
src/tmpfiles.c

diff --git a/TODO b/TODO
index 7c5fe6354b3473326b2d119ef48068cb9455eb15..78ceddebbccd34edfa9ac1969496fc97cd5a670a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -21,8 +21,6 @@ F15:
 * 0595f9a1c182a84581749823ef47c5f292e545f9 is borked, freezes shutdown
     (path: after installing inotify watches, recheck file again to fix race)
 
-* active_enter timestamps borked?
-
 Features:
 
 * fix alsa mixer restore to not print error when no config is stored
index b21df95a7350292ba5d6b3614eb65778bc9b3f1e..2526d1e915d1aace1598a4238c3251124e75d56c 100644 (file)
@@ -623,9 +623,39 @@ static void item_free(Item *i) {
         free(i);
 }
 
+static bool item_equal(Item *a, Item *b) {
+        assert(a);
+        assert(b);
+
+        if (!streq_ptr(a->path, b->path))
+                return false;
+
+        if (a->type != b->type)
+                return false;
+
+        if (a->uid_set != b->uid_set ||
+            (a->uid_set && a->uid != b->uid))
+            return false;
+
+        if (a->gid_set != b->gid_set ||
+            (a->gid_set && a->gid != b->gid))
+            return false;
+
+        if (a->mode_set != b->mode_set ||
+            (a->mode_set && a->mode != b->mode))
+            return false;
+
+        if (a->age_set != b->age_set ||
+            (a->age_set && a->age != b->age))
+            return false;
+
+        return true;
+}
+
 static int parse_line(const char *fname, unsigned line, const char *buffer) {
-        Item *i;
+        Item *i, *existing;
         char *mode = NULL, *user = NULL, *group = NULL, *age = NULL;
+        Hashmap *h;
         int r;
 
         assert(fname);
@@ -742,13 +772,19 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
                 i->age_set = true;
         }
 
-        if ((r = hashmap_put(needs_glob(i->type) ? globs : items, i->path, i)) < 0) {
-                if (r == -EEXIST) {
+        h = needs_glob(i->type) ? globs : items;
+
+        if ((existing = hashmap_get(h, i->path))) {
+
+                /* Two identical items are fine */
+                if (!item_equal(existing, i))
                         log_warning("Two or more conflicting lines for %s configured, ignoring.", i->path);
-                        r = 0;
-                        goto finish;
-                }
 
+                r = 0;
+                goto finish;
+        }
+
+        if ((r = hashmap_put(h, i->path, i)) < 0) {
                 log_error("Failed to insert item %s: %s", i->path, strerror(-r));
                 goto finish;
         }