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