Skip to content

Commit f3b6825

Browse files
committed
Test if busybox is not dynamically linked
1 parent 7194587 commit f3b6825

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

gns3server/compute/docker/__init__.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self):
5959
self._api_version = DOCKER_MINIMUM_API_VERSION
6060

6161
@staticmethod
62-
def install_busybox():
62+
async def install_busybox():
6363

6464
if not sys.platform.startswith("linux"):
6565
return
@@ -69,10 +69,24 @@ def install_busybox():
6969
for busybox_exec in ("busybox-static", "busybox.static", "busybox"):
7070
busybox_path = shutil.which(busybox_exec)
7171
if busybox_path:
72-
log.info(f"Installing busybox from '{busybox_path}'")
7372
try:
74-
shutil.copy2(busybox_path, dst_busybox, follow_symlinks=True)
75-
return
73+
# check that busybox is statically linked
74+
# (dynamically linked busybox will fail to run in a container)
75+
proc = await asyncio.create_subprocess_exec(
76+
"ldd",
77+
busybox_path,
78+
stdout=asyncio.subprocess.PIPE,
79+
stderr=asyncio.subprocess.DEVNULL
80+
)
81+
stdout, _ = await proc.communicate()
82+
if proc.returncode == 1:
83+
# ldd returns 1 if the file is not a dynamic executable
84+
log.info(f"Installing busybox from '{busybox_path}' to '{dst_busybox}'")
85+
shutil.copy2(busybox_path, dst_busybox, follow_symlinks=True)
86+
return
87+
else:
88+
log.warning(f"Busybox '{busybox_path}' is dynamically linked\n"
89+
f"{stdout.decode('utf-8', errors='ignore').strip()}")
7690
except OSError as e:
7791
raise DockerError(f"Could not install busybox: {e}")
7892
raise DockerError("No busybox executable could be found")

gns3server/compute/docker/docker_vm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ async def start(self):
545545
"""
546546

547547
# make sure busybox is installed
548-
self.manager.install_busybox()
548+
await self.manager.install_busybox()
549549

550550
try:
551551
state = await self._get_container_state()

gns3server/utils/asyncio/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def subprocess_check_output(*args, cwd=None, env=None, stderr=False):
7777
if output is None:
7878
return ""
7979
# If we received garbage we ignore invalid characters
80-
# it should happens only when user try to use another binary
80+
# it should happen only when user try to use another binary
8181
# and the code of VPCS, dynamips... Will detect it's not the correct binary
8282
return output.decode("utf-8", errors="ignore")
8383

0 commit comments

Comments
 (0)