This source file includes following definitions.
- pcmk__is_privileged
- pcmk__open_devnull
- 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 #include <string.h>
17 #include <fcntl.h>
18 #include <sys/types.h>
19
20 #include <glib.h>
21 #include <libxml/tree.h>
22
23 #include <crm/common/util.h>
24 #include <crm/common/logging.h>
25 #include <crm/common/mainloop.h>
26 #include <crm/common/health_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
32
33
34
35
36
37
38
39 extern bool pcmk__is_daemon;
40
41
42 #define PCMK__NELEM(a) ((int) (sizeof(a)/sizeof(a[0])) )
43
44
45
46 char *pcmk__uid2username(uid_t uid);
47 const char *pcmk__update_acl_user(xmlNode *request, const char *field,
48 const char *peer_user);
49
50 static inline bool
51 pcmk__is_privileged(const char *user)
52 {
53 return user && (!strcmp(user, CRM_DAEMON_USER) || !strcmp(user, "root"));
54 }
55
56 void pcmk__enable_acl(xmlNode *acl_source, xmlNode *target, const char *user);
57
58 bool pcmk__check_acl(xmlNode *xml, const char *name,
59 enum xml_private_flags mode);
60
61 #if SUPPORT_CIBSECRETS
62
63
64 int pcmk__substitute_secrets(const char *rsc_id, GHashTable *params);
65 #endif
66
67
68
69
70 bool pcmk__verify_digest(xmlNode *input, const char *expected);
71
72
73
74
75 int pcmk__real_path(const char *path, char **resolved_path);
76
77 char *pcmk__series_filename(const char *directory, const char *series,
78 int sequence, bool bzip);
79 int pcmk__read_series_sequence(const char *directory, const char *series,
80 unsigned int *seq);
81 void pcmk__write_series_sequence(const char *directory, const char *series,
82 unsigned int sequence, int max);
83 int pcmk__chown_series_sequence(const char *directory, const char *series,
84 uid_t uid, gid_t gid);
85
86 int pcmk__build_path(const char *path_c, mode_t mode);
87 char *pcmk__full_path(const char *filename, const char *dirname);
88 bool pcmk__daemon_can_write(const char *dir, const char *file);
89 void pcmk__sync_directory(const char *name);
90
91 int pcmk__file_contents(const char *filename, char **contents);
92 int pcmk__write_sync(int fd, const char *contents);
93 int pcmk__set_nonblocking(int fd);
94 const char *pcmk__get_tmpdir(void);
95
96 void pcmk__close_fds_in_child(bool);
97
98
99
100
101
102
103
104
105
106
107 static inline void
108 pcmk__open_devnull(int flags)
109 {
110
111
112 (void) open("/dev/null", flags);
113 }
114
115
116
117
118 int pcmk__add_mainloop_ipc(crm_ipc_t *ipc, int priority, void *userdata,
119 struct ipc_client_callbacks *callbacks,
120 mainloop_io_t **source);
121 guint pcmk__mainloop_timer_get_period(mainloop_timer_t *timer);
122
123
124
125
126 int pcmk__scan_nvpair(const char *input, char **name, char **value);
127 char *pcmk__format_nvpair(const char *name, const char *value,
128 const char *units);
129 char *pcmk__format_named_time(const char *name, time_t epoch_time);
130
131
132
133
134
135
136
137
138
139 void
140 pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value);
141
142
143
144
145
146
147
148
149
150
151
152 bool
153 pcmk__xe_attr_is_true(xmlNodePtr node, const char *name);
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170 int
171 pcmk__xe_get_bool_attr(xmlNodePtr node, const char *name, bool *value);
172
173
174
175
176 pid_t pcmk__procfs_pid_of(const char *name);
177 unsigned int pcmk__procfs_num_cores(void);
178
179
180
181
182 void crm_schema_init(void);
183 void crm_schema_cleanup(void);
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 int pcmk__pid_active(pid_t pid, const char *daemon);
205
206 int pcmk__read_pidfile(const char *filename, pid_t *pid);
207 int pcmk__pidfile_matches(const char *filename, pid_t expected_pid,
208 const char *expected_name, pid_t *pid);
209 int pcmk__lock_pidfile(const char *filename, const char *name);
210
211
212
213
214
215 #define PCMK__OP_FMT "%s_%s_%u"
216
217 char *pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms);
218 char *pcmk__notify_key(const char *rsc_id, const char *notify_type,
219 const char *op_type);
220 char *pcmk__transition_key(int transition_id, int action_id, int target_rc,
221 const char *node);
222 void pcmk__filter_op_for_digest(xmlNode *param_set);
223 bool pcmk__is_fencing_action(const char *action);
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243 static inline uint64_t
244 pcmk__set_flags_as(const char *function, int line, uint8_t log_level,
245 const char *flag_type, const char *target,
246 uint64_t flag_group, uint64_t flags, const char *flags_str)
247 {
248 uint64_t result = flag_group | flags;
249
250 if (result != flag_group) {
251 do_crm_log_unlikely(log_level,
252 "%s flags %#.8llx (%s) for %s set by %s:%d",
253 ((flag_type == NULL)? "Group of" : flag_type),
254 (unsigned long long) flags,
255 ((flags_str == NULL)? "flags" : flags_str),
256 ((target == NULL)? "target" : target),
257 function, line);
258 }
259 return result;
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277 static inline uint64_t
278 pcmk__clear_flags_as(const char *function, int line, uint8_t log_level,
279 const char *flag_type, const char *target,
280 uint64_t flag_group, uint64_t flags, const char *flags_str)
281 {
282 uint64_t result = flag_group & ~flags;
283
284 if (result != flag_group) {
285 do_crm_log_unlikely(log_level,
286 "%s flags %#.8llx (%s) for %s cleared by %s:%d",
287 ((flag_type == NULL)? "Group of" : flag_type),
288 (unsigned long long) flags,
289 ((flags_str == NULL)? "flags" : flags_str),
290 ((target == NULL)? "target" : target),
291 function, line);
292 }
293 return result;
294 }
295
296
297
298 void pcmk__daemonize(const char *name, const char *pidfile);
299 void pcmk__panic(const char *origin);
300 pid_t pcmk__locate_sbd(void);
301 void pcmk__sleep_ms(unsigned int ms);
302
303 extern int pcmk__score_red;
304 extern int pcmk__score_green;
305 extern int pcmk__score_yellow;
306
307
308
309
310
311
312
313
314
315
316
317
318
319 static inline void *
320 pcmk__realloc(void *ptr, size_t size)
321 {
322 void *new_ptr;
323
324
325 CRM_ASSERT(size > 0);
326
327 new_ptr = realloc(ptr, size);
328 if (new_ptr == NULL) {
329 free(ptr);
330 abort();
331 }
332 return new_ptr;
333 }
334
335
336 static inline char *
337 pcmk__getpid_s(void)
338 {
339 return crm_strdup_printf("%lu", (unsigned long) getpid());
340 }
341
342
343 static inline bool
344 pcmk__list_of_1(GList *list)
345 {
346 return list && (list->next == NULL);
347 }
348
349
350 static inline bool
351 pcmk__list_of_multiple(GList *list)
352 {
353 return list && (list->next != NULL);
354 }
355
356
357
358 #define PCMK__FAIL_COUNT_PREFIX "fail-count"
359 #define PCMK__LAST_FAILURE_PREFIX "last-failure"
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378 static inline char *
379 pcmk__fail_attr_name(const char *prefix, const char *rsc_id, const char *op,
380 guint interval_ms)
381 {
382 CRM_CHECK(prefix && rsc_id && op, return NULL);
383 return crm_strdup_printf("%s-%s#%s_%u", prefix, rsc_id, op, interval_ms);
384 }
385
386 static inline char *
387 pcmk__failcount_name(const char *rsc_id, const char *op, guint interval_ms)
388 {
389 return pcmk__fail_attr_name(PCMK__FAIL_COUNT_PREFIX, rsc_id, op,
390 interval_ms);
391 }
392
393 static inline char *
394 pcmk__lastfailure_name(const char *rsc_id, const char *op, guint interval_ms)
395 {
396 return pcmk__fail_attr_name(PCMK__LAST_FAILURE_PREFIX, rsc_id, op,
397 interval_ms);
398 }
399
400
401 int pcmk__effective_rc(int rc);
402
403 #endif