Skip to content

Commit

Permalink
Merge pull request #173 from P403n1x87/fix/macos-permissions
Browse files Browse the repository at this point in the history
fix(macos): report permission error if not root
  • Loading branch information
P403n1x87 authored Aug 12, 2023
2 parents 0484829 + 97b2f91 commit a183f2a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ jobs:
|| (python${{ matrix.python-version }} -m pip install virtualenv && python${{ matrix.python-version }} -m virtualenv .venv)
source .venv/bin/activate
sudo -E pytest --ignore=test/cunit --pastebin=failed --no-flaky-report -sr a
pytest --ignore=test/cunit --pastebin=failed --no-flaky-report -sr a -k _darwin
deactivate
wheels-osx:
Expand Down
8 changes: 8 additions & 0 deletions src/austin.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ int main(int argc, char ** argv) {
py_proc_t * py_proc = NULL;
int exec_arg = parse_args(argc, argv);

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

logger_init();
if (!pargs.pipe)
log_header();
Expand Down
11 changes: 11 additions & 0 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ 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 Darwin requires sudo in all cases",
)
@no_sudo
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" in result.stderr, result.stderr

0 comments on commit a183f2a

Please sign in to comment.