pacemaker  2.1.3-ea053b43a
Scalable High-Availability cluster resource manager
util.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2022 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef PCMK__CRM_COMMON_UTIL__H
11 # define PCMK__CRM_COMMON_UTIL__H
12 
13 # include <sys/types.h> // gid_t, mode_t, size_t, time_t, uid_t
14 # include <stdlib.h>
15 # include <stdbool.h>
16 # include <stdint.h> // uint32_t
17 # include <limits.h>
18 # include <signal.h>
19 # include <glib.h>
20 
21 # include <libxml/tree.h>
22 
23 # include <crm/lrmd.h>
24 # include <crm/common/acl.h>
25 # include <crm/common/agents.h>
26 # include <crm/common/results.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
39 # define ONLINESTATUS "online" // Status of an online client
40 # define OFFLINESTATUS "offline" // Status of an offline client
41 
42 /* public node attribute functions (from attrd_client.c) */
43 char *pcmk_promotion_score_name(const char *rsc_id);
44 
45 /* public Pacemaker Remote functions (from remote.c) */
46 int crm_default_remote_port(void);
47 
48 /* public score-related functions (from scores.c) */
49 int char2score(const char *score);
50 char *score2char(int score);
51 char *score2char_stack(int score, char *buf, size_t len);
52 int pcmk__add_scores(int score1, int score2);
53 
54 /* public string functions (from strings.c) */
55 gboolean crm_is_true(const char *s);
56 int crm_str_to_boolean(const char *s, int *ret);
57 long long crm_get_msec(const char *input);
58 char * crm_strip_trailing_newline(char *str);
59 char *crm_strdup_printf(char const *format, ...) G_GNUC_PRINTF(1, 2);
60 
61 guint crm_parse_interval_spec(const char *input);
62 
63 /* public operation functions (from operations.c) */
64 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
65  guint *interval_ms);
66 gboolean decode_transition_key(const char *key, char **uuid, int *transition_id,
67  int *action_id, int *target_rc);
68 gboolean decode_transition_magic(const char *magic, char **uuid,
69  int *transition_id, int *action_id,
70  int *op_status, int *op_rc, int *target_rc);
72 gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
73 bool crm_op_needs_metadata(const char *rsc_class, const char *op);
74 xmlNode *crm_create_op_xml(xmlNode *parent, const char *prefix,
75  const char *task, const char *interval_spec,
76  const char *timeout);
77 #define CRM_DEFAULT_OP_TIMEOUT_S "20s"
78 
79 bool pcmk_is_probe(const char *task, guint interval);
80 bool pcmk_xe_is_probe(xmlNode *xml_op);
81 bool pcmk_xe_mask_probe_failure(xmlNode *xml_op);
82 
83 int compare_version(const char *version1, const char *version2);
84 
85 /* coverity[+kill] */
86 void crm_abort(const char *file, const char *function, int line,
87  const char *condition, gboolean do_core, gboolean do_fork);
88 
98 static inline bool
99 pcmk_any_flags_set(uint64_t flag_group, uint64_t flags_to_check)
100 {
101  return (flag_group & flags_to_check) != 0;
102 }
103 
113 static inline bool
114 pcmk_all_flags_set(uint64_t flag_group, uint64_t flags_to_check)
115 {
116  return (flag_group & flags_to_check) == flags_to_check;
117 }
118 
122 #define pcmk_is_set(g, f) pcmk_all_flags_set((g), (f))
123 
124 char *crm_meta_name(const char *field);
125 const char *crm_meta_value(GHashTable * hash, const char *field);
126 
127 char *crm_md5sum(const char *buffer);
128 
129 char *crm_generate_uuid(void);
130 
131 // This belongs in ipc.h but is here for backward compatibility
132 bool crm_is_daemon_name(const char *name);
133 
134 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
135 int pcmk_daemon_user(uid_t *uid, gid_t *gid);
136 
137 #ifdef HAVE_GNUTLS_GNUTLS_H
138 void crm_gnutls_global_init(void);
139 #endif
140 
141 char *pcmk_hostname(void);
142 
143 bool pcmk_str_is_infinity(const char *s);
144 bool pcmk_str_is_minus_infinity(const char *s);
145 
146 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
147 #include <crm/common/util_compat.h>
148 #endif
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif
API related to resource agents.
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, guint *interval_ms)
Definition: operations.c:185
xmlNode * crm_create_op_xml(xmlNode *parent, const char *prefix, const char *task, const char *interval_spec, const char *timeout)
Create a CIB XML element for an operation.
Definition: operations.c:474
bool crm_is_daemon_name(const char *name)
Check whether string represents a client name used by cluster daemons.
Definition: ipc_server.c:995
char * crm_generate_uuid(void)
Definition: utils.c:480
const char * name
Definition: cib.c:24
int rsc_op_expected_rc(lrmd_event_data_t *event)
Definition: operations.c:426
int char2score(const char *score)
Get the integer value of a score string.
Definition: scores.c:36
long long crm_get_msec(const char *input)
Parse a time+units string and return milliseconds equivalent.
Definition: strings.c:364
char * score2char_stack(int score, char *buf, size_t len)
Convert an integer score to a string, using a provided buffer.
Definition: scores.c:85
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition: utils.c:461
bool pcmk_is_probe(const char *task, guint interval)
Definition: operations.c:542
Resource agent executor.
bool crm_op_needs_metadata(const char *rsc_class, const char *op)
Check whether an operation requires resource agent meta-data.
Definition: operations.c:501
char * pcmk_promotion_score_name(const char *rsc_id)
Return the name of the node attribute used as a promotion score.
Definition: attrd_client.c:320
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
Definition: utils.c:57
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user.
Definition: utils.c:97
char * crm_meta_name(const char *field)
Definition: utils.c:439
op_status
Low-level API for XML Access Control Lists (ACLs)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
bool pcmk_xe_mask_probe_failure(xmlNode *xml_op)
Definition: operations.c:563
bool pcmk_str_is_infinity(const char *s)
Definition: utils.c:513
Function and executable result codes.
int crm_str_to_boolean(const char *s, int *ret)
Definition: strings.c:427
bool pcmk_xe_is_probe(xmlNode *xml_op)
Definition: operations.c:552
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
Definition: operations.c:437
bool pcmk_str_is_minus_infinity(const char *s)
Definition: utils.c:518
char guint crm_parse_interval_spec(const char *input)
Parse milliseconds from a Pacemaker interval specification.
Definition: utils.c:242
gboolean decode_transition_key(const char *key, char **uuid, int *transition_id, int *action_id, int *target_rc)
Parse a transition key into its constituent parts.
Definition: operations.c:318
Deprecated Pacemaker utilities.
xmlNode * input
int compare_version(const char *version1, const char *version2)
Definition: utils.c:160
gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id, int *op_status, int *op_rc, int *target_rc)
Parse a transition magic string into its constituent parts.
Definition: operations.c:255
int pcmk__add_scores(int score1, int score2)
Definition: scores.c:140
char * crm_md5sum(const char *buffer)
Definition: digest.c:271
gboolean crm_is_true(const char *s)
Definition: strings.c:416
char * pcmk_hostname(void)
Get the local hostname.
Definition: utils.c:505
char * crm_strip_trailing_newline(char *str)
Definition: strings.c:1317
const char * parent
Definition: cib.c:25
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
Definition: utils.c:368
unsigned int timeout
Definition: pcmk_fence.c:31
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
Definition: remote.c:1249
char * score2char(int score)
Return the string equivalent of an integer score.
Definition: scores.c:114