Add --hostname to set the sandbox's hostname under -r/--run

Long-option only. Threaded through run_container() into
build_bwrap_args(), which passes it as bwrap's own --hostname only
when --unshare-uts is actually among the flags being given to bwrap
(bwrap itself refuses --hostname without it) -- otherwise logs a
warning and leaves the hostname alone, since a stock Android kernel
in degraded mode may not support a UTS namespace at all.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gv3s5jckJKzh6JkMoi2Akz
This commit is contained in:
2026-08-22 07:13:22 +00:00
parent 355675b43f
commit 9877ffe7f1
5 changed files with 65 additions and 17 deletions
+12 -3
View File
@@ -47,7 +47,10 @@ Source layout (all under `src/`):
`run_container()` resolves each spec (erroring out, `ok = false`, same as a
failed `--user` resolution — `bwrap` is skipped but unmount/cleanup still runs)
into a `ResolvedVolumeMount`, rejecting a duplicate or non-absolute container
path first, and passes the resolved list to `run_bwrap()`.
path first, and passes the resolved list to `run_bwrap()`. `--hostname <name>`
(long-option only, no short form) is likewise threaded straight through
`run_container()` into `run_bwrap()`/`build_bwrap_args()` (`bwrap.{h,cpp}`) —
see there for how/when it actually takes effect.
- `oci_image.{h,cpp}` — validates/parses the OCI Image Layout tar (libarchive +
nlohmann_json) and extracts layer blobs. `list_oci_images()` scans a directory
(non-recursively) for `*.tar`/`*.tar.*` files and, for each valid OCI archive,
@@ -80,6 +83,12 @@ Source layout (all under `src/`):
`slirp4netns`), unsharing it just leaves the sandbox with no network at all. Re-add
once network isolation is implemented; `detect_bwrap_unshare_args()` itself still
probes/reports it (e.g. via `-t/--test`), since that's kernel capability, not policy.
`build_bwrap_args()`/`run_bwrap()` also take an optional `hostname` (from
`--hostname`, long-option only): passed through as bwrap's own `--hostname` only
when `--unshare-uts` is actually among the flags `bwrap` is being given (bwrap
itself refuses `--hostname` without it) — otherwise logs a warning and leaves the
sandbox's hostname alone, since a stock Android kernel in degraded mode may not
support a UTS namespace at all.
Never requests `--unshare-user` when running as root: root doesn't need a fresh
user namespace for privilege, and bwrap's own single-mapping uid/gid setup for one
triggers the kernel's unprivileged-userns setgroups() restriction, which showed up
@@ -212,8 +221,8 @@ Build directory is `buildDir/` (already configured).
- Run the executable: `./buildDir/slocker-lite -m <image.tar>` (see `--help` for the
full flag list: `-m/--mount`, `-r/--run`, `-u/--umount`, `-c/--cleanup`,
`-l/--list-images`, `-i/--inspect`, `-n/--no-nsenter`, `--user`, `--group`,
`-v/--volume`, `--list-volumes`, `--delete-volume`, `--delete-volume-full`,
`-t/--test`, `--log-level`, `-h/--help`, `-V/--version`)
`--hostname`, `-v/--volume`, `--list-volumes`, `--delete-volume`,
`--delete-volume-full`, `-t/--test`, `--log-level`, `-h/--help`, `-V/--version`)
- Run tests: `meson test -C buildDir`
## Code style