dhodovsk / source-git / pacemaker

Forked from source-git/pacemaker 3 years ago
Clone

Blame include/crm/common/internal.h

rpm-build 3ee90c
/*
rpm-build 3ee90c
 * Copyright 2015-2019 the Pacemaker project contributors
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * The version control history for this file may have further details.
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * This source code is licensed under the GNU Lesser General Public License
rpm-build 3ee90c
 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
rpm-build 3ee90c
 */
rpm-build 3ee90c
rpm-build 3ee90c
#ifndef CRM_COMMON_INTERNAL__H
rpm-build 3ee90c
#define CRM_COMMON_INTERNAL__H
rpm-build 3ee90c
rpm-build 3ee90c
#include <glib.h>       /* for gboolean */
rpm-build 3ee90c
#include <dirent.h>     /* for struct dirent */
rpm-build 3ee90c
#include <unistd.h>     /* for getpid() */
rpm-build 3ee90c
#include <stdbool.h>    /* for bool */
rpm-build 3ee90c
#include <sys/types.h>  /* for uid_t and gid_t */
rpm-build 3ee90c
rpm-build 3ee90c
#include <crm/common/logging.h>
rpm-build 3ee90c
rpm-build 3ee90c
/* internal I/O utilities (from io.c) */
rpm-build 3ee90c
rpm-build 3ee90c
char *generate_series_filename(const char *directory, const char *series, int sequence,
rpm-build 3ee90c
                               gboolean bzip);
rpm-build 3ee90c
int get_last_sequence(const char *directory, const char *series);
rpm-build 3ee90c
void write_last_sequence(const char *directory, const char *series, int sequence, int max);
rpm-build 3ee90c
int crm_chown_last_sequence(const char *directory, const char *series, uid_t uid, gid_t gid);
rpm-build 3ee90c
rpm-build 3ee90c
bool pcmk__daemon_can_write(const char *dir, const char *file);
rpm-build 3ee90c
void crm_sync_directory(const char *name);
rpm-build 3ee90c
rpm-build 3ee90c
char *crm_read_contents(const char *filename);
rpm-build 3ee90c
int crm_write_sync(int fd, const char *contents);
rpm-build 3ee90c
int crm_set_nonblocking(int fd);
rpm-build 3ee90c
const char *crm_get_tmpdir(void);
rpm-build 3ee90c
rpm-build 3ee90c
void pcmk__close_fds_in_child(bool);
rpm-build 3ee90c
rpm-build 3ee90c
rpm-build 3ee90c
/* internal procfs utilities (from procfs.c) */
rpm-build 3ee90c
rpm-build 3ee90c
int crm_procfs_process_info(struct dirent *entry, char *name, int *pid);
rpm-build 3ee90c
int crm_procfs_pid_of(const char *name);
rpm-build 3ee90c
unsigned int crm_procfs_num_cores(void);
rpm-build 3ee90c
rpm-build 3ee90c
rpm-build 3ee90c
/* internal XML schema functions (from xml.c) */
rpm-build 3ee90c
rpm-build 3ee90c
void crm_schema_init(void);
rpm-build 3ee90c
void crm_schema_cleanup(void);
rpm-build 3ee90c
rpm-build 3ee90c
rpm-build 3ee90c
/* internal functions related to process IDs (from pid.c) */
rpm-build 3ee90c
rpm-build 3ee90c
/*!
rpm-build 3ee90c
 * \internal
rpm-build 3ee90c
 * \brief Detect if process per PID and optionally exe path (component) exists
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \param[in] pid     PID of process assumed alive, disproving of which to try
rpm-build 3ee90c
 * \param[in] daemon  exe path (component) to possibly match with procfs entry
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \return -1 on invalid PID specification, -2 when the calling process has no
rpm-build 3ee90c
 *         (is refused an) ability to (dis)prove the predicate,
rpm-build 3ee90c
 *         0 if the negation of the predicate is confirmed (check-through-kill
rpm-build 3ee90c
 *         indicates so, or the subsequent check-through-procfs-match on
rpm-build 3ee90c
 *         \p daemon when provided and procfs available at the standard path),
rpm-build 3ee90c
 *         1 if it cannot be disproved (reliably [modulo race conditions]
rpm-build 3ee90c
 *         when \p daemon provided, procfs available at the standard path
rpm-build 3ee90c
 *         and the calling process has permissions to access the respective
rpm-build 3ee90c
 *         procfs location, less so otherwise, since mere check-through-kill
rpm-build 3ee90c
 *         is exercised without powers to exclude PID recycled in the interim).
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \note This function cannot be used to verify \e authenticity of the process.
rpm-build 3ee90c
 */
rpm-build 3ee90c
int crm_pid_active(long pid, const char *daemon);
rpm-build 3ee90c
rpm-build 3ee90c
long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon);
rpm-build 3ee90c
long crm_read_pidfile(const char *filename);
rpm-build 3ee90c
int crm_lock_pidfile(const char *filename, const char *name);
rpm-build 3ee90c
rpm-build 3ee90c
rpm-build 3ee90c
/* interal functions related to resource operations (from operations.c) */
rpm-build 3ee90c
rpm-build 3ee90c
char *generate_op_key(const char *rsc_id, const char *op_type,
rpm-build 3ee90c
                      guint interval_ms);
rpm-build 3ee90c
char *generate_notify_key(const char *rsc_id, const char *notify_type,
rpm-build 3ee90c
                          const char *op_type);
rpm-build 3ee90c
char *generate_transition_key(int action, int transition_id, int target_rc,
rpm-build 3ee90c
                              const char *node);
rpm-build 3ee90c
void filter_action_parameters(xmlNode *param_set, const char *version);
rpm-build 3ee90c
rpm-build 3ee90c
rpm-build 3ee90c
// miscellaneous utilities (from utils.c)
rpm-build 3ee90c
rpm-build 3ee90c
const char *pcmk_message_name(const char *name);
rpm-build 3ee90c
rpm-build 3ee90c
rpm-build 3ee90c
/* internal generic string functions (from strings.c) */
rpm-build 3ee90c
rpm-build 3ee90c
long long crm_int_helper(const char *text, char **end_text);
rpm-build 3ee90c
guint crm_parse_ms(const char *text);
rpm-build 3ee90c
bool crm_starts_with(const char *str, const char *prefix);
rpm-build 3ee90c
gboolean crm_ends_with(const char *s, const char *match);
rpm-build 3ee90c
gboolean crm_ends_with_ext(const char *s, const char *match);
rpm-build 3ee90c
char *add_list_element(char *list, const char *value);
rpm-build 3ee90c
bool crm_compress_string(const char *data, int length, int max, char **result,
rpm-build 3ee90c
                         unsigned int *result_len);
rpm-build 3ee90c
gint crm_alpha_sort(gconstpointer a, gconstpointer b);
rpm-build 3ee90c
rpm-build 3ee90c
static inline char *
rpm-build 3ee90c
crm_concat(const char *prefix, const char *suffix, char join)
rpm-build 3ee90c
{
rpm-build 3ee90c
    CRM_ASSERT(prefix && suffix);
rpm-build 3ee90c
    return crm_strdup_printf("%s%c%s", prefix, join, suffix);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static inline int
rpm-build 3ee90c
crm_strlen_zero(const char *s)
rpm-build 3ee90c
{
rpm-build 3ee90c
    return !s || *s == '\0';
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static inline char *
rpm-build 3ee90c
crm_getpid_s()
rpm-build 3ee90c
{
rpm-build 3ee90c
    return crm_strdup_printf("%lu", (unsigned long) getpid());
rpm-build 3ee90c
}
rpm-build 3ee90c
767b10
// More efficient than g_list_length(list) == 1
767b10
static inline bool
767b10
pcmk__list_of_1(GList *list)
767b10
{
767b10
    return list && (list->next == NULL);
767b10
}
767b10
767b10
// More efficient than g_list_length(list) > 1
767b10
static inline bool
767b10
pcmk__list_of_multiple(GList *list)
767b10
{
767b10
    return list && (list->next != NULL);
767b10
}
767b10
rpm-build 3ee90c
/* convenience functions for failure-related node attributes */
rpm-build 3ee90c
rpm-build 3ee90c
#define CRM_FAIL_COUNT_PREFIX   "fail-count"
rpm-build 3ee90c
#define CRM_LAST_FAILURE_PREFIX "last-failure"
rpm-build 3ee90c
rpm-build 3ee90c
/*!
rpm-build 3ee90c
 * \internal
rpm-build 3ee90c
 * \brief Generate a failure-related node attribute name for a resource
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \param[in] prefix       Start of attribute name
rpm-build 3ee90c
 * \param[in] rsc_id       Resource name
rpm-build 3ee90c
 * \param[in] op           Operation name
rpm-build 3ee90c
 * \param[in] interval_ms  Operation interval
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \return Newly allocated string with attribute name
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \note Failure attributes are named like PREFIX-RSC#OP_INTERVAL (for example,
rpm-build 3ee90c
 *       "fail-count-myrsc#monitor_30000"). The '#' is used because it is not
rpm-build 3ee90c
 *       a valid character in a resource ID, to reliably distinguish where the
rpm-build 3ee90c
 *       operation name begins. The '_' is used simply to be more comparable to
rpm-build 3ee90c
 *       action labels like "myrsc_monitor_30000".
rpm-build 3ee90c
 */
rpm-build 3ee90c
static inline char *
rpm-build 3ee90c
crm_fail_attr_name(const char *prefix, const char *rsc_id, const char *op,
rpm-build 3ee90c
                   guint interval_ms)
rpm-build 3ee90c
{
rpm-build 3ee90c
    CRM_CHECK(prefix && rsc_id && op, return NULL);
rpm-build 3ee90c
    return crm_strdup_printf("%s-%s#%s_%u", prefix, rsc_id, op, interval_ms);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static inline char *
rpm-build 3ee90c
crm_failcount_name(const char *rsc_id, const char *op, guint interval_ms)
rpm-build 3ee90c
{
rpm-build 3ee90c
    return crm_fail_attr_name(CRM_FAIL_COUNT_PREFIX, rsc_id, op, interval_ms);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static inline char *
rpm-build 3ee90c
crm_lastfailure_name(const char *rsc_id, const char *op, guint interval_ms)
rpm-build 3ee90c
{
rpm-build 3ee90c
    return crm_fail_attr_name(CRM_LAST_FAILURE_PREFIX, rsc_id, op, interval_ms);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
#endif /* CRM_COMMON_INTERNAL__H */