Fix Void package lifecycle on host
This commit is contained in:
@@ -471,7 +471,9 @@ class TestRunitIsRunning:
|
||||
sv_dir = tmp_path / "sv" / "fenris-collect"
|
||||
sv_dir.mkdir(parents=True)
|
||||
|
||||
with patch("fenris.init_system.FENRIS_SV_DIR", sv_dir):
|
||||
with patch("fenris.init_system.FENRIS_SV_DIR", sv_dir), \
|
||||
patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value.returncode = 1
|
||||
assert _runit_is_running() is False
|
||||
|
||||
def test_is_running_false_dead_process(self, tmp_path):
|
||||
@@ -485,6 +487,37 @@ class TestRunitIsRunning:
|
||||
patch("os.kill", side_effect=OSError("No such process")):
|
||||
assert _runit_is_running() is False
|
||||
|
||||
def test_is_running_uses_process_table_when_supervise_is_unreadable(self, tmp_path):
|
||||
"""Void keeps runit's supervise directory root-only for normal users."""
|
||||
sv_dir = tmp_path / "sv" / "fenris-collect"
|
||||
supervise_dir = sv_dir / "supervise"
|
||||
supervise_dir.mkdir(parents=True)
|
||||
pid_file = supervise_dir / "pid"
|
||||
pid_file.write_text("12345")
|
||||
service_link = tmp_path / "service" / "fenris-collect"
|
||||
service_link.parent.mkdir(parents=True)
|
||||
service_link.symlink_to(sv_dir)
|
||||
|
||||
original_read_text = Path.read_text
|
||||
|
||||
def deny_pid(path, *args, **kwargs):
|
||||
if path == pid_file:
|
||||
raise PermissionError("supervise is root-only")
|
||||
return original_read_text(path, *args, **kwargs)
|
||||
|
||||
with patch("fenris.init_system.FENRIS_SV_DIR", sv_dir), \
|
||||
patch("fenris.init_system.FENRIS_SERVICE_LINK", service_link), \
|
||||
patch.object(Path, "read_text", autospec=True, side_effect=deny_pid), \
|
||||
patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value.returncode = 0
|
||||
assert _runit_is_running() is True
|
||||
mock_run.assert_called_once_with(
|
||||
["pgrep", "-f", "^runsv fenris-collect$"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Public API dispatching
|
||||
|
||||
Reference in New Issue
Block a user