1 /* 2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana 3 * University Research and Technology 4 * Corporation. All rights reserved. 5 * Copyright (c) 2004-2006 The University of Tennessee and The University 6 * of Tennessee Research Foundation. All rights 7 * reserved. 8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 9 * University of Stuttgart. All rights reserved. 10 * Copyright (c) 2004-2005 The Regents of the University of California. 11 * All rights reserved. 12 * Copyright (c) 2017 FUJITSU LIMITED. All rights reserved. 13 * $COPYRIGHT$ 14 * 15 * Additional copyrights may follow 16 * 17 * $HEADER$ 18 */ 19 20 #ifndef OPAL_UTIL_ERROR_H 21 #define OPAL_UTIL_ERROR_H 22 23 #include "opal_config.h" 24 25 #include "opal/util/output.h" 26 27 BEGIN_C_DECLS 28 29 #define OPAL_ERROR_LOG(r) \ 30 opal_output(0, "OPAL ERROR: %s in file %s at line %d", \ 31 opal_strerror((r)), __FILE__, __LINE__); 32 33 34 /** 35 * Prints error message for errnum on stderr 36 * 37 * Print the error message corresponding to the value of \c errnum and 38 * writes it, followed by a newline, to the standard error file 39 * descriptor. If the argument \c msg is non-NULL, this string is 40 * prepended to the message string and separated from it by a colon 41 * and a space. Otherwise, only the error message string is printed. 42 * 43 * If errnum is OPAL_ERR_IN_ERRNO, the system perror is called with 44 * the argument \c msg. 45 */ 46 OPAL_DECLSPEC void opal_perror(int errnum, const char *msg); 47 48 /** 49 * Return string for given error message 50 * 51 * Accepts an error number argument \c errnum and returns a pointer to 52 * the corresponding message string. The result is returned in a 53 * static buffer that should not be released with free(). 54 * 55 * If errnum is \c OPAL_ERR_IN_ERRNO, the system strerror is called 56 * with an argument of the current value of \c errno and the resulting 57 * string is returned. 58 * 59 * If the errnum is not a known value, the returned value may be 60 * overwritten by subsequent calls to opal_strerror. 61 */ 62 OPAL_DECLSPEC const char *opal_strerror(int errnum); 63 64 /** 65 * Return string for given error message 66 * 67 * Similar to opal_strerror, but a buffer is passed in which is filled 68 * with a string (up to buflen - 1 characters long) containing the 69 * error message corresponding to \c errnum. Unlike opal_strerror(), 70 * if an unknown value for \c errnum is passed, the returned buffer 71 * will not be overwritten by subsequent calls to opal_strerror_r(). 72 */ 73 OPAL_DECLSPEC int opal_strerror_r(int errnum, char *strerrbuf, size_t buflen); 74 75 76 typedef int (*opal_err2str_fn_t)(int errnum, const char **str); 77 78 /** 79 * \internal 80 * 81 * Register a handler for converting errnums to error strings 82 * 83 * Handlers will be invoked by opal_perror() , opal_strerror(), and 84 * opal_strerror_r() to return the appropriate values. 85 * 86 * \note A maximum of 5 converters can be registered. The 6th 87 * converter registration attempt will return OPAL_ERR_OUT_OF_RESOURCE 88 */ 89 OPAL_DECLSPEC int opal_error_register(const char *project, 90 int err_base, int err_max, 91 opal_err2str_fn_t converter); 92 93 /** 94 * Print a message and sleep in accordance with the opal_abort_delay value 95 * 96 * This function is (almost) async-thread-safe so it can be called from 97 * a signal handler. 98 */ 99 OPAL_DECLSPEC void opal_delay_abort(void); 100 101 END_C_DECLS 102 103 #endif /* OPAL_UTIL_ERROR_H */