diff --git a/cts/cli/regression.error_codes.exp b/cts/cli/regression.error_codes.exp
new file mode 100644
index 0000000000..6ad402aff0
--- /dev/null
+++ b/cts/cli/regression.error_codes.exp
@@ -0,0 +1,532 @@
+=#=#=#= Begin test: Get legacy return code =#=#=#=
+Error
+=#=#=#= End test: Get legacy return code - OK (0) =#=#=#=
+* Passed: crm_error      - Get legacy return code
+=#=#=#= Begin test: Get legacy return code (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error --output-as=xml -- 201">
+  <result-code code="201" description="Error"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get legacy return code (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get legacy return code (XML)
+=#=#=#= Begin test: Get legacy return code (with name) =#=#=#=
+pcmk_err_generic - Error
+=#=#=#= End test: Get legacy return code (with name) - OK (0) =#=#=#=
+* Passed: crm_error      - Get legacy return code (with name)
+=#=#=#= Begin test: Get legacy return code (with name) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -n --output-as=xml -- 201">
+  <result-code code="201" name="pcmk_err_generic" description="Error"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get legacy return code (with name) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get legacy return code (with name) (XML)
+=#=#=#= Begin test: Get multiple legacy return codes =#=#=#=
+Error
+Operation requires quorum
+=#=#=#= End test: Get multiple legacy return codes - OK (0) =#=#=#=
+* Passed: crm_error      - Get multiple legacy return codes
+=#=#=#= Begin test: Get multiple legacy return codes (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error --output-as=xml -- 201 202">
+  <result-code code="201" description="Error"/>
+  <result-code code="202" description="Operation requires quorum"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get multiple legacy return codes (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get multiple legacy return codes (XML)
+=#=#=#= Begin test: Get multiple legacy return codes (with names) =#=#=#=
+pcmk_err_generic - Error
+pcmk_err_no_quorum - Operation requires quorum
+=#=#=#= End test: Get multiple legacy return codes (with names) - OK (0) =#=#=#=
+* Passed: crm_error      - Get multiple legacy return codes (with names)
+=#=#=#= Begin test: Get multiple legacy return codes (with names) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -n --output-as=xml -- 201 202">
+  <result-code code="201" name="pcmk_err_generic" description="Error"/>
+  <result-code code="202" name="pcmk_err_no_quorum" description="Operation requires quorum"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get multiple legacy return codes (with names) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get multiple legacy return codes (with names) (XML)
+=#=#=#= Begin test: List legacy return codes (spot check) =#=#=#=
+  201: Error
+  202: Operation requires quorum
+  203: Update does not conform to the configured schema
+  204: Schema transform failed
+  205: Update was older than existing configuration
+  206: Application of update diff failed
+  207: Application of update diff failed, requesting full refresh
+  208: On-disk configuration was manually modified
+  209: Could not archive previous configuration
+=#=#=#= End test: List legacy return codes (spot check) - OK (0) =#=#=#=
+* Passed: crm_error      - List legacy return codes (spot check)
+=#=#=#= Begin test: List legacy return codes (spot check) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -l --output-as=xml">
+  <result-code code="201" description="Error"/>
+  <result-code code="202" description="Operation requires quorum"/>
+  <result-code code="203" description="Update does not conform to the configured schema"/>
+  <result-code code="204" description="Schema transform failed"/>
+  <result-code code="205" description="Update was older than existing configuration"/>
+  <result-code code="206" description="Application of update diff failed"/>
+  <result-code code="207" description="Application of update diff failed, requesting full refresh"/>
+  <result-code code="208" description="On-disk configuration was manually modified"/>
+  <result-code code="209" description="Could not archive previous configuration"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: List legacy return codes (spot check) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - List legacy return codes (spot check) (XML)
+=#=#=#= Begin test: List legacy return codes (spot check) (with names) =#=#=#=
+  201: pcmk_err_generic            Error
+  202: pcmk_err_no_quorum          Operation requires quorum
+  203: pcmk_err_schema_validation  Update does not conform to the configured schema
+  204: pcmk_err_transform_failed   Schema transform failed
+  205: pcmk_err_old_data           Update was older than existing configuration
+  206: pcmk_err_diff_failed        Application of update diff failed
+  207: pcmk_err_diff_resync        Application of update diff failed, requesting full refresh
+  208: pcmk_err_cib_modified       On-disk configuration was manually modified
+  209: pcmk_err_cib_backup         Could not archive previous configuration
+=#=#=#= End test: List legacy return codes (spot check) (with names) - OK (0) =#=#=#=
+* Passed: crm_error      - List legacy return codes (spot check) (with names)
+=#=#=#= Begin test: List legacy return codes (spot check) (with names) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -n -l --output-as=xml">
+  <result-code code="201" name="pcmk_err_generic" description="Error"/>
+  <result-code code="202" name="pcmk_err_no_quorum" description="Operation requires quorum"/>
+  <result-code code="203" name="pcmk_err_schema_validation" description="Update does not conform to the configured schema"/>
+  <result-code code="204" name="pcmk_err_transform_failed" description="Schema transform failed"/>
+  <result-code code="205" name="pcmk_err_old_data" description="Update was older than existing configuration"/>
+  <result-code code="206" name="pcmk_err_diff_failed" description="Application of update diff failed"/>
+  <result-code code="207" name="pcmk_err_diff_resync" description="Application of update diff failed, requesting full refresh"/>
+  <result-code code="208" name="pcmk_err_cib_modified" description="On-disk configuration was manually modified"/>
+  <result-code code="209" name="pcmk_err_cib_backup" description="Could not archive previous configuration"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: List legacy return codes (spot check) (with names) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - List legacy return codes (spot check) (with names) (XML)
+=#=#=#= Begin test: Get unknown Pacemaker return code =#=#=#=
+Error
+=#=#=#= End test: Get unknown Pacemaker return code - OK (0) =#=#=#=
+* Passed: crm_error      - Get unknown Pacemaker return code
+=#=#=#= Begin test: Get unknown Pacemaker return code (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -r --output-as=xml -- -10000">
+  <result-code code="-10000" description="Error"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get unknown Pacemaker return code (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get unknown Pacemaker return code (XML)
+=#=#=#= Begin test: Get unknown Pacemaker return code (with name) =#=#=#=
+Unknown - Error
+=#=#=#= End test: Get unknown Pacemaker return code (with name) - OK (0) =#=#=#=
+* Passed: crm_error      - Get unknown Pacemaker return code (with name)
+=#=#=#= Begin test: Get unknown Pacemaker return code (with name) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -n -r --output-as=xml -- -10000">
+  <result-code code="-10000" name="Unknown" description="Error"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get unknown Pacemaker return code (with name) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get unknown Pacemaker return code (with name) (XML)
+=#=#=#= Begin test: Get negative Pacemaker return code =#=#=#=
+Node not found
+=#=#=#= End test: Get negative Pacemaker return code - OK (0) =#=#=#=
+* Passed: crm_error      - Get negative Pacemaker return code
+=#=#=#= Begin test: Get negative Pacemaker return code (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -r --output-as=xml -- -1005">
+  <result-code code="-1005" description="Node not found"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get negative Pacemaker return code (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get negative Pacemaker return code (XML)
+=#=#=#= Begin test: Get negative Pacemaker return code (with name) =#=#=#=
+pcmk_rc_node_unknown - Node not found
+=#=#=#= End test: Get negative Pacemaker return code (with name) - OK (0) =#=#=#=
+* Passed: crm_error      - Get negative Pacemaker return code (with name)
+=#=#=#= Begin test: Get negative Pacemaker return code (with name) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -n -r --output-as=xml -- -1005">
+  <result-code code="-1005" name="pcmk_rc_node_unknown" description="Node not found"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get negative Pacemaker return code (with name) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get negative Pacemaker return code (with name) (XML)
+=#=#=#= Begin test: List Pacemaker return codes (non-positive) =#=#=#=
+-1033: Two or more XML elements have the same ID
+-1032: Unable to parse CIB XML
+-1031: Cluster simulation produced invalid transition
+-1030: Error writing graph file
+-1029: Error writing dot(1) file
+-1028: Value too small to be stored in data type
+-1027: Input file not available
+-1026: Output message produced no output
+-1025: Result occurs after given range
+-1024: Result occurs within given range
+-1023: Result occurs before given range
+-1022: Result undetermined
+-1021: Not applicable under current conditions
+-1020: IPC server process is active but not accepting connections
+-1019: IPC server is unresponsive
+-1018: IPC server is blocked by unauthorized process
+-1017: Operation requires quorum
+-1016: Update does not conform to the configured schema
+-1015: Schema is already the latest available
+-1014: Schema transform failed
+-1013: Update was older than existing configuration
+-1012: Application of update diff failed
+-1011: Application of update diff failed, requesting full refresh
+-1010: On-disk configuration was manually modified
+-1009: Could not archive previous configuration
+-1008: Could not save new configuration to disk
+-1007: Could not parse on-disk configuration
+-1006: Resource active on multiple nodes
+-1005: Node not found
+-1004: Already in requested state
+-1003: Bad name/value pair given
+-1002: Unknown output format
+-1001: Error
+    0: OK
+=#=#=#= End test: List Pacemaker return codes (non-positive) - OK (0) =#=#=#=
+* Passed: crm_error      - List Pacemaker return codes (non-positive)
+=#=#=#= Begin test: List Pacemaker return codes (non-positive) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -l -r --output-as=xml">
+  <result-code code="-1033" description="Two or more XML elements have the same ID"/>
+  <result-code code="-1032" description="Unable to parse CIB XML"/>
+  <result-code code="-1031" description="Cluster simulation produced invalid transition"/>
+  <result-code code="-1030" description="Error writing graph file"/>
+  <result-code code="-1029" description="Error writing dot(1) file"/>
+  <result-code code="-1028" description="Value too small to be stored in data type"/>
+  <result-code code="-1027" description="Input file not available"/>
+  <result-code code="-1026" description="Output message produced no output"/>
+  <result-code code="-1025" description="Result occurs after given range"/>
+  <result-code code="-1024" description="Result occurs within given range"/>
+  <result-code code="-1023" description="Result occurs before given range"/>
+  <result-code code="-1022" description="Result undetermined"/>
+  <result-code code="-1021" description="Not applicable under current conditions"/>
+  <result-code code="-1020" description="IPC server process is active but not accepting connections"/>
+  <result-code code="-1019" description="IPC server is unresponsive"/>
+  <result-code code="-1018" description="IPC server is blocked by unauthorized process"/>
+  <result-code code="-1017" description="Operation requires quorum"/>
+  <result-code code="-1016" description="Update does not conform to the configured schema"/>
+  <result-code code="-1015" description="Schema is already the latest available"/>
+  <result-code code="-1014" description="Schema transform failed"/>
+  <result-code code="-1013" description="Update was older than existing configuration"/>
+  <result-code code="-1012" description="Application of update diff failed"/>
+  <result-code code="-1011" description="Application of update diff failed, requesting full refresh"/>
+  <result-code code="-1010" description="On-disk configuration was manually modified"/>
+  <result-code code="-1009" description="Could not archive previous configuration"/>
+  <result-code code="-1008" description="Could not save new configuration to disk"/>
+  <result-code code="-1007" description="Could not parse on-disk configuration"/>
+  <result-code code="-1006" description="Resource active on multiple nodes"/>
+  <result-code code="-1005" description="Node not found"/>
+  <result-code code="-1004" description="Already in requested state"/>
+  <result-code code="-1003" description="Bad name/value pair given"/>
+  <result-code code="-1002" description="Unknown output format"/>
+  <result-code code="-1001" description="Error"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: List Pacemaker return codes (non-positive) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - List Pacemaker return codes (non-positive) (XML)
+=#=#=#= Begin test: List Pacemaker return codes (non-positive) (with names) =#=#=#=
+-1033: pcmk_rc_duplicate_id        Two or more XML elements have the same ID
+-1032: pcmk_rc_unpack_error        Unable to parse CIB XML
+-1031: pcmk_rc_invalid_transition  Cluster simulation produced invalid transition
+-1030: pcmk_rc_graph_error         Error writing graph file
+-1029: pcmk_rc_dot_error           Error writing dot(1) file
+-1028: pcmk_rc_underflow           Value too small to be stored in data type
+-1027: pcmk_rc_no_input            Input file not available
+-1026: pcmk_rc_no_output           Output message produced no output
+-1025: pcmk_rc_after_range         Result occurs after given range
+-1024: pcmk_rc_within_range        Result occurs within given range
+-1023: pcmk_rc_before_range        Result occurs before given range
+-1022: pcmk_rc_undetermined        Result undetermined
+-1021: pcmk_rc_op_unsatisfied      Not applicable under current conditions
+-1020: pcmk_rc_ipc_pid_only        IPC server process is active but not accepting connections
+-1019: pcmk_rc_ipc_unresponsive    IPC server is unresponsive
+-1018: pcmk_rc_ipc_unauthorized    IPC server is blocked by unauthorized process
+-1017: pcmk_rc_no_quorum           Operation requires quorum
+-1016: pcmk_rc_schema_validation   Update does not conform to the configured schema
+-1015: pcmk_rc_schema_unchanged    Schema is already the latest available
+-1014: pcmk_rc_transform_failed    Schema transform failed
+-1013: pcmk_rc_old_data            Update was older than existing configuration
+-1012: pcmk_rc_diff_failed         Application of update diff failed
+-1011: pcmk_rc_diff_resync         Application of update diff failed, requesting full refresh
+-1010: pcmk_rc_cib_modified        On-disk configuration was manually modified
+-1009: pcmk_rc_cib_backup          Could not archive previous configuration
+-1008: pcmk_rc_cib_save            Could not save new configuration to disk
+-1007: pcmk_rc_cib_corrupt         Could not parse on-disk configuration
+-1006: pcmk_rc_multiple            Resource active on multiple nodes
+-1005: pcmk_rc_node_unknown        Node not found
+-1004: pcmk_rc_already             Already in requested state
+-1003: pcmk_rc_bad_nvpair          Bad name/value pair given
+-1002: pcmk_rc_unknown_format      Unknown output format
+-1001: pcmk_rc_error               Error
+    0: pcmk_rc_ok                  OK
+=#=#=#= End test: List Pacemaker return codes (non-positive) (with names) - OK (0) =#=#=#=
+* Passed: crm_error      - List Pacemaker return codes (non-positive) (with names)
+=#=#=#= Begin test: List Pacemaker return codes (non-positive) (with names) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -n -l -r --output-as=xml">
+  <result-code code="-1033" name="pcmk_rc_duplicate_id" description="Two or more XML elements have the same ID"/>
+  <result-code code="-1032" name="pcmk_rc_unpack_error" description="Unable to parse CIB XML"/>
+  <result-code code="-1031" name="pcmk_rc_invalid_transition" description="Cluster simulation produced invalid transition"/>
+  <result-code code="-1030" name="pcmk_rc_graph_error" description="Error writing graph file"/>
+  <result-code code="-1029" name="pcmk_rc_dot_error" description="Error writing dot(1) file"/>
+  <result-code code="-1028" name="pcmk_rc_underflow" description="Value too small to be stored in data type"/>
+  <result-code code="-1027" name="pcmk_rc_no_input" description="Input file not available"/>
+  <result-code code="-1026" name="pcmk_rc_no_output" description="Output message produced no output"/>
+  <result-code code="-1025" name="pcmk_rc_after_range" description="Result occurs after given range"/>
+  <result-code code="-1024" name="pcmk_rc_within_range" description="Result occurs within given range"/>
+  <result-code code="-1023" name="pcmk_rc_before_range" description="Result occurs before given range"/>
+  <result-code code="-1022" name="pcmk_rc_undetermined" description="Result undetermined"/>
+  <result-code code="-1021" name="pcmk_rc_op_unsatisfied" description="Not applicable under current conditions"/>
+  <result-code code="-1020" name="pcmk_rc_ipc_pid_only" description="IPC server process is active but not accepting connections"/>
+  <result-code code="-1019" name="pcmk_rc_ipc_unresponsive" description="IPC server is unresponsive"/>
+  <result-code code="-1018" name="pcmk_rc_ipc_unauthorized" description="IPC server is blocked by unauthorized process"/>
+  <result-code code="-1017" name="pcmk_rc_no_quorum" description="Operation requires quorum"/>
+  <result-code code="-1016" name="pcmk_rc_schema_validation" description="Update does not conform to the configured schema"/>
+  <result-code code="-1015" name="pcmk_rc_schema_unchanged" description="Schema is already the latest available"/>
+  <result-code code="-1014" name="pcmk_rc_transform_failed" description="Schema transform failed"/>
+  <result-code code="-1013" name="pcmk_rc_old_data" description="Update was older than existing configuration"/>
+  <result-code code="-1012" name="pcmk_rc_diff_failed" description="Application of update diff failed"/>
+  <result-code code="-1011" name="pcmk_rc_diff_resync" description="Application of update diff failed, requesting full refresh"/>
+  <result-code code="-1010" name="pcmk_rc_cib_modified" description="On-disk configuration was manually modified"/>
+  <result-code code="-1009" name="pcmk_rc_cib_backup" description="Could not archive previous configuration"/>
+  <result-code code="-1008" name="pcmk_rc_cib_save" description="Could not save new configuration to disk"/>
+  <result-code code="-1007" name="pcmk_rc_cib_corrupt" description="Could not parse on-disk configuration"/>
+  <result-code code="-1006" name="pcmk_rc_multiple" description="Resource active on multiple nodes"/>
+  <result-code code="-1005" name="pcmk_rc_node_unknown" description="Node not found"/>
+  <result-code code="-1004" name="pcmk_rc_already" description="Already in requested state"/>
+  <result-code code="-1003" name="pcmk_rc_bad_nvpair" description="Bad name/value pair given"/>
+  <result-code code="-1002" name="pcmk_rc_unknown_format" description="Unknown output format"/>
+  <result-code code="-1001" name="pcmk_rc_error" description="Error"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: List Pacemaker return codes (non-positive) (with names) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - List Pacemaker return codes (non-positive) (with names) (XML)
+=#=#=#= Begin test: Get unknown crm_exit_t exit code =#=#=#=
+Unknown exit status
+=#=#=#= End test: Get unknown crm_exit_t exit code - OK (0) =#=#=#=
+* Passed: crm_error      - Get unknown crm_exit_t exit code
+=#=#=#= Begin test: Get unknown crm_exit_t exit code (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -X --output-as=xml -- -10000">
+  <result-code code="-10000" description="Unknown exit status"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get unknown crm_exit_t exit code (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get unknown crm_exit_t exit code (XML)
+=#=#=#= Begin test: Get unknown crm_exit_t exit code (with name) =#=#=#=
+CRM_EX_UNKNOWN - Unknown exit status
+=#=#=#= End test: Get unknown crm_exit_t exit code (with name) - OK (0) =#=#=#=
+* Passed: crm_error      - Get unknown crm_exit_t exit code (with name)
+=#=#=#= Begin test: Get unknown crm_exit_t exit code (with name) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -n -X --output-as=xml -- -10000">
+  <result-code code="-10000" name="CRM_EX_UNKNOWN" description="Unknown exit status"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get unknown crm_exit_t exit code (with name) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get unknown crm_exit_t exit code (with name) (XML)
+=#=#=#= Begin test: Get crm_exit_t exit code =#=#=#=
+Error occurred
+=#=#=#= End test: Get crm_exit_t exit code - OK (0) =#=#=#=
+* Passed: crm_error      - Get crm_exit_t exit code
+=#=#=#= Begin test: Get crm_exit_t exit code (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -X --output-as=xml -- 1">
+  <result-code code="1" description="Error occurred"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get crm_exit_t exit code (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get crm_exit_t exit code (XML)
+=#=#=#= Begin test: Get crm_exit_t exit code (with name) =#=#=#=
+CRM_EX_ERROR - Error occurred
+=#=#=#= End test: Get crm_exit_t exit code (with name) - OK (0) =#=#=#=
+* Passed: crm_error      - Get crm_exit_t exit code (with name)
+=#=#=#= Begin test: Get crm_exit_t exit code (with name) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -n -X --output-as=xml -- 1">
+  <result-code code="1" name="CRM_EX_ERROR" description="Error occurred"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get crm_exit_t exit code (with name) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get crm_exit_t exit code (with name) (XML)
+=#=#=#= Begin test: Get all crm_exit_t exit codes =#=#=#=
+    0: OK
+    1: Error occurred
+    2: Invalid parameter
+    3: Unimplemented
+    4: Insufficient privileges
+    5: Not installed
+    6: Not configured
+    7: Not running
+    8: Promoted
+    9: Failed in promoted role
+   64: Incorrect usage
+   65: Invalid data given
+   66: Input file not available
+   67: User does not exist
+   68: Host does not exist
+   69: Necessary service unavailable
+   70: Internal software bug
+   71: Operating system error occurred
+   72: System file not available
+   73: Cannot create output file
+   74: I/O error occurred
+   75: Temporary failure, try again
+   76: Protocol violated
+   77: Insufficient privileges
+   78: Invalid configuration
+  100: Fatal error occurred, will not respawn
+  101: System panic required
+  102: Not connected
+  103: Update was older than existing configuration
+  104: Digest mismatch
+  105: No such object
+  106: Quorum required
+  107: Operation not safe
+  108: Requested item already exists
+  109: Multiple items match request
+  110: Requested item has expired
+  111: Requested item is not yet in effect
+  112: Could not determine status
+  113: Not applicable under current conditions
+  124: Timeout occurred
+  190: Service is active but might fail soon
+  191: Service is promoted but might fail soon
+  193: No exit status available
+=#=#=#= End test: Get all crm_exit_t exit codes - OK (0) =#=#=#=
+* Passed: crm_error      - Get all crm_exit_t exit codes
+=#=#=#= Begin test: Get all crm_exit_t exit codes (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -l -X --output-as=xml">
+  <result-code code="0" description="OK"/>
+  <result-code code="1" description="Error occurred"/>
+  <result-code code="2" description="Invalid parameter"/>
+  <result-code code="3" description="Unimplemented"/>
+  <result-code code="4" description="Insufficient privileges"/>
+  <result-code code="5" description="Not installed"/>
+  <result-code code="6" description="Not configured"/>
+  <result-code code="7" description="Not running"/>
+  <result-code code="8" description="Promoted"/>
+  <result-code code="9" description="Failed in promoted role"/>
+  <result-code code="64" description="Incorrect usage"/>
+  <result-code code="65" description="Invalid data given"/>
+  <result-code code="66" description="Input file not available"/>
+  <result-code code="67" description="User does not exist"/>
+  <result-code code="68" description="Host does not exist"/>
+  <result-code code="69" description="Necessary service unavailable"/>
+  <result-code code="70" description="Internal software bug"/>
+  <result-code code="71" description="Operating system error occurred"/>
+  <result-code code="72" description="System file not available"/>
+  <result-code code="73" description="Cannot create output file"/>
+  <result-code code="74" description="I/O error occurred"/>
+  <result-code code="75" description="Temporary failure, try again"/>
+  <result-code code="76" description="Protocol violated"/>
+  <result-code code="77" description="Insufficient privileges"/>
+  <result-code code="78" description="Invalid configuration"/>
+  <result-code code="100" description="Fatal error occurred, will not respawn"/>
+  <result-code code="101" description="System panic required"/>
+  <result-code code="102" description="Not connected"/>
+  <result-code code="103" description="Update was older than existing configuration"/>
+  <result-code code="104" description="Digest mismatch"/>
+  <result-code code="105" description="No such object"/>
+  <result-code code="106" description="Quorum required"/>
+  <result-code code="107" description="Operation not safe"/>
+  <result-code code="108" description="Requested item already exists"/>
+  <result-code code="109" description="Multiple items match request"/>
+  <result-code code="110" description="Requested item has expired"/>
+  <result-code code="111" description="Requested item is not yet in effect"/>
+  <result-code code="112" description="Could not determine status"/>
+  <result-code code="113" description="Not applicable under current conditions"/>
+  <result-code code="124" description="Timeout occurred"/>
+  <result-code code="190" description="Service is active but might fail soon"/>
+  <result-code code="191" description="Service is promoted but might fail soon"/>
+  <result-code code="193" description="No exit status available"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get all crm_exit_t exit codes (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get all crm_exit_t exit codes (XML)
+=#=#=#= Begin test: Get all crm_exit_t exit codes (with name) =#=#=#=
+    0: CRM_EX_OK                   OK
+    1: CRM_EX_ERROR                Error occurred
+    2: CRM_EX_INVALID_PARAM        Invalid parameter
+    3: CRM_EX_UNIMPLEMENT_FEATURE  Unimplemented
+    4: CRM_EX_INSUFFICIENT_PRIV    Insufficient privileges
+    5: CRM_EX_NOT_INSTALLED        Not installed
+    6: CRM_EX_NOT_CONFIGURED       Not configured
+    7: CRM_EX_NOT_RUNNING          Not running
+    8: CRM_EX_PROMOTED             Promoted
+    9: CRM_EX_FAILED_PROMOTED      Failed in promoted role
+   64: CRM_EX_USAGE                Incorrect usage
+   65: CRM_EX_DATAERR              Invalid data given
+   66: CRM_EX_NOINPUT              Input file not available
+   67: CRM_EX_NOUSER               User does not exist
+   68: CRM_EX_NOHOST               Host does not exist
+   69: CRM_EX_UNAVAILABLE          Necessary service unavailable
+   70: CRM_EX_SOFTWARE             Internal software bug
+   71: CRM_EX_OSERR                Operating system error occurred
+   72: CRM_EX_OSFILE               System file not available
+   73: CRM_EX_CANTCREAT            Cannot create output file
+   74: CRM_EX_IOERR                I/O error occurred
+   75: CRM_EX_TEMPFAIL             Temporary failure, try again
+   76: CRM_EX_PROTOCOL             Protocol violated
+   77: CRM_EX_NOPERM               Insufficient privileges
+   78: CRM_EX_CONFIG               Invalid configuration
+  100: CRM_EX_FATAL                Fatal error occurred, will not respawn
+  101: CRM_EX_PANIC                System panic required
+  102: CRM_EX_DISCONNECT           Not connected
+  103: CRM_EX_OLD                  Update was older than existing configuration
+  104: CRM_EX_DIGEST               Digest mismatch
+  105: CRM_EX_NOSUCH               No such object
+  106: CRM_EX_QUORUM               Quorum required
+  107: CRM_EX_UNSAFE               Operation not safe
+  108: CRM_EX_EXISTS               Requested item already exists
+  109: CRM_EX_MULTIPLE             Multiple items match request
+  110: CRM_EX_EXPIRED              Requested item has expired
+  111: CRM_EX_NOT_YET_IN_EFFECT    Requested item is not yet in effect
+  112: CRM_EX_INDETERMINATE        Could not determine status
+  113: CRM_EX_UNSATISFIED          Not applicable under current conditions
+  124: CRM_EX_TIMEOUT              Timeout occurred
+  190: CRM_EX_DEGRADED             Service is active but might fail soon
+  191: CRM_EX_DEGRADED_PROMOTED    Service is promoted but might fail soon
+  193: CRM_EX_NONE                 No exit status available
+=#=#=#= End test: Get all crm_exit_t exit codes (with name) - OK (0) =#=#=#=
+* Passed: crm_error      - Get all crm_exit_t exit codes (with name)
+=#=#=#= Begin test: Get all crm_exit_t exit codes (with name) (XML) =#=#=#=
+<pacemaker-result api-version="X" request="crm_error -l -n -X --output-as=xml">
+  <result-code code="0" name="CRM_EX_OK" description="OK"/>
+  <result-code code="1" name="CRM_EX_ERROR" description="Error occurred"/>
+  <result-code code="2" name="CRM_EX_INVALID_PARAM" description="Invalid parameter"/>
+  <result-code code="3" name="CRM_EX_UNIMPLEMENT_FEATURE" description="Unimplemented"/>
+  <result-code code="4" name="CRM_EX_INSUFFICIENT_PRIV" description="Insufficient privileges"/>
+  <result-code code="5" name="CRM_EX_NOT_INSTALLED" description="Not installed"/>
+  <result-code code="6" name="CRM_EX_NOT_CONFIGURED" description="Not configured"/>
+  <result-code code="7" name="CRM_EX_NOT_RUNNING" description="Not running"/>
+  <result-code code="8" name="CRM_EX_PROMOTED" description="Promoted"/>
+  <result-code code="9" name="CRM_EX_FAILED_PROMOTED" description="Failed in promoted role"/>
+  <result-code code="64" name="CRM_EX_USAGE" description="Incorrect usage"/>
+  <result-code code="65" name="CRM_EX_DATAERR" description="Invalid data given"/>
+  <result-code code="66" name="CRM_EX_NOINPUT" description="Input file not available"/>
+  <result-code code="67" name="CRM_EX_NOUSER" description="User does not exist"/>
+  <result-code code="68" name="CRM_EX_NOHOST" description="Host does not exist"/>
+  <result-code code="69" name="CRM_EX_UNAVAILABLE" description="Necessary service unavailable"/>
+  <result-code code="70" name="CRM_EX_SOFTWARE" description="Internal software bug"/>
+  <result-code code="71" name="CRM_EX_OSERR" description="Operating system error occurred"/>
+  <result-code code="72" name="CRM_EX_OSFILE" description="System file not available"/>
+  <result-code code="73" name="CRM_EX_CANTCREAT" description="Cannot create output file"/>
+  <result-code code="74" name="CRM_EX_IOERR" description="I/O error occurred"/>
+  <result-code code="75" name="CRM_EX_TEMPFAIL" description="Temporary failure, try again"/>
+  <result-code code="76" name="CRM_EX_PROTOCOL" description="Protocol violated"/>
+  <result-code code="77" name="CRM_EX_NOPERM" description="Insufficient privileges"/>
+  <result-code code="78" name="CRM_EX_CONFIG" description="Invalid configuration"/>
+  <result-code code="100" name="CRM_EX_FATAL" description="Fatal error occurred, will not respawn"/>
+  <result-code code="101" name="CRM_EX_PANIC" description="System panic required"/>
+  <result-code code="102" name="CRM_EX_DISCONNECT" description="Not connected"/>
+  <result-code code="103" name="CRM_EX_OLD" description="Update was older than existing configuration"/>
+  <result-code code="104" name="CRM_EX_DIGEST" description="Digest mismatch"/>
+  <result-code code="105" name="CRM_EX_NOSUCH" description="No such object"/>
+  <result-code code="106" name="CRM_EX_QUORUM" description="Quorum required"/>
+  <result-code code="107" name="CRM_EX_UNSAFE" description="Operation not safe"/>
+  <result-code code="108" name="CRM_EX_EXISTS" description="Requested item already exists"/>
+  <result-code code="109" name="CRM_EX_MULTIPLE" description="Multiple items match request"/>
+  <result-code code="110" name="CRM_EX_EXPIRED" description="Requested item has expired"/>
+  <result-code code="111" name="CRM_EX_NOT_YET_IN_EFFECT" description="Requested item is not yet in effect"/>
+  <result-code code="112" name="CRM_EX_INDETERMINATE" description="Could not determine status"/>
+  <result-code code="113" name="CRM_EX_UNSATISFIED" description="Not applicable under current conditions"/>
+  <result-code code="124" name="CRM_EX_TIMEOUT" description="Timeout occurred"/>
+  <result-code code="190" name="CRM_EX_DEGRADED" description="Service is active but might fail soon"/>
+  <result-code code="191" name="CRM_EX_DEGRADED_PROMOTED" description="Service is promoted but might fail soon"/>
+  <result-code code="193" name="CRM_EX_NONE" description="No exit status available"/>
+  <status code="0" message="OK"/>
+</pacemaker-result>
+=#=#=#= End test: Get all crm_exit_t exit codes (with name) (XML) - OK (0) =#=#=#=
+* Passed: crm_error      - Get all crm_exit_t exit codes (with name) (XML)
diff --git a/cts/cts-cli.in b/cts/cts-cli.in
index c714cbf495..8db014c6bd 100755
--- a/cts/cts-cli.in
+++ b/cts/cts-cli.in
@@ -1,2321 +1,2509 @@
 #!@BASH_PATH@
 #
 # Copyright 2008-2022 the Pacemaker project contributors
 #
 # The version control history for this file may have further details.
 #
 # This source code is licensed under the GNU General Public License version 2
 # or later (GPLv2+) WITHOUT ANY WARRANTY.
 #
 
 # Set the exit status of a command to the exit code of the last program to
 # exit non-zero.  This is bash-specific.
 set -o pipefail
 
 #
 # Note on portable usage of sed: GNU/POSIX/*BSD sed have a limited subset of
 # compatible functionality. Do not use the -i option, alternation (\|),
 # \0, or character sequences such as \n or \s.
 #
 
 USAGE_TEXT="Usage: cts-cli [<options>]
 Options:
  --help          Display this text, then exit
  -V, --verbose   Display any differences from expected output
- -t 'TEST [...]' Run only specified tests (default: 'dates tools crm_mon acls validity upgrade rules feature_set').
+ -t 'TEST [...]' Run only specified tests
+                 (default: 'dates error_codes tools crm_mon acls validity
+                            upgrade rules feature_set').
                  Other tests: agents (must be run in an installed environment).
  -p DIR          Look for executables in DIR (may be specified multiple times)
  -v, --valgrind  Run all commands under valgrind
  -s              Save actual output as expected output"
 
 # If readlink supports -e (i.e. GNU), use it
 readlink -e / >/dev/null 2>/dev/null
 if [ $? -eq 0 ]; then
     test_home="$(dirname "$(readlink -e "$0")")"
 else
     test_home="$(dirname "$0")"
 fi
 
 : ${shadow=cts-cli}
 shadow_dir=$(mktemp -d ${TMPDIR:-/tmp}/cts-cli.shadow.XXXXXXXXXX)
 num_errors=0
 num_passed=0
 verbose=0
-tests="dates tools crm_mon acls validity upgrade rules feature_set"
+tests="dates error_codes tools crm_mon acls validity upgrade rules feature_set"
 do_save=0
 XMLLINT_CMD=
 VALGRIND_CMD=
 VALGRIND_OPTS="
     -q
     --gen-suppressions=all
     --show-reachable=no
     --leak-check=full
     --trace-children=no
     --time-stamp=yes
     --num-callers=20
     --suppressions=$test_home/valgrind-pcmk.suppressions
 "
 
 # Named pipe for saving a command's stderr in _test_assert()
 err_fifo=$(mktemp ${TMPDIR:-/tmp}/cts-cli.err_fifo.XXXXXXXXXX)
 mkfifo "$err_fifo"
 
 # Log test errors to stderr
 export PCMK_stderr=1
 
 # These constants must track crm_exit_t values
 CRM_EX_OK=0
 CRM_EX_ERROR=1
 CRM_EX_INVALID_PARAM=2
 CRM_EX_UNIMPLEMENT_FEATURE=3
 CRM_EX_INSUFFICIENT_PRIV=4
 CRM_EX_NOT_CONFIGURED=6
 CRM_EX_USAGE=64
 CRM_EX_DATAERR=65
 CRM_EX_CONFIG=78
 CRM_EX_OLD=103
 CRM_EX_DIGEST=104
 CRM_EX_NOSUCH=105
 CRM_EX_UNSAFE=107
 CRM_EX_EXISTS=108
 CRM_EX_MULTIPLE=109
 CRM_EX_EXPIRED=110
 CRM_EX_NOT_YET_IN_EFFECT=111
 
 reset_shadow_cib_version() {
     local SHADOWPATH
 
     SHADOWPATH="$(crm_shadow --file)"
     # sed -i isn't portable :-(
     cp -p "$SHADOWPATH" "${SHADOWPATH}.$$" # preserve permissions
     sed -e 's/epoch="[0-9]*"/epoch="1"/g' \
         -e 's/num_updates="[0-9]*"/num_updates="0"/g' \
         -e 's/admin_epoch="[0-9]*"/admin_epoch="0"/g' \
         "$SHADOWPATH" > "${SHADOWPATH}.$$"
     mv -- "${SHADOWPATH}.$$" "$SHADOWPATH"
 }
 
 # A newly created empty CIB might or might not have a rsc_defaults section
 # depending on whether the --with-resource-stickiness-default configure
 # option was used. To ensure regression tests behave the same either way,
 # delete any rsc_defaults after creating or erasing a CIB.
 delete_shadow_resource_defaults() {
     cibadmin --delete --xml-text '<rsc_defaults/>'
 
     # The above command might or might not bump the CIB version, so reset it
     # to ensure future changes result in the same version for comparison.
     reset_shadow_cib_version
 }
 
 create_shadow_cib() {
     local VALIDATE_WITH
     local SHADOW_CMD
 
     VALIDATE_WITH="$1"
 
     export CIB_shadow_dir="${shadow_dir}"
 
     SHADOW_CMD="$VALGRIND_CMD crm_shadow --batch --force --create-empty"
     if [ -z "$VALIDATE_WITH" ]; then
         $SHADOW_CMD "$shadow" 2>&1
     else
         $SHADOW_CMD "$shadow" --validate-with="${VALIDATE_WITH}" 2>&1
     fi
 
     export CIB_shadow="$shadow"
     delete_shadow_resource_defaults
 }
 
 function _test_assert() {
     target=$1; shift
     validate=$1; shift
     cib=$1; shift
     app=`echo "$cmd" | sed 's/\ .*//'`
     printf "* Running: $app - $desc\n" 1>&2
 
     printf "=#=#=#= Begin test: $desc =#=#=#=\n"
 
     # Capture stderr and stdout separately, then print them consecutively
     out=$(eval $VALGRIND_CMD $cmd 2> "$err_fifo")
     rc=$?
     cat "$err_fifo"
     [ -n "$out" ] && echo "$out"
 
     if [ x$cib != x0 ]; then
         printf "=#=#=#= Current cib after: $desc =#=#=#=\n"
         CIB_user=root cibadmin -Q
     fi
 
     # Do not validate if running under valgrind, even if told to do so.  Valgrind
     # will output a lot more stuff that is not XML, so it wouldn't validate anyway.
     if [ "$validate" = "1" ] && [ "$VALGRIND_CMD" = "" ] && [ $rc = 0 ] && [ "$XMLLINT_CMD" != "" ]; then
         # The sed command filters out the "- validates" line that xmllint will output
         # on success.  grep cannot be used here because "grep -v 'validates$'" will
         # return an exit code of 1 if its input consists entirely of "- validates".
         echo "$out" | $XMLLINT_CMD --noout --relaxng "$PCMK_schema_directory/api/api-result.rng" - 2>&1 | sed -n '/validates$/ !p'
         rc=$?
 
         if [ $rc = 0 ]; then
             printf "=#=#=#= End test: %s - $(crm_error --exit $rc) (%d) =#=#=#=\n" "$desc" $rc
         else
             printf "=#=#=#= End test: %s - Failed to validate (%d) =#=#=#=\n" "$desc" $rc
         fi
     else
         printf "=#=#=#= End test: %s - $(crm_error --exit $rc) (%d) =#=#=#=\n" "$desc" $rc
     fi
 
     rm -f "$outfile"
 
     if [ $rc -ne $target ]; then
         num_errors=$(( $num_errors + 1 ))
         printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc"
         printf "* Failed (rc=%.3d): %-14s - %s\n" $rc $app "$desc (`which $app`)" 1>&2
         return
         exit $CRM_EX_ERROR
     else
         printf "* Passed: %-14s - %s\n" $app "$desc"
         num_passed=$(( $num_passed + 1 ))
     fi
 }
 
 function test_assert() {
     _test_assert $1 0 $2
 }
 
 function test_assert_validate() {
     _test_assert $1 1 $2
 }
 
 # Tests that depend on resource agents and must be run in an installed
 # environment
 function test_agents() {
     desc="Validate a valid resource configuration"
     cmd="crm_resource --validate --class ocf --provider pacemaker --agent Dummy"
     test_assert $CRM_EX_OK 0
 
     desc="Validate a valid resource configuration (XML)"
     cmd="crm_resource --validate --class ocf --provider pacemaker --agent Dummy"
     cmd="$cmd --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     # Make the Dummy configuration invalid (op_sleep can't be a generic string)
     export OCF_RESKEY_op_sleep=asdf
 
     desc="Validate an invalid resource configuration"
     cmd="crm_resource --validate --class ocf --provider pacemaker --agent Dummy"
     test_assert $CRM_EX_NOT_CONFIGURED 0
 
     desc="Validate an invalid resource configuration (XML)"
     cmd="crm_resource --validate --class ocf --provider pacemaker --agent Dummy"
     cmd="$cmd --output-as=xml"
     test_assert_validate $CRM_EX_NOT_CONFIGURED 0
 
     unset OCF_RESKEY_op_sleep
     export OCF_RESKEY_op_sleep
 }
 
 function test_crm_mon() {
     local TMPXML
     export CIB_file="$test_home/cli/crm_mon.xml"
 
     desc="Basic text output"
     cmd="crm_mon -1"
     test_assert $CRM_EX_OK 0
 
     desc="XML output"
     cmd="crm_mon --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output without node section"
     cmd="crm_mon -1 --exclude=nodes"
     test_assert $CRM_EX_OK 0
 
     desc="XML output without the node section"
     cmd="crm_mon --output-as=xml --exclude=nodes"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Text output with only the node section"
     cmd="crm_mon -1 --exclude=all --include=nodes"
     test_assert $CRM_EX_OK 0
 
     # The above test doesn't need to be performed for other output formats.  It's
     # really just a test to make sure that blank lines are correct.
 
     desc="Complete text output"
     cmd="crm_mon -1 --include=all"
     test_assert $CRM_EX_OK 0
 
     # XML includes everything already so there's no need for a complete test
 
     desc="Complete text output with detail"
     cmd="crm_mon -1R --include=all"
     test_assert $CRM_EX_OK 0
 
     # XML includes detailed output already
 
     desc="Complete brief text output"
     cmd="crm_mon -1 --include=all --brief"
     test_assert $CRM_EX_OK 0
 
     desc="Complete text output grouped by node"
     cmd="crm_mon -1 --include=all --group-by-node"
     test_assert $CRM_EX_OK 0
 
     # XML does not have a brief output option
 
     desc="Complete brief text output grouped by node"
     cmd="crm_mon -1 --include=all --group-by-node --brief"
     test_assert $CRM_EX_OK 0
 
     desc="XML output grouped by node"
     cmd="crm_mon -1 --output-as=xml --group-by-node"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output filtered by node"
     cmd="crm_mon -1 --include=all --node=cluster01"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by node"
     cmd="crm_mon --output-as xml --include=all --node=cluster01"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output filtered by tag"
     cmd="crm_mon -1 --include=all --node=even-nodes"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by tag"
     cmd="crm_mon --output-as=xml --include=all --node=even-nodes"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output filtered by resource tag"
     cmd="crm_mon -1 --include=all --resource=fencing-rscs"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by resource tag"
     cmd="crm_mon --output-as=xml --include=all --resource=fencing-rscs"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output filtered by node that doesn't exist"
     cmd="crm_mon -1 --node=blah"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by node that doesn't exist"
     cmd="crm_mon --output-as=xml --node=blah"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output with inactive resources"
     cmd="crm_mon -1 -r"
     test_assert $CRM_EX_OK 0
 
     # XML already includes inactive resources
 
     desc="Basic text output with inactive resources, filtered by node"
     cmd="crm_mon -1 -r --node=cluster02"
     test_assert $CRM_EX_OK 0
 
     # XML already includes inactive resources
 
     desc="Complete text output filtered by primitive resource"
     cmd="crm_mon -1 --include=all --resource=Fencing"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by primitive resource"
     cmd="crm_mon --output-as=xml --resource=Fencing"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output filtered by group resource"
     cmd="crm_mon -1 --include=all --resource=exim-group"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by group resource"
     cmd="crm_mon --output-as=xml --resource=exim-group"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output filtered by group resource member"
     cmd="crm_mon -1 --include=all --resource=Public-IP"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by group resource member"
     cmd="crm_mon --output-as=xml --resource=Email"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output filtered by clone resource"
     cmd="crm_mon -1 --include=all --resource=ping-clone"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by clone resource"
     cmd="crm_mon --output-as=xml --resource=ping-clone"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output filtered by clone resource instance"
     cmd="crm_mon -1 --include=all --resource=ping"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by clone resource instance"
     cmd="crm_mon --output-as=xml --resource=ping"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output filtered by exact clone resource instance"
     cmd="crm_mon -1 --include=all --show-detail --resource=ping:0"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by exact clone resource instance"
     cmd="crm_mon --output-as=xml --resource=ping:1"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output filtered by resource that doesn't exist"
     cmd="crm_mon -1 --resource=blah"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by resource that doesn't exist"
     cmd="crm_mon --output-as=xml --resource=blah"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output with inactive resources, filtered by tag"
     cmd="crm_mon -1 -r --resource=inactive-rscs"
     test_assert $CRM_EX_OK 0
 
     desc="Basic text output with inactive resources, filtered by bundle resource"
     cmd="crm_mon -1 -r --resource=httpd-bundle"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by inactive bundle resource"
     cmd="crm_mon --output-as=xml --resource=httpd-bundle"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output with inactive resources, filtered by bundled IP address resource"
     cmd="crm_mon -1 -r --resource=httpd-bundle-ip-192.168.122.131"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by bundled IP address resource"
     cmd="crm_mon --output-as=xml --resource=httpd-bundle-ip-192.168.122.132"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output with inactive resources, filtered by bundled container"
     cmd="crm_mon -1 -r --resource=httpd-bundle-docker-1"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by bundled container"
     cmd="crm_mon --output-as=xml --resource=httpd-bundle-docker-2"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output with inactive resources, filtered by bundle connection"
     cmd="crm_mon -1 -r --resource=httpd-bundle-0"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by bundle connection"
     cmd="crm_mon --output-as=xml --resource=httpd-bundle-0"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Basic text output with inactive resources, filtered by bundled primitive resource"
     cmd="crm_mon -1 -r --resource=httpd"
     test_assert $CRM_EX_OK 0
 
     desc="XML output filtered by bundled primitive resource"
     cmd="crm_mon --output-as=xml --resource=httpd"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output, filtered by clone name in cloned group"
     cmd="crm_mon -1 --include=all --show-detail --resource=mysql-clone-group"
     test_assert $CRM_EX_OK 0
 
     desc="XML output, filtered by clone name in cloned group"
     cmd="crm_mon --output-as=xml --resource=mysql-clone-group"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output, filtered by group name in cloned group"
     cmd="crm_mon -1 --include=all --show-detail --resource=mysql-group"
     test_assert $CRM_EX_OK 0
 
     desc="XML output, filtered by group name in cloned group"
     cmd="crm_mon --output-as=xml --resource=mysql-group"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output, filtered by exact group instance name in cloned group"
     cmd="crm_mon -1 --include=all --show-detail --resource=mysql-group:1"
     test_assert $CRM_EX_OK 0
 
     desc="XML output, filtered by exact group instance name in cloned group"
     cmd="crm_mon --output-as=xml --resource=mysql-group:1"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output, filtered by primitive name in cloned group"
     cmd="crm_mon -1 --include=all --show-detail --resource=mysql-proxy"
     test_assert $CRM_EX_OK 0
 
     desc="XML output, filtered by primitive name in cloned group"
     cmd="crm_mon --output-as=xml --resource=mysql-proxy"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Complete text output, filtered by exact primitive instance name in cloned group"
     cmd="crm_mon -1 --include=all --show-detail --resource=mysql-proxy:1"
     test_assert $CRM_EX_OK 0
 
     desc="XML output, filtered by exact primitive instance name in cloned group"
     cmd="crm_mon --output-as=xml --resource=mysql-proxy:1"
     test_assert_validate $CRM_EX_OK 0
 
     unset CIB_file
 
     export CIB_file="$test_home/cli/crm_mon-partial.xml"
 
     desc="Text output of partially active resources"
     cmd="crm_mon -1 --show-detail"
     test_assert $CRM_EX_OK 0
 
     desc="XML output of partially active resources"
     cmd="crm_mon -1 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Text output of partially active resources, with inactive resources"
     cmd="crm_mon -1 -r --show-detail"
     test_assert $CRM_EX_OK 0
 
     # XML already includes inactive resources
 
     desc="Complete brief text output, with inactive resources"
     cmd="crm_mon -1 -r --include=all --brief --show-detail"
     test_assert $CRM_EX_OK 0
 
     # XML does not have a brief output option
 
     desc="Text output of partially active group"
     cmd="crm_mon -1 --resource=partially-active-group"
     test_assert $CRM_EX_OK 0
 
     desc="Text output of partially active group, with inactive resources"
     cmd="crm_mon -1 --resource=partially-active-group -r"
     test_assert $CRM_EX_OK 0
 
     desc="Text output of active member of partially active group"
     cmd="crm_mon -1 --resource=dummy-1"
     test_assert $CRM_EX_OK 0
 
     desc="Text output of inactive member of partially active group"
     cmd="crm_mon -1 --resource=dummy-2 --show-detail"
     test_assert $CRM_EX_OK 0
 
     desc="Complete brief text output grouped by node, with inactive resources"
     cmd="crm_mon -1 -r --include=all --group-by-node --brief --show-detail"
     test_assert $CRM_EX_OK 0
 
     desc="Text output of partially active resources, with inactive resources, filtered by node"
     cmd="crm_mon -1 -r --node=cluster01"
     test_assert $CRM_EX_OK 0
 
     desc="Text output of partially active resources, filtered by node"
     cmd="crm_mon -1 --output-as=xml --node=cluster01"
     test_assert_validate $CRM_EX_OK 0
 
     unset CIB_file
 
     export CIB_file="$test_home/cli/crm_mon-unmanaged.xml"
 
     desc="Text output of active unmanaged resource on offline node"
     cmd="crm_mon -1"
     test_assert $CRM_EX_OK 0
 
     desc="XML output of active unmanaged resource on offline node"
     cmd="crm_mon -1 --output-as=xml"
     test_assert $CRM_EX_OK 0
 
     desc="Brief text output of active unmanaged resource on offline node"
     cmd="crm_mon -1 --brief"
     test_assert $CRM_EX_OK 0
 
     desc="Brief text output of active unmanaged resource on offline node, grouped by node"
     cmd="crm_mon -1 --brief --group-by-node"
     test_assert $CRM_EX_OK 0
 
     export CIB_file=$(mktemp ${TMPDIR:-/tmp}/cts-cli.crm_mon.xml.XXXXXXXXXX)
     sed -e '/maintenance-mode/ s/false/true/' "$test_home/cli/crm_mon.xml" > $CIB_file
 
     desc="Text output of all resources with maintenance-mode enabled"
     cmd="crm_mon -1 -r"
     test_assert $CRM_EX_OK 0
 
     rm -r "$CIB_file"
     unset CIB_file
 }
 
+function test_error_codes() {
+    # Note: At the time of this writing, crm_error returns success even for
+    # unknown error codes. We don't want to cause a regression by changing that.
+
+    # Due to the way _test_assert() formats output, we need "crm_error" to be
+    # the first token of cmd. We can't start with a parenthesis or variable
+    # assignment. However, in the "list result codes" tests, we also need to
+    # save some output for later processing. We'll use a named pipe for this.
+    crm_error_fifo=$(mktemp ${TMPDIR:-/tmp}/cts-cli.crm_error_fifo.XXXXXXXXXX)
+    mkfifo "$crm_error_fifo"
+
+    # Legacy return codes
+    #
+    # Don't test unknown legacy code. FreeBSD includes a colon in strerror(),
+    # while other distros do not.
+    desc="Get legacy return code"
+    cmd="crm_error -- 201"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get legacy return code (XML)"
+    cmd="crm_error --output-as=xml -- 201"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get legacy return code (with name)"
+    cmd="crm_error -n -- 201"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get legacy return code (with name) (XML)"
+    cmd="crm_error -n --output-as=xml -- 201"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get multiple legacy return codes"
+    cmd="crm_error -- 201 202"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get multiple legacy return codes (XML)"
+    cmd="crm_error --output-as=xml -- 201 202"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get multiple legacy return codes (with names)"
+    cmd="crm_error -n -- 201 202"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get multiple legacy return codes (with names) (XML)"
+    cmd="crm_error -n --output-as=xml -- 201 202"
+    test_assert_validate $CRM_EX_OK 0
+
+    # We can only rely on our custom codes, so we'll spot-check codes 201-209
+    desc="List legacy return codes (spot check)"
+    cmd="crm_error -l | grep 20[1-9]"
+    test_assert $CRM_EX_OK 0
+
+    desc="List legacy return codes (spot check) (XML)"
+    cmd="crm_error -l --output-as=xml > $crm_error_fifo; rc=$?"
+    cmd="$cmd; cat $crm_error_fifo"
+    cmd="$cmd | grep -E -v '<result-code.*code=\"([^2]|2[^0]|20[^1-9])'"
+    cmd="$cmd; (exit $rc)"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="List legacy return codes (spot check) (with names)"
+    cmd="crm_error -n -l | grep 20[1-9]"
+    test_assert $CRM_EX_OK 0
+
+    desc="List legacy return codes (spot check) (with names) (XML)"
+    cmd="crm_error -n -l --output-as=xml > $crm_error_fifo; rc=$?"
+    cmd="$cmd; cat $crm_error_fifo"
+    cmd="$cmd | grep -E -v '<result-code.*code=\"([^2]|2[^0]|20[^1-9])'"
+    cmd="$cmd; (exit $rc)"
+    test_assert_validate $CRM_EX_OK 0
+
+    # Standard Pacemaker return codes
+    #
+    # Don't test positive (system) error codes, which may vary by OS
+
+    desc="Get unknown Pacemaker return code"
+    cmd="crm_error -r -- -10000"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get unknown Pacemaker return code (XML)"
+    cmd="crm_error -r --output-as=xml -- -10000"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get unknown Pacemaker return code (with name)"
+    cmd="crm_error -n -r -- -10000"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get unknown Pacemaker return code (with name) (XML)"
+    cmd="crm_error -n -r --output-as=xml -- -10000"
+    test_assert_validate $CRM_EX_OK 0
+
+    # Negative return codes require parsing out the "--" explicitly, so we need
+    # to test them as a separate case
+    desc="Get negative Pacemaker return code"
+    cmd="crm_error -r -- -1005"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get negative Pacemaker return code (XML)"
+    cmd="crm_error -r --output-as=xml -- -1005"
+    test_assert_validate $CRM_EX_OK 0
+
+    # Testing name lookups for negative return codes only is sufficient
+    desc="Get negative Pacemaker return code (with name)"
+    cmd="crm_error -n -r -- -1005"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get negative Pacemaker return code (with name) (XML)"
+    cmd="crm_error -n -r --output-as=xml -- -1005"
+    test_assert_validate $CRM_EX_OK 0
+
+    # We can only rely on our custom codes (negative and zero)
+    desc="List Pacemaker return codes (non-positive)"
+    cmd="crm_error -l -r | grep -E '^[[:blank:]]*(-[[:digit:]]+|0):'"
+    test_assert $CRM_EX_OK 0
+
+    desc="List Pacemaker return codes (non-positive) (XML)"
+    cmd="crm_error -l -r --output-as=xml > $crm_error_fifo; rc=$?"
+    cmd="$cmd; cat $crm_error_fifo"
+    cmd="$cmd | grep -E -v '<result-code.*code=\"[[:digit:]]'"
+    cmd="$cmd; (exit $rc)"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="List Pacemaker return codes (non-positive) (with names)"
+    cmd="crm_error -n -l -r | grep -E '^[[:blank:]]*(-[[:digit:]]+|0):'"
+    test_assert $CRM_EX_OK 0
+
+    desc="List Pacemaker return codes (non-positive) (with names) (XML)"
+    cmd="crm_error -n -l -r --output-as=xml > $crm_error_fifo; rc=$?"
+    cmd="$cmd; cat $crm_error_fifo"
+    cmd="$cmd | grep -E -v '<result-code.*code=\"[[:digit:]]'"
+    cmd="$cmd; (exit $rc)"
+    test_assert_validate $CRM_EX_OK 0
+
+    # crm_exit_t exit codes
+
+    desc="Get unknown crm_exit_t exit code"
+    cmd="crm_error -X -- -10000"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get unknown crm_exit_t exit code (XML)"
+    cmd="crm_error -X --output-as=xml -- -10000"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get unknown crm_exit_t exit code (with name)"
+    cmd="crm_error -n -X -- -10000"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get unknown crm_exit_t exit code (with name) (XML)"
+    cmd="crm_error -n -X --output-as=xml -- -10000"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get crm_exit_t exit code"
+    cmd="crm_error -X -- 1"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get crm_exit_t exit code (XML)"
+    cmd="crm_error -X --output-as=xml -- 1"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get crm_exit_t exit code (with name)"
+    cmd="crm_error -n -X -- 1"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get crm_exit_t exit code (with name) (XML)"
+    cmd="crm_error -n -X --output-as=xml -- 1"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get all crm_exit_t exit codes"
+    cmd="crm_error -l -X"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get all crm_exit_t exit codes (XML)"
+    cmd="crm_error -l -X --output-as=xml"
+    test_assert_validate $CRM_EX_OK 0
+
+    desc="Get all crm_exit_t exit codes (with name)"
+    cmd="crm_error -l -n -X"
+    test_assert $CRM_EX_OK 0
+
+    desc="Get all crm_exit_t exit codes (with name) (XML)"
+    cmd="crm_error -l -n -X --output-as=xml"
+    test_assert_validate $CRM_EX_OK 0
+
+    rm -f "$crm_error_fifo"
+}
+
 function test_tools() {
     local TMPXML
     local TMPORIG
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
     TMPORIG=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.existing.xml.XXXXXXXXXX)
 
     create_shadow_cib
 
     desc="Validate CIB"
     cmd="cibadmin -Q"
     test_assert $CRM_EX_OK
 
     desc="Query the value of an attribute that does not exist"
     cmd="crm_attribute -n ABCD --query --quiet"
     test_assert $CRM_EX_NOSUCH 0
 
     desc="Configure something before erasing"
     cmd="crm_attribute -n cluster-delay -v 60s"
     test_assert $CRM_EX_OK
 
     desc="Require --force for CIB erasure"
     cmd="cibadmin -E"
     test_assert $CRM_EX_UNSAFE
 
     desc="Allow CIB erasure with --force"
     cmd="cibadmin -E --force"
     test_assert $CRM_EX_OK 0
 
     # Skip outputting the resulting CIB in the previous command, and delete
     # rsc_defaults now, so tests behave the same regardless of build options.
     delete_shadow_resource_defaults
 
     # Verify the output after erasure
     desc="Query CIB"
     cmd="cibadmin -Q"
     test_assert $CRM_EX_OK
 
     # Save a copy of the CIB for a later test
     cibadmin -Q > "$TMPORIG"
 
     desc="Set cluster option"
     cmd="crm_attribute -n cluster-delay -v 60s"
     test_assert $CRM_EX_OK
 
     desc="Query new cluster option"
     cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay"
     test_assert $CRM_EX_OK
 
     desc="Query cluster options"
     cmd="cibadmin -Q -o crm_config > $TMPXML"
     test_assert $CRM_EX_OK
 
     desc="Set no-quorum policy"
     cmd="crm_attribute -n no-quorum-policy -v ignore"
     test_assert $CRM_EX_OK
 
     desc="Delete nvpair"
     cmd="cibadmin -D -o crm_config --xml-text '<nvpair id=\"cib-bootstrap-options-cluster-delay\"/>'"
     test_assert $CRM_EX_OK
 
     desc="Create operation should fail"
     cmd="cibadmin -C -o crm_config --xml-file $TMPXML"
     test_assert $CRM_EX_EXISTS
 
     desc="Modify cluster options section"
     cmd="cibadmin -M -o crm_config --xml-file $TMPXML"
     test_assert $CRM_EX_OK
 
     desc="Query updated cluster option"
     cmd="cibadmin -Q -o crm_config | grep cib-bootstrap-options-cluster-delay"
     test_assert $CRM_EX_OK
 
     desc="Set duplicate cluster option"
     cmd="crm_attribute -n cluster-delay -v 40s -s duplicate"
     test_assert $CRM_EX_OK
 
     desc="Setting multiply defined cluster option should fail"
     cmd="crm_attribute -n cluster-delay -v 30s"
     test_assert $CRM_EX_MULTIPLE
 
     desc="Set cluster option with -s"
     cmd="crm_attribute -n cluster-delay -v 30s -s duplicate"
     test_assert $CRM_EX_OK
 
     desc="Delete cluster option with -i"
     cmd="crm_attribute -n cluster-delay -D -i cib-bootstrap-options-cluster-delay"
     test_assert $CRM_EX_OK
 
     desc="Create node1 and bring it online"
     cmd="crm_simulate --live-check --in-place --node-up=node1"
     test_assert $CRM_EX_OK
 
     desc="Create node attribute"
     cmd="crm_attribute -n ram -v 1024M -N node1 -t nodes"
     test_assert $CRM_EX_OK
 
     desc="Query new node attribute"
     cmd="cibadmin -Q -o nodes | grep node1-ram"
     test_assert $CRM_EX_OK
 
     desc="Set a transient (fail-count) node attribute"
     cmd="crm_attribute -n fail-count-foo -v 3 -N node1 -t status"
     test_assert $CRM_EX_OK
 
     desc="Query a fail count"
     cmd="crm_failcount --query -r foo -N node1"
     test_assert $CRM_EX_OK
 
     desc="Show node attributes with crm_simulate"
     cmd="crm_simulate --live-check --show-attrs"
     test_assert $CRM_EX_OK 0
 
     desc="Set a second transient node attribute"
     cmd="crm_attribute -n fail-count-bar -v 5 -N node1 -t status"
     test_assert $CRM_EX_OK
 
     desc="Query node attributes by pattern"
     cmd="crm_attribute -t status -P fail-count -N node1 --query"
     test_assert $CRM_EX_OK 0
 
     desc="Update node attributes by pattern"
     cmd="crm_attribute -t status -P fail-count -N node1 -v 10"
     test_assert $CRM_EX_OK
 
     desc="Delete node attributes by pattern"
     cmd="crm_attribute -t status -P fail-count -N node1 -D"
     test_assert $CRM_EX_OK
 
     desc="crm_attribute given invalid pattern usage"
     cmd="crm_attribute -t nodes -P fail-count -N node1 -D"
     test_assert $CRM_EX_USAGE 0
 
     desc="crm_attribute given invalid delete usage"
     cmd="crm_attribute -t nodes -N node1 -D"
     test_assert $CRM_EX_USAGE 0
 
     desc="Digest calculation"
     cmd="cibadmin -Q | cibadmin -5 -p 2>&1 > /dev/null"
     test_assert $CRM_EX_OK
 
     # This update will fail because it has version numbers
     desc="Replace operation should fail"
     cmd="cibadmin -R --xml-file $TMPORIG"
     test_assert $CRM_EX_OLD
 
     desc="Default standby value"
     cmd="crm_standby -N node1 -G"
     test_assert $CRM_EX_OK
 
     desc="Set standby status"
     cmd="crm_standby -N node1 -v true"
     test_assert $CRM_EX_OK
 
     desc="Query standby value"
     cmd="crm_standby -N node1 -G"
     test_assert $CRM_EX_OK
 
     desc="Delete standby value"
     cmd="crm_standby -N node1 -D"
     test_assert $CRM_EX_OK
 
     desc="Create a resource"
     cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
     test_assert $CRM_EX_OK
 
     desc="crm_resource run with extra arguments"
     cmd="crm_resource foo bar"
     test_assert $CRM_EX_USAGE 0
 
     desc="crm_resource given both -r and resource config"
     cmd="crm_resource -r xyz --class ocf --provider pacemaker --agent Dummy"
     test_assert $CRM_EX_USAGE 0
 
     desc="crm_resource given resource config with invalid action"
     cmd="crm_resource --class ocf --provider pacemaker --agent Dummy -D"
     test_assert $CRM_EX_USAGE 0
 
     desc="Create a resource meta attribute"
     cmd="crm_resource -r dummy --meta -p is-managed -v false"
     test_assert $CRM_EX_OK
 
     desc="Query a resource meta attribute"
     cmd="crm_resource -r dummy --meta -g is-managed"
     test_assert $CRM_EX_OK
 
     desc="Remove a resource meta attribute"
     cmd="crm_resource -r dummy --meta -d is-managed"
     test_assert $CRM_EX_OK
 
     desc="Create another resource meta attribute"
     cmd="crm_resource -r dummy --meta -p target-role -v Stopped --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Show why a resource is not running"
     cmd="crm_resource -Y -r dummy --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Remove another resource meta attribute"
     cmd="crm_resource -r dummy --meta -d target-role --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Create a resource attribute"
     cmd="crm_resource -r dummy -p delay -v 10s"
     test_assert $CRM_EX_OK
 
     desc="List the configured resources"
     cmd="crm_resource -L"
     test_assert $CRM_EX_OK
 
     desc="List the configured resources in XML"
     cmd="crm_resource -L --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Implicitly list the configured resources"
     cmd="crm_resource"
     test_assert $CRM_EX_OK 0
 
     desc="List IDs of instantiated resources"
     cmd="crm_resource -l"
     test_assert $CRM_EX_OK 0
 
     desc="Show XML configuration of resource"
     cmd="crm_resource -q -r dummy"
     test_assert $CRM_EX_OK 0
 
     desc="Show XML configuration of resource, output as XML"
     cmd="crm_resource -q -r dummy --output-as=xml"
     test_assert $CRM_EX_OK 0
 
     desc="Require a destination when migrating a resource that is stopped"
     cmd="crm_resource -r dummy -M"
     test_assert $CRM_EX_USAGE
 
     desc="Don't support migration to non-existent locations"
     cmd="crm_resource -r dummy -M -N i.do.not.exist"
     test_assert $CRM_EX_NOSUCH
 
     desc="Create a fencing resource"
     cmd="cibadmin -C -o resources --xml-text '<primitive id=\"Fence\" class=\"stonith\" type=\"fence_true\"/>'"
     test_assert $CRM_EX_OK
 
     desc="Bring resources online"
     cmd="crm_simulate --live-check --in-place -S"
     test_assert $CRM_EX_OK
 
     desc="Try to move a resource to its existing location"
     cmd="crm_resource -r dummy --move --node node1"
     test_assert $CRM_EX_EXISTS
 
     desc="Try to move a resource that doesn't exist"
     cmd="crm_resource -r xyz --move --node node1"
     test_assert $CRM_EX_NOSUCH 0
 
     desc="Move a resource from its existing location"
     cmd="crm_resource -r dummy --move"
     test_assert $CRM_EX_OK
 
     desc="Clear out constraints generated by --move"
     cmd="crm_resource -r dummy --clear"
     test_assert $CRM_EX_OK
 
     desc="Default ticket granted state"
     cmd="crm_ticket -t ticketA -G granted -d false"
     test_assert $CRM_EX_OK
 
     desc="Set ticket granted state"
     cmd="crm_ticket -t ticketA -r --force"
     test_assert $CRM_EX_OK
 
     desc="Query ticket granted state"
     cmd="crm_ticket -t ticketA -G granted"
     test_assert $CRM_EX_OK
 
     desc="Delete ticket granted state"
     cmd="crm_ticket -t ticketA -D granted --force"
     test_assert $CRM_EX_OK
 
     desc="Make a ticket standby"
     cmd="crm_ticket -t ticketA -s"
     test_assert $CRM_EX_OK
 
     desc="Query ticket standby state"
     cmd="crm_ticket -t ticketA -G standby"
     test_assert $CRM_EX_OK
 
     desc="Activate a ticket"
     cmd="crm_ticket -t ticketA -a"
     test_assert $CRM_EX_OK
 
     desc="Delete ticket standby state"
     cmd="crm_ticket -t ticketA -D standby"
     test_assert $CRM_EX_OK
 
     desc="Ban a resource on unknown node"
     cmd="crm_resource -r dummy -B -N host1"
     test_assert $CRM_EX_NOSUCH
 
     desc="Create two more nodes and bring them online"
     cmd="crm_simulate --live-check --in-place --node-up=node2 --node-up=node3"
     test_assert $CRM_EX_OK
 
     desc="Ban dummy from node1"
     cmd="crm_resource -r dummy -B -N node1"
     test_assert $CRM_EX_OK
 
     desc="Show where a resource is running"
     cmd="crm_resource -r dummy -W"
     test_assert $CRM_EX_OK 0
 
     desc="Show constraints on a resource"
     cmd="crm_resource -a -r dummy"
     test_assert $CRM_EX_OK 0
 
     desc="Ban dummy from node2"
     cmd="crm_resource -r dummy -B -N node2 --output-as=xml"
     test_assert_validate $CRM_EX_OK
 
     desc="Relocate resources due to ban"
     cmd="crm_simulate --live-check --in-place -S"
     test_assert $CRM_EX_OK
 
     desc="Move dummy to node1"
     cmd="crm_resource -r dummy -M -N node1 --output-as=xml"
     test_assert_validate $CRM_EX_OK
 
     desc="Clear implicit constraints for dummy on node2"
     cmd="crm_resource -r dummy -U -N node2"
     test_assert $CRM_EX_OK
 
     desc="Drop the status section"
     cmd="cibadmin -R -o status --xml-text '<status/>'"
     test_assert $CRM_EX_OK 0
 
     desc="Create a clone"
     cmd="cibadmin -C -o resources --xml-text '<clone id=\"test-clone\"><primitive id=\"test-primitive\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/></clone>'"
     test_assert $CRM_EX_OK 0
 
     desc="Create a resource meta attribute"
     cmd="crm_resource -r test-primitive --meta -p is-managed -v false"
     test_assert $CRM_EX_OK
 
     desc="Create a resource meta attribute in the primitive"
     cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force"
     test_assert $CRM_EX_OK
 
     desc="Update resource meta attribute with duplicates"
     cmd="crm_resource -r test-clone --meta -p is-managed -v true"
     test_assert $CRM_EX_OK
 
     desc="Update resource meta attribute with duplicates (force clone)"
     cmd="crm_resource -r test-clone --meta -p is-managed -v true --force"
     test_assert $CRM_EX_OK
 
     desc="Update child resource meta attribute with duplicates"
     cmd="crm_resource -r test-primitive --meta -p is-managed -v false"
     test_assert $CRM_EX_OK
 
     desc="Delete resource meta attribute with duplicates"
     cmd="crm_resource -r test-clone --meta -d is-managed"
     test_assert $CRM_EX_OK
 
     desc="Delete resource meta attribute in parent"
     cmd="crm_resource -r test-primitive --meta -d is-managed"
     test_assert $CRM_EX_OK
 
     desc="Create a resource meta attribute in the primitive"
     cmd="crm_resource -r test-primitive --meta -p is-managed -v false --force"
     test_assert $CRM_EX_OK
 
     desc="Update existing resource meta attribute"
     cmd="crm_resource -r test-clone --meta -p is-managed -v true"
     test_assert $CRM_EX_OK
 
     desc="Create a resource meta attribute in the parent"
     cmd="crm_resource -r test-clone --meta -p is-managed -v true --force"
     test_assert $CRM_EX_OK
 
     desc="Copy resources"
     cmd="cibadmin -Q -o resources > $TMPXML"
     test_assert $CRM_EX_OK 0
 
     desc="Delete resource parent meta attribute (force)"
     cmd="crm_resource -r test-clone --meta -d is-managed --force"
     test_assert $CRM_EX_OK
 
     desc="Restore duplicates"
     cmd="cibadmin -R -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK
 
     desc="Delete resource child meta attribute"
     cmd="crm_resource -r test-primitive --meta -d is-managed"
     test_assert $CRM_EX_OK
 
     cibadmin -C -o resources --xml-text '<group id="dummy-group"> \
         <primitive id="dummy1" class="ocf" provider="pacemaker" type="Dummy"\/> \
         <primitive id="dummy2" class="ocf" provider="pacemaker" type="Dummy"\/> \
       </group>'
 
     desc="Create a resource meta attribute in dummy1"
     cmd="crm_resource -r dummy1 --meta -p is-managed -v true"
     test_assert $CRM_EX_OK
 
     desc="Create a resource meta attribute in dummy-group"
     cmd="crm_resource -r dummy-group --meta -p is-managed -v false"
     test_assert $CRM_EX_OK
 
     cibadmin -D -o resource --xml-text '<group id="dummy-group">'
 
     desc="Specify a lifetime when moving a resource"
     cmd="crm_resource -r dummy --move --node node2 --lifetime=PT1H"
     test_assert $CRM_EX_OK
 
     desc="Try to move a resource previously moved with a lifetime"
     cmd="crm_resource -r dummy --move --node node1"
     test_assert $CRM_EX_OK
 
     desc="Ban dummy from node1 for a short time"
     cmd="crm_resource -r dummy -B -N node1 --lifetime=PT1S"
     test_assert $CRM_EX_OK
 
     desc="Remove expired constraints"
     sleep 2
     cmd="crm_resource --clear --expired"
     test_assert $CRM_EX_OK
 
     # Clear has already been tested elsewhere, but we need to get rid of the
     # constraints so testing delete works.  It won't delete if there's still
     # a reference to the resource somewhere.
     desc="Clear all implicit constraints for dummy"
     cmd="crm_resource -r dummy -U"
     test_assert $CRM_EX_OK
 
     desc="Set a node health strategy"
     cmd="crm_attribute -n node-health-strategy -v migrate-on-red"
     test_assert $CRM_EX_OK
 
     desc="Set a node health attribute"
     cmd="crm_attribute -N node3 -n '#health-cts-cli' -v red"
     test_assert $CRM_EX_OK
 
     desc="Show why a resource is not running on an unhealthy node"
     cmd="crm_resource -N node3 -Y -r dummy --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Delete a resource"
     cmd="crm_resource -D -r dummy -t primitive"
     test_assert $CRM_EX_OK
 
     unset CIB_shadow
     unset CIB_shadow_dir
 
     desc="Create an XML patchset"
     cmd="crm_diff -o $test_home/cli/crm_diff_old.xml -n $test_home/cli/crm_diff_new.xml"
     test_assert $CRM_EX_ERROR 0
 
     export CIB_file="$test_home/cli/constraints.xml"
 
     for rsc in prim1 prim2 prim3 prim4 prim5 prim6 prim7 prim8 prim9 \
                prim10 prim11 prim12 prim13 group clone; do
         desc="Check locations and constraints for $rsc"
         cmd="crm_resource -a -r $rsc"
         test_assert $CRM_EX_OK 0
 
         desc="Recursively check locations and constraints for $rsc"
         cmd="crm_resource -A -r $rsc"
         test_assert $CRM_EX_OK 0
 
         desc="Check locations and constraints for $rsc in XML"
         cmd="crm_resource -a -r $rsc --output-as=xml"
         test_assert_validate $CRM_EX_OK 0
 
         desc="Recursively check locations and constraints for $rsc in XML"
         cmd="crm_resource -A -r $rsc --output-as=xml"
         test_assert_validate $CRM_EX_OK 0
     done
 
     unset CIB_file
 
     export CIB_file="$test_home/cli/crm_resource_digests.xml"
 
     desc="Show resource digests"
     cmd="crm_resource --digests -r rsc1 -N node1 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Show resource digests with overrides"
     cmd="$cmd CRM_meta_interval=10000 CRM_meta_timeout=20000"
     test_assert $CRM_EX_OK 0
 
     unset CIB_file
 
     export CIB_file="$test_home/cli/crmadmin-cluster-remote-guest-nodes.xml"
 
     desc="List all nodes"
     cmd="crmadmin -N"
     test_assert $CRM_EX_OK 0
 
     desc="Minimally list all nodes"
     cmd="crmadmin -N -q"
     test_assert $CRM_EX_OK 0
 
     desc="List all nodes as bash exports"
     cmd="crmadmin -N -B"
     test_assert $CRM_EX_OK 0
 
     desc="List cluster nodes"
     cmd="crmadmin -N cluster | wc -l | grep 6"
     test_assert $CRM_EX_OK 0
 
     desc="List guest nodes"
     cmd="crmadmin -N guest | wc -l | grep 2"
     test_assert $CRM_EX_OK 0
 
     desc="List remote nodes"
     cmd="crmadmin -N remote | wc -l | grep 3"
     test_assert $CRM_EX_OK 0
 
     desc="List cluster,remote nodes"
     cmd="crmadmin -N cluster,remote | wc -l | grep 9"
     test_assert $CRM_EX_OK 0
 
     desc="List guest,remote nodes"
     cmd="crmadmin -N guest,remote | wc -l | grep 5"
     test_assert $CRM_EX_OK 0
 
     unset CIB_file
 
     export CIB_file="$test_home/cli/crm_mon.xml"
     export CIB_shadow_dir="${shadow_dir}"
 
     desc="Show allocation scores with crm_simulate"
     cmd="crm_simulate -x $CIB_file --show-scores --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Show utilization with crm_simulate"
     cmd="crm_simulate -x $CIB_file --show-utilization"
     test_assert $CRM_EX_OK 0
 
     desc="Simulate injecting a failure"
     cmd="crm_simulate -x $CIB_file -S -i ping_monitor_10000@cluster02=1"
     test_assert $CRM_EX_OK 0
 
     desc="Simulate bringing a node down"
     cmd="crm_simulate -x $CIB_file -S --node-down=cluster01"
     test_assert $CRM_EX_OK 0
 
     desc="Simulate a node failing"
     cmd="crm_simulate -x $CIB_file -S --node-fail=cluster02"
     test_assert $CRM_EX_OK 0
 
     unset CIB_shadow_dir
 
     desc="List a promotable clone resource"
     cmd="crm_resource --locate -r promotable-clone"
     test_assert $CRM_EX_OK 0
 
     desc="List the primitive of a promotable clone resource"
     cmd="crm_resource --locate -r promotable-rsc"
     test_assert $CRM_EX_OK 0
 
     desc="List a single instance of a promotable clone resource"
     cmd="crm_resource --locate -r promotable-rsc:0"
     test_assert $CRM_EX_OK 0
 
     desc="List another instance of a promotable clone resource"
     cmd="crm_resource --locate -r promotable-rsc:1"
     test_assert $CRM_EX_OK 0
 
     desc="List a promotable clone resource in XML"
     cmd="crm_resource --locate -r promotable-clone --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="List the primitive of a promotable clone resource in XML"
     cmd="crm_resource --locate -r promotable-rsc --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="List a single instance of a promotable clone resource in XML"
     cmd="crm_resource --locate -r promotable-rsc:0 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="List another instance of a promotable clone resource in XML"
     cmd="crm_resource --locate -r promotable-rsc:1 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Try to move an instance of a cloned resource"
     cmd="crm_resource -r promotable-rsc:0 --move --node node1"
     test_assert $CRM_EX_INVALID_PARAM 0
 
     # Create a sandbox copy of crm_mon.xml
     cibadmin -Q > "$TMPXML"
     export CIB_file="$TMPXML"
 
     desc="Query a nonexistent promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
     test_assert $CRM_EX_NOSUCH 0
 
     desc="Query a nonexistent promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
     test_assert_validate $CRM_EX_NOSUCH 0
 
     desc="Delete a nonexistent promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -D"
     test_assert $CRM_EX_OK 0
 
     desc="Delete a nonexistent promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -D --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Query after deleting a nonexistent promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
     test_assert $CRM_EX_NOSUCH 0
 
     desc="Query after deleting a nonexistent promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
     test_assert_validate $CRM_EX_NOSUCH 0
 
     desc="Update a nonexistent promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -v 1"
     test_assert $CRM_EX_OK 0
 
     desc="Update a nonexistent promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -v 1 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Query after updating a nonexistent promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
     test_assert $CRM_EX_OK 0
 
     desc="Query after updating a nonexistent promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Update an existing promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -v 5"
     test_assert $CRM_EX_OK 0
 
     desc="Update an existing promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -v 5 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Query after updating an existing promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
     test_assert $CRM_EX_OK 0
 
     desc="Query after updating an existing promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Delete an existing promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -D"
     test_assert $CRM_EX_OK 0
 
     desc="Delete an existing promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -D --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Query after deleting an existing promotable score attribute"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G"
     test_assert $CRM_EX_NOSUCH 0
 
     desc="Query after deleting an existing promotable score attribute (XML)"
     cmd="crm_attribute -N cluster01 -p promotable-rsc -G --output-as=xml"
     test_assert_validate $CRM_EX_NOSUCH 0
 
     unset CIB_file
 
     export CIB_file="-"
 
     desc="Check that CIB_file=\"-\" works - crm_mon"
     cmd="cat $test_home/cli/crm_mon.xml | crm_mon -1"
     test_assert $CRM_EX_OK 0
 
     desc="Check that CIB_file=\"-\" works - crm_resource"
     cmd="cat $test_home/cli/crm_resource_digests.xml | crm_resource --digests -r rsc1 -N node1 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Check that CIB_file=\"-\" works - crmadmin"
     cmd="cat $test_home/cli/crmadmin-cluster-remote-guest-nodes.xml | crmadmin -N | wc -l | grep 11"
     test_assert $CRM_EX_OK 0
 
     unset CIB_file
     rm -f "$TMPXML" "$TMPORIG"
 }
 
 INVALID_PERIODS=(
     "2019-01-01 00:00:00Z"              # Start with no end
     "2019-01-01 00:00:00Z/"             # Start with only a trailing slash
     "PT2S/P1M"                          # Two durations
     "2019-13-01 00:00:00Z/P1M"          # Out-of-range month
     "20191077T15/P1M"                   # Out-of-range day
     "2019-10-01T25:00:00Z/P1M"          # Out-of-range hour
     "2019-10-01T24:00:01Z/P1M"          # Hour 24 with anything but :00:00
     "PT5H/20191001T007000Z"             # Out-of-range minute
     "2019-10-01 00:00:80Z/P1M"          # Out-of-range second
     "2019-10-01 00:00:10 +25:00/P1M"    # Out-of-range offset hour
     "20191001T000010 -00:61/P1M"        # Out-of-range offset minute
     "P1Y/2019-02-29 00:00:00Z"          # Feb. 29 in non-leap-year
     "2019-01-01 00:00:00Z/P"            # Duration with no values
     "P1Z/2019-02-20 00:00:00Z"          # Invalid duration unit
     "P1YM/2019-02-20 00:00:00Z"         # No number for duration unit
 )
 
 function test_dates() {
     # Ensure invalid period specifications are rejected
     for spec in '' "${INVALID_PERIODS[@]}"; do
         desc="Invalid period - [$spec]"
         cmd="iso8601 -p \"$spec\""
         test_assert $CRM_EX_INVALID_PARAM 0
     done
 
     desc="2014-01-01 00:30:00 - 1 Hour"
     cmd="iso8601 -d '2014-01-01 00:30:00Z' -D P-1H -E '2013-12-31 23:30:00Z'"
     test_assert $CRM_EX_OK 0
 
     desc="Valid date - Feb 29 in leap year"
     cmd="iso8601 -d '2020-02-29 00:00:00Z' -E '2020-02-29 00:00:00Z'"
     test_assert $CRM_EX_OK 0
 
     desc="Valid date - using 'T' and offset"
     cmd="iso8601 -d '20191201T131211 -05:00' -E '2019-12-01 18:12:11Z'"
     test_assert $CRM_EX_OK 0
 
     desc="24:00:00 equivalent to 00:00:00 of next day"
     cmd="iso8601 -d '2019-12-31 24:00:00Z' -E '2020-01-01 00:00:00Z'"
     test_assert $CRM_EX_OK 0
 
     for y in 06 07 08 09 10 11 12 13 14 15 16 17 18 40; do
         desc="20$y-W01-7"
         cmd="iso8601 -d '20$y-W01-7 00Z'"
         test_assert $CRM_EX_OK 0
 
         desc="20$y-W01-7 - round-trip"
         cmd="iso8601 -d '20$y-W01-7 00Z' -W -E '20$y-W01-7 00:00:00Z'"
         test_assert $CRM_EX_OK 0
 
         desc="20$y-W01-1"
         cmd="iso8601 -d '20$y-W01-1 00Z'"
         test_assert $CRM_EX_OK 0
 
         desc="20$y-W01-1 - round-trip"
         cmd="iso8601 -d '20$y-W01-1 00Z' -W -E '20$y-W01-1 00:00:00Z'"
         test_assert $CRM_EX_OK 0
     done
 
     desc="2009-W53-07"
     cmd="iso8601 -d '2009-W53-7 00:00:00Z' -W -E '2009-W53-7 00:00:00Z'"
     test_assert $CRM_EX_OK 0
 
     desc="epoch + 2 Years 5 Months 6 Minutes"
     cmd="iso8601 -d 'epoch' -D P2Y5MT6M -E '1972-06-01 00:06:00Z'"
     test_assert $CRM_EX_OK 0
 
     desc="2009-01-31 + 1 Month"
     cmd="iso8601 -d '20090131T000000Z' -D P1M -E '2009-02-28 00:00:00Z'"
     test_assert $CRM_EX_OK 0
 
     desc="2009-01-31 + 2 Months"
     cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P2M -E '2009-03-31 00:00:00Z'"
     test_assert $CRM_EX_OK 0
 
     desc="2009-01-31 + 3 Months"
     cmd="iso8601 -d '2009-01-31 00:00:00Z' -D P3M -E '2009-04-30 00:00:00Z'"
     test_assert $CRM_EX_OK 0
 
     desc="2009-03-31 - 1 Month"
     cmd="iso8601 -d '2009-03-31 01:00:00 +01:00' -D P-1M -E '2009-02-28 00:00:00Z'"
     test_assert $CRM_EX_OK 0
 
     desc="2038-01-01 + 3 Months"
     cmd="iso8601 -d '2038-01-01 00:00:00Z' -D P3M -E '2038-04-01 00:00:00Z'"
     test_assert $CRM_EX_OK 0
 }
 
 function test_acl_loop() {
     local TMPXML
 
     TMPXML="$1"
 
     # Make sure we're rejecting things for the right reasons
     orig_trace_fns="$PCMK_trace_functions"
     export PCMK_trace_functions=pcmk__check_acl,pcmk__apply_creation_acl
 
     CIB_user=root cibadmin --replace --xml-text '<resources/>'
 
     ### no ACL ###
     export CIB_user=unknownguy
     desc="$CIB_user: Query configuration"
     cmd="cibadmin -Q"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Set enable-acl"
     cmd="crm_attribute -n enable-acl -v false"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Set stonith-enabled"
     cmd="crm_attribute -n stonith-enabled -v false"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Create a resource"
     cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     ### deny /cib permission ###
     export CIB_user=l33t-haxor
     desc="$CIB_user: Query configuration"
     cmd="cibadmin -Q"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Set enable-acl"
     cmd="crm_attribute -n enable-acl -v false"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Set stonith-enabled"
     cmd="crm_attribute -n stonith-enabled -v false"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Create a resource"
     cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     ### observer role ###
     export CIB_user=niceguy
     desc="$CIB_user: Query configuration"
     cmd="cibadmin -Q"
     test_assert $CRM_EX_OK 0
 
     desc="$CIB_user: Set enable-acl"
     cmd="crm_attribute -n enable-acl -v false"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Set stonith-enabled"
     cmd="crm_attribute -n stonith-enabled -v false"
     test_assert $CRM_EX_OK
 
     desc="$CIB_user: Create a resource"
     cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     export CIB_user=root
     desc="$CIB_user: Query configuration"
     cmd="cibadmin -Q"
     test_assert $CRM_EX_OK 0
 
     desc="$CIB_user: Set stonith-enabled"
     cmd="crm_attribute -n stonith-enabled -v true"
     test_assert $CRM_EX_OK
 
     desc="$CIB_user: Create a resource"
     cmd="cibadmin -C -o resources --xml-text '<primitive id=\"dummy\" class=\"ocf\" provider=\"pacemaker\" type=\"Dummy\"/>'"
     test_assert $CRM_EX_OK
 
     ### deny /cib permission ###
     export CIB_user=l33t-haxor
 
     desc="$CIB_user: Create a resource meta attribute"
     cmd="crm_resource -r dummy --meta -p target-role -v Stopped"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Query a resource meta attribute"
     cmd="crm_resource -r dummy --meta -g target-role"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     desc="$CIB_user: Remove a resource meta attribute"
     cmd="crm_resource -r dummy --meta -d target-role"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     ### observer role ###
     export CIB_user=niceguy
 
     desc="$CIB_user: Create a resource meta attribute"
     cmd="crm_resource -r dummy --meta -p target-role -v Stopped"
     test_assert $CRM_EX_OK
 
     desc="$CIB_user: Query a resource meta attribute"
     cmd="crm_resource -r dummy --meta -g target-role"
     test_assert $CRM_EX_OK
 
     desc="$CIB_user: Remove a resource meta attribute"
     cmd="crm_resource -r dummy --meta -d target-role"
     test_assert $CRM_EX_OK
 
     desc="$CIB_user: Create a resource meta attribute"
     cmd="crm_resource -r dummy --meta -p target-role -v Started"
     test_assert $CRM_EX_OK
 
     ### read //meta_attributes ###
     export CIB_user=badidea
     desc="$CIB_user: Query configuration - implied deny"
     cmd="cibadmin -Q"
     test_assert $CRM_EX_OK 0
 
     ### deny /cib, read //meta_attributes ###
     export CIB_user=betteridea
     desc="$CIB_user: Query configuration - explicit deny"
     cmd="cibadmin -Q"
     test_assert $CRM_EX_OK 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --delete --xml-text '<acls/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     ### observer role ###
     export CIB_user=niceguy
     desc="$CIB_user: Replace - remove acls"
     cmd="cibadmin --replace --xml-file $TMPXML"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -C -o resources --xml-text '<primitive id="dummy2" class="ocf" provider="pacemaker" type="Dummy"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - create resource"
     cmd="cibadmin --replace --xml-file $TMPXML"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" crm_attribute -n enable-acl -v false
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - modify attribute (deny)"
     cmd="cibadmin --replace --xml-file $TMPXML"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace --xml-text '<nvpair id="cib-bootstrap-options-enable-acl" name="enable-acl"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - delete attribute (deny)"
     cmd="cibadmin --replace --xml-file $TMPXML"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - create attribute (deny)"
     cmd="cibadmin --replace --xml-file $TMPXML"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     ### admin role ###
     CIB_user=bob
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - create attribute (direct allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - modify attribute (direct allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - delete attribute (direct allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     ### super_user role ###
     export CIB_user=joe
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - create attribute (inherited allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - modify attribute (inherited allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - delete attribute (inherited allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     ### rsc_writer role ###
     export CIB_user=mike
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - create attribute (allow overrides deny)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - modify attribute (allow overrides deny)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - delete attribute (allow overrides deny)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK 0
 
     ### rsc_denied role ###
     export CIB_user=chris
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - create attribute (deny overrides allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     # Set as root since setting as chris failed
     CIB_user=root cibadmin --modify --xml-text '<primitive id="dummy" description="nothing interesting"/>'
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - modify attribute (deny overrides allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     # Set as root since setting as chris failed
     CIB_user=root cibadmin --modify --xml-text '<primitive id="dummy" description="something interesting"/>'
 
     CIB_user=root cibadmin -Q > "$TMPXML"
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin --replace -o resources --xml-text '<primitive id="dummy" class="ocf" provider="pacemaker" type="Dummy"/>'
     CIB_user=root CIB_file="$TMPXML" CIB_shadow="" cibadmin -Ql
 
     desc="$CIB_user: Replace - delete attribute (deny overrides allow)"
     cmd="cibadmin --replace -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_INSUFFICIENT_PRIV 0
 
     export PCMK_trace_functions="$orig_trace_fns"
 }
 
 function test_acls() {
     local SHADOWPATH
     local TMPXML
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.acls.xml.XXXXXXXXXX)
 
     create_shadow_cib pacemaker-1.3
 
     cat <<EOF > "$TMPXML"
     <acls>
       <acl_user id="l33t-haxor">
         <deny id="crook-nothing" xpath="/cib"/>
       </acl_user>
       <acl_user id="niceguy">
         <role_ref id="observer"/>
       </acl_user>
       <acl_user id="bob">
         <role_ref id="admin"/>
       </acl_user>
       <acl_user id="joe">
         <role_ref id="super_user"/>
       </acl_user>
       <acl_user id="mike">
         <role_ref id="rsc_writer"/>
       </acl_user>
       <acl_user id="chris">
         <role_ref id="rsc_denied"/>
       </acl_user>
       <acl_role id="observer">
         <read id="observer-read-1" xpath="/cib"/>
         <write id="observer-write-1" xpath="//nvpair[@name=&apos;stonith-enabled&apos;]"/>
         <write id="observer-write-2" xpath="//nvpair[@name=&apos;target-role&apos;]"/>
       </acl_role>
       <acl_role id="admin">
         <read id="admin-read-1" xpath="/cib"/>
         <write id="admin-write-1" xpath="//resources"/>
       </acl_role>
       <acl_role id="super_user">
         <write id="super_user-write-1" xpath="/cib"/>
       </acl_role>
       <acl_role id="rsc_writer">
         <deny id="rsc-writer-deny-1" xpath="/cib"/>
         <write id="rsc-writer-write-1" xpath="//resources"/>
       </acl_role>
       <acl_role id="rsc_denied">
         <write id="rsc-denied-write-1" xpath="/cib"/>
         <deny id="rsc-denied-deny-1" xpath="//resources"/>
       </acl_role>
     </acls>
 EOF
 
     desc="Configure some ACLs"
     cmd="cibadmin -M -o acls --xml-file $TMPXML"
     test_assert $CRM_EX_OK
 
     desc="Enable ACLs"
     cmd="crm_attribute -n enable-acl -v true"
     test_assert $CRM_EX_OK
 
     desc="Set cluster option"
     cmd="crm_attribute -n no-quorum-policy -v ignore"
     test_assert $CRM_EX_OK
 
     desc="New ACL"
     cmd="cibadmin --create -o acls --xml-text '<acl_user id=\"badidea\"><read id=\"badidea-resources\" xpath=\"//meta_attributes\"/></acl_user>'"
     test_assert $CRM_EX_OK
 
     desc="Another ACL"
     cmd="cibadmin --create -o acls --xml-text '<acl_user id=\"betteridea\"><read id=\"betteridea-resources\" xpath=\"//meta_attributes\"/></acl_user>'"
     test_assert $CRM_EX_OK
 
     desc="Updated ACL"
     cmd="cibadmin --replace -o acls --xml-text '<acl_user id=\"betteridea\"><deny id=\"betteridea-nothing\" xpath=\"/cib\"/><read id=\"betteridea-resources\" xpath=\"//meta_attributes\"/></acl_user>'"
     test_assert $CRM_EX_OK
 
     test_acl_loop "$TMPXML"
 
     printf "\n\n    !#!#!#!#! Upgrading to latest CIB schema and re-testing !#!#!#!#!\n"
     printf "\nUpgrading to latest CIB schema and re-testing\n" 1>&2
 
     export CIB_user=root
     desc="$CIB_user: Upgrade to latest CIB schema"
     cmd="cibadmin --upgrade --force -V"
     test_assert $CRM_EX_OK
 
     reset_shadow_cib_version
 
     test_acl_loop "$TMPXML"
 
     unset CIB_shadow_dir
     rm -f "$TMPXML"
 }
 
 function test_validity() {
     local TMPGOOD
     local TMPBAD
 
     TMPGOOD=$(mktemp ${TMPDIR:-/tmp}/cts-cli.validity.good.xml.XXXXXXXXXX)
     TMPBAD=$(mktemp ${TMPDIR:-/tmp}/cts-cli.validity.bad.xml.XXXXXXXXXX)
 
     create_shadow_cib pacemaker-1.2
     orig_trace_fns="$PCMK_trace_functions"
     export PCMK_trace_functions=apply_upgrade,update_validation
 
     cibadmin -C -o resources --xml-text '<primitive id="dummy1" class="ocf" provider="pacemaker" type="Dummy"/>'
     cibadmin -C -o resources --xml-text '<primitive id="dummy2" class="ocf" provider="pacemaker" type="Dummy"/>'
     cibadmin -C -o constraints --xml-text '<rsc_order id="ord_1-2" first="dummy1" first-action="start" then="dummy2"/>'
     cibadmin -Q > "$TMPGOOD"
 
 
     desc="Try to make resulting CIB invalid (enum violation)"
     cmd="cibadmin -M -o constraints --xml-text '<rsc_order id=\"ord_1-2\" first=\"dummy1\" first-action=\"break\" then=\"dummy2\"/>'"
     test_assert $CRM_EX_CONFIG
 
     sed 's|"start"|"break"|' "$TMPGOOD" > "$TMPBAD"
     desc="Run crm_simulate with invalid CIB (enum violation)"
     cmd="crm_simulate -x $TMPBAD -S"
     test_assert $CRM_EX_CONFIG 0
 
 
     desc="Try to make resulting CIB invalid (unrecognized validate-with)"
     cmd="cibadmin -M --xml-text '<cib validate-with=\"pacemaker-9999.0\"/>'"
     test_assert $CRM_EX_CONFIG
 
     sed 's|"pacemaker-1.2"|"pacemaker-9999.0"|' "$TMPGOOD" > "$TMPBAD"
     desc="Run crm_simulate with invalid CIB (unrecognized validate-with)"
     cmd="crm_simulate -x $TMPBAD -S"
     test_assert $CRM_EX_CONFIG 0
 
 
     desc="Try to make resulting CIB invalid, but possibly recoverable (valid with X.Y+1)"
     cmd="cibadmin -C -o configuration --xml-text '<tags/>'"
     test_assert $CRM_EX_CONFIG
 
     sed 's|</configuration>|<tags/></configuration>|' "$TMPGOOD" > "$TMPBAD"
     desc="Run crm_simulate with invalid, but possibly recoverable CIB (valid with X.Y+1)"
     cmd="crm_simulate -x $TMPBAD -S"
     test_assert $CRM_EX_OK 0
 
 
     sed 's|[ 	][ 	]*validate-with="[^"]*"||' "$TMPGOOD" > "$TMPBAD"
     desc="Make resulting CIB valid, although without validate-with attribute"
     cmd="cibadmin -R --xml-file $TMPBAD"
     test_assert $CRM_EX_OK
 
     desc="Run crm_simulate with valid CIB, but without validate-with attribute"
     cmd="crm_simulate -x $TMPBAD -S"
     test_assert $CRM_EX_OK 0
 
 
     # this will just disable validation and accept the config, outputting
     # validation errors
     sed -e 's|[ 	][ 	]*validate-with="[^"]*"||' \
         -e 's|\([ 	][ 	]*epoch="[^"]*\)"|\10"|' -e 's|"start"|"break"|' \
         "$TMPGOOD" > "$TMPBAD"
     desc="Make resulting CIB invalid, and without validate-with attribute"
     cmd="cibadmin -R --xml-file $TMPBAD"
     test_assert $CRM_EX_OK
 
     desc="Run crm_simulate with invalid CIB, also without validate-with attribute"
     cmd="crm_simulate -x $TMPBAD -S"
     test_assert $CRM_EX_OK 0
 
     unset CIB_shadow_dir
     rm -f "$TMPGOOD" "$TMPBAD"
     export PCMK_trace_functions="$orig_trace_fns"
 }
 
 test_upgrade() {
     local TMPXML
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
 
     create_shadow_cib pacemaker-2.10
     orig_trace_fns="$PCMK_trace_functions"
     export PCMK_trace_functions=apply_upgrade,update_validation
 
     desc="Set stonith-enabled=false"
     cmd="crm_attribute -n stonith-enabled -v false"
     test_assert $CRM_EX_OK
 
     cat <<EOF > "$TMPXML"
     <resources>
       <primitive id="mySmartFuse" class="ocf" provider="experiment" type="SmartFuse">
         <operations>
           <op id="mySmartFuse-start" name="start" interval="0" timeout="40s"/>
           <op id="mySmartFuse-monitor-inputpower" name="monitor" interval="30s">
             <instance_attributes id="mySmartFuse-inputpower-instanceparams">
               <nvpair id="mySmartFuse-inputpower-requires" name="requires" value="inputpower"/>
             </instance_attributes>
           </op>
           <op id="mySmartFuse-monitor-outputpower" name="monitor" interval="2s">
             <instance_attributes id="mySmartFuse-outputpower-instanceparams">
               <nvpair id="mySmartFuse-outputpower-requires" name="requires" value="outputpower"/>
             </instance_attributes>
           </op>
         </operations>
         <instance_attributes id="mySmartFuse-params">
           <nvpair id="mySmartFuse-params-ip" name="ip" value="192.0.2.10"/>
         </instance_attributes>
 	<!-- a bit hairy but valid -->
         <instance_attributes id-ref="mySmartFuse-outputpower-instanceparams"/>
       </primitive>
     </resources>
 EOF
 
     desc="Configure the initial resource"
     cmd="cibadmin -M -o resources --xml-file $TMPXML"
     test_assert $CRM_EX_OK
 
     desc="Upgrade to latest CIB schema (trigger 2.10.xsl + the wrapping)"
     cmd="cibadmin --upgrade --force -V -V"
     test_assert $CRM_EX_OK
 
     desc="Query a resource instance attribute (shall survive)"
     cmd="crm_resource -r mySmartFuse -g requires"
     test_assert $CRM_EX_OK
 
     unset CIB_shadow_dir
     rm -f "$TMPXML"
     export PCMK_trace_functions="$orig_trace_fns"
 }
 
 test_rules() {
     local TMPXML
 
     create_shadow_cib
 
     cibadmin -C -o crm_config --xml-text '<cluster_property_set id="cib-bootstrap-options"><nvpair id="cib-bootstrap-options-stonith-enabled" name="stonith-enabled" value="false"/></cluster_property_set>'
     cibadmin -C -o resources --xml-text '<primitive class="ocf" id="dummy" provider="heartbeat" type="Dummy" />'
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
     cat <<EOF > "$TMPXML"
 <rsc_location id="cli-too-many-date-expressions" rsc="dummy">
   <rule id="cli-rule-too-many-date-expressions" score="INFINITY" boolean-op="or">
     <date_expression id="cli-date-expression-1" operation="gt" start="2020-01-01 01:00:00 -0500"/>
     <date_expression id="cli-date-expression-2" operation="lt" end="2019-01-01 01:00:00 -0500"/>
   </rule>
 </rsc_location>
 EOF
 
     cibadmin -C -o constraints -x "$TMPXML"
     rm -f "$TMPXML"
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
     cat <<EOF > "$TMPXML"
 <rsc_location id="cli-prefer-dummy-expired" rsc="dummy">
   <rule id="cli-prefer-rule-dummy-expired" score="INFINITY">
     <date_expression id="cli-prefer-lifetime-end-dummy-expired" operation="lt" end="2019-01-01 12:00:00 -05:00"/>
   </rule>
 </rsc_location>
 EOF
 
     cibadmin -C -o constraints -x "$TMPXML"
     rm -f "$TMPXML"
 
     if [ "$(uname)" == "FreeBSD" ]; then
         tomorrow=$(date -v+1d +"%F %T %z")
     else
         tomorrow=$(date --date=tomorrow +"%F %T %z")
     fi
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
     cat <<EOF > "$TMPXML"
 <rsc_location id="cli-prefer-dummy-not-yet" rsc="dummy">
   <rule id="cli-prefer-rule-dummy-not-yet" score="INFINITY">
     <date_expression id="cli-prefer-lifetime-end-dummy-not-yet" operation="gt" start="${tomorrow}"/>
   </rule>
 </rsc_location>
 EOF
 
     cibadmin -C -o constraints -x "$TMPXML"
     rm -f "$TMPXML"
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
     cat <<EOF > "$TMPXML"
 <rsc_location id="cli-prefer-dummy-date_spec-only-years" rsc="dummy">
   <rule id="cli-prefer-rule-dummy-date_spec-only-years" score="INFINITY">
     <date_expression id="cli-prefer-dummy-date_spec-only-years-expr" operation="date_spec">
       <date_spec id="cli-prefer-dummy-date_spec-only-years-spec" years="2019"/>
     </date_expression>
   </rule>
 </rsc_location>
 EOF
 
     cibadmin -C -o constraints -x "$TMPXML"
     rm -f "$TMPXML"
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
     cat <<EOF > "$TMPXML"
 <rsc_location id="cli-prefer-dummy-date_spec-without-years" rsc="dummy">
   <rule id="cli-prefer-rule-dummy-date_spec-without-years" score="INFINITY">
     <date_expression id="cli-prefer-dummy-date_spec-without-years-expr" operation="date_spec">
       <date_spec id="cli-prefer-dummy-date_spec-without-years-spec" hours="20" months="1,3,5,7"/>
     </date_expression>
   </rule>
 </rsc_location>
 EOF
 
     cibadmin -C -o constraints -x "$TMPXML"
     rm -f "$TMPXML"
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
     cat <<EOF > "$TMPXML"
 <rsc_location id="cli-prefer-dummy-date_spec-years-moon" rsc="dummy">
   <rule id="cli-prefer-rule-dummy-date_spec-years-moon" score="INFINITY">
     <date_expression id="cli-prefer-dummy-date_spec-years-moon-expr" operation="date_spec">
       <date_spec id="cli-prefer-dummy-date_spec-years-moon-spec" years="2019" moon="1"/>
     </date_expression>
   </rule>
 </rsc_location>
 EOF
 
     cibadmin -C -o constraints -x "$TMPXML"
     rm -f "$TMPXML"
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.tools.xml.XXXXXXXXXX)
     cat <<EOF > "$TMPXML"
 <rsc_location id="cli-no-date_expression" rsc="dummy">
   <rule id="cli-no-date_expression-rule" score="INFINITY">
     <expression id="ban-apache-expr" attribute="#uname" operation="eq" value="node3"/>
   </rule>
 </rsc_location>
 EOF
 
     cibadmin -C -o constraints -x "$TMPXML"
     rm -f "$TMPXML"
 
     desc="crm_rule given no arguments"
     cmd="crm_rule"
     test_assert $CRM_EX_USAGE 0
 
     desc="crm_rule given no arguments (XML)"
     cmd="crm_rule --output-as=xml"
     test_assert_validate $CRM_EX_USAGE 0
 
     desc="crm_rule given no rule to check"
     cmd="crm_rule -c"
     test_assert $CRM_EX_USAGE 0
 
     desc="crm_rule given no rule to check (XML)"
     cmd="crm_rule -c --output-as=xml"
     test_assert_validate $CRM_EX_USAGE 0
 
     desc="crm_rule given invalid input XML"
     cmd="crm_rule -c -r blahblah -X 'invalidxml'"
     test_assert $CRM_EX_DATAERR 0
 
     desc="crm_rule given invalid input XML (XML)"
     cmd="crm_rule -c -r blahblah -X 'invalidxml' --output-as=xml"
     test_assert_validate $CRM_EX_DATAERR 0
 
     desc="crm_rule given invalid input XML on stdin"
     cmd="echo 'invalidxml' | crm_rule -c -r blahblah -X -"
     test_assert $CRM_EX_DATAERR 0
 
     desc="crm_rule given invalid input XML on stdin (XML)"
     cmd="echo 'invalidxml' | crm_rule -c -r blahblah -X - --output-as=xml"
     test_assert_validate $CRM_EX_DATAERR 0
 
     desc="Try to check a rule that doesn't exist"
     cmd="crm_rule -c -r blahblah"
     test_assert $CRM_EX_NOSUCH
 
     desc="Try to check a rule that doesn't exist, with XML output"
     cmd="crm_rule -c -r blahblah --output-as=xml"
     test_assert_validate $CRM_EX_NOSUCH 0
 
     desc="Try to check a rule that has too many date_expressions"
     cmd="crm_rule -c -r cli-rule-too-many-date-expressions"
     test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
 
     desc="Try to check a rule that has too many date_expressions (XML)"
     cmd="crm_rule -c -r cli-rule-too-many-date-expressions --output-as=xml"
     test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
 
     desc="Verify basic rule is expired"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-expired"
     test_assert $CRM_EX_EXPIRED 0
 
     desc="Verify basic rule is expired, with XML output"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-expired --output-as=xml"
     test_assert_validate $CRM_EX_EXPIRED 0
 
     desc="Verify basic rule worked in the past"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-expired -d 20180101"
     test_assert $CRM_EX_OK 0
 
     desc="Verify basic rule worked in the past (XML)"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-expired -d 20180101 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Verify basic rule is not yet in effect"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet"
     test_assert $CRM_EX_NOT_YET_IN_EFFECT 0
 
     desc="Verify basic rule is not yet in effect (XML)"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet --output-as=xml"
     test_assert_validate $CRM_EX_NOT_YET_IN_EFFECT 0
 
     desc="Verify date_spec rule with years has expired"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years"
     test_assert $CRM_EX_EXPIRED 0
 
     desc="Verify date_spec rule with years has expired (XML)"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years --output-as=xml"
     test_assert_validate $CRM_EX_EXPIRED 0
 
     desc="Verify multiple rules at once"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet -r cli-prefer-rule-dummy-date_spec-only-years"
     test_assert $CRM_EX_EXPIRED 0
 
     desc="Verify multiple rules at once, with XML output"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-not-yet -r cli-prefer-rule-dummy-date_spec-only-years --output-as=xml"
     test_assert_validate $CRM_EX_EXPIRED 0
 
     desc="Verify date_spec rule with years is in effect"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years -d 20190201"
     test_assert $CRM_EX_OK 0
 
     desc="Verify date_spec rule with years is in effect (XML)"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-only-years -d 20190201 --output-as=xml"
     test_assert_validate $CRM_EX_OK 0
 
     desc="Try to check a rule whose date_spec does not contain years="
     cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-without-years"
     test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
 
     desc="Try to check a rule whose date_spec does not contain years= (XML)"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-without-years --output-as=xml"
     test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
 
     desc="Try to check a rule whose date_spec contains years= and moon="
     cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-years-moon"
     test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
 
     desc="Try to check a rule whose date_spec contains years= and moon= (XML)"
     cmd="crm_rule -c -r cli-prefer-rule-dummy-date_spec-years-moon --output-as=xml"
     test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
 
     desc="Try to check a rule with no date_expression"
     cmd="crm_rule -c -r cli-no-date_expression-rule"
     test_assert $CRM_EX_UNIMPLEMENT_FEATURE 0
 
     desc="Try to check a rule with no date_expression (XML)"
     cmd="crm_rule -c -r cli-no-date_expression-rule --output-as=xml"
     test_assert_validate $CRM_EX_UNIMPLEMENT_FEATURE 0
 
     unset CIB_shadow_dir
 }
 
 # Ensure all command output is in portable locale for comparison
 export LC_ALL="C"
 test_access_render() {
     local TMPXML
 
     TMPXML=$(mktemp ${TMPDIR:-/tmp}/cts-cli.access_render.xml.XXXXXXXXXX)
     export CIB_shadow_dir="${shadow_dir}"
 
     $VALGRIND_CMD crm_shadow --batch --force --create-empty $shadow 2>&1
     export CIB_shadow=$shadow
 
     # Create a test CIB that has ACL roles
     cat <<EOF > "$TMPXML"
     <acls>
       <acl_role id="role-deny-acls">
         <acl_permission id="deny-acls" kind="deny" xpath="/cib/configuration/acls"/>
         <acl_permission id="read-rest" kind="read" xpath="/cib"/>
       </acl_role>
       <acl_target id="tony">
         <role id="role-deny-acls"/>
       </acl_target>
     </acls>
 EOF
 
     desc="Configure some ACLs"
     cmd="cibadmin -M -o acls --xml-file $TMPXML"
     test_assert $CRM_EX_OK
 
     desc="Enable ACLs"
     cmd="crm_attribute -n enable-acl -v true"
     test_assert $CRM_EX_OK
 
     unset CIB_user
 
     # Run cibadmin --show-access on the test CIB with different users (tony here)
 
     desc="An instance of ACLs render (into color)"
     cmd="cibadmin --force --show-access=color -Q --user tony"
     test_assert $CRM_EX_OK 0
 
     desc="An instance of ACLs render (into namespacing)"
     cmd="cibadmin --force --show-access=namespace -Q --user tony"
     test_assert $CRM_EX_OK 0
 
     desc="An instance of ACLs render (into text)"
     cmd="cibadmin --force --show-access=text -Q --user tony"
     test_assert $CRM_EX_OK 0
 
     unset CIB_shadow_dir
     rm -f "$TMPXML"
 }
 
 function test_feature_set() {
     create_shadow_cib
 
     # Import the initial test CIB with non-mixed versions
     desc="Import the test CIB"
     cmd="cibadmin --replace --xml-file $test_home/cli/crm_mon-feature_set.xml"
     test_assert $CRM_EX_OK
 
     desc="Complete text output, no mixed status"
     cmd="crm_mon -1 --show-detail"
     test_assert $CRM_EX_OK 0
 
     desc="XML output, no mixed status"
     cmd="crm_mon --output-as=xml"
     test_assert $CRM_EX_OK 0
 
     # Modify the CIB to fake that the cluster has mixed versions
     desc="Fake inconsistent feature set"
     cmd="crm_attribute --node=cluster02 --name=#feature-set --update=3.15.0 --lifetime=reboot"
     test_assert $CRM_EX_OK
 
     desc="Complete text output, mixed status"
     cmd="crm_mon -1 --show-detail"
     test_assert $CRM_EX_OK 0
 
     desc="XML output, mixed status"
     cmd="crm_mon --output-as=xml"
     test_assert $CRM_EX_OK 0
 
     unset CIB_shadow_dir
 }
 
 # Process command-line arguments
 while [ $# -gt 0 ]; do
     case "$1" in
         -t)
             tests="$2"
             shift 2
             ;;
         -V|--verbose)
             verbose=1
             shift
             ;;
         -v|--valgrind)
             export G_SLICE=always-malloc
             VALGRIND_CMD="valgrind $VALGRIND_OPTS"
             shift
             ;;
         -s)
             do_save=1
             shift
             ;;
         -p)
             export PATH="$2:$PATH"
             shift
             ;;
         --help)
             echo "$USAGE_TEXT"
             exit $CRM_EX_OK
             ;;
         *)
             echo "error: unknown option $1"
             echo
             echo "$USAGE_TEXT"
             exit $CRM_EX_USAGE
             ;;
     esac
 done
 
 for t in $tests; do
     case "$t" in
         agents) ;;
         dates) ;;
+        error_codes) ;;
         tools) ;;
         acls) ;;
         validity) ;;
         upgrade) ;;
         rules) ;;
         crm_mon) ;;
         feature_set) ;;
         *)
             echo "error: unknown test $t"
             echo
             echo "$USAGE_TEXT"
             exit $CRM_EX_USAGE
             ;;
     esac
 done
 
 XMLLINT_CMD=$(which xmllint 2>/dev/null)
 if [ $? -ne 0 ]; then
     XMLLINT_CMD=""
     echo "xmllint is missing - install it to validate command output"
 fi
 
 # Check whether we're running from source directory
 SRCDIR=$(dirname $test_home)
 if [ -x "$SRCDIR/tools/crm_simulate" ]; then
     export PATH="$SRCDIR/tools:$PATH"
     echo "Using local binaries from: $SRCDIR/tools"
 
     if [ -x "$SRCDIR/xml" ]; then
         export PCMK_schema_directory="$SRCDIR/xml"
         echo "Using local schemas from: $PCMK_schema_directory"
     fi
 else
     export PCMK_schema_directory=@CRM_SCHEMA_DIRECTORY@
 fi
 
 for t in $tests; do
     echo "Testing $t"
     TMPFILE=$(mktemp ${TMPDIR:-/tmp}/cts-cli.$t.XXXXXXXXXX)
     eval TMPFILE_$t="$TMPFILE"
     test_$t > "$TMPFILE"
 
     # last-rc-change= is always numeric in the CIB. However, for the crm_mon
     # test we also need to compare against the XML output of the crm_mon
     # program. There, these are shown as human readable strings (like the
     # output of the `date` command).
     sed -e 's/cib-last-written.*>/>/'\
         -e 's/Last updated: .*/Last updated:/' \
         -e 's/Last change: .*/Last change:/' \
         -e 's/(version .*)/(version)/' \
         -e 's/last_update time=\".*\"/last_update time=\"\"/' \
         -e 's/last_change time=\".*\"/last_change time=\"\"/' \
         -e 's/ api-version=\".*\" / api-version=\"X\" /' \
         -e 's/ version="[^"]*" / version="" /' \
         -e 's/request=\".*\(crm_[a-zA-Z0-9]*\)/request=\"\1/' \
         -e 's/crm_feature_set="[^"]*" //'\
         -e 's/validate-with="[^"]*" //'\
         -e 's/Created new pacemaker-.* configuration/Created new pacemaker configuration/'\
         -e 's/.*\(pcmk__.*\)@.*\.c:[0-9][0-9]*)/\1/g' \
         -e 's/.*\(unpack_.*\)@.*\.c:[0-9][0-9]*)/\1/g' \
         -e 's/.*\(update_validation\)@.*\.c:[0-9][0-9]*)/\1/g' \
         -e 's/.*\(apply_upgrade\)@.*\.c:[0-9][0-9]*)/\1/g' \
         -e "s/ last-rc-change=['\"][-+A-Za-z0-9: ]*['\"],\{0,1\}//" \
         -e 's|^/tmp/cts-cli\.validity\.bad.xml\.[^:]*:|validity.bad.xml:|'\
         -e 's/^Entity: line [0-9][0-9]*: //'\
         -e 's/\(validation ([0-9][0-9]* of \)[0-9][0-9]*\().*\)/\1X\2/' \
         -e 's/^Migration will take effect until: .*/Migration will take effect until:/' \
         -e 's/ end=\"[0-9][-+: 0-9]*Z*\"/ end=\"\"/' \
         -e 's/ start=\"[0-9][-+: 0-9]*Z*\"/ start=\"\"/' \
         -e 's/^Error checking rule: Device not configured/Error checking rule: No such device or address/' \
         -e 's/Error performing operation: Device not configured/Error performing operation: No such device or address/' \
         -e 's/\(Injecting attribute last-failure-ping#monitor_10000=\)[0-9]*/\1/' \
         -e 's/^lt-//' \
         -e 's/ocf::/ocf:/' \
         -e 's/Masters:/Promoted:/' \
         -e 's/Slaves:/Unpromoted:/' \
         -e 's/Master/Promoted/' \
         -e 's/Slave/Unpromoted/' \
         -e 's/\x1b/\\x1b/' \
         "$TMPFILE" > "${TMPFILE}.$$"
     mv -- "${TMPFILE}.$$" "$TMPFILE"
 
     if [ $do_save -eq 1 ]; then
         cp "$TMPFILE" $test_home/cli/regression.$t.exp
     fi
 done
 
 rm -rf "${shadow_dir}"
-rm -rf "${err_fifo}"
+rm -f "${err_fifo}"
 
 failed=0
 
 if [ $verbose -eq 1 ]; then
     echo -e "\n\nResults"
 fi
 for t in $tests; do
     eval TMPFILE="\$TMPFILE_$t"
     if [ $verbose -eq 1 ]; then
         diff -wu $test_home/cli/regression.$t.exp "$TMPFILE"
     else
         diff -w $test_home/cli/regression.$t.exp "$TMPFILE" >/dev/null 2>&1
     fi
     if [ $? -ne 0 ]; then
         failed=1
     fi
 done
 
 echo -e "\n\nSummary"
 for t in $tests; do
     eval TMPFILE="\$TMPFILE_$t"
     grep -e '^\* \(Passed\|Failed\)' "$TMPFILE"
 done
 
 function print_or_remove_file() {
 
   eval TMPFILE="\$TMPFILE_$1"
   if [[ ! $(diff -wq $test_home/cli/regression.$1.exp "$TMPFILE") ]]; then
     rm -f "$TMPFILE"
   else
     echo "    $TMPFILE"
   fi
 }
 
 if [ $num_errors -ne 0 ] && [ $failed -ne 0 ]; then
     echo "$num_errors tests failed; see output in:"
     for t in $tests; do
       print_or_remove_file "$t"
     done
     exit $CRM_EX_ERROR
 elif [ $num_errors -ne 0 ]; then
     echo "$num_errors tests failed"
     for t in $tests; do
       print_or_remove_file "$t"
     done
     exit $CRM_EX_ERROR
 elif [ $failed -eq 1 ]; then
     echo "$num_passed tests passed but output was unexpected; see output in:"
     for t in $tests; do
       print_or_remove_file "$t"
     done
     exit $CRM_EX_DIGEST
 else
     echo $num_passed tests passed
     for t in $tests; do
         eval TMPFILE="\$TMPFILE_$t"
         rm -f "$TMPFILE"
     done
     crm_shadow --force --delete $shadow >/dev/null 2>&1
     exit $CRM_EX_OK
 fi
diff --git a/include/crm/crm.h b/include/crm/crm.h
index 17a5d17938..087541616c 100644
--- a/include/crm/crm.h
+++ b/include/crm/crm.h
@@ -1,240 +1,240 @@
 /*
  * Copyright 2004-2022 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
  * This source code is licensed under the GNU Lesser General Public License
  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
  */
 
 #ifndef PCMK__CRM_CRM__H
 #  define PCMK__CRM_CRM__H
 
 #  include <crm_config.h>
 #  include <stdlib.h>
 #  include <glib.h>
 #  include <stdbool.h>
 
 #  include <string.h>
 
 #  include <libxml/tree.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /**
  * \file
  * \brief A dumping ground
  * \ingroup core
  */
 
 #ifndef PCMK_ALLOW_DEPRECATED
 /*!
  * \brief Allow use of deprecated Pacemaker APIs
  *
  * By default, external code using Pacemaker headers is allowed to use
  * deprecated Pacemaker APIs. If PCMK_ALLOW_DEPRECATED is defined to 0 before
  * including any Pacemaker headers, deprecated APIs will be unusable. It is
  * strongly recommended to leave this unchanged for production and release
  * builds, to avoid breakage when users upgrade to new Pacemaker releases that
  * deprecate more APIs. This should be defined to 0 only for development and
  * testing builds when desiring to check for usage of currently deprecated APIs.
  */
 #define PCMK_ALLOW_DEPRECATED 1
 #endif
 
 /*!
  * The CRM feature set assists with compatibility in mixed-version clusters.
  * The major version number increases when nodes with different versions
  * would not work (rolling upgrades are not allowed). The minor version
  * number increases when mixed-version clusters are allowed only during
  * rolling upgrades (a node with the oldest feature set will be elected DC). The
  * minor-minor version number is ignored, but allows resource agents to detect
  * cluster support for various features.
  *
  * The feature set also affects the processing of old saved CIBs (such as for
  * many scheduler regression tests).
  *
  * Particular feature points currently tested by Pacemaker code:
  *
  * >2.1:     Operation updates include timing data
  * >=3.0.5:  XML v2 digests are created
  * >=3.0.8:  Peers do not need acks for cancellations
  * >=3.0.9:  DC will send its own shutdown request to all peers
  *           XML v2 patchsets are created by default
  * >=3.0.13: Fail counts include operation name and interval
  * >=3.2.0:  DC supports PCMK_EXEC_INVALID and PCMK_EXEC_NOT_CONNECTED
  */
-#  define CRM_FEATURE_SET		"3.16.0"
+#  define CRM_FEATURE_SET		"3.16.1"
 
 /* Pacemaker's CPG protocols use fixed-width binary fields for the sender and
  * recipient of a CPG message. This imposes an arbitrary limit on cluster node
  * names.
  */
 //! \brief Maximum length of a Corosync cluster node name (in bytes)
 #define MAX_NAME	256
 
 #  define CRM_META			"CRM_meta"
 
 extern char *crm_system_name;
 
 /* *INDENT-OFF* */
 
 // How we represent "infinite" scores
 #  define CRM_SCORE_INFINITY    1000000
 #  define CRM_INFINITY_S        "INFINITY"
 #  define CRM_PLUS_INFINITY_S   "+" CRM_INFINITY_S
 #  define CRM_MINUS_INFINITY_S  "-" CRM_INFINITY_S
 
 /* @COMPAT API < 2.0.0 Deprecated "infinity" aliases
  *
  * INFINITY might be defined elsewhere (e.g. math.h), so undefine it first.
  * This, of course, complicates any attempt to use the other definition in any
  * code that includes this header.
  */
 #  undef INFINITY
 #  define INFINITY_S        "INFINITY"
 #  define MINUS_INFINITY_S "-INFINITY"
 #  define INFINITY        1000000
 
 /* Sub-systems */
 #  define CRM_SYSTEM_DC		"dc"
 #define CRM_SYSTEM_DCIB         "dcib" // Primary instance of CIB manager
 #  define CRM_SYSTEM_CIB		"cib"
 #  define CRM_SYSTEM_CRMD		"crmd"
 #  define CRM_SYSTEM_LRMD		"lrmd"
 #  define CRM_SYSTEM_PENGINE	"pengine"
 #  define CRM_SYSTEM_TENGINE	"tengine"
 #  define CRM_SYSTEM_STONITHD	"stonithd"
 #  define CRM_SYSTEM_MCP	"pacemakerd"
 
 // Names of internally generated node attributes
 #  define CRM_ATTR_UNAME            "#uname"
 #  define CRM_ATTR_ID               "#id"
 #  define CRM_ATTR_KIND             "#kind"
 #  define CRM_ATTR_ROLE             "#role"
 #  define CRM_ATTR_IS_DC            "#is_dc"
 #  define CRM_ATTR_CLUSTER_NAME     "#cluster-name"
 #  define CRM_ATTR_SITE_NAME        "#site-name"
 #  define CRM_ATTR_UNFENCED         "#node-unfenced"
 #  define CRM_ATTR_DIGESTS_ALL      "#digests-all"
 #  define CRM_ATTR_DIGESTS_SECURE   "#digests-secure"
 #  define CRM_ATTR_RA_VERSION       "#ra-version"
 #  define CRM_ATTR_PROTOCOL         "#attrd-protocol"
 #  define CRM_ATTR_FEATURE_SET      "#feature-set"
 
 /* Valid operations */
 #  define CRM_OP_NOOP		"noop"
 #  define CRM_OP_JOIN_ANNOUNCE	"join_announce"
 #  define CRM_OP_JOIN_OFFER	"join_offer"
 #  define CRM_OP_JOIN_REQUEST	"join_request"
 #  define CRM_OP_JOIN_ACKNAK	"join_ack_nack"
 #  define CRM_OP_JOIN_CONFIRM	"join_confirm"
 #  define CRM_OP_PING		"ping"
 #  define CRM_OP_NODE_INFO  "node-info"
 #  define CRM_OP_THROTTLE	"throttle"
 #  define CRM_OP_VOTE		"vote"
 #  define CRM_OP_NOVOTE		"no-vote"
 #  define CRM_OP_HELLO		"hello"
 #  define CRM_OP_PECALC		"pe_calc"
 #  define CRM_OP_QUIT		"quit"
 #  define CRM_OP_LOCAL_SHUTDOWN 	"start_shutdown"
 #  define CRM_OP_SHUTDOWN_REQ	"req_shutdown"
 #  define CRM_OP_SHUTDOWN 	"do_shutdown"
 #  define CRM_OP_FENCE	 	"stonith"
 #  define CRM_OP_REGISTER		"register"
 #  define CRM_OP_IPC_FWD		"ipc_fwd"
 #  define CRM_OP_INVOKE_LRM	"lrm_invoke"
 #  define CRM_OP_LRM_REFRESH	"lrm_refresh" /* Deprecated */
 #  define CRM_OP_LRM_QUERY	"lrm_query"
 #  define CRM_OP_LRM_DELETE	"lrm_delete"
 #  define CRM_OP_LRM_FAIL		"lrm_fail"
 #  define CRM_OP_PROBED		"probe_complete"
 #  define CRM_OP_REPROBE		"probe_again"
 #  define CRM_OP_CLEAR_FAILCOUNT  "clear_failcount"
 #  define CRM_OP_REMOTE_STATE     "remote_state"
 #  define CRM_OP_RELAXED_SET  "one-or-more"
 #  define CRM_OP_RELAXED_CLONE  "clone-one-or-more"
 #  define CRM_OP_RM_NODE_CACHE "rm_node_cache"
 #  define CRM_OP_MAINTENANCE_NODES "maintenance_nodes"
 
 /* Possible cluster membership states */
 #  define CRMD_JOINSTATE_DOWN           "down"
 #  define CRMD_JOINSTATE_PENDING        "pending"
 #  define CRMD_JOINSTATE_MEMBER         "member"
 #  define CRMD_JOINSTATE_NACK           "banned"
 
 #  define CRMD_ACTION_DELETE		"delete"
 #  define CRMD_ACTION_CANCEL		"cancel"
 
 #  define CRMD_ACTION_RELOAD		"reload"
 #  define CRMD_ACTION_RELOAD_AGENT	"reload-agent"
 #  define CRMD_ACTION_MIGRATE		"migrate_to"
 #  define CRMD_ACTION_MIGRATED		"migrate_from"
 
 #  define CRMD_ACTION_START		"start"
 #  define CRMD_ACTION_STARTED		"running"
 
 #  define CRMD_ACTION_STOP		"stop"
 #  define CRMD_ACTION_STOPPED		"stopped"
 
 #  define CRMD_ACTION_PROMOTE		"promote"
 #  define CRMD_ACTION_PROMOTED		"promoted"
 #  define CRMD_ACTION_DEMOTE		"demote"
 #  define CRMD_ACTION_DEMOTED		"demoted"
 
 #  define CRMD_ACTION_NOTIFY		"notify"
 #  define CRMD_ACTION_NOTIFIED		"notified"
 
 #  define CRMD_ACTION_STATUS		"monitor"
 #  define CRMD_ACTION_METADATA		"meta-data"
 #  define CRMD_METADATA_CALL_TIMEOUT   30000
 
 /* short names */
 #  define RSC_DELETE	CRMD_ACTION_DELETE
 #  define RSC_CANCEL	CRMD_ACTION_CANCEL
 
 #  define RSC_MIGRATE	CRMD_ACTION_MIGRATE
 #  define RSC_MIGRATED	CRMD_ACTION_MIGRATED
 
 #  define RSC_START	CRMD_ACTION_START
 #  define RSC_STARTED	CRMD_ACTION_STARTED
 
 #  define RSC_STOP	CRMD_ACTION_STOP
 #  define RSC_STOPPED	CRMD_ACTION_STOPPED
 
 #  define RSC_PROMOTE	CRMD_ACTION_PROMOTE
 #  define RSC_PROMOTED	CRMD_ACTION_PROMOTED
 #  define RSC_DEMOTE	CRMD_ACTION_DEMOTE
 #  define RSC_DEMOTED	CRMD_ACTION_DEMOTED
 
 #  define RSC_NOTIFY	CRMD_ACTION_NOTIFY
 #  define RSC_NOTIFIED	CRMD_ACTION_NOTIFIED
 
 #  define RSC_STATUS	CRMD_ACTION_STATUS
 #  define RSC_METADATA	CRMD_ACTION_METADATA
 /* *INDENT-ON* */
 
 #  include <crm/common/cib.h>
 #  include <crm/common/logging.h>
 #  include <crm/common/util.h>
 
 static inline const char *
 crm_action_str(const char *task, guint interval_ms) {
     if ((task != NULL) && (interval_ms == 0)
         && (strcasecmp(task, RSC_STATUS) == 0)) {
         return "probe";
     }
     return task;
 }
 
 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
 #include <crm/crm_compat.h>
 #endif
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif
diff --git a/include/pacemaker-internal.h b/include/pacemaker-internal.h
index c2c603435f..8610d1ed4d 100644
--- a/include/pacemaker-internal.h
+++ b/include/pacemaker-internal.h
@@ -1,26 +1,27 @@
 /*
  * Copyright 2019-2022 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
  * This source code is licensed under the GNU Lesser General Public License
  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
  */
 
 #ifndef PACEMAKER_INTERNAL__H
 #  define PACEMAKER_INTERNAL__H
 
 #  include <pcmki/pcmki_acl.h>
 #  include <pcmki/pcmki_cluster_queries.h>
 #  include <pcmki/pcmki_fence.h>
 #  include <pcmki/pcmki_output.h>
 #  include <pcmki/pcmki_resource.h>
+#  include <pcmki/pcmki_result_code.h>
 #  include <pcmki/pcmki_rule.h>
 #  include <pcmki/pcmki_sched_allocate.h>
 #  include <pcmki/pcmki_sched_utils.h>
 #  include <pcmki/pcmki_scheduler.h>
 #  include <pcmki/pcmki_simulate.h>
 #  include <pcmki/pcmki_status.h>
 #  include <pcmki/pcmki_transition.h>
 
 #endif
diff --git a/include/pacemaker.h b/include/pacemaker.h
index 627f281d7a..576418544b 100644
--- a/include/pacemaker.h
+++ b/include/pacemaker.h
@@ -1,406 +1,446 @@
 /*
  * Copyright 2019-2022 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
  * This source code is licensed under the GNU Lesser General Public License
  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
  */
 
 #ifndef PCMK__PACEMAKER__H
 #  define PCMK__PACEMAKER__H
 
 #  include <glib.h>
 #  include <libxml/tree.h>
 #  include <crm/cib/cib_types.h>
 #  include <crm/pengine/pe_types.h>
 
 #  include <crm/stonith-ng.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /**
  * \file
  * \brief High Level API
  * \ingroup pacemaker
  */
 
 
 /*!
  * \brief Modify operation of running a cluster simulation.
  */
 enum pcmk_sim_flags {
     pcmk_sim_none             = 0,
     pcmk_sim_all_actions      = 1 << 0,
     pcmk_sim_show_pending     = 1 << 1,
     pcmk_sim_process          = 1 << 2,
     pcmk_sim_show_scores      = 1 << 3,
     pcmk_sim_show_utilization = 1 << 4,
     pcmk_sim_simulate         = 1 << 5,
     pcmk_sim_sanitized        = 1 << 6,
     pcmk_sim_verbose          = 1 << 7,
 };
 
 /*!
  * \brief Synthetic cluster events that can be injected into the cluster
  *        for running simulations.
  */
 typedef struct {
     /*! A list of node names (gchar *) to simulate bringing online */
     GList *node_up;
     /*! A list of node names (gchar *) to simulate bringing offline */
     GList *node_down;
     /*! A list of node names (gchar *) to simulate failing */
     GList *node_fail;
     /*! A list of operations (gchar *) to inject.  The format of these strings
      * is described in the "Operation Specification" section of crm_simulate
      * help output.
      */
     GList *op_inject;
     /*! A list of operations (gchar *) that should return a given error code
      * if they fail.  The format of these strings is described in the
      * "Operation Specification" section of crm_simulate help output.
      */
     GList *op_fail;
     /*! A list of tickets (gchar *) to simulate granting */
     GList *ticket_grant;
     /*! A list of tickets (gchar *) to simulate revoking */
     GList *ticket_revoke;
     /*! A list of tickets (gchar *) to simulate putting on standby */
     GList *ticket_standby;
     /*! A list of tickets (gchar *) to simulate activating */
     GList *ticket_activate;
     /*! Does the cluster have an active watchdog device? */
     char *watchdog;
     /*! Does the cluster have quorum? */
     char *quorum;
 } pcmk_injections_t;
 
 /*!
  * \brief Get controller status
  *
  * \param[in,out] xml                The destination for the result, as an XML tree.
  * \param[in]     dest_node          Destination node for request
  * \param[in]     message_timeout_ms Message timeout
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_controller_status(xmlNodePtr *xml, char *dest_node, unsigned int message_timeout_ms);
 
 /*!
  * \brief Get designated controller
  *
  * \param[in,out] xml                The destination for the result, as an XML tree.
  * \param[in]     message_timeout_ms Message timeout
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms);
 
 /*!
  * \brief Free a :pcmk_injections_t structure
  *
  * \param[in,out] injections The structure to be freed
  */
 void pcmk_free_injections(pcmk_injections_t *injections);
 
 /*!
  * \brief Get pacemakerd status
  *
  * \param[in,out] xml                The destination for the result, as an XML tree.
  * \param[in]     ipc_name           IPC name for request
  * \param[in]     message_timeout_ms Message timeout
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_pacemakerd_status(xmlNodePtr *xml, char *ipc_name, unsigned int message_timeout_ms);
 
 /*!
  * \brief Calculate and output resource operation digests
  *
  * \param[out] xml        Where to store XML with result
  * \param[in]  rsc        Resource to calculate digests for
  * \param[in]  node       Node whose operation history should be used
  * \param[in]  overrides  Hash table of configuration parameters to override
  * \param[in]  data_set   Cluster working set (with status)
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_resource_digests(xmlNodePtr *xml, pe_resource_t *rsc,
                           pe_node_t *node, GHashTable *overrides,
                           pe_working_set_t *data_set);
 
 /**
  * \brief Simulate a cluster's response to events.
  *
  * This high-level function essentially implements crm_simulate(8).  It operates
  * on an input CIB file and various lists of events that can be simulated.  It
  * optionally writes out a variety of artifacts to show the results of the
  * simulation.  Output can be modified with various flags.
  *
  * \param[in,out] xml          The destination for the result, as an XML tree.
  * \param[in,out] data_set     Working set for the cluster.
  * \param[in]     events       A structure containing cluster events
  *                             (node up/down, tickets, injected operations)
  * \param[in]     flags        A bitfield of :pcmk_sim_flags to modify
  *                             operation of the simulation.
  * \param[in]     section_opts Which portions of the cluster status output
  *                             should be displayed?
  * \param[in]     use_date     The date to set the cluster's time to
  *                             (may be NULL).
  * \param[in]     input_file   The source CIB file, which may be overwritten by
  *                             this function (may be NULL).
  * \param[in]     graph_file   Where to write the XML-formatted transition graph
  *                             (may be NULL, in which case no file will be
  *                             written).
  * \param[in]     dot_file     Where to write the dot(1) formatted transition
  *                             graph (may be NULL, in which case no file will
  *                             be written).  See \p pcmk__write_sim_dotfile().
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_simulate(xmlNodePtr *xml, pe_working_set_t *data_set,
                   pcmk_injections_t *injections, unsigned int flags,
                   unsigned int section_opts, char *use_date, char *input_file,
                   char *graph_file, char *dot_file);
 
 /*!
  * \brief Get nodes list
  *
  * \param[in,out] xml                The destination for the result, as an XML tree.
  * \param[in]     node_types         Node type(s) to return (default: all)
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_list_nodes(xmlNodePtr *xml, char *node_types);
 
 /*!
  * \brief Output the current status of the cluster, formatted in the same way
  *        that `crm_mon --output-as=xml` would.
  *
  * \param[in,out] xml The destination for the result, as an XML tree.
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_status(xmlNodePtr *xml);
 
 /*!
  * \brief Check whether each rule in a list is in effect
  *
  * \param[in,out] xml       The destination for the result, as an XML tree
  * \param[in]     input     The CIB XML to check (if \c NULL, use current CIB)
  * \param[in]     date      Check whether the rule is in effect at this date and
  *                          time (if \c NULL, use current date and time)
  * \param[in]     rule_ids  The IDs of the rules to check, as a <tt>NULL</tt>-
  *                          terminated list.
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_check_rules(xmlNodePtr *xml, xmlNodePtr input, const crm_time_t *date,
                      const char **rule_ids);
 
 /*!
  * \brief Check whether a given rule is in effect
  *
  * \param[in,out] xml       The destination for the result, as an XML tree
  * \param[in]     input     The CIB XML to check (if \c NULL, use current CIB)
  * \param[in]     date      Check whether the rule is in effect at this date and
  *                          time (if \c NULL, use current date and time)
  * \param[in]     rule_ids  The ID of the rule to check
  *
  * \return Standard Pacemaker return code
  */
 static inline int
 pcmk_check_rule(xmlNodePtr *xml, xmlNodePtr input, const crm_time_t *date,
                 const char *rule_id)
 {
     const char *rule_ids[] = {rule_id, NULL};
     return pcmk_check_rules(xml, input, date, rule_ids);
 }
 
+/*
+ * \enum pcmk_rc_disp_flags
+ * \brief Bit flags to control which fields of result code info are displayed
+ */
+enum pcmk_rc_disp_flags {
+    pcmk_rc_disp_none = 0,          //!< (Does nothing)
+    pcmk_rc_disp_code = (1 << 0),   //!< Display result code number
+    pcmk_rc_disp_name = (1 << 1),   //!< Display result code name
+    pcmk_rc_disp_desc = (1 << 2),   //!< Display result code description
+};
+
+/*
+ * \brief Display the name and/or description of a result code
+ *
+ * \param[in,out] xml    The destination for the result, as an XML tree
+ * \param[in]     code   The result code
+ * \param[in]     type   Interpret \c code as this type of result code.
+ *                       Supported values: \c pcmk_result_legacy,
+ *                       \c pcmk_result_rc, \c pcmk_result_exitcode.
+ * \param[in]     flags  Group of \c pcmk_rc_disp_flags
+ *
+ * \return Standard Pacemaker return code
+ */
+int pcmk_show_result_code(xmlNodePtr *xml, int code, enum pcmk_result_type type,
+                          uint32_t flags);
+
+/*!
+ * \brief List all valid result codes in a particular family
+ *
+ * \param[in,out] xml    The destination for the result, as an XML tree
+ * \param[in]     type   The family of result codes to list. Supported
+ *                       values: \c pcmk_result_legacy, \c pcmk_result_rc,
+ *                       \c pcmk_result_exitcode.
+ * \param[in]     flags  Group of \c pcmk_rc_disp_flags
+ *
+ * \return Standard Pacemaker return code
+ */
+int pcmk_list_result_codes(xmlNodePtr *xml, enum pcmk_result_type type,
+                           uint32_t flags);
+
 #ifdef BUILD_PUBLIC_LIBPACEMAKER
 
 /*!
  * \brief Ask the cluster to perform fencing
  *
  * \param[in] st        A connection to the fencer API
  * \param[in] target    The node that should be fenced
  * \param[in] action    The fencing action (on, off, reboot) to perform
  * \param[in] name      Who requested the fence action?
  * \param[in] timeout   How long to wait for the operation to complete (in ms)
  * \param[in] tolerance If a successful action for \p target happened within
  *                      this many ms, return 0 without performing the action
  *                      again
  * \param[in] delay     Apply this delay (in milliseconds) before initiating the
  *                      fencing action (a value of -1 applies no delay and also
  *                      disables any fencing delay from pcmk_delay_base and
  *                      pcmk_delay_max)
  * \param[out] reason   If not NULL, where to put descriptive failure reason
  *
  * \return Standard Pacemaker return code
  * \note If \p reason is not NULL, the caller is responsible for freeing its
  *       returned value.
  */
 int pcmk_request_fencing(stonith_t *st, const char *target, const char *action,
                          const char *name, unsigned int timeout,
                          unsigned int tolerance, int delay, char **reason);
 
 /*!
  * \brief List the fencing operations that have occurred for a specific node.
  *
  * \note If \p xml is not NULL, it will be freed first and the previous
  *       contents lost.
  *
  * \param[in,out] xml       The destination for the result, as an XML tree.
  * \param[in]     st        A connection to the STONITH API.
  * \param[in]     target    The node to get history for.
  * \param[in]     timeout   How long to wait for the operation to complete (in ms).
  * \param[in]     quiet     Suppress most output.
  * \param[in]     verbose   Include additional output.
  * \param[in]     broadcast Gather fencing history from all nodes.
  * \param[in]     cleanup   Clean up fencing history after listing.
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_history(xmlNodePtr *xml, stonith_t *st, char *target,
                        unsigned int timeout, bool quiet, int verbose,
                        bool broadcast, bool cleanup);
 
 /*!
  * \brief List all installed STONITH agents.
  *
  * \note If \p xml is not NULL, it will be freed first and the previous
  *       contents lost.
  *
  * \param[in,out] xml     The destination for the result, as an XML tree.
  * \param[in]     st      A connection to the STONITH API.
  * \param[in]     timeout How long to wait for the operation to complete (in ms).
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_installed(xmlNodePtr *xml, stonith_t *st, unsigned int timeout);
 
 /*!
  * \brief When was a device last fenced?
  *
  * \note If \p xml is not NULL, it will be freed first and the previous
  *       contents lost.
  *
  * \param[in,out] xml       The destination for the result, as an XML tree.
  * \param[in]     target    The node that was fenced.
  * \param[in]     as_nodeid
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_last(xmlNodePtr *xml, const char *target, bool as_nodeid);
 
 /*!
  * \brief List nodes that can be fenced.
  *
  * \note If \p xml is not NULL, it will be freed first and the previous
  *       contents lost.
  *
  * \param[in,out] xml        The destination for the result, as an XML tree
  * \param[in]     st         A connection to the STONITH API
  * \param[in]     device_id  Resource ID of fence device to check
  * \param[in]     timeout    How long to wait for the operation to complete (in ms)
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_list_targets(xmlNodePtr *xml, stonith_t *st,
                             const char *device_id, unsigned int timeout);
 
 /*!
  * \brief Get metadata for a resource.
  *
  * \note If \p xml is not NULL, it will be freed first and the previous
  *       contents lost.
  *
  * \param[in,out] xml     The destination for the result, as an XML tree.
  * \param[in]     st      A connection to the STONITH API.
  * \param[in]     agent   The fence agent to get metadata for.
  * \param[in]     timeout How long to wait for the operation to complete (in ms).
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_metadata(xmlNodePtr *xml, stonith_t *st, char *agent,
                         unsigned int timeout);
 
 /*!
  * \brief List registered fence devices.
  *
  * \note If \p xml is not NULL, it will be freed first and the previous
  *       contents lost.
  *
  * \param[in,out] xml     The destination for the result, as an XML tree.
  * \param[in]     st      A connection to the STONITH API.
  * \param[in]     target  If not NULL, only return devices that can fence
  *                        this node.
  * \param[in]     timeout How long to wait for the operation to complete (in ms).
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_registered(xmlNodePtr *xml, stonith_t *st, char *target,
                           unsigned int timeout);
 
 /*!
  * \brief Register a fencing level for a specific node, node regex, or attribute.
  *
  * \p target can take three different forms:
  *   - name=value, in which case \p target is an attribute.
  *   - @pattern, in which case \p target is a node regex.
  *   - Otherwise, \p target is a node name.
  *
  * \param[in] st          A connection to the STONITH API.
  * \param[in] target      The object to register a fencing level for.
  * \param[in] fence_level Index number of level to add.
  * \param[in] devices     Devices to use in level.
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_register_level(stonith_t *st, char *target, int fence_level,
                               stonith_key_value_t *devices);
 
 /*!
  * \brief Unregister a fencing level for a specific node, node regex, or attribute.
  *
  * \p target can take three different forms:
  *   - name=value, in which case \p target is an attribute.
  *   - @pattern, in which case \p target is a node regex.
  *   - Otherwise, \p target is a node name.
  *
  * \param[in] st          A connection to the STONITH API.
  * \param[in] target      The object to unregister a fencing level for.
  * \param[in] fence_level Index number of level to remove.
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_unregister_level(stonith_t *st, char *target, int fence_level);
 
 /*!
  * \brief Validate a STONITH device configuration.
  *
  * \note If \p xml is not NULL, it will be freed first and the previous
  *       contents lost.
  *
  * \param[in,out] xml     The destination for the result, as an XML tree.
  * \param[in]     st      A connection to the STONITH API.
  * \param[in]     agent   The agent to validate (for example, "fence_xvm").
  * \param[in]     id      STONITH device ID (may be NULL).
  * \param[in]     params  STONITH device configuration parameters.
  * \param[in]     timeout How long to wait for the operation to complete (in ms).
  *
  * \return Standard Pacemaker return code
  */
 int pcmk_fence_validate(xmlNodePtr *xml, stonith_t *st, const char *agent,
                         const char *id, stonith_key_value_t *params,
                         unsigned int timeout);
 #endif
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif
diff --git a/include/pcmki/Makefile.am b/include/pcmki/Makefile.am
index faa6c6fdc8..b379fdb0c0 100644
--- a/include/pcmki/Makefile.am
+++ b/include/pcmki/Makefile.am
@@ -1,25 +1,26 @@
 #
 # Copyright 2019-2022 the Pacemaker project contributors
 #
 # The version control history for this file may have further details.
 #
 # This source code is licensed under the GNU General Public License version 2
 # or later (GPLv2+) WITHOUT ANY WARRANTY.
 #
 
 MAINTAINERCLEANFILES    = Makefile.in
 
 noinst_HEADERS		= pcmki_acl.h \
 			  pcmki_cluster_queries.h \
 			  pcmki_fence.h \
 			  pcmki_output.h \
 			  pcmki_resource.h \
+			  pcmki_result_code.h \
 			  pcmki_rule.h \
 			  pcmki_sched_allocate.h \
 			  pcmki_sched_utils.h \
 			  pcmki_scheduler.h \
 			  pcmki_simulate.h \
 			  pcmki_status.h \
 			  pcmki_transition.h
 
 .PHONY: $(ARCHIVE_VERSION)
diff --git a/include/pcmki/pcmki_result_code.h b/include/pcmki/pcmki_result_code.h
new file mode 100644
index 0000000000..479e9c71b0
--- /dev/null
+++ b/include/pcmki/pcmki_result_code.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2022 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#ifndef PCMK__PCMKI_PCMKI_RESULT_CODE__H
+#  define PCMK__PCMKI_PCMKI_RESULT_CODE__H
+
+#include <stdint.h>
+
+#include <crm/crm.h>
+#include <crm/common/output_internal.h>
+
+int pcmk__show_result_code(pcmk__output_t *out, int code,
+                           enum pcmk_result_type type, uint32_t flags);
+int pcmk__list_result_codes(pcmk__output_t *out, enum pcmk_result_type type,
+                            uint32_t flags);
+
+#endif // PCMK__PCMKI_PCMKI_RESULT_CODE__H
diff --git a/lib/pacemaker/Makefile.am b/lib/pacemaker/Makefile.am
index aaea39bb4b..dfc8f80c95 100644
--- a/lib/pacemaker/Makefile.am
+++ b/lib/pacemaker/Makefile.am
@@ -1,65 +1,66 @@
 #
 # Copyright 2004-2022 the Pacemaker project contributors
 #
 # The version control history for this file may have further details.
 #
 # This source code is licensed under the GNU General Public License version 2
 # or later (GPLv2+) WITHOUT ANY WARRANTY.
 #
 
 include $(top_srcdir)/mk/common.mk
 
 AM_CPPFLAGS	+= -I$(top_builddir) -I$(top_srcdir)
 
 noinst_HEADERS  = libpacemaker_private.h
 
 ## libraries
 lib_LTLIBRARIES	= libpacemaker.la
 
 ## SOURCES
 
 libpacemaker_la_LDFLAGS	= -version-info 5:0:4
 
 libpacemaker_la_CFLAGS	= $(CFLAGS_HARDENED_LIB)
 libpacemaker_la_LDFLAGS	+= $(LDFLAGS_HARDENED_LIB)
 
 libpacemaker_la_LIBADD	= $(top_builddir)/lib/pengine/libpe_status.la \
 			$(top_builddir)/lib/cib/libcib.la \
 			$(top_builddir)/lib/lrmd/liblrmd.la \
 			$(top_builddir)/lib/fencing/libstonithd.la \
 			$(top_builddir)/lib/services/libcrmservice.la \
 			$(top_builddir)/lib/common/libcrmcommon.la
 
 # -L$(top_builddir)/lib/pils -lpils -export-dynamic -module -avoid-version
 # Use += rather than backlashed continuation lines for parsing by bumplibs
 libpacemaker_la_SOURCES	=
 libpacemaker_la_SOURCES += pcmk_acl.c
 libpacemaker_la_SOURCES += pcmk_cluster_queries.c
 libpacemaker_la_SOURCES += pcmk_fence.c
 libpacemaker_la_SOURCES += pcmk_graph_consumer.c
 libpacemaker_la_SOURCES += pcmk_graph_logging.c
 libpacemaker_la_SOURCES += pcmk_graph_producer.c
 libpacemaker_la_SOURCES += pcmk_injections.c
 libpacemaker_la_SOURCES += pcmk_output.c
 libpacemaker_la_SOURCES += pcmk_resource.c
+libpacemaker_la_SOURCES += pcmk_result_code.c
 libpacemaker_la_SOURCES += pcmk_rule.c
 libpacemaker_la_SOURCES	+= pcmk_sched_actions.c
 libpacemaker_la_SOURCES	+= pcmk_sched_allocate.c
 libpacemaker_la_SOURCES += pcmk_sched_bundle.c
 libpacemaker_la_SOURCES += pcmk_sched_clone.c
 libpacemaker_la_SOURCES += pcmk_sched_colocation.c
 libpacemaker_la_SOURCES += pcmk_sched_constraints.c
 libpacemaker_la_SOURCES += pcmk_sched_fencing.c
 libpacemaker_la_SOURCES += pcmk_sched_group.c
 libpacemaker_la_SOURCES += pcmk_sched_location.c
 libpacemaker_la_SOURCES += pcmk_sched_nodes.c
 libpacemaker_la_SOURCES += pcmk_sched_ordering.c
 libpacemaker_la_SOURCES += pcmk_sched_primitive.c
 libpacemaker_la_SOURCES += pcmk_sched_probes.c
 libpacemaker_la_SOURCES += pcmk_sched_promotable.c
 libpacemaker_la_SOURCES += pcmk_sched_remote.c
 libpacemaker_la_SOURCES += pcmk_sched_resource.c
 libpacemaker_la_SOURCES += pcmk_sched_tickets.c
 libpacemaker_la_SOURCES += pcmk_sched_utilization.c
 libpacemaker_la_SOURCES += pcmk_simulate.c
 libpacemaker_la_SOURCES += pcmk_status.c
diff --git a/lib/pacemaker/pcmk_output.c b/lib/pacemaker/pcmk_output.c
index 9c9845754d..7c4e622235 100644
--- a/lib/pacemaker/pcmk_output.c
+++ b/lib/pacemaker/pcmk_output.c
@@ -1,2058 +1,2142 @@
 /*
  * Copyright 2019-2022 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
  * This source code is licensed under the GNU General Public License version 2
  * or later (GPLv2+) WITHOUT ANY WARRANTY.
  */
 
 #include <crm_internal.h>
 #include <crm/common/output.h>
 #include <crm/common/results.h>
 #include <crm/msg_xml.h>
 #include <crm/stonith-ng.h>
 #include <crm/fencing/internal.h>
 #include <crm/pengine/internal.h>
 #include <libxml/tree.h>
 #include <pacemaker-internal.h>
 
 #include <stdint.h>
 
 static char *
 colocations_header(pe_resource_t *rsc, pcmk__colocation_t *cons,
                    bool dependents) {
     char *retval = NULL;
 
     if (cons->primary_role > RSC_ROLE_STARTED) {
         retval = crm_strdup_printf("%s (score=%s, %s role=%s, id=%s)",
                                    rsc->id, pcmk_readable_score(cons->score),
                                    (dependents? "needs" : "with"),
                                    role2text(cons->primary_role), cons->id);
     } else {
         retval = crm_strdup_printf("%s (score=%s, id=%s)",
                                    rsc->id, pcmk_readable_score(cons->score),
                                    cons->id);
     }
     return retval;
 }
 
 static void
 colocations_xml_node(pcmk__output_t *out, pe_resource_t *rsc,
                      pcmk__colocation_t *cons) {
     xmlNodePtr node = NULL;
 
     node = pcmk__output_create_xml_node(out, XML_CONS_TAG_RSC_DEPEND,
                                         "id", cons->id,
                                         "rsc", cons->dependent->id,
                                         "with-rsc", cons->primary->id,
                                         "score", pcmk_readable_score(cons->score),
                                         NULL);
 
     if (cons->node_attribute) {
         xmlSetProp(node, (pcmkXmlStr) "node-attribute", (pcmkXmlStr) cons->node_attribute);
     }
 
     if (cons->dependent_role != RSC_ROLE_UNKNOWN) {
         xmlSetProp(node, (pcmkXmlStr) "rsc-role",
                    (pcmkXmlStr) role2text(cons->dependent_role));
     }
 
     if (cons->primary_role != RSC_ROLE_UNKNOWN) {
         xmlSetProp(node, (pcmkXmlStr) "with-rsc-role",
                    (pcmkXmlStr) role2text(cons->primary_role));
     }
 }
 
 static int
 do_locations_list_xml(pcmk__output_t *out, pe_resource_t *rsc, bool add_header)
 {
     GList *lpc = NULL;
     GList *list = rsc->rsc_location;
     int rc = pcmk_rc_no_output;
 
     for (lpc = list; lpc != NULL; lpc = lpc->next) {
         pe__location_t *cons = lpc->data;
 
         GList *lpc2 = NULL;
 
         for (lpc2 = cons->node_list_rh; lpc2 != NULL; lpc2 = lpc2->next) {
             pe_node_t *node = (pe_node_t *) lpc2->data;
 
             if (add_header) {
                 PCMK__OUTPUT_LIST_HEADER(out, false, rc, "locations");
             }
 
             pcmk__output_create_xml_node(out, XML_CONS_TAG_RSC_LOCATION,
                                          "node", node->details->uname,
                                          "rsc", rsc->id,
                                          "id", cons->id,
                                          "score", pcmk_readable_score(node->weight),
                                          NULL);
         }
     }
 
     if (add_header) {
         PCMK__OUTPUT_LIST_FOOTER(out, rc);
     }
 
     return rc;
 }
 
 PCMK__OUTPUT_ARGS("rsc-action-item", "const char *", "pe_resource_t *",
                   "pe_node_t *", "pe_node_t *", "pe_action_t *",
                   "pe_action_t *")
 static int
 rsc_action_item(pcmk__output_t *out, va_list args)
 {
     const char *change = va_arg(args, const char *);
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     pe_node_t *origin = va_arg(args, pe_node_t *);
     pe_node_t *destination = va_arg(args, pe_node_t *);
     pe_action_t *action = va_arg(args, pe_action_t *);
     pe_action_t *source = va_arg(args, pe_action_t *);
 
     int len = 0;
     char *reason = NULL;
     char *details = NULL;
     bool same_host = false;
     bool same_role = false;
     bool need_role = false;
 
     static int rsc_width = 5;
     static int detail_width = 5;
 
     CRM_ASSERT(action);
     CRM_ASSERT(destination != NULL || origin != NULL);
 
     if(source == NULL) {
         source = action;
     }
 
     len = strlen(rsc->id);
     if(len > rsc_width) {
         rsc_width = len + 2;
     }
 
     if ((rsc->role > RSC_ROLE_STARTED)
         || (rsc->next_role > RSC_ROLE_UNPROMOTED)) {
         need_role = true;
     }
 
     if(origin != NULL && destination != NULL && origin->details == destination->details) {
         same_host = true;
     }
 
     if(rsc->role == rsc->next_role) {
         same_role = true;
     }
 
     if (need_role && (origin == NULL)) {
         /* Starting and promoting a promotable clone instance */
         details = crm_strdup_printf("%s -> %s %s", role2text(rsc->role),
                                     role2text(rsc->next_role),
                                     pe__node_name(destination));
 
     } else if (origin == NULL) {
         /* Starting a resource */
         details = crm_strdup_printf("%s", pe__node_name(destination));
 
     } else if (need_role && (destination == NULL)) {
         /* Stopping a promotable clone instance */
         details = crm_strdup_printf("%s %s", role2text(rsc->role),
                                     pe__node_name(origin));
 
     } else if (destination == NULL) {
         /* Stopping a resource */
         details = crm_strdup_printf("%s", pe__node_name(origin));
 
     } else if (need_role && same_role && same_host) {
         /* Recovering, restarting or re-promoting a promotable clone instance */
         details = crm_strdup_printf("%s %s", role2text(rsc->role),
                                     pe__node_name(origin));
 
     } else if (same_role && same_host) {
         /* Recovering or Restarting a normal resource */
         details = crm_strdup_printf("%s", pe__node_name(origin));
 
     } else if (need_role && same_role) {
         /* Moving a promotable clone instance */
         details = crm_strdup_printf("%s -> %s %s", pe__node_name(origin),
                                     pe__node_name(destination),
                                     role2text(rsc->role));
 
     } else if (same_role) {
         /* Moving a normal resource */
         details = crm_strdup_printf("%s -> %s", pe__node_name(origin),
                                     pe__node_name(destination));
 
     } else if (same_host) {
         /* Promoting or demoting a promotable clone instance */
         details = crm_strdup_printf("%s -> %s %s", role2text(rsc->role),
                                     role2text(rsc->next_role),
                                     pe__node_name(origin));
 
     } else {
         /* Moving and promoting/demoting */
         details = crm_strdup_printf("%s %s -> %s %s", role2text(rsc->role),
                                     pe__node_name(origin),
                                     role2text(rsc->next_role),
                                     pe__node_name(destination));
     }
 
     len = strlen(details);
     if(len > detail_width) {
         detail_width = len;
     }
 
     if(source->reason && !pcmk_is_set(action->flags, pe_action_runnable)) {
         reason = crm_strdup_printf("due to %s (blocked)", source->reason);
 
     } else if(source->reason) {
         reason = crm_strdup_printf("due to %s", source->reason);
 
     } else if (!pcmk_is_set(action->flags, pe_action_runnable)) {
         reason = strdup("blocked");
 
     }
 
     out->list_item(out, NULL, "%-8s   %-*s   ( %*s )%s%s", change, rsc_width,
                    rsc->id, detail_width, details, reason ? "  " : "", reason ? reason : "");
 
     free(details);
     free(reason);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("rsc-action-item", "const char *", "pe_resource_t *",
                   "pe_node_t *", "pe_node_t *", "pe_action_t *",
                   "pe_action_t *")
 static int
 rsc_action_item_xml(pcmk__output_t *out, va_list args)
 {
     const char *change = va_arg(args, const char *);
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     pe_node_t *origin = va_arg(args, pe_node_t *);
     pe_node_t *destination = va_arg(args, pe_node_t *);
     pe_action_t *action = va_arg(args, pe_action_t *);
     pe_action_t *source = va_arg(args, pe_action_t *);
 
     char *change_str = NULL;
 
     bool same_host = false;
     bool same_role = false;
     bool need_role = false;
     xmlNode *xml = NULL;
 
     CRM_ASSERT(action);
     CRM_ASSERT(destination != NULL || origin != NULL);
 
     if (source == NULL) {
         source = action;
     }
 
     if ((rsc->role > RSC_ROLE_STARTED)
         || (rsc->next_role > RSC_ROLE_UNPROMOTED)) {
         need_role = true;
     }
 
     if(origin != NULL && destination != NULL && origin->details == destination->details) {
         same_host = true;
     }
 
     if(rsc->role == rsc->next_role) {
         same_role = true;
     }
 
     change_str = g_ascii_strdown(change, -1);
     xml = pcmk__output_create_xml_node(out, "rsc_action",
                                        "action", change_str,
                                        "resource", rsc->id,
                                        NULL);
     g_free(change_str);
 
     if (need_role && (origin == NULL)) {
         /* Starting and promoting a promotable clone instance */
         pcmk__xe_set_props(xml,
                            "role", role2text(rsc->role),
                            "next-role", role2text(rsc->next_role),
                            "dest", destination->details->uname,
                            NULL);
 
     } else if (origin == NULL) {
         /* Starting a resource */
         crm_xml_add(xml, "node", destination->details->uname);
 
     } else if (need_role && (destination == NULL)) {
         /* Stopping a promotable clone instance */
         pcmk__xe_set_props(xml,
                            "role", role2text(rsc->role),
                            "node", origin->details->uname,
                            NULL);
 
     } else if (destination == NULL) {
         /* Stopping a resource */
         crm_xml_add(xml, "node", origin->details->uname);
 
     } else if (need_role && same_role && same_host) {
         /* Recovering, restarting or re-promoting a promotable clone instance */
         pcmk__xe_set_props(xml,
                            "role", role2text(rsc->role),
                            "source", origin->details->uname,
                            NULL);
 
     } else if (same_role && same_host) {
         /* Recovering or Restarting a normal resource */
         crm_xml_add(xml, "source", origin->details->uname);
 
     } else if (need_role && same_role) {
         /* Moving a promotable clone instance */
         pcmk__xe_set_props(xml,
                            "source", origin->details->uname,
                            "dest", destination->details->uname,
                            "role", role2text(rsc->role),
                            NULL);
 
     } else if (same_role) {
         /* Moving a normal resource */
         pcmk__xe_set_props(xml,
                            "source", origin->details->uname,
                            "dest", destination->details->uname,
                            NULL);
 
     } else if (same_host) {
         /* Promoting or demoting a promotable clone instance */
         pcmk__xe_set_props(xml,
                            "role", role2text(rsc->role),
                            "next-role", role2text(rsc->next_role),
                            "source", origin->details->uname,
                            NULL);
 
     } else {
         /* Moving and promoting/demoting */
         pcmk__xe_set_props(xml,
                            "role", role2text(rsc->role),
                            "source", origin->details->uname,
                            "next-role", role2text(rsc->next_role),
                            "dest", destination->details->uname,
                            NULL);
     }
 
     if (source->reason && !pcmk_is_set(action->flags, pe_action_runnable)) {
         pcmk__xe_set_props(xml,
                            "reason", source->reason,
                            "blocked", "true",
                            NULL);
 
     } else if(source->reason) {
         crm_xml_add(xml, "reason", source->reason);
 
     } else if (!pcmk_is_set(action->flags, pe_action_runnable)) {
         pcmk__xe_set_bool_attr(xml, "blocked", true);
 
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("rsc-is-colocated-with-list", "pe_resource_t *", "bool")
 static int
 rsc_is_colocated_with_list(pcmk__output_t *out, va_list args) {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     bool recursive = va_arg(args, int);
 
     int rc = pcmk_rc_no_output;
 
     if (pcmk_is_set(rsc->flags, pe_rsc_allocating)) {
         return rc;
     }
 
     pe__set_resource_flags(rsc, pe_rsc_allocating);
     for (GList *lpc = rsc->rsc_cons; lpc != NULL; lpc = lpc->next) {
         pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
         char *hdr = NULL;
 
         PCMK__OUTPUT_LIST_HEADER(out, false, rc, "Resources %s is colocated with", rsc->id);
 
         if (pcmk_is_set(cons->primary->flags, pe_rsc_allocating)) {
             out->list_item(out, NULL, "%s (id=%s - loop)",
                            cons->primary->id, cons->id);
             continue;
         }
 
         hdr = colocations_header(cons->primary, cons, false);
         out->list_item(out, NULL, "%s", hdr);
         free(hdr);
 
         /* Empty list header just for indentation of information about this resource. */
         out->begin_list(out, NULL, NULL, NULL);
 
         out->message(out, "locations-list", cons->primary);
         if (recursive) {
             out->message(out, "rsc-is-colocated-with-list",
                          cons->primary, recursive);
         }
 
         out->end_list(out);
     }
 
     PCMK__OUTPUT_LIST_FOOTER(out, rc);
     return rc;
 }
 
 PCMK__OUTPUT_ARGS("rsc-is-colocated-with-list", "pe_resource_t *", "bool")
 static int
 rsc_is_colocated_with_list_xml(pcmk__output_t *out, va_list args) {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     bool recursive = va_arg(args, int);
 
     int rc = pcmk_rc_no_output;
 
     if (pcmk_is_set(rsc->flags, pe_rsc_allocating)) {
         return rc;
     }
 
     pe__set_resource_flags(rsc, pe_rsc_allocating);
     for (GList *lpc = rsc->rsc_cons; lpc != NULL; lpc = lpc->next) {
         pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
 
         if (pcmk_is_set(cons->primary->flags, pe_rsc_allocating)) {
             colocations_xml_node(out, cons->primary, cons);
             continue;
         }
 
         colocations_xml_node(out, cons->primary, cons);
         do_locations_list_xml(out, cons->primary, false);
 
         if (recursive) {
             out->message(out, "rsc-is-colocated-with-list",
                          cons->primary, recursive);
         }
     }
 
     return rc;
 }
 
 PCMK__OUTPUT_ARGS("rscs-colocated-with-list", "pe_resource_t *", "bool")
 static int
 rscs_colocated_with_list(pcmk__output_t *out, va_list args) {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     bool recursive = va_arg(args, int);
 
     int rc = pcmk_rc_no_output;
 
     if (pcmk_is_set(rsc->flags, pe_rsc_allocating)) {
         return rc;
     }
 
     pe__set_resource_flags(rsc, pe_rsc_allocating);
     for (GList *lpc = rsc->rsc_cons_lhs; lpc != NULL; lpc = lpc->next) {
         pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
         char *hdr = NULL;
 
         PCMK__OUTPUT_LIST_HEADER(out, false, rc, "Resources colocated with %s", rsc->id);
 
         if (pcmk_is_set(cons->dependent->flags, pe_rsc_allocating)) {
             out->list_item(out, NULL, "%s (id=%s - loop)",
                            cons->dependent->id, cons->id);
             continue;
         }
 
         hdr = colocations_header(cons->dependent, cons, true);
         out->list_item(out, NULL, "%s", hdr);
         free(hdr);
 
         /* Empty list header just for indentation of information about this resource. */
         out->begin_list(out, NULL, NULL, NULL);
 
         out->message(out, "locations-list", cons->dependent);
         if (recursive) {
             out->message(out, "rscs-colocated-with-list",
                          cons->dependent, recursive);
         }
 
         out->end_list(out);
     }
 
     PCMK__OUTPUT_LIST_FOOTER(out, rc);
     return rc;
 }
 
 PCMK__OUTPUT_ARGS("rscs-colocated-with-list", "pe_resource_t *", "bool")
 static int
 rscs_colocated_with_list_xml(pcmk__output_t *out, va_list args) {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     bool recursive = va_arg(args, int);
 
     int rc = pcmk_rc_no_output;
 
     if (pcmk_is_set(rsc->flags, pe_rsc_allocating)) {
         return rc;
     }
 
     pe__set_resource_flags(rsc, pe_rsc_allocating);
     for (GList *lpc = rsc->rsc_cons_lhs; lpc != NULL; lpc = lpc->next) {
         pcmk__colocation_t *cons = (pcmk__colocation_t *) lpc->data;
 
         if (pcmk_is_set(cons->dependent->flags, pe_rsc_allocating)) {
             colocations_xml_node(out, cons->dependent, cons);
             continue;
         }
 
         colocations_xml_node(out, cons->dependent, cons);
         do_locations_list_xml(out, cons->dependent, false);
 
         if (recursive) {
             out->message(out, "rscs-colocated-with-list",
                          cons->dependent, recursive);
         }
     }
 
     return rc;
 }
 
 PCMK__OUTPUT_ARGS("locations-list", "pe_resource_t *")
 static int
 locations_list(pcmk__output_t *out, va_list args) {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
 
     GList *lpc = NULL;
     GList *list = rsc->rsc_location;
     int rc = pcmk_rc_no_output;
 
     for (lpc = list; lpc != NULL; lpc = lpc->next) {
         pe__location_t *cons = lpc->data;
 
         GList *lpc2 = NULL;
 
         for (lpc2 = cons->node_list_rh; lpc2 != NULL; lpc2 = lpc2->next) {
             pe_node_t *node = (pe_node_t *) lpc2->data;
 
             PCMK__OUTPUT_LIST_HEADER(out, false, rc, "Locations");
             out->list_item(out, NULL, "Node %s (score=%s, id=%s, rsc=%s)",
                            pe__node_name(node),
                            pcmk_readable_score(node->weight), cons->id,
                            rsc->id);
         }
     }
 
     PCMK__OUTPUT_LIST_FOOTER(out, rc);
     return rc;
 }
 
 PCMK__OUTPUT_ARGS("locations-list", "pe_resource_t *")
 static int
 locations_list_xml(pcmk__output_t *out, va_list args) {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     return do_locations_list_xml(out, rsc, true);
 }
 
 PCMK__OUTPUT_ARGS("stacks-constraints", "pe_resource_t *", "pe_working_set_t *", "bool")
 static int
 stacks_and_constraints(pcmk__output_t *out, va_list args) {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
     bool recursive = va_arg(args, int);
 
     pcmk__unpack_constraints(data_set);
 
     // Constraints apply to group/clone, not member/instance
     rsc = uber_parent(rsc);
 
     out->message(out, "locations-list", rsc);
 
     pe__clear_resource_flags_on_all(data_set, pe_rsc_allocating);
     out->message(out, "rscs-colocated-with-list", rsc, recursive);
 
     pe__clear_resource_flags_on_all(data_set, pe_rsc_allocating);
     out->message(out, "rsc-is-colocated-with-list", rsc, recursive);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("stacks-constraints", "pe_resource_t *", "pe_working_set_t *", "bool")
 static int
 stacks_and_constraints_xml(pcmk__output_t *out, va_list args) {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
     bool recursive = va_arg(args, int);
 
     pcmk__unpack_constraints(data_set);
 
     // Constraints apply to group/clone, not member/instance
     rsc = uber_parent(rsc);
 
     pcmk__output_xml_create_parent(out, "constraints", NULL);
     do_locations_list_xml(out, rsc, false);
 
     pe__clear_resource_flags_on_all(data_set, pe_rsc_allocating);
     out->message(out, "rscs-colocated-with-list", rsc, recursive);
 
     pe__clear_resource_flags_on_all(data_set, pe_rsc_allocating);
     out->message(out, "rsc-is-colocated-with-list", rsc, recursive);
 
     pcmk__output_xml_pop_parent(out);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("health", "const char *", "const char *", "const char *", "const char *")
 static int
 health(pcmk__output_t *out, va_list args)
 {
     const char *sys_from G_GNUC_UNUSED = va_arg(args, const char *);
     const char *host_from = va_arg(args, const char *);
     const char *fsa_state = va_arg(args, const char *);
     const char *result = va_arg(args, const char *);
 
     return out->info(out, "Controller on %s in state %s: %s",
                      pcmk__s(host_from, "unknown node"),
                      pcmk__s(fsa_state, "unknown"),
                      pcmk__s(result, "unknown result"));
 }
 
 PCMK__OUTPUT_ARGS("health", "const char *", "const char *", "const char *", "const char *")
 static int
 health_text(pcmk__output_t *out, va_list args)
 {
     if (!out->is_quiet(out)) {
         return health(out, args);
     } else {
         const char *sys_from G_GNUC_UNUSED = va_arg(args, const char *);
         const char *host_from G_GNUC_UNUSED = va_arg(args, const char *);
         const char *fsa_state = va_arg(args, const char *);
         const char *result G_GNUC_UNUSED = va_arg(args, const char *);
 
         if (fsa_state != NULL) {
             pcmk__formatted_printf(out, "%s\n", fsa_state);
             return pcmk_rc_ok;
         }
     }
 
     return pcmk_rc_no_output;
 }
 
 PCMK__OUTPUT_ARGS("health", "const char *", "const char *", "const char *", "const char *")
 static int
 health_xml(pcmk__output_t *out, va_list args)
 {
     const char *sys_from = va_arg(args, const char *);
     const char *host_from = va_arg(args, const char *);
     const char *fsa_state = va_arg(args, const char *);
     const char *result = va_arg(args, const char *);
 
     pcmk__output_create_xml_node(out, pcmk__s(sys_from, ""),
                                  "node_name", pcmk__s(host_from, ""),
                                  "state", pcmk__s(fsa_state, ""),
                                  "result", pcmk__s(result, ""),
                                  NULL);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "const char *", "const char *")
 static int
 pacemakerd_health(pcmk__output_t *out, va_list args)
 {
     const char *sys_from = va_arg(args, const char *);
     const char *state = va_arg(args, const char *);
     const char *last_updated = va_arg(args, const char *);
 
     return out->info(out, "Status of %s: '%s' (last updated %s)",
                      pcmk__s(sys_from, "unknown node"),
                      pcmk__s(state, "unknown state"),
                      pcmk__s(last_updated, "at unknown time"));
 }
 
 PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "const char *", "const char *")
 static int
 pacemakerd_health_text(pcmk__output_t *out, va_list args)
 {
     if (!out->is_quiet(out)) {
         return pacemakerd_health(out, args);
     } else {
         const char *sys_from G_GNUC_UNUSED = va_arg(args, const char *);
         const char *state = va_arg(args, const char *);
         const char *last_updated G_GNUC_UNUSED = va_arg(args, const char *);
 
         pcmk__formatted_printf(out, "%s\n", pcmk__s(state, "<null>"));
         return pcmk_rc_ok;
     }
 }
 
 PCMK__OUTPUT_ARGS("pacemakerd-health", "const char *", "const char *", "const char *")
 static int
 pacemakerd_health_xml(pcmk__output_t *out, va_list args)
 {
     const char *sys_from = va_arg(args, const char *);
     const char *state = va_arg(args, const char *);
     const char *last_updated = va_arg(args, const char *);
 
     pcmk__output_create_xml_node(out, pcmk__s(sys_from, "<null>"),
                                  "state", pcmk__s(state, ""),
                                  "last_updated", pcmk__s(last_updated, ""),
                                  NULL);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("profile", "const char *", "clock_t", "clock_t")
 static int
 profile_default(pcmk__output_t *out, va_list args) {
     const char *xml_file = va_arg(args, const char *);
     clock_t start = va_arg(args, clock_t);
     clock_t end = va_arg(args, clock_t);
 
     out->list_item(out, NULL, "Testing %s ... %.2f secs", xml_file,
                    (end - start) / (float) CLOCKS_PER_SEC);
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("profile", "const char *", "clock_t", "clock_t")
 static int
 profile_xml(pcmk__output_t *out, va_list args) {
     const char *xml_file = va_arg(args, const char *);
     clock_t start = va_arg(args, clock_t);
     clock_t end = va_arg(args, clock_t);
 
     char *duration = pcmk__ftoa((end - start) / (float) CLOCKS_PER_SEC);
 
     pcmk__output_create_xml_node(out, "timing",
                                  "file", xml_file,
                                  "duration", duration,
                                  NULL);
 
     free(duration);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("dc", "const char *")
 static int
 dc(pcmk__output_t *out, va_list args)
 {
     const char *dc = va_arg(args, const char *);
 
     return out->info(out, "Designated Controller is: %s",
                      pcmk__s(dc, "not yet elected"));
 }
 
 PCMK__OUTPUT_ARGS("dc", "const char *")
 static int
 dc_text(pcmk__output_t *out, va_list args)
 {
     if (!out->is_quiet(out)) {
         return dc(out, args);
     } else {
         const char *dc = va_arg(args, const char *);
 
         if (dc != NULL) {
             pcmk__formatted_printf(out, "%s\n", pcmk__s(dc, ""));
             return pcmk_rc_ok;
         }
     }
 
     return pcmk_rc_no_output;
 }
 
 PCMK__OUTPUT_ARGS("dc", "const char *")
 static int
 dc_xml(pcmk__output_t *out, va_list args)
 {
     const char *dc = va_arg(args, const char *);
 
     pcmk__output_create_xml_node(out, "dc",
                                  "node_name", pcmk__s(dc, ""),
                                  NULL);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("crmadmin-node", "const char *", "const char *", "const char *", "bool")
 static int
 crmadmin_node(pcmk__output_t *out, va_list args)
 {
     const char *type = va_arg(args, const char *);
     const char *name = va_arg(args, const char *);
     const char *id = va_arg(args, const char *);
     bool bash_export = va_arg(args, int);
 
     if (bash_export) {
         return out->info(out, "export %s=%s",
                          pcmk__s(name, "<null>"), pcmk__s(id, ""));
     } else {
         return out->info(out, "%s node: %s (%s)", type ? type : "cluster",
                          pcmk__s(name, "<null>"), pcmk__s(id, "<null>"));
     }
 }
 
 PCMK__OUTPUT_ARGS("crmadmin-node", "const char *", "const char *", "const char *", "bool")
 static int
 crmadmin_node_text(pcmk__output_t *out, va_list args)
 {
     if (!out->is_quiet(out)) {
         return crmadmin_node(out, args);
     } else {
         const char *type G_GNUC_UNUSED = va_arg(args, const char *);
         const char *name = va_arg(args, const char *);
         const char *id G_GNUC_UNUSED = va_arg(args, const char *);
         bool bash_export G_GNUC_UNUSED = va_arg(args, int);
 
         pcmk__formatted_printf(out, "%s\n", pcmk__s(name, "<null>"));
         return pcmk_rc_ok;
     }
 }
 
 PCMK__OUTPUT_ARGS("crmadmin-node", "const char *", "const char *", "const char *", "bool")
 static int
 crmadmin_node_xml(pcmk__output_t *out, va_list args)
 {
     const char *type = va_arg(args, const char *);
     const char *name = va_arg(args, const char *);
     const char *id = va_arg(args, const char *);
     bool bash_export G_GNUC_UNUSED = va_arg(args, int);
 
     pcmk__output_create_xml_node(out, "node",
                                  "type", type ? type : "cluster",
                                  "name", pcmk__s(name, ""),
                                  "id", pcmk__s(id, ""),
                                  NULL);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("digests", "pe_resource_t *", "pe_node_t *", "const char *",
                   "guint", "op_digest_cache_t *")
 static int
 digests_text(pcmk__output_t *out, va_list args)
 {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     pe_node_t *node = va_arg(args, pe_node_t *);
     const char *task = va_arg(args, const char *);
     guint interval_ms = va_arg(args, guint);
     op_digest_cache_t *digests = va_arg(args, op_digest_cache_t *);
 
     char *action_desc = NULL;
     const char *rsc_desc = "unknown resource";
     const char *node_desc = "unknown node";
 
     if (interval_ms != 0) {
         action_desc = crm_strdup_printf("%ums-interval %s action", interval_ms,
                                         ((task == NULL)? "unknown" : task));
     } else if (pcmk__str_eq(task, "monitor", pcmk__str_none)) {
         action_desc = strdup("probe action");
     } else {
         action_desc = crm_strdup_printf("%s action",
                                         ((task == NULL)? "unknown" : task));
     }
     if ((rsc != NULL) && (rsc->id != NULL)) {
         rsc_desc = rsc->id;
     }
     if ((node != NULL) && (node->details->uname != NULL)) {
         node_desc = node->details->uname;
     }
     out->begin_list(out, NULL, NULL, "Digests for %s %s on %s",
                     rsc_desc, action_desc, node_desc);
     free(action_desc);
 
     if (digests == NULL) {
         out->list_item(out, NULL, "none");
         out->end_list(out);
         return pcmk_rc_ok;
     }
     if (digests->digest_all_calc != NULL) {
         out->list_item(out, NULL, "%s (all parameters)",
                        digests->digest_all_calc);
     }
     if (digests->digest_secure_calc != NULL) {
         out->list_item(out, NULL, "%s (non-private parameters)",
                        digests->digest_secure_calc);
     }
     if (digests->digest_restart_calc != NULL) {
         out->list_item(out, NULL, "%s (non-reloadable parameters)",
                        digests->digest_restart_calc);
     }
     out->end_list(out);
     return pcmk_rc_ok;
 }
 
 static void
 add_digest_xml(xmlNode *parent, const char *type, const char *digest,
                xmlNode *digest_source)
 {
     if (digest != NULL) {
         xmlNodePtr digest_xml = create_xml_node(parent, "digest");
 
         crm_xml_add(digest_xml, "type", ((type == NULL)? "unspecified" : type));
         crm_xml_add(digest_xml, "hash", digest);
         if (digest_source != NULL) {
             add_node_copy(digest_xml, digest_source);
         }
     }
 }
 
 PCMK__OUTPUT_ARGS("digests", "pe_resource_t *", "pe_node_t *", "const char *",
                   "guint", "op_digest_cache_t *")
 static int
 digests_xml(pcmk__output_t *out, va_list args)
 {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     pe_node_t *node = va_arg(args, pe_node_t *);
     const char *task = va_arg(args, const char *);
     guint interval_ms = va_arg(args, guint);
     op_digest_cache_t *digests = va_arg(args, op_digest_cache_t *);
 
     char *interval_s = crm_strdup_printf("%ums", interval_ms);
     xmlNode *xml = NULL;
 
     xml = pcmk__output_create_xml_node(out, "digests",
                                        "resource", pcmk__s(rsc->id, ""),
                                        "node", pcmk__s(node->details->uname, ""),
                                        "task", pcmk__s(task, ""),
                                        "interval", interval_s,
                                        NULL);
     free(interval_s);
     if (digests != NULL) {
         add_digest_xml(xml, "all", digests->digest_all_calc,
                        digests->params_all);
         add_digest_xml(xml, "nonprivate", digests->digest_secure_calc,
                        digests->params_secure);
         add_digest_xml(xml, "nonreloadable", digests->digest_restart_calc,
                        digests->params_restart);
     }
     return pcmk_rc_ok;
 }
 
 #define STOP_SANITY_ASSERT(lineno) do {                                 \
         if(current && current->details->unclean) {                      \
             /* It will be a pseudo op */                                \
         } else if(stop == NULL) {                                       \
             crm_err("%s:%d: No stop action exists for %s",              \
                     __func__, lineno, rsc->id);                         \
             CRM_ASSERT(stop != NULL);                                   \
         } else if (pcmk_is_set(stop->flags, pe_action_optional)) {      \
             crm_err("%s:%d: Action %s is still optional",               \
                     __func__, lineno, stop->uuid);                      \
             CRM_ASSERT(!pcmk_is_set(stop->flags, pe_action_optional));  \
         }                                                               \
     } while(0)
 
 PCMK__OUTPUT_ARGS("rsc-action", "pe_resource_t *", "pe_node_t *", "pe_node_t *")
 static int
 rsc_action_default(pcmk__output_t *out, va_list args)
 {
     pe_resource_t *rsc = va_arg(args, pe_resource_t *);
     pe_node_t *current = va_arg(args, pe_node_t *);
     pe_node_t *next = va_arg(args, pe_node_t *);
 
     GList *possible_matches = NULL;
     char *key = NULL;
     int rc = pcmk_rc_no_output;
     bool moving = false;
 
     pe_node_t *start_node = NULL;
     pe_action_t *start = NULL;
     pe_action_t *stop = NULL;
     pe_action_t *promote = NULL;
     pe_action_t *demote = NULL;
 
     if (!pcmk_is_set(rsc->flags, pe_rsc_managed)
         || (current == NULL && next == NULL)) {
         pe_rsc_info(rsc, "Leave   %s\t(%s%s)",
                     rsc->id, role2text(rsc->role),
                     !pcmk_is_set(rsc->flags, pe_rsc_managed)? " unmanaged" : "");
         return rc;
     }
 
     moving = (current != NULL) && (next != NULL)
              && (current->details != next->details);
 
     possible_matches = pe__resource_actions(rsc, next, RSC_START, false);
     if (possible_matches) {
         start = possible_matches->data;
         g_list_free(possible_matches);
     }
 
     if ((start == NULL) || !pcmk_is_set(start->flags, pe_action_runnable)) {
         start_node = NULL;
     } else {
         start_node = current;
     }
     possible_matches = pe__resource_actions(rsc, start_node, RSC_STOP, false);
     if (possible_matches) {
         stop = possible_matches->data;
         g_list_free(possible_matches);
     } else if (pcmk_is_set(rsc->flags, pe_rsc_stop_unexpected)) {
         /* The resource is multiply active with multiple-active set to
          * stop_unexpected, and not stopping on its current node, but it should
          * be stopping elsewhere.
          */
         possible_matches = pe__resource_actions(rsc, NULL, RSC_STOP, false);
         if (possible_matches != NULL) {
             stop = possible_matches->data;
             g_list_free(possible_matches);
         }
     }
 
     possible_matches = pe__resource_actions(rsc, next, RSC_PROMOTE, false);
     if (possible_matches) {
         promote = possible_matches->data;
         g_list_free(possible_matches);
     }
 
     possible_matches = pe__resource_actions(rsc, next, RSC_DEMOTE, false);
     if (possible_matches) {
         demote = possible_matches->data;
         g_list_free(possible_matches);
     }
 
     if (rsc->role == rsc->next_role) {
         pe_action_t *migrate_op = NULL;
 
         CRM_CHECK(next != NULL, return rc);
 
         possible_matches = pe__resource_actions(rsc, next, RSC_MIGRATED, false);
         if (possible_matches) {
             migrate_op = possible_matches->data;
         }
 
         if ((migrate_op != NULL) && (current != NULL)
                    && pcmk_is_set(migrate_op->flags, pe_action_runnable)) {
             rc = out->message(out, "rsc-action-item", "Migrate", rsc, current,
                               next, start, NULL);
 
         } else if (pcmk_is_set(rsc->flags, pe_rsc_reload)) {
             rc = out->message(out, "rsc-action-item", "Reload", rsc, current,
                               next, start, NULL);
 
         } else if (start == NULL || pcmk_is_set(start->flags, pe_action_optional)) {
             if ((demote != NULL) && (promote != NULL)
                 && !pcmk_is_set(demote->flags, pe_action_optional)
                 && !pcmk_is_set(promote->flags, pe_action_optional)) {
                 rc = out->message(out, "rsc-action-item", "Re-promote", rsc,
                                   current, next, promote, demote);
             } else {
                 pe_rsc_info(rsc, "Leave   %s\t(%s %s)", rsc->id,
                             role2text(rsc->role), pe__node_name(next));
             }
 
         } else if (!pcmk_is_set(start->flags, pe_action_runnable)) {
             rc = out->message(out, "rsc-action-item", "Stop", rsc, current,
                               NULL, stop, (stop && stop->reason)? stop : start);
             STOP_SANITY_ASSERT(__LINE__);
 
         } else if (moving && current) {
             rc = out->message(out, "rsc-action-item", pcmk_is_set(rsc->flags, pe_rsc_failed)? "Recover" : "Move",
                               rsc, current, next, stop, NULL);
 
         } else if (pcmk_is_set(rsc->flags, pe_rsc_failed)) {
             rc = out->message(out, "rsc-action-item", "Recover", rsc, current,
                               NULL, stop, NULL);
             STOP_SANITY_ASSERT(__LINE__);
 
         } else {
             rc = out->message(out, "rsc-action-item", "Restart", rsc, current,
                               next, start, NULL);
             /* STOP_SANITY_ASSERT(__LINE__); False positive for migrate-fail-7 */
         }
 
         g_list_free(possible_matches);
         return rc;
     }
 
     if(stop
        && (rsc->next_role == RSC_ROLE_STOPPED
            || (start && !pcmk_is_set(start->flags, pe_action_runnable)))) {
 
         GList *gIter = NULL;
 
         key = stop_key(rsc);
         for (gIter = rsc->running_on; gIter != NULL; gIter = gIter->next) {
             pe_node_t *node = (pe_node_t *) gIter->data;
             pe_action_t *stop_op = NULL;
 
             possible_matches = find_actions(rsc->actions, key, node);
             if (possible_matches) {
                 stop_op = possible_matches->data;
                 g_list_free(possible_matches);
             }
 
             if (stop_op && (stop_op->flags & pe_action_runnable)) {
                 STOP_SANITY_ASSERT(__LINE__);
             }
 
             if (out->message(out, "rsc-action-item", "Stop", rsc, node, NULL,
                              stop_op, (stop_op && stop_op->reason)? stop_op : start) == pcmk_rc_ok) {
                 rc = pcmk_rc_ok;
             }
         }
 
         free(key);
 
     } else if ((stop != NULL)
                && pcmk_all_flags_set(rsc->flags, pe_rsc_failed|pe_rsc_stop)) {
         /* 'stop' may be NULL if the failure was ignored */
         rc = out->message(out, "rsc-action-item", "Recover", rsc, current,
                           next, stop, start);
         STOP_SANITY_ASSERT(__LINE__);
 
     } else if (moving) {
         rc = out->message(out, "rsc-action-item", "Move", rsc, current, next,
                           stop, NULL);
         STOP_SANITY_ASSERT(__LINE__);
 
     } else if (pcmk_is_set(rsc->flags, pe_rsc_reload)) {
         rc = out->message(out, "rsc-action-item", "Reload", rsc, current, next,
                           start, NULL);
 
     } else if (stop != NULL && !pcmk_is_set(stop->flags, pe_action_optional)) {
         rc = out->message(out, "rsc-action-item", "Restart", rsc, current,
                           next, start, NULL);
         STOP_SANITY_ASSERT(__LINE__);
 
     } else if (rsc->role == RSC_ROLE_PROMOTED) {
         CRM_LOG_ASSERT(current != NULL);
         rc = out->message(out, "rsc-action-item", "Demote", rsc, current,
                           next, demote, NULL);
 
     } else if (rsc->next_role == RSC_ROLE_PROMOTED) {
         CRM_LOG_ASSERT(next);
         rc = out->message(out, "rsc-action-item", "Promote", rsc, current,
                           next, promote, NULL);
 
     } else if (rsc->role == RSC_ROLE_STOPPED && rsc->next_role > RSC_ROLE_STOPPED) {
         rc = out->message(out, "rsc-action-item", "Start", rsc, current, next,
                           start, NULL);
     }
 
     return rc;
 }
 
 PCMK__OUTPUT_ARGS("node-action", "char *", "char *", "char *")
 static int
 node_action(pcmk__output_t *out, va_list args)
 {
     char *task = va_arg(args, char *);
     char *node_name = va_arg(args, char *);
     char *reason = va_arg(args, char *);
 
     if (task == NULL) {
         return pcmk_rc_no_output;
     } else if (reason) {
         out->list_item(out, NULL, "%s %s '%s'", task, node_name, reason);
     } else {
         crm_notice(" * %s %s", task, node_name);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("node-action", "char *", "char *", "char *")
 static int
 node_action_xml(pcmk__output_t *out, va_list args)
 {
     char *task = va_arg(args, char *);
     char *node_name = va_arg(args, char *);
     char *reason = va_arg(args, char *);
 
     if (task == NULL) {
         return pcmk_rc_no_output;
     } else if (reason) {
         pcmk__output_create_xml_node(out, "node_action",
                                      "task", task,
                                      "node", node_name,
                                      "reason", reason,
                                      NULL);
     } else {
         crm_notice(" * %s %s", task, node_name);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-cluster-action", "const char *", "const char *", "xmlNodePtr")
 static int
 inject_cluster_action(pcmk__output_t *out, va_list args)
 {
     const char *node = va_arg(args, const char *);
     const char *task = va_arg(args, const char *);
     xmlNodePtr rsc = va_arg(args, xmlNodePtr);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     if(rsc) {
         out->list_item(out, NULL, "Cluster action:  %s for %s on %s", task, ID(rsc), node);
     } else {
         out->list_item(out, NULL, "Cluster action:  %s on %s", task, node);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-cluster-action", "const char *", "const char *", "xmlNodePtr")
 static int
 inject_cluster_action_xml(pcmk__output_t *out, va_list args)
 {
     const char *node = va_arg(args, const char *);
     const char *task = va_arg(args, const char *);
     xmlNodePtr rsc = va_arg(args, xmlNodePtr);
 
     xmlNodePtr xml_node = NULL;
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     xml_node = pcmk__output_create_xml_node(out, "cluster_action",
                                             "task", task,
                                             "node", node,
                                             NULL);
 
     if (rsc) {
         crm_xml_add(xml_node, "id", ID(rsc));
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-fencing-action", "char *", "const char *")
 static int
 inject_fencing_action(pcmk__output_t *out, va_list args)
 {
     char *target = va_arg(args, char *);
     const char *op = va_arg(args, const char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     out->list_item(out, NULL, "Fencing %s (%s)", target, op);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-fencing-action", "char *", "const char *")
 static int
 inject_fencing_action_xml(pcmk__output_t *out, va_list args)
 {
     char *target = va_arg(args, char *);
     const char *op = va_arg(args, const char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     pcmk__output_create_xml_node(out, "fencing_action",
                                  "target", target,
                                  "op", op,
                                  NULL);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-attr", "const char *", "const char *", "xmlNodePtr")
 static int
 inject_attr(pcmk__output_t *out, va_list args)
 {
     const char *name = va_arg(args, const char *);
     const char *value = va_arg(args, const char *);
     xmlNodePtr cib_node = va_arg(args, xmlNodePtr);
 
     xmlChar *node_path = NULL;
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     node_path = xmlGetNodePath(cib_node);
 
     out->list_item(out, NULL, "Injecting attribute %s=%s into %s '%s'",
                    name, value, node_path, ID(cib_node));
 
     free(node_path);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-attr", "const char *", "const char *", "xmlNodePtr")
 static int
 inject_attr_xml(pcmk__output_t *out, va_list args)
 {
     const char *name = va_arg(args, const char *);
     const char *value = va_arg(args, const char *);
     xmlNodePtr cib_node = va_arg(args, xmlNodePtr);
 
     xmlChar *node_path = NULL;
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     node_path = xmlGetNodePath(cib_node);
 
     pcmk__output_create_xml_node(out, "inject_attr",
                                  "name", name,
                                  "value", value,
                                  "node_path", node_path,
                                  "cib_node", ID(cib_node),
                                  NULL);
     free(node_path);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-spec", "const char *")
 static int
 inject_spec(pcmk__output_t *out, va_list args)
 {
     const char *spec = va_arg(args, const char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     out->list_item(out, NULL, "Injecting %s into the configuration", spec);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-spec", "const char *")
 static int
 inject_spec_xml(pcmk__output_t *out, va_list args)
 {
     const char *spec = va_arg(args, const char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     pcmk__output_create_xml_node(out, "inject_spec",
                                  "spec", spec,
                                  NULL);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-modify-config", "char *", "char *")
 static int
 inject_modify_config(pcmk__output_t *out, va_list args)
 {
     char *quorum = va_arg(args, char *);
     char *watchdog = va_arg(args, char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     out->begin_list(out, NULL, NULL, "Performing Requested Modifications");
 
     if (quorum) {
         out->list_item(out, NULL, "Setting quorum: %s", quorum);
     }
 
     if (watchdog) {
         out->list_item(out, NULL, "Setting watchdog: %s", watchdog);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-modify-config", "char *", "char *")
 static int
 inject_modify_config_xml(pcmk__output_t *out, va_list args)
 {
     char *quorum = va_arg(args, char *);
     char *watchdog = va_arg(args, char *);
 
     xmlNodePtr node = NULL;
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     node = pcmk__output_xml_create_parent(out, "modifications", NULL);
 
     if (quorum) {
         crm_xml_add(node, "quorum", quorum);
     }
 
     if (watchdog) {
         crm_xml_add(node, "watchdog", watchdog);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-modify-node", "const char *", "char *")
 static int
 inject_modify_node(pcmk__output_t *out, va_list args)
 {
     const char *action = va_arg(args, const char *);
     char *node = va_arg(args, char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     if (pcmk__str_eq(action, "Online", pcmk__str_none)) {
         out->list_item(out, NULL, "Bringing node %s online", node);
         return pcmk_rc_ok;
     } else if (pcmk__str_eq(action, "Offline", pcmk__str_none)) {
         out->list_item(out, NULL, "Taking node %s offline", node);
         return pcmk_rc_ok;
     } else if (pcmk__str_eq(action, "Failing", pcmk__str_none)) {
         out->list_item(out, NULL, "Failing node %s", node);
         return pcmk_rc_ok;
     }
 
     return pcmk_rc_no_output;
 }
 
 PCMK__OUTPUT_ARGS("inject-modify-node", "const char *", "char *")
 static int
 inject_modify_node_xml(pcmk__output_t *out, va_list args)
 {
     const char *action = va_arg(args, const char *);
     char *node = va_arg(args, char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     pcmk__output_create_xml_node(out, "modify_node",
                                  "action", action,
                                  "node", node,
                                  NULL);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-modify-ticket", "const char *", "char *")
 static int
 inject_modify_ticket(pcmk__output_t *out, va_list args)
 {
     const char *action = va_arg(args, const char *);
     char *ticket = va_arg(args, char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     if (pcmk__str_eq(action, "Standby", pcmk__str_none)) {
         out->list_item(out, NULL, "Making ticket %s standby", ticket);
     } else {
         out->list_item(out, NULL, "%s ticket %s", action, ticket);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-modify-ticket", "const char *", "char *")
 static int
 inject_modify_ticket_xml(pcmk__output_t *out, va_list args)
 {
     const char *action = va_arg(args, const char *);
     char *ticket = va_arg(args, char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     pcmk__output_create_xml_node(out, "modify_ticket",
                                  "action", action,
                                  "ticket", ticket,
                                  NULL);
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-pseudo-action", "const char *", "const char *")
 static int
 inject_pseudo_action(pcmk__output_t *out, va_list args)
 {
     const char *node = va_arg(args, const char *);
     const char *task = va_arg(args, const char *);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     out->list_item(out, NULL, "Pseudo action:   %s%s%s", task, node ? " on " : "",
                    node ? node : "");
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-pseudo-action", "const char *", "const char *")
 static int
 inject_pseudo_action_xml(pcmk__output_t *out, va_list args)
 {
     const char *node = va_arg(args, const char *);
     const char *task = va_arg(args, const char *);
 
     xmlNodePtr xml_node = NULL;
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     xml_node = pcmk__output_create_xml_node(out, "pseudo_action",
                                             "task", task,
                                             NULL);
     if (node) {
         crm_xml_add(xml_node, "node", node);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-rsc-action", "const char *", "const char *", "char *", "guint")
 static int
 inject_rsc_action(pcmk__output_t *out, va_list args)
 {
     const char *rsc = va_arg(args, const char *);
     const char *operation = va_arg(args, const char *);
     char *node = va_arg(args, char *);
     guint interval_ms = va_arg(args, guint);
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     if (interval_ms) {
         out->list_item(out, NULL, "Resource action: %-15s %s=%u on %s",
                        rsc, operation, interval_ms, node);
     } else {
         out->list_item(out, NULL, "Resource action: %-15s %s on %s",
                        rsc, operation, node);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("inject-rsc-action", "const char *", "const char *", "char *", "guint")
 static int
 inject_rsc_action_xml(pcmk__output_t *out, va_list args)
 {
     const char *rsc = va_arg(args, const char *);
     const char *operation = va_arg(args, const char *);
     char *node = va_arg(args, char *);
     guint interval_ms = va_arg(args, guint);
 
     xmlNodePtr xml_node = NULL;
 
     if (out->is_quiet(out)) {
         return pcmk_rc_no_output;
     }
 
     xml_node = pcmk__output_create_xml_node(out, "rsc_action",
                                             "resource", rsc,
                                             "op", operation,
                                             "node", node,
                                             NULL);
 
     if (interval_ms) {
         char *interval_s = pcmk__itoa(interval_ms);
 
         crm_xml_add(xml_node, "interval", interval_s);
         free(interval_s);
     }
 
     return pcmk_rc_ok;
 }
 
 #define CHECK_RC(retcode, retval)   \
     if (retval == pcmk_rc_ok) {     \
         retcode = pcmk_rc_ok;       \
     }
 
 PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
                   "enum pcmk__fence_history", "uint32_t", "uint32_t", "const char *", "GList *",
                   "GList *")
 int
 pcmk__cluster_status_text(pcmk__output_t *out, va_list args)
 {
     pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
     crm_exit_t history_rc = va_arg(args, crm_exit_t);
     stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
     enum pcmk__fence_history fence_history = va_arg(args, int);
     uint32_t section_opts = va_arg(args, uint32_t);
     uint32_t show_opts = va_arg(args, uint32_t);
     const char *prefix = va_arg(args, const char *);
     GList *unames = va_arg(args, GList *);
     GList *resources = va_arg(args, GList *);
 
     int rc = pcmk_rc_no_output;
     bool already_printed_failure = false;
 
     CHECK_RC(rc, out->message(out, "cluster-summary", data_set,
                               section_opts, show_opts));
 
     if (pcmk_is_set(section_opts, pcmk_section_nodes) && unames) {
         CHECK_RC(rc, out->message(out, "node-list", data_set->nodes, unames,
                                   resources, show_opts, rc == pcmk_rc_ok));
     }
 
     /* Print resources section, if needed */
     if (pcmk_is_set(section_opts, pcmk_section_resources)) {
         CHECK_RC(rc, out->message(out, "resource-list", data_set, show_opts,
                                   true, unames, resources, rc == pcmk_rc_ok));
     }
 
     /* print Node Attributes section if requested */
     if (pcmk_is_set(section_opts, pcmk_section_attributes)) {
         CHECK_RC(rc, out->message(out, "node-attribute-list", data_set,
                                   show_opts, rc == pcmk_rc_ok, unames, resources));
     }
 
     /* If requested, print resource operations (which includes failcounts)
      * or just failcounts
      */
     if (pcmk_any_flags_set(section_opts, pcmk_section_operations | pcmk_section_failcounts)) {
         CHECK_RC(rc, out->message(out, "node-summary", data_set, unames,
                                   resources, section_opts, show_opts, rc == pcmk_rc_ok));
     }
 
     /* If there were any failed actions, print them */
     if (pcmk_is_set(section_opts, pcmk_section_failures)
         && xml_has_children(data_set->failed)) {
 
         CHECK_RC(rc, out->message(out, "failed-action-list", data_set, unames,
                                   resources, show_opts, rc == pcmk_rc_ok));
     }
 
     /* Print failed stonith actions */
     if (pcmk_is_set(section_opts, pcmk_section_fence_failed) &&
         fence_history != pcmk__fence_history_none) {
         if (history_rc == 0) {
             stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_eq,
                                                                   GINT_TO_POINTER(st_failed));
 
             if (hp) {
                 CHECK_RC(rc, out->message(out, "failed-fencing-list",
                                           stonith_history, unames, section_opts,
                                           show_opts, rc == pcmk_rc_ok));
             }
         } else {
             PCMK__OUTPUT_SPACER_IF(out, rc == pcmk_rc_ok);
             out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
             out->list_item(out, NULL, "Failed to get fencing history: %s",
                            crm_exit_str(history_rc));
             out->end_list(out);
 
             already_printed_failure = true;
         }
     }
 
     /* Print tickets if requested */
     if (pcmk_is_set(section_opts, pcmk_section_tickets)) {
         CHECK_RC(rc, out->message(out, "ticket-list", data_set, rc == pcmk_rc_ok));
     }
 
     /* Print negative location constraints if requested */
     if (pcmk_is_set(section_opts, pcmk_section_bans)) {
         CHECK_RC(rc, out->message(out, "ban-list", data_set, prefix, resources,
                                   show_opts, rc == pcmk_rc_ok));
     }
 
     /* Print stonith history */
     if (pcmk_any_flags_set(section_opts, pcmk_section_fencing_all) &&
         fence_history != pcmk__fence_history_none) {
         if (history_rc != 0) {
             if (!already_printed_failure) {
                 PCMK__OUTPUT_SPACER_IF(out, rc == pcmk_rc_ok);
                 out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
                 out->list_item(out, NULL, "Failed to get fencing history: %s",
                                crm_exit_str(history_rc));
                 out->end_list(out);
             }
         } else if (pcmk_is_set(section_opts, pcmk_section_fence_worked)) {
             stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_neq,
                                                                   GINT_TO_POINTER(st_failed));
 
             if (hp) {
                 CHECK_RC(rc, out->message(out, "fencing-list", hp, unames,
                                           section_opts, show_opts,
                                           rc == pcmk_rc_ok));
             }
         } else if (pcmk_is_set(section_opts, pcmk_section_fence_pending)) {
             stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_pending, NULL);
 
             if (hp) {
                 CHECK_RC(rc, out->message(out, "pending-fencing-list", hp,
                                           unames, section_opts, show_opts,
                                           rc == pcmk_rc_ok));
             }
         }
     }
 
     return rc;
 }
 
 PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
                   "enum pcmk__fence_history", "uint32_t", "uint32_t", "const char *", "GList *",
                   "GList *")
 static int
 cluster_status_xml(pcmk__output_t *out, va_list args)
 {
     pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
     crm_exit_t history_rc = va_arg(args, crm_exit_t);
     stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
     enum pcmk__fence_history fence_history = va_arg(args, int);
     uint32_t section_opts = va_arg(args, uint32_t);
     uint32_t show_opts = va_arg(args, uint32_t);
     const char *prefix = va_arg(args, const char *);
     GList *unames = va_arg(args, GList *);
     GList *resources = va_arg(args, GList *);
 
     out->message(out, "cluster-summary", data_set, section_opts, show_opts);
 
     /*** NODES ***/
     if (pcmk_is_set(section_opts, pcmk_section_nodes)) {
         out->message(out, "node-list", data_set->nodes, unames, resources,
                      show_opts, false);
     }
 
     /* Print resources section, if needed */
     if (pcmk_is_set(section_opts, pcmk_section_resources)) {
         /* XML output always displays full details. */
         uint32_t full_show_opts = show_opts & ~pcmk_show_brief;
 
         out->message(out, "resource-list", data_set, full_show_opts,
                      false, unames, resources, false);
     }
 
     /* print Node Attributes section if requested */
     if (pcmk_is_set(section_opts, pcmk_section_attributes)) {
         out->message(out, "node-attribute-list", data_set, show_opts, false,
                      unames, resources);
     }
 
     /* If requested, print resource operations (which includes failcounts)
      * or just failcounts
      */
     if (pcmk_any_flags_set(section_opts, pcmk_section_operations | pcmk_section_failcounts)) {
         out->message(out, "node-summary", data_set, unames,
                      resources, section_opts, show_opts, false);
     }
 
     /* If there were any failed actions, print them */
     if (pcmk_is_set(section_opts, pcmk_section_failures)
         && xml_has_children(data_set->failed)) {
 
         out->message(out, "failed-action-list", data_set, unames, resources,
                      show_opts, false);
     }
 
     /* Print stonith history */
     if (pcmk_is_set(section_opts, pcmk_section_fencing_all) &&
         fence_history != pcmk__fence_history_none) {
         out->message(out, "full-fencing-list", history_rc, stonith_history,
                      unames, section_opts, show_opts, false);
     }
 
     /* Print tickets if requested */
     if (pcmk_is_set(section_opts, pcmk_section_tickets)) {
         out->message(out, "ticket-list", data_set, false);
     }
 
     /* Print negative location constraints if requested */
     if (pcmk_is_set(section_opts, pcmk_section_bans)) {
         out->message(out, "ban-list", data_set, prefix, resources, show_opts,
                      false);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("cluster-status", "pe_working_set_t *", "crm_exit_t", "stonith_history_t *",
                   "enum pcmk__fence_history", "uint32_t", "uint32_t", "const char *", "GList *",
                   "GList *")
 static int
 cluster_status_html(pcmk__output_t *out, va_list args)
 {
     pe_working_set_t *data_set = va_arg(args, pe_working_set_t *);
     crm_exit_t history_rc = va_arg(args, crm_exit_t);
     stonith_history_t *stonith_history = va_arg(args, stonith_history_t *);
     enum pcmk__fence_history fence_history = va_arg(args, int);
     uint32_t section_opts = va_arg(args, uint32_t);
     uint32_t show_opts = va_arg(args, uint32_t);
     const char *prefix = va_arg(args, const char *);
     GList *unames = va_arg(args, GList *);
     GList *resources = va_arg(args, GList *);
     bool already_printed_failure = false;
 
     out->message(out, "cluster-summary", data_set, section_opts, show_opts);
 
     /*** NODE LIST ***/
     if (pcmk_is_set(section_opts, pcmk_section_nodes) && unames) {
         out->message(out, "node-list", data_set->nodes, unames, resources,
                      show_opts, false);
     }
 
     /* Print resources section, if needed */
     if (pcmk_is_set(section_opts, pcmk_section_resources)) {
         out->message(out, "resource-list", data_set, show_opts, true, unames,
                      resources, false);
     }
 
     /* print Node Attributes section if requested */
     if (pcmk_is_set(section_opts, pcmk_section_attributes)) {
         out->message(out, "node-attribute-list", data_set, show_opts, false,
                      unames, resources);
     }
 
     /* If requested, print resource operations (which includes failcounts)
      * or just failcounts
      */
     if (pcmk_any_flags_set(section_opts, pcmk_section_operations | pcmk_section_failcounts)) {
         out->message(out, "node-summary", data_set, unames,
                      resources, section_opts, show_opts, false);
     }
 
     /* If there were any failed actions, print them */
     if (pcmk_is_set(section_opts, pcmk_section_failures)
         && xml_has_children(data_set->failed)) {
 
         out->message(out, "failed-action-list", data_set, unames, resources,
                      show_opts, false);
     }
 
     /* Print failed stonith actions */
     if (pcmk_is_set(section_opts, pcmk_section_fence_failed) &&
         fence_history != pcmk__fence_history_none) {
         if (history_rc == 0) {
             stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_eq,
                                                                   GINT_TO_POINTER(st_failed));
 
             if (hp) {
                 out->message(out, "failed-fencing-list", stonith_history, unames,
                              section_opts, show_opts, false);
             }
         } else {
             out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
             out->list_item(out, NULL, "Failed to get fencing history: %s",
                            crm_exit_str(history_rc));
             out->end_list(out);
         }
     }
 
     /* Print stonith history */
     if (pcmk_any_flags_set(section_opts, pcmk_section_fencing_all) &&
         fence_history != pcmk__fence_history_none) {
         if (history_rc != 0) {
             if (!already_printed_failure) {
                 out->begin_list(out, NULL, NULL, "Failed Fencing Actions");
                 out->list_item(out, NULL, "Failed to get fencing history: %s",
                                crm_exit_str(history_rc));
                 out->end_list(out);
             }
         } else if (pcmk_is_set(section_opts, pcmk_section_fence_worked)) {
             stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_neq,
                                                                   GINT_TO_POINTER(st_failed));
 
             if (hp) {
                 out->message(out, "fencing-list", hp, unames, section_opts,
                              show_opts, false);
             }
         } else if (pcmk_is_set(section_opts, pcmk_section_fence_pending)) {
             stonith_history_t *hp = stonith__first_matching_event(stonith_history, stonith__event_state_pending, NULL);
 
             if (hp) {
                 out->message(out, "pending-fencing-list", hp, unames,
                              section_opts, show_opts, false);
             }
         }
     }
 
     /* Print tickets if requested */
     if (pcmk_is_set(section_opts, pcmk_section_tickets)) {
         out->message(out, "ticket-list", data_set, false);
     }
 
     /* Print negative location constraints if requested */
     if (pcmk_is_set(section_opts, pcmk_section_bans)) {
         out->message(out, "ban-list", data_set, prefix, resources, show_opts,
                      false);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("attribute", "const char *", "const char *", "const char *",
                   "const char *", "const char *")
 static int
 attribute_default(pcmk__output_t *out, va_list args)
 {
     const char *scope = va_arg(args, const char *);
     const char *instance = va_arg(args, const char *);
     const char *name = va_arg(args, const char *);
     const char *value = va_arg(args, const char *);
     const char *host = va_arg(args, const char *);
 
     GString *s = g_string_sized_new(50);
 
     if (!pcmk__str_empty(scope)) {
         g_string_append_printf(s, "scope=\"%s\" ", scope);
     }
 
     if (!pcmk__str_empty(instance)) {
         g_string_append_printf(s, "id=\"%s\" ", instance);
     }
 
     g_string_append_printf(s, "name=\"%s\" ", name);
 
     if (!pcmk__str_empty(host)) {
         g_string_append_printf(s, "host=\"%s\" ", host);
     }
 
     g_string_append_printf(s, "value=\"%s\"", value ? value : "");
 
     out->info(out, "%s", s->str);
     g_string_free(s, TRUE);
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("attribute", "const char *", "const char *", "const char *",
                   "const char *", "const char *")
 static int
 attribute_xml(pcmk__output_t *out, va_list args)
 {
     const char *scope = va_arg(args, const char *);
     const char *instance = va_arg(args, const char *);
     const char *name = va_arg(args, const char *);
     const char *value = va_arg(args, const char *);
     const char *host = va_arg(args, const char *);
 
     xmlNodePtr node = NULL;
 
     node = pcmk__output_create_xml_node(out, "attribute",
                                         "name", name,
                                         "value", value ? value : "",
                                         NULL);
 
     if (!pcmk__str_empty(scope)) {
         crm_xml_add(node, "scope", scope);
     }
 
     if (!pcmk__str_empty(instance)) {
         crm_xml_add(node, "id", instance);
     }
 
     if (!pcmk__str_empty(host)) {
         crm_xml_add(node, "host", host);
     }
 
     return pcmk_rc_ok;
 }
 
 PCMK__OUTPUT_ARGS("rule-check", "const char *", "int", "const char *")
 static int
 rule_check_default(pcmk__output_t *out, va_list args)
 {
     const char *rule_id = va_arg(args, const char *);
     int result = va_arg(args, int);
     const char *error = va_arg(args, const char *);
 
     switch (result) {
         case pcmk_rc_within_range:
             return out->info(out, "Rule %s is still in effect", rule_id);
         case pcmk_rc_ok:
             return out->info(out, "Rule %s satisfies conditions", rule_id);
         case pcmk_rc_after_range:
             return out->info(out, "Rule %s is expired", rule_id);
         case pcmk_rc_before_range:
             return out->info(out, "Rule %s has not yet taken effect", rule_id);
         case pcmk_rc_op_unsatisfied:
             return out->info(out, "Rule %s does not satisfy conditions",
                              rule_id);
         default:
             out->err(out,
                      "Could not determine whether rule %s is in effect: %s",
                      rule_id, ((error != NULL)? error : "unexpected error"));
             return pcmk_rc_ok;
     }
 }
 
 PCMK__OUTPUT_ARGS("rule-check", "const char *", "int", "const char *")
 static int
 rule_check_xml(pcmk__output_t *out, va_list args)
 {
     const char *rule_id = va_arg(args, const char *);
     int result = va_arg(args, int);
     const char *error = va_arg(args, const char *);
 
     char *rc_str = pcmk__itoa(pcmk_rc2exitc(result));
 
     pcmk__output_create_xml_node(out, "rule-check",
                                  "rule-id", rule_id,
                                  "rc", rc_str,
                                  NULL);
     free(rc_str);
 
     switch (result) {
         case pcmk_rc_within_range:
         case pcmk_rc_ok:
         case pcmk_rc_after_range:
         case pcmk_rc_before_range:
         case pcmk_rc_op_unsatisfied:
             return pcmk_rc_ok;
         default:
             out->err(out,
                     "Could not determine whether rule %s is in effect: %s",
                     rule_id, ((error != NULL)? error : "unexpected error"));
             return pcmk_rc_ok;
     }
 }
 
+PCMK__OUTPUT_ARGS("result-code", "int", "char *", "char *");
+static int
+result_code_none(pcmk__output_t *out, va_list args)
+{
+    return pcmk_rc_no_output;
+}
+
+PCMK__OUTPUT_ARGS("result-code", "int", "char *", "char *");
+static int
+result_code_text(pcmk__output_t *out, va_list args)
+{
+    int code = va_arg(args, int);
+    char *name = va_arg(args, char *);
+    char *desc = va_arg(args, char *);
+
+    static int code_width = 0;
+
+    if (out->is_quiet(out)) {
+        /* If out->is_quiet(), don't print the code. Print name and/or desc in a
+         * compact format for text output, or print nothing at all for none-type
+         * output.
+         */
+        if ((name != NULL) && (desc != NULL)) {
+            pcmk__formatted_printf(out, "%s - %s\n", name, desc);
+
+        } else if ((name != NULL) || (desc != NULL)) {
+            pcmk__formatted_printf(out, "%s\n", ((name != NULL)? name : desc));
+        }
+        return pcmk_rc_ok;
+    }
+
+    /* Get length of longest (most negative) standard Pacemaker return code
+     * This should be longer than all the values of any other type of return
+     * code.
+     */
+    if (code_width == 0) {
+        long long most_negative = pcmk_rc_error - (long long) pcmk__n_rc + 1;
+        code_width = (int) snprintf(NULL, 0, "%lld", most_negative);
+    }
+
+    if ((name != NULL) && (desc != NULL)) {
+        static int name_width = 0;
+
+        if (name_width == 0) {
+            // Get length of longest standard Pacemaker return code name
+            for (int lpc = 0; lpc < pcmk__n_rc; lpc++) {
+                int len = (int) strlen(pcmk_rc_name(pcmk_rc_error - lpc));
+                name_width = QB_MAX(name_width, len);
+            }
+        }
+        return out->info(out, "% *d: %-*s  %s", code_width, code, name_width,
+                         name, desc);
+    }
+
+    if ((name != NULL) || (desc != NULL)) {
+        return out->info(out, "% *d: %s", code_width, code,
+                         ((name != NULL)? name : desc));
+    }
+
+    return out->info(out, "% *d", code_width, code);
+}
+
+PCMK__OUTPUT_ARGS("result-code", "int", "char *", "char *");
+static int
+result_code_xml(pcmk__output_t *out, va_list args)
+{
+    int code = va_arg(args, int);
+    char *name = va_arg(args, char *);
+    char *desc = va_arg(args, char *);
+
+    char *code_str = pcmk__itoa(code);
+
+    pcmk__output_create_xml_node(out, "result-code",
+                                 "code", code_str,
+                                 XML_ATTR_NAME, name,
+                                 XML_ATTR_DESC, desc,
+                                 NULL);
+    free(code_str);
+    return pcmk_rc_ok;
+}
+
 static pcmk__message_entry_t fmt_functions[] = {
     { "attribute", "default", attribute_default },
     { "attribute", "xml", attribute_xml },
     { "cluster-status", "default", pcmk__cluster_status_text },
     { "cluster-status", "html", cluster_status_html },
     { "cluster-status", "xml", cluster_status_xml },
     { "crmadmin-node", "default", crmadmin_node },
     { "crmadmin-node", "text", crmadmin_node_text },
     { "crmadmin-node", "xml", crmadmin_node_xml },
     { "dc", "default", dc },
     { "dc", "text", dc_text },
     { "dc", "xml", dc_xml },
     { "digests", "default", digests_text },
     { "digests", "xml", digests_xml },
     { "health", "default", health },
     { "health", "text", health_text },
     { "health", "xml", health_xml },
     { "inject-attr", "default", inject_attr },
     { "inject-attr", "xml", inject_attr_xml },
     { "inject-cluster-action", "default", inject_cluster_action },
     { "inject-cluster-action", "xml", inject_cluster_action_xml },
     { "inject-fencing-action", "default", inject_fencing_action },
     { "inject-fencing-action", "xml", inject_fencing_action_xml },
     { "inject-modify-config", "default", inject_modify_config },
     { "inject-modify-config", "xml", inject_modify_config_xml },
     { "inject-modify-node", "default", inject_modify_node },
     { "inject-modify-node", "xml", inject_modify_node_xml },
     { "inject-modify-ticket", "default", inject_modify_ticket },
     { "inject-modify-ticket", "xml", inject_modify_ticket_xml },
     { "inject-pseudo-action", "default", inject_pseudo_action },
     { "inject-pseudo-action", "xml", inject_pseudo_action_xml },
     { "inject-rsc-action", "default", inject_rsc_action },
     { "inject-rsc-action", "xml", inject_rsc_action_xml },
     { "inject-spec", "default", inject_spec },
     { "inject-spec", "xml", inject_spec_xml },
     { "locations-list", "default", locations_list },
     { "locations-list", "xml", locations_list_xml },
     { "node-action", "default", node_action },
     { "node-action", "xml", node_action_xml },
     { "pacemakerd-health", "default", pacemakerd_health },
     { "pacemakerd-health", "text", pacemakerd_health_text },
     { "pacemakerd-health", "xml", pacemakerd_health_xml },
     { "profile", "default", profile_default, },
     { "profile", "xml", profile_xml },
+    { "result-code", "none", result_code_none },
+    { "result-code", "text", result_code_text },
+    { "result-code", "xml", result_code_xml },
     { "rsc-action", "default", rsc_action_default },
     { "rsc-action-item", "default", rsc_action_item },
     { "rsc-action-item", "xml", rsc_action_item_xml },
     { "rsc-is-colocated-with-list", "default", rsc_is_colocated_with_list },
     { "rsc-is-colocated-with-list", "xml", rsc_is_colocated_with_list_xml },
     { "rscs-colocated-with-list", "default", rscs_colocated_with_list },
     { "rscs-colocated-with-list", "xml", rscs_colocated_with_list_xml },
     { "rule-check", "default", rule_check_default },
     { "rule-check", "xml", rule_check_xml },
     { "stacks-constraints", "default", stacks_and_constraints },
     { "stacks-constraints", "xml", stacks_and_constraints_xml },
 
     { NULL, NULL, NULL }
 };
 
 void
 pcmk__register_lib_messages(pcmk__output_t *out) {
     pcmk__register_messages(out, fmt_functions);
 }
diff --git a/lib/pacemaker/pcmk_result_code.c b/lib/pacemaker/pcmk_result_code.c
new file mode 100644
index 0000000000..4f502764bc
--- /dev/null
+++ b/lib/pacemaker/pcmk_result_code.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright 2022 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU Lesser General Public License
+ * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+
+#include <crm/cib/internal.h>
+#include <crm/crm.h>
+
+#include <pacemaker.h>
+#include <pacemaker-internal.h>
+
+#include <inttypes.h>   // PRIx32
+#include <stdint.h>     // uint32_t
+
+/*!
+ * \internal
+ * \brief Display the name and/or description of a result code
+ *
+ * \param[in,out] out    Output object
+ * \param[in]     code   The result code
+ * \param[in]     type   Interpret \c code as this type of result code.
+ *                       Supported values: \c pcmk_result_legacy,
+ *                       \c pcmk_result_rc, \c pcmk_result_exitcode.
+ * \param[in]     flags  Group of \c pcmk_rc_disp_flags
+ *
+ * \return Standard Pacemaker return code
+ */
+int
+pcmk__show_result_code(pcmk__output_t *out, int code,
+                       enum pcmk_result_type type, uint32_t flags)
+{
+    int rc = pcmk_rc_ok;
+    bool quiet_orig = out->quiet;
+    const char *name = NULL;
+    const char *desc = NULL;
+
+    rc = pcmk_result_get_strings(code, type, &name, &desc);
+    if (rc != pcmk_rc_ok) {
+        out->err(out, "Error looking up result code %d", code);
+        return rc;
+    }
+
+    // out->quiet controls whether the code is shown (if quiet is supported)
+    out->quiet = !pcmk_is_set(flags, pcmk_rc_disp_code);
+
+    out->message(out, "result-code", code,
+                 pcmk_is_set(flags, pcmk_rc_disp_name)? name : NULL,
+                 pcmk_is_set(flags, pcmk_rc_disp_desc)? desc : NULL);
+    out->quiet = quiet_orig;
+
+    return rc;
+}
+
+// Documented in header
+int
+pcmk_show_result_code(xmlNodePtr *xml, int code, enum pcmk_result_type type,
+                      uint32_t flags)
+{
+    pcmk__output_t *out = NULL;
+    int rc = pcmk_rc_ok;
+
+    rc = pcmk__xml_output_new(&out, xml);
+    if (rc != pcmk_rc_ok) {
+        return rc;
+    }
+
+    pcmk__register_lib_messages(out);
+
+    rc = pcmk__show_result_code(out, code, type, flags);
+    pcmk__xml_output_finish(out, xml);
+    return rc;
+}
+
+/*!
+ * \internal
+ * \brief List all valid result codes in a particular family
+ *
+ * \param[in,out] out    Output object
+ * \param[in]     type   The family of result codes to list. Supported
+ *                       values: \c pcmk_result_legacy, \c pcmk_result_rc,
+ *                       \c pcmk_result_exitcode.
+ * \param[in]     flags  Group of \c pcmk_rc_disp_flags
+ *
+ * \return Standard Pacemaker return code
+ */
+int
+pcmk__list_result_codes(pcmk__output_t *out, enum pcmk_result_type type,
+                        uint32_t flags)
+{
+    int rc = pcmk_rc_ok;
+    int start = 0;
+    int end = 0;
+    int code = 0;
+
+    bool quiet_orig = out->quiet;
+    const char *name = NULL;
+    const char *desc = NULL;
+
+    rc = pcmk__result_bounds(type, &start, &end);
+    if (rc != pcmk_rc_ok) {
+        out->err(out,
+                "Failed to get result code bounds for result code type "
+                 "%#010x" PRIx32, (uint32_t) type);
+        return rc;
+    }
+
+    code = start;
+    while (code <= end) {
+        int local_rc = pcmk_rc_ok;
+
+        if (code == (pcmk_rc_error + 1)) {
+            /* Values between pcmk_rc_error and pcmk_rc_ok are reserved for
+             * callers, so skip them
+             */
+            code = pcmk_rc_ok;
+            continue;
+        }
+
+        // Shouldn't affect the return code of the whole list operation
+        local_rc = pcmk_result_get_strings(code, type, &name, &desc);
+
+        if ((local_rc != pcmk_rc_ok) || (name == NULL)
+            || pcmk__str_any_of(name, "Unknown", "CRM_EX_UNKNOWN", NULL)) {
+
+            code++;
+            continue;
+        }
+
+        // out->quiet controls whether the code is shown (if quiet is supported)
+        out->quiet = !pcmk_is_set(flags, pcmk_rc_disp_code);
+
+        out->message(out, "result-code", code,
+                     pcmk_is_set(flags, pcmk_rc_disp_name)? name : NULL,
+                     pcmk_is_set(flags, pcmk_rc_disp_desc)? desc : NULL);
+        out->quiet = quiet_orig;
+
+        code++;
+    }
+
+    return rc;
+}
+
+// Documented in header
+int
+pcmk_list_result_codes(xmlNodePtr *xml, enum pcmk_result_type type,
+                       uint32_t flags)
+{
+    pcmk__output_t *out = NULL;
+    int rc = pcmk_rc_ok;
+
+    rc = pcmk__xml_output_new(&out, xml);
+    if (rc != pcmk_rc_ok) {
+        return rc;
+    }
+
+    pcmk__register_lib_messages(out);
+
+    rc = pcmk__list_result_codes(out, type, flags);
+    pcmk__xml_output_finish(out, xml);
+    return rc;
+}
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 84daeb14e3..0704f2c99a 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,159 +1,160 @@
 #
 # Copyright 2004-2022 the Pacemaker project contributors
 #
 # The version control history for this file may have further details.
 #
 # This source code is licensed under the GNU General Public License version 2
 # or later (GPLv2+) WITHOUT ANY WARRANTY.
 #
 include $(top_srcdir)/mk/common.mk
 include $(top_srcdir)/mk/man.mk
 
 if BUILD_SYSTEMD
 systemdsystemunit_DATA	= crm_mon.service
 endif
 
 noinst_HEADERS		= crm_mon.h crm_resource.h
 
 pcmkdir			= $(datadir)/$(PACKAGE)
 pcmk_DATA		= report.common report.collector
 
 sbin_SCRIPTS		= crm_report crm_standby crm_master crm_failcount
 if BUILD_CIBSECRETS
 sbin_SCRIPTS		+= cibsecret
 endif
 noinst_SCRIPTS		= pcmk_simtimes
 
 EXTRA_DIST		= attrd_updater.8.inc \
 				  crm_attribute.8.inc \
 				  crm_diff.8.inc \
 				  crm_error.8.inc \
 			  crm_mon.8.inc			\
 			  crm_node.8.inc \
 			  crm_resource.8.inc \
 			  crm_rule.8.inc \
 			  crm_simulate.8.inc \
 			  crm_ticket.8.inc \
 			  crm_verify.8.inc \
 			  crmadmin.8.inc \
 			  fix-manpages \
 			  iso8601.8.inc \
 			  stonith_admin.8.inc
 
 sbin_PROGRAMS		= attrd_updater \
 			  cibadmin \
 			  crmadmin \
 			  crm_simulate \
 			  crm_attribute \
 			  crm_diff \
 			  crm_error \
 			  crm_mon \
 			  crm_node \
 			  crm_resource \
 			  crm_rule \
 			  crm_shadow \
 			  crm_verify \
 			  crm_ticket \
 			  iso8601 \
 			  stonith_admin
 
 ## SOURCES
 
 # A few tools are just thin wrappers around crm_attribute.
 # This makes their help get updated when crm_attribute changes
 # (see mk/common.mk).
 MAN8DEPS		= crm_attribute
 
 crmadmin_SOURCES	= crmadmin.c
 crmadmin_LDADD		= $(top_builddir)/lib/pengine/libpe_status.la	\
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la	\
 			  $(top_builddir)/lib/pacemaker/libpacemaker.la
 
 crm_error_SOURCES	= crm_error.c
-crm_error_LDADD		= $(top_builddir)/lib/common/libcrmcommon.la
+crm_error_LDADD		= $(top_builddir)/lib/pacemaker/libpacemaker.la	\
+			  $(top_builddir)/lib/common/libcrmcommon.la
 
 cibadmin_SOURCES	= cibadmin.c
 cibadmin_LDADD		= $(top_builddir)/lib/pacemaker/libpacemaker.la		\
 			  	$(top_builddir)/lib/cib/libcib.la		\
 				$(top_builddir)/lib/common/libcrmcommon.la
 
 crm_shadow_SOURCES	= crm_shadow.c
 crm_shadow_LDADD	= $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 crm_node_SOURCES	= crm_node.c
 crm_node_LDADD		= $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 crm_simulate_SOURCES	= crm_simulate.c
 
 crm_simulate_LDADD	= $(top_builddir)/lib/pengine/libpe_status.la	\
 			  $(top_builddir)/lib/pacemaker/libpacemaker.la	\
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 crm_diff_SOURCES	= crm_diff.c
 crm_diff_LDADD		= $(top_builddir)/lib/common/libcrmcommon.la
 
 crm_mon_SOURCES		= crm_mon.c crm_mon_curses.c
 crm_mon_LDADD		= $(top_builddir)/lib/pengine/libpe_status.la	\
 			  $(top_builddir)/lib/fencing/libstonithd.la	\
 			  $(top_builddir)/lib/pacemaker/libpacemaker.la	\
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la	\
 			  $(CURSESLIBS)
 
 crm_verify_SOURCES	= crm_verify.c
 crm_verify_LDADD	= $(top_builddir)/lib/pengine/libpe_status.la 	\
 			  $(top_builddir)/lib/pacemaker/libpacemaker.la	\
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 crm_attribute_SOURCES	= crm_attribute.c
 crm_attribute_LDADD	= $(top_builddir)/lib/pacemaker/libpacemaker.la	\
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 crm_resource_SOURCES	= crm_resource.c		\
 			  crm_resource_ban.c		\
 			  crm_resource_print.c		\
 			  crm_resource_runtime.c
 crm_resource_LDADD	= $(top_builddir)/lib/pengine/libpe_rules.la  	\
 			  $(top_builddir)/lib/fencing/libstonithd.la	\
 			  $(top_builddir)/lib/lrmd/liblrmd.la 		\
 			  $(top_builddir)/lib/services/libcrmservice.la \
 			  $(top_builddir)/lib/pengine/libpe_status.la 	\
 			  $(top_builddir)/lib/pacemaker/libpacemaker.la	\
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 crm_rule_SOURCES 	= crm_rule.c
 crm_rule_LDADD		= $(top_builddir)/lib/pacemaker/libpacemaker.la \
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/pengine/libpe_rules.la   \
 			  $(top_builddir)/lib/pengine/libpe_status.la   \
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 iso8601_SOURCES		= iso8601.c
 iso8601_LDADD		= $(top_builddir)/lib/common/libcrmcommon.la
 
 attrd_updater_SOURCES	= attrd_updater.c
 attrd_updater_LDADD	= $(top_builddir)/lib/pacemaker/libpacemaker.la	\
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 crm_ticket_SOURCES	= crm_ticket.c
 crm_ticket_LDADD	= $(top_builddir)/lib/pengine/libpe_rules.la	\
 			  $(top_builddir)/lib/pengine/libpe_status.la	\
 			  $(top_builddir)/lib/pacemaker/libpacemaker.la	\
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 stonith_admin_SOURCES	= stonith_admin.c
 stonith_admin_LDADD	= $(top_builddir)/lib/pacemaker/libpacemaker.la	\
 			  $(top_builddir)/lib/cib/libcib.la		\
 			  $(top_builddir)/lib/pengine/libpe_status.la	\
 			  $(top_builddir)/lib/fencing/libstonithd.la \
 			  $(top_builddir)/lib/common/libcrmcommon.la
 
 CLEANFILES = $(man8_MANS)
diff --git a/tools/crm_error.c b/tools/crm_error.c
index 01a175103f..4e0fd33641 100644
--- a/tools/crm_error.c
+++ b/tools/crm_error.c
@@ -1,175 +1,174 @@
 /*
  * Copyright 2012-2022 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
  * This source code is licensed under the GNU General Public License version 2
  * or later (GPLv2+) WITHOUT ANY WARRANTY.
  */
 
 #include <crm_internal.h>
+#include <crm/msg_xml.h>
 #include <crm/common/cmdline_internal.h>
 #include <crm/common/output_internal.h>
 #include <crm/common/strings_internal.h>
 
 #include <crm/crm.h>
 
-#define SUMMARY "crm_error - display name or description of a Pacemaker error code"
+#include <pacemaker-internal.h>
 
-GError *error = NULL;
+#define SUMMARY "crm_error - display name or description of a Pacemaker error code"
 
 struct {
     gboolean with_name;
     gboolean do_list;
     enum pcmk_result_type result_type; // How to interpret result codes
 } options = {
     .result_type = pcmk_result_legacy,
 };
 
 static gboolean
 result_type_cb(const gchar *option_name, const gchar *optarg, gpointer data,
                GError **error)
 {
     if (pcmk__str_any_of(option_name, "--exit", "-X", NULL)) {
         options.result_type = pcmk_result_exitcode;
     } else if (pcmk__str_any_of(option_name, "--rc", "-r", NULL)) {
         options.result_type = pcmk_result_rc;
     }
 
     return TRUE;
 }
 
 static GOptionEntry entries[] = {
     { "name", 'n', 0, G_OPTION_ARG_NONE, &options.with_name,
       "Show error's name with its description (useful for looking for sources "
       "of the error in source code)",
        NULL },
     { "list", 'l', 0, G_OPTION_ARG_NONE, &options.do_list,
       "Show all known errors (enabled by default if no rc is specified)",
       NULL },
     { "exit", 'X', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, result_type_cb,
       "Interpret as exit code rather than legacy function return value",
       NULL },
     { "rc", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, result_type_cb,
       "Interpret as return code rather than legacy function return value",
       NULL },
 
     { NULL }
 };
 
+static pcmk__supported_format_t formats[] = {
+    PCMK__SUPPORTED_FORMAT_NONE,
+    PCMK__SUPPORTED_FORMAT_TEXT,
+    PCMK__SUPPORTED_FORMAT_XML,
+    { NULL, NULL, NULL }
+};
+
 static GOptionContext *
 build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) {
     GOptionContext *context = NULL;
 
-    context = pcmk__build_arg_context(args, NULL, group, "[-- <rc> [<rc>...]]");
+    context = pcmk__build_arg_context(args, "text (default), xml", group,
+                                      "[-- <rc> [<rc>...]]");
     pcmk__add_main_args(context, entries);
     return context;
 }
 
 int
 main(int argc, char **argv)
 {
     crm_exit_t exit_code = CRM_EX_OK;
-    const char *name = NULL;
-    const char *desc = NULL;
+    int rc = pcmk_rc_ok;
+
+    pcmk__output_t *out = NULL;
+
+    GError *error = NULL;
 
     GOptionGroup *output_group = NULL;
     pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
     gchar **processed_args = pcmk__cmdline_preproc(argv, NULL);
     GOptionContext *context = build_arg_context(args, &output_group);
 
+    pcmk__register_formats(output_group, formats);
     if (!g_option_context_parse_strv(context, &processed_args, &error)) {
         exit_code = CRM_EX_USAGE;
         goto done;
     }
 
     pcmk__cli_init_logging("crm_error", args->verbosity);
 
-    if (args->version) {
-        g_strfreev(processed_args);
-        pcmk__free_arg_context(context);
-        /* FIXME:  When crm_error is converted to use formatted output, this can go. */
-        pcmk__cli_help('v', CRM_EX_OK);
+    rc = pcmk__output_new(&out, args->output_ty, args->output_dest, argv);
+    if (rc != pcmk_rc_ok) {
+        exit_code = CRM_EX_ERROR;
+        g_set_error(&error, PCMK__EXITC_ERROR, exit_code,
+                    "Error creating output format %s: %s", args->output_ty,
+                    pcmk_rc_str(rc));
+        goto done;
     }
 
     if (g_strv_length(processed_args) < 2) {
         // If no result codes were specified, list them all
         options.do_list = TRUE;
     }
 
+    if (args->version) {
+        out->version(out, false);
+        goto done;
+    }
+
+    pcmk__register_lib_messages(out);
+
     if (options.do_list) {
-        int start = 0;
-        int end = 0;
-        int code = 0;
-
-        /* Get length of longest (most negative) standard Pacemaker return code
-         * This should be longer than all the values of any other type of return
-         * code.
-         */
-        long long most_negative = pcmk_rc_error - (long long) pcmk__n_rc + 1;
-        int code_width = (int) snprintf(NULL, 0, "%lld", most_negative);
-        int name_width = 0;
+        uint32_t flags = pcmk_rc_disp_code|pcmk_rc_disp_desc;
 
         if (options.with_name) {
-            // Get length of longest standard Pacemaker return code name
-            for (int lpc = 0; lpc < pcmk__n_rc; lpc++) {
-                int len = (int) strlen(pcmk_rc_name(pcmk_rc_error - lpc));
-                name_width = QB_MAX(name_width, len);
-            }
+            flags = pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE,
+                                       "pcmk_rc_disp_flags",
+                                       "pcmk__list_result_codes", flags,
+                                       pcmk_rc_disp_name, "pcmk_rc_disp_name");
         }
+        pcmk__list_result_codes(out, options.result_type, flags);
 
-        pcmk__result_bounds(options.result_type, &start, &end);
-
-        code = start;
-        while (code <= end) {
-            if (code == (pcmk_rc_error + 1)) {
-                /* Values between here and pcmk_rc_ok are reserved for callers,
-                 * so skip them
-                 */
-                code = pcmk_rc_ok;
-                continue;
-            }
-            pcmk_result_get_strings(code, options.result_type, &name, &desc);
-
-            if ((name == NULL)
-                || pcmk__str_any_of(name, "Unknown", "CRM_EX_UNKNOWN", NULL)) {
-
-                code++;
-                continue;
-            }
-
-            if (options.with_name) {
-                printf("% *d: %-*s  %s\n", code_width, code, name_width, name,
-                       desc);
-            } else {
-                printf("% *d: %s\n", code_width, code, desc);
-            }
-            code++;
+    } else {
+        uint32_t flags = pcmk_rc_disp_desc;
+
+        // For text output, print only "[name -] description" by default
+        if (args->verbosity > 0) {
+            flags = pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE,
+                                       "pcmk_rc_disp_flags",
+                                       "pcmk__show_result_code", flags,
+                                       pcmk_rc_disp_code, "pcmk_rc_disp_code");
         }
 
-    } else {
-        int code = 0;
+        if (options.with_name) {
+            flags = pcmk__set_flags_as(__func__, __LINE__, LOG_TRACE,
+                                       "pcmk_rc_disp_flags",
+                                       "pcmk__show_result_code", flags,
+                                       pcmk_rc_disp_name, "pcmk_rc_disp_name");
+        }
 
         /* Skip #1 because that's the program name. */
         for (int lpc = 1; processed_args[lpc] != NULL; lpc++) {
+            int code = 0;
+
             if (pcmk__str_eq(processed_args[lpc], "--", pcmk__str_none)) {
                 continue;
             }
-
             pcmk__scan_min_int(processed_args[lpc], &code, INT_MIN);
-            pcmk_result_get_strings(code, options.result_type, &name, &desc);
-            if (options.with_name) {
-                printf("%s - %s\n", name, desc);
-            } else {
-                printf("%s\n", desc);
-            }
+            pcmk__show_result_code(out, code, options.result_type, flags);
         }
     }
 
  done:
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, NULL);
-    return exit_code;
+    pcmk__output_and_clear_error(error, out);
+
+    if (out != NULL) {
+        out->finish(out, exit_code, true, NULL);
+        pcmk__output_free(out);
+    }
+    crm_exit(exit_code);
 }
diff --git a/xml/Makefile.am b/xml/Makefile.am
index 999d5d9a51..64e130f14c 100644
--- a/xml/Makefile.am
+++ b/xml/Makefile.am
@@ -1,315 +1,316 @@
 #
 # Copyright 2004-2022 the Pacemaker project contributors
 #
 # The version control history for this file may have further details.
 #
 # This source code is licensed under the GNU General Public License version 2
 # or later (GPLv2+) WITHOUT ANY WARRANTY.
 #
 
 include $(top_srcdir)/mk/common.mk
 
 noarch_pkgconfig_DATA	= $(builddir)/pacemaker-schemas.pc
 
 # Pacemaker has 3 schemas: the CIB schema, the API schema (for command-line
 # tool XML output), and a legacy schema for crm_mon --as-xml.
 #
 # See README.md for details on updating CIB schema files (API is similar)
 
 # The CIB and crm_mon schemas are installed directly in CRM_SCHEMA_DIRECTORY
 # for historical reasons, while the API schema is installed in a subdirectory.
 APIdir	= $(CRM_SCHEMA_DIRECTORY)/api
 CIBdir	= $(CRM_SCHEMA_DIRECTORY)
 MONdir	= $(CRM_SCHEMA_DIRECTORY)
 
 basexsltdir		= $(CRM_SCHEMA_DIRECTORY)/base
 dist_basexslt_DATA	= $(srcdir)/base/access-render-2.xsl
 
 # Extract a sorted list of available numeric schema versions
 # from filenames like NAME-MAJOR[.MINOR][.MINOR-MINOR].rng
 numeric_versions = $(shell ls -1 $(1) \
 			  | sed -n -e 's/^.*-\([0-9][0-9.]*\).rng$$/\1/p' \
 			  | sort -u -t. -k 1,1n -k 2,2n -k 3,3n)
 
 # @COMPAT: pacemaker-next is deprecated since 2.1.5
 version_pairs = $(join \
 			    $(1),$(addprefix \
 			      -,$(wordlist \
 			        2,$(words $(1)),$(1) \
 			      ) next \
 			    ) \
 			  )
 
 version_pairs_last = $(wordlist \
 			    $(words \
 			      $(wordlist \
 			        2,$(1),$(2) \
 			      ) \
 			    ),$(1),$(2) \
 			  )
 
 # NOTE: All files in API_request_base, CIB_cfg_base, API_base, and CIB_base
 # need to start with a unique prefix.  These variables all get iterated over
 # and globbed, and two files starting with the same prefix will cause
 # problems.
 
 # Names of API schemas that form the choices for pacemaker-result content
 API_request_base	= command-output	\
 			  crm_attribute 	\
+			  crm_error 	\
 			  crm_mon		\
 			  crm_resource		\
 			  crm_rule \
 			  crm_simulate		\
 			  crmadmin		\
 			  digests		\
 			  pacemakerd 		\
 			  stonith_admin		\
 			  version
 
 # Names of CIB schemas that form the choices for cib/configuration content
 CIB_cfg_base		= options nodes resources constraints fencing acls tags alerts
 
 # Names of all schemas (including top level and those included by others)
 API_base		= $(API_request_base)	\
 			  failure		\
 			  fence-event 		\
 			  generic-list		\
 			  item			\
 			  node-attrs		\
 			  node-history		\
 			  nodes			\
 			  resources		\
 			  status		\
 			  subprocess-output
 CIB_base		= cib $(CIB_cfg_base) status score rule nvset
 
 # Static schema files and transforms (only CIB has transforms)
 # 
 # This is more complicated than it should be due to the need to support
 # VPATH builds and "make distcheck". We need the absolute paths for reliable
 # substitution back and forth, and relative paths for distributed files.
 API_abs_files		= $(foreach base,$(API_base),$(wildcard $(abs_srcdir)/api/$(base)-*.rng))
 CIB_abs_files		= $(foreach base,$(CIB_base),$(wildcard $(abs_srcdir)/$(base).rng $(abs_srcdir)/$(base)-*.rng))
 CIB_abs_xsl		= $(abs_srcdir)/upgrade-1.3.xsl			\
 			  $(abs_srcdir)/upgrade-2.10.xsl		\
 			  $(wildcard $(abs_srcdir)/upgrade-*enter.xsl)	\
 			  $(wildcard $(abs_srcdir)/upgrade-*leave.xsl)
 MON_abs_files 		= $(abs_srcdir)/crm_mon.rng
 API_files		= $(foreach base,$(API_base),$(wildcard $(srcdir)/api/$(base)-*.rng))
 CIB_files		= $(foreach base,$(CIB_base),$(wildcard $(srcdir)/$(base).rng $(srcdir)/$(base)-*.rng))
 CIB_xsl			= $(srcdir)/upgrade-1.3.xsl			\
 			  $(srcdir)/upgrade-2.10.xsl		\
 			  $(wildcard $(srcdir)/upgrade-*enter.xsl)	\
 			  $(wildcard $(srcdir)/upgrade-*leave.xsl)
 MON_files 		= $(srcdir)/crm_mon.rng
 
 # Sorted lists of all numeric schema versions
 API_numeric_versions	= $(call numeric_versions,${API_files})
 CIB_numeric_versions	= $(call numeric_versions,${CIB_files})
 MON_numeric_versions 	= $(call numeric_versions,$(wildcard $(srcdir)/api/crm_mon*.rng))
 
 # The highest numeric schema version
 API_max			?= $(lastword $(API_numeric_versions))
 CIB_max			?= $(lastword $(CIB_numeric_versions))
 MON_max 			?= $(lastword $(MON_numeric_versions))
 
 # Sorted lists of all schema versions (including "next")
 # @COMPAT: pacemaker-next is deprecated since 2.1.5
 API_versions		= next $(API_numeric_versions)
 CIB_versions		= next $(CIB_numeric_versions)
 
 # Build tree locations of static schema files and transforms (for VPATH builds)
 API_build_copies	= $(foreach f,$(API_abs_files),$(subst $(abs_srcdir),$(abs_builddir),$(f)))
 CIB_build_copies	= $(foreach f,$(CIB_abs_files) $(CIB_abs_xsl),$(subst $(abs_srcdir),$(abs_builddir),$(f)))
 MON_build_copies 	= $(foreach f,$(MON_abs_files),$(subst $(abs_srcdir),$(abs_builddir),$(f)))
 
 # Dynamically generated schema files
 API_generated		= api/api-result.rng $(foreach base,$(API_versions),api/api-result-$(base).rng)
 CIB_generated		= pacemaker.rng $(foreach base,$(CIB_versions),pacemaker-$(base).rng) versions.rng
 MON_generated 		= crm_mon.rng
 
 CIB_version_pairs	= $(call version_pairs,${CIB_numeric_versions})
 CIB_version_pairs_cnt	= $(words ${CIB_version_pairs})
 CIB_version_pairs_last  = $(call version_pairs_last,${CIB_version_pairs_cnt},${CIB_version_pairs})
 
 dist_API_DATA		= $(API_files)
 dist_CIB_DATA		= $(CIB_files) $(CIB_xsl)
 
 nodist_API_DATA		= $(API_generated)
 nodist_CIB_DATA		= $(CIB_generated)
 nodist_MON_DATA		= $(MON_generated)
 
 EXTRA_DIST		= README.md			\
 			  best-match.sh			\
 			  cibtr-2.rng			\
 			  context-of.xsl		\
 			  ocf-meta2man.xsl		\
 			  regression.sh			\
 			  upgrade-2.10-roundtrip.xsl	\
 			  upgrade-detail.xsl		\
 			  xslt_cibtr-2.rng		\
 			  assets			\
 			  test-2			\
 			  test-2-enter			\
 			  test-2-leave			\
 			  test-2-roundtrip
 
 cib-versions:
 	@echo "Max: $(CIB_max)"
 	@echo "Available: $(CIB_versions)"
 
 api-versions:
 	@echo "Max: $(API_max)"
 	@echo "Available: $(API_versions)"
 
 # Dynamically generated top-level API schema
 api/api-result.rng: api/api-result-$(API_max).rng
 	$(AM_V_at)$(MKDIR_P) api # might not exist in VPATH build
 	$(AM_V_SCHEMA)cp $(top_builddir)/xml/$< $@
 
 api/api-result-%.rng: $(API_build_copies) best-match.sh Makefile.am
 	$(AM_V_at)echo '<?xml version="1.0" encoding="UTF-8"?>' > $@
 	$(AM_V_at)echo '<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">' >> $@
 	$(AM_V_at)echo '  <start>' >> $@
 	$(AM_V_at)echo '    <element name="pacemaker-result">' >> $@
 	$(AM_V_at)echo '      <attribute name="api-version"> <text /> </attribute>' >> $@
 	$(AM_V_at)echo '      <attribute name="request"> <text /> </attribute>' >> $@
 	$(AM_V_at)echo '      <optional>' >> $@
 	$(AM_V_at)echo '        <choice>' >> $@
 	$(AM_V_at)for rng in $(API_request_base); do $(srcdir)/best-match.sh api/$$rng $(*) $(@) "          " || :; done
 	$(AM_V_at)echo '        </choice>' >> $@
 	$(AM_V_at)echo '      </optional>' >> $@
 	$(AM_V_at)$(srcdir)/best-match.sh api/status $(*) $(@) "      " || :
 	$(AM_V_at)echo '    </element>' >> $@
 	$(AM_V_at)echo '  </start>' >> $@
 	$(AM_V_SCHEMA)echo '</grammar>' >> $@
 
 crm_mon.rng: api/crm_mon-$(MON_max).rng
 	$(AM_V_at)echo '<?xml version="1.0" encoding="UTF-8"?>' > $@
 	$(AM_V_at)echo '<grammar xmlns="http://relaxng.org/ns/structure/1.0"' >> $@
 	$(AM_V_at)echo '         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">' >> $@
 	$(AM_V_at)echo '    <start>' >> $@
 	$(AM_V_at)echo '        <ref name="element-crm_mon-old"/>' >> $@
 	$(AM_V_at)echo '    </start>' >> $@
 	$(AM_V_at)echo '    <define name="element-crm_mon-old">' >> $@
 	$(AM_V_at)echo '        <element name="crm_mon">' >> $@
 	$(AM_V_at)echo '            <attribute name="version"> <text/> </attribute>' >> $@
 	$(AM_V_at)echo '            <externalRef href="$(<)" />' >> $@
 	$(AM_V_at)echo '        </element>' >> $@
 	$(AM_V_at)echo '    </define>' >> $@
 	$(AM_V_SCHEMA)echo '</grammar>' >> $@
 
 # Dynamically generated top-level CIB schema
 pacemaker.rng: pacemaker-$(CIB_max).rng
 	$(AM_V_SCHEMA)cp $(top_builddir)/xml/$< $@
 
 pacemaker-%.rng: $(CIB_build_copies) best-match.sh Makefile.am
 	$(AM_V_at)echo '<?xml version="1.0" encoding="UTF-8"?>' > $@
 	$(AM_V_at)echo '<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">' >> $@
 	$(AM_V_at)echo '  <start>' >> $@
 	$(AM_V_at)echo '    <element name="cib">' >> $@
 	$(AM_V_at)$(srcdir)/best-match.sh cib $(*) $(@) "      "
 	$(AM_V_at)echo '      <element name="configuration">' >> $@
 	$(AM_V_at)echo '        <interleave>' >> $@
 	$(AM_V_at)for rng in $(CIB_cfg_base); do $(srcdir)/best-match.sh $$rng $(*) $(@) "          " || :; done
 	$(AM_V_at)echo '        </interleave>' >> $@
 	$(AM_V_at)echo '      </element>' >> $@
 	$(AM_V_at)echo '      <optional>' >> $@
 	$(AM_V_at)echo '        <element name="status">' >> $@
 	$(AM_V_at)$(srcdir)/best-match.sh status $(*) $(@) "          "
 	$(AM_V_at)echo '        </element>' >> $@
 	$(AM_V_at)echo '      </optional>' >> $@
 	$(AM_V_at)echo '    </element>' >> $@
 	$(AM_V_at)echo '  </start>' >> $@
 	$(AM_V_SCHEMA)echo '</grammar>' >> $@
 
 # Dynamically generated CIB schema listing all pacemaker versions
 versions.rng: pacemaker-$(CIB_max).rng Makefile.am
 	$(AM_V_at)echo '<?xml version="1.0" encoding="UTF-8"?>' > $@
 	$(AM_V_at)echo '<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">' >> $@
 	$(AM_V_at)echo '  <start>' >> $@
 	$(AM_V_at)echo '   <interleave>' >> $@
 	$(AM_V_at)echo '    <optional>' >> $@
 	$(AM_V_at)echo '      <attribute name="validate-with">' >> $@
 	$(AM_V_at)echo '        <choice>' >> $@
 	$(AM_V_at)echo '          <value>none</value>' >> $@
 	$(AM_V_at)echo '          <value>pacemaker-0.6</value>' >> $@
 	$(AM_V_at)echo '          <value>transitional-0.6</value>' >> $@
 	$(AM_V_at)echo '          <value>pacemaker-0.7</value>' >> $@
 	$(AM_V_at)echo '          <value>pacemaker-1.1</value>' >> $@
 	$(AM_V_at)for rng in $(CIB_versions); do echo "          <value>pacemaker-$$rng</value>" >> $@; done
 	$(AM_V_at)echo '        </choice>' >> $@
 	$(AM_V_at)echo '      </attribute>' >> $@
 	$(AM_V_at)echo '    </optional>' >> $@
 	$(AM_V_at)echo '    <attribute name="admin_epoch"><data type="nonNegativeInteger"/></attribute>' >> $@
 	$(AM_V_at)echo '    <attribute name="epoch"><data type="nonNegativeInteger"/></attribute>' >> $@
 	$(AM_V_at)echo '    <attribute name="num_updates"><data type="nonNegativeInteger"/></attribute>' >> $@
 	$(AM_V_at)echo '   </interleave>' >> $@
 	$(AM_V_at)echo '  </start>' >> $@
 	$(AM_V_SCHEMA)echo '</grammar>' >> $@
 
 # diff fails with ec=2 if no predecessor is found;
 # this uses '=' GNU extension to sed, if that's not available,
 # one can use: hline=`echo "$${p}" | grep -Fn "$${hunk}" | cut -d: -f1`;
 # XXX: use line information from hunk to avoid "not detected" for ambiguity
 version_diff = \
 	@for p in $(1); do \
 	  set `echo "$${p}" | tr '-' ' '`; \
 	  echo "\#\#\# *-$$2.rng vs. predecessor"; \
 	  for v in *-$$2.rng; do \
 	    echo "\#\#\#\# $${v} vs. predecessor"; b=`echo "$${v}" | cut -d- -f1`; \
 	    old=`./best-match.sh $${b} $$1`; \
 	    p=`diff -u "$${old}" "$${v}" 2>/dev/null`; \
 	    case $$? in \
 	    1) echo "$${p}" | sed -n -e '/^@@ /!d;=;p' \
 	       -e ':l;n;/^\([- ]\|+.*<[^ />]\+\([^/>]\+="ID\|>$$\)\)/bl;s/^[+ ]\(.*\)/\1/p' \
 	       | while read hline; do \
 	           read h && read i || break; \
 	           iline=`grep -Fn "$${i}" "$${v}" | cut -d: -f1`; \
 	           ctxt="(not detected)"; \
 	           if test `echo "$${iline}" | wc -l` -eq 1; then \
 	             ctxt=`{ sed -n -e "1,$$(($${iline}-1))p" "$${v}"; \
 	                     echo "<inject id=\"GOAL\"/>$${i}"; \
 	                     sed -n -e "$$(($${iline}+1)),$$ p" "$${v}"; \
 	                   } | $(XSLTPROC) --param skip 1 context-of.xsl -`; \
 	           fi; \
 	           echo "$${p}" | sed -n -e "$$(($${hline}-2)),$${hline}!d" \
 	             -e '/^\(+++\|---\)/p'; \
 	           echo "$${h} context: $${ctxt}"; \
 	           echo "$${p}" | sed -n -e "1,$${hline}d" \
 	             -e '/^\(---\|@@ \)/be;p;d;:e;n;be'; \
 	           done; \
 	       ;; \
 	    2) echo "\#\#\#\#\# $${v} has no predecessor";; \
 	    esac; \
 	  done; \
 	done
 
 diff: best-match.sh
 	@echo "#  Comparing changes in + since $(CIB_max)"
 	$(call version_diff,${CIB_version_pairs_last})
 
 fulldiff: best-match.sh
 	@echo "#  Comparing all changes across all the subsequent increments"
 	$(call version_diff,${CIB_version_pairs})
 
 CLEANFILES = $(API_generated) $(CIB_generated) $(MON_generated)
 
 # Remove pacemaker schema files generated by *any* source version. This allows
 # "make -C xml clean" to have the desired effect when checking out an earlier
 # revision in a source tree.
 clean-local:
 	if [ "x$(srcdir)" != "x$(builddir)" ]; then					\
 		rm -f $(API_build_copies) $(CIB_build_copies) $(MON_build_copies);	\
 	fi
 	rm -f $(builddir)/pacemaker-[0-9]*.[0-9]*.rng
 
 # Enable ability to use $@ in prerequisite
 .SECONDEXPANSION:
 
 # For VPATH builds, copy the static schema files into the build tree
 $(API_build_copies) $(CIB_build_copies) $(MON_build_copies): $$(subst $(abs_builddir),$(srcdir),$$(@))
 	$(AM_V_GEN)if [ "x$(srcdir)" != "x$(builddir)" ]; then	\
 		$(MKDIR_P) "$(dir $(@))";			\
 		cp "$(<)" "$(@)";				\
 	fi
diff --git a/xml/api/crm_error-2.23.rng b/xml/api/crm_error-2.23.rng
new file mode 100644
index 0000000000..8ba6e62647
--- /dev/null
+++ b/xml/api/crm_error-2.23.rng
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0"
+         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+
+    <start>
+        <ref name="element-crm_error" />
+    </start>
+
+    <define name="element-crm_error">
+        <zeroOrMore>
+            <ref name="element-result-code" />
+        </zeroOrMore>
+    </define>
+
+    <define name="element-result-code">
+        <element name="result-code">
+            <attribute name="code"> <data type="integer" /> </attribute>
+            <attribute name="description"> <text /> </attribute>
+            <optional>
+                <attribute name="name"> <text /> </attribute>
+            </optional>
+        </element>
+    </define>
+</grammar>