45#include <sys/socket.h>
76 char *buf,
size_t buf_size)
80 for (i = 0; servicenames[i].c_name != NULL; i++) {
81 if (service_id == servicenames[i].
c_val) {
82 return (servicenames[i].
c_name);
85 snprintf(buf, buf_size,
"%d", service_id);
95 return ((strncmp ((
char *)name1->
value, (
char *)name2->
value,
109 if (gettimeofday(&tv, 0)) {
113 time_now = (
cs_time_t)(tv.tv_sec) * 1000000000ULL;
114 time_now += (
cs_time_t)(tv.tv_usec) * 1000ULL;
134 "Corosync Cluster Engine exiting normally");
137 "with status %d at %s:%u.", err, file, line);
149 memset (ret_name, 0,
sizeof (ret_name));
153 return ((
char *)name->
value);
157 strncpy ((
char *)name->
value, str, sizeof (name->
value) - 1);
158 ((
char *)name->
value)[
sizeof (name->
value) - 1] =
'\0';
162 name->
length = strlen (str);
167 if (str1->
length == strlen (str2)) {
168 return ((strncmp ((
char *)str1->
value, (
char *)str2,
177 static char path[PATH_MAX] = {
'\0'};
181 if (path[0] ==
'\0') {
183 res = snprintf(path, PATH_MAX,
"%s", state_dir);
185 }
else if ((state_dir = getenv(
"STATE_DIRECTORY")) != NULL) {
195 res = snprintf(path, PATH_MAX,
"%s", state_dir);
197 res = snprintf(path, PATH_MAX,
"%s/%s",
LOCALSTATEDIR,
"lib/corosync");
200 assert(res < PATH_MAX);
206static int safe_strcat(
char *dst,
size_t dst_len,
const char *src)
209 if (strlen(dst) + strlen(src) >= dst_len - 1) {
226 const char **list_str,
int machine_parseable_str,
227 const char *error_string_prefix,
const char **error_string)
230 struct knet_crypto_info crypto_list[16];
232 static char local_error_str[512];
233 static char local_list_str[256];
236 if (list_str != NULL) {
237 *list_str = local_list_str;
240 memset(local_error_str, 0,
sizeof(local_error_str));
241 memset(local_list_str, 0,
sizeof(local_list_str));
243 safe_strcat(local_error_str,
sizeof(local_error_str), error_string_prefix);
245 if (knet_get_crypto_list(NULL, &entries) != 0) {
246 *error_string =
"internal error - cannot get knet crypto list";
250 if (entries >
sizeof(crypto_list) /
sizeof(crypto_list[0])) {
251 *error_string =
"internal error - too many knet crypto list entries";
255 if (knet_get_crypto_list(crypto_list, &entries) != 0) {
256 *error_string =
"internal error - cannot get knet crypto list";
260 for (zi = 0; zi < entries; zi++) {
262 }
else if (zi == entries - 1) {
263 if (machine_parseable_str) {
264 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" ");
266 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" or ");
269 if (machine_parseable_str) {
270 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" ");
272 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
", ");
276 (void)safe_strcat(local_list_str,
sizeof(local_list_str), crypto_list[zi].name);
278 if (val != NULL && strcmp(val, crypto_list[zi].name) == 0) {
284 (void)safe_strcat(local_error_str,
sizeof(local_error_str), local_list_str);
285 *error_string = local_error_str;
288 return (model_found);
292 const char **list_str,
int machine_parseable_str,
293 const char *error_string_prefix,
const char **error_string)
296 struct knet_compress_info compress_list[16];
298 static char local_error_str[512];
299 static char local_list_str[256];
302 if (list_str != NULL) {
303 *list_str = local_list_str;
306 memset(local_error_str, 0,
sizeof(local_error_str));
307 memset(local_list_str, 0,
sizeof(local_list_str));
309 safe_strcat(local_error_str,
sizeof(local_error_str), error_string_prefix);
311 if (knet_get_compress_list(NULL, &entries) != 0) {
312 *error_string =
"internal error - cannot get knet compress list";
316 if (entries >
sizeof(compress_list) /
sizeof(compress_list[0])) {
317 *error_string =
"internal error - too many knet compress list entries";
321 if (knet_get_compress_list(compress_list, &entries) != 0) {
322 *error_string =
"internal error - cannot get knet compress list";
326 for (zi = 0; zi < entries; zi++) {
328 }
else if (zi == entries - 1) {
329 if (machine_parseable_str) {
330 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" ");
332 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" or ");
335 if (machine_parseable_str) {
336 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
" ");
338 (void)safe_strcat(local_list_str,
sizeof(local_list_str),
", ");
342 (void)safe_strcat(local_list_str,
sizeof(local_list_str), compress_list[zi].name);
344 if (val != NULL && strcmp(val, compress_list[zi].name) == 0) {
350 (void)safe_strcat(local_error_str,
sizeof(local_error_str), local_list_str);
351 *error_string = local_error_str;
354 return (model_found);
365 tos = (dscp & 0x3f) << 2;
366 res = setsockopt(socket, IPPROTO_IP, IP_TOS, &tos,
sizeof(tos));
int64_t cs_time_t
cs_time_t
#define CS_MAX_NAME_LENGTH
cs_error_t icmap_get_string(const char *key_name, char **str)
Shortcut for icmap_get for string type.
#define LOGSYS_LEVEL_ERROR
#define log_printf(level, format, args...)
void logsys_system_fini(void)
logsys_system_fini
#define LOGSYS_LEVEL_NOTICE
#define LOGSYS_DECLARE_SUBSYS(subsys)
The LOGSYS_DECLARE_SUBSYS macro.
uint8_t value[CS_MAX_NAME_LENGTH]
int util_is_valid_knet_crypto_model(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
char * getcs_name_t(cs_name_t *name)
const char * get_state_dir(void)
cs_time_t clust_time_now(void)
Get the time of day and convert to nanoseconds.
const char * short_service_name_get(uint32_t service_id, char *buf, size_t buf_size)
Get the short name of a service from the service_id.
int util_is_valid_knet_compress_model(const char *val, const char **list_str, int machine_parseable_str, const char *error_string_prefix, const char **error_string)
int name_match(cs_name_t *name1, cs_name_t *name2)
Compare two names.
void setcs_name_t(cs_name_t *name, char *str)
int set_socket_dscp(int socket, unsigned char dscp)
void _corosync_out_of_memory_error(void)
void _corosync_exit_error(enum e_corosync_done err, const char *file, unsigned int line) __attribute__((noreturn))
int cs_name_tisEqual(cs_name_t *str1, char *str2)