This source file includes following definitions.
- G_DEFINE_QUARK
- pcmk__result_bounds
- pcmk_errorname
- pcmk_strerror
- pcmk_rc_name
- pcmk_rc_str
- pcmk_rc2legacy
- pcmk_legacy2rc
- crm_exit_name
- crm_exit_str
- pcmk_rc2exitc
- pcmk_rc2ocf
- pcmk__gaierror2rc
- pcmk__bzlib2rc
- crm_exit
- pcmk__set_result
- G_GNUC_PRINTF
- pcmk__set_result_output
- pcmk__reset_result
- pcmk__copy_result
- bz2_strerror
- crm_errno2exit
1
2
3
4
5
6
7
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 <netdb.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <qb/qbdefs.h>
22
23 #include <crm/common/mainloop.h>
24 #include <crm/common/xml.h>
25
26 G_DEFINE_QUARK(pcmk-rc-error-quark, pcmk__rc_error)
27 G_DEFINE_QUARK(pcmk-exitc-error-quark, pcmk__exitc_error)
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 int
44 pcmk_result_get_strings(int code, enum pcmk_result_type type, const char **name,
45 const char **desc)
46 {
47 const char *code_name = NULL;
48 const char *code_desc = NULL;
49
50 switch (type) {
51 case pcmk_result_legacy:
52 code_name = pcmk_errorname(code);
53 code_desc = pcmk_strerror(code);
54 break;
55 case pcmk_result_rc:
56 code_name = pcmk_rc_name(code);
57 code_desc = pcmk_rc_str(code);
58 break;
59 case pcmk_result_exitcode:
60 code_name = crm_exit_name(code);
61 code_desc = crm_exit_str((crm_exit_t) code);
62 break;
63 default:
64 return pcmk_rc_undetermined;
65 }
66
67 if (name != NULL) {
68 *name = code_name;
69 }
70
71 if (desc != NULL) {
72 *desc = code_desc;
73 }
74 return pcmk_rc_ok;
75 }
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 int
94 pcmk__result_bounds(enum pcmk_result_type type, int *lower, int *upper)
95 {
96 CRM_ASSERT((lower != NULL) && (upper != NULL));
97
98 switch (type) {
99 case pcmk_result_legacy:
100 *lower = pcmk_ok;
101 *upper = 256;
102 break;
103 case pcmk_result_rc:
104 *lower = pcmk_rc_error - pcmk__n_rc + 1;
105 *upper = 256;
106 break;
107 case pcmk_result_exitcode:
108 *lower = CRM_EX_OK;
109 *upper = CRM_EX_MAX;
110 break;
111 default:
112 *lower = 0;
113 *upper = -1;
114 return pcmk_rc_undetermined;
115 }
116 return pcmk_rc_ok;
117 }
118
119
120
121
122 const char *
123 pcmk_errorname(int rc)
124 {
125 rc = abs(rc);
126 switch (rc) {
127 case pcmk_err_generic: return "pcmk_err_generic";
128 case pcmk_err_no_quorum: return "pcmk_err_no_quorum";
129 case pcmk_err_schema_validation: return "pcmk_err_schema_validation";
130 case pcmk_err_transform_failed: return "pcmk_err_transform_failed";
131 case pcmk_err_old_data: return "pcmk_err_old_data";
132 case pcmk_err_diff_failed: return "pcmk_err_diff_failed";
133 case pcmk_err_diff_resync: return "pcmk_err_diff_resync";
134 case pcmk_err_cib_modified: return "pcmk_err_cib_modified";
135 case pcmk_err_cib_backup: return "pcmk_err_cib_backup";
136 case pcmk_err_cib_save: return "pcmk_err_cib_save";
137 case pcmk_err_cib_corrupt: return "pcmk_err_cib_corrupt";
138 case pcmk_err_multiple: return "pcmk_err_multiple";
139 case pcmk_err_node_unknown: return "pcmk_err_node_unknown";
140 case pcmk_err_already: return "pcmk_err_already";
141 case pcmk_err_bad_nvpair: return "pcmk_err_bad_nvpair";
142 case pcmk_err_unknown_format: return "pcmk_err_unknown_format";
143 default: return pcmk_rc_name(rc);
144 }
145 }
146
147
148 const char *
149 pcmk_strerror(int rc)
150 {
151 return pcmk_rc_str(pcmk_legacy2rc(rc));
152 }
153
154
155
156
157
158
159
160 static const struct pcmk__rc_info {
161 const char *name;
162 const char *desc;
163 int legacy_rc;
164 } pcmk__rcs[] = {
165 { "pcmk_rc_error",
166 "Error",
167 -pcmk_err_generic,
168 },
169 { "pcmk_rc_unknown_format",
170 "Unknown output format",
171 -pcmk_err_unknown_format,
172 },
173 { "pcmk_rc_bad_nvpair",
174 "Bad name/value pair given",
175 -pcmk_err_bad_nvpair,
176 },
177 { "pcmk_rc_already",
178 "Already in requested state",
179 -pcmk_err_already,
180 },
181 { "pcmk_rc_node_unknown",
182 "Node not found",
183 -pcmk_err_node_unknown,
184 },
185 { "pcmk_rc_multiple",
186 "Resource active on multiple nodes",
187 -pcmk_err_multiple,
188 },
189 { "pcmk_rc_cib_corrupt",
190 "Could not parse on-disk configuration",
191 -pcmk_err_cib_corrupt,
192 },
193 { "pcmk_rc_cib_save",
194 "Could not save new configuration to disk",
195 -pcmk_err_cib_save,
196 },
197 { "pcmk_rc_cib_backup",
198 "Could not archive previous configuration",
199 -pcmk_err_cib_backup,
200 },
201 { "pcmk_rc_cib_modified",
202 "On-disk configuration was manually modified",
203 -pcmk_err_cib_modified,
204 },
205 { "pcmk_rc_diff_resync",
206 "Application of update diff failed, requesting full refresh",
207 -pcmk_err_diff_resync,
208 },
209 { "pcmk_rc_diff_failed",
210 "Application of update diff failed",
211 -pcmk_err_diff_failed,
212 },
213 { "pcmk_rc_old_data",
214 "Update was older than existing configuration",
215 -pcmk_err_old_data,
216 },
217 { "pcmk_rc_transform_failed",
218 "Schema transform failed",
219 -pcmk_err_transform_failed,
220 },
221 { "pcmk_rc_schema_unchanged",
222 "Schema is already the latest available",
223 -pcmk_err_schema_unchanged,
224 },
225 { "pcmk_rc_schema_validation",
226 "Update does not conform to the configured schema",
227 -pcmk_err_schema_validation,
228 },
229 { "pcmk_rc_no_quorum",
230 "Operation requires quorum",
231 -pcmk_err_no_quorum,
232 },
233 { "pcmk_rc_ipc_unauthorized",
234 "IPC server is blocked by unauthorized process",
235 -pcmk_err_generic,
236 },
237 { "pcmk_rc_ipc_unresponsive",
238 "IPC server is unresponsive",
239 -pcmk_err_generic,
240 },
241 { "pcmk_rc_ipc_pid_only",
242 "IPC server process is active but not accepting connections",
243 -pcmk_err_generic,
244 },
245 { "pcmk_rc_op_unsatisfied",
246 "Not applicable under current conditions",
247 -pcmk_err_generic,
248 },
249 { "pcmk_rc_undetermined",
250 "Result undetermined",
251 -pcmk_err_generic,
252 },
253 { "pcmk_rc_before_range",
254 "Result occurs before given range",
255 -pcmk_err_generic,
256 },
257 { "pcmk_rc_within_range",
258 "Result occurs within given range",
259 -pcmk_err_generic,
260 },
261 { "pcmk_rc_after_range",
262 "Result occurs after given range",
263 -pcmk_err_generic,
264 },
265 { "pcmk_rc_no_output",
266 "Output message produced no output",
267 -pcmk_err_generic,
268 },
269 { "pcmk_rc_no_input",
270 "Input file not available",
271 -pcmk_err_generic,
272 },
273 { "pcmk_rc_underflow",
274 "Value too small to be stored in data type",
275 -pcmk_err_generic,
276 },
277 { "pcmk_rc_dot_error",
278 "Error writing dot(1) file",
279 -pcmk_err_generic,
280 },
281 { "pcmk_rc_graph_error",
282 "Error writing graph file",
283 -pcmk_err_generic,
284 },
285 { "pcmk_rc_invalid_transition",
286 "Cluster simulation produced invalid transition",
287 -pcmk_err_generic,
288 },
289 { "pcmk_rc_unpack_error",
290 "Unable to parse CIB XML",
291 -pcmk_err_generic,
292 },
293 { "pcmk_rc_duplicate_id",
294 "Two or more XML elements have the same ID",
295 -pcmk_err_generic,
296 },
297 { "pcmk_rc_disabled",
298 "Disabled",
299 -pcmk_err_generic,
300 },
301 { "pcmk_rc_bad_input",
302 "Bad input value provided",
303 -pcmk_err_generic,
304 },
305 { "pcmk_rc_bad_xml_patch",
306 "Bad XML patch format",
307 -pcmk_err_generic,
308 },
309 { "pcmk_rc_no_transaction",
310 "No active transaction found",
311 -pcmk_err_generic,
312 },
313 { "pcmk_rc_ns_resolution",
314 "Nameserver resolution error",
315 -pcmk_err_generic,
316 },
317 { "pcmk_rc_compression",
318 "Compression/decompression error",
319 -pcmk_err_generic,
320 },
321 };
322
323
324
325
326
327
328
329
330
331 const size_t pcmk__n_rc = PCMK__NELEM(pcmk__rcs);
332
333
334
335
336
337
338
339
340 const char *
341 pcmk_rc_name(int rc)
342 {
343 if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < pcmk__n_rc)) {
344 return pcmk__rcs[pcmk_rc_error - rc].name;
345 }
346 switch (rc) {
347 case pcmk_rc_ok: return "pcmk_rc_ok";
348 case E2BIG: return "E2BIG";
349 case EACCES: return "EACCES";
350 case EADDRINUSE: return "EADDRINUSE";
351 case EADDRNOTAVAIL: return "EADDRNOTAVAIL";
352 case EAFNOSUPPORT: return "EAFNOSUPPORT";
353 case EAGAIN: return "EAGAIN";
354 case EALREADY: return "EALREADY";
355 case EBADF: return "EBADF";
356 case EBADMSG: return "EBADMSG";
357 case EBUSY: return "EBUSY";
358 case ECANCELED: return "ECANCELED";
359 case ECHILD: return "ECHILD";
360 case ECOMM: return "ECOMM";
361 case ECONNABORTED: return "ECONNABORTED";
362 case ECONNREFUSED: return "ECONNREFUSED";
363 case ECONNRESET: return "ECONNRESET";
364
365 case EDESTADDRREQ: return "EDESTADDRREQ";
366 case EDOM: return "EDOM";
367 case EDQUOT: return "EDQUOT";
368 case EEXIST: return "EEXIST";
369 case EFAULT: return "EFAULT";
370 case EFBIG: return "EFBIG";
371 case EHOSTDOWN: return "EHOSTDOWN";
372 case EHOSTUNREACH: return "EHOSTUNREACH";
373 case EIDRM: return "EIDRM";
374 case EILSEQ: return "EILSEQ";
375 case EINPROGRESS: return "EINPROGRESS";
376 case EINTR: return "EINTR";
377 case EINVAL: return "EINVAL";
378 case EIO: return "EIO";
379 case EISCONN: return "EISCONN";
380 case EISDIR: return "EISDIR";
381 case ELIBACC: return "ELIBACC";
382 case ELOOP: return "ELOOP";
383 case EMFILE: return "EMFILE";
384 case EMLINK: return "EMLINK";
385 case EMSGSIZE: return "EMSGSIZE";
386 #ifdef EMULTIHOP
387 case EMULTIHOP: return "EMULTIHOP";
388 #endif
389 case ENAMETOOLONG: return "ENAMETOOLONG";
390 case ENETDOWN: return "ENETDOWN";
391 case ENETRESET: return "ENETRESET";
392 case ENETUNREACH: return "ENETUNREACH";
393 case ENFILE: return "ENFILE";
394 case ENOBUFS: return "ENOBUFS";
395 case ENODATA: return "ENODATA";
396 case ENODEV: return "ENODEV";
397 case ENOENT: return "ENOENT";
398 case ENOEXEC: return "ENOEXEC";
399 case ENOKEY: return "ENOKEY";
400 case ENOLCK: return "ENOLCK";
401 #ifdef ENOLINK
402 case ENOLINK: return "ENOLINK";
403 #endif
404 case ENOMEM: return "ENOMEM";
405 case ENOMSG: return "ENOMSG";
406 case ENOPROTOOPT: return "ENOPROTOOPT";
407 case ENOSPC: return "ENOSPC";
408 #ifdef ENOSR
409 case ENOSR: return "ENOSR";
410 #endif
411 #ifdef ENOSTR
412 case ENOSTR: return "ENOSTR";
413 #endif
414 case ENOSYS: return "ENOSYS";
415 case ENOTBLK: return "ENOTBLK";
416 case ENOTCONN: return "ENOTCONN";
417 case ENOTDIR: return "ENOTDIR";
418 case ENOTEMPTY: return "ENOTEMPTY";
419 case ENOTSOCK: return "ENOTSOCK";
420 #if ENOTSUP != EOPNOTSUPP
421 case ENOTSUP: return "ENOTSUP";
422 #endif
423 case ENOTTY: return "ENOTTY";
424 case ENOTUNIQ: return "ENOTUNIQ";
425 case ENXIO: return "ENXIO";
426 case EOPNOTSUPP: return "EOPNOTSUPP";
427 case EOVERFLOW: return "EOVERFLOW";
428 case EPERM: return "EPERM";
429 case EPFNOSUPPORT: return "EPFNOSUPPORT";
430 case EPIPE: return "EPIPE";
431 case EPROTO: return "EPROTO";
432 case EPROTONOSUPPORT: return "EPROTONOSUPPORT";
433 case EPROTOTYPE: return "EPROTOTYPE";
434 case ERANGE: return "ERANGE";
435 case EREMOTE: return "EREMOTE";
436 case EREMOTEIO: return "EREMOTEIO";
437 case EROFS: return "EROFS";
438 case ESHUTDOWN: return "ESHUTDOWN";
439 case ESPIPE: return "ESPIPE";
440 case ESOCKTNOSUPPORT: return "ESOCKTNOSUPPORT";
441 case ESRCH: return "ESRCH";
442 case ESTALE: return "ESTALE";
443 case ETIME: return "ETIME";
444 case ETIMEDOUT: return "ETIMEDOUT";
445 case ETXTBSY: return "ETXTBSY";
446 #ifdef EUNATCH
447 case EUNATCH: return "EUNATCH";
448 #endif
449 case EUSERS: return "EUSERS";
450
451 case EXDEV: return "EXDEV";
452
453 #ifdef EBADE
454 case EBADE: return "EBADE";
455 case EBADFD: return "EBADFD";
456 case EBADSLT: return "EBADSLT";
457 case EDEADLOCK: return "EDEADLOCK";
458 case EBADR: return "EBADR";
459 case EBADRQC: return "EBADRQC";
460 case ECHRNG: return "ECHRNG";
461 #ifdef EISNAM
462 case EISNAM: return "EISNAM";
463 case EKEYEXPIRED: return "EKEYEXPIRED";
464 case EKEYREVOKED: return "EKEYREVOKED";
465 #endif
466 case EKEYREJECTED: return "EKEYREJECTED";
467 case EL2HLT: return "EL2HLT";
468 case EL2NSYNC: return "EL2NSYNC";
469 case EL3HLT: return "EL3HLT";
470 case EL3RST: return "EL3RST";
471 case ELIBBAD: return "ELIBBAD";
472 case ELIBMAX: return "ELIBMAX";
473 case ELIBSCN: return "ELIBSCN";
474 case ELIBEXEC: return "ELIBEXEC";
475 #ifdef ENOMEDIUM
476 case ENOMEDIUM: return "ENOMEDIUM";
477 case EMEDIUMTYPE: return "EMEDIUMTYPE";
478 #endif
479 case ENONET: return "ENONET";
480 case ENOPKG: return "ENOPKG";
481 case EREMCHG: return "EREMCHG";
482 case ERESTART: return "ERESTART";
483 case ESTRPIPE: return "ESTRPIPE";
484 #ifdef EUCLEAN
485 case EUCLEAN: return "EUCLEAN";
486 #endif
487 case EXFULL: return "EXFULL";
488 #endif
489 default: return "Unknown";
490 }
491 }
492
493
494
495
496
497
498
499
500 const char *
501 pcmk_rc_str(int rc)
502 {
503 if (rc == pcmk_rc_ok) {
504 return "OK";
505 }
506 if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < pcmk__n_rc)) {
507 return pcmk__rcs[pcmk_rc_error - rc].desc;
508 }
509 if (rc < 0) {
510 return "Error";
511 }
512
513
514 switch (rc) {
515 #ifdef PCMK__ENOTUNIQ
516 case ENOTUNIQ: return "Name not unique on network";
517 #endif
518 #ifdef PCMK__ECOMM
519 case ECOMM: return "Communication error on send";
520 #endif
521 #ifdef PCMK__ELIBACC
522 case ELIBACC: return "Can not access a needed shared library";
523 #endif
524 #ifdef PCMK__EREMOTEIO
525 case EREMOTEIO: return "Remote I/O error";
526 #endif
527 #ifdef PCMK__ENOKEY
528 case ENOKEY: return "Required key not available";
529 #endif
530 #ifdef PCMK__ENODATA
531 case ENODATA: return "No data available";
532 #endif
533 #ifdef PCMK__ETIME
534 case ETIME: return "Timer expired";
535 #endif
536 #ifdef PCMK__EKEYREJECTED
537 case EKEYREJECTED: return "Key was rejected by service";
538 #endif
539 default: return strerror(rc);
540 }
541 }
542
543
544
545 int
546 pcmk_rc2legacy(int rc)
547 {
548 if (rc >= 0) {
549 return -rc;
550 }
551 if ((rc <= pcmk_rc_error) && ((pcmk_rc_error - rc) < pcmk__n_rc)) {
552 return pcmk__rcs[pcmk_rc_error - rc].legacy_rc;
553 }
554 return -pcmk_err_generic;
555 }
556
557
558 int
559 pcmk_legacy2rc(int legacy_rc)
560 {
561 legacy_rc = abs(legacy_rc);
562 switch (legacy_rc) {
563 case pcmk_err_no_quorum: return pcmk_rc_no_quorum;
564 case pcmk_err_schema_validation: return pcmk_rc_schema_validation;
565 case pcmk_err_schema_unchanged: return pcmk_rc_schema_unchanged;
566 case pcmk_err_transform_failed: return pcmk_rc_transform_failed;
567 case pcmk_err_old_data: return pcmk_rc_old_data;
568 case pcmk_err_diff_failed: return pcmk_rc_diff_failed;
569 case pcmk_err_diff_resync: return pcmk_rc_diff_resync;
570 case pcmk_err_cib_modified: return pcmk_rc_cib_modified;
571 case pcmk_err_cib_backup: return pcmk_rc_cib_backup;
572 case pcmk_err_cib_save: return pcmk_rc_cib_save;
573 case pcmk_err_cib_corrupt: return pcmk_rc_cib_corrupt;
574 case pcmk_err_multiple: return pcmk_rc_multiple;
575 case pcmk_err_node_unknown: return pcmk_rc_node_unknown;
576 case pcmk_err_already: return pcmk_rc_already;
577 case pcmk_err_bad_nvpair: return pcmk_rc_bad_nvpair;
578 case pcmk_err_unknown_format: return pcmk_rc_unknown_format;
579 case pcmk_err_generic: return pcmk_rc_error;
580 case pcmk_ok: return pcmk_rc_ok;
581 default: return legacy_rc;
582 }
583 }
584
585
586
587 const char *
588 crm_exit_name(crm_exit_t exit_code)
589 {
590 switch (exit_code) {
591 case CRM_EX_OK: return "CRM_EX_OK";
592 case CRM_EX_ERROR: return "CRM_EX_ERROR";
593 case CRM_EX_INVALID_PARAM: return "CRM_EX_INVALID_PARAM";
594 case CRM_EX_UNIMPLEMENT_FEATURE: return "CRM_EX_UNIMPLEMENT_FEATURE";
595 case CRM_EX_INSUFFICIENT_PRIV: return "CRM_EX_INSUFFICIENT_PRIV";
596 case CRM_EX_NOT_INSTALLED: return "CRM_EX_NOT_INSTALLED";
597 case CRM_EX_NOT_CONFIGURED: return "CRM_EX_NOT_CONFIGURED";
598 case CRM_EX_NOT_RUNNING: return "CRM_EX_NOT_RUNNING";
599 case CRM_EX_PROMOTED: return "CRM_EX_PROMOTED";
600 case CRM_EX_FAILED_PROMOTED: return "CRM_EX_FAILED_PROMOTED";
601 case CRM_EX_USAGE: return "CRM_EX_USAGE";
602 case CRM_EX_DATAERR: return "CRM_EX_DATAERR";
603 case CRM_EX_NOINPUT: return "CRM_EX_NOINPUT";
604 case CRM_EX_NOUSER: return "CRM_EX_NOUSER";
605 case CRM_EX_NOHOST: return "CRM_EX_NOHOST";
606 case CRM_EX_UNAVAILABLE: return "CRM_EX_UNAVAILABLE";
607 case CRM_EX_SOFTWARE: return "CRM_EX_SOFTWARE";
608 case CRM_EX_OSERR: return "CRM_EX_OSERR";
609 case CRM_EX_OSFILE: return "CRM_EX_OSFILE";
610 case CRM_EX_CANTCREAT: return "CRM_EX_CANTCREAT";
611 case CRM_EX_IOERR: return "CRM_EX_IOERR";
612 case CRM_EX_TEMPFAIL: return "CRM_EX_TEMPFAIL";
613 case CRM_EX_PROTOCOL: return "CRM_EX_PROTOCOL";
614 case CRM_EX_NOPERM: return "CRM_EX_NOPERM";
615 case CRM_EX_CONFIG: return "CRM_EX_CONFIG";
616 case CRM_EX_FATAL: return "CRM_EX_FATAL";
617 case CRM_EX_PANIC: return "CRM_EX_PANIC";
618 case CRM_EX_DISCONNECT: return "CRM_EX_DISCONNECT";
619 case CRM_EX_DIGEST: return "CRM_EX_DIGEST";
620 case CRM_EX_NOSUCH: return "CRM_EX_NOSUCH";
621 case CRM_EX_QUORUM: return "CRM_EX_QUORUM";
622 case CRM_EX_UNSAFE: return "CRM_EX_UNSAFE";
623 case CRM_EX_EXISTS: return "CRM_EX_EXISTS";
624 case CRM_EX_MULTIPLE: return "CRM_EX_MULTIPLE";
625 case CRM_EX_EXPIRED: return "CRM_EX_EXPIRED";
626 case CRM_EX_NOT_YET_IN_EFFECT: return "CRM_EX_NOT_YET_IN_EFFECT";
627 case CRM_EX_INDETERMINATE: return "CRM_EX_INDETERMINATE";
628 case CRM_EX_UNSATISFIED: return "CRM_EX_UNSATISFIED";
629 case CRM_EX_OLD: return "CRM_EX_OLD";
630 case CRM_EX_TIMEOUT: return "CRM_EX_TIMEOUT";
631 case CRM_EX_DEGRADED: return "CRM_EX_DEGRADED";
632 case CRM_EX_DEGRADED_PROMOTED: return "CRM_EX_DEGRADED_PROMOTED";
633 case CRM_EX_NONE: return "CRM_EX_NONE";
634 case CRM_EX_MAX: return "CRM_EX_UNKNOWN";
635 }
636 return "CRM_EX_UNKNOWN";
637 }
638
639 const char *
640 crm_exit_str(crm_exit_t exit_code)
641 {
642 switch (exit_code) {
643 case CRM_EX_OK: return "OK";
644 case CRM_EX_ERROR: return "Error occurred";
645 case CRM_EX_INVALID_PARAM: return "Invalid parameter";
646 case CRM_EX_UNIMPLEMENT_FEATURE: return "Unimplemented";
647 case CRM_EX_INSUFFICIENT_PRIV: return "Insufficient privileges";
648 case CRM_EX_NOT_INSTALLED: return "Not installed";
649 case CRM_EX_NOT_CONFIGURED: return "Not configured";
650 case CRM_EX_NOT_RUNNING: return "Not running";
651 case CRM_EX_PROMOTED: return "Promoted";
652 case CRM_EX_FAILED_PROMOTED: return "Failed in promoted role";
653 case CRM_EX_USAGE: return "Incorrect usage";
654 case CRM_EX_DATAERR: return "Invalid data given";
655 case CRM_EX_NOINPUT: return "Input file not available";
656 case CRM_EX_NOUSER: return "User does not exist";
657 case CRM_EX_NOHOST: return "Host does not exist";
658 case CRM_EX_UNAVAILABLE: return "Necessary service unavailable";
659 case CRM_EX_SOFTWARE: return "Internal software bug";
660 case CRM_EX_OSERR: return "Operating system error occurred";
661 case CRM_EX_OSFILE: return "System file not available";
662 case CRM_EX_CANTCREAT: return "Cannot create output file";
663 case CRM_EX_IOERR: return "I/O error occurred";
664 case CRM_EX_TEMPFAIL: return "Temporary failure, try again";
665 case CRM_EX_PROTOCOL: return "Protocol violated";
666 case CRM_EX_NOPERM: return "Insufficient privileges";
667 case CRM_EX_CONFIG: return "Invalid configuration";
668 case CRM_EX_FATAL: return "Fatal error occurred, will not respawn";
669 case CRM_EX_PANIC: return "System panic required";
670 case CRM_EX_DISCONNECT: return "Not connected";
671 case CRM_EX_DIGEST: return "Digest mismatch";
672 case CRM_EX_NOSUCH: return "No such object";
673 case CRM_EX_QUORUM: return "Quorum required";
674 case CRM_EX_UNSAFE: return "Operation not safe";
675 case CRM_EX_EXISTS: return "Requested item already exists";
676 case CRM_EX_MULTIPLE: return "Multiple items match request";
677 case CRM_EX_EXPIRED: return "Requested item has expired";
678 case CRM_EX_NOT_YET_IN_EFFECT: return "Requested item is not yet in effect";
679 case CRM_EX_INDETERMINATE: return "Could not determine status";
680 case CRM_EX_UNSATISFIED: return "Not applicable under current conditions";
681 case CRM_EX_OLD: return "Update was older than existing configuration";
682 case CRM_EX_TIMEOUT: return "Timeout occurred";
683 case CRM_EX_DEGRADED: return "Service is active but might fail soon";
684 case CRM_EX_DEGRADED_PROMOTED: return "Service is promoted but might fail soon";
685 case CRM_EX_NONE: return "No exit status available";
686 case CRM_EX_MAX: return "Error occurred";
687 }
688 if ((exit_code > 128) && (exit_code < CRM_EX_MAX)) {
689 return "Interrupted by signal";
690 }
691 return "Unknown exit status";
692 }
693
694
695
696
697
698
699
700
701 crm_exit_t
702 pcmk_rc2exitc(int rc)
703 {
704 switch (rc) {
705 case pcmk_rc_ok:
706 case pcmk_rc_no_output:
707 return CRM_EX_OK;
708
709 case pcmk_rc_no_quorum:
710 return CRM_EX_QUORUM;
711
712 case pcmk_rc_old_data:
713 return CRM_EX_OLD;
714
715 case pcmk_rc_schema_validation:
716 case pcmk_rc_transform_failed:
717 case pcmk_rc_unpack_error:
718 return CRM_EX_CONFIG;
719
720 case pcmk_rc_bad_nvpair:
721 return CRM_EX_INVALID_PARAM;
722
723 case EACCES:
724 return CRM_EX_INSUFFICIENT_PRIV;
725
726 case EBADF:
727 case EINVAL:
728 case EFAULT:
729 case ENOSYS:
730 case EOVERFLOW:
731 case pcmk_rc_underflow:
732 case pcmk_rc_compression:
733 return CRM_EX_SOFTWARE;
734
735 case EBADMSG:
736 case EMSGSIZE:
737 case ENOMSG:
738 case ENOPROTOOPT:
739 case EPROTO:
740 case EPROTONOSUPPORT:
741 case EPROTOTYPE:
742 return CRM_EX_PROTOCOL;
743
744 case ECOMM:
745 case ENOMEM:
746 return CRM_EX_OSERR;
747
748 case ECONNABORTED:
749 case ECONNREFUSED:
750 case ECONNRESET:
751 case ENOTCONN:
752 return CRM_EX_DISCONNECT;
753
754 case EEXIST:
755 case pcmk_rc_already:
756 return CRM_EX_EXISTS;
757
758 case EIO:
759 case pcmk_rc_dot_error:
760 case pcmk_rc_graph_error:
761 return CRM_EX_IOERR;
762
763 case ENOTSUP:
764 #if EOPNOTSUPP != ENOTSUP
765 case EOPNOTSUPP:
766 #endif
767 return CRM_EX_UNIMPLEMENT_FEATURE;
768
769 case ENOTUNIQ:
770 case pcmk_rc_multiple:
771 return CRM_EX_MULTIPLE;
772
773 case ENODEV:
774 case ENOENT:
775 case ENXIO:
776 case pcmk_rc_no_transaction:
777 case pcmk_rc_unknown_format:
778 return CRM_EX_NOSUCH;
779
780 case pcmk_rc_node_unknown:
781 case pcmk_rc_ns_resolution:
782 return CRM_EX_NOHOST;
783
784 case ETIME:
785 case ETIMEDOUT:
786 return CRM_EX_TIMEOUT;
787
788 case EAGAIN:
789 case EBUSY:
790 return CRM_EX_UNSATISFIED;
791
792 case pcmk_rc_before_range:
793 return CRM_EX_NOT_YET_IN_EFFECT;
794
795 case pcmk_rc_after_range:
796 return CRM_EX_EXPIRED;
797
798 case pcmk_rc_undetermined:
799 return CRM_EX_INDETERMINATE;
800
801 case pcmk_rc_op_unsatisfied:
802 return CRM_EX_UNSATISFIED;
803
804 case pcmk_rc_within_range:
805 return CRM_EX_OK;
806
807 case pcmk_rc_no_input:
808 return CRM_EX_NOINPUT;
809
810 case pcmk_rc_duplicate_id:
811 return CRM_EX_MULTIPLE;
812
813 case pcmk_rc_bad_input:
814 case pcmk_rc_bad_xml_patch:
815 return CRM_EX_DATAERR;
816
817 default:
818 return CRM_EX_ERROR;
819 }
820 }
821
822
823
824
825
826
827
828
829 enum ocf_exitcode
830 pcmk_rc2ocf(int rc)
831 {
832 switch (rc) {
833 case pcmk_rc_ok:
834 return PCMK_OCF_OK;
835
836 case pcmk_rc_bad_nvpair:
837 return PCMK_OCF_INVALID_PARAM;
838
839 case EACCES:
840 return PCMK_OCF_INSUFFICIENT_PRIV;
841
842 case ENOTSUP:
843 #if EOPNOTSUPP != ENOTSUP
844 case EOPNOTSUPP:
845 #endif
846 return PCMK_OCF_UNIMPLEMENT_FEATURE;
847
848 default:
849 return PCMK_OCF_UNKNOWN_ERROR;
850 }
851 }
852
853
854
855
856
857
858
859
860
861
862
863
864 int
865 pcmk__gaierror2rc(int gai)
866 {
867 switch (gai) {
868 case 0:
869 return pcmk_rc_ok;
870
871 case EAI_AGAIN:
872 return EAGAIN;
873
874 case EAI_BADFLAGS:
875 case EAI_SERVICE:
876 return EINVAL;
877
878 case EAI_FAMILY:
879 return EAFNOSUPPORT;
880
881 case EAI_MEMORY:
882 return ENOMEM;
883
884 case EAI_NONAME:
885 return pcmk_rc_node_unknown;
886
887 case EAI_SOCKTYPE:
888 return ESOCKTNOSUPPORT;
889
890 case EAI_SYSTEM:
891 return errno;
892
893 default:
894 return pcmk_rc_ns_resolution;
895 }
896 }
897
898
899
900
901
902
903
904
905 int
906 pcmk__bzlib2rc(int bz2)
907 {
908 switch (bz2) {
909 case BZ_OK:
910 case BZ_RUN_OK:
911 case BZ_FLUSH_OK:
912 case BZ_FINISH_OK:
913 case BZ_STREAM_END:
914 return pcmk_rc_ok;
915
916 case BZ_MEM_ERROR:
917 return ENOMEM;
918
919 case BZ_DATA_ERROR:
920 case BZ_DATA_ERROR_MAGIC:
921 case BZ_UNEXPECTED_EOF:
922 return pcmk_rc_bad_input;
923
924 case BZ_IO_ERROR:
925 return EIO;
926
927 case BZ_OUTBUFF_FULL:
928 return EFBIG;
929
930 default:
931 return pcmk_rc_compression;
932 }
933 }
934
935 crm_exit_t
936 crm_exit(crm_exit_t rc)
937 {
938
939
940
941 if ((((int) rc) < 0) || (((int) rc) > CRM_EX_MAX)) {
942 rc = CRM_EX_ERROR;
943 }
944
945 mainloop_cleanup();
946 crm_xml_cleanup();
947
948 free(pcmk__our_nodename);
949
950 if (crm_system_name) {
951 crm_info("Exiting %s " CRM_XS " with status %d", crm_system_name, rc);
952 free(crm_system_name);
953 } else {
954 crm_trace("Exiting with status %d", rc);
955 }
956 pcmk__free_common_logger();
957 qb_log_fini();
958
959 exit(rc);
960 }
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975 void
976 pcmk__set_result(pcmk__action_result_t *result, int exit_status,
977 enum pcmk_exec_status exec_status, const char *exit_reason)
978 {
979 if (result == NULL) {
980 return;
981 }
982
983 result->exit_status = exit_status;
984 result->execution_status = exec_status;
985
986 if (!pcmk__str_eq(result->exit_reason, exit_reason, pcmk__str_none)) {
987 free(result->exit_reason);
988 result->exit_reason = (exit_reason == NULL)? NULL : strdup(exit_reason);
989 }
990 }
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004 G_GNUC_PRINTF(4, 5)
1005 void
1006 pcmk__format_result(pcmk__action_result_t *result, int exit_status,
1007 enum pcmk_exec_status exec_status,
1008 const char *format, ...)
1009 {
1010 va_list ap;
1011 int len = 0;
1012 char *reason = NULL;
1013
1014 if (result == NULL) {
1015 return;
1016 }
1017
1018 result->exit_status = exit_status;
1019 result->execution_status = exec_status;
1020
1021 if (format != NULL) {
1022 va_start(ap, format);
1023 len = vasprintf(&reason, format, ap);
1024 CRM_ASSERT(len > 0);
1025 va_end(ap);
1026 }
1027 free(result->exit_reason);
1028 result->exit_reason = reason;
1029 }
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044 void
1045 pcmk__set_result_output(pcmk__action_result_t *result, char *out, char *err)
1046 {
1047 if (result == NULL) {
1048 return;
1049 }
1050
1051 free(result->action_stdout);
1052 result->action_stdout = out;
1053
1054 free(result->action_stderr);
1055 result->action_stderr = err;
1056 }
1057
1058
1059
1060
1061
1062
1063
1064 void
1065 pcmk__reset_result(pcmk__action_result_t *result)
1066 {
1067 if (result == NULL) {
1068 return;
1069 }
1070
1071 free(result->exit_reason);
1072 result->exit_reason = NULL;
1073
1074 free(result->action_stdout);
1075 result->action_stdout = NULL;
1076
1077 free(result->action_stderr);
1078 result->action_stderr = NULL;
1079 }
1080
1081
1082
1083
1084
1085
1086
1087
1088 void
1089 pcmk__copy_result(const pcmk__action_result_t *src, pcmk__action_result_t *dst)
1090 {
1091 CRM_CHECK((src != NULL) && (dst != NULL), return);
1092 dst->exit_status = src->exit_status;
1093 dst->execution_status = src->execution_status;
1094 pcmk__str_update(&dst->exit_reason, src->exit_reason);
1095 pcmk__str_update(&dst->action_stdout, src->action_stdout);
1096 pcmk__str_update(&dst->action_stderr, src->action_stderr);
1097 }
1098
1099
1100
1101
1102 #include <crm/common/results_compat.h>
1103
1104 const char *
1105 bz2_strerror(int rc)
1106 {
1107
1108 switch (rc) {
1109 case BZ_OK:
1110 case BZ_RUN_OK:
1111 case BZ_FLUSH_OK:
1112 case BZ_FINISH_OK:
1113 case BZ_STREAM_END:
1114 return "Ok";
1115 case BZ_CONFIG_ERROR:
1116 return "libbz2 has been improperly compiled on your platform";
1117 case BZ_SEQUENCE_ERROR:
1118 return "library functions called in the wrong order";
1119 case BZ_PARAM_ERROR:
1120 return "parameter is out of range or otherwise incorrect";
1121 case BZ_MEM_ERROR:
1122 return "memory allocation failed";
1123 case BZ_DATA_ERROR:
1124 return "data integrity error is detected during decompression";
1125 case BZ_DATA_ERROR_MAGIC:
1126 return "the compressed stream does not start with the correct magic bytes";
1127 case BZ_IO_ERROR:
1128 return "error reading or writing in the compressed file";
1129 case BZ_UNEXPECTED_EOF:
1130 return "compressed file finishes before the logical end of stream is detected";
1131 case BZ_OUTBUFF_FULL:
1132 return "output data will not fit into the buffer provided";
1133 }
1134 return "Data compression error";
1135 }
1136
1137 crm_exit_t
1138 crm_errno2exit(int rc)
1139 {
1140 return pcmk_rc2exitc(pcmk_legacy2rc(rc));
1141 }
1142
1143
1144