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 Jun 24, 2024
1 parent bd653a8 commit dfd274a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/pacemaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,11 @@ static int save_attributes(struct ticket_config *tk, xmlDocPtr doc)

#define CHUNK_SIZE 256

static int parse_ticket_state(struct ticket_config *tk, FILE *p)
static int read_ticket_state(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 @@ -542,8 +541,8 @@ static int parse_ticket_state(struct ticket_config *tk, FILE *p)
}
}

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 @@ -555,18 +554,16 @@ static int parse_ticket_state(struct ticket_config *tk, FILE *p)
rv = -EINVAL;
goto out;
}
rv = save_attributes(tk, doc);

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

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

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

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

0 comments on commit dfd274a

Please sign in to comment.