pacemaker  1.1.16-94ff4df
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
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 /* public string functions (from strings.c) */
54 char *crm_itoa_stack(int an_int, char *buf, size_t len);
55 char *crm_itoa(int an_int);
56 gboolean crm_is_true(const char *s);
57 int crm_str_to_boolean(const char *s, int *ret);
58 int crm_parse_int(const char *text, const char *default_text);
59 char * crm_strip_trailing_newline(char *str);
60 gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
61 gboolean safe_str_neq(const char *a, const char *b);
62 
63 # define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
64 
65 /* used with hash tables where case does not matter */
66 static inline gboolean
67 crm_strcase_equal(gconstpointer a, gconstpointer b)
68 {
69  return crm_str_eq((const char *) a, (const char *) b, FALSE);
70 }
71 
72 # define crm_atoi(text, default_text) crm_parse_int(text, default_text)
73 
74 /* public I/O functions (from io.c) */
75 void crm_build_path(const char *path_c, mode_t mode);
76 
77 long long crm_get_msec(const char *input);
78 unsigned long long crm_get_interval(const char *input);
79 int char2score(const char *score);
80 char *score2char(int score);
81 char *score2char_stack(int score, char *buf, size_t len);
82 
83 int compare_version(const char *version1, const char *version2);
84 
85 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, int *interval);
86 gboolean decode_transition_key(const char *key, char **uuid, int *action, int *transition_id,
87  int *target_rc);
88 gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id,
89  int *op_status, int *op_rc, int *target_rc);
90 /* coverity[+kill] */
91 void crm_abort(const char *file, const char *function, int line,
92  const char *condition, gboolean do_core, gboolean do_fork);
93 
94 static inline gboolean
95 is_not_set(long long word, long long bit)
96 {
97  return ((word & bit) == 0);
98 }
99 
100 static inline gboolean
101 is_set(long long word, long long bit)
102 {
103  return ((word & bit) == bit);
104 }
105 
106 static inline gboolean
107 is_set_any(long long word, long long bit)
108 {
109  return ((word & bit) != 0);
110 }
111 
112 static inline guint
113 crm_hash_table_size(GHashTable * hashtable)
114 {
115  if (hashtable == NULL) {
116  return 0;
117  }
118  return g_hash_table_size(hashtable);
119 }
120 
121 char *crm_meta_name(const char *field);
122 const char *crm_meta_value(GHashTable * hash, const char *field);
123 
125 gboolean did_rsc_op_fail(lrmd_event_data_t * event, int target_rc);
126 
127 char *crm_md5sum(const char *buffer);
128 
129 char *crm_generate_uuid(void);
130 
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: strings.c:150
char * crm_generate_uuid(void)
Definition: utils.c:2078
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:1716
int char2score(const char *score)
Definition: utils.c:225
long long crm_get_msec(const char *input)
Definition: utils.c:578
char * score2char_stack(int score, char *buf, size_t len)
Definition: utils.c:263
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition: utils.c:1249
int crm_parse_int(const char *text, const char *default_text)
Definition: strings.c:125
Local Resource Manager.
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
Definition: utils.c:413
char * crm_meta_name(const char *field)
Definition: utils.c:1227
gboolean decode_transition_key(const char *key, char **uuid, int *action, int *transition_id, int *target_rc)
Definition: utils.c:821
op_status
Definition: services.h:120
bool pcmk_acl_required(const char *user)
Definition: utils.c:1924
unsigned long long crm_get_interval(const char *input)
Definition: utils.c:553
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
Definition: strings.c:213
char * crm_itoa_stack(int an_int, char *buf, size_t len)
Definition: strings.c:50
int crm_str_to_boolean(const char *s, int *ret)
Definition: strings.c:176
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, int *interval)
Definition: utils.c:650
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
Definition: utils.c:1731
int compare_version(const char *version1, const char *version2)
Definition: utils.c:466
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:778
int crm_exit(int rc)
Definition: utils.c:87
char * crm_md5sum(const char *buffer)
Definition: utils.c:2091
gboolean crm_is_true(const char *s)
Definition: strings.c:165
char * crm_strip_trailing_newline(char *str)
Definition: strings.c:197
char * crm_itoa(int an_int)
Definition: strings.c:60
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
Definition: utils.c:956
char * score2char(int score)
Definition: utils.c:277