From eb7f03cd7aa0e81539ef0bd57f04ebd9552f6d2a Mon Sep 17 00:00:00 2001 From: Jeff Ng Date: Fri, 13 Nov 2026 01:46:38 +0000 Subject: [PATCH] Make xauth file unique switched to mktemp incorporated code review feedback Signed-off-by: Jeff Ng --- flow/util/docker_shell | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/flow/util/docker_shell b/flow/util/docker_shell index 6cfe7eb961..1b0db5958d 100755 --- a/flow/util/docker_shell +++ b/flow/util/docker_shell @@ -9,7 +9,7 @@ set -ex # -i, --image IMAGE Docker image (overrides $OR_IMAGE and default) # --user Map host UID/GID into the container via entrypoint.sh # -p, --port SPEC Forward a port, e.g. --port 8265:8265 (repeatable) -# --dry-run Print the docker command without executing it +# --dry-run Print the commands (xauth setup + docker run) without executing them # -h|--help Show this help and exit # @@ -39,7 +39,7 @@ IMAGE="" CMD_ARGS=() usage() { - grep '^#' "$0" | sed 's/^# \{0,1\}//' + sed -n '3,/^$/s/^# \{0,1\}//p' "$0" exit 0 } @@ -67,9 +67,14 @@ OPENROAD_EXE=${OPENROAD_EXE:-/OpenROAD-flow-scripts/tools/install/OpenROAD/bin/o KLAYOUT_CMD=${KLAYOUT_CMD:-/usr/bin/klayout} XSOCK=/tmp/.X11-unix -XAUTH=/tmp/.docker.xauth -if ! $DRY_RUN; then - xauth nlist ${DISPLAY:-:0} | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - + +if $DRY_RUN; then + # Use a fixed path so the printed commands work when run by hand + XAUTH=/tmp/.docker.xauth.dry-run +else + XAUTH=$(mktemp /tmp/.docker.xauth.XXXXXXXXXX) + trap 'rm -f "$XAUTH"' EXIT + xauth nlist "${DISPLAY:-:0}" | sed -e 's/^..../ffff/' | xauth -f "$XAUTH" nmerge - fi if test -t 0; then @@ -99,7 +104,7 @@ CMD_STR= ENV_SH_CMD='if [ -f ../env.sh ]; then . ../env.sh; fi;' -# Build the command once; dry-run prints it, otherwise exec it. +# Build the command once; dry-run prints it, otherwise run it. DOCKER_CMD=( "$container_engine" run --rm -i $DOCKER_INTERACTIVE @@ -125,8 +130,11 @@ DOCKER_CMD=( ) if $DRY_RUN; then - echo "${DOCKER_CMD[*]}" + echo "# Run both lines; the first creates $XAUTH for X forwarding" + echo "xauth nlist '${DISPLAY:-:0}' | sed -e 's/^..../ffff/' | xauth -f '$XAUTH' nmerge -" + printf '%q ' "${DOCKER_CMD[@]}" + echo exit 0 fi -exec "${DOCKER_CMD[@]}" +"${DOCKER_CMD[@]}"