12345678910111213141516171819202122232425262728293031323334353637383940 |
- #!/bin/sh
- # write stderr to both calling party and local log; be very careful about
- # closing file descriptors here - if either stdout or stderr will not be closed
- # when service process does the same - service call will hang (waiting for EOF
- # on stdout/stderr)
- stderr_pipe=/tmp/qrexec-rpc-stderr.$$
- mkfifo $stderr_pipe
- # tee can't write to file descriptor, nor /proc/self/fd/2 (EXIO on open)
- return_stderr_pipe=/tmp/qrexec-rpc-stderr-return.$$
- mkfifo $return_stderr_pipe
- { cat <$return_stderr_pipe >&2 2>/dev/null; rm -f $return_stderr_pipe; } &
- { tee $return_stderr_pipe 2>/dev/null <$stderr_pipe |\
- logger -t "$1-$2" >/dev/null 2>&1; rm -f $stderr_pipe; } &
- exec 2>$stderr_pipe
- QUBES_RPC=/etc/qubes-rpc
- LOCAL_QUBES_RPC=/usr/local/etc/qubes-rpc
- if ! [ $# = 2 ] ; then
- echo $0: bad argument count, usage: $0 SERVICE-NAME REMOTE-DOMAIN-NAME >&2
- exit 1
- fi
- export QREXEC_REMOTE_DOMAIN="$2"
- for CFG_FILE in $LOCAL_QUBES_RPC/"$1" $QUBES_RPC/"$1"; do
- if [ -s "$CFG_FILE" ]; then
- break
- fi
- done
- if [ -x "$CFG_FILE" ] ; then
- exec "$CFG_FILE"
- echo "$0: failed to execute handler for" "$1" >&2
- exit 1
- else
- exec /bin/sh "$CFG_FILE"
- echo "$0: failed to execute handler for" "$1" >&2
- exit 1
- fi
|