Skip to content

Commit 7b1bc41

Browse files
authored
gh-159452: Run the regen-configure container as the invoking user (#159454)
`Tools/build/regen-configure.sh` ran the Autoconf container as root, so with a rootful Docker daemon the regenerated files and `autom4te.cache` ended up owned by root. The stale cache broke subsequent runs and couldn't be removed without sudo. Run the container as the invoking user instead: `--userns=keep-id` for Podman, `-u UID:GID` for rootful Docker. Rootless runtimes already map container root to the invoking user and need nothing. Also remove `autom4te.cache` before and after the run, using the same image, so an existing root-owned cache gets cleaned up too.
1 parent c7fd652 commit 7b1bc41

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``Tools/build/regen-configure.sh`` no longer leaves
2+
root-owned files in the source tree.

‎Tools/build/regen-configure.sh‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,27 @@ if command -v selinuxenabled >/dev/null && selinuxenabled; then
2626
PATH_OPT=":Z"
2727
fi
2828

29-
"$RUNTIME" run --rm -v "$abs_srcdir:$WORK_DIR$PATH_OPT" "$IMAGE"
29+
# Run the container as the invoking user so that generated files are owned by
30+
# that user and not by root. Rootless runtimes already map root to the invoking
31+
# user, so a user mapping is only needed for rootful Docker.
32+
USER_OPT=""
33+
case "$RUNTIME" in
34+
podman)
35+
USER_OPT="--userns=keep-id"
36+
;;
37+
docker)
38+
if ! docker info --format '{{.SecurityOptions}}' | grep -q rootless; then
39+
USER_OPT="-u $(id -u):$(id -g)"
40+
fi
41+
;;
42+
esac
43+
44+
purge_autom4te_cache() {
45+
[ -d "$abs_srcdir/autom4te.cache" ] || return 0
46+
"$RUNTIME" run --rm -v "$abs_srcdir:$WORK_DIR$PATH_OPT" \
47+
"$IMAGE" sh -c "rm -rf $WORK_DIR/autom4te.cache"
48+
}
49+
50+
purge_autom4te_cache
51+
trap 'purge_autom4te_cache || true' EXIT
52+
"$RUNTIME" run --rm $USER_OPT -v "$abs_srcdir:$WORK_DIR$PATH_OPT" "$IMAGE"

0 commit comments

Comments
 (0)