Skip to content

Commit

Permalink
pacemaker: Rename parse_ticket_state to read_ticket_state.
Browse files Browse the repository at this point in the history
This function is now slightly different.  Instead of going all the way
from reading a file pointer to loading attributes, it now stops before
loading the attributes and returns an XML document.  The attribute
loading happens afterwards in the caller.
  • Loading branch information
clumens committed Oct 1, 2024
1 parent 23c1aab commit 7a94c72
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/pcmk.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,12 @@ static int save_attributes(struct booth_config *conf, struct ticket_config *tk,

#define CHUNK_SIZE 256

static int parse_ticket_state(struct booth_config *conf, struct ticket_config *tk,
FILE *p)
static int read_ticket_state(struct booth_config *conf, struct ticket_config *tk,
xmlDocPtr *doc, FILE *p)
{
int rv = 0;
GString *input = NULL;
char line[CHUNK_SIZE];
xmlDocPtr doc = NULL;
int opts = XML_PARSE_COMPACT | XML_PARSE_NONET;

/* skip first two lines of output */
Expand All @@ -559,8 +558,8 @@ static int parse_ticket_state(struct booth_config *conf, struct ticket_config *t
}
}

doc = xmlReadDoc((const xmlChar *) input->str, NULL, NULL, opts);
if (doc == NULL) {
*doc = xmlReadDoc((const xmlChar *) input->str, NULL, NULL, opts);
if (*doc == NULL) {
const xmlError *errptr = xmlGetLastError();
if (errptr) {
tk_log_error("crm_ticket xml parse failed (domain=%d, level=%d, code=%d): %s",
Expand All @@ -572,18 +571,16 @@ static int parse_ticket_state(struct booth_config *conf, struct ticket_config *t
rv = -EINVAL;
goto out;
}
rv = save_attributes(conf, tk, doc);

out:
if (doc)
xmlFreeDoc(doc);
if (input)
g_string_free(input, TRUE);
return rv;
}

static int pcmk_load_ticket(struct booth_config *conf, struct ticket_config *tk)
{
xmlDocPtr doc;
char cmd[COMMAND_MAX];
int rv = 0, pipe_rv;
int res;
Expand All @@ -606,7 +603,11 @@ static int pcmk_load_ticket(struct booth_config *conf, struct ticket_config *tk)
return (pipe_rv != 0 ? pipe_rv : EINVAL);
}

rv = parse_ticket_state(conf, tk, p);
rv = read_ticket_state(conf, tk, &doc, p);
if (rv == 0) {
rv = save_attributes(conf, tk, doc);
xmlFreeDoc(doc);
}

if (!tk->leader) {
/* Hmm, no site found for the ticket we have in the
Expand Down

0 comments on commit 7a94c72

Please sign in to comment.