pacemaker  1.1.15-e174ec8
Scalable High-Availability cluster resource manager
util.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CRM_COMMON_UTIL__H
19 # define CRM_COMMON_UTIL__H
20 
27 # include <sys/types.h>
28 # include <stdlib.h>
29 # include <limits.h>
30 # include <signal.h>
31 # include <sysexits.h>
32 
33 # include <crm/lrmd.h>
34 
35 # if SUPPORT_HEARTBEAT
36 # include <heartbeat.h>
37 # else
38 # define NORMALNODE "normal"
39 # define ACTIVESTATUS "active"/* fully functional, and all links are up */
40 # define DEADSTATUS "dead"
41  /* Status of non-working link or machine */
42 # define PINGSTATUS "ping"
43  /* Status of a working ping node */
44 # define JOINSTATUS "join"
45  /* Status when an api client joins */
46 # define LEAVESTATUS "leave"
47  /* Status when an api client leaves */
48 # define ONLINESTATUS "online"/* Status of an online client */
49 # define OFFLINESTATUS "offline"
50  /* Status of an offline client */
51 # endif
52 
53 char *crm_itoa_stack(int an_int, char *buf, size_t len);
54 char *crm_itoa(int an_int);
55 gboolean crm_is_true(const char *s);
56 int crm_str_to_boolean(const char *s, int *ret);
57 int crm_parse_int(const char *text, const char *default_text);
58 long long crm_get_msec(const char *input);
59 unsigned long long crm_get_interval(const char *input);
60 int char2score(const char *score);
61 char *score2char(int score);
62 char *score2char_stack(int score, char *buf, size_t len);
63 
64 int compare_version(const char *version1, const char *version2);
65 
66 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, int *interval);
67 gboolean decode_transition_key(const char *key, char **uuid, int *action, int *transition_id,
68  int *target_rc);
69 gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id,
70  int *op_status, int *op_rc, int *target_rc);
71 
72 char * crm_strip_trailing_newline(char *str);
73 
74 # define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
75 
76 gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
77 
78 /* used with hash tables where case does not matter */
79 static inline gboolean
80 crm_strcase_equal(gconstpointer a, gconstpointer b)
81 {
82  return crm_str_eq((const char *) a, (const char *) b, FALSE);
83 }
84 
85 gboolean safe_str_neq(const char *a, const char *b);
86 
87 # define crm_atoi(text, default_text) crm_parse_int(text, default_text)
88 
89 /* coverity[+kill] */
90 void crm_abort(const char *file, const char *function, int line,
91  const char *condition, gboolean do_core, gboolean do_fork);
92 
93 static inline gboolean
94 is_not_set(long long word, long long bit)
95 {
96  return ((word & bit) == 0);
97 }
98 
99 static inline gboolean
100 is_set(long long word, long long bit)
101 {
102  return ((word & bit) == bit);
103 }
104 
105 static inline gboolean
106 is_set_any(long long word, long long bit)
107 {
108  return ((word & bit) != 0);
109 }
110 
111 static inline guint
112 crm_hash_table_size(GHashTable * hashtable)
113 {
114  if (hashtable == NULL) {
115  return 0;
116  }
117  return g_hash_table_size(hashtable);
118 }
119 
120 char *crm_meta_name(const char *field);
121 const char *crm_meta_value(GHashTable * hash, const char *field);
122 
124 gboolean did_rsc_op_fail(lrmd_event_data_t * event, int target_rc);
125 
126 char *crm_md5sum(const char *buffer);
127 
128 char *crm_generate_uuid(void);
129 
130 void crm_build_path(const char *path_c, mode_t mode);
131 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
132 
133 #ifdef HAVE_GNUTLS_GNUTLS_H
134 void crm_gnutls_global_init(void);
135 #endif
136 
137 int crm_exit(int rc);
138 bool pcmk_acl_required(const char *user);
139 
140 #endif
gboolean safe_str_neq(const char *a, const char *b)
Definition: utils.c:696
char * crm_generate_uuid(void)
Definition: utils.c:2361
void crm_build_path(const char *path_c, mode_t mode)
Create a directory, including any parent directories needed.
Definition: io.c:49
int rsc_op_expected_rc(lrmd_event_data_t *event)
Definition: utils.c:1943
int char2score(const char *score)
Definition: utils.c:253
long long crm_get_msec(const char *input)
Definition: utils.c:776
char * score2char_stack(int score, char *buf, size_t len)
Definition: utils.c:291
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition: utils.c:1483
int crm_parse_int(const char *text, const char *default_text)
Definition: utils.c:671
Local Resource Manager.
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
Definition: utils.c:483
char * crm_meta_name(const char *field)
Definition: utils.c:1461
gboolean decode_transition_key(const char *key, char **uuid, int *action, int *transition_id, int *target_rc)
Definition: utils.c:1019
op_status
Definition: services.h:120
bool pcmk_acl_required(const char *user)
Definition: utils.c:2151
unsigned long long crm_get_interval(const char *input)
Definition: utils.c:751
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: utils.c:1441
char * crm_itoa_stack(int an_int, char *buf, size_t len)
Definition: utils.c:459
int crm_str_to_boolean(const char *s, int *ret)
Definition: utils.c:722
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, int *interval)
Definition: utils.c:848
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
Definition: utils.c:1958
int compare_version(const char *version1, const char *version2)
Definition: utils.c:536
gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id, int *op_status, int *op_rc, int *target_rc)
Definition: utils.c:976
int crm_exit(int rc)
Definition: utils.c:87
char * crm_md5sum(const char *buffer)
Definition: utils.c:2374
gboolean crm_is_true(const char *s)
Definition: utils.c:711
char * crm_strip_trailing_newline(char *str)
Definition: utils.c:1425
char * crm_itoa(int an_int)
Definition: utils.c:469
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
Definition: utils.c:1154
char * score2char(int score)
Definition: utils.c:305