pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
results.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2019 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 #include <crm_internal.h>
11 
12 #ifndef _GNU_SOURCE
13 # define _GNU_SOURCE
14 #endif
15 
16 #include <bzlib.h>
17 #include <errno.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <qb/qbdefs.h>
21 
22 #include <crm/common/mainloop.h>
23 #include <crm/common/xml.h>
24 
25 const char *
27 {
28  int error = abs(rc);
29 
30  switch (error) {
31  case E2BIG: return "E2BIG";
32  case EACCES: return "EACCES";
33  case EADDRINUSE: return "EADDRINUSE";
34  case EADDRNOTAVAIL: return "EADDRNOTAVAIL";
35  case EAFNOSUPPORT: return "EAFNOSUPPORT";
36  case EAGAIN: return "EAGAIN";
37  case EALREADY: return "EALREADY";
38  case EBADF: return "EBADF";
39  case EBADMSG: return "EBADMSG";
40  case EBUSY: return "EBUSY";
41  case ECANCELED: return "ECANCELED";
42  case ECHILD: return "ECHILD";
43  case ECOMM: return "ECOMM";
44  case ECONNABORTED: return "ECONNABORTED";
45  case ECONNREFUSED: return "ECONNREFUSED";
46  case ECONNRESET: return "ECONNRESET";
47  /* case EDEADLK: return "EDEADLK"; */
48  case EDESTADDRREQ: return "EDESTADDRREQ";
49  case EDOM: return "EDOM";
50  case EDQUOT: return "EDQUOT";
51  case EEXIST: return "EEXIST";
52  case EFAULT: return "EFAULT";
53  case EFBIG: return "EFBIG";
54  case EHOSTDOWN: return "EHOSTDOWN";
55  case EHOSTUNREACH: return "EHOSTUNREACH";
56  case EIDRM: return "EIDRM";
57  case EILSEQ: return "EILSEQ";
58  case EINPROGRESS: return "EINPROGRESS";
59  case EINTR: return "EINTR";
60  case EINVAL: return "EINVAL";
61  case EIO: return "EIO";
62  case EISCONN: return "EISCONN";
63  case EISDIR: return "EISDIR";
64  case ELIBACC: return "ELIBACC";
65  case ELOOP: return "ELOOP";
66  case EMFILE: return "EMFILE";
67  case EMLINK: return "EMLINK";
68  case EMSGSIZE: return "EMSGSIZE";
69 #ifdef EMULTIHOP // Not available on OpenBSD
70  case EMULTIHOP: return "EMULTIHOP";
71 #endif
72  case ENAMETOOLONG: return "ENAMETOOLONG";
73  case ENETDOWN: return "ENETDOWN";
74  case ENETRESET: return "ENETRESET";
75  case ENETUNREACH: return "ENETUNREACH";
76  case ENFILE: return "ENFILE";
77  case ENOBUFS: return "ENOBUFS";
78  case ENODATA: return "ENODATA";
79  case ENODEV: return "ENODEV";
80  case ENOENT: return "ENOENT";
81  case ENOEXEC: return "ENOEXEC";
82  case ENOKEY: return "ENOKEY";
83  case ENOLCK: return "ENOLCK";
84 #ifdef ENOLINK // Not available on OpenBSD
85  case ENOLINK: return "ENOLINK";
86 #endif
87  case ENOMEM: return "ENOMEM";
88  case ENOMSG: return "ENOMSG";
89  case ENOPROTOOPT: return "ENOPROTOOPT";
90  case ENOSPC: return "ENOSPC";
91  case ENOSR: return "ENOSR";
92  case ENOSTR: return "ENOSTR";
93  case ENOSYS: return "ENOSYS";
94  case ENOTBLK: return "ENOTBLK";
95  case ENOTCONN: return "ENOTCONN";
96  case ENOTDIR: return "ENOTDIR";
97  case ENOTEMPTY: return "ENOTEMPTY";
98  case ENOTSOCK: return "ENOTSOCK";
99  /* case ENOTSUP: return "ENOTSUP"; */
100  case ENOTTY: return "ENOTTY";
101  case ENOTUNIQ: return "ENOTUNIQ";
102  case ENXIO: return "ENXIO";
103  case EOPNOTSUPP: return "EOPNOTSUPP";
104  case EOVERFLOW: return "EOVERFLOW";
105  case EPERM: return "EPERM";
106  case EPFNOSUPPORT: return "EPFNOSUPPORT";
107  case EPIPE: return "EPIPE";
108  case EPROTO: return "EPROTO";
109  case EPROTONOSUPPORT: return "EPROTONOSUPPORT";
110  case EPROTOTYPE: return "EPROTOTYPE";
111  case ERANGE: return "ERANGE";
112  case EREMOTE: return "EREMOTE";
113  case EREMOTEIO: return "EREMOTEIO";
114 
115  case EROFS: return "EROFS";
116  case ESHUTDOWN: return "ESHUTDOWN";
117  case ESPIPE: return "ESPIPE";
118  case ESOCKTNOSUPPORT: return "ESOCKTNOSUPPORT";
119  case ESRCH: return "ESRCH";
120  case ESTALE: return "ESTALE";
121  case ETIME: return "ETIME";
122  case ETIMEDOUT: return "ETIMEDOUT";
123  case ETXTBSY: return "ETXTBSY";
124  case EUNATCH: return "EUNATCH";
125  case EUSERS: return "EUSERS";
126  /* case EWOULDBLOCK: return "EWOULDBLOCK"; */
127  case EXDEV: return "EXDEV";
128 
129 #ifdef EBADE
130  /* Not available on OSX */
131  case EBADE: return "EBADE";
132  case EBADFD: return "EBADFD";
133  case EBADSLT: return "EBADSLT";
134  case EDEADLOCK: return "EDEADLOCK";
135  case EBADR: return "EBADR";
136  case EBADRQC: return "EBADRQC";
137  case ECHRNG: return "ECHRNG";
138 #ifdef EISNAM /* Not available on Illumos/Solaris */
139  case EISNAM: return "EISNAM";
140  case EKEYEXPIRED: return "EKEYEXPIRED";
141  case EKEYREJECTED: return "EKEYREJECTED";
142  case EKEYREVOKED: return "EKEYREVOKED";
143 #endif
144  case EL2HLT: return "EL2HLT";
145  case EL2NSYNC: return "EL2NSYNC";
146  case EL3HLT: return "EL3HLT";
147  case EL3RST: return "EL3RST";
148  case ELIBBAD: return "ELIBBAD";
149  case ELIBMAX: return "ELIBMAX";
150  case ELIBSCN: return "ELIBSCN";
151  case ELIBEXEC: return "ELIBEXEC";
152 #ifdef ENOMEDIUM /* Not available on Illumos/Solaris */
153  case ENOMEDIUM: return "ENOMEDIUM";
154  case EMEDIUMTYPE: return "EMEDIUMTYPE";
155 #endif
156  case ENONET: return "ENONET";
157  case ENOPKG: return "ENOPKG";
158  case EREMCHG: return "EREMCHG";
159  case ERESTART: return "ERESTART";
160  case ESTRPIPE: return "ESTRPIPE";
161 #ifdef EUCLEAN /* Not available on Illumos/Solaris */
162  case EUCLEAN: return "EUCLEAN";
163 #endif
164  case EXFULL: return "EXFULL";
165 #endif
166 
167  case pcmk_err_generic: return "pcmk_err_generic";
168  case pcmk_err_no_quorum: return "pcmk_err_no_quorum";
169  case pcmk_err_schema_validation: return "pcmk_err_schema_validation";
170  case pcmk_err_transform_failed: return "pcmk_err_transform_failed";
171  case pcmk_err_old_data: return "pcmk_err_old_data";
172  case pcmk_err_diff_failed: return "pcmk_err_diff_failed";
173  case pcmk_err_diff_resync: return "pcmk_err_diff_resync";
174  case pcmk_err_cib_modified: return "pcmk_err_cib_modified";
175  case pcmk_err_cib_backup: return "pcmk_err_cib_backup";
176  case pcmk_err_cib_save: return "pcmk_err_cib_save";
177  case pcmk_err_cib_corrupt: return "pcmk_err_cib_corrupt";
178  case pcmk_err_multiple: return "pcmk_err_multiple";
179  case pcmk_err_node_unknown: return "pcmk_err_node_unknown";
180  case pcmk_err_already: return "pcmk_err_already";
181  case pcmk_err_bad_nvpair: return "pcmk_err_bad_nvpair";
182  case pcmk_err_unknown_format: return "pcmk_err_unknown_format";
183  }
184  return "Unknown";
185 }
186 
187 const char *
189 {
190  int error = abs(rc);
191 
192  if (error == 0) {
193  return "OK";
194  } else if (error < PCMK_ERROR_OFFSET) {
195  return strerror(error);
196  }
197 
198  switch (error) {
199  case pcmk_err_generic:
200  return "Generic Pacemaker error";
201  case pcmk_err_no_quorum:
202  return "Operation requires quorum";
204  return "Update does not conform to the configured schema";
206  return "Schema transform failed";
207  case pcmk_err_old_data:
208  return "Update was older than existing configuration";
210  return "Application of an update diff failed";
212  return "Application of an update diff failed, requesting a full refresh";
214  return "The on-disk configuration was manually modified";
215  case pcmk_err_cib_backup:
216  return "Could not archive the previous configuration";
217  case pcmk_err_cib_save:
218  return "Could not save the new configuration to disk";
220  return "Could not parse on-disk configuration";
221  case pcmk_err_multiple:
222  return "Resource active on multiple nodes";
224  return "Node not found";
225  case pcmk_err_already:
226  return "Situation already as requested";
227  case pcmk_err_bad_nvpair:
228  return "Bad name/value pair given";
230  return "Schema is already the latest available";
232  return "Unknown output format";
233 
234  /* The following cases will only be hit on systems for which they are non-standard */
235  /* coverity[dead_error_condition] False positive on non-Linux */
236  case ENOTUNIQ:
237  return "Name not unique on network";
238  /* coverity[dead_error_condition] False positive on non-Linux */
239  case ECOMM:
240  return "Communication error on send";
241  /* coverity[dead_error_condition] False positive on non-Linux */
242  case ELIBACC:
243  return "Can not access a needed shared library";
244  /* coverity[dead_error_condition] False positive on non-Linux */
245  case EREMOTEIO:
246  return "Remote I/O error";
247  /* coverity[dead_error_condition] False positive on non-Linux */
248  case EUNATCH:
249  return "Protocol driver not attached";
250  /* coverity[dead_error_condition] False positive on non-Linux */
251  case ENOKEY:
252  return "Required key not available";
253  }
254 
255  crm_err("Unknown error code: %d", rc);
256  return "Unknown error";
257 }
258 
259 const char *
261 {
262  switch (exit_code) {
263  case CRM_EX_OK: return "CRM_EX_OK";
264  case CRM_EX_ERROR: return "CRM_EX_ERROR";
265  case CRM_EX_INVALID_PARAM: return "CRM_EX_INVALID_PARAM";
266  case CRM_EX_UNIMPLEMENT_FEATURE: return "CRM_EX_UNIMPLEMENT_FEATURE";
267  case CRM_EX_INSUFFICIENT_PRIV: return "CRM_EX_INSUFFICIENT_PRIV";
268  case CRM_EX_NOT_INSTALLED: return "CRM_EX_NOT_INSTALLED";
269  case CRM_EX_NOT_CONFIGURED: return "CRM_EX_NOT_CONFIGURED";
270  case CRM_EX_NOT_RUNNING: return "CRM_EX_NOT_RUNNING";
271  case CRM_EX_USAGE: return "CRM_EX_USAGE";
272  case CRM_EX_DATAERR: return "CRM_EX_DATAERR";
273  case CRM_EX_NOINPUT: return "CRM_EX_NOINPUT";
274  case CRM_EX_NOUSER: return "CRM_EX_NOUSER";
275  case CRM_EX_NOHOST: return "CRM_EX_NOHOST";
276  case CRM_EX_UNAVAILABLE: return "CRM_EX_UNAVAILABLE";
277  case CRM_EX_SOFTWARE: return "CRM_EX_SOFTWARE";
278  case CRM_EX_OSERR: return "CRM_EX_OSERR";
279  case CRM_EX_OSFILE: return "CRM_EX_OSFILE";
280  case CRM_EX_CANTCREAT: return "CRM_EX_CANTCREAT";
281  case CRM_EX_IOERR: return "CRM_EX_IOERR";
282  case CRM_EX_TEMPFAIL: return "CRM_EX_TEMPFAIL";
283  case CRM_EX_PROTOCOL: return "CRM_EX_PROTOCOL";
284  case CRM_EX_NOPERM: return "CRM_EX_NOPERM";
285  case CRM_EX_CONFIG: return "CRM_EX_CONFIG";
286  case CRM_EX_FATAL: return "CRM_EX_FATAL";
287  case CRM_EX_PANIC: return "CRM_EX_PANIC";
288  case CRM_EX_DISCONNECT: return "CRM_EX_DISCONNECT";
289  case CRM_EX_DIGEST: return "CRM_EX_DIGEST";
290  case CRM_EX_NOSUCH: return "CRM_EX_NOSUCH";
291  case CRM_EX_QUORUM: return "CRM_EX_QUORUM";
292  case CRM_EX_UNSAFE: return "CRM_EX_UNSAFE";
293  case CRM_EX_EXISTS: return "CRM_EX_EXISTS";
294  case CRM_EX_MULTIPLE: return "CRM_EX_MULTIPLE";
295  case CRM_EX_EXPIRED: return "CRM_EX_EXPIRED";
296  case CRM_EX_NOT_YET_IN_EFFECT: return "CRM_EX_NOT_YET_IN_EFFECT";
297  case CRM_EX_INDETERMINATE: return "CRM_EX_INDETERMINATE";
298  case CRM_EX_OLD: return "CRM_EX_OLD";
299  case CRM_EX_TIMEOUT: return "CRM_EX_TIMEOUT";
300  case CRM_EX_MAX: return "CRM_EX_UNKNOWN";
301  }
302  return "CRM_EX_UNKNOWN";
303 }
304 
305 const char *
307 {
308  switch (exit_code) {
309  case CRM_EX_OK: return "OK";
310  case CRM_EX_ERROR: return "Error occurred";
311  case CRM_EX_INVALID_PARAM: return "Invalid parameter";
312  case CRM_EX_UNIMPLEMENT_FEATURE: return "Unimplemented";
313  case CRM_EX_INSUFFICIENT_PRIV: return "Insufficient privileges";
314  case CRM_EX_NOT_INSTALLED: return "Not installed";
315  case CRM_EX_NOT_CONFIGURED: return "Not configured";
316  case CRM_EX_NOT_RUNNING: return "Not running";
317  case CRM_EX_USAGE: return "Incorrect usage";
318  case CRM_EX_DATAERR: return "Invalid data given";
319  case CRM_EX_NOINPUT: return "Input file not available";
320  case CRM_EX_NOUSER: return "User does not exist";
321  case CRM_EX_NOHOST: return "Host does not exist";
322  case CRM_EX_UNAVAILABLE: return "Necessary service unavailable";
323  case CRM_EX_SOFTWARE: return "Internal software bug";
324  case CRM_EX_OSERR: return "Operating system error occurred";
325  case CRM_EX_OSFILE: return "System file not available";
326  case CRM_EX_CANTCREAT: return "Cannot create output file";
327  case CRM_EX_IOERR: return "I/O error occurred";
328  case CRM_EX_TEMPFAIL: return "Temporary failure, try again";
329  case CRM_EX_PROTOCOL: return "Protocol violated";
330  case CRM_EX_NOPERM: return "Insufficient privileges";
331  case CRM_EX_CONFIG: return "Invalid configuration";
332  case CRM_EX_FATAL: return "Fatal error occurred, will not respawn";
333  case CRM_EX_PANIC: return "System panic required";
334  case CRM_EX_DISCONNECT: return "Not connected";
335  case CRM_EX_DIGEST: return "Digest mismatch";
336  case CRM_EX_NOSUCH: return "No such object";
337  case CRM_EX_QUORUM: return "Quorum required";
338  case CRM_EX_UNSAFE: return "Operation not safe";
339  case CRM_EX_EXISTS: return "Requested item already exists";
340  case CRM_EX_MULTIPLE: return "Multiple items match request";
341  case CRM_EX_EXPIRED: return "Requested item has expired";
342  case CRM_EX_NOT_YET_IN_EFFECT: return "Requested item is not yet in effect";
343  case CRM_EX_INDETERMINATE: return "Could not determine status";
344  case CRM_EX_OLD: return "Update was older than existing configuration";
345  case CRM_EX_TIMEOUT: return "Timeout occurred";
346  case CRM_EX_MAX: return "Error occurred";
347  }
348  if (exit_code > 128) {
349  return "Interrupted by signal";
350  }
351  return "Unknown exit status";
352 }
353 
363 {
364  rc = abs(rc); // Convenience for functions that return -errno
365  if (rc == EOPNOTSUPP) {
366  rc = ENOTSUP; // Values are same on Linux, can't use both in case
367  }
368  switch (rc) {
369  case pcmk_ok:
370  return CRM_EX_OK;
371 
372  case pcmk_err_no_quorum:
373  return CRM_EX_QUORUM;
374 
375  case pcmk_err_old_data:
376  return CRM_EX_OLD;
377 
380  return CRM_EX_CONFIG;
381 
382  case pcmk_err_bad_nvpair:
383  return CRM_EX_INVALID_PARAM;
384 
385  case EACCES:
387 
388  case EBADF:
389  case EINVAL:
390  case EFAULT:
391  case ENOSYS:
392  case EOVERFLOW:
393  return CRM_EX_SOFTWARE;
394 
395  case EBADMSG:
396  case EMSGSIZE:
397  case ENOMSG:
398  case ENOPROTOOPT:
399  case EPROTO:
400  case EPROTONOSUPPORT:
401  case EPROTOTYPE:
402  return CRM_EX_PROTOCOL;
403 
404  case ECOMM:
405  case ENOMEM:
406  return CRM_EX_OSERR;
407 
408  case ECONNABORTED:
409  case ECONNREFUSED:
410  case ECONNRESET:
411  case ENOTCONN:
412  return CRM_EX_DISCONNECT;
413 
414  case EEXIST:
415  case pcmk_err_already:
416  return CRM_EX_EXISTS;
417 
418  case EIO:
419  return CRM_EX_IOERR;
420 
421  case ENOTSUP:
423 
424  case ENOTUNIQ:
425  case pcmk_err_multiple:
426  return CRM_EX_MULTIPLE;
427 
428  case ENXIO:
431  return CRM_EX_NOSUCH;
432 
433  case ETIME:
434  case ETIMEDOUT:
435  return CRM_EX_TIMEOUT;
436 
437  default:
438  return CRM_EX_ERROR;
439  }
440 }
441 
442 const char *
444 {
445  // See ftp://sources.redhat.com/pub/bzip2/docs/manual_3.html#SEC17
446  switch (rc) {
447  case BZ_OK:
448  case BZ_RUN_OK:
449  case BZ_FLUSH_OK:
450  case BZ_FINISH_OK:
451  case BZ_STREAM_END:
452  return "Ok";
453  case BZ_CONFIG_ERROR:
454  return "libbz2 has been improperly compiled on your platform";
455  case BZ_SEQUENCE_ERROR:
456  return "library functions called in the wrong order";
457  case BZ_PARAM_ERROR:
458  return "parameter is out of range or otherwise incorrect";
459  case BZ_MEM_ERROR:
460  return "memory allocation failed";
461  case BZ_DATA_ERROR:
462  return "data integrity error is detected during decompression";
463  case BZ_DATA_ERROR_MAGIC:
464  return "the compressed stream does not start with the correct magic bytes";
465  case BZ_IO_ERROR:
466  return "error reading or writing in the compressed file";
467  case BZ_UNEXPECTED_EOF:
468  return "compressed file finishes before the logical end of stream is detected";
469  case BZ_OUTBUFF_FULL:
470  return "output data will not fit into the buffer provided";
471  }
472  return "Unknown error";
473 }
474 
477 {
478  /* A compiler could theoretically use any type for crm_exit_t, but an int
479  * should always hold it, so cast to int to keep static analysis happy.
480  */
481  if ((((int) rc) < 0) || (((int) rc) > CRM_EX_MAX)) {
482  rc = CRM_EX_ERROR;
483  }
484 
486  crm_xml_cleanup();
487 
488  qb_log_fini();
489  crm_args_fini();
490 
491  if (crm_system_name) {
492  crm_info("Exiting %s " CRM_XS " with status %d", crm_system_name, rc);
493  free(crm_system_name);
494  } else {
495  crm_trace("Exiting with status %d", rc);
496  }
497 
498  exit(rc);
499 }
#define pcmk_err_old_data
Definition: results.h:64
#define pcmk_err_schema_validation
Definition: results.h:62
const char * pcmk_errorname(int rc)
Definition: results.c:26
#define pcmk_err_already
Definition: results.h:74
crm_exit_t crm_errno2exit(int rc)
Map an errno to a similar exit status.
Definition: results.c:362
const char * pcmk_strerror(int rc)
Definition: results.c:188
#define ETIME
Definition: portability.h:162
const char * bz2_strerror(int rc)
Definition: results.c:443
#define pcmk_err_no_quorum
Definition: results.h:61
#define pcmk_err_schema_unchanged
Definition: results.h:70
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
Definition: results.c:476
#define ENOSTR
Definition: portability.h:170
void crm_xml_cleanup(void)
Definition: xml.c:4217
#define EKEYREJECTED
Definition: portability.h:174
#define pcmk_err_transform_failed
Definition: results.h:63
#define EREMOTEIO
Definition: portability.h:146
#define pcmk_err_node_unknown
Definition: results.h:73
#define pcmk_err_generic
Definition: results.h:60
void mainloop_cleanup(void)
Definition: mainloop.c:460
char * crm_system_name
Definition: utils.c:61
enum crm_exit_e crm_exit_t
char * strerror(int errnum)
#define pcmk_err_cib_backup
Definition: results.h:68
Wrappers for and extensions to glib mainloop.
#define pcmk_err_cib_save
Definition: results.h:69
#define pcmk_err_diff_failed
Definition: results.h:65
void crm_args_fini(void)
Definition: utils.c:192
const char * crm_exit_str(crm_exit_t exit_code)
Definition: results.c:306
#define PCMK_ERROR_OFFSET
Definition: results.h:58
#define pcmk_err_multiple
Definition: results.h:72
#define crm_trace(fmt, args...)
Definition: logging.h:246
Wrappers for and extensions to libxml2.
#define ECOMM
Definition: portability.h:138
#define pcmk_err_cib_modified
Definition: results.h:67
#define ENOSR
Definition: portability.h:166
#define ENOKEY
Definition: portability.h:154
#define CRM_XS
Definition: logging.h:34
#define ELIBACC
Definition: portability.h:142
#define EUNATCH
Definition: portability.h:150
#define ENODATA
Definition: portability.h:158
#define pcmk_err_diff_resync
Definition: results.h:66
#define crm_err(fmt, args...)
Definition: logging.h:240
#define pcmk_err_unknown_format
Definition: results.h:76
#define ENOTUNIQ
Definition: portability.h:134
#define pcmk_ok
Definition: results.h:57
#define pcmk_err_bad_nvpair
Definition: results.h:75
#define pcmk_err_cib_corrupt
Definition: results.h:71
#define crm_info(fmt, args...)
Definition: logging.h:243
const char * crm_exit_name(crm_exit_t exit_code)
Definition: results.c:260