root/include/crm/common/internal.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. crm_strlen_zero
  2. crm_getpid_s
  3. crm_fail_attr_name
  4. crm_failcount_name
  5. crm_lastfailure_name

   1 /*
   2  * Copyright (C) 2015
   3  *     Andrew Beekhof <andrew@beekhof.net>
   4  *
   5  * This program is free software; you can redistribute it and/or modify
   6  * it under the terms of the GNU Lesser General Public License as published by
   7  * the Free Software Foundation; either version 2 of the License, or
   8  * (at your option) any later version.
   9  *
  10  * This program is distributed in the hope that it will be useful,
  11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  * GNU Lesser General Public License for more details.
  14  *
  15  * You should have received a copy of the GNU Lesser General Public
  16  * License along with this library; if not, write to the Free Software
  17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  18  */
  19 
  20 #ifndef CRM_COMMON_INTERNAL__H
  21 #define CRM_COMMON_INTERNAL__H
  22 
  23 #include <glib.h>       /* for gboolean */
  24 #include <dirent.h>     /* for struct dirent */
  25 #include <unistd.h>     /* for getpid() */
  26 #include <sys/types.h>  /* for uid_t and gid_t */
  27 
  28 #include <crm/common/logging.h>
  29 
  30 /* internal I/O utilities (from io.c) */
  31 
  32 char *generate_series_filename(const char *directory, const char *series, int sequence,
  33                                gboolean bzip);
  34 int get_last_sequence(const char *directory, const char *series);
  35 void write_last_sequence(const char *directory, const char *series, int sequence, int max);
  36 int crm_chown_last_sequence(const char *directory, const char *series, uid_t uid, gid_t gid);
  37 
  38 gboolean crm_is_writable(const char *dir, const char *file, const char *user, const char *group,
  39                          gboolean need_both);
  40 
  41 void crm_sync_directory(const char *name);
  42 
  43 char *crm_read_contents(const char *filename);
  44 int crm_write_sync(int fd, const char *contents);
  45 int crm_set_nonblocking(int fd);
  46 
  47 
  48 /* internal procfs utilities (from procfs.c) */
  49 
  50 int crm_procfs_process_info(struct dirent *entry, char *name, int *pid);
  51 int crm_procfs_pid_of(const char *name);
  52 unsigned int crm_procfs_num_cores(void);
  53 
  54 
  55 /* internal XML schema functions (from xml.c) */
  56 
  57 void crm_schema_init(void);
  58 void crm_schema_cleanup(void);
  59 
  60 
  61 /* internal generic string functions (from strings.c) */
  62 
  63 char *crm_concat(const char *prefix, const char *suffix, char join);
  64 void g_hash_destroy_str(gpointer data);
  65 long long crm_int_helper(const char *text, char **end_text);
  66 bool crm_starts_with(const char *str, const char *prefix);
  67 gboolean crm_ends_with(const char *s, const char *match);
  68 gboolean crm_ends_with_ext(const char *s, const char *match);
  69 char *add_list_element(char *list, const char *value);
  70 bool crm_compress_string(const char *data, int length, int max, char **result,
  71                          unsigned int *result_len);
  72 gint crm_alpha_sort(gconstpointer a, gconstpointer b);
  73 
  74 static inline int
  75 crm_strlen_zero(const char *s)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77     return !s || *s == '\0';
  78 }
  79 
  80 static inline char *
  81 crm_getpid_s()
     /* [previous][next][first][last][top][bottom][index][help] */
  82 {
  83     return crm_strdup_printf("%lu", (unsigned long) getpid());
  84 }
  85 
  86 /* convenience functions for failure-related node attributes */
  87 
  88 #define CRM_FAIL_COUNT_PREFIX   "fail-count"
  89 #define CRM_LAST_FAILURE_PREFIX "last-failure"
  90 
  91 /*!
  92  * \internal
  93  * \brief Generate a failure-related node attribute name for a resource
  94  *
  95  * \param[in] prefix    Start of attribute name
  96  * \param[in] rsc_id    Resource name
  97  * \param[in] op        Operation name
  98  * \param[in] interval  Operation interval
  99  *
 100  * \return Newly allocated string with attribute name
 101  *
 102  * \note Failure attributes are named like PREFIX-RSC#OP_INTERVAL (for example,
 103  *       "fail-count-myrsc#monitor_30000"). The '#' is used because it is not
 104  *       a valid character in a resource ID, to reliably distinguish where the
 105  *       operation name begins. The '_' is used simply to be more comparable to
 106  *       action labels like "myrsc_monitor_30000".
 107  */
 108 static inline char *
 109 crm_fail_attr_name(const char *prefix, const char *rsc_id, const char *op,
     /* [previous][next][first][last][top][bottom][index][help] */
 110                    int interval)
 111 {
 112     CRM_CHECK(prefix && rsc_id && op, return NULL);
 113     return crm_strdup_printf("%s-%s#%s_%d", prefix, rsc_id, op, interval);
 114 }
 115 
 116 static inline char *
 117 crm_failcount_name(const char *rsc_id, const char *op, int interval)
     /* [previous][next][first][last][top][bottom][index][help] */
 118 {
 119     return crm_fail_attr_name(CRM_FAIL_COUNT_PREFIX, rsc_id, op, interval);
 120 }
 121 
 122 static inline char *
 123 crm_lastfailure_name(const char *rsc_id, const char *op, int interval)
     /* [previous][next][first][last][top][bottom][index][help] */
 124 {
 125     return crm_fail_attr_name(CRM_LAST_FAILURE_PREFIX, rsc_id, op, interval);
 126 }
 127 
 128 #endif /* CRM_COMMON_INTERNAL__H */

/* [previous][next][first][last][top][bottom][index][help] */