Because KRB5CCNAME was set in update-environment, when attaching
to a running session the saved KRB5CCNAME would be replaced with
that from the attaching user. This conflicts with the cache used
by ktmux_helper.
Instead, use set-environment to put KRB5CCNAME in the session
environment and kinit with it before running tmux.
# Don't wait so long to parse escape sequences.
set -s escape-time 100
-# Ensure KRB5CCNAME is preserved in the environment.
-set -a -g update-environment ' KRB5CCNAME'
-
# Clock.
setw -g clock-mode-colour white
setw -g clock-mode-style 24
done
shift $((OPTIND-1))
-exec $tmux ${tmux_opts## } new-session ${session_opts## } -d ';' attach ';' run-shell ktmux_helper
+if [ -z "$KRB5CCNAME" ]; then
+ krb5ccname="$KRB5CCNAME"
+ [ -z "$krb5ccname" ] && krb5ccname=FILE:${TMPDIR:-/tmp}/krb5cc_${UID}_ktmux_$$
+ export KRB5CCNAME="$krb5ccname"
+fi
+klist -s || kinit
+
+exec $tmux ${tmux_opts## } new-session ${session_opts## } -d ';' set-environment KRB5CCNAME "$KRB5CCNAME" ';' attach ';' run-shell ktmux_helper