pacemaker 2.1.1-77db578727
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
14extern "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) */
42char *pcmk_promotion_score_name(const char *rsc_id);
43
44/* public Pacemaker Remote functions (from remote.c) */
46
47/* public string functions (from strings.c) */
48gboolean crm_is_true(const char *s);
49int crm_str_to_boolean(const char *s, int *ret);
50long long crm_get_msec(const char *input);
51char * crm_strip_trailing_newline(char *str);
52char *crm_strdup_printf(char const *format, ...) G_GNUC_PRINTF(1, 2);
53
54guint crm_parse_interval_spec(const char *input);
55int char2score(const char *score);
56char *score2char(int score);
57char *score2char_stack(int score, char *buf, size_t len);
58
59/* public operation functions (from operations.c) */
60gboolean parse_op_key(const char *key, char **rsc_id, char **op_type,
61 guint *interval_ms);
62gboolean decode_transition_key(const char *key, char **uuid, int *transition_id,
63 int *action_id, int *target_rc);
64gboolean 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);
68gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc);
69bool crm_op_needs_metadata(const char *rsc_class, const char *op);
70xmlNode *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
75int compare_version(const char *version1, const char *version2);
76
77/* coverity[+kill] */
78void crm_abort(const char *file, const char *function, int line,
79 const char *condition, gboolean do_core, gboolean do_fork);
80
90static inline bool
91pcmk_any_flags_set(uint64_t flag_group, uint64_t flags_to_check)
92{
93 return (flag_group & flags_to_check) != 0;
94}
95
105static inline bool
106pcmk_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
116char *crm_meta_name(const char *field);
117const char *crm_meta_value(GHashTable * hash, const char *field);
118
119char *crm_md5sum(const char *buffer);
120
121char *crm_generate_uuid(void);
122
123// This belongs in ipc.h but is here for backward compatibility
124bool crm_is_daemon_name(const char *name);
125
126int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
127int pcmk_daemon_user(uid_t *uid, gid_t *gid);
128
129#ifdef HAVE_GNUTLS_GNUTLS_H
130void crm_gnutls_global_init(void);
131#endif
132
133char *pcmk_hostname(void);
134
135bool pcmk_str_is_infinity(const char *s);
136bool pcmk_str_is_minus_infinity(const char *s);
137
138#if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
140#endif
141
142#ifdef __cplusplus
143}
144#endif
145
146#endif
Low-level API for XML Access Control Lists (ACLs)
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
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition utils.c:533
bool pcmk_str_is_infinity(const char *s)
Definition utils.c:585
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
Definition operations.c:437
char * score2char_stack(int score, char *buf, size_t len)
Definition utils.c:101
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
char * crm_md5sum(const char *buffer)
Definition digest.c:271
char guint crm_parse_interval_spec(const char *input)
Parse milliseconds from a Pacemaker interval specification.
Definition utils.c:314
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user.
Definition utils.c:169
int rsc_op_expected_rc(lrmd_event_data_t *event)
Definition operations.c:426
char * crm_generate_uuid(void)
Definition utils.c:552
char * crm_meta_name(const char *field)
Definition utils.c:511
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
Definition remote.c:1249
long long crm_get_msec(const char *input)
Parse a time+units string and return milliseconds equivalent.
Definition strings.c:363
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 * score2char(int score)
Definition utils.c:117
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
int char2score(const char *score)
Definition utils.c:61
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
Definition utils.c:129
char * pcmk_promotion_score_name(const char *rsc_id)
Return the name of the node attribute used as a promotion score.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
char * crm_strip_trailing_newline(char *str)
Definition strings.c:1303
int compare_version(const char *version1, const char *version2)
Definition utils.c:232
char * pcmk_hostname(void)
Get the local hostname.
Definition utils.c:577
bool crm_is_daemon_name(const char *name)
Check whether string represents a client name used by cluster daemons.
Definition ipc_server.c:958
gboolean crm_is_true(const char *s)
Definition strings.c:415
int crm_str_to_boolean(const char *s, int *ret)
Definition strings.c:426
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
bool pcmk_str_is_minus_infinity(const char *s)
Definition utils.c:590
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
Resource agent executor.
unsigned int timeout
Definition pcmk_fence.c:32
char * name
Definition pcmk_fence.c:31
Function and executable result codes.
op_status
Definition services.h:86
Deprecated Pacemaker utilities.