Skip to content

Commit

Permalink
fix(macos): report permission error if not root
Browse files Browse the repository at this point in the history
This change ensures that Austin reports the expected error code and
message when running without the superuser privileges.
  • Loading branch information
P403n1x87 committed Feb 24, 2023
1 parent b48d980 commit 2798213
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/austin.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ do_child_processes(py_proc_t * py_proc) {

// ----------------------------------------------------------------------------
int main(int argc, char ** argv) {

#if defined PL_MACOS
// On MacOS, we need to be root to use Austin.
if (geteuid() != 0) {
_msg(MPERM);
return EPROCPERM;
}
#endif

int retval = 0;
py_proc_t * py_proc = NULL;
int exec_arg = parse_args(argc, argv);
Expand Down
12 changes: 12 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ def test_cli_permissions():
result = austin("-i", "1ms", "-p", str(p.pid))
assert result.returncode == 37, result.stderr
assert "Insufficient permissions" in result.stderr, result.stderr


@pytest.mark.skipif(
platform.system() != "Darwin",
reason="Only Darwing requires sudo in all cases",
)
def test_cli_permissions_darwin():
result = austin(
"-i", "1ms", "python3.10", "-c", "'from time import sleep; sleep(1)'"
)
assert result.returncode == 37, result.stderr
assert "Insufficient permissions" not in result.stderr, result.stderr

0 comments on commit 2798213

Please sign in to comment.