Skip to content

Commit 8f8a87d

Browse files
authored
Make xauth file unique (#4831)
switched to mktemp incorporated code review feedback Signed-off-by: Jeff Ng <jeffng@precisioninno.com>
1 parent 1f78392 commit 8f8a87d

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

‎flow/util/docker_shell‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -ex
99
# -i, --image IMAGE Docker image (overrides $OR_IMAGE and default)
1010
# --user Map host UID/GID into the container via entrypoint.sh
1111
# -p, --port SPEC Forward a port, e.g. --port 8265:8265 (repeatable)
12-
# --dry-run Print the docker command without executing it
12+
# --dry-run Print the commands (xauth setup + docker run) without executing them
1313
# -h|--help Show this help and exit
1414

1515
#
@@ -39,7 +39,7 @@ IMAGE=""
3939
CMD_ARGS=()
4040

4141
usage() {
42-
grep '^#' "$0" | sed 's/^# \{0,1\}//'
42+
sed -n '3,/^$/s/^# \{0,1\}//p' "$0"
4343
exit 0
4444
}
4545

@@ -72,9 +72,14 @@ if [[ -n "${KLAYOUT_CMD:-}" ]]; then
7272
fi
7373

7474
XSOCK=/tmp/.X11-unix
75-
XAUTH=/tmp/.docker.xauth
76-
if ! $DRY_RUN; then
77-
xauth nlist ${DISPLAY:-:0} | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
75+
76+
if $DRY_RUN; then
77+
# Use a fixed path so the printed commands work when run by hand
78+
XAUTH=/tmp/.docker.xauth.dry-run
79+
else
80+
XAUTH=$(mktemp /tmp/.docker.xauth.XXXXXXXXXX)
81+
trap 'rm -f "$XAUTH"' EXIT
82+
xauth nlist "${DISPLAY:-:0}" | sed -e 's/^..../ffff/' | xauth -f "$XAUTH" nmerge -
7883
fi
7984

8085
if test -t 0; then
@@ -104,7 +109,7 @@ CMD_STR=
104109

105110
ENV_SH_CMD='if [ -f ../env.sh ]; then . ../env.sh; fi;'
106111

107-
# Build the command once; dry-run prints it, otherwise exec it.
112+
# Build the command once; dry-run prints it, otherwise run it.
108113
DOCKER_CMD=(
109114
"$container_engine" run --rm -i
110115
$DOCKER_INTERACTIVE
@@ -130,8 +135,11 @@ DOCKER_CMD=(
130135
)
131136

132137
if $DRY_RUN; then
133-
echo "${DOCKER_CMD[*]}"
138+
echo "# Run both lines; the first creates $XAUTH for X forwarding"
139+
echo "xauth nlist '${DISPLAY:-:0}' | sed -e 's/^..../ffff/' | xauth -f '$XAUTH' nmerge -"
140+
printf '%q ' "${DOCKER_CMD[@]}"
141+
echo
134142
exit 0
135143
fi
136144

137-
exec "${DOCKER_CMD[@]}"
145+
"${DOCKER_CMD[@]}"

0 commit comments

Comments
 (0)