26 #include <sys/param.h>
27 #include <sys/types.h>
30 #include <sys/utsname.h>
43 #include <qb/qbdefs.h>
56 #include <libxml2/libxml/relaxng.h>
67 # define PW_BUFFER_LEN 500
81 static struct crm_option *crm_long_options = NULL;
82 static const char *crm_app_description = NULL;
83 static char *crm_short_options = NULL;
84 static const char *crm_app_usage = NULL;
99 free(crm_short_options);
191 if(stat(value, &st) != 0) {
192 crm_err(
"Script %s does not exist", value);
196 if(S_ISREG(st.st_mode) == 0) {
197 crm_err(
"Script %s is not a regular file", value);
201 if( (st.st_mode & (S_IXUSR | S_IXGRP )) == 0) {
202 crm_err(
"Script %s is not executable", value);
213 long number = strtol(value, &end, 10);
215 if(end && end[0] !=
'%') {
217 }
else if(number < 0) {
290 const char *name,
const char *old_name,
const char *def_value)
292 const char *value = NULL;
296 if (options != NULL) {
297 value = g_hash_table_lookup(options, name);
300 if (value == NULL && old_name && options != NULL) {
301 value = g_hash_table_lookup(options, old_name);
304 " cluster option '%s'", old_name, name);
305 g_hash_table_insert(options, strdup(name), strdup(value));
306 value = g_hash_table_lookup(options, old_name);
311 crm_trace(
"Using default value '%s' for cluster option '%s'", def_value, name);
313 if (options == NULL) {
316 }
else if(def_value == NULL) {
320 g_hash_table_insert(options, strdup(name), strdup(def_value));
321 value = g_hash_table_lookup(options, name);
324 if (validate && validate(value) == FALSE) {
326 " Defaulting to %s", value, name, def_value);
327 g_hash_table_replace(options, strdup(name), strdup(def_value));
328 value = g_hash_table_lookup(options, name);
338 const char *value = NULL;
339 gboolean found = FALSE;
341 for (lpc = 0; lpc < len; lpc++) {
345 option_list[lpc].is_valid,
346 option_list[lpc].name,
347 option_list[lpc].alt_name, option_list[lpc].default_value);
360 fprintf(stdout,
"<?xml version=\"1.0\"?>"
361 "<!DOCTYPE resource-agent SYSTEM \"ra-api-1.dtd\">\n"
362 "<resource-agent name=\"%s\">\n"
363 " <version>%s</version>\n"
364 " <longdesc lang=\"en\">%s</longdesc>\n"
365 " <shortdesc lang=\"en\">%s</shortdesc>\n"
366 " <parameters>\n", name, version, desc_long, desc_short);
368 for (lpc = 0; lpc < len; lpc++) {
369 if (option_list[lpc].description_long == NULL && option_list[lpc].description_short == NULL) {
372 fprintf(stdout,
" <parameter name=\"%s\" unique=\"0\">\n"
373 " <shortdesc lang=\"en\">%s</shortdesc>\n"
374 " <content type=\"%s\" default=\"%s\"/>\n"
375 " <longdesc lang=\"en\">%s%s%s</longdesc>\n"
377 option_list[lpc].name,
378 option_list[lpc].description_short,
379 option_list[lpc].
type,
380 option_list[lpc].default_value,
381 option_list[lpc].description_long ? option_list[lpc].
382 description_long : option_list[lpc].description_short,
383 option_list[lpc].values ?
" Allowed values: " :
"",
384 option_list[lpc].values ? option_list[lpc].values :
"");
386 fprintf(stdout,
" </parameters>\n</resource-agent>\n");
394 for (lpc = 0; lpc < len; lpc++) {
396 option_list[lpc].is_valid,
397 option_list[lpc].name,
398 option_list[lpc].alt_name, option_list[lpc].default_value);
403 crm_concat(
const char *prefix,
const char *suffix,
char join)
406 char *new_str = NULL;
410 len = strlen(prefix) + strlen(suffix) + 2;
412 new_str = malloc(len);
414 sprintf(new_str,
"%s%c%s", prefix, join, suffix);
415 new_str[len - 1] = 0;
423 char *hash_key =
crm_concat(sys ? sys :
"none", crm_msg_reference,
'_');
425 crm_trace(
"created hash key: (%s)", hash_key);
433 if (buffer != NULL) {
434 snprintf(buffer, len,
"%d", an_int);
446 buffer = malloc(len + 1);
447 if (buffer != NULL) {
448 snprintf(buffer, len,
"%d", an_int);
460 struct passwd *pwentry = NULL;
467 *uid = pwentry->pw_uid;
470 *gid = pwentry->pw_gid;
472 crm_trace(
"Cluster user %s has uid=%d gid=%d", name, pwentry->pw_uid, pwentry->pw_gid);
475 crm_err(
"Cluster user %s does not exist", name);
483 crm_version_helper(
const char *text,
char **end_text)
485 int atoi_result = -1;
491 if (text != NULL && text[0] != 0) {
492 atoi_result = (int)strtol(text, end_text, 10);
494 if (errno == EINVAL) {
495 crm_err(
"Conversion of '%s' %c failed", text, text[0]);
512 char *ver1_copy = NULL, *ver2_copy = NULL;
513 char *rest1 = NULL, *rest2 = NULL;
515 if (version1 == NULL && version2 == NULL) {
517 }
else if (version1 == NULL) {
519 }
else if (version2 == NULL) {
523 ver1_copy = strdup(version1);
524 ver2_copy = strdup(version2);
534 if (rest1 == rest2) {
539 digit1 = crm_version_helper(rest1, &rest1);
543 digit2 = crm_version_helper(rest2, &rest2);
546 if (digit1 < digit2) {
550 }
else if (digit1 > digit2) {
555 if (rest1 != NULL && rest1[0] ==
'.') {
558 if (rest1 != NULL && rest1[0] == 0) {
562 if (rest2 != NULL && rest2[0] ==
'.') {
565 if (rest2 != NULL && rest2[0] == 0) {
574 crm_trace(
"%s == %s (%d)", version1, version2, lpc);
576 crm_trace(
"%s < %s (%d)", version1, version2, lpc);
578 crm_trace(
"%s > %s (%d)", version1, version2, lpc);
592 #include <sys/types.h>
599 long long result = -1;
600 char *local_end_text = NULL;
607 if (end_text != NULL) {
608 result = strtol(text, end_text, 10);
610 result = strtol(text, &local_end_text, 10);
613 if (end_text != NULL) {
614 result = strtoll(text, end_text, 10);
616 result = strtoll(text, &local_end_text, 10);
622 if (errno == EINVAL) {
623 crm_err(
"Conversion of %s failed", text);
626 }
else if (errno == ERANGE) {
627 crm_err(
"Conversion of %s was clipped: %lld", text, result);
629 }
else if (errno != 0) {
630 crm_perror(LOG_ERR,
"Conversion of %s failed:", text);
633 if (local_end_text != NULL && local_end_text[0] !=
'\0') {
634 crm_err(
"Characters left over after parsing '%s': '%s'", text, local_end_text);
645 int atoi_result = -1;
654 if (default_text != NULL) {
661 crm_err(
"No default conversion value supplied");
673 }
else if (a == NULL || b == NULL) {
676 }
else if (strcasecmp(a, b) == 0) {
685 gboolean ret = FALSE;
699 }
else if (strcasecmp(s,
"true") == 0
700 || strcasecmp(s,
"on") == 0
701 || strcasecmp(s,
"yes") == 0 || strcasecmp(s,
"y") == 0 || strcasecmp(s,
"1") == 0) {
705 }
else if (strcasecmp(s,
"false") == 0
706 || strcasecmp(s,
"off") == 0
707 || strcasecmp(s,
"no") == 0 || strcasecmp(s,
"n") == 0 || strcasecmp(s,
"0") == 0) {
715 # define NUMCHARS "0123456789."
719 # define WHITESPACE " \t\n\r\f"
725 unsigned long long msec = 0;
730 }
else if (input[0] !=
'P') {
750 const char *cp = input;
752 long long multiplier = 1000;
753 long long divisor = 1;
755 char *end_text = NULL;
767 if (strchr(
NUMCHARS, *cp) == NULL) {
771 if (strncasecmp(units,
"ms", 2) == 0 || strncasecmp(units,
"msec", 4) == 0) {
774 }
else if (strncasecmp(units,
"us", 2) == 0 || strncasecmp(units,
"usec", 4) == 0) {
777 }
else if (strncasecmp(units,
"s", 1) == 0 || strncasecmp(units,
"sec", 3) == 0) {
780 }
else if (strncasecmp(units,
"m", 1) == 0 || strncasecmp(units,
"min", 3) == 0) {
781 multiplier = 60 * 1000;
783 }
else if (strncasecmp(units,
"h", 1) == 0 || strncasecmp(units,
"hr", 2) == 0) {
784 multiplier = 60 * 60 * 1000;
786 }
else if (*units !=
EOS && *units !=
'\n' && *units !=
'\r') {
791 if (msec > LLONG_MAX/multiplier) {
811 len += strlen(op_type);
812 len += strlen(rsc_id);
815 sprintf(op_id,
"%s_%s_%d", rsc_id, op_type, interval);
820 parse_op_key(
const char *key,
char **rsc_id,
char **op_type,
int *interval)
823 char *mutable_key = NULL;
824 char *mutable_key_ptr = NULL;
825 int len = 0, offset = 0, ch = 0;
835 while (offset > 0 && isdigit(key[offset])) {
836 int digits = len - offset;
838 ch = key[offset] -
'0';
850 CRM_CHECK(key[offset] ==
'_',
return FALSE);
852 mutable_key = strdup(key);
853 mutable_key[offset] = 0;
856 while (offset > 0 && key[offset] !=
'_') {
860 CRM_CHECK(key[offset] ==
'_', free(mutable_key);
863 mutable_key_ptr = mutable_key + offset + 1;
865 crm_trace(
" Action: %s", mutable_key_ptr);
867 *op_type = strdup(mutable_key_ptr);
869 mutable_key[offset] = 0;
872 CRM_CHECK(mutable_key != mutable_key_ptr, free(mutable_key);
875 notify = strstr(mutable_key,
"_post_notify");
876 if (notify &&
safe_str_eq(notify,
"_post_notify")) {
880 notify = strstr(mutable_key,
"_pre_notify");
881 if (notify &&
safe_str_eq(notify,
"_pre_notify")) {
886 *rsc_id = mutable_key;
899 CRM_CHECK(notify_type != NULL,
return NULL);
901 len += strlen(op_type);
902 len += strlen(rsc_id);
903 len += strlen(notify_type);
908 sprintf(op_id,
"%s_%s_notify_%s_0", rsc_id, notify_type, op_type);
917 char *fail_state = NULL;
919 CRM_CHECK(transition_key != NULL,
return NULL);
921 len += strlen(transition_key);
923 fail_state = malloc(len);
924 if (fail_state != NULL) {
925 snprintf(fail_state, len,
"%d:%s", op_status, transition_key);
934 char *fail_state = NULL;
936 CRM_CHECK(transition_key != NULL,
return NULL);
938 len += strlen(transition_key);
940 fail_state = malloc(len);
941 if (fail_state != NULL) {
942 snprintf(fail_state, len,
"%d:%d;%s", op_status, op_rc, transition_key);
949 int *
op_status,
int *op_rc,
int *target_rc)
953 gboolean result = TRUE;
957 CRM_CHECK(op_status != NULL,
return FALSE);
959 key = calloc(1, strlen(magic) + 1);
960 res = sscanf(magic,
"%d:%d;%s", op_status, op_rc, key);
962 crm_warn(
"Only found %d items in: '%s'", res, magic);
977 char *fail_state = NULL;
983 fail_state = malloc(len);
984 if (fail_state != NULL) {
985 snprintf(fail_state, len,
"%d:%d:%d:%-*s", action_id, transition_id, target_rc, 36, node);
995 gboolean done = FALSE;
998 CRM_CHECK(target_rc != NULL,
return FALSE);
999 CRM_CHECK(action_id != NULL,
return FALSE);
1000 CRM_CHECK(transition_id != NULL,
return FALSE);
1002 *uuid = calloc(1, 37);
1003 res = sscanf(key,
"%d:%d:%d:%36s", action_id, transition_id, target_rc, *uuid);
1016 res = sscanf(key,
"%d:%d:%36s", action_id, transition_id, *uuid);
1019 res = sscanf(key,
"%d:%36s", transition_id, *uuid);
1022 }
else if (res != 3) {
1032 res = sscanf(key,
"%d:%36s", transition_id, *uuid);
1036 crm_crit(
"Unhandled sscanf result (%d) for %s", res, key);
1039 if (strlen(*uuid) != 36) {
1040 crm_warn(
"Bad UUID (%s) in sscanf result (%d) for %s", *uuid, res, key);
1043 if (done == FALSE) {
1044 crm_err(
"Cannot decode '%s' rc=%d", key, res);
1050 *transition_id = -1;
1060 char *timeout = NULL;
1061 char *interval = NULL;
1063 const char *attr_filter[] = {
1069 gboolean do_delete = FALSE;
1071 static int meta_len = 0;
1073 if (meta_len == 0) {
1077 if (param_set == NULL) {
1081 for (lpc = 0; lpc <
DIMOF(attr_filter); lpc++) {
1093 xmlAttrPtr xIter = param_set->properties;
1096 const char *prop_name = (
const char *)xIter->name;
1098 xIter = xIter->next;
1100 if (strncasecmp(prop_name,
CRM_META, meta_len) == 0) {
1112 if (timeout != NULL) {
1127 const char *assert_condition, gboolean do_core, gboolean do_fork)
1136 if(crm_is_daemon == FALSE) {
1144 if (do_core == FALSE) {
1145 crm_err(
"%s: Triggered assert at %s:%d : %s",
function, file, line, assert_condition);
1148 }
else if (do_fork) {
1152 crm_err(
"%s: Triggered fatal assert at %s:%d : %s",
function, file, line, assert_condition);
1156 crm_crit(
"%s: Cannot create core for non-fatal assert at %s:%d : %s",
1157 function, file, line, assert_condition);
1160 }
else if(pid == 0) {
1167 crm_err(
"%s: Forked child %d to record non-fatal assert at %s:%d : %s",
1168 function, pid, file, line, assert_condition);
1172 rc = waitpid(pid, &status, 0);
1177 }
while(errno == EINTR);
1179 if (errno == ECHILD) {
1181 crm_trace(
"Cannot wait on forked child %d - SIGCHLD is probably set to SIG_IGN", pid);
1184 crm_perror(LOG_ERR,
"Cannot wait on forked child %d", pid);
1190 static int have_proc_pid = 0;
1192 if(have_proc_pid == 0) {
1193 char proc_path[PATH_MAX], exe_path[PATH_MAX];
1196 snprintf(proc_path,
sizeof(proc_path),
"/proc/%lu/exe", (
long unsigned int)getpid());
1199 if(readlink(proc_path, exe_path, PATH_MAX - 1) < 0) {
1207 }
else if (kill(pid, 0) < 0 && errno == ESRCH) {
1210 }
else if(daemon == NULL || have_proc_pid == -1) {
1215 char proc_path[PATH_MAX], exe_path[PATH_MAX], myexe_path[PATH_MAX];
1218 snprintf(proc_path,
sizeof(proc_path),
"/proc/%lu/exe", pid);
1220 rc = readlink(proc_path, exe_path, PATH_MAX - 1);
1222 crm_perror(LOG_ERR,
"Could not read from %s", proc_path);
1228 if(daemon[0] !=
'/') {
1229 rc = snprintf(myexe_path,
sizeof(proc_path),
CRM_DAEMON_DIR"/%s", daemon);
1232 rc = snprintf(myexe_path,
sizeof(proc_path),
"%s", daemon);
1236 if (strcmp(exe_path, myexe_path) == 0) {
1244 #define LOCKSTRLEN 11
1253 if ((fd = open(filename, O_RDONLY)) < 0) {
1257 if (read(fd, buf,
sizeof(buf)) < 1) {
1261 if (sscanf(buf,
"%lu", &pid) > 0) {
1280 int rc = -ENOENT, fd = 0;
1282 if ((fd = open(filename, O_RDONLY)) >= 0) {
1283 if (fstat(fd, &sbuf) >= 0 && sbuf.st_size <
LOCKSTRLEN) {
1288 if (read(fd, buf,
sizeof(buf)) > 0) {
1289 if (sscanf(buf,
"%lu", &pid) > 0) {
1290 crm_trace(
"Got pid %lu from %s\n", pid, filename);
1296 }
else if (mypid && pid == mypid) {
1305 }
else if (mypid && pid != mypid) {
1317 crm_lock_pidfile(
const char *filename,
const char *name)
1323 mypid = (
unsigned long)getpid();
1326 if (rc == -ENOENT) {
1334 if ((fd = open(filename, O_CREAT | O_WRONLY | O_EXCL, 0644)) < 0) {
1339 snprintf(buf,
sizeof(buf),
"%*lu\n",
LOCKSTRLEN - 1, mypid);
1344 crm_perror(LOG_ERR,
"Incomplete write to %s", filename);
1356 const char *devnull =
"/dev/null";
1358 if (daemonize == FALSE) {
1364 if(rc <
pcmk_ok && rc != -ENOENT) {
1366 crm_err(
"%s: already running [pid %ld in %s]", name, pid, pidfile);
1367 printf(
"%s: already running [pid %ld in %s]\n", name, pid, pidfile);
1373 fprintf(stderr,
"%s: could not start daemon\n", name);
1377 }
else if (pid > 0) {
1381 rc = crm_lock_pidfile(pidfile, name);
1384 printf(
"Could not lock '%s' for %s: %s (%d)\n", pidfile, name,
pcmk_strerror(rc), rc);
1388 umask(S_IWGRP | S_IWOTH | S_IROTH);
1390 close(STDIN_FILENO);
1391 (void)open(devnull, O_RDONLY);
1392 close(STDOUT_FILENO);
1393 (void)open(devnull, O_WRONLY);
1394 close(STDERR_FILENO);
1395 (void)open(devnull, O_WRONLY);
1407 for (len = strlen(str) - 1; len >= 0 && str[len] ==
'\n'; len--) {
1418 return g_strcmp0(a, b) == 0;
1421 }
else if (a == b) {
1424 }
else if (a == NULL || b == NULL) {
1428 }
else if (strcasecmp(a, b) == 0) {
1439 char *crm_name = NULL;
1445 max = strlen(crm_name);
1446 for (; lpc < max; lpc++) {
1447 switch (crm_name[lpc]) {
1449 crm_name[lpc] =
'_';
1460 const char *value = NULL;
1464 value = g_hash_table_lookup(hash, key);
1471 static struct option *
1472 crm_create_long_opts(
struct crm_option *long_options)
1474 struct option *long_opts = NULL;
1476 #ifdef HAVE_GETOPT_H
1477 int index = 0, lpc = 0;
1486 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1487 long_opts[index].name =
"__dummmy__";
1488 long_opts[index].has_arg = 0;
1489 long_opts[index].flag = 0;
1490 long_opts[index].val =
'_';
1493 for (lpc = 0; long_options[lpc].
name != NULL; lpc++) {
1494 if (long_options[lpc].name[0] ==
'-') {
1498 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1501 long_opts[index].name = long_options[lpc].
name;
1502 long_opts[index].has_arg = long_options[lpc].
has_arg;
1503 long_opts[index].flag = long_options[lpc].
flag;
1504 long_opts[index].val = long_options[lpc].
val;
1509 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1510 long_opts[index].name = NULL;
1511 long_opts[index].has_arg = 0;
1512 long_opts[index].flag = 0;
1513 long_opts[index].val = 0;
1521 const char *app_desc)
1523 if (short_options) {
1524 crm_short_options = strdup(short_options);
1526 }
else if (long_options) {
1528 int opt_string_len = 0;
1529 char *local_short_options = NULL;
1531 for (lpc = 0; long_options[lpc].
name != NULL; lpc++) {
1532 if (long_options[lpc].val && long_options[lpc].val !=
'-' && long_options[lpc].val < UCHAR_MAX) {
1533 local_short_options = realloc_safe(local_short_options, opt_string_len + 4);
1534 local_short_options[opt_string_len++] = long_options[lpc].
val;
1536 if (long_options[lpc].has_arg == optional_argument) {
1537 local_short_options[opt_string_len++] =
':';
1539 if (long_options[lpc].has_arg >= required_argument) {
1540 local_short_options[opt_string_len++] =
':';
1542 local_short_options[opt_string_len] = 0;
1545 crm_short_options = local_short_options;
1546 crm_trace(
"Generated short option string: '%s'", local_short_options);
1550 crm_long_options = long_options;
1553 crm_app_description = app_desc;
1556 crm_app_usage = app_usage;
1569 #ifdef HAVE_GETOPT_H
1570 static struct option *long_opts = NULL;
1572 if (long_opts == NULL && crm_long_options) {
1573 long_opts = crm_create_long_opts(crm_long_options);
1578 int flag = getopt_long(argc, argv, crm_short_options, long_opts, index);
1582 if (long_opts[*index].val) {
1583 return long_opts[*index].val;
1584 }
else if (longname) {
1585 *longname = long_opts[*index].name;
1587 crm_notice(
"Unhandled option --%s", long_opts[*index].name);
1604 if (crm_short_options) {
1605 return getopt(argc, argv, crm_short_options);
1615 FILE *stream = (exit_code ? stderr : stdout);
1617 if (cmd ==
'v' || cmd ==
'$') {
1619 fprintf(stream,
"Written by Andrew Beekhof\n");
1630 if (crm_app_usage) {
1634 if (crm_long_options) {
1635 fprintf(stream,
"Options:\n");
1636 for (i = 0; crm_long_options[i].
name != NULL; i++) {
1640 fprintf(stream,
"%s\n\n", crm_long_options[i].desc);
1643 fprintf(stream,
"\t#%s\n\n", crm_long_options[i].desc);
1645 }
else if (crm_long_options[i].val ==
'-' && crm_long_options[i].desc) {
1646 fprintf(stream,
"%s\n", crm_long_options[i].desc);
1650 if (crm_long_options[i].val && crm_long_options[i].val <= UCHAR_MAX) {
1651 fprintf(stream,
" -%c,", crm_long_options[i].val);
1655 fprintf(stream,
" --%s%s\t%s\n", crm_long_options[i].name,
1656 crm_long_options[i].has_arg == optional_argument ?
"[=value]" :
1657 crm_long_options[i].has_arg == required_argument ?
"=value" :
"",
1658 crm_long_options[i].desc ? crm_long_options[i].desc :
"");
1662 }
else if (crm_short_options) {
1663 fprintf(stream,
"Usage: %s - %s\n",
crm_system_name, crm_app_description);
1664 for (i = 0; crm_short_options[i] != 0; i++) {
1665 int has_arg = no_argument ;
1667 if (crm_short_options[i + 1] ==
':') {
1668 if (crm_short_options[i + 2] ==
':')
1669 has_arg = optional_argument ;
1671 has_arg = required_argument ;
1674 fprintf(stream,
" -%c %s\n", crm_short_options[i],
1675 has_arg == optional_argument ?
"[value]" :
1676 has_arg == required_argument ?
"{value}" :
"");
1688 qb_ipcs_service_t **ipcs_rw,
1689 qb_ipcs_service_t **ipcs_shm,
1690 struct qb_ipcs_service_handlers *ro_cb,
1691 struct qb_ipcs_service_handlers *rw_cb)
1697 if (*ipcs_ro == NULL || *ipcs_rw == NULL || *ipcs_shm == NULL) {
1698 crm_err(
"Failed to create cib servers: exiting and inhibiting respawn.");
1699 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1705 qb_ipcs_service_t *ipcs_rw,
1706 qb_ipcs_service_t *ipcs_shm)
1708 qb_ipcs_destroy(ipcs_ro);
1709 qb_ipcs_destroy(ipcs_rw);
1710 qb_ipcs_destroy(ipcs_shm);
1724 if (*ipcs == NULL) {
1725 crm_err(
"Failed to create attrd servers: exiting and inhibiting respawn.");
1726 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1736 if (*ipcs == NULL) {
1737 crm_err(
"Failed to create stonith-ng servers: exiting and inhibiting respawn.");
1738 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1745 const char *value,
const char *section,
const char *set,
const char *dampen,
1746 const char *user_name,
int options)
1752 static gboolean connected = TRUE;
1756 if (ipc == NULL && local_ipc == NULL) {
1777 if (name == NULL && command ==
'U') {
1818 if (connected == FALSE) {
1819 crm_info(
"Connecting to cluster... %d retries remaining", max);
1826 crm_perror(LOG_INFO,
"Connection to cluster attribute manager failed");
1829 if (ipc != local_ipc) {
1832 }
else if (rc > 0) {
1835 }
else if (rc == -EAGAIN || rc == -EALREADY) {
1849 crm_debug(
"Sent update: %s=%s for %s", name, value, host ? host :
"localhost");
1853 crm_debug(
"Could not send update %s=%s for %s: %s (%d)", name, value,
1859 #define FAKE_TE_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1868 char *digest = NULL;
1869 xmlNode *args_xml = NULL;
1871 if (op->
params == NULL) {
1885 do_crm_log(level,
"Calculated digest %s for %s (%s). Source: %s\n",
1886 digest,
ID(update), magic, digest_source);
1887 free(digest_source);
1927 if (target_rc != op->
rc) {
1937 int target_rc,
const char * node,
const char * origin,
int level)
1942 char *op_id_additional = NULL;
1943 char *local_user_data = NULL;
1944 const char *exit_reason = NULL;
1946 xmlNode *xml_op = NULL;
1947 const char *task = NULL;
1948 gboolean dc_munges_migrate_ops = (
compare_version(caller_version,
"3.0.3") < 0);
1949 gboolean dc_needs_unique_ops = (
compare_version(caller_version,
"3.0.6") < 0);
1952 do_crm_log(level,
"%s: Updating resource %s after %s op %s (interval=%d)",
1956 crm_trace(
"DC version: %s", caller_version);
1977 }
else if (dc_munges_migrate_ops
1984 if (dc_needs_unique_ops && op->
interval > 0) {
1985 op_id = strdup(key);
2008 op_id = strdup(key);
2016 if (xml_op == NULL) {
2021 crm_debug(
"Generating fake transition key for:"
2022 " %s_%s_%d %d from %s",
2049 crm_trace(
"Timing data (%s_%s_%d): last=%lu change=%lu exec=%lu queue=%lu",
2085 append_digest(op, xml_op, caller_version, magic, LOG_DEBUG);
2087 if (op_id_additional) {
2089 op_id = op_id_additional;
2090 op_id_additional = NULL;
2094 if (local_user_data) {
2095 free(local_user_data);
2108 if(user == NULL || strlen(user) == 0) {
2115 }
else if (strcmp(user,
"root") == 0) {
2118 crm_trace(
"acls required for %s", user);
2130 struct passwd *pwent = getpwuid(uid);
2132 if (pwent == NULL) {
2133 crm_perror(LOG_ERR,
"Cannot get password entry of uid: %d", uid);
2137 return strdup(pwent->pw_name);
2145 static const char *effective_user = NULL;
2146 const char *requested_user = NULL;
2147 const char *user = NULL;
2149 if(effective_user == NULL) {
2154 if(requested_user == NULL) {
2158 if (is_privileged(effective_user) == FALSE) {
2160 user = effective_user;
2162 }
else if(peer_user == NULL && requested_user == NULL) {
2164 user = effective_user;
2166 }
else if(peer_user == NULL) {
2168 user = requested_user;
2170 }
else if (is_privileged(peer_user) == FALSE) {
2174 }
else if (requested_user == NULL) {
2180 user = requested_user;
2192 return requested_user;
2199 CRM_CHECK(user != NULL && request != NULL && field != NULL,
return);
2202 if (is_privileged(user) == FALSE) {
2233 const signed char *p;
2236 for (p = v; *p !=
'\0'; p++)
2237 h = (h << 5) - h + *p;
2245 const signed char *p;
2248 for (p = v; *p !=
'\0'; p++)
2249 h = (h << 5) - h + g_ascii_tolower(*p);
2260 if (*handle == NULL) {
2261 *handle = dlopen(lib, RTLD_LAZY);
2265 crm_err(
"%sCould not open %s: %s", fatal ?
"Fatal: " :
"", lib, dlerror());
2272 a_function = dlsym(*handle, fn);
2273 if ((error = dlerror()) != NULL) {
2274 crm_err(
"%sCould not find %s in %s: %s", fatal ?
"Fatal: " :
"", fn, lib, error);
2289 if (value == NULL) {
2293 last = strlen(list);
2296 len += strlen(value);
2297 list = realloc_safe(list, len);
2298 sprintf(list + last,
" %s", value);
2309 #ifdef HAVE_UUID_UUID_H
2310 # include <uuid/uuid.h>
2316 unsigned char uuid[16];
2317 char *buffer = malloc(37);
2319 uuid_generate(uuid);
2320 uuid_unparse(uuid, buffer);
2329 int lpc = 0, len = 0;
2330 char *digest = NULL;
2333 if (buffer == NULL) {
2336 len = strlen(buffer);
2338 crm_trace(
"Beginning digest of %d bytes", len);
2343 sprintf(digest + (2 * lpc),
"%02x", raw_digest[lpc]);
2349 crm_err(
"Could not create digest");
2361 char *compressed = NULL;
2362 char *uncompressed = strdup(data);
2363 struct timespec after_t;
2364 struct timespec before_t;
2367 max = (length * 1.1) + 600;
2370 #ifdef CLOCK_MONOTONIC
2371 clock_gettime(CLOCK_MONOTONIC, &before_t);
2375 compressed = malloc(max);
2378 rc = BZ2_bzBuffToBuffCompress(compressed, result_len, uncompressed, length,
CRM_BZ2_BLOCKS, 0,
2389 #ifdef CLOCK_MONOTONIC
2390 clock_gettime(CLOCK_MONOTONIC, &after_t);
2392 crm_info(
"Compressed %d bytes into %d (ratio %d:1) in %dms",
2393 length, *result_len, length / (*result_len),
2394 (after_t.tv_sec - before_t.tv_sec) * 1000 + (after_t.tv_nsec -
2395 before_t.tv_nsec) / 1000000);
2397 crm_info(
"Compressed %d bytes into %d (ratio %d:1)",
2398 length, *result_len, length / (*result_len));
2401 *result = compressed;
2405 #ifdef HAVE_GNUTLS_GNUTLS_H
2407 crm_gnutls_global_init(
void)
2409 signal(SIGPIPE, SIG_IGN);
2410 gnutls_global_init();
#define CRM_CHECK(expr, failure_action)
#define XML_RSC_OP_LAST_CHANGE
void * find_library_function(void **handle, const char *lib, const char *fn, gboolean fatal)
void verify_all_options(GHashTable *options, pe_cluster_option *option_list, int len)
gboolean parse_op_key(const char *key, char **rsc_id, char **op_type, int *interval)
void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite)
bool crm_ipc_connect(crm_ipc_t *client)
Establish an IPC connection to a Pacemaker component.
long long crm_get_msec(const char *input)
int crm_get_option_long(int argc, char **argv, int *index, const char **longname)
#define crm_notice(fmt, args...)
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
#define CRMD_ACTION_MIGRATED
int attrd_update_delegate(crm_ipc_t *ipc, char command, const char *host, const char *name, const char *value, const char *section, const char *set, const char *dampen, const char *user_name, int options)
void crm_enable_stderr(int enable)
void * convert_const_pointer(const void *ptr)
bool crm_compress_string(const char *data, int length, int max, char **result, unsigned int *result_len)
#define crm_crit(fmt, args...)
gboolean check_utilization(const char *value)
const char * crm_meta_value(GHashTable *hash, const char *field)
#define XML_ATTR_TRANSITION_MAGIC
void cib_ipc_servers_destroy(qb_ipcs_service_t *ipcs_ro, qb_ipcs_service_t *ipcs_rw, qb_ipcs_service_t *ipcs_shm)
void attrd_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
char * crm_concat(const char *prefix, const char *suffix, char join)
struct crm_time_s crm_time_t
const char * pcmk_strerror(int rc)
gboolean check_time(const char *value)
#define crm_config_err(fmt...)
void crm_make_daemon(const char *name, gboolean daemonize, const char *pidfile)
void crm_xml_cleanup(void)
gboolean decode_transition_key(const char *key, char **uuid, int *transition_id, int *action_id, int *target_rc)
void g_hash_destroy_str(gpointer data)
#define CRMD_ACTION_NOTIFY
void cib_ipc_servers_init(qb_ipcs_service_t **ipcs_ro, qb_ipcs_service_t **ipcs_rw, qb_ipcs_service_t **ipcs_shm, struct qb_ipcs_service_handlers *ro_cb, struct qb_ipcs_service_handlers *rw_cb)
char * crm_md5sum(const char *buffer)
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
#define XML_RSC_OP_T_EXEC
char * generate_transition_key(int transition_id, int action_id, int target_rc, const char *node)
#define XML_LRM_ATTR_INTERVAL
gboolean safe_str_neq(const char *a, const char *b)
gboolean crm_config_warning
int crm_help(char cmd, int exit_code)
#define XML_LRM_ATTR_OP_DIGEST
void mainloop_cleanup(void)
char * crm_element_value_copy(xmlNode *data, const char *name)
crm_time_t * crm_time_parse_duration(const char *duration_str)
char * crm_itoa_stack(int an_int, char *buffer, size_t len)
#define CRM_LOG_ASSERT(expr)
void crm_set_options(const char *short_options, const char *app_usage, struct crm_option *long_options, const char *app_desc)
const char * get_cluster_pref(GHashTable *options, pe_cluster_option *option_list, int len, const char *name)
#define XML_RSC_OP_T_QUEUE
#define XML_CIB_TAG_NODES
#define PACEMAKER_VERSION
#define attrd_opt_private
int crm_pidfile_inuse(const char *filename, long mypid, const char *daemon)
Wrappers for and extensions to glib mainloop.
void config_metadata(const char *name, const char *version, const char *desc_short, const char *desc_long, pe_cluster_option *option_list, int len)
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
#define ATTRD_OP_PEER_REMOVE
bool pcmk_acl_required(const char *user)
guint g_str_hash_traditional(gconstpointer v)
void stonith_ipc_server_init(qb_ipcs_service_t **ipcs, struct qb_ipcs_service_handlers *cb)
#define CRMD_ACTION_START
xmlNode * create_operation_update(xmlNode *parent, lrmd_event_data_t *op, const char *caller_version, int target_rc, const char *node, const char *origin, int level)
char * crm_meta_name(const char *field)
gboolean check_quorum(const char *value)
#define XML_LRM_ATTR_TASK_KEY
#define XML_LRM_ATTR_TASK
void hash2field(gpointer key, gpointer value, gpointer user_data)
char * calculate_operation_digest(xmlNode *local_cib, const char *version)
Calculate and return digest of XML operation.
#define crm_warn(fmt, args...)
int crm_pid_active(long pid, const char *daemon)
int daemon(int nochdir, int noclose)
#define F_ATTRD_ATTRIBUTE
char * generate_hash_key(const char *crm_msg_reference, const char *sys)
#define crm_debug(fmt, args...)
void determine_request_user(const char *user, xmlNode *request, const char *field)
struct crm_ipc_s crm_ipc_t
#define F_ATTRD_IS_PRIVATE
char * score2char(int score)
#define pcmk_option_example
unsigned long long crm_get_interval(const char *input)
gboolean did_rsc_op_fail(lrmd_event_data_t *op, int target_rc)
#define crm_trace(fmt, args...)
#define do_crm_log(level, fmt, args...)
Log a message.
const char * cluster_option(GHashTable *options, gboolean(*validate)(const char *), const char *name, const char *old_name, const char *def_value)
#define pcmk_option_paragraph
Wrappers for and extensions to libxml2.
xmlNode * create_xml_node(xmlNode *parent, const char *name)
const char * crm_element_value(xmlNode *data, const char *name)
long long crm_int_helper(const char *text, char **end_text)
char * crm_itoa(int an_int)
gboolean crm_is_true(const char *s)
#define F_ATTRD_IS_REMOTE
#define XML_LRM_ATTR_MIGRATE_TARGET
char * crm_generate_uuid(void)
#define XML_LRM_ATTR_EXIT_REASON
void free_xml(xmlNode *child)
void filter_action_parameters(xmlNode *param_set, const char *version)
CRM_TRACE_INIT_DATA(common)
gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id, int *op_status, int *op_rc, int *target_rc)
long long int crm_time_get_seconds(crm_time_t *dt)
#define DAEMON_RESPAWN_STOP
int compare_version(const char *version1, const char *version2)
gboolean check_script(const char *value)
#define crm_config_warn(fmt...)
#define XML_ATTR_TRANSITION_KEY
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
unsigned int get_crm_log_level(void)
void crm_abort(const char *file, const char *function, int line, const char *assert_condition, gboolean do_core, gboolean do_fork)
char * generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
gboolean check_timer(const char *value)
#define crm_perror(level, fmt, args...)
Log a system error message.
char * generate_transition_magic_v202(const char *transition_key, int op_status)
int char2score(const char *score)
#define crm_err(fmt, args...)
int crm_parse_int(const char *text, const char *default_text)
int crm_ipc_send(crm_ipc_t *client, xmlNode *message, enum crm_ipc_flags flags, int32_t ms_timeout, xmlNode **reply)
const char * bz2_strerror(int rc)
gboolean check_number(const char *value)
void xml_remove_prop(xmlNode *obj, const char *name)
int rsc_op_expected_rc(lrmd_event_data_t *op)
crm_ipc_t * crm_ipc_new(const char *name, size_t max_size)
char * dump_xml_unformatted(xmlNode *msg)
#define XML_LRM_ATTR_CALLID
#define CRMD_ACTION_MIGRATE
#define XML_LRM_ATTR_OPSTATUS
#define XML_ATTR_CRM_VERSION
#define pcmk_option_hidden
int crm_get_option(int argc, char **argv, int *index)
char * generate_op_key(const char *rsc_id, const char *op_type, int interval)
void * md5_buffer(const char *buffer, size_t len, void *resblock)
Wrappers for and extensions to libqb IPC.
#define PACKAGE_BUGREPORT
int crm_read_pidfile(const char *filename)
#define XML_CIB_TAG_STATUS
char * generate_transition_magic(const char *transition_key, int op_status, int op_rc)
int crm_str_to_boolean(const char *s, int *ret)
const char * crm_acl_get_set_user(xmlNode *request, const char *field, const char *peer_user)
gboolean crm_config_error
#define XML_LRM_ATTR_TARGET
#define XML_LRM_TAG_RSC_OP
#define XML_RSC_OP_LAST_RUN
#define safe_str_eq(a, b)
qb_ipcs_service_t * mainloop_add_ipc_server(const char *name, enum qb_ipc_type type, struct qb_ipcs_service_handlers *callbacks)
#define XML_LRM_ATTR_MIGRATE_SOURCE
gboolean check_boolean(const char *value)
void crm_ipc_close(crm_ipc_t *client)
char * crm_strip_trailing_newline(char *str)
#define crm_info(fmt, args...)
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
char * uid2username(uid_t uid)
char * score2char_stack(int score, char *buf, size_t len)
qb_ipcs_service_t * crmd_ipc_server_init(struct qb_ipcs_service_handlers *cb)
enum crm_ais_msg_types type
char * add_list_element(char *list, const char *value)
guint crm_strcase_hash(gconstpointer v)
#define CRMD_ACTION_STATUS
void crm_time_free(crm_time_t *dt)