ARPA2 Common Libraries
2.6.2
|
Modules | |
Common Error table A2ID | |
Common Error table A2XS | |
Functions | |
void | arpa2comerr_init (void) |
Initialise the COM-ERR list of error codes. More... | |
Most ARPA2 systems report errors in errno
, but without being too agressive; the Common Error system is an old, but still the best idea of compressing a table name into 3 bytes to address a table of 256 contiguous error codes. The risk of clashes when packages are arbitrarily composed is minimal.
The following is an exmple of how ARPA2 Identity reports an error:
The low risk of clashes means we can use errno
, which is already supported broadly. The value may travel up through several layers, but because a2id_init()
registered the error messages in a global table, these higher-up layers can produce meaningful errors without knowing about a low-down layer like ARPA2 Identity, so
would print something meaningful like
We actually use it with a wrapper that auto-detects Common Errors,
(basically replacing log_error()
with log_errno()
and no further changes) to yield the much more informative message
where the expiration of the Identity is a helpful hint, shared in errno
with the declaration in lib/id/errno.et
as
Check the file to learn more about the errors you might expect. It will show you how much information we would loose by constraining our errors to POSIX error codes or just a boolean.
The include file <arpa2/com_err.h> handles variations in the location of the "real" <com_err.h>, which:
void arpa2comerr_init | ( | void | ) |
Initialise the COM-ERR list of error codes.
This call is not usually needed, but a COM-ERR library may count on the list being set to NULL before getting started and this can fail if a program loads a module as a shared object that in turn loads the COM-ERR library. In such cases, you may need to explicitly initialise.
If you program uses threads, then use pthread_once() or similar to avoid calling it concurrently, using
static pthread_once_t a2ce_ctl = PTHREAD_ONCE_INIT; pthread_once (*a2ce_ctl, arpa2comerr_init);
It is not a problem if multiple modules call this function in sequence, as long as these code fragments are not concurrently called, which is not usually what modular programs do.