commit df758a035669172183a2e0eb56d3ad92087c053a parent 7ca00b849b8ae91b7a22ffabe8b6bf1c76f0075c Author: Jan Pobrislo <ccx@webprojekty.cz> Date: Thu, 31 Dec 2020 04:09:26 +0100 Message to launch X11 application. Diffstat:
M | bin/handle-nsx11-message | | | 64 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- |
1 file changed, 63 insertions(+), 1 deletion(-)
diff --git a/bin/handle-nsx11-message b/bin/handle-nsx11-message @@ -103,11 +103,69 @@ abduco-run() { nag -m "Failed to link abduco socket." return 1 fi - if ! s6-sudo $x_container_tmpfs/run/exec/exec urxvt -e abduco -a /run/inbox/${socket#/run/containers/}; then + if ! s6-sudo $x_container_tmpfs/run/exec/exec urxvt \ + -name abduco:${session//./-}:${container//./-} \ + -title "[$session@$container] abduco" \ + -e abduco -a /run/inbox/${socket#/run/containers/} + then nag -m "Failed to spawn terminal for abduco session: /run/inbox/${socket#/run/containers/}" fi } +x11-run() { + if ! [[ $1 == *!*!*!* ]]; then + nag -m "Got malformed x11 command: ${(qqq)1}" + return 1 + fi + local container display cookie cmd rest out + container=${1%%!*} + rest=${1#*!} + + display=${rest%%!*} + rest=${rest#*!} + + cookie=${rest%%!*} + cmd=${rest#*!} + + if [[ $container == */* ]]; then + nag -m "Invalid container name: contains slashes" + return 1 + fi + + if ! [[ $display =~ ^[0-9]+$ ]]; then + nag -m "Invalid display name: ${(qqq)display}" + return 1 + fi + + if ! [[ $display == ${X}* ]]; then + nag -m "Display number not starting with ${X}: ${(qqq)display}" + return 1 + fi + + if ! [[ $cookie =~ ^[0-9a-fA-F]+$ ]]; then + nag -m "Invalid MIT cookie format: ${(qqq)cookie}" + return 1 + fi + + if ! ensure-container-started $container; then + nag -m "Failed to start container ${(qqq)container}" + return 1 + fi + + if ! link-to-container-inbox xsession.$X.$USER $container tmp/.X11-unix/X$display; then + nag -m "Failed to link X11 socket." + return 1 + fi + + if out=$( 2>&1 env EXEC_PATH=/run/containers/$container/run/exec/x11 execlineb -c "importas -i -u EXEC_PATH EXEC_PATH s6-sudo \$EXEC_PATH ${(qqq)display} ${(qqq)cookie} $cmd" ); then + return 0 + else + nag -m "Error spawning session (exit $?): ${(qqq)out}" + return 1 + fi +} +typeset -f -t x11-run + # read full data from stdin, will handle binary payloads correctly unlike env IFS= read -ru 0 -k $plumb_ndata data || return $? @@ -131,6 +189,10 @@ case $data in abduco-run "${data#*!}" ;; + (x11!*) + x11-run "${data#*!}" + ;; + (*) nag -t warning -m "Powerbox got message: ${(qqq)plumb_data}" ;;