|
1 | 1 | #!/bin/sh -l
|
| 2 | +# we don't use globbing, disable it |
| 3 | +set -f |
2 | 4 |
|
3 |
| -if [ -z "$QREXEC_SERVICE_PATH" ]; then |
| 5 | +if [ -z "${QREXEC_SERVICE_PATH+x}" ]; then |
4 | 6 | QREXEC_SERVICE_PATH=/usr/local/etc/qubes-rpc:/etc/qubes-rpc
|
5 | 7 | fi
|
| 8 | +tmpdir=${XDG_RUNTIME_DIR-/tmp} |
6 | 9 |
|
7 | 10 | # write stderr to both calling party and local log; be very careful about
|
8 | 11 | # closing file descriptors here - if either stdout or stderr will not be closed
|
9 | 12 | # when service process does the same - service call will hang (waiting for EOF
|
10 | 13 | # on stdout/stderr)
|
11 |
| -stderr_pipe=/tmp/qrexec-rpc-stderr.$$ |
12 |
| -mkfifo $stderr_pipe |
| 14 | +stderr_pipe=$tmpdir/qrexec-rpc-stderr.$$ |
| 15 | +mkfifo -- "$stderr_pipe" |
13 | 16 | # tee can't write to file descriptor, nor /proc/self/fd/2 (EXIO on open)
|
14 |
| -return_stderr_pipe=/tmp/qrexec-rpc-stderr-return.$$ |
15 |
| -mkfifo $return_stderr_pipe |
16 |
| -{ cat <$return_stderr_pipe >&2 2>/dev/null; rm -f $return_stderr_pipe; } </dev/null >/dev/null & |
17 |
| -{ tee $return_stderr_pipe <$stderr_pipe |\ |
18 |
| - logger -t "$1-$2"; rm -f $stderr_pipe; } </dev/null >/dev/null 2>&1 & |
19 |
| -exec 2>$stderr_pipe |
| 17 | +return_stderr_pipe=$tmpdir/qrexec-rpc-stderr-return.$$ |
| 18 | +mkfifo -- "$return_stderr_pipe" |
| 19 | +{ cat <"$return_stderr_pipe" >&2 2>/dev/null; rm -f -- "$return_stderr_pipe"; } </dev/null >/dev/null & |
| 20 | +{ tee -- "$return_stderr_pipe" <"$stderr_pipe" | |
| 21 | + logger -t "$1-$2"; rm -f -- "$stderr_pipe"; } </dev/null >/dev/null 2>&1 & |
| 22 | +exec 2>"$stderr_pipe" |
20 | 23 |
|
21 | 24 | if ! [ $# = 2 -o $# = 4 ] ; then
|
22 | 25 | echo "$0: bad argument count, usage: $0 SERVICE-NAME REMOTE-DOMAIN-NAME [REQUESTED_TARGET_TYPE REQUESTED_TARGET]" >&2
|
|
0 commit comments