17 #include <sys/param.h> 18 #include <sys/types.h> 21 #include <sys/utsname.h> 34 #include <qb/qbdefs.h> 47 #include <libxml2/libxml/relaxng.h> 58 # define PW_BUFFER_LEN 500 72 static struct crm_option *crm_long_options = NULL;
73 static const char *crm_app_description = NULL;
74 static char *crm_short_options = NULL;
75 static const char *crm_app_usage = NULL;
90 free(crm_short_options);
182 if(stat(value, &st) != 0) {
183 crm_err(
"Script %s does not exist", value);
187 if(S_ISREG(st.st_mode) == 0) {
188 crm_err(
"Script %s is not a regular file", value);
192 if( (st.st_mode & (S_IXUSR | S_IXGRP )) == 0) {
193 crm_err(
"Script %s is not executable", value);
204 long number = strtol(value, &end, 10);
206 if(end && end[0] !=
'%') {
208 }
else if(number < 0) {
281 const char *name,
const char *old_name,
const char *def_value)
283 const char *value = NULL;
287 if (options != NULL) {
288 value = g_hash_table_lookup(options, name);
291 if (value == NULL && old_name && options != NULL) {
292 value = g_hash_table_lookup(options, old_name);
295 " cluster option '%s'", old_name, name);
296 g_hash_table_insert(options, strdup(name), strdup(value));
297 value = g_hash_table_lookup(options, old_name);
302 crm_trace(
"Using default value '%s' for cluster option '%s'", def_value, name);
304 if (options == NULL) {
307 }
else if(def_value == NULL) {
311 g_hash_table_insert(options, strdup(name), strdup(def_value));
312 value = g_hash_table_lookup(options, name);
315 if (validate && validate(value) == FALSE) {
317 " Defaulting to %s", value, name, def_value);
318 g_hash_table_replace(options, strdup(name), strdup(def_value));
319 value = g_hash_table_lookup(options, name);
329 const char *value = NULL;
330 gboolean found = FALSE;
332 for (lpc = 0; lpc < len; lpc++) {
336 option_list[lpc].is_valid,
337 option_list[lpc].name,
338 option_list[lpc].alt_name, option_list[lpc].default_value);
351 fprintf(stdout,
"<?xml version=\"1.0\"?>" 352 "<!DOCTYPE resource-agent SYSTEM \"ra-api-1.dtd\">\n" 353 "<resource-agent name=\"%s\">\n" 354 " <version>%s</version>\n" 355 " <longdesc lang=\"en\">%s</longdesc>\n" 356 " <shortdesc lang=\"en\">%s</shortdesc>\n" 357 " <parameters>\n", name, version, desc_long, desc_short);
359 for (lpc = 0; lpc < len; lpc++) {
360 if (option_list[lpc].description_long == NULL && option_list[lpc].description_short == NULL) {
363 fprintf(stdout,
" <parameter name=\"%s\" unique=\"0\">\n" 364 " <shortdesc lang=\"en\">%s</shortdesc>\n" 365 " <content type=\"%s\" default=\"%s\"/>\n" 366 " <longdesc lang=\"en\">%s%s%s</longdesc>\n" 368 option_list[lpc].name,
369 option_list[lpc].description_short,
370 option_list[lpc].
type,
371 option_list[lpc].default_value,
372 option_list[lpc].description_long ? option_list[lpc].
373 description_long : option_list[lpc].description_short,
374 option_list[lpc].values ?
" Allowed values: " :
"",
375 option_list[lpc].values ? option_list[lpc].values :
"");
377 fprintf(stdout,
" </parameters>\n</resource-agent>\n");
385 for (lpc = 0; lpc < len; lpc++) {
387 option_list[lpc].is_valid,
388 option_list[lpc].name,
389 option_list[lpc].alt_name, option_list[lpc].default_value);
394 crm_concat(
const char *prefix,
const char *suffix,
char join)
397 char *new_str = NULL;
401 len = strlen(prefix) + strlen(suffix) + 2;
403 new_str = malloc(len);
405 sprintf(new_str,
"%s%c%s", prefix, join, suffix);
406 new_str[len - 1] = 0;
414 char *hash_key =
crm_concat(sys ? sys :
"none", crm_msg_reference,
'_');
416 crm_trace(
"created hash key: (%s)", hash_key);
424 if (buffer != NULL) {
425 snprintf(buffer, len,
"%d", an_int);
437 buffer = malloc(len + 1);
438 if (buffer != NULL) {
439 snprintf(buffer, len,
"%d", an_int);
451 struct passwd *pwentry = NULL;
458 *uid = pwentry->pw_uid;
461 *gid = pwentry->pw_gid;
463 crm_trace(
"Cluster user %s has uid=%d gid=%d", name, pwentry->pw_uid, pwentry->pw_gid);
466 crm_err(
"Cluster user %s does not exist", name);
474 crm_version_helper(
const char *text,
char **end_text)
476 int atoi_result = -1;
482 if (text != NULL && text[0] != 0) {
483 atoi_result = (int)strtol(text, end_text, 10);
485 if (errno == EINVAL) {
486 crm_err(
"Conversion of '%s' %c failed", text, text[0]);
503 char *ver1_copy = NULL, *ver2_copy = NULL;
504 char *rest1 = NULL, *rest2 = NULL;
506 if (version1 == NULL && version2 == NULL) {
508 }
else if (version1 == NULL) {
510 }
else if (version2 == NULL) {
514 ver1_copy = strdup(version1);
515 ver2_copy = strdup(version2);
525 if (rest1 == rest2) {
530 digit1 = crm_version_helper(rest1, &rest1);
534 digit2 = crm_version_helper(rest2, &rest2);
537 if (digit1 < digit2) {
541 }
else if (digit1 > digit2) {
546 if (rest1 != NULL && rest1[0] ==
'.') {
549 if (rest1 != NULL && rest1[0] == 0) {
553 if (rest2 != NULL && rest2[0] ==
'.') {
556 if (rest2 != NULL && rest2[0] == 0) {
565 crm_trace(
"%s == %s (%d)", version1, version2, lpc);
567 crm_trace(
"%s < %s (%d)", version1, version2, lpc);
569 crm_trace(
"%s > %s (%d)", version1, version2, lpc);
583 #include <sys/types.h> 590 long long result = -1;
591 char *local_end_text = NULL;
598 if (end_text != NULL) {
599 result = strtol(text, end_text, 10);
601 result = strtol(text, &local_end_text, 10);
604 if (end_text != NULL) {
605 result = strtoll(text, end_text, 10);
607 result = strtoll(text, &local_end_text, 10);
613 if (errno == EINVAL) {
614 crm_err(
"Conversion of %s failed", text);
617 }
else if (errno == ERANGE) {
618 crm_err(
"Conversion of %s was clipped: %lld", text, result);
620 }
else if (errno != 0) {
621 crm_perror(LOG_ERR,
"Conversion of %s failed:", text);
624 if (local_end_text != NULL && local_end_text[0] !=
'\0') {
625 crm_err(
"Characters left over after parsing '%s': '%s'", text, local_end_text);
636 int atoi_result = -1;
645 if (default_text != NULL) {
652 crm_err(
"No default conversion value supplied");
664 }
else if (a == NULL || b == NULL) {
667 }
else if (strcasecmp(a, b) == 0) {
676 gboolean ret = FALSE;
690 }
else if (strcasecmp(s,
"true") == 0
691 || strcasecmp(s,
"on") == 0
692 || strcasecmp(s,
"yes") == 0 || strcasecmp(s,
"y") == 0 || strcasecmp(s,
"1") == 0) {
696 }
else if (strcasecmp(s,
"false") == 0
697 || strcasecmp(s,
"off") == 0
698 || strcasecmp(s,
"no") == 0 || strcasecmp(s,
"n") == 0 || strcasecmp(s,
"0") == 0) {
706 # define NUMCHARS "0123456789." 710 # define WHITESPACE " \t\n\r\f" 716 unsigned long long msec = 0;
721 }
else if (input[0] !=
'P') {
741 const char *cp = input;
743 long long multiplier = 1000;
744 long long divisor = 1;
746 char *end_text = NULL;
758 if (strchr(
NUMCHARS, *cp) == NULL) {
762 if (strncasecmp(units,
"ms", 2) == 0 || strncasecmp(units,
"msec", 4) == 0) {
765 }
else if (strncasecmp(units,
"us", 2) == 0 || strncasecmp(units,
"usec", 4) == 0) {
768 }
else if (strncasecmp(units,
"s", 1) == 0 || strncasecmp(units,
"sec", 3) == 0) {
771 }
else if (strncasecmp(units,
"m", 1) == 0 || strncasecmp(units,
"min", 3) == 0) {
772 multiplier = 60 * 1000;
774 }
else if (strncasecmp(units,
"h", 1) == 0 || strncasecmp(units,
"hr", 2) == 0) {
775 multiplier = 60 * 60 * 1000;
777 }
else if (*units !=
EOS && *units !=
'\n' && *units !=
'\r') {
782 if (msec > LLONG_MAX/multiplier) {
802 len += strlen(op_type);
803 len += strlen(rsc_id);
806 sprintf(op_id,
"%s_%s_%d", rsc_id, op_type, interval);
811 parse_op_key(
const char *key,
char **rsc_id,
char **op_type,
int *interval)
814 char *mutable_key = NULL;
815 char *mutable_key_ptr = NULL;
816 int len = 0, offset = 0, ch = 0;
826 while (offset > 0 && isdigit(key[offset])) {
827 int digits = len - offset;
829 ch = key[offset] -
'0';
841 CRM_CHECK(key[offset] ==
'_',
return FALSE);
843 mutable_key = strdup(key);
844 mutable_key[offset] = 0;
847 while (offset > 0 && key[offset] !=
'_') {
851 CRM_CHECK(key[offset] ==
'_', free(mutable_key);
854 mutable_key_ptr = mutable_key + offset + 1;
856 crm_trace(
" Action: %s", mutable_key_ptr);
858 *op_type = strdup(mutable_key_ptr);
860 mutable_key[offset] = 0;
863 CRM_CHECK(mutable_key != mutable_key_ptr, free(mutable_key);
866 notify = strstr(mutable_key,
"_post_notify");
867 if (notify &&
safe_str_eq(notify,
"_post_notify")) {
871 notify = strstr(mutable_key,
"_pre_notify");
872 if (notify &&
safe_str_eq(notify,
"_pre_notify")) {
877 *rsc_id = mutable_key;
890 CRM_CHECK(notify_type != NULL,
return NULL);
892 len += strlen(op_type);
893 len += strlen(rsc_id);
894 len += strlen(notify_type);
899 sprintf(op_id,
"%s_%s_notify_%s_0", rsc_id, notify_type, op_type);
908 char *fail_state = NULL;
910 CRM_CHECK(transition_key != NULL,
return NULL);
912 len += strlen(transition_key);
914 fail_state = malloc(len);
915 if (fail_state != NULL) {
916 snprintf(fail_state, len,
"%d:%s", op_status, transition_key);
925 char *fail_state = NULL;
927 CRM_CHECK(transition_key != NULL,
return NULL);
929 len += strlen(transition_key);
931 fail_state = malloc(len);
932 if (fail_state != NULL) {
933 snprintf(fail_state, len,
"%d:%d;%s", op_status, op_rc, transition_key);
940 int *
op_status,
int *op_rc,
int *target_rc)
944 gboolean result = TRUE;
948 CRM_CHECK(op_status != NULL,
return FALSE);
950 key = calloc(1, strlen(magic) + 1);
951 res = sscanf(magic,
"%d:%d;%s", op_status, op_rc, key);
953 crm_warn(
"Only found %d items in: '%s'", res, magic);
968 char *fail_state = NULL;
974 fail_state = malloc(len);
975 if (fail_state != NULL) {
976 snprintf(fail_state, len,
"%d:%d:%d:%-*s", action_id, transition_id, target_rc, 36, node);
986 gboolean done = FALSE;
989 CRM_CHECK(target_rc != NULL,
return FALSE);
990 CRM_CHECK(action_id != NULL,
return FALSE);
991 CRM_CHECK(transition_id != NULL,
return FALSE);
993 *uuid = calloc(1, 37);
994 res = sscanf(key,
"%d:%d:%d:%36s", action_id, transition_id, target_rc, *uuid);
1007 res = sscanf(key,
"%d:%d:%36s", action_id, transition_id, *uuid);
1010 res = sscanf(key,
"%d:%36s", transition_id, *uuid);
1013 }
else if (res != 3) {
1023 res = sscanf(key,
"%d:%36s", transition_id, *uuid);
1027 crm_crit(
"Unhandled sscanf result (%d) for %s", res, key);
1030 if (strlen(*uuid) != 36) {
1031 crm_warn(
"Bad UUID (%s) in sscanf result (%d) for %s", *uuid, res, key);
1034 if (done == FALSE) {
1035 crm_err(
"Cannot decode '%s' rc=%d", key, res);
1041 *transition_id = -1;
1051 char *timeout = NULL;
1052 char *interval = NULL;
1054 const char *attr_filter[] = {
1060 gboolean do_delete = FALSE;
1062 static int meta_len = 0;
1064 if (meta_len == 0) {
1068 if (param_set == NULL) {
1072 for (lpc = 0; lpc <
DIMOF(attr_filter); lpc++) {
1084 xmlAttrPtr xIter = param_set->properties;
1087 const char *prop_name = (
const char *)xIter->name;
1089 xIter = xIter->next;
1091 if (strncasecmp(prop_name,
CRM_META, meta_len) == 0) {
1103 if (timeout != NULL) {
1118 const char *assert_condition, gboolean do_core, gboolean do_fork)
1127 if(crm_is_daemon == FALSE) {
1135 if (do_core == FALSE) {
1136 crm_err(
"%s: Triggered assert at %s:%d : %s",
function, file, line, assert_condition);
1139 }
else if (do_fork) {
1143 crm_err(
"%s: Triggered fatal assert at %s:%d : %s",
function, file, line, assert_condition);
1147 crm_crit(
"%s: Cannot create core for non-fatal assert at %s:%d : %s",
1148 function, file, line, assert_condition);
1151 }
else if(pid == 0) {
1158 crm_err(
"%s: Forked child %d to record non-fatal assert at %s:%d : %s",
1159 function, pid, file, line, assert_condition);
1163 rc = waitpid(pid, &status, 0);
1168 }
while(errno == EINTR);
1170 if (errno == ECHILD) {
1172 crm_trace(
"Cannot wait on forked child %d - SIGCHLD is probably set to SIG_IGN", pid);
1175 crm_perror(LOG_ERR,
"Cannot wait on forked child %d", pid);
1181 static int last_asked_pid = 0;
1183 static int have_proc_pid = 0;
1185 static int have_proc_pid = -1;
1189 if (have_proc_pid == 0) {
1191 char proc_path[PATH_MAX], exe_path[PATH_MAX];
1192 snprintf(proc_path,
sizeof(proc_path),
"/proc/%lu/exe",
1193 (
long unsigned int) getpid());
1195 if (readlink(proc_path, exe_path,
sizeof(exe_path) - 1) < 0) {
1203 }
else if ((rc = kill(pid, 0)) < 0 && errno == ESRCH) {
1206 }
else if (rc < 0 && have_proc_pid == -1) {
1207 if (last_asked_pid != pid) {
1209 last_asked_pid =
pid;
1213 }
else if (rc == 0 && (daemon == NULL || have_proc_pid == -1)) {
1219 bool checked_through_kill = (rc == 0);
1220 char proc_path[PATH_MAX], exe_path[PATH_MAX], myexe_path[PATH_MAX];
1222 snprintf(proc_path,
sizeof(proc_path),
"/proc/%ld/exe", pid);
1224 rc = readlink(proc_path, exe_path,
sizeof(exe_path) - 1);
1225 if ((rc < 0) && (errno == EACCES)) {
1226 if (last_asked_pid != pid) {
1227 crm_info(
"Could not read from %s: %s", proc_path,
1229 last_asked_pid =
pid;
1231 return checked_through_kill ? 1 : -2;
1232 }
else if (rc < 0) {
1233 if (last_asked_pid != pid) {
1234 crm_err(
"Could not read from %s: %s (%d)", proc_path,
1236 last_asked_pid =
pid;
1240 exe_path[rc] =
'\0';
1242 if (daemon[0] !=
'/') {
1243 rc = snprintf(myexe_path,
sizeof(myexe_path),
CRM_DAEMON_DIR"/%s",
1246 rc = snprintf(myexe_path,
sizeof(myexe_path),
"%s", daemon);
1249 if (rc > 0 && rc <
sizeof(myexe_path) && !strcmp(exe_path, myexe_path)) {
1257 #define LOCKSTRLEN 11 1266 if ((fd = open(filename, O_RDONLY)) < 0) {
1270 if (read(fd, buf,
sizeof(buf)) < 1) {
1274 if (sscanf(buf,
"%lu", &pid) > 0) {
1293 int rc = -ENOENT, fd = 0;
1295 if ((fd = open(filename, O_RDONLY)) >= 0) {
1296 if (fstat(fd, &sbuf) >= 0 && sbuf.st_size <
LOCKSTRLEN) {
1301 if (read(fd, buf,
sizeof(buf)) > 0) {
1302 if (sscanf(buf,
"%lu", &pid) > 0) {
1303 crm_trace(
"Got pid %lu from %s\n", pid, filename);
1309 }
else if (mypid && pid == mypid) {
1318 }
else if (mypid && pid != mypid) {
1330 crm_lock_pidfile(
const char *filename,
const char *name)
1336 mypid = (
unsigned long)getpid();
1339 if (rc == -ENOENT) {
1347 if ((fd = open(filename, O_CREAT | O_WRONLY | O_EXCL, 0644)) < 0) {
1352 snprintf(buf,
sizeof(buf),
"%*lu\n",
LOCKSTRLEN - 1, mypid);
1357 crm_perror(LOG_ERR,
"Incomplete write to %s", filename);
1369 const char *devnull =
"/dev/null";
1371 if (daemonize == FALSE) {
1377 if(rc <
pcmk_ok && rc != -ENOENT) {
1379 crm_err(
"%s: already running [pid %ld in %s]", name, pid, pidfile);
1380 printf(
"%s: already running [pid %ld in %s]\n", name, pid, pidfile);
1386 fprintf(stderr,
"%s: could not start daemon\n", name);
1390 }
else if (pid > 0) {
1394 rc = crm_lock_pidfile(pidfile, name);
1397 printf(
"Could not lock '%s' for %s: %s (%d)\n", pidfile, name,
pcmk_strerror(rc), rc);
1401 umask(S_IWGRP | S_IWOTH | S_IROTH);
1403 close(STDIN_FILENO);
1404 (void)open(devnull, O_RDONLY);
1405 close(STDOUT_FILENO);
1406 (void)open(devnull, O_WRONLY);
1407 close(STDERR_FILENO);
1408 (void)open(devnull, O_WRONLY);
1420 for (len = strlen(str) - 1; len >= 0 && str[len] ==
'\n'; len--) {
1431 return g_strcmp0(a, b) == 0;
1434 }
else if (a == b) {
1437 }
else if (a == NULL || b == NULL) {
1441 }
else if (strcasecmp(a, b) == 0) {
1452 char *crm_name = NULL;
1458 max = strlen(crm_name);
1459 for (; lpc < max; lpc++) {
1460 switch (crm_name[lpc]) {
1462 crm_name[lpc] =
'_';
1473 const char *value = NULL;
1477 value = g_hash_table_lookup(hash, key);
1484 static struct option *
1485 crm_create_long_opts(
struct crm_option *long_options)
1487 struct option *long_opts = NULL;
1489 #ifdef HAVE_GETOPT_H 1490 int index = 0, lpc = 0;
1499 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1500 long_opts[index].name =
"__dummmy__";
1501 long_opts[index].has_arg = 0;
1502 long_opts[index].flag = 0;
1503 long_opts[index].val =
'_';
1506 for (lpc = 0; long_options[lpc].
name != NULL; lpc++) {
1507 if (long_options[lpc].name[0] ==
'-') {
1511 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1514 long_opts[index].name = long_options[lpc].
name;
1515 long_opts[index].has_arg = long_options[lpc].
has_arg;
1516 long_opts[index].flag = long_options[lpc].
flag;
1517 long_opts[index].val = long_options[lpc].
val;
1522 long_opts = realloc_safe(long_opts, (index + 1) *
sizeof(
struct option));
1523 long_opts[index].name = NULL;
1524 long_opts[index].has_arg = 0;
1525 long_opts[index].flag = 0;
1526 long_opts[index].val = 0;
1534 const char *app_desc)
1536 if (short_options) {
1537 crm_short_options = strdup(short_options);
1539 }
else if (long_options) {
1541 int opt_string_len = 0;
1542 char *local_short_options = NULL;
1544 for (lpc = 0; long_options[lpc].
name != NULL; lpc++) {
1545 if (long_options[lpc].val && long_options[lpc].val !=
'-' && long_options[lpc].val < UCHAR_MAX) {
1546 local_short_options = realloc_safe(local_short_options, opt_string_len + 4);
1547 local_short_options[opt_string_len++] = long_options[lpc].
val;
1549 if (long_options[lpc].has_arg == optional_argument) {
1550 local_short_options[opt_string_len++] =
':';
1552 if (long_options[lpc].has_arg >= required_argument) {
1553 local_short_options[opt_string_len++] =
':';
1555 local_short_options[opt_string_len] = 0;
1558 crm_short_options = local_short_options;
1559 crm_trace(
"Generated short option string: '%s'", local_short_options);
1563 crm_long_options = long_options;
1566 crm_app_description = app_desc;
1569 crm_app_usage = app_usage;
1582 #ifdef HAVE_GETOPT_H 1583 static struct option *long_opts = NULL;
1585 if (long_opts == NULL && crm_long_options) {
1586 long_opts = crm_create_long_opts(crm_long_options);
1591 int flag = getopt_long(argc, argv, crm_short_options, long_opts, index);
1595 if (long_opts[*index].val) {
1596 return long_opts[*index].val;
1597 }
else if (longname) {
1598 *longname = long_opts[*index].name;
1600 crm_notice(
"Unhandled option --%s", long_opts[*index].name);
1617 if (crm_short_options) {
1618 return getopt(argc, argv, crm_short_options);
1628 FILE *stream = (exit_code ? stderr : stdout);
1630 if (cmd ==
'v' || cmd ==
'$') {
1632 fprintf(stream,
"Written by Andrew Beekhof\n");
1643 if (crm_app_usage) {
1647 if (crm_long_options) {
1648 fprintf(stream,
"Options:\n");
1649 for (i = 0; crm_long_options[i].
name != NULL; i++) {
1653 fprintf(stream,
"%s\n\n", crm_long_options[i].desc);
1656 fprintf(stream,
"\t#%s\n\n", crm_long_options[i].desc);
1658 }
else if (crm_long_options[i].val ==
'-' && crm_long_options[i].desc) {
1659 fprintf(stream,
"%s\n", crm_long_options[i].desc);
1663 if (crm_long_options[i].val && crm_long_options[i].val <= UCHAR_MAX) {
1664 fprintf(stream,
" -%c,", crm_long_options[i].val);
1668 fprintf(stream,
" --%s%s\t%s\n", crm_long_options[i].name,
1669 crm_long_options[i].has_arg == optional_argument ?
"[=value]" :
1670 crm_long_options[i].has_arg == required_argument ?
"=value" :
"",
1671 crm_long_options[i].desc ? crm_long_options[i].desc :
"");
1675 }
else if (crm_short_options) {
1676 fprintf(stream,
"Usage: %s - %s\n",
crm_system_name, crm_app_description);
1677 for (i = 0; crm_short_options[i] != 0; i++) {
1678 int has_arg = no_argument ;
1680 if (crm_short_options[i + 1] ==
':') {
1681 if (crm_short_options[i + 2] ==
':')
1682 has_arg = optional_argument ;
1684 has_arg = required_argument ;
1687 fprintf(stream,
" -%c %s\n", crm_short_options[i],
1688 has_arg == optional_argument ?
"[value]" :
1689 has_arg == required_argument ?
"{value}" :
"");
1701 qb_ipcs_service_t **ipcs_rw,
1702 qb_ipcs_service_t **ipcs_shm,
1703 struct qb_ipcs_service_handlers *ro_cb,
1704 struct qb_ipcs_service_handlers *rw_cb)
1710 if (*ipcs_ro == NULL || *ipcs_rw == NULL || *ipcs_shm == NULL) {
1711 crm_err(
"Failed to create cib servers: exiting and inhibiting respawn.");
1712 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1718 qb_ipcs_service_t *ipcs_rw,
1719 qb_ipcs_service_t *ipcs_shm)
1721 qb_ipcs_destroy(ipcs_ro);
1722 qb_ipcs_destroy(ipcs_rw);
1723 qb_ipcs_destroy(ipcs_shm);
1737 if (*ipcs == NULL) {
1738 crm_err(
"Failed to create attrd servers: exiting and inhibiting respawn.");
1739 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1749 if (*ipcs == NULL) {
1750 crm_err(
"Failed to create stonith-ng servers: exiting and inhibiting respawn.");
1751 crm_warn(
"Verify pacemaker and pacemaker_remote are not both enabled.");
1758 const char *value,
const char *section,
const char *
set,
const char *dampen,
1759 const char *user_name,
int options)
1765 static gboolean connected = TRUE;
1769 if (ipc == NULL && local_ipc == NULL) {
1790 if (name == NULL && command ==
'U') {
1831 if (connected == FALSE) {
1832 crm_info(
"Connecting to cluster... %d retries remaining", max);
1839 crm_perror(LOG_INFO,
"Connection to cluster attribute manager failed");
1842 if (ipc != local_ipc) {
1845 }
else if (rc > 0) {
1848 }
else if (rc == -EAGAIN || rc == -EALREADY) {
1862 crm_debug(
"Sent update: %s=%s for %s", name, value, host ? host :
"localhost");
1866 crm_debug(
"Could not send update %s=%s for %s: %s (%d)", name, value,
1872 #define FAKE_TE_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 1881 char *digest = NULL;
1882 xmlNode *args_xml = NULL;
1884 if (op->
params == NULL) {
1898 do_crm_log(level,
"Calculated digest %s for %s (%s). Source: %s\n",
1899 digest,
ID(update), magic, digest_source);
1900 free(digest_source);
1940 if (target_rc != op->
rc) {
1950 int target_rc,
const char * node,
const char * origin,
int level)
1955 char *op_id_additional = NULL;
1956 char *local_user_data = NULL;
1957 const char *exit_reason = NULL;
1959 xmlNode *xml_op = NULL;
1960 const char *task = NULL;
1961 gboolean dc_munges_migrate_ops = (
compare_version(caller_version,
"3.0.3") < 0);
1962 gboolean dc_needs_unique_ops = (
compare_version(caller_version,
"3.0.6") < 0);
1965 do_crm_log(level,
"%s: Updating resource %s after %s op %s (interval=%d)",
1969 crm_trace(
"DC version: %s", caller_version);
1990 }
else if (dc_munges_migrate_ops
1997 if (dc_needs_unique_ops && op->
interval > 0) {
1998 op_id = strdup(key);
2021 op_id = strdup(key);
2029 if (xml_op == NULL) {
2034 crm_debug(
"Generating fake transition key for:" 2035 " %s_%s_%d %d from %s",
2062 crm_trace(
"Timing data (%s_%s_%d): last=%lu change=%lu exec=%lu queue=%lu",
2098 append_digest(op, xml_op, caller_version, magic, LOG_DEBUG);
2100 if (op_id_additional) {
2102 op_id = op_id_additional;
2103 op_id_additional = NULL;
2107 if (local_user_data) {
2108 free(local_user_data);
2121 if(user == NULL || strlen(user) == 0) {
2128 }
else if (strcmp(user,
"root") == 0) {
2131 crm_trace(
"acls required for %s", user);
2143 struct passwd *pwent = getpwuid(uid);
2145 if (pwent == NULL) {
2146 crm_perror(LOG_ERR,
"Cannot get password entry of uid: %d", uid);
2150 return strdup(pwent->pw_name);
2158 static const char *effective_user = NULL;
2159 const char *requested_user = NULL;
2160 const char *user = NULL;
2162 if(effective_user == NULL) {
2167 if(requested_user == NULL) {
2171 if (is_privileged(effective_user) == FALSE) {
2173 user = effective_user;
2175 }
else if(peer_user == NULL && requested_user == NULL) {
2177 user = effective_user;
2179 }
else if(peer_user == NULL) {
2181 user = requested_user;
2183 }
else if (is_privileged(peer_user) == FALSE) {
2187 }
else if (requested_user == NULL) {
2193 user = requested_user;
2205 return requested_user;
2212 CRM_CHECK(user != NULL && request != NULL && field != NULL,
return);
2215 if (is_privileged(user) == FALSE) {
2246 const signed char *p;
2249 for (p = v; *p !=
'\0'; p++)
2250 h = (h << 5) - h + *p;
2258 const signed char *p;
2261 for (p = v; *p !=
'\0'; p++)
2262 h = (h << 5) - h + g_ascii_tolower(*p);
2273 if (*handle == NULL) {
2274 *handle = dlopen(lib, RTLD_LAZY);
2278 crm_err(
"%sCould not open %s: %s", fatal ?
"Fatal: " :
"", lib, dlerror());
2285 a_function = dlsym(*handle, fn);
2286 if ((error = dlerror()) != NULL) {
2287 crm_err(
"%sCould not find %s in %s: %s", fatal ?
"Fatal: " :
"", fn, lib, error);
2302 if (value == NULL) {
2306 last = strlen(list);
2309 len += strlen(value);
2310 list = realloc_safe(list, len);
2311 sprintf(list + last,
" %s", value);
2322 #ifdef HAVE_UUID_UUID_H 2323 # include <uuid/uuid.h> 2329 unsigned char uuid[16];
2330 char *buffer = malloc(37);
2332 uuid_generate(uuid);
2333 uuid_unparse(uuid, buffer);
2342 int lpc = 0, len = 0;
2343 char *digest = NULL;
2346 if (buffer == NULL) {
2349 len = strlen(buffer);
2351 crm_trace(
"Beginning digest of %d bytes", len);
2356 sprintf(digest + (2 * lpc),
"%02x", raw_digest[lpc]);
2362 crm_err(
"Could not create digest");
2374 char *compressed = NULL;
2375 char *uncompressed = strdup(data);
2376 struct timespec after_t;
2377 struct timespec before_t;
2380 max = (length * 1.1) + 600;
2383 #ifdef CLOCK_MONOTONIC 2384 clock_gettime(CLOCK_MONOTONIC, &before_t);
2388 compressed = malloc(max);
2391 rc = BZ2_bzBuffToBuffCompress(compressed, result_len, uncompressed, length,
CRM_BZ2_BLOCKS, 0,
2402 #ifdef CLOCK_MONOTONIC 2403 clock_gettime(CLOCK_MONOTONIC, &after_t);
2405 crm_info(
"Compressed %d bytes into %d (ratio %d:1) in %dms",
2406 length, *result_len, length / (*result_len),
2407 (after_t.tv_sec - before_t.tv_sec) * 1000 + (after_t.tv_nsec -
2408 before_t.tv_nsec) / 1000000);
2410 crm_info(
"Compressed %d bytes into %d (ratio %d:1)",
2411 length, *result_len, length / (*result_len));
2414 *result = compressed;
2418 #ifdef HAVE_GNUTLS_GNUTLS_H 2420 crm_gnutls_global_init(
void)
2422 signal(SIGPIPE, SIG_IGN);
2423 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)
char * strerror(int errnum)
#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)