diff --git a/CHANGES b/CHANGES index 89472e0ec7..db66391e2a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +5997. [cleanup] Less ceremonial UNEXPECTED_ERROR() and FATAL_ERROR() + reporting macros. [GL !6914] + 5996. [bug] Fix a couple of bugs in cfg_print_duration(), which could result in generating incomplete duration values when printing the configuration using named-checkconf. diff --git a/bin/named/dlz_dlopen_driver.c b/bin/named/dlz_dlopen_driver.c index 45cfbfa976..f636cd26de 100644 --- a/bin/named/dlz_dlopen_driver.c +++ b/bin/named/dlz_dlopen_driver.c @@ -532,8 +532,7 @@ dlz_dlopen_init(isc_mem_t *mctx) { mctx, &dlz_dlopen); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "dns_sdlzregister() failed: %s", + UNEXPECTED_ERROR("dns_sdlzregister() failed: %s", isc_result_totext(result)); result = ISC_R_UNEXPECTED; } diff --git a/bin/named/main.c b/bin/named/main.c index b8122401d0..c496bfb587 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -240,12 +240,12 @@ assertion_failed(const char *file, int line, isc_assertiontype_t type, } noreturn static void -library_fatal_error(const char *file, int line, const char *format, - va_list args) ISC_FORMAT_PRINTF(3, 0); +library_fatal_error(const char *file, int line, const char *func, + const char *format, va_list args) ISC_FORMAT_PRINTF(3, 0); static void -library_fatal_error(const char *file, int line, const char *format, - va_list args) { +library_fatal_error(const char *file, int line, const char *func, + const char *format, va_list args) { /* * Handle isc_error_fatal() calls from our libraries. */ @@ -259,7 +259,7 @@ library_fatal_error(const char *file, int line, const char *format, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL, - "%s:%d: fatal error:", file, line); + "%s:%d:%s(): fatal error: ", file, line, func); isc_log_vwrite(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL, format, args); @@ -267,7 +267,7 @@ library_fatal_error(const char *file, int line, const char *format, NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL, "exiting (due to fatal error in library)"); } else { - fprintf(stderr, "%s:%d: fatal error: ", file, line); + fprintf(stderr, "%s:%d:%s(): fatal error: ", file, line, func); vfprintf(stderr, format, args); fprintf(stderr, "\n"); fflush(stderr); @@ -280,12 +280,13 @@ library_fatal_error(const char *file, int line, const char *format, } static void -library_unexpected_error(const char *file, int line, const char *format, - va_list args) ISC_FORMAT_PRINTF(3, 0); +library_unexpected_error(const char *file, int line, const char *func, + const char *format, va_list args) + ISC_FORMAT_PRINTF(3, 0); static void -library_unexpected_error(const char *file, int line, const char *format, - va_list args) { +library_unexpected_error(const char *file, int line, const char *func, + const char *format, va_list args) { /* * Handle isc_error_unexpected() calls from our libraries. */ @@ -293,12 +294,13 @@ library_unexpected_error(const char *file, int line, const char *format, if (named_g_lctx != NULL) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN, ISC_LOG_ERROR, - "%s:%d: unexpected error:", file, line); + "%s:%d:%s(): unexpected error: ", file, line, + func); isc_log_vwrite(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_MAIN, ISC_LOG_ERROR, format, args); } else { - fprintf(stderr, "%s:%d: fatal error: ", file, line); + fprintf(stderr, "%s:%d:%s(): fatal error: ", file, line, func); vfprintf(stderr, format, args); fprintf(stderr, "\n"); fflush(stderr); @@ -1426,8 +1428,7 @@ named_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) { if ((h = scf_handle_create(SCF_VERSION)) == NULL) { if (debug) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "scf_handle_create() failed: %s", + UNEXPECTED_ERROR("scf_handle_create() failed: %s", scf_strerror(scf_error())); } return (ISC_R_FAILURE); @@ -1435,8 +1436,7 @@ named_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) { if (scf_handle_bind(h) == -1) { if (debug) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "scf_handle_bind() failed: %s", + UNEXPECTED_ERROR("scf_handle_bind() failed: %s", scf_strerror(scf_error())); } scf_handle_destroy(h); @@ -1445,8 +1445,7 @@ named_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) { if ((namelen = scf_myname(h, NULL, 0)) == -1) { if (debug) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "scf_myname() failed: %s", + UNEXPECTED_ERROR("scf_myname() failed: %s", scf_strerror(scf_error())); } scf_handle_destroy(h); @@ -1454,8 +1453,7 @@ named_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) { } if ((instance = isc_mem_allocate(mctx, namelen + 1)) == NULL) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "named_smf_get_instance memory " + UNEXPECTED_ERROR("named_smf_get_instance memory " "allocation failed: %s", isc_result_totext(ISC_R_NOMEMORY)); scf_handle_destroy(h); @@ -1464,8 +1462,7 @@ named_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx) { if (scf_myname(h, instance, namelen + 1) == -1) { if (debug) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "scf_myname() failed: %s", + UNEXPECTED_ERROR("scf_myname() failed: %s", scf_strerror(scf_error())); } scf_handle_destroy(h); @@ -1576,8 +1573,7 @@ main(int argc, char *argv[]) { if (result == ISC_R_RELOAD) { named_server_reloadwanted(named_g_server); } else if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_app_run(): %s", + UNEXPECTED_ERROR("isc_app_run(): %s", isc_result_totext(result)); /* * Force exit. @@ -1591,8 +1587,7 @@ main(int argc, char *argv[]) { result = named_smf_get_instance(&instance, 1, named_g_mctx); if (result == ISC_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "smf_disable_instance() " + UNEXPECTED_ERROR("smf_disable_instance() " "failed for %s : %s", instance, scf_strerror(scf_error())); diff --git a/bin/named/server.c b/bin/named/server.c index d4ac044dda..d213c7a900 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -4758,8 +4758,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, maps, AF_INET6, &dispatch6, &dscp6, (ISC_LIST_PREV(view, link) == NULL))); if (dispatch4 == NULL && dispatch6 == NULL) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "unable to obtain either an IPv4 or" + UNEXPECTED_ERROR("unable to obtain either an IPv4 or" " an IPv6 dispatch"); result = ISC_R_UNEXPECTED; goto cleanup; diff --git a/bin/tests/system/dyndb/driver/db.c b/bin/tests/system/dyndb/driver/db.c index 05485bd631..a2bdb6916b 100644 --- a/bin/tests/system/dyndb/driver/db.c +++ b/bin/tests/system/dyndb/driver/db.c @@ -133,7 +133,7 @@ beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) { UNUSED(db); UNUSED(callbacks); - fatal_error("current implementation should never call beginload()"); + FATAL_ERROR("current implementation should never call beginload()"); /* Not reached */ return (ISC_R_SUCCESS); @@ -149,7 +149,7 @@ endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) { UNUSED(db); UNUSED(callbacks); - fatal_error("current implementation should never call endload()"); + FATAL_ERROR("current implementation should never call endload()"); /* Not reached */ return (ISC_R_SUCCESS); @@ -163,7 +163,7 @@ dump(dns_db_t *db, dns_dbversion_t *version, const char *filename, UNUSED(filename); UNUSED(masterformat); - fatal_error("current implementation should never call dump()"); + FATAL_ERROR("current implementation should never call dump()"); /* Not reached */ return (ISC_R_SUCCESS); diff --git a/bin/tests/system/dyndb/driver/log.h b/bin/tests/system/dyndb/driver/log.h index 2cb968bf81..375db2b46a 100644 --- a/bin/tests/system/dyndb/driver/log.h +++ b/bin/tests/system/dyndb/driver/log.h @@ -34,8 +34,6 @@ #include -#define fatal_error(...) isc_error_fatal(__FILE__, __LINE__, __VA_ARGS__) - #define log_error_r(fmt, ...) \ log_error(fmt ": %s", ##__VA_ARGS__, isc_result_totext(result)) diff --git a/bin/tests/system/dyndb/driver/syncptr.c b/bin/tests/system/dyndb/driver/syncptr.c index 81d98e5d43..5124df32b4 100644 --- a/bin/tests/system/dyndb/driver/syncptr.c +++ b/bin/tests/system/dyndb/driver/syncptr.c @@ -157,7 +157,7 @@ syncptr_find_zone(sample_instance_t *inst, dns_rdata_t *rdata, dns_name_t *name, break; default: - fatal_error("unsupported address type 0x%x", rdata->type); + FATAL_ERROR("unsupported address type 0x%x", rdata->type); break; } diff --git a/doc/dev/unexpected b/doc/dev/unexpected index ffa4b2a9b9..bb9f00a8b5 100644 --- a/doc/dev/unexpected +++ b/doc/dev/unexpected @@ -37,8 +37,7 @@ not, we call UNEXPECTED_ERROR(). E.g. void foo() { if (some_unix_thang() < 0) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "some_unix_thang() failed: %s", + UNEXPECTED_ERROR("some_unix_thang() failed: %s", strerror(errno)); return (ISC_R_UNEXPECTED); } diff --git a/lib/dns/cache.c b/lib/dns/cache.c index bb4bea3052..3e4e8c95f8 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -467,8 +467,7 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr, if (taskmgr != NULL && timermgr != NULL) { result = isc_task_create(taskmgr, 1, &cleaner->task); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_task_create() failed: %s", + UNEXPECTED_ERROR("isc_task_create() failed: %s", isc_result_totext(result)); result = ISC_R_UNEXPECTED; goto cleanup; @@ -480,8 +479,7 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr, cleaner_shutdown_action, cache); if (result != ISC_R_SUCCESS) { isc_refcount_decrement0(&cleaner->cache->live_tasks); - UNEXPECTED_ERROR(__FILE__, __LINE__, - "cache cleaner: " + UNEXPECTED_ERROR("cache cleaner: " "isc_task_onshutdown() failed: %s", isc_result_totext(result)); goto cleanup; @@ -547,8 +545,7 @@ begin_cleaning(cache_cleaner_t *cleaner) { * so there is nothing to be cleaned. */ if (result != ISC_R_NOMORE && cleaner->iterator != NULL) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "cache cleaner: " + UNEXPECTED_ERROR("cache cleaner: " "dns_dbiterator_first() failed: %s", isc_result_totext(result)); dns_dbiterator_destroy(&cleaner->iterator); @@ -687,10 +684,8 @@ incremental_cleaning_action(isc_task_t *task, isc_event_t *event) { result = dns_dbiterator_current(cleaner->iterator, &node, NULL); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "cache cleaner: " - "dns_dbiterator_current() " - "failed: %s", + UNEXPECTED_ERROR("cache cleaner: " + "dns_dbiterator_current() failed: %s", isc_result_totext(result)); end_cleaning(cleaner, event); @@ -716,8 +711,7 @@ incremental_cleaning_action(isc_task_t *task, isc_event_t *event) { * keep trying to clean it, otherwise stop cleaning. */ if (result != ISC_R_NOMORE) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "cache cleaner: " + UNEXPECTED_ERROR("cache cleaner: " "dns_dbiterator_next() " "failed: %s", isc_result_totext(result)); @@ -792,8 +786,7 @@ dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now) { */ result = dns_db_expirenode(cache->db, node, now); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "cache cleaner: dns_db_expirenode() " + UNEXPECTED_ERROR("cache cleaner: dns_db_expirenode() " "failed: %s", isc_result_totext(result)); /* diff --git a/lib/dns/diff.c b/lib/dns/diff.c index f5f7cef11c..a1a2c438d3 100644 --- a/lib/dns/diff.c +++ b/lib/dns/diff.c @@ -176,8 +176,7 @@ dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuplep) { { ISC_LIST_UNLINK(diff->tuples, ot, link); if ((*tuplep)->op == ot->op) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "unexpected non-minimal diff"); + UNEXPECTED_ERROR("unexpected non-minimal diff"); } else { dns_difftuple_free(tuplep); } @@ -615,8 +614,7 @@ dns_diff_print(dns_diff_t *diff, FILE *file) { result = diff_tuple_tordataset(t, &rd, &rdl, &rds); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "diff_tuple_tordataset failed: %s", + UNEXPECTED_ERROR("diff_tuple_tordataset failed: %s", isc_result_totext(result)); result = ISC_R_UNEXPECTED; goto cleanup; diff --git a/lib/dns/journal.c b/lib/dns/journal.c index 23534115ed..930fae3c73 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -168,7 +168,7 @@ dns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx, freenode: dns_db_detachnode(db, &node); nonode: - UNEXPECTED_ERROR(__FILE__, __LINE__, "missing SOA"); + UNEXPECTED_ERROR("missing SOA"); return (result); } diff --git a/lib/dns/master.c b/lib/dns/master.c index f84dd114cf..6acd19232f 100644 --- a/lib/dns/master.c +++ b/lib/dns/master.c @@ -445,8 +445,7 @@ loadctx_destroy(dns_loadctx_t *lctx) { if (lctx->f != NULL) { isc_result_t result = isc_stdio_close(lctx->f); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_stdio_close() failed: %s", + UNEXPECTED_ERROR("isc_stdio_close() failed: %s", isc_result_totext(result)); } } @@ -1281,8 +1280,7 @@ load_text(dns_loadctx_t *lctx) { } dump_time = (isc_stdtime_t)dump_time64; if (dump_time != dump_time64) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "%s: %s:%lu: $DATE " + UNEXPECTED_ERROR("%s: %s:%lu: $DATE " "outside epoch", "dns_master_load", source, line); @@ -1290,8 +1288,7 @@ load_text(dns_loadctx_t *lctx) { goto insist_and_cleanup; } if (dump_time > current_time) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "%s: %s:%lu: " + UNEXPECTED_ERROR("%s: %s:%lu: " "$DATE in future, " "using current date", "dns_master_load", @@ -1570,8 +1567,7 @@ load_text(dns_loadctx_t *lctx) { ictx->drop = false; } } else { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "%s:%lu: isc_lex_gettoken() returned " + UNEXPECTED_ERROR("%s:%lu: isc_lex_gettoken() returned " "unexpected token type (%d)", source, line, token.type); result = ISC_R_UNEXPECTED; @@ -1663,8 +1659,7 @@ load_text(dns_loadctx_t *lctx) { } if (token.type != isc_tokentype_string) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_lex_gettoken() returned " + UNEXPECTED_ERROR("isc_lex_gettoken() returned " "unexpected token type"); result = ISC_R_UNEXPECTED; if (MANYERRS(lctx, result)) { @@ -1685,8 +1680,7 @@ load_text(dns_loadctx_t *lctx) { } if (token.type != isc_tokentype_string) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_lex_gettoken() returned " + UNEXPECTED_ERROR("isc_lex_gettoken() returned " "unexpected token type"); result = ISC_R_UNEXPECTED; if (MANYERRS(lctx, result)) { @@ -2273,8 +2267,7 @@ load_header(dns_loadctx_t *lctx) { result = isc_stdio_read(data, 1, commonlen, lctx->f, NULL); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_stdio_read failed: %s", + UNEXPECTED_ERROR("isc_stdio_read failed: %s", isc_result_totext(result)); return (result); } @@ -2306,8 +2299,7 @@ load_header(dns_loadctx_t *lctx) { result = isc_stdio_read(data + commonlen, 1, remainder, lctx->f, NULL); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_stdio_read failed: %s", + UNEXPECTED_ERROR("isc_stdio_read failed: %s", isc_result_totext(result)); return (result); } @@ -2332,8 +2324,7 @@ openfile_raw(dns_loadctx_t *lctx, const char *master_file) { result = isc_stdio_open(master_file, "rb", &lctx->f); if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_stdio_open() failed: %s", + UNEXPECTED_ERROR("isc_stdio_open() failed: %s", isc_result_totext(result)); } diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index e2743de806..505de8394c 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -856,8 +856,7 @@ dns_rdataset_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, isc_result_t result; result = totext_ctx_init(&dns_master_style_debug, NULL, &ctx); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "could not set master file style"); + UNEXPECTED_ERROR("could not set master file style"); return (ISC_R_UNEXPECTED); } @@ -889,8 +888,7 @@ dns_master_rdatasettotext(const dns_name_t *owner_name, isc_result_t result; result = totext_ctx_init(style, indent, &ctx); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "could not set master file style"); + UNEXPECTED_ERROR("could not set master file style"); return (ISC_R_UNEXPECTED); } @@ -906,8 +904,7 @@ dns_master_questiontotext(const dns_name_t *owner_name, isc_result_t result; result = totext_ctx_init(style, NULL, &ctx); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "could not set master file style"); + UNEXPECTED_ERROR("could not set master file style"); return (ISC_R_UNEXPECTED); } @@ -982,8 +979,7 @@ dump_rdataset(isc_mem_t *mctx, const dns_name_t *name, dns_rdataset_t *rdataset, result = isc_stdio_write(r.base, 1, (size_t)r.length, f, NULL); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "master file write failed: %s", + UNEXPECTED_ERROR("master file write failed: %s", isc_result_totext(result)); return (result); } @@ -1265,8 +1261,7 @@ restart: result = isc_stdio_write(r.base, 1, (size_t)r.length, f, NULL); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "raw master file write failed: %s", + UNEXPECTED_ERROR("raw master file write failed: %s", isc_result_totext(result)); return (result); } @@ -1585,8 +1580,7 @@ dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, result = totext_ctx_init(style, NULL, &dctx->tctx); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "could not set master file style"); + UNEXPECTED_ERROR("could not set master file style"); goto cleanup; } @@ -1976,8 +1970,7 @@ dns_master_dumpnodetostream(isc_mem_t *mctx, dns_db_t *db, result = totext_ctx_init(style, NULL, &ctx); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "could not set master file style"); + UNEXPECTED_ERROR("could not set master file style"); return (ISC_R_UNEXPECTED); } diff --git a/lib/dns/name.c b/lib/dns/name.c index f1939d27d1..9fa238b14c 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1244,8 +1244,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, } break; default: - FATAL_ERROR(__FILE__, __LINE__, "Unexpected state %d", - state); + FATAL_ERROR("Unexpected state %d", state); /* Does not return. */ } } @@ -1467,8 +1466,7 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, count--; } } else { - FATAL_ERROR(__FILE__, __LINE__, - "Unexpected label type %02x", count); + FATAL_ERROR("Unexpected label type %02x", count); UNREACHABLE(); } @@ -1591,8 +1589,7 @@ dns_name_tofilenametext(const dns_name_t *name, bool omit_final_dot, count--; } } else { - FATAL_ERROR(__FILE__, __LINE__, - "Unexpected label type %02x", count); + FATAL_ERROR("Unexpected label type %02x", count); UNREACHABLE(); } @@ -1674,8 +1671,7 @@ dns_name_downcase(const dns_name_t *source, dns_name_t *name, count--; } } else { - FATAL_ERROR(__FILE__, __LINE__, - "Unexpected label type %02x", count); + FATAL_ERROR("Unexpected label type %02x", count); /* Does not return. */ } } @@ -1885,8 +1881,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, state = fw_start; break; default: - FATAL_ERROR(__FILE__, __LINE__, "Unknown state %d", - state); + FATAL_ERROR("Unknown state %d", state); /* Does not return. */ } } diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index d5b542aaa4..ea3c005d35 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -4436,7 +4436,7 @@ zone_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, UNUSED(rdataset); UNUSED(sigrdataset); - FATAL_ERROR(__FILE__, __LINE__, "zone_findzonecut() called!"); + FATAL_ERROR("zone_findzonecut() called!"); UNREACHABLE(); return (ISC_R_NOTIMPLEMENTED); diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index e7437656b6..4f2e363b99 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -1299,7 +1299,7 @@ fctx_stoptimer(fetchctx_t *fctx) { result = isc_timer_reset(fctx->timer, isc_timertype_inactive, NULL, NULL, true); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_timer_reset(): %s", + UNEXPECTED_ERROR("isc_timer_reset(): %s", isc_result_totext(result)); } } @@ -4907,8 +4907,7 @@ fctx_create(dns_resolver_t *res, isc_task_t *task, const dns_name_t *name, if (!dns_name_issubdomain(fctx->name, fctx->domain)) { dns_name_format(fctx->domain, buf, sizeof(buf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, - "'%s' is not subdomain of '%s'", fctx->info, + UNEXPECTED_ERROR("'%s' is not subdomain of '%s'", fctx->info, buf); result = ISC_R_UNEXPECTED; goto cleanup_fcount; @@ -4924,8 +4923,7 @@ fctx_create(dns_resolver_t *res, isc_task_t *task, const dns_name_t *name, res->query_timeout % 1000 * 1000000); iresult = isc_time_nowplusinterval(&fctx->expires, &interval); if (iresult != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_time_nowplusinterval: %s", + UNEXPECTED_ERROR("isc_time_nowplusinterval: %s", isc_result_totext(iresult)); result = ISC_R_UNEXPECTED; goto cleanup_qmessage; @@ -4941,7 +4939,7 @@ fctx_create(dns_resolver_t *res, isc_task_t *task, const dns_name_t *name, isc_interval_set(&interval, 2, 0); iresult = isc_time_add(&fctx->expires, &interval, &fctx->final); if (iresult != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_time_add: %s", + UNEXPECTED_ERROR("isc_time_add: %s", isc_result_totext(iresult)); result = ISC_R_UNEXPECTED; goto cleanup_qmessage; @@ -4956,7 +4954,7 @@ fctx_create(dns_resolver_t *res, isc_task_t *task, const dns_name_t *name, NULL, res->buckets[bucketnum].task, fctx_expired, fctx, &fctx->timer); if (iresult != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_timer_create: %s", + UNEXPECTED_ERROR("isc_timer_create: %s", isc_result_totext(iresult)); result = ISC_R_UNEXPECTED; goto cleanup_qmessage; @@ -4983,8 +4981,7 @@ fctx_create(dns_resolver_t *res, isc_task_t *task, const dns_name_t *name, iresult = isc_time_nowplusinterval(&fctx->expires_try_stale, &interval); if (iresult != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_time_nowplusinterval: %s", + UNEXPECTED_ERROR("isc_time_nowplusinterval: %s", isc_result_totext(iresult)); result = ISC_R_UNEXPECTED; goto cleanup_timer; diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index 90832b34d1..3e4cb54739 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -213,7 +213,7 @@ dns_rpz_type2str(dns_rpz_type_t type) { case DNS_RPZ_TYPE_BAD: break; } - FATAL_ERROR(__FILE__, __LINE__, "impossible rpz type %d", type); + FATAL_ERROR("impossible rpz type %d", type); return ("impossible"); } diff --git a/lib/dns/view.c b/lib/dns/view.c index f413cf2527..e1b9d5394d 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -123,8 +123,7 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, const char *name, view->zonetable = NULL; result = dns_zt_create(mctx, rdclass, &view->zonetable); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "dns_zt_create() failed: %s", + UNEXPECTED_ERROR("dns_zt_create() failed: %s", isc_result_totext(result)); result = ISC_R_UNEXPECTED; goto cleanup_mutex; @@ -135,8 +134,7 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, const char *name, view->fwdtable = NULL; result = dns_fwdtable_create(mctx, &view->fwdtable); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "dns_fwdtable_create() failed: %s", + UNEXPECTED_ERROR("dns_fwdtable_create() failed: %s", isc_result_totext(result)); result = ISC_R_UNEXPECTED; goto cleanup_zt; diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 3247fdea99..ce209780ef 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -5234,8 +5234,7 @@ zone_postload(dns_zone_t *zone, dns_db_t *db, isc_time_t loadtime, break; default: - UNEXPECTED_ERROR(__FILE__, __LINE__, "unexpected zone type %d", - zone->type); + UNEXPECTED_ERROR("unexpected zone type %d", zone->type); result = ISC_R_UNEXPECTED; goto cleanup; } diff --git a/lib/isc/app.c b/lib/isc/app.c index c60fd9a671..413a02640d 100644 --- a/lib/isc/app.c +++ b/lib/isc/app.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -75,10 +74,7 @@ handle_signal(int sig, void (*handler)(int)) { sa.sa_handler = handler; if (sigfillset(&sa.sa_mask) != 0 || sigaction(sig, &sa, NULL) < 0) { - char strbuf[ISC_STRERRORSIZE]; - strerror_r(errno, strbuf, sizeof(strbuf)); - isc_error_fatal(__FILE__, __LINE__, - "handle_signal() %d setup: %s", sig, strbuf); + FATAL_SYSERROR(errno, "signal %d", sig); } } @@ -86,7 +82,6 @@ isc_result_t isc_app_ctxstart(isc_appctx_t *ctx) { int presult; sigset_t sset; - char strbuf[ISC_STRERRORSIZE]; REQUIRE(VALID_APPCTX(ctx)); @@ -128,15 +123,11 @@ isc_app_ctxstart(isc_appctx_t *ctx) { if (sigemptyset(&sset) != 0 || sigaddset(&sset, SIGHUP) != 0 || sigaddset(&sset, SIGINT) != 0 || sigaddset(&sset, SIGTERM) != 0) { - strerror_r(errno, strbuf, sizeof(strbuf)); - isc_error_fatal(__FILE__, __LINE__, - "isc_app_start() sigsetops: %s", strbuf); + FATAL_SYSERROR(errno, "sigsetops"); } presult = pthread_sigmask(SIG_BLOCK, &sset, NULL); if (presult != 0) { - strerror_r(presult, strbuf, sizeof(strbuf)); - isc_error_fatal(__FILE__, __LINE__, - "isc_app_start() pthread_sigmask: %s", strbuf); + FATAL_SYSERROR(presult, "pthread_sigmask()"); } return (ISC_R_SUCCESS); @@ -226,11 +217,7 @@ isc_app_ctxrun(isc_appctx_t *ctx) { sigaddset(&sset, SIGINT) != 0 || sigaddset(&sset, SIGTERM) != 0) { - char strbuf[ISC_STRERRORSIZE]; - strerror_r(errno, strbuf, sizeof(strbuf)); - isc_error_fatal(__FILE__, __LINE__, - "isc_app_run() sigsetops: %s", - strbuf); + FATAL_SYSERROR(errno, "sigsetops"); } if (sigwait(&sset, &sig) == 0) { @@ -315,12 +302,7 @@ isc_app_ctxshutdown(isc_appctx_t *ctx) { } else { /* Normal single BIND9 context */ if (kill(getpid(), SIGTERM) < 0) { - char strbuf[ISC_STRERRORSIZE]; - strerror_r(errno, strbuf, sizeof(strbuf)); - isc_error_fatal(__FILE__, __LINE__, - "isc_app_shutdown() " - "kill: %s", - strbuf); + FATAL_SYSERROR(errno, "kill"); } } } @@ -348,12 +330,7 @@ isc_app_ctxsuspend(isc_appctx_t *ctx) { } else { /* Normal single BIND9 context */ if (kill(getpid(), SIGHUP) < 0) { - char strbuf[ISC_STRERRORSIZE]; - strerror_r(errno, strbuf, sizeof(strbuf)); - isc_error_fatal(__FILE__, __LINE__, - "isc_app_reload() " - "kill: %s", - strbuf); + FATAL_SYSERROR(errno, "kill"); } } } diff --git a/lib/isc/assertions.c b/lib/isc/assertions.c index 8b954cf475..e9a7935a1d 100644 --- a/lib/isc/assertions.c +++ b/lib/isc/assertions.c @@ -20,7 +20,6 @@ #include #include #include -#include /* * The maximum number of stack frames to dump on assertion failure. diff --git a/lib/isc/condition.c b/lib/isc/condition.c index 19c16be6b1..18fab69b5a 100644 --- a/lib/isc/condition.c +++ b/lib/isc/condition.c @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -26,7 +25,6 @@ isc_condition_waituntil(isc_condition_t *c, isc_mutex_t *m, isc_time_t *t) { int presult; isc_result_t result; struct timespec ts; - char strbuf[ISC_STRERRORSIZE]; REQUIRE(c != NULL && m != NULL && t != NULL); @@ -61,8 +59,6 @@ isc_condition_waituntil(isc_condition_t *c, isc_mutex_t *m, isc_time_t *t) { } } while (presult == EINTR); - strerror_r(presult, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, - "pthread_cond_timedwait() returned %s", strbuf); + UNEXPECTED_SYSERROR(presult, "pthread_cond_timedwait()"); return (ISC_R_UNEXPECTED); } diff --git a/lib/isc/entropy.c b/lib/isc/entropy.c index ce79ba21c3..38fcfa0df7 100644 --- a/lib/isc/entropy.c +++ b/lib/isc/entropy.c @@ -22,7 +22,7 @@ void isc_entropy_get(void *buf, size_t buflen) { if (RAND_bytes(buf, buflen) < 1) { - FATAL_ERROR(__FILE__, __LINE__, "RAND_bytes(): %s", + FATAL_ERROR("RAND_bytes(): %s", ERR_error_string(ERR_get_error(), NULL)); } } diff --git a/lib/isc/error.c b/lib/isc/error.c index 336be8432e..051a6c48aa 100644 --- a/lib/isc/error.c +++ b/lib/isc/error.c @@ -21,12 +21,12 @@ /*% Default unexpected callback. */ static void -default_unexpected_callback(const char *, int, const char *, va_list) - ISC_FORMAT_PRINTF(3, 0); +default_unexpected_callback(const char *, int, const char *, const char *, + va_list) ISC_FORMAT_PRINTF(4, 0); /*% Default fatal callback. */ static void -default_fatal_callback(const char *, int, const char *, va_list) +default_fatal_callback(const char *, int, const char *, const char *, va_list) ISC_FORMAT_PRINTF(3, 0); /*% unexpected_callback */ @@ -52,42 +52,39 @@ isc_error_setfatal(isc_errorcallback_t cb) { } void -isc_error_unexpected(const char *file, int line, const char *format, ...) { +isc_error_unexpected(const char *file, int line, const char *func, + const char *format, ...) { va_list args; va_start(args, format); - (unexpected_callback)(file, line, format, args); + (unexpected_callback)(file, line, func, format, args); va_end(args); } void -isc_error_fatal(const char *file, int line, const char *format, ...) { +isc_error_fatal(const char *file, int line, const char *func, + const char *format, ...) { va_list args; va_start(args, format); - (fatal_callback)(file, line, format, args); + (fatal_callback)(file, line, func, format, args); va_end(args); abort(); } -void -isc_error_runtimecheck(const char *file, int line, const char *expression) { - isc_error_fatal(file, line, "RUNTIME_CHECK(%s) failed", expression); -} - static void -default_unexpected_callback(const char *file, int line, const char *format, - va_list args) { - fprintf(stderr, "%s:%d: ", file, line); +default_unexpected_callback(const char *file, int line, const char *func, + const char *format, va_list args) { + fprintf(stderr, "%s:%d:%s(): ", file, line, func); vfprintf(stderr, format, args); fprintf(stderr, "\n"); fflush(stderr); } static void -default_fatal_callback(const char *file, int line, const char *format, - va_list args) { - fprintf(stderr, "%s:%d: fatal error: ", file, line); +default_fatal_callback(const char *file, int line, const char *func, + const char *format, va_list args) { + fprintf(stderr, "%s:%d:%s(): fatal error: ", file, line, func); vfprintf(stderr, format, args); fprintf(stderr, "\n"); fflush(stderr); diff --git a/lib/isc/include/isc/condition.h b/lib/isc/include/isc/condition.h index 54e497df0f..0e1dcf135b 100644 --- a/lib/isc/include/isc/condition.h +++ b/lib/isc/include/isc/condition.h @@ -27,14 +27,9 @@ typedef pthread_cond_t isc_condition_t; -#define isc_condition_init(cond) \ - if (pthread_cond_init(cond, NULL) != 0) { \ - char isc_condition_strbuf[ISC_STRERRORSIZE]; \ - strerror_r(errno, isc_condition_strbuf, \ - sizeof(isc_condition_strbuf)); \ - isc_error_fatal(__FILE__, __LINE__, \ - "pthread_cond_init failed: %s", \ - isc_condition_strbuf); \ +#define isc_condition_init(cond) \ + if (pthread_cond_init(cond, NULL) != 0) { \ + FATAL_SYSERROR(errno, "pthread_cond_init()"); \ } #define isc_condition_wait(cp, mp) \ diff --git a/lib/isc/include/isc/error.h b/lib/isc/include/isc/error.h index ecebab60a2..f4f668203f 100644 --- a/lib/isc/include/isc/error.h +++ b/lib/isc/include/isc/error.h @@ -23,7 +23,8 @@ ISC_LANG_BEGINDECLS -typedef void (*isc_errorcallback_t)(const char *, int, const char *, va_list); +typedef void (*isc_errorcallback_t)(const char *, int, const char *, + const char *, va_list); /*% set unexpected error */ void isc_error_setunexpected(isc_errorcallback_t); @@ -33,19 +34,12 @@ void isc_error_setfatal(isc_errorcallback_t); /*% unexpected error */ void -isc_error_unexpected(const char *, int, const char *, ...) - ISC_FORMAT_PRINTF(3, 4); +isc_error_unexpected(const char *, int, const char *, const char *, ...) + ISC_FORMAT_PRINTF(4, 5); /*% fatal error */ noreturn void -isc_error_fatal(const char *, int, const char *, ...) ISC_FORMAT_PRINTF(3, 4); - -/*% runtimecheck error */ -noreturn void -isc_error_runtimecheck(const char *, int, const char *); - -#define ISC_ERROR_RUNTIMECHECK(cond) \ - ((void)((cond) || \ - ((isc_error_runtimecheck)(__FILE__, __LINE__, #cond), 0))) +isc_error_fatal(const char *, int, const char *, const char *, ...) + ISC_FORMAT_PRINTF(4, 5); ISC_LANG_ENDDECLS diff --git a/lib/isc/include/isc/mutex.h b/lib/isc/include/isc/mutex.h index c454dd2b24..b7942169ef 100644 --- a/lib/isc/include/isc/mutex.h +++ b/lib/isc/include/isc/mutex.h @@ -25,10 +25,16 @@ ISC_LANG_BEGINDECLS typedef pthread_mutex_t isc_mutex_t; -void -isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line); +int +isc__mutex_init(isc_mutex_t *mp); -#define isc_mutex_init(mp) isc__mutex_init((mp), __FILE__, __LINE__) +#define isc_mutex_init(mp) \ + do { \ + int _err = isc__mutex_init((mp)); \ + if (_err != 0) { \ + FATAL_SYSERROR(_err, "pthread_mutex_init()"); \ + } \ + } while (0) #define isc_mutex_lock(mp) \ ((pthread_mutex_lock((mp)) == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED) diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 1409710fbc..6b8e581450 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -309,24 +309,39 @@ mock_assert(const int result, const char *const expression, /* * Errors */ -#include /* Contractual promise. */ +#include /* Contractual promise. */ +#include /* for ISC_STRERRORSIZE */ -/*% Unexpected Error */ -#define UNEXPECTED_ERROR isc_error_unexpected -/*% Fatal Error */ -#define FATAL_ERROR isc_error_fatal +#define UNEXPECTED_ERROR(...) \ + isc_error_unexpected(__FILE__, __LINE__, __func__, __VA_ARGS__) + +#define FATAL_ERROR(...) \ + isc_error_fatal(__FILE__, __LINE__, __func__, __VA_ARGS__) + +#define REPORT_SYSERROR(report, err, fmt, ...) \ + { \ + char strerr[ISC_STRERRORSIZE]; \ + strerror_r(err, strerr, sizeof(strerr)); \ + report(__FILE__, __LINE__, __func__, fmt ": %s (%d)", \ + ##__VA_ARGS__, strerr, err); \ + } + +#define UNEXPECTED_SYSERROR(err, ...) \ + REPORT_SYSERROR(isc_error_unexpected, err, __VA_ARGS__) + +#define FATAL_SYSERROR(err, ...) \ + REPORT_SYSERROR(isc_error_fatal, err, __VA_ARGS__) #ifdef UNIT_TESTING -#define RUNTIME_CHECK(expression) \ - ((!(expression)) \ - ? (mock_assert(0, #expression, __FILE__, __LINE__), abort()) \ - : (void)0) +#define RUNTIME_CHECK(cond) \ + ((cond) ? (void)0 \ + : (mock_assert(0, #cond, __FILE__, __LINE__), abort())) #else /* UNIT_TESTING */ -/*% Runtime Check */ -#define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond) +#define RUNTIME_CHECK(cond) \ + ((cond) ? (void)0 : FATAL_ERROR("RUNTIME_CHECK(%s) failed", #cond)) #endif /* UNIT_TESTING */ diff --git a/lib/isc/interfaceiter.c b/lib/isc/interfaceiter.c index abb16f4b6d..566c5bd465 100644 --- a/lib/isc/interfaceiter.c +++ b/lib/isc/interfaceiter.c @@ -202,8 +202,7 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) { if (getifaddrs(&iter->ifaddrs) < 0) { strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, - "getting interface addresses: getifaddrs: %s", + UNEXPECTED_ERROR("getting interface addresses: getifaddrs: %s", strbuf); result = ISC_R_UNEXPECTED; goto failure; diff --git a/lib/isc/lex.c b/lib/isc/lex.c index 50218b78b3..63b9b79d34 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -902,8 +902,7 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { remaining--; break; default: - FATAL_ERROR(__FILE__, __LINE__, "Unexpected state %d", - state); + FATAL_ERROR("Unexpected state %d", state); } } while (!done); diff --git a/lib/isc/managers.c b/lib/isc/managers.c index 63ef09e5b4..5e9a6c3731 100644 --- a/lib/isc/managers.c +++ b/lib/isc/managers.c @@ -37,8 +37,7 @@ isc_managers_create(isc_mem_t *mctx, size_t workers, size_t quantum, INSIST(netmgr != NULL); result = isc__taskmgr_create(mctx, quantum, netmgr, &taskmgr); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_taskmgr_create() failed: %s", + UNEXPECTED_ERROR("isc_taskmgr_create() failed: %s", isc_result_totext(result)); goto fail; } @@ -49,8 +48,7 @@ isc_managers_create(isc_mem_t *mctx, size_t workers, size_t quantum, if (timermgrp != NULL) { result = isc__timermgr_create(mctx, &timermgr); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_timermgr_create() failed: %s", + UNEXPECTED_ERROR("isc_timermgr_create() failed: %s", isc_result_totext(result)); goto fail; } diff --git a/lib/isc/mem.c b/lib/isc/mem.c index f828672119..e99471b0b2 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -1236,10 +1235,7 @@ isc__mempool_destroy(isc_mempool_t **restrict mpctxp FLARG) { #endif if (mpctx->allocated > 0) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "isc_mempool_destroy(): mempool %s " - "leaked memory", - mpctx->name); + UNEXPECTED_ERROR("mempool %s leaked memory", mpctx->name); } REQUIRE(mpctx->allocated == 0); diff --git a/lib/isc/mutex.c b/lib/isc/mutex.c index 0b050fa43d..65f1663a5c 100644 --- a/lib/isc/mutex.c +++ b/lib/isc/mutex.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -40,23 +39,15 @@ initialize_attr(void) { } #endif /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP */ -void -isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) { - int err; - +int +isc__mutex_init(isc_mutex_t *mp) { #ifdef HAVE_PTHREAD_MUTEX_ADAPTIVE_NP isc_result_t result = ISC_R_SUCCESS; result = isc_once_do(&once_attr, initialize_attr); RUNTIME_CHECK(result == ISC_R_SUCCESS); - err = pthread_mutex_init(mp, &attr); + return (pthread_mutex_init(mp, &attr)); #else /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP */ - err = pthread_mutex_init(mp, NULL); + return (pthread_mutex_init(mp, NULL)); #endif /* HAVE_PTHREAD_MUTEX_ADAPTIVE_NP */ - if (err != 0) { - char strbuf[ISC_STRERRORSIZE]; - strerror_r(err, strbuf, sizeof(strbuf)); - isc_error_fatal(file, line, "pthread_mutex_init failed: %s", - strbuf); - } } diff --git a/lib/isc/net.c b/lib/isc/net.c index efb9ff1ccf..4fdc87ee45 100644 --- a/lib/isc/net.c +++ b/lib/isc/net.c @@ -122,7 +122,6 @@ static isc_result_t try_proto(int domain) { int s; isc_result_t result = ISC_R_SUCCESS; - char strbuf[ISC_STRERRORSIZE]; s = socket(domain, SOCK_STREAM, 0); if (s == -1) { @@ -141,9 +140,7 @@ try_proto(int domain) { #endif /* ifdef EINVAL */ return (ISC_R_NOTFOUND); default: - strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, - "socket() failed: %s", strbuf); + UNEXPECTED_SYSERROR(errno, "socket()"); return (ISC_R_UNEXPECTED); } } @@ -223,7 +220,6 @@ static void try_ipv6only(void) { #ifdef IPV6_V6ONLY int s, on; - char strbuf[ISC_STRERRORSIZE]; #endif /* ifdef IPV6_V6ONLY */ isc_result_t result; @@ -240,9 +236,7 @@ try_ipv6only(void) { /* check for TCP sockets */ s = socket(PF_INET6, SOCK_STREAM, 0); if (s == -1) { - strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, "socket() failed: %s", - strbuf); + UNEXPECTED_SYSERROR(errno, "socket()"); ipv6only_result = ISC_R_UNEXPECTED; return; } @@ -258,9 +252,7 @@ try_ipv6only(void) { /* check for UDP sockets */ s = socket(PF_INET6, SOCK_DGRAM, 0); if (s == -1) { - strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, "socket() failed: %s", - strbuf); + UNEXPECTED_SYSERROR(errno, "socket()"); ipv6only_result = ISC_R_UNEXPECTED; return; } @@ -289,7 +281,6 @@ initialize_ipv6only(void) { static void try_ipv6pktinfo(void) { int s, on; - char strbuf[ISC_STRERRORSIZE]; isc_result_t result; int optname; @@ -302,9 +293,7 @@ try_ipv6pktinfo(void) { /* we only use this for UDP sockets */ s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); if (s == -1) { - strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, "socket() failed: %s", - strbuf); + UNEXPECTED_SYSERROR(errno, "socket()"); ipv6pktinfo_result = ISC_R_UNEXPECTED; return; } @@ -411,11 +400,10 @@ static isc_result_t make_nonblock(int fd) { int ret; int flags; - char strbuf[ISC_STRERRORSIZE]; -#ifdef USE_FIONBIO_IOCTL - int on = 1; - ret = ioctl(fd, FIONBIO, (char *)&on); +#ifdef USE_FIONBIO_IOCTL + flags = 1; + ret = ioctl(fd, FIONBIO, (char *)&flags); #else /* ifdef USE_FIONBIO_IOCTL */ flags = fcntl(fd, F_GETFL, 0); flags |= O_NONBLOCK; @@ -423,15 +411,11 @@ make_nonblock(int fd) { #endif /* ifdef USE_FIONBIO_IOCTL */ if (ret == -1) { - strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, #ifdef USE_FIONBIO_IOCTL - "ioctl(%d, FIONBIO, &on): %s", fd, -#else /* ifdef USE_FIONBIO_IOCTL */ - "fcntl(%d, F_SETFL, %d): %s", fd, flags, -#endif /* ifdef USE_FIONBIO_IOCTL */ - strbuf); - + UNEXPECTED_SYSERROR(errno, "ioctl(%d, FIONBIO, &on)", fd); +#else + UNEXPECTED_SYSERROR(errno, "fcntl(%d, F_SETFL, %d)", fd, flags); +#endif return (ISC_R_UNEXPECTED); } @@ -510,8 +494,6 @@ cmsgsend(int s, int level, int type, struct addrinfo *res) { } if (sendmsg(s, &msg, 0) < 0) { - int debug = ISC_LOG_DEBUG(10); - const char *typestr; switch (errno) { #ifdef ENOPROTOOPT case ENOPROTOOPT: @@ -521,21 +503,17 @@ cmsgsend(int s, int level, int type, struct addrinfo *res) { #endif /* ifdef EOPNOTSUPP */ case EINVAL: case EPERM: - break; - default: - debug = ISC_LOG_NOTICE; - } - strerror_r(errno, strbuf, sizeof(strbuf)); - if (debug != ISC_LOG_NOTICE) { + strerror_r(errno, strbuf, sizeof(strbuf)); isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_DEBUG(10), "sendmsg: %s", strbuf); - } else { - typestr = (type == IP_TOS) ? "IP_TOS" : "IPV6_TCLASS"; - UNEXPECTED_ERROR(__FILE__, __LINE__, - "probing " - "sendmsg() with %s=%02x failed: %s", - typestr, dscp, strbuf); + break; + default: + UNEXPECTED_SYSERROR( + errno, "probing sendmsg() with %s=%02x failed", + (type == IP_TOS) ? "IP_TOS" : "IPV6_TCLASS", + dscp); + break; } return (false); } @@ -595,7 +573,6 @@ try_dscp_v4(void) { } s = socket(res0->ai_family, res0->ai_socktype, res0->ai_protocol); - if (s == -1) { strerror_r(errno, strbuf, sizeof(strbuf)); isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 0aba2b8b59..2a51fe35ca 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -2235,10 +2235,9 @@ isc__nmsocket_readtimeout_cb(uv_timer_t *timer); void isc__nmsocket_writetimeout_cb(void *data, isc_result_t eresult); -#define UV_RUNTIME_CHECK(func, ret) \ - if (ret != 0) { \ - isc_error_fatal(__FILE__, __LINE__, "%s failed: %s\n", #func, \ - uv_strerror(ret)); \ +#define UV_RUNTIME_CHECK(func, ret) \ + if (ret != 0) { \ + FATAL_ERROR("%s failed: %s\n", #func, uv_strerror(ret)); \ } void diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 256e93967c..57d5390c68 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -227,11 +226,10 @@ isc__netmgr_create(isc_mem_t *mctx, uint32_t workers, isc_nm_t **netmgrp) { REQUIRE(workers > 0); if (uv_version() < MINIMAL_UV_VERSION) { - isc_error_fatal(__FILE__, __LINE__, - "libuv version too old: running with libuv %s " - "when compiled with libuv %s will lead to " - "libuv failures because of unknown flags", - uv_version_string(), UV_VERSION_STRING); + FATAL_ERROR("libuv version too old: running with libuv %s " + "when compiled with libuv %s will lead to " + "libuv failures because of unknown flags", + uv_version_string(), UV_VERSION_STRING); } isc__nm_threadpool_initialize(workers); diff --git a/lib/isc/netmgr/uverr2result.c b/lib/isc/netmgr/uverr2result.c index 5ce953d729..99ed1b3aa9 100644 --- a/lib/isc/netmgr/uverr2result.c +++ b/lib/isc/netmgr/uverr2result.c @@ -15,7 +15,6 @@ #include #include -#include #include #include diff --git a/lib/isc/rwlock.c b/lib/isc/rwlock.c index 2691a44de4..9a56dc30a1 100644 --- a/lib/isc/rwlock.c +++ b/lib/isc/rwlock.c @@ -208,8 +208,7 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota, rwl->readers_waiting = 0; atomic_init(&rwl->write_granted, 0); if (read_quota != 0) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "read quota is not supported"); + UNEXPECTED_ERROR("read quota is not supported"); } if (write_quota == 0) { write_quota = RWLOCK_DEFAULT_WRITE_QUOTA; diff --git a/lib/isc/sockaddr.c b/lib/isc/sockaddr.c index 85b3d28439..038e3ec7c4 100644 --- a/lib/isc/sockaddr.c +++ b/lib/isc/sockaddr.c @@ -234,8 +234,7 @@ isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, bool address_only) { p = ntohs(sockaddr->type.sin6.sin6_port); break; default: - UNEXPECTED_ERROR(__FILE__, __LINE__, - "unknown address family: %d", + UNEXPECTED_ERROR("unknown address family: %d", (int)sockaddr->type.sa.sa_family); s = (const unsigned char *)&sockaddr->type; length = sockaddr->length; @@ -341,7 +340,7 @@ isc_sockaddr_pf(const isc_sockaddr_t *sockaddr) { case AF_INET6: return (PF_INET6); default: - FATAL_ERROR(__FILE__, __LINE__, "unknown address family: %d", + FATAL_ERROR("unknown address family: %d", (int)sockaddr->type.sa.sa_family); } #endif /* if (AF_INET == PF_INET && AF_INET6 == PF_INET6) */ @@ -380,7 +379,7 @@ isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port) { sockaddr->type.sin6.sin6_port = htons(port); break; default: - FATAL_ERROR(__FILE__, __LINE__, "unknown address family: %d", + FATAL_ERROR("unknown address family: %d", (int)sockaddr->type.sa.sa_family); } } @@ -397,7 +396,7 @@ isc_sockaddr_getport(const isc_sockaddr_t *sockaddr) { port = ntohs(sockaddr->type.sin6.sin6_port); break; default: - FATAL_ERROR(__FILE__, __LINE__, "unknown address family: %d", + FATAL_ERROR("unknown address family: %d", (int)sockaddr->type.sa.sa_family); } diff --git a/lib/isc/stdtime.c b/lib/isc/stdtime.c index ada19d0ef5..574d149b67 100644 --- a/lib/isc/stdtime.c +++ b/lib/isc/stdtime.c @@ -21,7 +21,6 @@ #include #include -#include #include #define NS_PER_S 1000000000 /*%< Nanoseconds per second. */ @@ -41,10 +40,7 @@ isc_stdtime_get(isc_stdtime_t *t) { struct timespec ts; if (clock_gettime(CLOCKSOURCE, &ts) == -1) { - char strbuf[ISC_STRERRORSIZE]; - strerror_r(errno, strbuf, sizeof(strbuf)); - isc_error_fatal(__FILE__, __LINE__, "clock_gettime failed: %s", - strbuf); + FATAL_SYSERROR(errno, "clock_gettime()"); } REQUIRE(ts.tv_sec > 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_S); diff --git a/lib/isc/thread.c b/lib/isc/thread.c index 4c7380cac1..5b762edcb9 100644 --- a/lib/isc/thread.c +++ b/lib/isc/thread.c @@ -28,7 +28,6 @@ #include #endif /* if defined(HAVE_SYS_PROCSET_H) */ -#include #include #include @@ -38,13 +37,6 @@ #define THREAD_MINSTACKSIZE (1024U * 1024) #endif /* ifndef THREAD_MINSTACKSIZE */ -#define _FATAL(r, f) \ - { \ - char strbuf[ISC_STRERRORSIZE]; \ - strerror_r(r, strbuf, sizeof(strbuf)); \ - isc_error_fatal(__FILE__, __LINE__, f " failed: %s", strbuf); \ - } - void isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg, isc_thread_t *thread) { @@ -66,13 +58,13 @@ isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg, defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) ret = pthread_attr_getstacksize(&attr, &stacksize); if (ret != 0) { - _FATAL(ret, "pthread_attr_getstacksize()"); + FATAL_SYSERROR(ret, "pthread_attr_getstacksize()"); } if (stacksize < THREAD_MINSTACKSIZE) { ret = pthread_attr_setstacksize(&attr, THREAD_MINSTACKSIZE); if (ret != 0) { - _FATAL(ret, "pthread_attr_setstacksize()"); + FATAL_SYSERROR(ret, "pthread_attr_setstacksize()"); } } #endif /* if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \ @@ -81,7 +73,7 @@ isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg, ret = pthread_create(thread, &attr, isc__trampoline_run, trampoline_arg); if (ret != 0) { - _FATAL(ret, "pthread_create()"); + FATAL_SYSERROR(ret, "pthread_create()"); } pthread_attr_destroy(&attr); @@ -93,7 +85,7 @@ void isc_thread_join(isc_thread_t thread, isc_threadresult_t *result) { int ret = pthread_join(thread, result); if (ret != 0) { - _FATAL(ret, "pthread_join()"); + FATAL_SYSERROR(ret, "pthread_join()"); } } diff --git a/lib/isc/time.c b/lib/isc/time.c index 4f6c4a03c3..05c67ffc0a 100644 --- a/lib/isc/time.c +++ b/lib/isc/time.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -131,13 +130,11 @@ isc_time_isepoch(const isc_time_t *t) { static isc_result_t time_now(isc_time_t *t, clockid_t clock) { struct timespec ts; - char strbuf[ISC_STRERRORSIZE]; REQUIRE(t != NULL); if (clock_gettime(clock, &ts) == -1) { - strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, "%s", strbuf); + UNEXPECTED_SYSERROR(errno, "clock_gettime()"); return (ISC_R_UNEXPECTED); } @@ -173,15 +170,13 @@ isc_time_now(isc_time_t *t) { isc_result_t isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) { struct timespec ts; - char strbuf[ISC_STRERRORSIZE]; REQUIRE(t != NULL); REQUIRE(i != NULL); INSIST(i->nanoseconds < NS_PER_S); if (clock_gettime(CLOCKSOURCE, &ts) == -1) { - strerror_r(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, "%s", strbuf); + UNEXPECTED_SYSERROR(errno, "clock_gettime()"); return (ISC_R_UNEXPECTED); } diff --git a/lib/isc/timer.c b/lib/isc/timer.c index 30de75632f..a9d15cb390 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -565,9 +566,7 @@ dispatch(isc_timermgr_t *manager, isc_time_t *now) { isc_task_send(timer->task, ISC_EVENT_PTR(&event)); } else { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "%s", - "couldn't allocate " + UNEXPECTED_ERROR("couldn't allocate " "event"); } } @@ -579,11 +578,9 @@ dispatch(isc_timermgr_t *manager, isc_time_t *now) { if (need_schedule) { result = schedule(timer, now, false); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "%s: %u", - "couldn't schedule " - "timer", - result); + UNEXPECTED_ERROR( + "couldn't schedule timer: %s", + isc_result_totext(result)); } } } else { diff --git a/lib/isc/tls.c b/lib/isc/tls.c index 4dc848260e..f92a6ac049 100644 --- a/lib/isc/tls.c +++ b/lib/isc/tls.c @@ -122,8 +122,7 @@ tls_initialize(void) { /* Protect ourselves against unseeded PRNG */ if (RAND_status() != 1) { - FATAL_ERROR(__FILE__, __LINE__, - "OpenSSL pseudorandom number generator " + FATAL_ERROR("OpenSSL pseudorandom number generator " "cannot be initialized (see the `PRNG not " "seeded' message in the OpenSSL FAQ)"); } diff --git a/lib/ns/interfacemgr.c b/lib/ns/interfacemgr.c index d02493244e..10deb55fb9 100644 --- a/lib/ns/interfacemgr.c +++ b/lib/ns/interfacemgr.c @@ -1317,8 +1317,7 @@ do_scan(ns_interfacemgr_t *mgr, bool verbose, bool config) { continue; } if (result != ISC_R_NOMORE) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "interface iteration failed: %s", + UNEXPECTED_ERROR("interface iteration failed: %s", isc_result_totext(result)); } else { result = ((tried_listening && all_addresses_in_use) diff --git a/lib/ns/sortlist.c b/lib/ns/sortlist.c index 3e6a3517e9..2aada90b19 100644 --- a/lib/ns/sortlist.c +++ b/lib/ns/sortlist.c @@ -173,10 +173,9 @@ ns_sortlist_byaddrsetup(dns_acl_t *sortlist_acl, dns_aclenv_t *env, *orderp = NULL; break; default: - UNEXPECTED_ERROR(__FILE__, __LINE__, - "unexpected return from ns_sortlist_setup(): " - "%d", - sortlisttype); + UNEXPECTED_ERROR( + "unexpected return from ns_sortlist_setup(): %d", + sortlisttype); break; } } diff --git a/lib/ns/update.c b/lib/ns/update.c index 24bd3c3677..a0599cad65 100644 --- a/lib/ns/update.c +++ b/lib/ns/update.c @@ -2746,10 +2746,9 @@ update_action(isc_task_t *task, isc_event_t *event) { /* "temp += rr;" */ result = temp_append(&temp, name, &rdata); if (result != ISC_R_SUCCESS) { - UNEXPECTED_ERROR(__FILE__, __LINE__, - "temp entry creation failed: " - "%s", - isc_result_totext(result)); + UNEXPECTED_ERROR( + "temp entry creation failed: %s", + isc_result_totext(result)); FAIL(ISC_R_UNEXPECTED); } } else {