Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macos): report permission error if not root #173

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading