This source file includes following definitions.
- pcmk__format_result
1
2
3
4
5
6
7
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>
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
38
39
40
41
42
43
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
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
62
63 typedef struct {
64 int exit_status;
65 enum pcmk_exec_status execution_status;
66 char *exit_reason;
67 char *action_stdout;
68 char *action_stderr;
69 } pcmk__action_result_t;
70
71
72
73
74
75
76
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,
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
107
108
109
110
111
112
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