19 #include <sys/types.h> 27 if (cmd ==
'v' || cmd ==
'$') {
29 printf(
"Written by Andrew Beekhof and " 30 "the Pacemaker project contributors\n");
32 }
else if (cmd ==
'!') {
60 const char *
const prefixes[] = {
"PCMK_",
"HA_"};
62 const char *value = NULL;
64 CRM_CHECK(!pcmk__str_empty(option),
return NULL);
67 int rv = snprintf(env_name,
NAME_MAX,
"%s%s", prefixes[i], option);
70 crm_err(
"Failed to write %s%s to buffer: %s", prefixes[i], option,
75 if (rv >=
sizeof(env_name)) {
76 crm_trace(
"\"%s%s\" is too long", prefixes[i], option);
80 value = getenv(env_name);
82 crm_trace(
"Found %s = %s", env_name, value);
87 crm_trace(
"Nothing found for %s", option);
111 const char *
const prefixes[] = {
"PCMK_",
"HA_"};
114 CRM_CHECK(!pcmk__str_empty(option) && (strchr(option,
'=') == NULL),
118 int rv = snprintf(env_name,
NAME_MAX,
"%s%s", prefixes[i], option);
121 crm_err(
"Failed to write %s%s to buffer: %s", prefixes[i], option,
126 if (rv >=
sizeof(env_name)) {
127 crm_trace(
"\"%s%s\" is too long", prefixes[i], option);
132 crm_trace(
"Setting %s to %s", env_name, value);
133 rv = setenv(env_name, value, 1);
136 rv = unsetenv(env_name);
140 crm_err(
"Failed to %sset %s: %s", (value != NULL)?
"" :
"un",
141 env_name, strerror(errno));
144 if (!compat && (value != NULL)) {
169 return (value != NULL)
171 || ((daemon != NULL) && (strstr(value, daemon) != NULL)));
232 if (stat(value, &
st) != 0) {
233 crm_err(
"Script %s does not exist", value);
237 if (S_ISREG(
st.st_mode) == 0) {
238 crm_err(
"Script %s is not a regular file", value);
242 if ((
st.st_mode & (S_IXUSR | S_IXGRP)) == 0) {
243 crm_err(
"Script %s is not executable", value);
254 long number = strtol(value, &end, 10);
256 if (end && (end[0] !=
'%')) {
275 cluster_option_value(GHashTable *options,
bool (*validate)(
const char *),
276 const char *
name,
const char *old_name,
277 const char *def_value)
279 const char *value = NULL;
280 char *new_value = NULL;
285 value = g_hash_table_lookup(options,
name);
287 if ((value == NULL) && old_name) {
288 value = g_hash_table_lookup(options, old_name);
291 "option '%s' is deprecated and will be " 292 "removed in a future release",
296 new_value = strdup(value);
297 g_hash_table_insert(options, strdup(
name), new_value);
302 if (value && validate && (validate(value) == FALSE)) {
304 "because '%s' is invalid",
name, value);
317 crm_trace(
"No value or default provided for cluster option '%s'",
324 crm_err(
"Bug: default value for cluster option '%s' is invalid",
name);
328 crm_trace(
"Using default value '%s' for cluster option '%s'",
331 new_value = strdup(value);
332 g_hash_table_insert(options, strdup(
name), new_value);
352 int len,
const char *
name)
354 const char *value = NULL;
356 for (
int lpc = 0; lpc < len; lpc++) {
358 value = cluster_option_value(options, option_list[lpc].is_valid,
359 option_list[lpc].
name,
360 option_list[lpc].alt_name,
361 option_list[lpc].default_value);
381 add_desc(GString *s,
const char *tag,
const char *desc,
const char *values,
386 if (spaces != NULL) {
387 g_string_append(s, spaces);
391 if (values != NULL) {
398 static const char *locale = NULL;
402 if (strcmp(escaped_en, localized) != 0) {
403 if (locale == NULL) {
404 locale = strtok(setlocale(LC_ALL, NULL),
"_");
407 if (spaces != NULL) {
408 g_string_append(s, spaces);
413 if (values != NULL) {
427 const char *desc_long,
431 GString *s = g_string_sized_new(13000);
434 "<?xml version=\"1.0\"?>\n" 435 "<resource-agent name=\"",
name,
"\" " 439 add_desc(s,
"longdesc", desc_long, NULL,
" ");
440 add_desc(s,
"shortdesc", desc_short, NULL,
" ");
442 g_string_append(s,
" <parameters>\n");
444 for (
int lpc = 0; lpc < len; lpc++) {
445 const char *opt_name = option_list[lpc].
name;
446 const char *opt_type = option_list[lpc].
type;
447 const char *opt_values = option_list[lpc].
values;
453 CRM_ASSERT((opt_desc_short != NULL) || (opt_desc_long != NULL));
455 if (opt_desc_short == NULL) {
456 opt_desc_short = opt_desc_long;
457 }
else if (opt_desc_long == NULL) {
458 opt_desc_long = opt_desc_short;
464 pcmk__g_strcat(s,
" <parameter name=\"", opt_name,
"\">\n", NULL);
466 add_desc(s,
"longdesc", opt_desc_long, opt_values,
" ");
467 add_desc(s,
"shortdesc", opt_desc_short, NULL,
" ");
470 if (opt_default != NULL) {
474 if ((opt_values != NULL) && (strcmp(opt_type,
"select") == 0)) {
475 char *str = strdup(opt_values);
476 const char *delim =
", ";
477 char *ptr = strtok(str, delim);
479 g_string_append(s,
">\n");
481 while (ptr != NULL) {
484 ptr = strtok(NULL, delim);
486 g_string_append_printf(s,
" </content>\n");
490 g_string_append(s,
"/>\n");
493 g_string_append(s,
" </parameter>\n");
495 g_string_append(s,
" </parameters>\n</resource-agent>\n");
497 return g_string_free(s, FALSE);
504 for (
int lpc = 0; lpc < len; lpc++) {
505 cluster_option_value(options, option_list[lpc].is_valid,
506 option_list[lpc].
name,
507 option_list[lpc].alt_name,
508 option_list[lpc].default_value);
#define CRM_CHECK(expr, failure_action)
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
bool pcmk__valid_script(const char *value)
#define pcmk__config_warn(fmt...)
bool pcmk__valid_interval_spec(const char *value)
#define pcmk__config_err(fmt...)
bool pcmk__valid_positive_number(const char *value)
const char * default_value
#define PACEMAKER_VERSION
bool pcmk__valid_percentage(const char *value)
void pcmk__set_env_option(const char *option, const char *value, bool compat)
Set or unset a Pacemaker environment variable option.
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
const char * pcmk__cluster_option(GHashTable *options, const pcmk__cluster_option_t *option_list, int len, const char *name)
bool pcmk__valid_quorum(const char *value)
#define crm_trace(fmt, args...)
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
bool pcmk_str_is_infinity(const char *s)
int crm_str_to_boolean(const char *s, int *ret)
#define crm_err(fmt, args...)
bool pcmk_str_is_minus_infinity(const char *s)
char guint crm_parse_interval_spec(const char *input)
Parse milliseconds from a Pacemaker interval specification.
const char * description_short
void pcmk__validate_cluster_options(GHashTable *options, pcmk__cluster_option_t *option_list, int len)
void pcmk__cli_help(char cmd)
bool pcmk__env_option_enabled(const char *daemon, const char *option)
gboolean crm_is_true(const char *s)
const char * pcmk__env_option(const char *option)
bool pcmk__valid_number(const char *value)
char * crm_xml_escape(const char *text)
Replace special characters with their XML escape sequences.
bool pcmk__valid_boolean(const char *value)
gchar * pcmk__format_option_metadata(const char *name, const char *desc_short, const char *desc_long, pcmk__cluster_option_t *option_list, int len)
const char * description_long