This source file includes following definitions.
- attrd_set_requesting_shutdown
- attrd_clear_requesting_shutdown
- attrd_shutting_down
- attrd_shutdown
- attrd_init_mainloop
- attrd_run_mainloop
- attrd_value_needs_expansion
- attrd_expand_value
- attrd_failure_regex
- attrd_free_attribute_value
- attrd_free_attribute
- attrd_remove_peer_protocol_ver
- attrd_update_minimum_protocol_ver
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <stdbool.h>
14 #include <errno.h>
15 #include <glib.h>
16 #include <regex.h>
17 #include <sys/types.h>
18
19 #include <crm/crm.h>
20 #include <crm/common/ipc_internal.h>
21 #include <crm/common/mainloop.h>
22 #include <crm/common/xml.h>
23
24 #include "pacemaker-attrd.h"
25
26 cib_t *the_cib = NULL;
27
28 static bool requesting_shutdown = false;
29 static bool shutting_down = false;
30 static GMainLoop *mloop = NULL;
31
32
33
34
35 GHashTable *peer_protocol_vers = NULL;
36
37
38
39
40
41 void
42 attrd_set_requesting_shutdown(void)
43 {
44 requesting_shutdown = true;
45 }
46
47
48
49
50
51 void
52 attrd_clear_requesting_shutdown(void)
53 {
54 requesting_shutdown = false;
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 bool
73 attrd_shutting_down(bool if_requested)
74 {
75 return shutting_down || (if_requested && requesting_shutdown);
76 }
77
78
79
80
81
82
83
84 void
85 attrd_shutdown(int nsig)
86 {
87
88 shutting_down = true;
89
90
91 mainloop_destroy_signal(SIGTERM);
92 mainloop_destroy_signal(SIGCHLD);
93 mainloop_destroy_signal(SIGPIPE);
94 mainloop_destroy_signal(SIGUSR1);
95 mainloop_destroy_signal(SIGUSR2);
96 mainloop_destroy_signal(SIGTRAP);
97
98 attrd_free_waitlist();
99 attrd_free_confirmations();
100
101 if (peer_protocol_vers != NULL) {
102 g_hash_table_destroy(peer_protocol_vers);
103 peer_protocol_vers = NULL;
104 }
105
106 if ((mloop == NULL) || !g_main_loop_is_running(mloop)) {
107
108
109
110 crm_exit(CRM_EX_OK);
111 } else {
112 g_main_loop_quit(mloop);
113 g_main_loop_unref(mloop);
114 }
115 }
116
117
118
119
120
121 void
122 attrd_init_mainloop(void)
123 {
124 mloop = g_main_loop_new(NULL, FALSE);
125 }
126
127
128
129
130
131 void
132 attrd_run_mainloop(void)
133 {
134 g_main_loop_run(mloop);
135 }
136
137
138 #define plus_plus_len (5)
139
140
141
142
143
144
145
146
147
148 bool
149 attrd_value_needs_expansion(const char *value)
150 {
151 return ((strlen(value) >= (plus_plus_len + 2))
152 && (value[plus_plus_len] == '+')
153 && ((value[plus_plus_len + 1] == '+')
154 || (value[plus_plus_len + 1] == '=')));
155 }
156
157
158
159
160
161
162
163
164
165
166 int
167 attrd_expand_value(const char *value, const char *old_value)
168 {
169 int increment = 1;
170 int score = 0;
171
172 if (pcmk_parse_score(old_value, &score, 0) != pcmk_rc_ok) {
173 return 0;
174 }
175
176
177 if ((value[plus_plus_len + 1] != '+')
178 && (pcmk_parse_score(value + plus_plus_len + 2, &increment,
179 0) != pcmk_rc_ok)) {
180 increment = 0;
181 }
182
183 if (increment < 0) {
184 return QB_MAX(score + increment, -PCMK_SCORE_INFINITY);
185 }
186 return QB_MIN(score + increment, PCMK_SCORE_INFINITY);
187 }
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202 int
203 attrd_failure_regex(regex_t *regex, const char *rsc, const char *op,
204 guint interval_ms)
205 {
206 char *pattern = NULL;
207 int rc;
208
209
210
211 if (rsc == NULL) {
212 pattern = pcmk__str_copy(ATTRD_RE_CLEAR_ALL);
213 } else if (op == NULL) {
214 pattern = crm_strdup_printf(ATTRD_RE_CLEAR_ONE, rsc);
215 } else {
216 pattern = crm_strdup_printf(ATTRD_RE_CLEAR_OP, rsc, op, interval_ms);
217 }
218
219
220 crm_trace("Clearing attributes matching %s", pattern);
221 rc = regcomp(regex, pattern, REG_EXTENDED|REG_NOSUB);
222 free(pattern);
223
224 return (rc == 0)? pcmk_ok : -EINVAL;
225 }
226
227 void
228 attrd_free_attribute_value(gpointer data)
229 {
230 attribute_value_t *v = data;
231
232 free(v->nodename);
233 free(v->current);
234 free(v->requested);
235 free(v);
236 }
237
238 void
239 attrd_free_attribute(gpointer data)
240 {
241 attribute_t *a = data;
242 if(a) {
243 free(a->id);
244 free(a->set_id);
245 free(a->set_type);
246 free(a->user);
247
248 mainloop_timer_del(a->timer);
249 g_hash_table_destroy(a->values);
250
251 free(a);
252 }
253 }
254
255
256
257
258
259
260
261 void
262 attrd_remove_peer_protocol_ver(const char *host)
263 {
264 if (peer_protocol_vers != NULL) {
265 g_hash_table_remove(peer_protocol_vers, host);
266 }
267 }
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283 void
284 attrd_update_minimum_protocol_ver(const char *host, const char *value)
285 {
286 int ver;
287
288 if (peer_protocol_vers == NULL) {
289 peer_protocol_vers = pcmk__strkey_table(free, NULL);
290 }
291
292 pcmk__scan_min_int(value, &ver, 0);
293
294 if (ver > 0) {
295
296 g_hash_table_insert(peer_protocol_vers, pcmk__str_copy(host),
297 GINT_TO_POINTER(ver));
298
299
300 if (minimum_protocol_version == -1 || ver < minimum_protocol_version) {
301 minimum_protocol_version = ver;
302 crm_trace("Set minimum attrd protocol version to %d",
303 minimum_protocol_version);
304 }
305 }
306 }