This source file includes following definitions.
- pcmk__show_result_code
- pcmk_show_result_code
- pcmk__list_result_codes
- pcmk_list_result_codes
1
2
3
4
5
6
7
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>
19 #include <stdint.h>
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 int
35 pcmk__show_result_code(pcmk__output_t *out, int code,
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
50 out->quiet = !pcmk_is_set(flags, pcmk_rc_disp_code);
51
52 out->message(out, "result-code", code,
53 pcmk_is_set(flags, pcmk_rc_disp_name)? name : NULL,
54 pcmk_is_set(flags, pcmk_rc_disp_desc)? desc : NULL);
55 out->quiet = quiet_orig;
56
57 return rc;
58 }
59
60
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
73 pcmk__register_lib_messages(out);
74
75 rc = pcmk__show_result_code(out, code, type, flags);
76 pcmk__xml_output_finish(out, xml);
77 return rc;
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92 int
93 pcmk__list_result_codes(pcmk__output_t *out, enum pcmk_result_type type,
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
119
120
121 code = pcmk_rc_ok;
122 continue;
123 }
124
125
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
136 out->quiet = !pcmk_is_set(flags, pcmk_rc_disp_code);
137
138 out->message(out, "result-code", code,
139 pcmk_is_set(flags, pcmk_rc_disp_name)? name : NULL,
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
150 int
151 pcmk_list_result_codes(xmlNodePtr *xml, enum pcmk_result_type type,
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
162 pcmk__register_lib_messages(out);
163
164 rc = pcmk__list_result_codes(out, type, flags);
165 pcmk__xml_output_finish(out, xml);
166 return rc;
167 }