pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
util.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2024 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 <crm/common/acl.h>
22 #include <crm/common/actions.h>
23 #include <crm/common/agents.h>
24 #include <crm/common/results.h>
25 #include <crm/common/scores.h>
26 #include <crm/common/nvpair.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
38 /* public node attribute functions (from attrd_client.c) */
39 char *pcmk_promotion_score_name(const char *rsc_id);
40 
41 /* public Pacemaker Remote functions (from remote.c) */
42 int crm_default_remote_port(void);
43 
44 /* public string functions (from strings.c) */
45 
46 // NOTE: sbd (as of at least 1.5.2) uses this
47 gboolean crm_is_true(const char *s);
48 
49 int crm_str_to_boolean(const char *s, int *ret);
50 
51 // NOTE: sbd (as of at least 1.5.2) uses this
52 long long crm_get_msec(const char *input);
53 
54 // NOTE: sbd (as of at least 1.5.2) uses this
55 char *crm_strdup_printf(char const *format, ...) G_GNUC_PRINTF(1, 2);
56 
57 int pcmk_parse_interval_spec(const char *input, guint *result_ms);
58 
59 int compare_version(const char *version1, const char *version2);
60 
61 /* coverity[+kill] */
62 void crm_abort(const char *file, const char *function, int line,
63  const char *condition, gboolean do_core, gboolean do_fork);
64 
74 static inline bool
75 pcmk_any_flags_set(uint64_t flag_group, uint64_t flags_to_check)
76 {
77  return (flag_group & flags_to_check) != 0;
78 }
79 
89 static inline bool
90 pcmk_all_flags_set(uint64_t flag_group, uint64_t flags_to_check)
91 {
92  return (flag_group & flags_to_check) == flags_to_check;
93 }
94 
98 #define pcmk_is_set(g, f) pcmk_all_flags_set((g), (f))
99 
100 char *crm_md5sum(const char *buffer);
101 
102 char *crm_generate_uuid(void);
103 
104 // This belongs in ipc.h but is here for backward compatibility
105 bool crm_is_daemon_name(const char *name);
106 
107 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
108 int pcmk_daemon_user(uid_t *uid, gid_t *gid);
109 
110 #ifdef HAVE_GNUTLS_GNUTLS_H
111 void crm_gnutls_global_init(void);
112 #endif
113 
114 bool pcmk_str_is_infinity(const char *s);
115 bool pcmk_str_is_minus_infinity(const char *s);
116 
117 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1)
118 #include <crm/common/util_compat.h>
119 #endif
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif
API related to resource agents.
bool crm_is_daemon_name(const char *name)
Check whether string represents a client name used by cluster daemons.
Definition: ipc_server.c:1001
char * crm_generate_uuid(void)
Definition: utils.c:431
const char * name
Definition: cib.c:26
APIs related to actions.
long long crm_get_msec(const char *input)
Parse a time+units string and return milliseconds equivalent.
Definition: strings.c:356
char * pcmk_promotion_score_name(const char *rsc_id)
Return the name of the node attribute used as a promotion score.
Definition: attrs.c:92
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
Definition: utils.c:85
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user.
Definition: utils.c:125
char int pcmk_parse_interval_spec(const char *input, guint *result_ms)
Parse milliseconds from a Pacemaker interval specification.
Definition: strings.c:451
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:452
Function and executable result codes.
Functionality for manipulating name/value pairs.
int crm_str_to_boolean(const char *s, int *ret)
Definition: strings.c:496
bool pcmk_str_is_minus_infinity(const char *s)
Definition: utils.c:458
Deprecated Pacemaker utilities.
xmlNode * input
int compare_version(const char *version1, const char *version2)
Definition: utils.c:188
Pacemaker APIs related to scores.
char * crm_md5sum(const char *buffer)
Definition: digest.c:251
gboolean crm_is_true(const char *s)
Definition: strings.c:488
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
Definition: utils.c:356
int crm_default_remote_port(void)
Get the default remote connection TCP port on this host.
Definition: remote.c:1274