pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
Macros | Enumerations | Functions
util.h File Reference

Utility functions. More...

#include <sys/types.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <limits.h>
#include <signal.h>
#include <glib.h>
#include <libxml/tree.h>
#include <crm/lrmd.h>
#include <crm/common/acl.h>
#include <crm/common/results.h>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ONLINESTATUS   "online"
 
#define OFFLINESTATUS   "offline"
 
#define crm_str_hash   g_str_hash_traditional
 
#define crm_atoi(text, default_text)   crm_parse_int(text, default_text)
 
#define CRM_DEFAULT_OP_TIMEOUT_S   "20s"
 
#define pcmk_is_set(g, f)   pcmk_all_flags_set((g), (f))
 Convenience alias for pcmk_all_flags_set(), to check single flag. More...
 
#define crm_get_interval   crm_parse_interval_spec
 
#define safe_str_eq(a, b)   crm_str_eq(a, b, FALSE)
 

Enumerations

enum  pcmk_ra_caps {
  pcmk_ra_cap_none = 0, pcmk_ra_cap_provider = (1 << 0), pcmk_ra_cap_status = (1 << 1), pcmk_ra_cap_params = (1 << 2),
  pcmk_ra_cap_unique = (1 << 3), pcmk_ra_cap_promotable = (1 << 4), pcmk_ra_cap_stdin = (1 << 5), pcmk_ra_cap_fence_params = (1 << 6)
}
 

Functions

int pcmk_scan_nvpair (const char *input, char **name, char **value)
 Extract the name and value from an input string formatted as "name=value". If unable to extract them, they are returned as NULL. More...
 
char * pcmk_format_nvpair (const char *name, const char *value, const char *units)
 
char * pcmk_format_named_time (const char *name, time_t epoch_time)
 
int crm_default_remote_port (void)
 Get the default remote connection TCP port on this host. More...
 
char * crm_itoa_stack (int an_int, char *buf, size_t len)
 
gboolean crm_is_true (const char *s)
 
int crm_str_to_boolean (const char *s, int *ret)
 
long long crm_parse_ll (const char *text, const char *default_text)
 Parse a long long integer value from a string. More...
 
int crm_parse_int (const char *text, const char *default_text)
 Parse an integer value from a string. More...
 
long long crm_get_msec (const char *input)
 Parse a time+units string and return milliseconds equivalent. More...
 
char * crm_strip_trailing_newline (char *str)
 
gboolean crm_strcase_equal (gconstpointer a, gconstpointer b)
 
guint crm_strcase_hash (gconstpointer v)
 
guint g_str_hash_traditional (gconstpointer v)
 
char * crm_strdup_printf (char const *format,...) __attribute__((__format__(__printf__
 
char int pcmk_numeric_strcasecmp (const char *s1, const char *s2)
 Sort strings, with numeric portions sorted numerically. More...
 
GHashTable * crm_str_table_dup (GHashTable *old_table)
 
void crm_build_path (const char *path_c, mode_t mode)
 Create a directory, including any parent directories needed. More...
 
guint crm_parse_interval_spec (const char *input)
 Parse milliseconds from a Pacemaker interval specification. More...
 
int char2score (const char *score)
 
char * score2char (int score)
 
char * score2char_stack (int score, char *buf, size_t len)
 
gboolean parse_op_key (const char *key, char **rsc_id, char **op_type, guint *interval_ms)
 
gboolean decode_transition_key (const char *key, char **uuid, int *transition_id, int *action_id, int *target_rc)
 Parse a transition key into its constituent parts. More...
 
gboolean decode_transition_magic (const char *magic, char **uuid, int *transition_id, int *action_id, int *op_status, int *op_rc, int *target_rc)
 Parse a transition magic string into its constituent parts. More...
 
int rsc_op_expected_rc (lrmd_event_data_t *event)
 
gboolean did_rsc_op_fail (lrmd_event_data_t *event, int target_rc)
 
bool crm_op_needs_metadata (const char *rsc_class, const char *op)
 Check whether an operation requires resource agent meta-data. More...
 
xmlNode * crm_create_op_xml (xmlNode *parent, const char *prefix, const char *task, const char *interval_spec, const char *timeout)
 Create a CIB XML element for an operation. More...
 
uint32_t pcmk_get_ra_caps (const char *standard)
 Get capabilities of a resource agent standard. More...
 
char * crm_generate_ra_key (const char *standard, const char *provider, const char *type)
 
int crm_parse_agent_spec (const char *spec, char **standard, char **provider, char **type)
 Parse a "standard[:provider]:type" agent specification. More...
 
int compare_version (const char *version1, const char *version2)
 
void crm_abort (const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
 
char * crm_meta_name (const char *field)
 
const char * crm_meta_value (GHashTable *hash, const char *field)
 
char * crm_md5sum (const char *buffer)
 
char * crm_generate_uuid (void)
 
bool crm_is_daemon_name (const char *name)
 Check whether string represents a client name used by cluster daemons. More...
 
int crm_user_lookup (const char *name, uid_t *uid, gid_t *gid)
 
int pcmk_daemon_user (uid_t *uid, gid_t *gid)
 Get user and group IDs of pacemaker daemon user. More...
 
char * pcmk_hostname (void)
 Get the local hostname. More...
 
bool pcmk_str_is_infinity (const char *s)
 
bool pcmk_str_is_minus_infinity (const char *s)
 
bool crm_provider_required (const char *standard)
 Check whether a resource standard requires a provider to be specified. More...
 
gboolean crm_str_eq (const char *a, const char *b, gboolean use_case)
 
gboolean safe_str_neq (const char *a, const char *b)
 

Detailed Description

Utility functions.

Definition in file util.h.

Macro Definition Documentation

◆ crm_atoi

#define crm_atoi (   text,
  default_text 
)    crm_parse_int(text, default_text)

Definition at line 110 of file util.h.

◆ CRM_DEFAULT_OP_TIMEOUT_S

#define CRM_DEFAULT_OP_TIMEOUT_S   "20s"

Definition at line 134 of file util.h.

◆ crm_get_interval

#define crm_get_interval   crm_parse_interval_spec
Deprecated:
Use crm_parse_interval_spec() instead

Definition at line 235 of file util.h.

◆ crm_str_hash

#define crm_str_hash   g_str_hash_traditional

Definition at line 62 of file util.h.

◆ OFFLINESTATUS

#define OFFLINESTATUS   "offline"

Definition at line 38 of file util.h.

◆ ONLINESTATUS

#define ONLINESTATUS   "online"

Definition at line 37 of file util.h.

◆ pcmk_is_set

#define pcmk_is_set (   g,
 
)    pcmk_all_flags_set((g), (f))

Convenience alias for pcmk_all_flags_set(), to check single flag.

Definition at line 196 of file util.h.

◆ safe_str_eq

#define safe_str_eq (   a,
 
)    crm_str_eq(a, b, FALSE)
Deprecated:
Use strcasecmp instead

Definition at line 268 of file util.h.

Enumeration Type Documentation

◆ pcmk_ra_caps

Enumerator
pcmk_ra_cap_none 
pcmk_ra_cap_provider 
pcmk_ra_cap_status 
pcmk_ra_cap_params 
pcmk_ra_cap_unique 
pcmk_ra_cap_promotable 
pcmk_ra_cap_stdin 
pcmk_ra_cap_fence_params 

Definition at line 139 of file util.h.

Function Documentation

◆ char2score()

int char2score ( const char *  score)

Definition at line 61 of file utils.c.

◆ compare_version()

int compare_version ( const char *  version1,
const char *  version2 
)

Definition at line 225 of file utils.c.

◆ crm_abort()

void crm_abort ( const char *  file,
const char *  function,
int  line,
const char *  condition,
gboolean  do_core,
gboolean  do_fork 
)

Definition at line 337 of file utils.c.

◆ crm_build_path()

void crm_build_path ( const char *  path_c,
mode_t  mode 
)

Create a directory, including any parent directories needed.

Parameters
[in]path_cPathname of the directory to create
[in]modePermissions to be used (with current umask) when creating
Note
This logs errors but does not return them to the caller.

Definition at line 81 of file io.c.

◆ crm_create_op_xml()

xmlNode* crm_create_op_xml ( xmlNode *  parent,
const char *  prefix,
const char *  task,
const char *  interval_spec,
const char *  timeout 
)

Create a CIB XML element for an operation.

Parameters
[in]parentIf not NULL, make new XML node a child of this one
[in]prefixGenerate an ID using this prefix
[in]taskOperation task to set
[in]interval_specOperation interval to set
[in]timeoutIf not NULL, operation timeout to set
Returns
New XML object on success, NULL otherwise

Definition at line 474 of file operations.c.

◆ crm_default_remote_port()

int crm_default_remote_port ( void  )

Get the default remote connection TCP port on this host.

Returns
Remote connection TCP port number

Definition at line 1262 of file remote.c.

◆ crm_generate_ra_key()

char* crm_generate_ra_key ( const char *  standard,
const char *  provider,
const char *  type 
)

Definition at line 92 of file agents.c.

◆ crm_generate_uuid()

char* crm_generate_uuid ( void  )

Definition at line 498 of file utils.c.

◆ crm_get_msec()

long long crm_get_msec ( const char *  input)

Parse a time+units string and return milliseconds equivalent.

Parameters
[in]inputString with a number and units (optionally with whitespace before and/or after the number)
Returns
Milliseconds corresponding to string expression, or PCMK__PARSE_INT_DEFAULT on error

Definition at line 340 of file strings.c.

◆ crm_is_daemon_name()

bool crm_is_daemon_name ( const char *  name)

Check whether string represents a client name used by cluster daemons.

Parameters
[in]nameString to check
Returns
true if name is standard client name used by daemons, false otherwise
Note
This is provided by the client, and so cannot be used by itself as a secure means of authentication.

Definition at line 923 of file ipc_server.c.

◆ crm_is_true()

gboolean crm_is_true ( const char *  s)

Definition at line 392 of file strings.c.

◆ crm_itoa_stack()

char* crm_itoa_stack ( int  an_int,
char *  buf,
size_t  len 
)

Definition at line 28 of file strings.c.

◆ crm_md5sum()

char* crm_md5sum ( const char *  buffer)

Definition at line 271 of file digest.c.

◆ crm_meta_name()

char* crm_meta_name ( const char *  field)

Definition at line 457 of file utils.c.

◆ crm_meta_value()

const char* crm_meta_value ( GHashTable *  hash,
const char *  field 
)

Definition at line 479 of file utils.c.

◆ crm_op_needs_metadata()

bool crm_op_needs_metadata ( const char *  rsc_class,
const char *  op 
)

Check whether an operation requires resource agent meta-data.

Parameters
[in]rsc_classResource agent class (or NULL to skip class check)
[in]opOperation action (or NULL to skip op check)
Returns
TRUE if operation needs meta-data, FALSE otherwise
Note
At least one of rsc_class and op must be specified.

Definition at line 501 of file operations.c.

◆ crm_parse_agent_spec()

int crm_parse_agent_spec ( const char *  spec,
char **  standard,
char **  provider,
char **  type 
)

Parse a "standard[:provider]:type" agent specification.

Parameters
[in]specAgent specification
[out]standardNewly allocated memory containing agent standard (or NULL)
[out]providerNewly allocated memory containing agent provider (or NULL)
[put]type Newly allocated memory containing agent type (or NULL)
Returns
pcmk_ok if the string could be parsed, -EINVAL otherwise
Note
It is acceptable for the type to contain a ':' if the standard supports that. For example, systemd supports the form "systemd:UNIT@A:B".
It is the caller's responsibility to free the returned values.

Definition at line 120 of file agents.c.

◆ crm_parse_int()

int crm_parse_int ( const char *  text,
const char *  default_text 
)

Parse an integer value from a string.

Parameters
[in]textThe string to parse
[in]default_textDefault string to parse if text is NULL
Returns
Parsed value on success, INT_MIN or INT_MAX (and set errno to ERANGE) if parsed value is out of integer range, otherwise PCMK__PARSE_INT_DEFAULT (and set errno)

Definition at line 134 of file strings.c.

◆ crm_parse_interval_spec()

guint crm_parse_interval_spec ( const char *  input)

Parse milliseconds from a Pacemaker interval specification.

Parameters
[in]inputPacemaker time interval specification (a bare number of seconds, a number with a unit optionally with whitespace before and/or after the number, or an ISO 8601 duration)
Returns
Milliseconds equivalent of given specification on success (limited to the range of an unsigned integer), 0 if input is NULL, or 0 (and set errno to EINVAL) on error

Definition at line 307 of file utils.c.

◆ crm_parse_ll()

long long crm_parse_ll ( const char *  text,
const char *  default_text 
)

Parse a long long integer value from a string.

Parameters
[in]textThe string to parse
[in]default_textDefault string to parse if text is NULL
Returns
Parsed value on success, PCMK__PARSE_INT_DEFAULT (and set errno) on error

Definition at line 107 of file strings.c.

◆ crm_provider_required()

bool crm_provider_required ( const char *  standard)

Check whether a resource standard requires a provider to be specified.

Deprecated:
Use pcmk_get_ra_caps() instead
Deprecated:
Parameters
[in]standardStandard name
Returns
TRUE if standard requires a provider, FALSE otherwise

Definition at line 170 of file agents.c.

◆ crm_str_eq()

gboolean crm_str_eq ( const char *  a,
const char *  b,
gboolean  use_case 
)
Deprecated:
Use strcmp or strcasecmp instead
Deprecated:
Use pcmk__str_eq() instead

Definition at line 1098 of file strings.c.

◆ crm_str_table_dup()

GHashTable* crm_str_table_dup ( GHashTable *  old_table)

Definition at line 589 of file strings.c.

◆ crm_str_to_boolean()

int crm_str_to_boolean ( const char *  s,
int *  ret 
)

Definition at line 403 of file strings.c.

◆ crm_strcase_equal()

gboolean crm_strcase_equal ( gconstpointer  a,
gconstpointer  b 
)

Definition at line 563 of file strings.c.

◆ crm_strcase_hash()

guint crm_strcase_hash ( gconstpointer  v)

Definition at line 569 of file strings.c.

◆ crm_strdup_printf()

char* crm_strdup_printf ( char const *  format,
  ... 
)

◆ crm_strip_trailing_newline()

char* crm_strip_trailing_newline ( char *  str)

Definition at line 424 of file strings.c.

◆ crm_user_lookup()

int crm_user_lookup ( const char *  name,
uid_t *  uid,
gid_t *  gid 
)

Definition at line 122 of file utils.c.

◆ decode_transition_key()

gboolean decode_transition_key ( const char *  key,
char **  uuid,
int *  transition_id,
int *  action_id,
int *  target_rc 
)

Parse a transition key into its constituent parts.

Parameters
[in]keyTransition key to parse (must be non-NULL)
[out]uuidIf non-NULL, where to store copy of parsed UUID
[out]transition_idIf non-NULL, where to store parsed transition ID
[out]action_idIf non-NULL, where to store parsed action ID
[out]target_rcIf non-NULL, where to stored parsed target rc
Returns
TRUE if key was valid, FALSE otherwise
Note
If uuid is supplied and this returns TRUE, the caller is responsible for freeing the memory for *uuid using free().

Definition at line 317 of file operations.c.

◆ decode_transition_magic()

gboolean decode_transition_magic ( const char *  magic,
char **  uuid,
int *  transition_id,
int *  action_id,
int *  op_status,
int *  op_rc,
int *  target_rc 
)

Parse a transition magic string into its constituent parts.

Parameters
[in]magicMagic string to parse (must be non-NULL)
[out]uuidIf non-NULL, where to store copy of parsed UUID
[out]transition_idIf non-NULL, where to store parsed transition ID
[out]action_idIf non-NULL, where to store parsed action ID
[out]op_statusIf non-NULL, where to store parsed result status
[out]op_rcIf non-NULL, where to store parsed actual rc
[out]target_rcIf non-NULL, where to stored parsed target rc
Returns
TRUE if key was valid, FALSE otherwise
Note
If uuid is supplied and this returns TRUE, the caller is responsible for freeing the memory for *uuid using free().

Definition at line 254 of file operations.c.

◆ did_rsc_op_fail()

gboolean did_rsc_op_fail ( lrmd_event_data_t event,
int  target_rc 
)

Definition at line 439 of file operations.c.

◆ g_str_hash_traditional()

guint g_str_hash_traditional ( gconstpointer  v)

Definition at line 550 of file strings.c.

◆ parse_op_key()

gboolean parse_op_key ( const char *  key,
char **  rsc_id,
char **  op_type,
guint *  interval_ms 
)

Definition at line 184 of file operations.c.

◆ pcmk_daemon_user()

int pcmk_daemon_user ( uid_t *  uid,
gid_t *  gid 
)

Get user and group IDs of pacemaker daemon user.

Parameters
[out]uidIf non-NULL, where to store daemon user ID
[out]gidIf non-NULL, where to store daemon group ID
Returns
pcmk_ok on success, -errno otherwise

Definition at line 162 of file utils.c.

◆ pcmk_format_named_time()

char* pcmk_format_named_time ( const char *  name,
time_t  epoch_time 
)

Definition at line 298 of file nvpair.c.

◆ pcmk_format_nvpair()

char* pcmk_format_nvpair ( const char *  name,
const char *  value,
const char *  units 
)

Definition at line 282 of file nvpair.c.

◆ pcmk_get_ra_caps()

uint32_t pcmk_get_ra_caps ( const char *  standard)

Get capabilities of a resource agent standard.

Parameters
[in]standardStandard name
Returns
Bitmask of enum pcmk_ra_caps values

Definition at line 31 of file agents.c.

◆ pcmk_hostname()

char* pcmk_hostname ( void  )

Get the local hostname.

Returns
Newly allocated string with name, or NULL (and set errno) on error

Definition at line 523 of file utils.c.

◆ pcmk_numeric_strcasecmp()

char int pcmk_numeric_strcasecmp ( const char *  s1,
const char *  s2 
)

Sort strings, with numeric portions sorted numerically.

Sort two strings case-insensitively like strcasecmp(), but with any numeric portions of the string sorted numerically. This is particularly useful for node names (for example, "node10" will sort higher than "node9" but lower than "remotenode9").

Parameters
[in]s1First string to compare (must not be NULL)
[in]s2Second string to compare (must not be NULL)
Return values
-1s1 comes before s2
0s1 and s2 are equal
1s1 comes after s2

Definition at line 931 of file strings.c.

◆ pcmk_scan_nvpair()

int pcmk_scan_nvpair ( const char *  input,
char **  name,
char **  value 
)

Extract the name and value from an input string formatted as "name=value". If unable to extract them, they are returned as NULL.

Parameters
[in]inputThe input string, likely from the command line
[out]nameEverything before the first '=' in the input string
[out]valueEverything after the first '=' in the input string
Returns
2 if both name and value could be extracted, 1 if only one could, and and error code otherwise

Definition at line 221 of file nvpair.c.

◆ pcmk_str_is_infinity()

bool pcmk_str_is_infinity ( const char *  s)

Definition at line 531 of file utils.c.

◆ pcmk_str_is_minus_infinity()

bool pcmk_str_is_minus_infinity ( const char *  s)

Definition at line 536 of file utils.c.

◆ rsc_op_expected_rc()

int rsc_op_expected_rc ( lrmd_event_data_t event)

Definition at line 428 of file operations.c.

◆ safe_str_neq()

gboolean safe_str_neq ( const char *  a,
const char *  b 
)
Deprecated:
Use strcmp instead
Deprecated:
Use pcmk__str_eq() instead

Definition at line 1082 of file strings.c.

◆ score2char()

char* score2char ( int  score)

Definition at line 110 of file utils.c.

◆ score2char_stack()

char* score2char_stack ( int  score,
char *  buf,
size_t  len 
)

Definition at line 96 of file utils.c.