pacemaker  2.1.0-7c3f660
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-2020 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 G_DEFINE_QUARK(pcmk-rc-error-quark, pcmk__rc_error)
26 G_DEFINE_QUARK(pcmk-exitc-error-quark, pcmk__exitc_error)
27 
28 // @COMPAT Legacy function return codes
29 
31 const char *
33 {
34  rc = abs(rc);
35  switch (rc) {
36  case pcmk_err_generic: return "pcmk_err_generic";
37  case pcmk_err_no_quorum: return "pcmk_err_no_quorum";
38  case pcmk_err_schema_validation: return "pcmk_err_schema_validation";
39  case pcmk_err_transform_failed: return "pcmk_err_transform_failed";
40  case pcmk_err_old_data: return "pcmk_err_old_data";
41  case pcmk_err_diff_failed: return "pcmk_err_diff_failed";
42  case pcmk_err_diff_resync: return "pcmk_err_diff_resync";
43  case pcmk_err_cib_modified: return "pcmk_err_cib_modified";
44  case pcmk_err_cib_backup: return "pcmk_err_cib_backup";
45  case pcmk_err_cib_save: return "pcmk_err_cib_save";
46  case pcmk_err_cib_corrupt: return "pcmk_err_cib_corrupt";
47  case pcmk_err_multiple: return "pcmk_err_multiple";
48  case pcmk_err_node_unknown: return "pcmk_err_node_unknown";
49  case pcmk_err_already: return "pcmk_err_already";
50  case pcmk_err_bad_nvpair: return "pcmk_err_bad_nvpair";
51  case pcmk_err_unknown_format: return "pcmk_err_unknown_format";
52  default: return pcmk_rc_name(rc); // system errno
53  }
54 }
55 
57 const char *
59 {
60  if (rc == 0) {
61  return "OK";
62  }
63 
64  rc = abs(rc);
65 
66  // Of course rc > 0 ... unless someone passed INT_MIN as rc
67  if ((rc > 0) && (rc < PCMK_ERROR_OFFSET)) {
68  return strerror(rc);
69  }
70 
71  switch (rc) {
72  case pcmk_err_generic:
73  return "Generic Pacemaker error";
74  case pcmk_err_no_quorum:
75  return "Operation requires quorum";
77  return "Update does not conform to the configured schema";
79  return "Schema transform failed";
80  case pcmk_err_old_data:
81  return "Update was older than existing configuration";
83  return "Application of an update diff failed";
85  return "Application of an update diff failed, requesting a full refresh";
87  return "The on-disk configuration was manually modified";
89  return "Could not archive the previous configuration";
90  case pcmk_err_cib_save:
91  return "Could not save the new configuration to disk";
93  return "Could not parse on-disk configuration";
94  case pcmk_err_multiple:
95  return "Resource active on multiple nodes";
97  return "Node not found";
98  case pcmk_err_already:
99  return "Situation already as requested";
100  case pcmk_err_bad_nvpair:
101  return "Bad name/value pair given";
103  return "Schema is already the latest available";
105  return "Unknown output format";
106 
107  /* The following cases will only be hit on systems for which they are non-standard */
108  /* coverity[dead_error_condition] False positive on non-Linux */
109  case ENOTUNIQ:
110  return "Name not unique on network";
111  /* coverity[dead_error_condition] False positive on non-Linux */
112  case ECOMM:
113  return "Communication error on send";
114  /* coverity[dead_error_condition] False positive on non-Linux */
115  case ELIBACC:
116  return "Can not access a needed shared library";
117  /* coverity[dead_error_condition] False positive on non-Linux */
118  case EREMOTEIO:
119  return "Remote I/O error";
120  /* coverity[dead_error_condition] False positive on non-Linux */
121  case EUNATCH:
122  return "Protocol driver not attached";
123  /* coverity[dead_error_condition] False positive on non-Linux */
124  case ENOKEY:
125  return "Required key not available";
126  }
127  crm_err("Unknown error code: %d", rc);
128  return "Unknown error";
129 }
130 
131 // Standard Pacemaker API return codes
132 
133 /* This array is used only for nonzero values of pcmk_rc_e. Its values must be
134  * kept in the exact reverse order of the enum value numbering (i.e. add new
135  * values to the end of the array).
136  */
137 static struct pcmk__rc_info {
138  const char *name;
139  const char *desc;
140  int legacy_rc;
141 } pcmk__rcs[] = {
142  { "pcmk_rc_error",
143  "Error",
145  },
146  { "pcmk_rc_unknown_format",
147  "Unknown output format",
149  },
150  { "pcmk_rc_bad_nvpair",
151  "Bad name/value pair given",
153  },
154  { "pcmk_rc_already",
155  "Already in requested state",
157  },
158  { "pcmk_rc_node_unknown",
159  "Node not found",
161  },
162  { "pcmk_rc_multiple",
163  "Resource active on multiple nodes",
165  },
166  { "pcmk_rc_cib_corrupt",
167  "Could not parse on-disk configuration",
169  },
170  { "pcmk_rc_cib_save",
171  "Could not save new configuration to disk",
173  },
174  { "pcmk_rc_cib_backup",
175  "Could not archive previous configuration",
177  },
178  { "pcmk_rc_cib_modified",
179  "On-disk configuration was manually modified",
181  },
182  { "pcmk_rc_diff_resync",
183  "Application of update diff failed, requesting full refresh",
185  },
186  { "pcmk_rc_diff_failed",
187  "Application of update diff failed",
189  },
190  { "pcmk_rc_old_data",
191  "Update was older than existing configuration",
193  },
194  { "pcmk_rc_transform_failed",
195  "Schema transform failed",
197  },
198  { "pcmk_rc_schema_unchanged",
199  "Schema is already the latest available",
201  },
202  { "pcmk_rc_schema_validation",
203  "Update does not conform to the configured schema",
205  },
206  { "pcmk_rc_no_quorum",
207  "Operation requires quorum",
209  },
210  { "pcmk_rc_ipc_pid_only",
211  "IPC server process is active but not accepting connections",
213  },
214  { "pcmk_rc_ipc_unresponsive",
215  "IPC server is unresponsive",
217  },
218  { "pcmk_rc_ipc_unauthorized",
219  "IPC server is blocked by unauthorized process",
221  },
222  { "pcmk_rc_op_unsatisifed",
223  "Not applicable under current conditions",
225  },
226  { "pcmk_rc_undetermined",
227  "Result undetermined",
229  },
230  { "pcmk_rc_before_range",
231  "Result occurs before given range",
233  },
234  { "pcmk_rc_within_range",
235  "Result occurs within given range",
237  },
238  { "pcmk_rc_after_range",
239  "Result occurs after given range",
241  },
242  { "pcmk_rc_no_output",
243  "Output message produced no output",
245  },
246  { "pcmk_rc_no_input",
247  "Input file not available",
249  },
250  { "pcmk_rc_underflow",
251  "Value too small to be stored in data type",
253  }
254 };
255 
256 #define PCMK__N_RC (sizeof(pcmk__rcs) / sizeof(struct pcmk__rc_info))
257 
265 const char *
267 {
268  if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < PCMK__N_RC)) {
269  return pcmk__rcs[pcmk_rc_error - rc].name;
270  }
271  switch (rc) {
272  case pcmk_rc_ok: return "pcmk_rc_ok";
273  case E2BIG: return "E2BIG";
274  case EACCES: return "EACCES";
275  case EADDRINUSE: return "EADDRINUSE";
276  case EADDRNOTAVAIL: return "EADDRNOTAVAIL";
277  case EAFNOSUPPORT: return "EAFNOSUPPORT";
278  case EAGAIN: return "EAGAIN";
279  case EALREADY: return "EALREADY";
280  case EBADF: return "EBADF";
281  case EBADMSG: return "EBADMSG";
282  case EBUSY: return "EBUSY";
283  case ECANCELED: return "ECANCELED";
284  case ECHILD: return "ECHILD";
285  case ECOMM: return "ECOMM";
286  case ECONNABORTED: return "ECONNABORTED";
287  case ECONNREFUSED: return "ECONNREFUSED";
288  case ECONNRESET: return "ECONNRESET";
289  /* case EDEADLK: return "EDEADLK"; */
290  case EDESTADDRREQ: return "EDESTADDRREQ";
291  case EDOM: return "EDOM";
292  case EDQUOT: return "EDQUOT";
293  case EEXIST: return "EEXIST";
294  case EFAULT: return "EFAULT";
295  case EFBIG: return "EFBIG";
296  case EHOSTDOWN: return "EHOSTDOWN";
297  case EHOSTUNREACH: return "EHOSTUNREACH";
298  case EIDRM: return "EIDRM";
299  case EILSEQ: return "EILSEQ";
300  case EINPROGRESS: return "EINPROGRESS";
301  case EINTR: return "EINTR";
302  case EINVAL: return "EINVAL";
303  case EIO: return "EIO";
304  case EISCONN: return "EISCONN";
305  case EISDIR: return "EISDIR";
306  case ELIBACC: return "ELIBACC";
307  case ELOOP: return "ELOOP";
308  case EMFILE: return "EMFILE";
309  case EMLINK: return "EMLINK";
310  case EMSGSIZE: return "EMSGSIZE";
311 #ifdef EMULTIHOP // Not available on OpenBSD
312  case EMULTIHOP: return "EMULTIHOP";
313 #endif
314  case ENAMETOOLONG: return "ENAMETOOLONG";
315  case ENETDOWN: return "ENETDOWN";
316  case ENETRESET: return "ENETRESET";
317  case ENETUNREACH: return "ENETUNREACH";
318  case ENFILE: return "ENFILE";
319  case ENOBUFS: return "ENOBUFS";
320  case ENODATA: return "ENODATA";
321  case ENODEV: return "ENODEV";
322  case ENOENT: return "ENOENT";
323  case ENOEXEC: return "ENOEXEC";
324  case ENOKEY: return "ENOKEY";
325  case ENOLCK: return "ENOLCK";
326 #ifdef ENOLINK // Not available on OpenBSD
327  case ENOLINK: return "ENOLINK";
328 #endif
329  case ENOMEM: return "ENOMEM";
330  case ENOMSG: return "ENOMSG";
331  case ENOPROTOOPT: return "ENOPROTOOPT";
332  case ENOSPC: return "ENOSPC";
333  case ENOSR: return "ENOSR";
334  case ENOSTR: return "ENOSTR";
335  case ENOSYS: return "ENOSYS";
336  case ENOTBLK: return "ENOTBLK";
337  case ENOTCONN: return "ENOTCONN";
338  case ENOTDIR: return "ENOTDIR";
339  case ENOTEMPTY: return "ENOTEMPTY";
340  case ENOTSOCK: return "ENOTSOCK";
341 #if ENOTSUP != EOPNOTSUPP
342  case ENOTSUP: return "ENOTSUP";
343 #endif
344  case ENOTTY: return "ENOTTY";
345  case ENOTUNIQ: return "ENOTUNIQ";
346  case ENXIO: return "ENXIO";
347  case EOPNOTSUPP: return "EOPNOTSUPP";
348  case EOVERFLOW: return "EOVERFLOW";
349  case EPERM: return "EPERM";
350  case EPFNOSUPPORT: return "EPFNOSUPPORT";
351  case EPIPE: return "EPIPE";
352  case EPROTO: return "EPROTO";
353  case EPROTONOSUPPORT: return "EPROTONOSUPPORT";
354  case EPROTOTYPE: return "EPROTOTYPE";
355  case ERANGE: return "ERANGE";
356  case EREMOTE: return "EREMOTE";
357  case EREMOTEIO: return "EREMOTEIO";
358  case EROFS: return "EROFS";
359  case ESHUTDOWN: return "ESHUTDOWN";
360  case ESPIPE: return "ESPIPE";
361  case ESOCKTNOSUPPORT: return "ESOCKTNOSUPPORT";
362  case ESRCH: return "ESRCH";
363  case ESTALE: return "ESTALE";
364  case ETIME: return "ETIME";
365  case ETIMEDOUT: return "ETIMEDOUT";
366  case ETXTBSY: return "ETXTBSY";
367  case EUNATCH: return "EUNATCH";
368  case EUSERS: return "EUSERS";
369  /* case EWOULDBLOCK: return "EWOULDBLOCK"; */
370  case EXDEV: return "EXDEV";
371 
372 #ifdef EBADE // Not available on OS X
373  case EBADE: return "EBADE";
374  case EBADFD: return "EBADFD";
375  case EBADSLT: return "EBADSLT";
376  case EDEADLOCK: return "EDEADLOCK";
377  case EBADR: return "EBADR";
378  case EBADRQC: return "EBADRQC";
379  case ECHRNG: return "ECHRNG";
380 #ifdef EISNAM // Not available on OS X, Illumos, Solaris
381  case EISNAM: return "EISNAM";
382  case EKEYEXPIRED: return "EKEYEXPIRED";
383  case EKEYREJECTED: return "EKEYREJECTED";
384  case EKEYREVOKED: return "EKEYREVOKED";
385 #endif
386  case EL2HLT: return "EL2HLT";
387  case EL2NSYNC: return "EL2NSYNC";
388  case EL3HLT: return "EL3HLT";
389  case EL3RST: return "EL3RST";
390  case ELIBBAD: return "ELIBBAD";
391  case ELIBMAX: return "ELIBMAX";
392  case ELIBSCN: return "ELIBSCN";
393  case ELIBEXEC: return "ELIBEXEC";
394 #ifdef ENOMEDIUM // Not available on OS X, Illumos, Solaris
395  case ENOMEDIUM: return "ENOMEDIUM";
396  case EMEDIUMTYPE: return "EMEDIUMTYPE";
397 #endif
398  case ENONET: return "ENONET";
399  case ENOPKG: return "ENOPKG";
400  case EREMCHG: return "EREMCHG";
401  case ERESTART: return "ERESTART";
402  case ESTRPIPE: return "ESTRPIPE";
403 #ifdef EUCLEAN // Not available on OS X, Illumos, Solaris
404  case EUCLEAN: return "EUCLEAN";
405 #endif
406  case EXFULL: return "EXFULL";
407 #endif // EBADE
408  default: return "Unknown";
409  }
410 }
411 
419 const char *
421 {
422  if (rc == pcmk_rc_ok) {
423  return "OK";
424  }
425  if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < PCMK__N_RC)) {
426  return pcmk__rcs[pcmk_rc_error - rc].desc;
427  }
428  if (rc < 0) {
429  return "Unknown error";
430  }
431  return strerror(rc);
432 }
433 
434 // This returns negative values for errors
436 int
438 {
439  if (rc >= 0) {
440  return -rc; // OK or system errno
441  }
442  if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < PCMK__N_RC)) {
443  return pcmk__rcs[pcmk_rc_error - rc].legacy_rc;
444  }
445  return -pcmk_err_generic;
446 }
447 
449 int
450 pcmk_legacy2rc(int legacy_rc)
451 {
452  legacy_rc = abs(legacy_rc);
453  switch (legacy_rc) {
458  case pcmk_err_old_data: return pcmk_rc_old_data;
463  case pcmk_err_cib_save: return pcmk_rc_cib_save;
465  case pcmk_err_multiple: return pcmk_rc_multiple;
467  case pcmk_err_already: return pcmk_rc_already;
470  case pcmk_err_generic: return pcmk_rc_error;
471  case pcmk_ok: return pcmk_rc_ok;
472  default: return legacy_rc; // system errno
473  }
474 }
475 
476 // Exit status codes
477 
478 const char *
480 {
481  switch (exit_code) {
482  case CRM_EX_OK: return "CRM_EX_OK";
483  case CRM_EX_ERROR: return "CRM_EX_ERROR";
484  case CRM_EX_INVALID_PARAM: return "CRM_EX_INVALID_PARAM";
485  case CRM_EX_UNIMPLEMENT_FEATURE: return "CRM_EX_UNIMPLEMENT_FEATURE";
486  case CRM_EX_INSUFFICIENT_PRIV: return "CRM_EX_INSUFFICIENT_PRIV";
487  case CRM_EX_NOT_INSTALLED: return "CRM_EX_NOT_INSTALLED";
488  case CRM_EX_NOT_CONFIGURED: return "CRM_EX_NOT_CONFIGURED";
489  case CRM_EX_NOT_RUNNING: return "CRM_EX_NOT_RUNNING";
490  case CRM_EX_USAGE: return "CRM_EX_USAGE";
491  case CRM_EX_DATAERR: return "CRM_EX_DATAERR";
492  case CRM_EX_NOINPUT: return "CRM_EX_NOINPUT";
493  case CRM_EX_NOUSER: return "CRM_EX_NOUSER";
494  case CRM_EX_NOHOST: return "CRM_EX_NOHOST";
495  case CRM_EX_UNAVAILABLE: return "CRM_EX_UNAVAILABLE";
496  case CRM_EX_SOFTWARE: return "CRM_EX_SOFTWARE";
497  case CRM_EX_OSERR: return "CRM_EX_OSERR";
498  case CRM_EX_OSFILE: return "CRM_EX_OSFILE";
499  case CRM_EX_CANTCREAT: return "CRM_EX_CANTCREAT";
500  case CRM_EX_IOERR: return "CRM_EX_IOERR";
501  case CRM_EX_TEMPFAIL: return "CRM_EX_TEMPFAIL";
502  case CRM_EX_PROTOCOL: return "CRM_EX_PROTOCOL";
503  case CRM_EX_NOPERM: return "CRM_EX_NOPERM";
504  case CRM_EX_CONFIG: return "CRM_EX_CONFIG";
505  case CRM_EX_FATAL: return "CRM_EX_FATAL";
506  case CRM_EX_PANIC: return "CRM_EX_PANIC";
507  case CRM_EX_DISCONNECT: return "CRM_EX_DISCONNECT";
508  case CRM_EX_DIGEST: return "CRM_EX_DIGEST";
509  case CRM_EX_NOSUCH: return "CRM_EX_NOSUCH";
510  case CRM_EX_QUORUM: return "CRM_EX_QUORUM";
511  case CRM_EX_UNSAFE: return "CRM_EX_UNSAFE";
512  case CRM_EX_EXISTS: return "CRM_EX_EXISTS";
513  case CRM_EX_MULTIPLE: return "CRM_EX_MULTIPLE";
514  case CRM_EX_EXPIRED: return "CRM_EX_EXPIRED";
515  case CRM_EX_NOT_YET_IN_EFFECT: return "CRM_EX_NOT_YET_IN_EFFECT";
516  case CRM_EX_INDETERMINATE: return "CRM_EX_INDETERMINATE";
517  case CRM_EX_UNSATISFIED: return "CRM_EX_UNSATISFIED";
518  case CRM_EX_OLD: return "CRM_EX_OLD";
519  case CRM_EX_TIMEOUT: return "CRM_EX_TIMEOUT";
520  case CRM_EX_MAX: return "CRM_EX_UNKNOWN";
521  }
522  return "CRM_EX_UNKNOWN";
523 }
524 
525 const char *
527 {
528  switch (exit_code) {
529  case CRM_EX_OK: return "OK";
530  case CRM_EX_ERROR: return "Error occurred";
531  case CRM_EX_INVALID_PARAM: return "Invalid parameter";
532  case CRM_EX_UNIMPLEMENT_FEATURE: return "Unimplemented";
533  case CRM_EX_INSUFFICIENT_PRIV: return "Insufficient privileges";
534  case CRM_EX_NOT_INSTALLED: return "Not installed";
535  case CRM_EX_NOT_CONFIGURED: return "Not configured";
536  case CRM_EX_NOT_RUNNING: return "Not running";
537  case CRM_EX_USAGE: return "Incorrect usage";
538  case CRM_EX_DATAERR: return "Invalid data given";
539  case CRM_EX_NOINPUT: return "Input file not available";
540  case CRM_EX_NOUSER: return "User does not exist";
541  case CRM_EX_NOHOST: return "Host does not exist";
542  case CRM_EX_UNAVAILABLE: return "Necessary service unavailable";
543  case CRM_EX_SOFTWARE: return "Internal software bug";
544  case CRM_EX_OSERR: return "Operating system error occurred";
545  case CRM_EX_OSFILE: return "System file not available";
546  case CRM_EX_CANTCREAT: return "Cannot create output file";
547  case CRM_EX_IOERR: return "I/O error occurred";
548  case CRM_EX_TEMPFAIL: return "Temporary failure, try again";
549  case CRM_EX_PROTOCOL: return "Protocol violated";
550  case CRM_EX_NOPERM: return "Insufficient privileges";
551  case CRM_EX_CONFIG: return "Invalid configuration";
552  case CRM_EX_FATAL: return "Fatal error occurred, will not respawn";
553  case CRM_EX_PANIC: return "System panic required";
554  case CRM_EX_DISCONNECT: return "Not connected";
555  case CRM_EX_DIGEST: return "Digest mismatch";
556  case CRM_EX_NOSUCH: return "No such object";
557  case CRM_EX_QUORUM: return "Quorum required";
558  case CRM_EX_UNSAFE: return "Operation not safe";
559  case CRM_EX_EXISTS: return "Requested item already exists";
560  case CRM_EX_MULTIPLE: return "Multiple items match request";
561  case CRM_EX_EXPIRED: return "Requested item has expired";
562  case CRM_EX_NOT_YET_IN_EFFECT: return "Requested item is not yet in effect";
563  case CRM_EX_INDETERMINATE: return "Could not determine status";
564  case CRM_EX_UNSATISFIED: return "Not applicable under current conditions";
565  case CRM_EX_OLD: return "Update was older than existing configuration";
566  case CRM_EX_TIMEOUT: return "Timeout occurred";
567  case CRM_EX_MAX: return "Error occurred";
568  }
569  if ((exit_code > 128) && (exit_code < CRM_EX_MAX)) {
570  return "Interrupted by signal";
571  }
572  return "Unknown exit status";
573 }
574 
578 {
579  rc = abs(rc); // Convenience for functions that return -errno
580  switch (rc) {
581  case pcmk_ok:
582  return CRM_EX_OK;
583 
584  case pcmk_err_no_quorum:
585  return CRM_EX_QUORUM;
586 
587  case pcmk_err_old_data:
588  return CRM_EX_OLD;
589 
592  return CRM_EX_CONFIG;
593 
594  case pcmk_err_bad_nvpair:
595  return CRM_EX_INVALID_PARAM;
596 
597  case pcmk_err_already:
598  return CRM_EX_EXISTS;
599 
600  case pcmk_err_multiple:
601  return CRM_EX_MULTIPLE;
602 
605  return CRM_EX_NOSUCH;
606 
607  default:
608  return pcmk_rc2exitc(rc); // system errno
609  }
610 }
611 
621 {
622  switch (rc) {
623  case pcmk_rc_ok:
624  return CRM_EX_OK;
625 
626  case pcmk_rc_no_quorum:
627  return CRM_EX_QUORUM;
628 
629  case pcmk_rc_old_data:
630  return CRM_EX_OLD;
631 
634  return CRM_EX_CONFIG;
635 
636  case pcmk_rc_bad_nvpair:
637  return CRM_EX_INVALID_PARAM;
638 
639  case EACCES:
641 
642  case EBADF:
643  case EINVAL:
644  case EFAULT:
645  case ENOSYS:
646  case EOVERFLOW:
647  case pcmk_rc_underflow:
648  return CRM_EX_SOFTWARE;
649 
650  case EBADMSG:
651  case EMSGSIZE:
652  case ENOMSG:
653  case ENOPROTOOPT:
654  case EPROTO:
655  case EPROTONOSUPPORT:
656  case EPROTOTYPE:
657  return CRM_EX_PROTOCOL;
658 
659  case ECOMM:
660  case ENOMEM:
661  return CRM_EX_OSERR;
662 
663  case ECONNABORTED:
664  case ECONNREFUSED:
665  case ECONNRESET:
666  case ENOTCONN:
667  return CRM_EX_DISCONNECT;
668 
669  case EEXIST:
670  case pcmk_rc_already:
671  return CRM_EX_EXISTS;
672 
673  case EIO:
674  case pcmk_rc_no_output:
675  return CRM_EX_IOERR;
676 
677  case ENOTSUP:
678 #if EOPNOTSUPP != ENOTSUP
679  case EOPNOTSUPP:
680 #endif
682 
683  case ENOTUNIQ:
684  case pcmk_rc_multiple:
685  return CRM_EX_MULTIPLE;
686 
687  case ENXIO:
690  return CRM_EX_NOSUCH;
691 
692  case ETIME:
693  case ETIMEDOUT:
694  return CRM_EX_TIMEOUT;
695 
696  case EAGAIN:
697  case EBUSY:
698  return CRM_EX_UNSATISFIED;
699 
702 
703  case pcmk_rc_after_range:
704  return CRM_EX_EXPIRED;
705 
707  return CRM_EX_INDETERMINATE;
708 
710  return CRM_EX_UNSATISFIED;
711 
713  return CRM_EX_OK;
714 
715  case pcmk_rc_no_input:
716  return CRM_EX_NOINPUT;
717 
718  default:
719  return CRM_EX_ERROR;
720  }
721 }
722 
723 // Other functions
724 
725 const char *
727 {
728  // See ftp://sources.redhat.com/pub/bzip2/docs/manual_3.html#SEC17
729  switch (rc) {
730  case BZ_OK:
731  case BZ_RUN_OK:
732  case BZ_FLUSH_OK:
733  case BZ_FINISH_OK:
734  case BZ_STREAM_END:
735  return "Ok";
736  case BZ_CONFIG_ERROR:
737  return "libbz2 has been improperly compiled on your platform";
738  case BZ_SEQUENCE_ERROR:
739  return "library functions called in the wrong order";
740  case BZ_PARAM_ERROR:
741  return "parameter is out of range or otherwise incorrect";
742  case BZ_MEM_ERROR:
743  return "memory allocation failed";
744  case BZ_DATA_ERROR:
745  return "data integrity error is detected during decompression";
746  case BZ_DATA_ERROR_MAGIC:
747  return "the compressed stream does not start with the correct magic bytes";
748  case BZ_IO_ERROR:
749  return "error reading or writing in the compressed file";
750  case BZ_UNEXPECTED_EOF:
751  return "compressed file finishes before the logical end of stream is detected";
752  case BZ_OUTBUFF_FULL:
753  return "output data will not fit into the buffer provided";
754  }
755  return "Unknown error";
756 }
757 
760 {
761  /* A compiler could theoretically use any type for crm_exit_t, but an int
762  * should always hold it, so cast to int to keep static analysis happy.
763  */
764  if ((((int) rc) < 0) || (((int) rc) > CRM_EX_MAX)) {
765  rc = CRM_EX_ERROR;
766  }
767 
769  crm_xml_cleanup();
770 
772 
773  if (crm_system_name) {
774  crm_info("Exiting %s " CRM_XS " with status %d", crm_system_name, rc);
775  free(crm_system_name);
776  } else {
777  crm_trace("Exiting with status %d", rc);
778  }
779  qb_log_fini(); // Don't log anything after this point
780 
781  exit(rc);
782 }
#define pcmk_err_old_data
Definition: results.h:74
#define pcmk_err_schema_validation
Definition: results.h:72
const char * pcmk_errorname(int rc)
Definition: results.c:32
#define pcmk_err_already
Definition: results.h:84
crm_exit_t crm_errno2exit(int rc)
Definition: results.c:577
const char * pcmk_strerror(int rc)
Definition: results.c:58
#define ETIME
Definition: portability.h:142
const char * bz2_strerror(int rc)
Definition: results.c:726
#define pcmk_err_no_quorum
Definition: results.h:71
#define pcmk_err_schema_unchanged
Definition: results.h:80
int pcmk_rc2legacy(int rc)
Definition: results.c:437
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
Definition: results.c:759
#define ENOSTR
Definition: portability.h:150
void crm_xml_cleanup(void)
Definition: xml.c:2853
#define EKEYREJECTED
Definition: portability.h:154
#define pcmk_err_transform_failed
Definition: results.h:73
crm_exit_t pcmk_rc2exitc(int rc)
Map a function return code to the most similar exit code.
Definition: results.c:620
#define EREMOTEIO
Definition: portability.h:126
#define pcmk_err_node_unknown
Definition: results.h:83
#define pcmk_err_generic
Definition: results.h:70
void mainloop_cleanup(void)
Definition: mainloop.c:429
char * crm_system_name
Definition: utils.c:54
enum crm_exit_e crm_exit_t
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Definition: results.c:420
char * strerror(int errnum)
#define pcmk_err_cib_backup
Definition: results.h:78
Wrappers for and extensions to glib mainloop.
#define pcmk_err_cib_save
Definition: results.h:79
#define pcmk_err_diff_failed
Definition: results.h:75
const char * crm_exit_str(crm_exit_t exit_code)
Definition: results.c:526
int rc
Definition: pcmk_fence.c:35
#define PCMK_ERROR_OFFSET
Definition: results.h:68
#define pcmk_err_multiple
Definition: results.h:82
#define crm_trace(fmt, args...)
Definition: logging.h:356
Wrappers for and extensions to libxml2.
#define ECOMM
Definition: portability.h:118
int pcmk_legacy2rc(int legacy_rc)
Definition: results.c:450
#define pcmk_err_cib_modified
Definition: results.h:77
#define ENOSR
Definition: portability.h:146
#define ENOKEY
Definition: portability.h:134
#define CRM_XS
Definition: logging.h:54
#define ELIBACC
Definition: portability.h:122
#define EUNATCH
Definition: portability.h:130
#define ENODATA
Definition: portability.h:138
#define pcmk_err_diff_resync
Definition: results.h:76
void pcmk__cli_option_cleanup(void)
Definition: options.c:39
const char * pcmk_rc_name(int rc)
Get a return code constant name as a string.
Definition: results.c:266
#define crm_err(fmt, args...)
Definition: logging.h:350
#define pcmk_err_unknown_format
Definition: results.h:91
#define ENOTUNIQ
Definition: portability.h:114
#define pcmk_ok
Definition: results.h:67
#define PCMK__N_RC
Definition: results.c:256
char * name
Definition: pcmk_fence.c:31
#define pcmk_err_bad_nvpair
Definition: results.h:90
#define pcmk_err_cib_corrupt
Definition: results.h:81
#define crm_info(fmt, args...)
Definition: logging.h:353
const char * crm_exit_name(crm_exit_t exit_code)
Definition: results.c:479