qubes-rpc-multiplexer 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. # write stderr to both calling party and local log; be very careful about
  3. # closing file descriptors here - if either stdout or stderr will not be closed
  4. # when service process does the same - service call will hang (waiting for EOF
  5. # on stdout/stderr)
  6. stderr_pipe=/tmp/qrexec-rpc-stderr.$$
  7. mkfifo $stderr_pipe
  8. # tee can't write to file descriptor, nor /proc/self/fd/2 (EXIO on open)
  9. return_stderr_pipe=/tmp/qrexec-rpc-stderr-return.$$
  10. mkfifo $return_stderr_pipe
  11. { cat <$return_stderr_pipe >&2 2>/dev/null; rm -f $return_stderr_pipe; } &
  12. { tee $return_stderr_pipe 2>/dev/null <$stderr_pipe |\
  13. logger -t "$1-$2" >/dev/null 2>&1; rm -f $stderr_pipe; } &
  14. exec 2>$stderr_pipe
  15. QUBES_RPC=/etc/qubes-rpc
  16. LOCAL_QUBES_RPC=/usr/local/etc/qubes-rpc
  17. if ! [ $# = 2 ] ; then
  18. echo $0: bad argument count, usage: $0 SERVICE-NAME REMOTE-DOMAIN-NAME >&2
  19. exit 1
  20. fi
  21. export QREXEC_REMOTE_DOMAIN="$2"
  22. for CFG_FILE in $LOCAL_QUBES_RPC/"$1" $QUBES_RPC/"$1"; do
  23. if [ -s "$CFG_FILE" ]; then
  24. break
  25. fi
  26. done
  27. if [ -x "$CFG_FILE" ] ; then
  28. exec "$CFG_FILE"
  29. echo "$0: failed to execute handler for" "$1" >&2
  30. exit 1
  31. else
  32. exec /bin/sh "$CFG_FILE"
  33. echo "$0: failed to execute handler for" "$1" >&2
  34. exit 1
  35. fi