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);
103 const char *
const prefixes[] = {
"PCMK_",
"HA_"};
106 CRM_CHECK(!pcmk__str_empty(option) && (strchr(option,
'=') == NULL),
110 int rv = snprintf(env_name,
NAME_MAX,
"%s%s", prefixes[i], option);
113 crm_err(
"Failed to write %s%s to buffer: %s", prefixes[i], option,
118 if (rv >=
sizeof(env_name)) {
119 crm_trace(
"\"%s%s\" is too long", prefixes[i], option);
124 crm_trace(
"Setting %s to %s", env_name, value);
125 rv =
setenv(env_name, value, 1);
128 rv = unsetenv(env_name);
132 crm_err(
"Failed to %sset %s: %s", (value != NULL)?
"" :
"un",
156 return (value != NULL)
158 || ((
daemon != NULL) && (strstr(value,
daemon) != NULL)));
219 if (stat(value, &
st) != 0) {
220 crm_err(
"Script %s does not exist", value);
224 if (S_ISREG(
st.st_mode) == 0) {
225 crm_err(
"Script %s is not a regular file", value);
229 if ((
st.st_mode & (S_IXUSR | S_IXGRP)) == 0) {
230 crm_err(
"Script %s is not executable", value);
241 long number = strtol(value, &end, 10);
243 if (end && (end[0] !=
'%')) {
262 cluster_option_value(GHashTable *options,
bool (*validate)(
const char *),
263 const char *
name,
const char *old_name,
264 const char *def_value)
266 const char *value = NULL;
267 char *new_value = NULL;
272 value = g_hash_table_lookup(options,
name);
274 if ((value == NULL) && old_name) {
275 value = g_hash_table_lookup(options, old_name);
278 "option '%s' is deprecated and will be " 279 "removed in a future release",
283 new_value = strdup(value);
284 g_hash_table_insert(options, strdup(
name), new_value);
289 if (value && validate && (validate(value) == FALSE)) {
291 "because '%s' is invalid",
name, value);
304 crm_trace(
"No value or default provided for cluster option '%s'",
311 crm_err(
"Bug: default value for cluster option '%s' is invalid",
name);
315 crm_trace(
"Using default value '%s' for cluster option '%s'",
318 new_value = strdup(value);
319 g_hash_table_insert(options, strdup(
name), new_value);
339 int len,
const char *
name)
341 const char *value = NULL;
343 for (
int lpc = 0; lpc < len; lpc++) {
345 value = cluster_option_value(options, option_list[lpc].is_valid,
346 option_list[lpc].
name,
347 option_list[lpc].alt_name,
348 option_list[lpc].default_value);
368 add_desc(GString *s,
const char *tag,
const char *desc,
const char *values,
373 if (spaces != NULL) {
374 g_string_append(s, spaces);
378 if (values != NULL) {
385 static const char *locale = NULL;
389 if (strcmp(escaped_en, localized) != 0) {
390 if (locale == NULL) {
391 locale = strtok(setlocale(LC_ALL, NULL),
"_");
394 if (spaces != NULL) {
395 g_string_append(s, spaces);
400 if (values != NULL) {
414 const char *desc_long,
418 GString *s = g_string_sized_new(13000);
421 "<?xml version=\"1.0\"?>\n" 422 "<resource-agent name=\"",
name,
"\" " 426 add_desc(s,
"longdesc", desc_long, NULL,
" ");
427 add_desc(s,
"shortdesc", desc_short, NULL,
" ");
429 g_string_append(s,
" <parameters>\n");
431 for (
int lpc = 0; lpc < len; lpc++) {
432 const char *opt_name = option_list[lpc].
name;
433 const char *opt_type = option_list[lpc].
type;
434 const char *opt_values = option_list[lpc].
values;
440 CRM_ASSERT((opt_desc_short != NULL) || (opt_desc_long != NULL));
442 if (opt_desc_short == NULL) {
443 opt_desc_short = opt_desc_long;
444 }
else if (opt_desc_long == NULL) {
445 opt_desc_long = opt_desc_short;
451 pcmk__g_strcat(s,
" <parameter name=\"", opt_name,
"\">\n", NULL);
453 add_desc(s,
"longdesc", opt_desc_long, opt_values,
" ");
454 add_desc(s,
"shortdesc", opt_desc_short, NULL,
" ");
457 if (opt_default != NULL) {
461 if ((opt_values != NULL) && (strcmp(opt_type,
"select") == 0)) {
462 char *str = strdup(opt_values);
463 const char *delim =
", ";
464 char *ptr = strtok(str, delim);
466 g_string_append(s,
">\n");
468 while (ptr != NULL) {
471 ptr = strtok(NULL, delim);
473 g_string_append_printf(s,
" </content>\n");
477 g_string_append(s,
"/>\n");
480 g_string_append(s,
" </parameter>\n");
482 g_string_append(s,
" </parameters>\n</resource-agent>\n");
484 return g_string_free(s, FALSE);
491 for (
int lpc = 0; lpc < len; lpc++) {
492 cluster_option_value(options, option_list[lpc].is_valid,
493 option_list[lpc].
name,
494 option_list[lpc].alt_name,
495 option_list[lpc].default_value);
#define CRM_CHECK(expr, failure_action)
void pcmk__set_env_option(const char *option, const char *value)
Set or unset a Pacemaker environment variable option.
_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
char * strerror(int errnum)
#define PACEMAKER_VERSION
bool pcmk__valid_percentage(const char *value)
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
int daemon(int nochdir, int noclose)
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...)
int setenv(const char *name, const char *value, int why)
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