diff --git a/lib/portage/gpkg.py b/lib/portage/gpkg.py index 031b3f87c..74e9012dd 100644 --- a/lib/portage/gpkg.py +++ b/lib/portage/gpkg.py @@ -347,9 +347,9 @@ class tar_stream_reader: kill external program if any error happened in python """ if self.proc is not None: - self.killed = True - self.proc.kill() self.proc.stdin.close() + self.proc.kill() + self.killed = True self.close() def read(self, bufsize=-1): diff --git a/lib/portage/tests/process/test_spawn_fail_e2big.py b/lib/portage/tests/process/test_spawn_fail_e2big.py index 7a0096630..13655e1cf 100644 --- a/lib/portage/tests/process/test_spawn_fail_e2big.py +++ b/lib/portage/tests/process/test_spawn_fail_e2big.py @@ -2,6 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 import platform +import resource import pytest @@ -12,7 +13,9 @@ from portage.const import BASH_BINARY @pytest.mark.skipif(platform.system() != "Linux", reason="not Linux") def test_spawnE2big(capsys, tmp_path): env = dict() - env["VERY_LARGE_ENV_VAR"] = "X" * 1024 * 256 + # Kernel MAX_ARG_STRLEN is defined as 32 * PAGE_SIZE + max_arg_strlen_bytes = 1024 * 32 * resource.getpagesize() + env["VERY_LARGE_ENV_VAR"] = "X" * max_arg_strlen_bytes logfile = tmp_path / "logfile" echo_output = "Should never appear" @@ -24,7 +27,7 @@ def test_spawnE2big(capsys, tmp_path): with open(logfile) as f: logfile_content = f.read() assert ( - "Largest environment variable: VERY_LARGE_ENV_VAR (262164 bytes)" + f"Largest environment variable: VERY_LARGE_ENV_VAR ({max_arg_strlen_bytes + 20} bytes)" in logfile_content ) assert retval == 1