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 offset = 1;
170 int int_value = char2score(old_value);
171
172 if (value[plus_plus_len + 1] != '+') {
173 const char *offset_s = value + (plus_plus_len + 2);
174
175 offset = char2score(offset_s);
176 }
177 int_value += offset;
178
179 if (int_value > PCMK_SCORE_INFINITY) {
180 int_value = PCMK_SCORE_INFINITY;
181 }
182 return int_value;
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 int
199 attrd_failure_regex(regex_t *regex, const char *rsc, const char *op,
200 guint interval_ms)
201 {
202 char *pattern = NULL;
203 int rc;
204
205
206
207 if (rsc == NULL) {
208 pattern = pcmk__str_copy(ATTRD_RE_CLEAR_ALL);
209 } else if (op == NULL) {
210 pattern = crm_strdup_printf(ATTRD_RE_CLEAR_ONE, rsc);
211 } else {
212 pattern = crm_strdup_printf(ATTRD_RE_CLEAR_OP, rsc, op, interval_ms);
213 }
214
215
216 crm_trace("Clearing attributes matching %s", pattern);
217 rc = regcomp(regex, pattern, REG_EXTENDED|REG_NOSUB);
218 free(pattern);
219
220 return (rc == 0)? pcmk_ok : -EINVAL;
221 }
222
223 void
224 attrd_free_attribute_value(gpointer data)
225 {
226 attribute_value_t *v = data;
227
228 free(v->nodename);
229 free(v->current);
230 free(v->requested);
231 free(v);
232 }
233
234 void
235 attrd_free_attribute(gpointer data)
236 {
237 attribute_t *a = data;
238 if(a) {
239 free(a->id);
240 free(a->set_id);
241 free(a->set_type);
242 free(a->user);
243
244 mainloop_timer_del(a->timer);
245 g_hash_table_destroy(a->values);
246
247 free(a);
248 }
249 }
250
251
252
253
254
255
256
257 void
258 attrd_remove_peer_protocol_ver(const char *host)
259 {
260 if (peer_protocol_vers != NULL) {
261 g_hash_table_remove(peer_protocol_vers, host);
262 }
263 }
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279 void
280 attrd_update_minimum_protocol_ver(const char *host, const char *value)
281 {
282 int ver;
283
284 if (peer_protocol_vers == NULL) {
285 peer_protocol_vers = pcmk__strkey_table(free, NULL);
286 }
287
288 pcmk__scan_min_int(value, &ver, 0);
289
290 if (ver > 0) {
291
292 g_hash_table_insert(peer_protocol_vers, pcmk__str_copy(host),
293 GINT_TO_POINTER(ver));
294
295
296 if (minimum_protocol_version == -1 || ver < minimum_protocol_version) {
297 minimum_protocol_version = ver;
298 crm_trace("Set minimum attrd protocol version to %d",
299 minimum_protocol_version);
300 }
301 }
302 }