Skip to content

Commit

Permalink
Add qvi_abort() with minor cleanups. (#124)
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel K. Gutierrez <samuel@lanl.gov>
  • Loading branch information
samuelkgutierrez authored Apr 27, 2024
1 parent 5204c1d commit c10a8e4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/qvi-hwloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ qvi_hwloc_get_obj_type(
return HWLOC_OBJ_OS_DEVICE;
default:
// This is an internal development error.
abort();
qvi_abort();
}
}

Expand All @@ -182,7 +182,7 @@ qvi_hwloc_obj_type_is_host_resource(
return false;
default:
// This is an internal development error.
abort();
qvi_abort();
}
}

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/qvi-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand Down
4 changes: 2 additions & 2 deletions src/qvi-scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions src/qvi-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -77,7 +77,7 @@ qvi_time(void)

bool
qvi_path_usable(
const char *path,
const cstr_t path,
int *errc
) {
*errc = 0;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;

Expand All @@ -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. "
Expand All @@ -155,7 +155,7 @@ qvi_conn_ers(void)
return msg;
}

const char *
cstr_t
qvi_tmpdir(void)
{
static thread_local char tmpdir[PATH_MAX];
Expand All @@ -174,7 +174,7 @@ qvi_tmpdir(void)
return tmp;
}

const char *
cstr_t
qvi_whoami(void)
{
static const int bsize = 128;
Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/qvi-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extern "C" {
/**
*
*/
char *
cstr_t
qvi_strerr(int ec);

/**
Expand All @@ -109,7 +109,7 @@ qvi_time(void);
*/
bool
qvi_path_usable(
const char *path,
const cstr_t path,
int *errc
);

Expand All @@ -133,27 +133,27 @@ qvi_url(
/**
*
*/
const char *
cstr_t
qvi_conn_ers(void);

/**
*
*/
const char *
cstr_t
qvi_tmpdir(void);

/**
*
*/
const char *
cstr_t
qvi_whoami(void);

/**
*
*/
int
qvi_file_size(
const char *path,
const cstr_t path,
size_t *size
);

Expand Down

0 comments on commit c10a8e4

Please sign in to comment.