This source file includes following definitions.
- pcmk__set_flags_as
- pcmk__clear_flags_as
- pcmk__realloc
- pcmk__getpid_s
- pcmk__list_of_1
- pcmk__list_of_multiple
- pcmk__fail_attr_name
- pcmk__failcount_name
- pcmk__lastfailure_name
1
2
3
4
5
6
7
8
9
10 #ifndef CRM_COMMON_INTERNAL__H
11 #define CRM_COMMON_INTERNAL__H
12
13 #include <unistd.h>
14 #include <stdbool.h>
15 #include <stdint.h>
16
17 #include <glib.h>
18 #include <libxml/tree.h>
19
20 #include <crm/common/util.h>
21 #include <crm/common/logging.h>
22 #include <crm/common/mainloop.h>
23 #include <crm/common/actions_internal.h>
24 #include <crm/common/digests_internal.h>
25 #include <crm/common/health_internal.h>
26 #include <crm/common/io_internal.h>
27 #include <crm/common/iso8601_internal.h>
28 #include <crm/common/results_internal.h>
29 #include <crm/common/messages_internal.h>
30 #include <crm/common/strings_internal.h>
31 #include <crm/common/acl_internal.h>
32
33
34
35
36
37
38
39
40 extern bool pcmk__is_daemon;
41
42
43 extern char *pcmk__our_nodename;
44
45
46 #define PCMK__NELEM(a) ((int) (sizeof(a)/sizeof(a[0])) )
47
48 #if SUPPORT_CIBSECRETS
49
50
51 int pcmk__substitute_secrets(const char *rsc_id, GHashTable *params);
52 #endif
53
54
55
56
57 int pcmk__add_mainloop_ipc(crm_ipc_t *ipc, int priority, void *userdata,
58 const struct ipc_client_callbacks *callbacks,
59 mainloop_io_t **source);
60 guint pcmk__mainloop_timer_get_period(const mainloop_timer_t *timer);
61
62
63
64
65
66
67
68
69
70
71
72
73 void pcmk__xe_add_node(xmlNode *xml, const char *node, int nodeid);
74
75
76
77
78 int pcmk__scan_nvpair(const char *input, char **name, char **value);
79 char *pcmk__format_nvpair(const char *name, const char *value,
80 const char *units);
81
82
83
84
85
86
87
88
89
90 void
91 pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value);
92
93
94
95
96
97
98
99
100
101
102
103 bool
104 pcmk__xe_attr_is_true(const xmlNode *node, const char *name);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 int
122 pcmk__xe_get_bool_attr(const xmlNode *node, const char *name, bool *value);
123
124
125
126
127 pid_t pcmk__procfs_pid_of(const char *name);
128 unsigned int pcmk__procfs_num_cores(void);
129 int pcmk__procfs_pid2path(pid_t pid, char path[], size_t path_size);
130 bool pcmk__procfs_has_pids(void);
131
132
133
134 void crm_schema_init(void);
135 void crm_schema_cleanup(void);
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 int pcmk__pid_active(pid_t pid, const char *daemon);
157
158 int pcmk__read_pidfile(const char *filename, pid_t *pid);
159 int pcmk__pidfile_matches(const char *filename, pid_t expected_pid,
160 const char *expected_name, pid_t *pid);
161 int pcmk__lock_pidfile(const char *filename, const char *name);
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 static inline uint64_t
182 pcmk__set_flags_as(const char *function, int line, uint8_t log_level,
183 const char *flag_type, const char *target,
184 uint64_t flag_group, uint64_t flags, const char *flags_str)
185 {
186 uint64_t result = flag_group | flags;
187
188 if (result != flag_group) {
189 do_crm_log_unlikely(log_level,
190 "%s flags %#.8llx (%s) for %s set by %s:%d",
191 ((flag_type == NULL)? "Group of" : flag_type),
192 (unsigned long long) flags,
193 ((flags_str == NULL)? "flags" : flags_str),
194 ((target == NULL)? "target" : target),
195 function, line);
196 }
197 return result;
198 }
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 static inline uint64_t
216 pcmk__clear_flags_as(const char *function, int line, uint8_t log_level,
217 const char *flag_type, const char *target,
218 uint64_t flag_group, uint64_t flags, const char *flags_str)
219 {
220 uint64_t result = flag_group & ~flags;
221
222 if (result != flag_group) {
223 do_crm_log_unlikely(log_level,
224 "%s flags %#.8llx (%s) for %s cleared by %s:%d",
225 ((flag_type == NULL)? "Group of" : flag_type),
226 (unsigned long long) flags,
227 ((flags_str == NULL)? "flags" : flags_str),
228 ((target == NULL)? "target" : target),
229 function, line);
230 }
231 return result;
232 }
233
234
235
236 void pcmk__daemonize(const char *name, const char *pidfile);
237 void pcmk__panic(const char *origin);
238 pid_t pcmk__locate_sbd(void);
239 void pcmk__sleep_ms(unsigned int ms);
240
241 extern int pcmk__score_red;
242 extern int pcmk__score_green;
243 extern int pcmk__score_yellow;
244
245
246
247
248
249
250
251
252
253
254
255
256
257 static inline void *
258 pcmk__realloc(void *ptr, size_t size)
259 {
260 void *new_ptr;
261
262
263 CRM_ASSERT(size > 0);
264
265 new_ptr = realloc(ptr, size);
266 if (new_ptr == NULL) {
267 free(ptr);
268 abort();
269 }
270 return new_ptr;
271 }
272
273
274 static inline char *
275 pcmk__getpid_s(void)
276 {
277 return crm_strdup_printf("%lu", (unsigned long) getpid());
278 }
279
280
281 static inline bool
282 pcmk__list_of_1(GList *list)
283 {
284 return list && (list->next == NULL);
285 }
286
287
288 static inline bool
289 pcmk__list_of_multiple(GList *list)
290 {
291 return list && (list->next != NULL);
292 }
293
294
295
296 #define PCMK__FAIL_COUNT_PREFIX "fail-count"
297 #define PCMK__LAST_FAILURE_PREFIX "last-failure"
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316 static inline char *
317 pcmk__fail_attr_name(const char *prefix, const char *rsc_id, const char *op,
318 guint interval_ms)
319 {
320 CRM_CHECK(prefix && rsc_id && op, return NULL);
321 return crm_strdup_printf("%s-%s#%s_%u", prefix, rsc_id, op, interval_ms);
322 }
323
324 static inline char *
325 pcmk__failcount_name(const char *rsc_id, const char *op, guint interval_ms)
326 {
327 return pcmk__fail_attr_name(PCMK__FAIL_COUNT_PREFIX, rsc_id, op,
328 interval_ms);
329 }
330
331 static inline char *
332 pcmk__lastfailure_name(const char *rsc_id, const char *op, guint interval_ms)
333 {
334 return pcmk__fail_attr_name(PCMK__LAST_FAILURE_PREFIX, rsc_id, op,
335 interval_ms);
336 }
337
338
339 int pcmk__effective_rc(int rc);
340
341 #endif