pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | 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/agents.h>
#include <crm/common/results.h>
#include <crm/common/util_compat.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_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...
 

Functions

char * pcmk_promotion_score_name (const char *rsc_id)
 Return the name of the node attribute used as a promotion score. More...
 
int crm_default_remote_port (void)
 Get the default remote connection TCP port on this host. More...
 
gboolean crm_is_true (const char *s)
 
int crm_str_to_boolean (const char *s, int *ret)
 
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)
 
char * crm_strdup_printf (char const *format,...) G_GNUC_PRINTF(1
 
char 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...
 
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)
 

Detailed Description

Utility functions.

Definition in file util.h.

Macro Definition Documentation

#define CRM_DEFAULT_OP_TIMEOUT_S   "20s"

Definition at line 73 of file util.h.

#define OFFLINESTATUS   "offline"

Definition at line 39 of file util.h.

#define ONLINESTATUS   "online"

Definition at line 38 of file util.h.

#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 114 of file util.h.

Function Documentation

int char2score ( const char *  score)

Definition at line 61 of file utils.c.

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

Definition at line 232 of file utils.c.

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

Definition at line 440 of file utils.c.

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 472 of file operations.c.

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 1249 of file remote.c.

char* crm_generate_uuid ( void  )

Definition at line 552 of file utils.c.

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 363 of file strings.c.

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 958 of file ipc_server.c.

gboolean crm_is_true ( const char *  s)

Definition at line 415 of file strings.c.

char* crm_md5sum ( const char *  buffer)

Definition at line 271 of file digest.c.

char* crm_meta_name ( const char *  field)

Definition at line 511 of file utils.c.

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

Definition at line 533 of file utils.c.

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 499 of file operations.c.

char 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 314 of file utils.c.

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

Definition at line 426 of file strings.c.

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

Definition at line 1277 of file strings.c.

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

Definition at line 129 of file utils.c.

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 318 of file operations.c.

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 255 of file operations.c.

gboolean did_rsc_op_fail ( lrmd_event_data_t event,
int  target_rc 
)

Definition at line 437 of file operations.c.

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

Definition at line 185 of file operations.c.

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 169 of file utils.c.

char* pcmk_hostname ( void  )

Get the local hostname.

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

Definition at line 577 of file utils.c.

char* pcmk_promotion_score_name ( const char *  rsc_id)

Return the name of the node attribute used as a promotion score.

Parameters
[in]rsc_idResource ID that promotion score is for (or NULL to check the OCF_RESOURCE_INSTANCE environment variable)
Returns
Newly allocated string with the node attribute name (or NULL on error, including no ID or environment variable specified)
Note
It is the caller's responsibility to free() the result.

Definition at line 320 of file attrd_client.c.

bool pcmk_str_is_infinity ( const char *  s)

Definition at line 585 of file utils.c.

bool pcmk_str_is_minus_infinity ( const char *  s)

Definition at line 590 of file utils.c.

int rsc_op_expected_rc ( lrmd_event_data_t event)

Definition at line 426 of file operations.c.

char* score2char ( int  score)

Definition at line 117 of file utils.c.

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

Definition at line 101 of file utils.c.