pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
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 <crm/common/acl.h>
#include <crm/common/actions.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 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...
 
const char * pcmk_readable_score (int score)
 Return a displayable static string for a score value. More...
 
int char2score (const char *score)
 Get the integer value of a score string. More...
 
int pcmk__add_scores (int score1, int score2)
 
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 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

◆ 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 99 of file util.h.

Function Documentation

◆ char2score()

int char2score ( const char *  score)

Get the integer value of a score string.

Given a string representation of a score, return the integer equivalent. This accepts infinity strings as well as red, yellow, and green, and bounds the result to +/-INFINITY.

Parameters
[in]scoreScore as string
Returns
Integer value corresponding to score

Definition at line 36 of file scores.c.

◆ compare_version()

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

Definition at line 189 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 397 of file utils.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 1258 of file remote.c.

◆ crm_generate_uuid()

char* crm_generate_uuid ( void  )

Definition at line 509 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 optional unit (optionally with whitespace before and/or after the number). If missing, the unit defaults to seconds.
Returns
Milliseconds corresponding to string expression, or PCMK__PARSE_INT_DEFAULT on error

Definition at line 364 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 999 of file ipc_server.c.

◆ crm_is_true()

gboolean crm_is_true ( const char *  s)

Definition at line 416 of file strings.c.

◆ crm_md5sum()

char* crm_md5sum ( const char *  buffer)

Definition at line 253 of file digest.c.

◆ crm_meta_name()

char* crm_meta_name ( const char *  field)

Definition at line 468 of file utils.c.

◆ crm_meta_value()

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

Definition at line 490 of file utils.c.

◆ crm_parse_interval_spec()

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

◆ crm_str_to_boolean()

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

Definition at line 424 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 1351 of file strings.c.

◆ crm_user_lookup()

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

Definition at line 86 of file utils.c.

◆ pcmk__add_scores()

int pcmk__add_scores ( int  score1,
int  score2 
)

Definition at line 116 of file scores.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 126 of file utils.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 535 of file utils.c.

◆ pcmk_promotion_score_name()

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 80 of file attrs.c.

◆ pcmk_readable_score()

const char* pcmk_readable_score ( int  score)

Return a displayable static string for a score value.

Given a score value, return a pointer to a static string representation of the score suitable for log messages, output, etc.

Parameters
[in]scoreScore to display
Returns
Pointer to static memory containing string representation of score
Note
Subsequent calls to this function will overwrite the returned value, so it should be used only in a local context such as a printf()-style statement.

Definition at line 86 of file scores.c.

◆ pcmk_str_is_infinity()

bool pcmk_str_is_infinity ( const char *  s)

Definition at line 543 of file utils.c.

◆ pcmk_str_is_minus_infinity()

bool pcmk_str_is_minus_infinity ( const char *  s)

Definition at line 548 of file utils.c.