Skip to content

Commit

Permalink
clar/sandbox: convert to use clar_abort()
Browse files Browse the repository at this point in the history
The function `clar_sandbox()` can fail either because it failed to build
a sandbox path or because it failed to change directories into it. The
error reporting happens at the callsite of this function though, where
we are unable to distinguish those two root causes.

Adapt the code to instead perform error handling via `clar_abort()` in
`clar_sandbox()` itself. This gives us direct access to the root cause.
Callers do not need to check for errors anymore.
  • Loading branch information
pks-t committed Sep 20, 2024
1 parent 3a9a6c6 commit 3daf348
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions clar.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static void clar_print_onabort(const char *msg, ...);

/* From clar_sandbox.c */
static void clar_unsandbox(void);
static int clar_sandbox(void);
static void clar_sandbox(void);

/* From summary.h */
static struct clar_summary *clar_summary_init(const char *filename);
Expand Down Expand Up @@ -570,8 +570,7 @@ clar_test_init(int argc, char **argv)
if (_clar.write_summary)
_clar.summary = clar_summary_init(_clar.summary_filename);

if (clar_sandbox() < 0)
clar_abort("Failed to sandbox the test runner.\n");
clar_sandbox();
}

int
Expand Down
9 changes: 4 additions & 5 deletions clar/sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,14 @@ static int build_sandbox_path(void)
return 0;
}

static int clar_sandbox(void)
static void clar_sandbox(void)
{
if (_clar_path[0] == '\0' && build_sandbox_path() < 0)
return -1;
clar_abort("Failed to build sandbox path.\n");

if (chdir(_clar_path) != 0)
return -1;

return 0;
clar_abort("Failed to change into sandbox directory '%s': %s.\n",
_clar_path, strerror(errno));
}

const char *clar_sandbox_path(void)
Expand Down

0 comments on commit 3daf348

Please sign in to comment.