X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=opt%2Fbin%2Fktmux_helper;h=e2b58a50cb4ffe9ef7741a49aac9e0afb4153eb4;hp=31605c8c7e234bc176123170f571e086e05c8232;hb=08392e37a0280a6943b36d0b857f916cd650a3d5;hpb=aeb96cb02bc3ec6be1adea9bd5c6a1dbc0e08886 diff --git a/opt/bin/ktmux_helper b/opt/bin/ktmux_helper index 31605c8..e2b58a5 100755 --- a/opt/bin/ktmux_helper +++ b/opt/bin/ktmux_helper @@ -1,10 +1,16 @@ #!/usr/bin/perl # # ktmux_helper: Run krenew in the background for tmux. +# Usage: ktmux_helper [options] +# Options: -I Specify path to kinit. +# -L Specify path to klist. +# -R Specify path to krenew. +# -T Specify path to tmux. # Notes: Doesn't handle multiple sessions properly. # use FindBin; +use Getopt::Std; use POSIX ":sys_wait_h"; my $PROG = $FindBin::Script; @@ -21,6 +27,16 @@ my $tmux_helper = &get_tmux_helper; exit 0 if $tmux_helper; $tmux_helper = $$; +my %opts; +getopts('I:L:R:T:', \%opts); + +my $kinit = $opts{'I'} || "kinit"; +my $klist = $opts{'L'} || "klist"; +my $krenew = $opts{'R'} || "krenew"; +my $tmux = $opts{'T'} || "tmux"; + +my $avoid_race = 0; + my $exitasap = 0; my $pid = 0; @@ -47,7 +63,7 @@ LOOP: while (&ping_tmux) { } else { exit 1 if &check_credentials; - exec "krenew", "-K", "60"; + exec $krenew, "-K", "60"; print "$PROG: Can't run krenew: $!\n"; exit 111; } @@ -88,7 +104,7 @@ sub ping_tmux { # Try to check existing Kerberos credentials. sub check_credentials { - system "klist", "-s"; + system $klist, "-s"; return 1 if $? < 0; return 0 unless $?; kill USR1, $tmux_helper; @@ -97,9 +113,12 @@ sub check_credentials { # We were signalled by our child which noticed that our credentials expired. sub want_credentials { + return sleep 1 if $avoid_race; + $avoid_race = 1; # Do we already know? - return sleep 1 if &check_kinit_child; - system "tmux", "new-window", "-n", "Renew Kerberos credentials", "exec kinit"; + system $tmux, "new-window", "-n", "Renew Kerberos credentials", "exec $kinit" unless &check_kinit_child; + sleep 1; + $avoid_race = 0; } sub cleanup {