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

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