commit f55b18f88d908881b4bd6c3d962577d04ec0d2e0
parent 10e101ca0a7aa2312ff3bff61851e50676257a3e
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Thu, 17 Dec 2020 01:58:38 +0100
Clean up fds and environment, use external script to handle plumber messages
Diffstat:
3 files changed, 51 insertions(+), 19 deletions(-)
diff --git a/bin/handle-nsx11-message b/bin/handle-nsx11-message
@@ -0,0 +1,13 @@
+#!/bin/zsh
+setopt no_unset warn_create_global
+
+typeset -g plumber_fifo terminal_exec_socket terminal_el x_container_service x_container_tmpfs
+x_container_tmpfs=/run/containers/xsession.$X.$USER
+x_container_service=/run/service/container.xsession.$X.$USER
+plumber_fifo=$x_container_tmpfs/run/plumber_fifo
+terminal_exec_socket=$x_container_tmpfs/run/exec/urxvt
+terminal_el="redirfd -w 1 /dev/null redirfd -w 2 /dev/null s6-sudo ${(qqq)terminal_exec_socket:A}"
+terminal_env=rxvt-unicode # the TERM variable used
+
+exec s6-sudo $x_container_tmpfs/run/exec/exec \
+ i3-nagbar -t warning -f fixed -m "Powerbox got message: ${(qqq)plumb_data}"
diff --git a/bin/startsshagent.passfd b/bin/startsshagent.passfd
@@ -9,6 +9,7 @@ unexport ZSHASKPASS_READFD
unexport ZSHASKPASS_WRITEFD
if { redirfd -r 0 /dev/null env DISPLAY=pipe SSH_ASKPASS=/home/ccx/bin/zshaskpass ssh-add -c }
importas -i LOGINPASS_FD LOGINPASS_FD
-fdclose $LOGINPASS_FD
+fdclose $LOGINPASS_FD
+unexport LOGINPASS_FD
s6-env ZSHASKPASS_PASSFD=7 ZSHASKPASS_PROMPTFD=5
$@
diff --git a/bin/zshaskpass_lock b/bin/zshaskpass_lock
@@ -13,14 +13,14 @@ setopt no_unset warn_create_global
zmodload zsh/zselect
typeset -g COPROC_OUT fd newfd prompt_end keep_running X die_color plumb_r plumb_w
-typeset -a coproc_args
+typeset -a coproc_args clean_process_state
typeset -gA fds
-#if [[ $ZSHASKPASS_PROMPTFD -gt $ZSHASKPASS_PASSFD ]]; then
-# COPROC_OUT=$[ $ZSHASKPASS_PROMPTFD + 1 ]
-#else
-# COPROC_OUT=$[ $ZSHASKPASS_PASSFD + 1 ]
-#fi
+clean_process_state=(
+ unexport SSH_ASKPASS
+ fdclose $ZSHASKPASS_PROMPTFD unexport ZSHASKPASS_PROMPTFD
+ fdclose $ZSHASKPASS_PASSFD unexport ZSHASKPASS_PASSFD
+)
if [[ $TTY == /dev/tty[1234] ]]; then
typeset -g X
@@ -37,10 +37,6 @@ die() {
coproc_args=(
fdmove -c 2 1
- unexport ZSHASKPASS_PROMPTFD
- unexport ZSHASKPASS_PASSFD
- unexport SSH_ASKPASS
- #"$@"
)
if [[ -n $X ]]; then
typeset -g plumber_fifo terminal_exec_socket terminal_el x_container_service x_container_tmpfs
@@ -55,12 +51,19 @@ else
coproc_args+=( tail -F /run/user/$USER.logs/current )
fi
if (($+LOGINCAP_READFD)); then
- coproc_args=( fdclose $LOGINCAP_READFD unexport LOGINCAP_FD "$coproc_args[@]" )
+ clean_process_state+=( fdclose $LOGINCAP_READFD unexport LOGINCAP_FD )
+ #coproc_args=( fdclose $LOGINCAP_READFD unexport LOGINCAP_FD "$coproc_args[@]" )
fi
if (($+LOGINCAP_WRITEFD)); then
- coproc_args=( fdclose $LOGINCAP_WRITEFD unexport LOGINCAP_FD "$coproc_args[@]" )
+ clean_process_state+=( fdclose $LOGINCAP_WRITEFD unexport LOGINCAP_FD )
+ #coproc_args=( fdclose $LOGINCAP_WRITEFD unexport LOGINCAP_FD "$coproc_args[@]" )
fi
+run() { # run external process in cleaned-up environment
+ "$clean_process_state[@]" "$@"
+}
+# typeset -f -t run
+
logincap() {
if ! (( $+LOGINCAP_READFD & $+LOGINCAP_WRITEFD )); then
echo "logincap FDs not defined"
@@ -109,8 +112,8 @@ cmd() {
logincap ${1#c };;
(x)
logincap X\ $X
- s6-svc -wu -o $x_container_service
- s6-svstat $x_container_service
+ run s6-svc -wu -o $x_container_service
+ run s6-svstat $x_container_service
setup-plumber-listener
;;
(off|poweroff)
@@ -133,7 +136,9 @@ cmd() {
keep_running=0
;;
(shell)
- zsh -i; printf "shell exited with %d\n" $?;;
+ zsh -li; printf "shell exited with %d\n" $?;;
+ (cleanshell)
+ run zsh -li; printf "shell exited with %d\n" $?;;
(*) printf '%s: unknown command\n' ${(qqq)REPLY};;
esac
}
@@ -165,16 +170,29 @@ read-plumber-message() {
;;
(exit)
true >/run/user/$USER/X$X/fifo
- s6-svc -wd -di -T 1 $x_container_service
- s6-svc -wd -d -T 1 /run/service/X$X
+ run s6-svc -wd -di -T 1 $x_container_service
+ run s6-svc -wd -d -T 1 /run/service/X$X
keep_running=0
;;
+ (*)
+ printf %s $plumb_data | run env \
+ plumb_src=$plumb_src \
+ plumb_dst=$plumb_dst \
+ plumb_wdir=$plumb_wdir \
+ plumb_type=$plumb_type \
+ plumb_attr=$plumb_attr \
+ plumb_ndata=$plumb_ndata \
+ plumb_data=$plumb_data \
+ X=$X \
+ handle-nsx11-message &!
+ ;;
+
esac
}
# typeset -f -t cmd
-coproc "$coproc_args[@]" | s6-tai64nlocal
+coproc run "$coproc_args[@]" | run s6-tai64nlocal
trap 'kill %1' EXIT
trap 'kill %1; ssh-add -D; exit' INT HUP TERM QUIT
trap 'printf "\nALRM!\n"' ALRM