From c10a8e43c19507831461a4c317a3dae4cba3f449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20K=2E=20Guti=C3=A9rrez?= Date: Sat, 27 Apr 2024 17:18:51 -0600 Subject: [PATCH] Add qvi_abort() with minor cleanups. (#124) Signed-off-by: Samuel K. Gutierrez --- src/qvi-hwloc.cc | 8 ++++---- src/qvi-macros.h | 9 +++++++++ src/qvi-scope.cc | 4 ++-- src/qvi-utils.cc | 20 ++++++++++---------- src/qvi-utils.h | 12 ++++++------ 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/qvi-hwloc.cc b/src/qvi-hwloc.cc index ef57446a..2cea7d02 100644 --- a/src/qvi-hwloc.cc +++ b/src/qvi-hwloc.cc @@ -157,7 +157,7 @@ qvi_hwloc_get_obj_type( return HWLOC_OBJ_OS_DEVICE; default: // This is an internal development error. - abort(); + qvi_abort(); } } @@ -182,7 +182,7 @@ qvi_hwloc_obj_type_is_host_resource( return false; default: // This is an internal development error. - abort(); + qvi_abort(); } } @@ -949,13 +949,13 @@ qvi_hwloc_cpuset_debug( #endif if (!cpuset) { - abort(); + qvi_abort(); } char *cpusets = nullptr; int rc = qvi_hwloc_bitmap_asprintf(&cpusets, cpuset); if (rc != QV_SUCCESS) { - abort(); + qvi_abort(); } qvi_log_debug("{} CPUSET={}", msg, cpusets); diff --git a/src/qvi-macros.h b/src/qvi-macros.h index b520cb3f..82214a07 100644 --- a/src/qvi-macros.h +++ b/src/qvi-macros.h @@ -30,6 +30,15 @@ do { \ (void)(x); \ } while (0) +/** + * Prints abort location then calls abort(). + */ +#define qvi_abort() \ +do { \ + qvi_log_info("abort() raised at {}:{}", __FILE__, __LINE__); \ + abort(); \ +} while (0) + /** * Convenience macro for new(std::nothrow). */ diff --git a/src/qvi-scope.cc b/src/qvi-scope.cc index 7860f9b4..da2c0a59 100644 --- a/src/qvi-scope.cc +++ b/src/qvi-scope.cc @@ -862,7 +862,7 @@ agg_split_user_defined( if (rc != QV_SUCCESS) return rc; // Developer sanity check. if (cpusets.size() != split_size) { - abort(); + qvi_abort(); return QV_ERR_INTERNAL; } // Maintains the mapping between task (consumer) IDs and resource IDs. @@ -947,7 +947,7 @@ agg_split_affinity_preserving_pass1( if (rc != QV_SUCCESS) return rc; // Make sure that we mapped all the tasks. If not, this is a bug. if (qvi_map_nfids_mapped(map) != group_size) { - abort(); + qvi_abort(); return QV_ERR_INTERNAL; } // Update the hardware pools and colors to reflect the new mapping. diff --git a/src/qvi-utils.cc b/src/qvi-utils.cc index dccc5e8b..37eb80bf 100644 --- a/src/qvi-utils.cc +++ b/src/qvi-utils.cc @@ -53,7 +53,7 @@ qv_strerr(int ec) return got->second.c_str(); } -char * +cstr_t qvi_strerr(int ec) { static thread_local char sb[1024]; @@ -77,7 +77,7 @@ qvi_time(void) bool qvi_path_usable( - const char *path, + const cstr_t path, int *errc ) { *errc = 0; @@ -124,7 +124,7 @@ int qvi_port( int *port ) { - cstr_t ports = getenv(QVI_ENV_PORT); + const cstr_t ports = getenv(QVI_ENV_PORT); if (!ports) return QV_ERR_ENV; return qvi_atoi(ports, port); } @@ -135,7 +135,7 @@ qvi_url( ) { static const cstr_t base = "tcp://127.0.0.1"; - int port; + int port = 0; int rc = qvi_port(&port); if (rc != QV_SUCCESS) return rc; @@ -145,7 +145,7 @@ qvi_url( return QV_SUCCESS; } -const char * +cstr_t qvi_conn_ers(void) { static const cstr_t msg = "Cannot determine connection information. " @@ -155,7 +155,7 @@ qvi_conn_ers(void) return msg; } -const char * +cstr_t qvi_tmpdir(void) { static thread_local char tmpdir[PATH_MAX]; @@ -174,7 +174,7 @@ qvi_tmpdir(void) return tmp; } -const char * +cstr_t qvi_whoami(void) { static const int bsize = 128; @@ -183,18 +183,18 @@ qvi_whoami(void) if (!user) { user = PACKAGE_NAME; } - int nw = snprintf(buff, bsize, "%s", user); + const int nw = snprintf(buff, bsize, "%s", user); if (nw >= bsize) return PACKAGE_NAME; return buff; } int qvi_file_size( - const char *path, + const cstr_t path, size_t *size ) { struct stat st; - int rc = stat(path, &st); + const int rc = stat(path, &st); if (rc == -1) return QV_ERR_FILE_IO; *size = st.st_size; return QV_SUCCESS; diff --git a/src/qvi-utils.h b/src/qvi-utils.h index 47cd2fac..1ee1c100 100644 --- a/src/qvi-utils.h +++ b/src/qvi-utils.h @@ -89,7 +89,7 @@ extern "C" { /** * */ -char * +cstr_t qvi_strerr(int ec); /** @@ -109,7 +109,7 @@ qvi_time(void); */ bool qvi_path_usable( - const char *path, + const cstr_t path, int *errc ); @@ -133,19 +133,19 @@ qvi_url( /** * */ -const char * +cstr_t qvi_conn_ers(void); /** * */ -const char * +cstr_t qvi_tmpdir(void); /** * */ -const char * +cstr_t qvi_whoami(void); /** @@ -153,7 +153,7 @@ qvi_whoami(void); */ int qvi_file_size( - const char *path, + const cstr_t path, size_t *size );