1 /* 2 * Copyright 2012-2020 the Pacemaker project contributors 3 * 4 * The version control history for this file may have further details. 5 * 6 * This source code is licensed under the GNU Lesser General Public License 7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. 8 */ 9 #ifndef CRM_ERROR__H 10 # define CRM_ERROR__H 11 # include <crm_config.h> 12 # include <assert.h> 13 14 /*! 15 * \file 16 * \brief Function and executable result codes 17 * \ingroup core 18 */ 19 20 # define CRM_ASSERT(expr) do { \ 21 if(__unlikely((expr) == FALSE)) { \ 22 crm_abort(__FILE__, __FUNCTION__, __LINE__, #expr, TRUE, FALSE); \ 23 abort(); /* Redundant but it makes analyzers like coverity and clang happy */ \ 24 } \ 25 } while(0) 26 27 /* 28 * Function return codes 29 * 30 * Most Pacemaker API functions return an integer return code. There are two 31 * alternative interpretations. The legacy interpration is that the absolute 32 * value of the return code is either a system error number or a custom 33 * pcmk_err_* number. This is less than ideal because system error numbers are 34 * constrained only to the positive int range, so there's the possibility 35 * (though not noticed in the wild) that system errors and custom errors could 36 * collide. The new intepretation is that negative values are from the pcmk_rc_e 37 * enum, and positive values are system error numbers. Both use 0 for success. 38 * 39 * For system error codes, see: 40 * - /usr/include/asm-generic/errno.h 41 * - /usr/include/asm-generic/errno-base.h 42 */ 43 44 // Legacy custom return codes for Pacemaker API functions 45 # define pcmk_ok 0 46 # define PCMK_ERROR_OFFSET 190 /* Replacements on non-linux systems, see include/portability.h */ 47 # define PCMK_CUSTOM_OFFSET 200 /* Purely custom codes */ 48 # define pcmk_err_generic 201 49 # define pcmk_err_no_quorum 202 50 # define pcmk_err_schema_validation 203 51 # define pcmk_err_transform_failed 204 52 # define pcmk_err_old_data 205 53 # define pcmk_err_diff_failed 206 54 # define pcmk_err_diff_resync 207 55 # define pcmk_err_cib_modified 208 56 # define pcmk_err_cib_backup 209 57 # define pcmk_err_cib_save 210 58 # define pcmk_err_schema_unchanged 211 59 # define pcmk_err_cib_corrupt 212 60 # define pcmk_err_multiple 213 61 # define pcmk_err_node_unknown 214 62 # define pcmk_err_already 215 63 /* On HPPA 215 is ENOSYM (Unknown error 215), which hopefully never happens. */ 64 #ifdef __hppa__ 65 # define pcmk_err_bad_nvpair 250 /* 216 is ENOTSOCK */ 66 # define pcmk_err_unknown_format 252 /* 217 is EDESTADDRREQ */ 67 #else 68 # define pcmk_err_bad_nvpair 216 69 # define pcmk_err_unknown_format 217 70 #endif 71 # define pcmk_err_panic 255 72 73 /*! 74 * \enum pcmk_rc_e 75 * \brief Return codes for Pacemaker API functions 76 * 77 * Any Pacemaker API function documented as returning a "standard Pacemaker 78 * return code" will return pcmk_rc_ok (0) on success, and one of this 79 * enumeration's other (negative) values or a (positive) system error number 80 * otherwise. The custom codes are at -1001 and lower, so that the caller may 81 * use -1 through -1000 for their own custom values if desired. While generally 82 * referred to as "errors", nonzero values simply indicate a result, which might 83 * or might not be an error depending on the calling context. 84 */ 85 enum pcmk_rc_e { 86 /* When adding new values, use consecutively lower numbers, update the array 87 * in lib/common/logging.c and test with crm_error. 88 */ 89 pcmk_rc_no_quorum = -1017, 90 pcmk_rc_schema_validation = -1016, 91 pcmk_rc_schema_unchanged = -1015, 92 pcmk_rc_transform_failed = -1014, 93 pcmk_rc_old_data = -1013, 94 pcmk_rc_diff_failed = -1012, 95 pcmk_rc_diff_resync = -1011, 96 pcmk_rc_cib_modified = -1010, 97 pcmk_rc_cib_backup = -1009, 98 pcmk_rc_cib_save = -1008, 99 pcmk_rc_cib_corrupt = -1007, 100 pcmk_rc_multiple = -1006, 101 pcmk_rc_node_unknown = -1005, 102 pcmk_rc_already = -1004, 103 pcmk_rc_bad_nvpair = -1003, 104 pcmk_rc_unknown_format = -1002, 105 // Developers: Use a more specific code than pcmk_rc_error whenever possible 106 pcmk_rc_error = -1001, 107 108 // Values -1 through -1000 reserved for caller use 109 110 pcmk_rc_ok = 0 111 112 // Positive values reserved for system error numbers 113 }; 114 115 const char *pcmk_rc_name(int rc); 116 const char *pcmk_rc_str(int rc); 117 int pcmk_rc2legacy(int rc); 118 int pcmk_legacy2rc(int legacy_rc); 119 const char *pcmk_strerror(int rc); 120 const char *pcmk_errorname(int rc); 121 const char *bz2_strerror(int rc); 122 123 #endif 124