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

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