Index: trunk/psModules/src/config/pmConfig.c
===================================================================
--- trunk/psModules/src/config/pmConfig.c	(revision 20345)
+++ trunk/psModules/src/config/pmConfig.c	(revision 20480)
@@ -1351,29 +1351,44 @@
     psMetadataItem *rulesItem = NULL;   // Item from iteration
     while ((rulesItem = psMetadataGetAndIncrement(rulesIter))) {
-        // this will insert each of the MULTI entries, writing over the previous copies
-        if (PS_DATA_IS_PRIMITIVE (rulesItem->type) || (rulesItem->type == PS_DATA_STRING)) {
-            psMetadataItem *newItem = psMetadataItemCopy(rulesItem); // Copy of item
-            psMetadataAddItem(header, newItem, PS_LIST_TAIL, PS_META_REPLACE);
-            psFree(newItem);                // Drop reference
-            continue;
-        }
-
-        # if (0) // XXX not needed
-        // for MULTI entries, supply the first one
-        if (rulesItem->type == PS_DATA_METADATA_MULTI) {
-            psMetadataItem *entry = psListGet (rulesItem->data.list, PS_LIST_HEAD);
-            if (!entry) {
-                psError(PS_ERR_UNKNOWN, true, "No entries for MULTI RULE item.");
-                return false;
-            }
-            psMetadataItem *newItem = psMetadataItemCopy(entry); // Copy of item
-            psMetadataAddItem(header, newItem, PS_LIST_TAIL, PS_META_REPLACE);
-            psFree(newItem);                // Drop reference
-            continue;
-        }
-        # endif
-
-        psError(PS_ERR_UNKNOWN, false, "Invalid type for RULE %s.", rulesItem->name);
-        return false;
+        if (!PS_DATA_IS_PRIMITIVE(rulesItem->type) && rulesItem->type != PS_DATA_STRING) {
+            psError(PS_ERR_UNKNOWN, false, "Invalid type for RULE %s.", rulesItem->name);
+            return false;
+        }
+
+        psMetadataItem *hdrItem = psMetadataLookup(header, rulesItem->name); // Item from header
+        if (hdrItem && psMetadataItemCompare(hdrItem, rulesItem)) {
+            // It's already there and matches
+            break;
+        }
+
+        // Look for an operation
+        psMetadataItemCompareOp op = psMetadataItemCompareOperation(rulesItem);
+        switch (op) {
+          case PS_METADATA_ITEM_COMPARE_OP_NONE:
+          case PS_METADATA_ITEM_COMPARE_OP_EQ:
+          case PS_METADATA_ITEM_COMPARE_OP_LE:
+          case PS_METADATA_ITEM_COMPARE_OP_GE: {
+              // A comparison involving equality: add the value
+              psMetadataItem *newItem = psMetadataItemCopy(rulesItem); // Copy of item
+              if (op == PS_METADATA_ITEM_COMPARE_OP_LE || op == PS_METADATA_ITEM_COMPARE_OP_GE) {
+                  // Not clear what the value is supposed to be, so add a warning as well
+                  psFree(newItem->comment);
+                  newItem->comment = psStringCopy("MAY BE WRONG: added to match format rule");
+              }
+              psMetadataAddItem(header, newItem, PS_LIST_TAIL, PS_META_REPLACE);
+              psFree(newItem);                // Drop reference
+              break;
+          }
+          case PS_METADATA_ITEM_COMPARE_OP_LT:
+          case PS_METADATA_ITEM_COMPARE_OP_GT:
+          case PS_METADATA_ITEM_COMPARE_OP_NE:
+            // It's not at all obvious what the value should be, so return an error.
+            psError(PS_ERR_IO, true,
+                    "RULE %s (defined by an OPeration) is not present or not consistent in output header",
+                    rulesItem->name);
+            return false;
+          default:
+            psAbort("Unknown operation: %x", op);
+        }
     }
     psFree(rulesIter);
@@ -1722,14 +1737,14 @@
     // re-try access up to 5 times (1.25sec) to reduce NFS lurches
     for (int i = 0; i < 5; i++) {
-	if (access(filename, R_OK) == 0) {
-	    // file already exists
-	    if (trunc) {
-		if(truncate(filename, 0) != 0) {
-		    psError(PS_ERR_IO, true, "Failed to truncate file, %s\n", filename);
-		    return false;
-		}
-	    }
-	    return true;
-	} 
+        if (access(filename, R_OK) == 0) {
+            // file already exists
+            if (trunc) {
+                if(truncate(filename, 0) != 0) {
+                    psError(PS_ERR_IO, true, "Failed to truncate file, %s\n", filename);
+                    return false;
+                }
+            }
+            return true;
+        }
 
         // file does not exist
@@ -1744,7 +1759,7 @@
                 return false;
             }
-	    return true;
-        }
-	usleep (250000);
+            return true;
+        }
+        usleep (250000);
     }
 
