Skip to content

Commit cc63a4d

Browse files
committed
login,build: skip /dev/fd and /dev/std{in,out,err} binds when host already has them
Partial fix for #689
1 parent b27b8ee commit cc63a4d

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

proot_distro/commands/login/proot_cmd.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,11 @@ def _add_non_minimal_binds(
185185

186186
def _add_termux_dev_binds(args, rootfs):
187187
"""Bind device files and fake /proc/sys substitutes used by Termux."""
188-
args += [
189-
"--bind=/dev/urandom:/dev/random",
190-
"--bind=/proc/self/fd:/dev/fd",
191-
]
188+
args.append("--bind=/dev/urandom:/dev/random")
189+
if not os.path.lexists("/dev/fd"):
190+
args.append("--bind=/proc/self/fd:/dev/fd")
192191
for i, name in ((0, "stdin"), (1, "stdout"), (2, "stderr")):
193-
if os.path.exists(f"/proc/self/fd/{i}"):
192+
if not os.path.lexists(f"/dev/{name}") and os.path.exists(f"/proc/self/fd/{i}"):
194193
args.append(f"--bind=/proc/self/fd/{i}:/dev/{name}")
195194
sysdata_dir = os.path.join(os.path.dirname(rootfs), "sysdata")
196195
args.append(f"--bind={sysdata_dir}/sys_empty:/sys/fs/selinux")

proot_distro/helpers/build_engine/run_step.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,11 @@ def _exec_proot(engine, stage, command, stdin_input):
174174
proot_args += ["--bind=/dev", "--bind=/proc", "--bind=/sys"]
175175

176176
if IS_TERMUX:
177-
proot_args += [
178-
"--bind=/dev/urandom:/dev/random",
179-
"--bind=/proc/self/fd:/dev/fd",
180-
]
177+
proot_args.append("--bind=/dev/urandom:/dev/random")
178+
if not os.path.lexists("/dev/fd"):
179+
proot_args.append("--bind=/proc/self/fd:/dev/fd")
181180
for i, name in ((0, "stdin"), (1, "stdout"), (2, "stderr")):
182-
if os.path.exists(f"/proc/self/fd/{i}"):
181+
if not os.path.lexists(f"/dev/{name}") and os.path.exists(f"/proc/self/fd/{i}"):
183182
proot_args.append(f"--bind=/proc/self/fd/{i}:/dev/{name}")
184183
setup_fake_sysdata(rootfs)
185184
sysdata_dir = os.path.join(os.path.dirname(rootfs), "sysdata")

0 commit comments

Comments
 (0)