Blame SOURCES/Merge-duplicate-subsections-in-profile-library.patch

d738b9
From a19917522862f26bc711fd8271940906284ff55d Mon Sep 17 00:00:00 2001
d738b9
From: Robbie Harwood <rharwood@redhat.com>
d738b9
Date: Tue, 10 Apr 2018 15:55:41 -0400
d738b9
Subject: [PATCH] Merge duplicate subsections in profile library
d738b9
d738b9
Modify profile_add_node() to return the existing node, rather than
d738b9
making a new one, when adding subsection configuration.
d738b9
d738b9
This fixes an issue where the first instance of a subsection will hide
d738b9
the second instance entirely.  In particular, it was previously
d738b9
impossible to split realm-specific configuration across multiple
d738b9
config files.
d738b9
d738b9
[ghudson@mit.edu: adjusted style, added test case]
d738b9
d738b9
(cherry picked from commit efab9fa5a6d23c486467264e20b58bf5a9c60f0c)
d738b9
d738b9
ticket: 7863
d738b9
version_fixed: 1.16.1
d738b9
d738b9
(cherry picked from commit 98d0061c8083af960438ad1ac088f60497694a68)
d738b9
---
d738b9
 src/util/profile/prof_test1  | 22 ++++++++++++++++++++++
d738b9
 src/util/profile/prof_tree.c | 15 +++++++++++----
d738b9
 src/util/profile/test.ini    |  6 ++++++
d738b9
 3 files changed, 39 insertions(+), 4 deletions(-)
d738b9
d738b9
diff --git a/src/util/profile/prof_test1 b/src/util/profile/prof_test1
d738b9
index 7e30fc12f..7d13c9389 100644
d738b9
--- a/src/util/profile/prof_test1
d738b9
+++ b/src/util/profile/prof_test1
d738b9
@@ -341,6 +341,27 @@ proc test9 {} {
d738b9
     puts "OK: test9: profile_flush_to_file with no changes"
d738b9
 }
d738b9
 
d738b9
+proc test10 {} {
d738b9
+    global wd verbose
d738b9
+
d738b9
+    # Regression test for #7863: multiply-specified subsections should
d738b9
+    # be merged.
d738b9
+    set p [profile_init_path $wd/test2.ini]
d738b9
+    set x [profile_get_values $p {{test section 2} child_section2 child}]
d738b9
+    if $verbose { puts "Read $x from profile" }
d738b9
+    if ![string equal $x "slick harry {john\tb } ron"] {
d738b9
+	puts stderr "Error: test10: Did not get expected merged children."
d738b9
+	exit 1
d738b9
+    }
d738b9
+
d738b9
+    set x [profile_get_string $p {test section 2} child_section2 chores]
d738b9
+    if $verbose { puts "Read $x from profile" }
d738b9
+    if ![string equal $x "cleaning"] {
d738b9
+	puts stderr "Error: test10: Did not find expected chores."
d738b9
+	exit 1
d738b9
+    }
d738b9
+}
d738b9
+
d738b9
 test1
d738b9
 test2
d738b9
 test3
d738b9
@@ -350,5 +371,6 @@ test6
d738b9
 test7
d738b9
 test8
d738b9
 test9
d738b9
+test10
d738b9
 
d738b9
 exit 0
d738b9
diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c
d738b9
index 081f688e4..38aadc4e5 100644
d738b9
--- a/src/util/profile/prof_tree.c
d738b9
+++ b/src/util/profile/prof_tree.c
d738b9
@@ -9,7 +9,7 @@
d738b9
  *
d738b9
  * Each node may represent either a relation or a section header.
d738b9
  *
d738b9
- * A section header must have its value field set to 0, and may a one
d738b9
+ * A section header must have its value field be null, and may have one
d738b9
  * or more child nodes, pointed to by first_child.
d738b9
  *
d738b9
  * A relation has as its value a pointer to allocated memory
d738b9
@@ -159,15 +159,22 @@ errcode_t profile_add_node(struct profile_node *section, const char *name,
d738b9
         return PROF_ADD_NOT_SECTION;
d738b9
 
d738b9
     /*
d738b9
-     * Find the place to insert the new node.  We look for the
d738b9
-     * place *after* the last match of the node name, since
d738b9
+     * Find the place to insert the new node.  If we are adding a subsection
d738b9
+     * and already have a subsection with that name, merge them.  Otherwise,
d738b9
+     * we look for the place *after* the last match of the node name, since
d738b9
      * order matters.
d738b9
      */
d738b9
     for (p=section->first_child, last = 0; p; last = p, p = p->next) {
d738b9
         int cmp;
d738b9
         cmp = strcmp(p->name, name);
d738b9
-        if (cmp > 0)
d738b9
+        if (cmp > 0) {
d738b9
             break;
d738b9
+        } else if (value == NULL && cmp == 0 &&
d738b9
+                   p->value == NULL && p->deleted != 1) {
d738b9
+            /* Found duplicate subsection, so don't make a new one. */
d738b9
+            *ret_node = p;
d738b9
+            return 0;
d738b9
+        }
d738b9
     }
d738b9
     retval = profile_create_node(name, value, &new;;
d738b9
     if (retval)
d738b9
diff --git a/src/util/profile/test.ini b/src/util/profile/test.ini
d738b9
index 23ca89677..6622df108 100644
d738b9
--- a/src/util/profile/test.ini
d738b9
+++ b/src/util/profile/test.ini
d738b9
@@ -10,6 +10,12 @@ this is a comment.  Everything up to the first square brace is ignored.
d738b9
 	}
d738b9
 	child_section2 = foo
d738b9
 
d738b9
+[test section 2]
d738b9
+	child_section2 = {
d738b9
+		child = ron
d738b9
+		chores = cleaning
d738b9
+	}
d738b9
+
d738b9
 [realms]
d738b9
 ATHENA.MIT.EDU = {
d738b9
 	server = KERBEROS.MIT.EDU:88