 f0b057479e
			
		
	
	
		f0b057479e
		
			
		
	
	
	
	
		
			
			Previously the script was called through shell as:
    execl(shell, "-sh", "-c", "/usr/lib/qubes/qubes-rpc-multiplexer
            ...", 0);
This tells the shell to load login scripts, including /etc/profile.
Since 5512e4eada this is no longer the
case and the script is called directly. Since most services do expect
proper user session initialized (/etc/profile loaded etc), adjust the
script's shebang to behave like a login shell and load those startup
scripts.
Fixes QubesOS/qubes-issues#3615
		
	
			
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/sh -l
 | |
| 
 | |
| # 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"
 | |
| export QREXEC_SERVICE_FULL_NAME="$1"
 | |
| SERVICE_WITHOUT_ARGUMENT="${1%%+*}"
 | |
| if [ "${QREXEC_SERVICE_FULL_NAME}" != "${SERVICE_WITHOUT_ARGUMENT}" ]; then
 | |
|     export QREXEC_SERVICE_ARGUMENT="${QREXEC_SERVICE_FULL_NAME#*+}"
 | |
| fi
 | |
| 
 | |
| for CFG_FILE in $LOCAL_QUBES_RPC/"$1" $QUBES_RPC/"$1" \
 | |
|         $LOCAL_QUBES_RPC/"${SERVICE_WITHOUT_ARGUMENT}" \
 | |
|         $QUBES_RPC/"${SERVICE_WITHOUT_ARGUMENT}"; do
 | |
| 	if [ -s "$CFG_FILE" ]; then
 | |
|         break
 | |
| 	fi
 | |
| done
 | |
| 
 | |
| if [ -x "$CFG_FILE" ] ; then
 | |
|     # shellcheck disable=SC2086
 | |
| 	exec "$CFG_FILE" ${QREXEC_SERVICE_ARGUMENT}
 | |
| 	echo "$0: failed to execute handler for" "$1" >&2
 | |
| 	exit 1
 | |
| else
 | |
|     # shellcheck disable=SC2086
 | |
| 	exec /bin/sh -- "$CFG_FILE" ${QREXEC_SERVICE_ARGUMENT}
 | |
| 	echo "$0: failed to execute handler for" "$1" >&2
 | |
| 	exit 1
 | |
| fi
 |