Timo Aaltonen pushed to branch debian-unstable at X Strike Force / xserver / xorg-server
Commits: 4766ab7d by Simon McVittie at 2024-11-13T15:09:07+00:00 xvfb-run: Special-case "-e /dev/stderr", etc. as redirection In some execution environments, standard error is an inherited file descriptor, but we cannot actually reopen it by opening /dev/stderr or /proc/self/fd/2: for example, it might be a file or terminal owned by a different uid with restrictive permissions, or it might be an AF_UNIX socket. It's generically useful to be able to send Xvfb output to stderr (and several packages are already doing this, which does work on Debian's official buildds), so special-case these pseudo-filenames and interpret them as redirection to a duplicate of the inherited file descriptor, which works in more situations. Closes: #1087418, #921657 Signed-off-by: Simon McVittie <[email protected]> - - - - - 2 changed files: - debian/local/xvfb-run - debian/local/xvfb-run.1 Changes: ===================================== debian/local/xvfb-run ===================================== @@ -79,7 +79,7 @@ find_free_servernum() { # Clean up files clean_up() { if [ -e "$AUTHFILE" ]; then - XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >>"$ERRORFILE" 2>&1 + XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >&3 2>&3 fi if [ -n "$XVFB_RUN_TMPDIR" ]; then if ! rm -r "$XVFB_RUN_TMPDIR"; then @@ -88,7 +88,7 @@ clean_up() { fi fi if [ -n "$XVFBPID" ]; then - kill "$XVFBPID" >>"$ERRORFILE" 2>&1 + kill "$XVFBPID" >&3 2>&3 fi } @@ -139,6 +139,22 @@ if ! command -v xauth >/dev/null; then exit 3 fi +# Open fd 3 for diagnostic output from Xvfb, etc. +case "$ERRORFILE" in + (/proc/self/fd/1 | /dev/stdout) + # We might not actually be able to write to this if it's a file or + # terminal owned by someone else, so duplicate the fd instead + exec 3>&1 + ;; + (/proc/self/fd/2 | /dev/stderr) + # See above + exec 3>&2 + ;; + (*) + exec 3>>"$ERRORFILE" + ;; +esac + # tidy up after ourselves trap clean_up EXIT @@ -156,13 +172,13 @@ MCOOKIE=$(mcookie) tries=10 while [ $tries -gt 0 ]; do tries=$(( $tries - 1 )) - XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1 + XAUTHORITY=$AUTHFILE xauth source - << EOF >&3 2>&3 add :$SERVERNUM $XAUTHPROTO $MCOOKIE EOF # handle SIGUSR1 so Xvfb knows to send a signal when it's ready to accept # connections trap : USR1 - (trap '' USR1; exec Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP -auth $AUTHFILE >>"$ERRORFILE" 2>&1) & + (trap '' USR1; exec Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP -auth $AUTHFILE >&3 2>&3 3>&-) & XVFBPID=$! wait || : @@ -181,7 +197,7 @@ done # Start the command and save its exit status. set +e -DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" +DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 3>&- RETVAL=$? set -e ===================================== debian/local/xvfb-run.1 ===================================== @@ -87,6 +87,15 @@ in .IR file . The default is .IR /dev/null . +As a special case, specifying +.B /proc/self/fd/2 +or +.B /dev/stderr +writes to standard error (without actually reopening the file descriptor), while +.B /proc/self/fd/1 +or +.B /dev/stdout +writes to standard output. .TP .BI \-f\ file \fR,\fB\ \-\-auth\-file= file Store X authentication data in View it on GitLab: https://salsa.debian.org/xorg-team/xserver/xorg-server/-/commit/4766ab7d1cf447c173564ed8a6c74318f4189fa8 -- View it on GitLab: https://salsa.debian.org/xorg-team/xserver/xorg-server/-/commit/4766ab7d1cf447c173564ed8a6c74318f4189fa8 You're receiving this email because of your account on salsa.debian.org.

