root/include/crm/common/results_internal.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. pcmk__format_result

   1 /*
   2  * Copyright 2020-2024 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 
  10 #ifndef PCMK__CRM_COMMON_RESULTS_INTERNAL__H
  11 #define PCMK__CRM_COMMON_RESULTS_INTERNAL__H
  12 
  13 #include <stdbool.h>
  14 
  15 #include <glib.h>               // GQuark
  16 
  17 #include <crm/common/results.h>
  18 
  19 #ifdef __cplusplus
  20 extern "C" {
  21 #endif
  22 
  23 extern const size_t pcmk__n_rc;
  24 
  25 int pcmk__result_bounds(enum pcmk_result_type, int *lower, int *upper);
  26 
  27 _Noreturn void pcmk__abort_as(const char *file, const char *function, int line,
  28                               const char *assert_condition);
  29 
  30 #define pcmk__assert(expr) do {                                     \
  31         if (!(expr)) {                                              \
  32             pcmk__abort_as(__FILE__, __func__, __LINE__, #expr);    \
  33         }                                                           \
  34     } while(0)
  35 
  36 /*!
  37  * \internal
  38  * \brief Abort without dumping core if a pointer is \c NULL
  39  *
  40  * This is intended to check for memory allocation failure, rather than for null
  41  * pointers in general.
  42  *
  43  * \param[in] ptr  Pointer to check
  44  */
  45 #define pcmk__mem_assert(ptr) do {                                          \
  46         if ((ptr) == NULL) {                                                \
  47             crm_abort(__FILE__, __func__, __LINE__, "Out of memory", FALSE, \
  48                       TRUE);                                                \
  49             crm_exit(CRM_EX_OSERR);                                         \
  50         }                                                                   \
  51     } while (0)
  52 
  53 /* Error domains for use with g_set_error */
  54 
  55 GQuark pcmk__rc_error_quark(void);
  56 GQuark pcmk__exitc_error_quark(void);
  57 
  58 #define PCMK__RC_ERROR       pcmk__rc_error_quark()
  59 #define PCMK__EXITC_ERROR    pcmk__exitc_error_quark()
  60 
  61 /* Action results */
  62 
  63 typedef struct {
  64     int exit_status;        // Child exit status
  65     enum pcmk_exec_status execution_status; // Execution status
  66     char *exit_reason;      // Brief, human-friendly explanation
  67     char *action_stdout;    // Action output
  68     char *action_stderr;    // Action error output
  69 } pcmk__action_result_t;
  70 
  71 /*!
  72  * \internal
  73  * \brief Static initialization for an action result
  74  *
  75  * \note Importantly, this ensures pcmk__reset_result() won't try to free
  76  *       garbage.
  77  */
  78 #define PCMK__UNKNOWN_RESULT {                  \
  79         .exit_status = CRM_EX_OK,               \
  80         .execution_status = PCMK_EXEC_UNKNOWN,  \
  81         .exit_reason = NULL,                    \
  82         .action_stdout = NULL,                  \
  83         .action_stderr = NULL,                  \
  84     }
  85 
  86 void pcmk__set_result(pcmk__action_result_t *result, int exit_status,
  87                       enum pcmk_exec_status exec_status,
  88                       const char *exit_reason);
  89 
  90 void pcmk__format_result(pcmk__action_result_t *result, int exit_status,
     /* [previous][next][first][last][top][bottom][index][help] */
  91                          enum pcmk_exec_status exec_status,
  92                          const char *format, ...) G_GNUC_PRINTF(4, 5);
  93 
  94 void pcmk__set_result_output(pcmk__action_result_t *result,
  95                              char *out, char *err);
  96 
  97 void pcmk__reset_result(pcmk__action_result_t *result);
  98 
  99 void pcmk__copy_result(const pcmk__action_result_t *src,
 100                        pcmk__action_result_t *dst);
 101 
 102 int pcmk__gaierror2rc(int gai);
 103 int pcmk__bzlib2rc(int bz2);
 104 
 105 /*!
 106  * \internal
 107  * \brief Check whether a result is OK
 108  *
 109  * \param[in] result
 110  *
 111  * \return true if the result's exit status is CRM_EX_OK and its
 112  *         execution status is PCMK_EXEC_DONE, otherwise false
 113  */
 114 static inline bool
 115 pcmk__result_ok(const pcmk__action_result_t *result)
 116 {
 117     return (result != NULL) && (result->exit_status == CRM_EX_OK)
 118             && (result->execution_status == PCMK_EXEC_DONE);
 119 }
 120 
 121 #ifdef __cplusplus
 122 }
 123 #endif
 124 
 125 #endif // PCMK__COMMON_RESULTS_INTERNAL__H

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