Skip to content

Commit 7a94c72

Browse files
committed
pacemaker: Rename parse_ticket_state to read_ticket_state.
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.
1 parent 23c1aab commit 7a94c72

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/pcmk.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,12 @@ static int save_attributes(struct booth_config *conf, struct ticket_config *tk,
530530

531531
#define CHUNK_SIZE 256
532532

533-
static int parse_ticket_state(struct booth_config *conf, struct ticket_config *tk,
534-
FILE *p)
533+
static int read_ticket_state(struct booth_config *conf, struct ticket_config *tk,
534+
xmlDocPtr *doc, FILE *p)
535535
{
536536
int rv = 0;
537537
GString *input = NULL;
538538
char line[CHUNK_SIZE];
539-
xmlDocPtr doc = NULL;
540539
int opts = XML_PARSE_COMPACT | XML_PARSE_NONET;
541540

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

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

577575
out:
578-
if (doc)
579-
xmlFreeDoc(doc);
580576
if (input)
581577
g_string_free(input, TRUE);
582578
return rv;
583579
}
584580

585581
static int pcmk_load_ticket(struct booth_config *conf, struct ticket_config *tk)
586582
{
583+
xmlDocPtr doc;
587584
char cmd[COMMAND_MAX];
588585
int rv = 0, pipe_rv;
589586
int res;
@@ -606,7 +603,11 @@ static int pcmk_load_ticket(struct booth_config *conf, struct ticket_config *tk)
606603
return (pipe_rv != 0 ? pipe_rv : EINVAL);
607604
}
608605

609-
rv = parse_ticket_state(conf, tk, p);
606+
rv = read_ticket_state(conf, tk, &doc, p);
607+
if (rv == 0) {
608+
rv = save_attributes(conf, tk, doc);
609+
xmlFreeDoc(doc);
610+
}
610611

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

0 commit comments

Comments
 (0)