[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Git][xorg-team/xserver/xorg-server][debian-unstable] xvfb-run: Special-case "-e /dev/stderr", etc. as redirection



Title: GitLab

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 <smcv@debian.org>
    

2 changed files:

Changes:

  • debian/local/xvfb-run
    ... ... @@ -79,7 +79,7 @@ find_free_servernum() {
    79 79
     # Clean up files
    
    80 80
     clean_up() {
    
    81 81
         if [ -e "$AUTHFILE" ]; then
    
    82
    -        XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >>"$ERRORFILE" 2>&1
    
    82
    +        XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >&3 2>&3
    
    83 83
         fi
    
    84 84
         if [ -n "$XVFB_RUN_TMPDIR" ]; then
    
    85 85
             if ! rm -r "$XVFB_RUN_TMPDIR"; then
    
    ... ... @@ -88,7 +88,7 @@ clean_up() {
    88 88
             fi
    
    89 89
         fi
    
    90 90
         if [ -n "$XVFBPID" ]; then
    
    91
    -        kill "$XVFBPID" >>"$ERRORFILE" 2>&1
    
    91
    +        kill "$XVFBPID" >&3 2>&3
    
    92 92
         fi
    
    93 93
     }
    
    94 94
     
    
    ... ... @@ -139,6 +139,22 @@ if ! command -v xauth >/dev/null; then
    139 139
         exit 3
    
    140 140
     fi
    
    141 141
     
    
    142
    +# Open fd 3 for diagnostic output from Xvfb, etc.
    
    143
    +case "$ERRORFILE" in
    
    144
    +    (/proc/self/fd/1 | /dev/stdout)
    
    145
    +        # We might not actually be able to write to this if it's a file or
    
    146
    +        # terminal owned by someone else, so duplicate the fd instead
    
    147
    +        exec 3>&1
    
    148
    +        ;;
    
    149
    +    (/proc/self/fd/2 | /dev/stderr)
    
    150
    +        # See above
    
    151
    +        exec 3>&2
    
    152
    +        ;;
    
    153
    +    (*)
    
    154
    +        exec 3>>"$ERRORFILE"
    
    155
    +        ;;
    
    156
    +esac
    
    157
    +
    
    142 158
     # tidy up after ourselves
    
    143 159
     trap clean_up EXIT
    
    144 160
     
    
    ... ... @@ -156,13 +172,13 @@ MCOOKIE=$(mcookie)
    156 172
     tries=10
    
    157 173
     while [ $tries -gt 0 ]; do
    
    158 174
         tries=$(( $tries - 1 ))
    
    159
    -    XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1
    
    175
    +    XAUTHORITY=$AUTHFILE xauth source - << EOF >&3 2>&3
    
    160 176
     add :$SERVERNUM $XAUTHPROTO $MCOOKIE
    
    161 177
     EOF
    
    162 178
         # handle SIGUSR1 so Xvfb knows to send a signal when it's ready to accept
    
    163 179
         # connections
    
    164 180
         trap : USR1
    
    165
    -    (trap '' USR1; exec Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP -auth $AUTHFILE >>"$ERRORFILE" 2>&1) &
    
    181
    +    (trap '' USR1; exec Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP -auth $AUTHFILE >&3 2>&3 3>&-) &
    
    166 182
         XVFBPID=$!
    
    167 183
     
    
    168 184
         wait || :
    
    ... ... @@ -181,7 +197,7 @@ done
    181 197
     
    
    182 198
     # Start the command and save its exit status.
    
    183 199
     set +e
    
    184
    -DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@"
    
    200
    +DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 3>&-
    
    185 201
     RETVAL=$?
    
    186 202
     set -e
    
    187 203
     
    

  • debian/local/xvfb-run.1
    ... ... @@ -87,6 +87,15 @@ in
    87 87
     .IR file .
    
    88 88
     The default is
    
    89 89
     .IR /dev/null .
    
    90
    +As a special case, specifying
    
    91
    +.B /proc/self/fd/2
    
    92
    +or
    
    93
    +.B /dev/stderr
    
    94
    +writes to standard error (without actually reopening the file descriptor), while
    
    95
    +.B /proc/self/fd/1
    
    96
    +or
    
    97
    +.B /dev/stdout
    
    98
    +writes to standard output.
    
    90 99
     .TP
    
    91 100
     .BI \-f\  file \fR,\fB\ \-\-auth\-file= file
    
    92 101
     Store X authentication data in
    


  • Reply to: