pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
results_internal.h
Go to the documentation of this file.
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 
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
70 
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,
91  enum pcmk_exec_status exec_status,
92  const char *format, ...) G_GNUC_PRINTF(4, 5);
93 
95  char *out, char *err);
96 
98 
100  pcmk__action_result_t *dst);
101 
102 int pcmk__gaierror2rc(int gai);
103 int pcmk__bzlib2rc(int bz2);
104 
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)
119 }
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif // PCMK__COMMON_RESULTS_INTERNAL__H
void pcmk__format_result(pcmk__action_result_t *result, int exit_status, enum pcmk_exec_status exec_status, const char *format,...) G_GNUC_PRINTF(4
const size_t pcmk__n_rc
Definition: results.c:439
void void pcmk__set_result_output(pcmk__action_result_t *result, char *out, char *err)
Definition: results.c:1143
_Noreturn void pcmk__abort_as(const char *file, const char *function, int line, const char *assert_condition)
Definition: results.c:150
enum pcmk_exec_status execution_status
int pcmk__result_bounds(enum pcmk_result_type, int *lower, int *upper)
Definition: results.c:92
void pcmk__copy_result(const pcmk__action_result_t *src, pcmk__action_result_t *dst)
Definition: results.c:1187
Action completed, result is known.
Definition: results.h:309
Success.
Definition: results.h:231
Function and executable result codes.
int pcmk__bzlib2rc(int bz2)
Map a bz2 return code to the most similar Pacemaker return code.
Definition: results.c:1014
pcmk__action_result_t result
Definition: pcmk_fence.c:37
#define _Noreturn
Definition: results.h:40
int pcmk__gaierror2rc(int gai)
Map a getaddrinfo() return code to the most similar Pacemaker return code.
Definition: results.c:973
GQuark pcmk__rc_error_quark(void)
void pcmk__set_result(pcmk__action_result_t *result, int exit_status, enum pcmk_exec_status exec_status, const char *exit_reason)
Definition: results.c:1074
pcmk_exec_status
Execution status.
Definition: results.h:306
GQuark pcmk__exitc_error_quark(void)
void pcmk__reset_result(pcmk__action_result_t *result)
Definition: results.c:1163
pcmk_result_type
Types of Pacemaker result codes.
Definition: results.h:340