Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer /lib{,32,64} behavior from host system (alternative to #34) #61

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions sandwine/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class AccessMode(Enum):


class MountMode(Enum):
DEVTMPFS = auto()
BIND_DEV = auto()
BIND_RO = auto()
BIND_RW = auto()
BIND_DEV = auto()
TMPFS = auto()
DEVTMPFS = auto()
PROC = auto()
SYMLINK = auto()
TMPFS = auto()


def parse_command_line(args):
Expand Down Expand Up @@ -225,6 +226,16 @@ class MountTask:
required: bool = True


def infer_mount_task(mode: MountMode, abs_target_path: str, required: bool = True) -> MountTask:
if os.path.islink(abs_target_path):
mode = MountMode.SYMLINK
source = os.readlink(abs_target_path)
else:
source = None

return MountTask(mode=mode, target=abs_target_path, source=source, required=required)


def random_hostname():
return ''.join(hex(random.randint(0, 15))[2:] for _ in range(12))

Expand All @@ -237,9 +248,9 @@ def create_bwrap_argv(config):
MountTask(MountMode.DEVTMPFS, '/dev'),
MountTask(MountMode.BIND_DEV, '/dev/dri'),
MountTask(MountMode.BIND_RO, '/etc'),
MountTask(MountMode.BIND_RO, '/lib'),
MountTask(MountMode.BIND_RO, '/lib32', required=False),
MountTask(MountMode.BIND_RO, '/lib64'),
infer_mount_task(MountMode.BIND_RO, '/lib'),
infer_mount_task(MountMode.BIND_RO, '/lib32', required=False),
infer_mount_task(MountMode.BIND_RO, '/lib64'),
MountTask(MountMode.PROC, '/proc'),
MountTask(MountMode.BIND_RO, '/sys'),
MountTask(MountMode.TMPFS, '/tmp'),
Expand Down Expand Up @@ -341,15 +352,17 @@ def create_bwrap_argv(config):
argv.add('--dev', mount_task.target)
elif mount_task.mode == MountMode.PROC:
argv.add('--proc', mount_task.target)
elif mount_task.mode in (MountMode.BIND_RO, MountMode.BIND_RW, MountMode.BIND_DEV):
elif mount_task.mode in (MountMode.BIND_RO, MountMode.BIND_RW, MountMode.BIND_DEV,
MountMode.SYMLINK):
if mount_task.source is None:
mount_task.source = mount_task.target

# NOTE: The X11 Unix socket will only show up later
keep_missing_source = X11Mode(
config.x11) != X11Mode.NONE and mount_task.target == x11_unix_socket

if not os.path.exists(mount_task.source) and not keep_missing_source:
if (mount_task.mode != MountMode.SYMLINK and not os.path.exists(mount_task.source)
and not keep_missing_source):
if mount_task.required:
_logger.error(
f'Path {mount_task.source!r} does not exist on the host, aborting.')
Expand All @@ -365,6 +378,8 @@ def create_bwrap_argv(config):
argv.add('--bind', mount_task.source, mount_task.target)
elif mount_task.mode == MountMode.BIND_DEV:
argv.add('--dev-bind', mount_task.source, mount_task.target)
elif mount_task.mode == MountMode.SYMLINK:
argv.add('--symlink', mount_task.source, mount_task.target)
else:
assert False, f'Mode {mount_task.mode} not supported'
else:
Expand Down
Loading