pacemaker  1.1.17-b36b869ca8
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 <stdbool.h>
30 # include <limits.h>
31 # include <signal.h>
32 # include <sysexits.h>
33 
34 # include <crm/lrmd.h>
35 
36 # if SUPPORT_HEARTBEAT
37 # include <heartbeat.h>
38 # else
39 # define NORMALNODE "normal"
40 # define ACTIVESTATUS "active"/* fully functional, and all links are up */
41 # define DEADSTATUS "dead"
42  /* Status of non-working link or machine */
43 # define PINGSTATUS "ping"
44  /* Status of a working ping node */
45 # define JOINSTATUS "join"
46  /* Status when an api client joins */
47 # define LEAVESTATUS "leave"
48  /* Status when an api client leaves */
49 # define ONLINESTATUS "online"/* Status of an online client */
50 # define OFFLINESTATUS "offline"
51  /* Status of an offline client */
52 # endif
53 
54 /* public string functions (from strings.c) */
55 char *crm_itoa_stack(int an_int, char *buf, size_t len);
56 char *crm_itoa(int an_int);
57 gboolean crm_is_true(const char *s);
58 int crm_str_to_boolean(const char *s, int *ret);
59 int crm_parse_int(const char *text, const char *default_text);
60 char * crm_strip_trailing_newline(char *str);
61 gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
62 gboolean safe_str_neq(const char *a, const char *b);
63 
64 # define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
65 
66 /* used with hash tables where case does not matter */
67 static inline gboolean
68 crm_strcase_equal(gconstpointer a, gconstpointer b)
69 {
70  return crm_str_eq((const char *) a, (const char *) b, FALSE);
71 }
72 
73 # define crm_atoi(text, default_text) crm_parse_int(text, default_text)
74 
75 /* public I/O functions (from io.c) */
76 void crm_build_path(const char *path_c, mode_t mode);
77 
78 long long crm_get_msec(const char *input);
79 unsigned long long crm_get_interval(const char *input);
80 int char2score(const char *score);
81 char *score2char(int score);
82 char *score2char_stack(int score, char *buf, size_t len);
83 
84 int compare_version(const char *version1, const char *version2);
85 
86 gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, int *interval);
87 gboolean decode_transition_key(const char *key, char **uuid, int *action, int *transition_id,
88  int *target_rc);
89 gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id,
90  int *op_status, int *op_rc, int *target_rc);
91 /* coverity[+kill] */
92 void crm_abort(const char *file, const char *function, int line,
93  const char *condition, gboolean do_core, gboolean do_fork);
94 
95 static inline gboolean
96 is_not_set(long long word, long long bit)
97 {
98  return ((word & bit) == 0);
99 }
100 
101 static inline gboolean
102 is_set(long long word, long long bit)
103 {
104  return ((word & bit) == bit);
105 }
106 
107 static inline gboolean
108 is_set_any(long long word, long long bit)
109 {
110  return ((word & bit) != 0);
111 }
112 
113 static inline guint
114 crm_hash_table_size(GHashTable * hashtable)
115 {
116  if (hashtable == NULL) {
117  return 0;
118  }
119  return g_hash_table_size(hashtable);
120 }
121 
122 char *crm_meta_name(const char *field);
123 const char *crm_meta_value(GHashTable * hash, const char *field);
124 
126 gboolean did_rsc_op_fail(lrmd_event_data_t * event, int target_rc);
127 
128 char *crm_md5sum(const char *buffer);
129 
130 char *crm_generate_uuid(void);
131 bool crm_is_daemon_name(const char *name);
132 
133 int crm_user_lookup(const char *name, uid_t * uid, gid_t * gid);
134 
135 #ifdef HAVE_GNUTLS_GNUTLS_H
136 void crm_gnutls_global_init(void);
137 #endif
138 
139 int crm_exit(int rc);
140 bool pcmk_acl_required(const char *user);
141 
142 #endif
bool crm_is_daemon_name(const char *name)
Check whether a string represents a cluster daemon name.
Definition: utils.c:1970
gboolean safe_str_neq(const char *a, const char *b)
Definition: strings.c:150
char * crm_generate_uuid(void)
Definition: utils.c:1952
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:1590
int char2score(const char *score)
Definition: utils.c:233
long long crm_get_msec(const char *input)
Definition: utils.c:586
char * score2char_stack(int score, char *buf, size_t len)
Definition: utils.c:271
const char * crm_meta_value(GHashTable *hash, const char *field)
Definition: utils.c:1263
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:421
char * crm_meta_name(const char *field)
Definition: utils.c:1241
gboolean decode_transition_key(const char *key, char **uuid, int *action, int *transition_id, int *target_rc)
Definition: utils.c:832
op_status
Definition: services.h:130
bool pcmk_acl_required(const char *user)
Definition: utils.c:1798
unsigned long long crm_get_interval(const char *input)
Definition: utils.c:561
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:661
gboolean did_rsc_op_fail(lrmd_event_data_t *event, int target_rc)
Definition: utils.c:1605
int compare_version(const char *version1, const char *version2)
Definition: utils.c:474
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:789
int crm_exit(int rc)
Definition: utils.c:86
char * crm_md5sum(const char *buffer)
Definition: utils.c:1986
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:970
char * score2char(int score)
Definition: utils.c:285