pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk_result_code.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <crm/cib/internal.h>
13 #include <crm/crm.h>
14 
15 #include <pacemaker.h>
16 #include <pacemaker-internal.h>
17 
18 #include <inttypes.h> // PRIx32
19 #include <stdint.h> // uint32_t
20 
34 int
36  enum pcmk_result_type type, uint32_t flags)
37 {
38  int rc = pcmk_rc_ok;
39  bool quiet_orig = out->quiet;
40  const char *name = NULL;
41  const char *desc = NULL;
42 
43  rc = pcmk_result_get_strings(code, type, &name, &desc);
44  if (rc != pcmk_rc_ok) {
45  out->err(out, "Error looking up result code %d", code);
46  return rc;
47  }
48 
49  // out->quiet controls whether the code is shown (if quiet is supported)
51 
52  out->message(out, "result-code", code,
54  pcmk_is_set(flags, pcmk_rc_disp_desc)? desc : NULL);
55  out->quiet = quiet_orig;
56 
57  return rc;
58 }
59 
60 // Documented in header
61 int
62 pcmk_show_result_code(xmlNodePtr *xml, int code, enum pcmk_result_type type,
63  uint32_t flags)
64 {
65  pcmk__output_t *out = NULL;
66  int rc = pcmk_rc_ok;
67 
68  rc = pcmk__xml_output_new(&out, xml);
69  if (rc != pcmk_rc_ok) {
70  return rc;
71  }
72 
74 
75  rc = pcmk__show_result_code(out, code, type, flags);
76  pcmk__xml_output_finish(out, xml);
77  return rc;
78 }
79 
92 int
94  uint32_t flags)
95 {
96  int rc = pcmk_rc_ok;
97  int start = 0;
98  int end = 0;
99  int code = 0;
100 
101  bool quiet_orig = out->quiet;
102  const char *name = NULL;
103  const char *desc = NULL;
104 
105  rc = pcmk__result_bounds(type, &start, &end);
106  if (rc != pcmk_rc_ok) {
107  out->err(out,
108  "Failed to get result code bounds for result code type "
109  "%#010x" PRIx32, (uint32_t) type);
110  return rc;
111  }
112 
113  code = start;
114  while (code <= end) {
115  int local_rc = pcmk_rc_ok;
116 
117  if (code == (pcmk_rc_error + 1)) {
118  /* Values between pcmk_rc_error and pcmk_rc_ok are reserved for
119  * callers, so skip them
120  */
121  code = pcmk_rc_ok;
122  continue;
123  }
124 
125  // Shouldn't affect the return code of the whole list operation
126  local_rc = pcmk_result_get_strings(code, type, &name, &desc);
127 
128  if ((local_rc != pcmk_rc_ok) || (name == NULL)
129  || pcmk__str_any_of(name, "Unknown", "CRM_EX_UNKNOWN", NULL)) {
130 
131  code++;
132  continue;
133  }
134 
135  // out->quiet controls whether the code is shown (if quiet is supported)
137 
138  out->message(out, "result-code", code,
140  pcmk_is_set(flags, pcmk_rc_disp_desc)? desc : NULL);
141  out->quiet = quiet_orig;
142 
143  code++;
144  }
145 
146  return rc;
147 }
148 
149 // Documented in header
150 int
152  uint32_t flags)
153 {
154  pcmk__output_t *out = NULL;
155  int rc = pcmk_rc_ok;
156 
157  rc = pcmk__xml_output_new(&out, xml);
158  if (rc != pcmk_rc_ok) {
159  return rc;
160  }
161 
163 
164  rc = pcmk__list_result_codes(out, type, flags);
165  pcmk__xml_output_finish(out, xml);
166  return rc;
167 }
int pcmk_list_result_codes(xmlNodePtr *xml, enum pcmk_result_type type, uint32_t flags)
List all valid result codes in a particular family.
A dumping ground.
const char * name
Definition: cib.c:26
int(* message)(pcmk__output_t *out, const char *message_id,...)
int pcmk__show_result_code(pcmk__output_t *out, int code, enum pcmk_result_type type, uint32_t flags)
int pcmk_show_result_code(xmlNodePtr *xml, int code, enum pcmk_result_type type, uint32_t flags)
Display the name and/or description of a result code.
int pcmk__result_bounds(enum pcmk_result_type, int *lower, int *upper)
Definition: results.c:94
High Level API.
enum crm_ais_msg_types type
Definition: cpg.c:48
int pcmk__list_result_codes(pcmk__output_t *out, enum pcmk_result_type type, uint32_t flags)
Display result code description.
Definition: pacemaker.h:308
int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml)
Definition: output.c:236
bool quiet
Should this formatter supress most output?
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:99
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__register_lib_messages(pcmk__output_t *out)
Definition: pcmk_output.c:2403
int pcmk_result_get_strings(int code, enum pcmk_result_type type, const char **name, const char **desc)
Get the name and description of a given result code.
Definition: results.c:44
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:957
Display result code name.
Definition: pacemaker.h:307
This structure contains everything that makes up a single output formatter.
Display result code number.
Definition: pacemaker.h:306
void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml)
Definition: output.c:258
uint64_t flags
Definition: remote.c:215
pcmk_result_type
Types of Pacemaker result codes.
Definition: results.h:349