Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors from cluster_status #3735

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
60 changes: 59 additions & 1 deletion tools/crm_ticket.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,54 @@ static GOptionEntry deprecated_entries[] = {
{ NULL }
};

/*!
* \internal
* \brief Output a configuration error
*
* \param[in] ctx Output object
* \param[in] msg printf(3)-style format string
* \param[in] ... Format string arguments
*/
G_GNUC_PRINTF(2, 3)
static void
output_config_error(void *ctx, const char *msg, ...)
{
va_list ap;
char *buf = NULL;
pcmk__output_t *out = ctx;

va_start(ap, msg);
pcmk__assert(vasprintf(&buf, msg, ap) > 0);
if (!out->is_quiet(out)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well just un-deprecate -Q

out->err(out, "error: %s", buf);
}
va_end(ap);
}

/*!
* \internal
* \brief Output a configuration warning
*
* \param[in] ctx Output object
* \param[in] msg printf(3)-style format string
* \param[in] ... Format string arguments
*/
G_GNUC_PRINTF(2, 3)
static void
output_config_warning(void *ctx, const char *msg, ...)
{
va_list ap;
char *buf = NULL;
pcmk__output_t *out = ctx;

va_start(ap, msg);
pcmk__assert(vasprintf(&buf, msg, ap) > 0);
if (!out->is_quiet(out)) {
out->err(out, "warning: %s", buf);
}
va_end(ap);
}

static void
ticket_grant_warning(gchar *ticket_id)
{
Expand Down Expand Up @@ -382,6 +430,11 @@ main(int argc, char **argv)
pe__register_messages(out);
pcmk__register_lib_messages(out);

out->quiet = options.quiet;

pcmk__set_config_error_handler(output_config_error, out);
pcmk__set_config_warning_handler(output_config_warning, out);

if (args->version) {
out->version(out, false);
goto done;
Expand Down Expand Up @@ -441,7 +494,12 @@ main(int argc, char **argv)
scheduler->input = cib_xml_copy;
scheduler->priv->now = crm_time_new(NULL);

pcmk_unpack_scheduler_input(scheduler);
rc = pcmk_unpack_scheduler_input(scheduler);
if (rc != pcmk_rc_ok) {
/* Error printing is handled by pcmk__set_config_error_handler */
exit_code = pcmk_rc2exitc(rc);
goto done;
}

/* For recording the tickets that are referenced in PCMK_XE_RSC_TICKET
* constraints but have never been granted yet.
Expand Down