Merge pull request #2612 from dalearbo/fix/busybox-musl-ldd-check

fix: busybox static link detection on Alpine/musl
This commit is contained in:
Jeremy Grossmann 2026-02-20 16:01:01 +08:00 committed by GitHub
commit 3b95859b79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -79,8 +79,10 @@ class Docker(BaseManager):
stderr=asyncio.subprocess.DEVNULL
)
stdout, _ = await proc.communicate()
if proc.returncode == 1:
if proc.returncode == 1 or "static" in busybox_exec:
# ldd returns 1 if the file is not a dynamic executable
# on Alpine/musl, ldd returns 0 even for static binaries,
# so also trust binaries named busybox-static or busybox.static
log.info(f"Installing busybox from '{busybox_path}' to '{dst_busybox}'")
shutil.copy2(busybox_path, dst_busybox, follow_symlinks=True)
return

View File

@ -251,7 +251,7 @@ async def test_install_busybox_dynamic_linked():
mock_process.communicate = AsyncioMagicMock(return_value=(b"Dynamically linked library", b""))
with patch("os.path.isfile", return_value=False):
with patch("gns3server.compute.docker.shutil.which", return_value="/usr/bin/busybox"):
with patch("gns3server.compute.docker.shutil.which", side_effect=lambda name: "/usr/bin/busybox" if name == "busybox" else None):
with asyncio_patch("gns3server.compute.docker.asyncio.create_subprocess_exec", return_value=mock_process):
with pytest.raises(DockerError) as e:
dst_dir = Docker.resources_path()