pacemaker  2.1.1-52dc28db4
Scalable High-Availability cluster resource manager
util.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2021 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 CRM_COMMON_UTIL__H
11 # define CRM_COMMON_UTIL__H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
23 # include <sys/types.h> // gid_t, mode_t, size_t, time_t, uid_t
24 # include <stdlib.h>
25 # include <stdbool.h>
26 # include <stdint.h> // uint32_t
27 # include <limits.h>
28 # include <signal.h>
29 # include <glib.h>
30 
31 # include <libxml/tree.h>
32 
33 # include <crm/lrmd.h>
34 # include <crm/common/acl.h>
35 # include <crm/common/agents.h>
36 # include <crm/common/results.h>
37 
38 # define ONLINESTATUS "online" // Status of an online client
39 # define OFFLINESTATUS "offline" // Status of an offline client
40 
41 /* public node attribute functions (from attrd_client.c) */
42 char *pcmk_promotion_score_name(const char *rsc_id);
43 
44 /* public Pacemaker Remote functions (from remote.c) */
45 int crm_default_remote_port(void);
46 
47 /* public string functions (from strings.c) */
48 gboolean crm_is_true(const char *s);
49 int crm_str_to_boolean(const char *s, int *ret);
50 long long crm_get_msec(const char *input);
51 char * crm_strip_trailing_newline(char *str);
52 char *crm_strdup_printf(char const *format, ...) G_GNUC_PRINTF(1, 2);
53 
54 guint crm_parse_interval_spec(const char *input);
55 int char2score(const char *score);
56 char *score2char(int score);
57 char *score2char_stack(int score, char *buf, size_t len);
58 
59 /* public operation functions (from operations.c) */
60 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
61  guint *interval_ms);
62 gboolean decode_transition_key(const char *key, char **uuid, int *transition_id,
63  int *action_id, int *target_rc);
64 gboolean decode_transition_magic(const char *magic, char **uuid,
65  int *transition_id, int *action_id,
66  int *op_status, int *op_rc, int *target_rc);
68 gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
69 bool crm_op_needs_metadata(const char *rsc_class, const char *op);
70 xmlNode *crm_create_op_xml(xmlNode *parent, const char *prefix,
71  const char *task, const char *interval_spec,
72  const char *timeout);
73 #define CRM_DEFAULT_OP_TIMEOUT_S "20s"
74 
75 int compare_version(const char *version1, const char *version2);
76 
77 /* coverity[+kill] */
78 void crm_abort(const char *file, const char *function, int line,
79  const char *condition, gboolean do_core, gboolean do_fork);
80 
90 static inline bool
91 pcmk_any_flags_set(uint64_t flag_group, uint64_t flags_to_check)
92 {
93  return (flag_group & flags_to_check) != 0;
94 }
95 
105 static inline bool
106 pcmk_all_flags_set(uint64_t flag_group, uint64_t flags_to_check)
107 {
108  return (flag_group & flags_to_check) == flags_to_check;
109 }
110 
114 #define pcmk_is_set(g, f) pcmk_all_flags_set((g), (f))
115 
116 char *crm_meta_name(const char *field);
117 const char *crm_meta_value(GHashTable * hash, const char *field);
118 
119 char *crm_md5sum(const char *buffer);
120 
121 char *crm_generate_uuid(void);
122 
123 // This belongs in ipc.h but is here for backward compatibility
124 bool crm_is_daemon_name(const char *name);
125 
126 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
127 int pcmk_daemon_user(uid_t *uid, gid_t *gid);
128 
129 #ifdef HAVE_GNUTLS_GNUTLS_H
130 void crm_gnutls_global_init(void);
131 #endif
132 
133 char *pcmk_hostname(void);
134 
135 bool pcmk_str_is_infinity(const char *s);
136 bool pcmk_str_is_minus_infinity(const char *s);
137 
138 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
139 #include <crm/common/util_compat.h>
140 #endif
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #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:472
bool crm_is_daemon_name(const char *name)
Check whether string represents a client name used by cluster daemons.
Definition: ipc_server.c:958
char * crm_generate_uuid(void)
Definition: utils.c:552
int rsc_op_expected_rc(lrmd_event_data_t *event)
Definition: operations.c:426
int char2score(const char *score)
Definition: utils.c:61
long long crm_get_msec(const char *input)
Parse a time+units string and return milliseconds equivalent.
Definition: strings.c:363
char * score2char_stack(int score, char *buf, size_t len)
Definition: utils.c:101
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition: utils.c:533
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:499
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:129
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user.
Definition: utils.c:169
char * crm_meta_name(const char *field)
Definition: utils.c:511
op_status
Definition: services.h:86
Low-level API for XML Access Control Lists (ACLs)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
bool pcmk_str_is_infinity(const char *s)
Definition: utils.c:585
Function and executable result codes.
int crm_str_to_boolean(const char *s, int *ret)
Definition: strings.c:426
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:590
char guint crm_parse_interval_spec(const char *input)
Parse milliseconds from a Pacemaker interval specification.
Definition: utils.c:314
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
int compare_version(const char *version1, const char *version2)
Definition: utils.c:232
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
char * crm_md5sum(const char *buffer)
Definition: digest.c:271
gboolean crm_is_true(const char *s)
Definition: strings.c:415
char * pcmk_hostname(void)
Get the local hostname.
Definition: utils.c:577
char * crm_strip_trailing_newline(char *str)
Definition: strings.c:1303
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
Definition: utils.c:440
char * name
Definition: pcmk_fence.c:31
unsigned int timeout
Definition: pcmk_fence.c:32
Deprecated Pacemaker utilities.
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
Definition: remote.c:1249
char * score2char(int score)
Definition: utils.c:117