commit ae64d05f72fa7c1d1c6f7612228849b68bf6a746
parent 29eaef3e6b7c71bf57aa93df34250bbcf1b6e37e
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Thu, 30 May 2019 02:14:12 +0200
session cleanup, x command
Diffstat:
3 files changed, 56 insertions(+), 20 deletions(-)
diff --git a/bin/zshaskpass_lock b/bin/zshaskpass_lock
@@ -12,7 +12,7 @@ fi
setopt no_unset warn_create_global
zmodload zsh/zselect
-typeset -g COPROC_OUT fd newfd prompt_end keep_running
+typeset -g COPROC_OUT fd newfd prompt_end keep_running X
typeset -a coproc_args
typeset -gA fds
@@ -22,14 +22,23 @@ typeset -gA fds
# COPROC_OUT=$[ $ZSHASKPASS_PASSFD + 1 ]
#fi
+if [[ $TTY == /dev/tty[1234] ]]; then
+ X=$[ ${TTY#/dev/tty} + 4 ]
+fi
+
prompt_end=%f
coproc_args=(
fdmove -c 2 1
unexport ZSHASKPASS_PROMPTFD
unexport ZSHASKPASS_PASSFD
unexport SSH_ASKPASS
- "$@"
+ #"$@"
)
+if [[ -n $X ]]; then
+ coproc_args+=( tail -F /run/containers/xsession.$X.ccx/run/uncaught-logs/current )
+else
+ coproc_args+=( tail -F /run/user/ccx.logs/current )
+fi
if (($+LOGINCAP_READFD)); then
coproc_args=( fdclose $LOGINCAP_READFD unexport LOGINCAP_FD "$coproc_args[@]" )
fi
@@ -52,8 +61,17 @@ logincap() {
cmd() {
case $1 in
('') ;;
+ (-x) set -x;;
+ (+x) set +x;;
('c '*)
logincap ${1#c };;
+ (x)
+ local X
+ X=$[ ${TTY#/dev/tty} + 4 ]
+ logincap X\ $X
+ s6-svc -wu -o /run/service/container.xsession.$X.ccx
+ s6-svstat /run/service/container.xsession.$X.ccx
+ ;;
(off|poweroff)
logincap o;;
(reboot)
@@ -71,7 +89,7 @@ cmd() {
# typeset -f -t cmd
-coproc "$coproc_args[@]"
+coproc "$coproc_args[@]" | s6-tai64nlocal
trap 'kill %1' EXIT
trap 'kill %1; ssh-add -D; exit' INT HUP TERM QUIT
trap 'printf "\nALRM!\n"' ALRM
@@ -112,12 +130,12 @@ while (($keep_running)) && zselect -A fds -r 0 $select_fds; do
elif [[ $fd == $COPROC_OUT ]]; then
# coprocess
if IFS= read -u $COPROC_OUT -t; then
- if [[ $REPLY == "XFIFO: "* ]]; then
- printf '< opening: %s\n' ${REPLY#*: }
- exec {newfd}>>${REPLY#*: }
- else
+ # if [[ $REPLY == "XFIFO: "* ]]; then
+ # printf '< opening: %s\n' ${REPLY#*: }
+ # exec {newfd}>>${REPLY#*: }
+ # else
printf '> %s\n' $REPLY
- fi
+ # fi
fi
else
# stdin
diff --git a/home/loginexec b/home/loginexec
@@ -1,6 +1,11 @@
#!/bin/zsh -l
set -x
mkdir -p /run/user/$USER/ssh-master && chmod 700 /run/user/$USER/ssh-master
+if [[ -e $HOME/s6-rc/user/compiled && ! -e /run/user/$USER/s6-rc ]]; then
+ if ! s6-rc-init -c $HOME/s6-rc/user/compiled -l /run/user/$USER/s6-rc -d /run/user/$USER/service; then
+ echo >&2 'Warning: s6-rc failed to start!'
+ fi
+fi
if [[ $TTY = /dev/tty[1-4] ]]; then
[[ -S /run/user/$USER/ssh_agent.${${TTY#/dev/}//\//.} ]] && rm /run/user/$USER/ssh_agent.${${TTY#/dev/}//\//.}
X=$[ ${TTY#/dev/tty} + 4 ]
diff --git a/sbin/logincaps b/sbin/logincaps
@@ -2,32 +2,45 @@
setopt no_unset warn_create_global
#set -x
-trap 'printf "\nlogincaps: ALRM!\n"' ALRM
+trap 'printf >&2 "\nlogincaps: ALRM!\n"' ALRM
+trap 'printf >&2 "\nlogincaps: HUP!\n"' HUP
pretendrun() { : "$@" }
typeset -f -t pretendrun
initialize() {
- if (($+LOGIN_TTY)) && [[ $LOGIN_TTY = /dev/tty[1-4] ]]; then
- typeset -g X
- X=$[ ${LOGIN_TTY#/dev/tty} + 4 ]
+ if (($+LOGIN_TTY)); then
+ mkdir -p /run/ttylock || exit $?
+ touch /run/ttylock/$LOGIN_TTY:t || exit $?
+ exec 3< /run/ttylock/$LOGIN_TTY:t || exit $?
+ flock 3 || exit $?
+ touch /run/ttylock/$LOGIN_TTY:t.cleanup || exit $?
+ exec 4< /run/ttylock/$LOGIN_TTY:t.cleanup || exit $?
+ flock 4 || exit $?
+ if [[ $LOGIN_TTY = /dev/tty[1-4] ]]; then
+ typeset -g X
+ X=$[ ${LOGIN_TTY#/dev/tty} + 4 ]
+ # cleanup
+ nohup flock -F /run/ttylock/$LOGIN_TTY:t.cleanup \
+ s6-svc -wD -d /run/service/X$X 4<& - &!
+ fi
fi
}
typeset -f -t initialize
-cleanup() {
- if (($+X)); then
- s6-svc -d /run/service/X$X
- fi
-}
-typeset -f -t cleanup
+# cleanup() {
+# if (($+X)); then
+# s6-svc -wD -d /run/service/X$X
+# fi
+# }
+# typeset -f -t cleanup
run_x() {
(($+X)) || return 1
[[ $X == $1 ]] || return 2
shift
- s6-svc -wU -o /run/service/X$X &&
truncate -s 0 /run/Xauthority.$X &&
+ s6-svc -wU -o /run/service/X$X &&
chmod 640 /run/Xauthority.$X &&
chown root:$USER /run/Xauthority.$X &&
cat /run/service/X$X/data/Xauthority > /run/Xauthority.$X
@@ -86,4 +99,4 @@ main() {
initialize
main
-cleanup
+#cleanup