my $PROG = $FindBin::Script;
# Ensure tmux is our parent and find its PID.
-my $tmux_pid = &get_tmux_pid;
+our $tmux_pid = &get_tmux_pid;
unless ($tmux_pid) {
print STDERR "$PROG: Not a child of tmux!\n";
exit 100;
my $exitasap = 0;
my $pid = 0;
-our $have_valid_credentials = undef;
$SIG{INT} = \&cleanup;
$SIG{QUIT} = \&cleanup;
$SIG{TERM} = \&cleanup;
$SIG{USR1} = \&want_credentials;
-$SIG{USR2} = \&got_credentials;
LOOP: while (&ping_tmux) {
$pid = fork;
exit 0;
}
else {
- kill USR2, $tmux_helper unless &check_credentials;
+ exit 1 if &check_credentials;
exec "krenew", "-K", "60";
print "$PROG: Can't run krenew: $!\n";
exit 111;
return undef;
}
+sub check_kinit_child {
+ foreach my $pid (`/bin/ps -o ppid= -C kinit`) {
+ return 1 if $pid =~ /^\s*$tmux_pid\s*$/;
+ }
+ return 0;
+}
+
sub get_tmux_helper {
my $pid = undef;
if (open IN, "pgrep -x -P $tmux_pid $PROG | ") {
# We were signalled by our child which noticed that our credentials expired.
sub want_credentials {
# Do we already know?
- return if defined $have_valid_credentials && $have_valid_credentials == 0;
- $SIG{USR1} = IGNORE;
- $have_valid_credentials = 0;
- system "tmux", "new-window", "exec kinit";
-}
-
-# We were signalled by our child which noticed that our credentials are valid.
-sub got_credentials {
- $have_valid_credentials = 1;
- $SIG{USR1} = \&want_credentials;
+ return sleep 1 if &check_kinit_child;
+ system "tmux", "new-window", "-n", "Renew Kerberos credentials", "exec kinit";
}
sub cleanup {