Skip to content

Commit b9fa064

Browse files
author
Ken Gaillot
authored
Merge pull request #2008 from clumens/output-retval
Convert formatted output to use new pacemaker return codes
2 parents 4c997e6 + bc2ef3e commit b9fa064

14 files changed

Lines changed: 246 additions & 230 deletions

File tree

include/crm/common/output.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ struct pcmk__output_s {
303303
* previous call to register_message.
304304
* \param[in] ... Arguments to be passed to the registered function.
305305
*
306-
* \return 0 if a function was registered for the message, that function was
307-
* called, and returned successfully. A negative value is returned if
308-
* no function was registered. A positive value is returned if the
309-
* function was called but encountered an error.
306+
* \return A standard Pacemaker return code. Generally: 0 if a function was
307+
* registered for the message, that function was called, and returned
308+
* successfully; EINVAL if no function was registered; or pcmk_rc_no_output
309+
* if a function was called but produced no output.
310310
*/
311311
int (*message) (pcmk__output_t *out, const char *message_id, ...);
312312

include/crm/common/results.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ enum pcmk_rc_e {
107107
/* When adding new values, use consecutively lower numbers, update the array
108108
* in lib/common/results.c, and test with crm_error.
109109
*/
110+
pcmk_rc_no_output = -1026,
110111
pcmk_rc_after_range = -1025,
111112
pcmk_rc_within_range = -1024,
112113
pcmk_rc_before_range = -1023,

include/crm/pengine/internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,14 @@ gboolean add_tag_ref(GHashTable * tags, const char * tag_name, const char * obj
395395

396396
void print_rscs_brief(GListPtr rsc_list, const char * pre_text, long options,
397397
void * print_data, gboolean print_all);
398-
void pe__rscs_brief_output(pcmk__output_t *out, GListPtr rsc_list, long options, gboolean print_all);
398+
int pe__rscs_brief_output(pcmk__output_t *out, GListPtr rsc_list, long options, gboolean print_all);
399399
void pe_fence_node(pe_working_set_t * data_set, node_t * node, const char *reason);
400400

401401
node_t *pe_create_node(const char *id, const char *uname, const char *type,
402402
const char *score, pe_working_set_t * data_set);
403403
void common_print(resource_t * rsc, const char *pre_text, const char *name, node_t *node, long options, void *print_data);
404-
void pe__common_output_text(pcmk__output_t *out, resource_t * rsc, const char *name, node_t *node, long options);
405-
void pe__common_output_html(pcmk__output_t *out, resource_t * rsc, const char *name, node_t *node, long options);
404+
int pe__common_output_text(pcmk__output_t *out, resource_t * rsc, const char *name, node_t *node, long options);
405+
int pe__common_output_html(pcmk__output_t *out, resource_t * rsc, const char *name, node_t *node, long options);
406406
pe_resource_t *pe__find_bundle_replica(const pe_resource_t *bundle,
407407
const pe_node_t *node);
408408
bool pe__bundle_needs_remote_name(pe_resource_t *rsc);

lib/common/output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ pcmk__register_formats(GOptionGroup *group, pcmk__supported_format_t *formats) {
108108
int
109109
pcmk__call_message(pcmk__output_t *out, const char *message_id, ...) {
110110
va_list args;
111-
int rc = 0;
111+
int rc = pcmk_rc_ok;
112112
pcmk__message_fn_t fn;
113113

114114
fn = g_hash_table_lookup(out->messages, message_id);
115115
if (fn == NULL) {
116-
return -EINVAL;
116+
return EINVAL;
117117
}
118118

119119
va_start(args, message_id);

lib/common/results.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ static struct pcmk__rc_info {
235235
{ "pcmk_rc_after_range",
236236
"Result occurs after given range",
237237
-pcmk_err_generic,
238+
},
239+
{ "pcmk_rc_no_output",
240+
"Output message produced no output",
241+
-pcmk_err_generic,
238242
}
239243
};
240244

@@ -655,6 +659,7 @@ pcmk_rc2exitc(int rc)
655659
return CRM_EX_EXISTS;
656660

657661
case EIO:
662+
case pcmk_rc_no_output:
658663
return CRM_EX_IOERR;
659664

660665
case ENOTSUP:

lib/fencing/st_output.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ last_fenced_html(pcmk__output_t *out, va_list args) {
3636
char *buf = crm_strdup_printf("Node %s last fenced at: %s", target, ctime(&when));
3737
pcmk__output_create_html_node(out, "div", NULL, NULL, buf);
3838
free(buf);
39+
return pcmk_rc_ok;
40+
} else {
41+
return pcmk_rc_no_output;
3942
}
40-
41-
return 0;
4243
}
4344

4445
static int
@@ -52,7 +53,7 @@ last_fenced_text(pcmk__output_t *out, va_list args) {
5253
pcmk__indented_printf(out, "Node %s has never been fenced\n", target);
5354
}
5455

55-
return 0;
56+
return pcmk_rc_ok;
5657
}
5758

5859
static int
@@ -68,9 +69,10 @@ last_fenced_xml(pcmk__output_t *out, va_list args) {
6869
xmlSetProp(node, (pcmkXmlStr) "when", (pcmkXmlStr) buf);
6970

7071
free(buf);
72+
return pcmk_rc_ok;
73+
} else {
74+
return pcmk_rc_no_output;
7175
}
72-
73-
return 0;
7476
}
7577

7678
static int
@@ -117,7 +119,7 @@ stonith_event_html(pcmk__output_t *out, va_list args) {
117119
break;
118120
}
119121

120-
return 0;
122+
return pcmk_rc_ok;
121123
}
122124

123125
static int
@@ -154,7 +156,7 @@ stonith_event_text(pcmk__output_t *out, va_list args) {
154156
}
155157

156158
free(buf);
157-
return 0;
159+
return pcmk_rc_ok;
158160
}
159161

160162
static int
@@ -199,7 +201,7 @@ stonith_event_xml(pcmk__output_t *out, va_list args) {
199201
free(buf);
200202
}
201203

202-
return 0;
204+
return pcmk_rc_ok;
203205
}
204206

205207
static int

lib/pacemaker/pcmk_fence.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ pcmk__fence_last(pcmk__output_t *out, const char *target, bool as_nodeid) {
286286
when = stonith_api_time(0, target, FALSE);
287287
}
288288

289-
out->message(out, "last-fenced", target, when);
290-
return pcmk_rc_ok;
289+
return out->message(out, "last-fenced", target, when);
291290
}
292291

293292
#ifdef BUILD_PUBLIC_LIBPACEMAKER

lib/pengine/bundle.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ pe__bundle_xml(pcmk__output_t *out, va_list args)
15011501
unsigned int options = va_arg(args, unsigned int);
15021502
pe_resource_t *rsc = va_arg(args, pe_resource_t *);
15031503
pe__bundle_variant_data_t *bundle_data = NULL;
1504-
int rc = 0;
1504+
int rc = pcmk_rc_no_output;
15051505

15061506
CRM_ASSERT(rsc != NULL);
15071507

@@ -1514,7 +1514,7 @@ pe__bundle_xml(pcmk__output_t *out, va_list args)
15141514
, "unique", BOOL2STR(is_set(rsc->flags, pe_rsc_unique))
15151515
, "managed", BOOL2STR(is_set(rsc->flags, pe_rsc_managed))
15161516
, "failed", BOOL2STR(is_set(rsc->flags, pe_rsc_failed)));
1517-
CRM_ASSERT(rc == 0);
1517+
CRM_ASSERT(rc == pcmk_rc_ok);
15181518

15191519
for (GList *gIter = bundle_data->replicas; gIter != NULL;
15201520
gIter = gIter->next) {
@@ -1525,7 +1525,7 @@ pe__bundle_xml(pcmk__output_t *out, va_list args)
15251525

15261526
rc = pe__name_and_nvpairs_xml(out, true, "replica", 1, "id", id);
15271527
free(id);
1528-
CRM_ASSERT(rc == 0);
1528+
CRM_ASSERT(rc == pcmk_rc_ok);
15291529

15301530
if (replica->ip != NULL) {
15311531
out->message(out, crm_map_element_name(replica->ip->xml), options, replica->ip);
@@ -1634,7 +1634,7 @@ pe__bundle_html(pcmk__output_t *out, va_list args)
16341634
}
16351635

16361636
out->end_list(out);
1637-
return 0;
1637+
return pcmk_rc_ok;
16381638
}
16391639

16401640
static void
@@ -1719,7 +1719,7 @@ pe__bundle_text(pcmk__output_t *out, va_list args)
17191719
}
17201720

17211721
out->end_list(out);
1722-
return 0;
1722+
return pcmk_rc_ok;
17231723
}
17241724

17251725
static void

lib/pengine/clone.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ pe__clone_xml(pcmk__output_t *out, va_list args)
584584
, "failed", BOOL2STR(is_set(rsc->flags, pe_rsc_failed))
585585
, "failure_ignored", BOOL2STR(is_set(rsc->flags, pe_rsc_failure_ignored))
586586
, "target_role", configured_role_str(rsc));
587-
CRM_ASSERT(rc == 0);
587+
CRM_ASSERT(rc == pcmk_rc_ok);
588588

589589
for (; gIter != NULL; gIter = gIter->next) {
590590
pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
@@ -781,7 +781,7 @@ pe__clone_html(pcmk__output_t *out, va_list args)
781781

782782
out->end_list(out);
783783

784-
return 0;
784+
return pcmk_rc_ok;
785785
}
786786

787787
int
@@ -968,8 +968,9 @@ pe__clone_text(pcmk__output_t *out, va_list args)
968968

969969
out->end_list(out);
970970

971-
return 0;
971+
return pcmk_rc_ok;
972972
}
973+
973974
void
974975
clone_free(resource_t * rsc)
975976
{

lib/pengine/group.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pe__group_xml(pcmk__output_t *out, va_list args)
196196
, "id", rsc->id
197197
, "number_resources", count);
198198
free(count);
199-
CRM_ASSERT(rc == 0);
199+
CRM_ASSERT(rc == pcmk_rc_ok);
200200

201201
for (; gIter != NULL; gIter = gIter->next) {
202202
pe_resource_t *child_rsc = (pe_resource_t *) gIter->data;
@@ -228,7 +228,7 @@ pe__group_html(pcmk__output_t *out, va_list args)
228228

229229
out->end_list(out);
230230

231-
return 0;
231+
return pcmk_rc_ok;
232232
}
233233

234234
int
@@ -251,7 +251,7 @@ pe__group_text(pcmk__output_t *out, va_list args)
251251
}
252252
out->end_list(out);
253253

254-
return 0;
254+
return pcmk_rc_ok;
255255
}
256256

257257
void

0 commit comments

Comments
 (0)