diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 739b7dc2..1aed7bc8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: diff --git a/src/austin.c b/src/austin.c index a584243b..f607dc1e 100644 --- a/src/austin.c +++ b/src/austin.c @@ -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(); diff --git a/test/test_cli.py b/test/test_cli.py index 733ceded..40067dde 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -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