-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable_rgmanager.c
125 lines (102 loc) · 2.53 KB
/
disable_rgmanager.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
Copyright Red Hat, Inc. 2004-2006
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
MA 02139, USA.
*/
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
#include <libxml/xpath.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libgen.h>
#define shift() {++argv; --argc;}
int
disable_rgmanager(xmlDocPtr doc)
{
char buf[32];
xmlNodePtr n, o;
char *a;
int x;
if (!doc)
return 0;
n = xmlDocGetRootElement(doc);
if (!n)
return 0;
if (strcmp((char *)n->name, "cluster")) {
fprintf(stderr,"Expected cluster tag, got %s\n",
(char *)n->name);
return 0;
}
a = (char *)xmlGetProp(n, (xmlChar *)"config_version");
if (!a) {
fprintf(stderr,"No config_version found on cluster tag\n");
return 0;
}
x = atoi(a);
if (x == 0) {
fprintf(stderr,"config_version was invalid\n");
return 0;
}
++x;
snprintf(buf, sizeof(buf), "%d", x);
if (xmlSetProp(n, (xmlChar *)"config_version", (xmlChar *)buf) == NULL) {
fprintf(stderr,"Failed to update config_version\n");
return 0;
}
for (o = n->xmlChildrenNode; o; o = o->next) {
if (o->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((char *)o->name, "rm"))
break;
}
if (!o)
return 0;
if (xmlSetProp(o, (xmlChar *)"disabled", (xmlChar *)"1") == NULL) {
fprintf(stderr,"Failed to disable rgmanager\n");
return 0;
}
return 1;
}
void
usage(const char *arg0, int ret)
{
fprintf(stderr,"usage: %s <input.conf> [output.conf]\n", arg0);
exit(ret);
}
int
main(int argc, char **argv)
{
char *arg0 = basename(argv[0]);
int ret = 0;
xmlDocPtr doc = NULL;
if (argc < 2) {
usage(arg0, 1);
}
if (!strcasecmp(argv[1], "-h") ||
!strcasecmp(argv[1], "-?")) {
usage(arg0, 0);
}
xmlInitParser();
xmlIndentTreeOutput = 1;
xmlKeepBlanksDefault(0);
shift();
doc = xmlParseFile(argv[0]);
if (disable_rgmanager(doc)) {
xmlDocFormatDump(stdout, doc, 1);
}
if (doc)
xmlFreeDoc(doc);
xmlCleanupParser();
return ret;
}