[Script] ssh-add dropping keys when xscreensaver blanks

Andrew Stribblehill a.d.stribblehill at durham.ac.uk
Wed Feb 28 21:10:36 EST 2001


Quoting Damien Miller <djm at mindrot.org>:
> On Tue, 27 Feb 2001, Andrew Stribblehill wrote:
> 
> > The people at Debian were chuntering that it'd be a good idea for
> > xscreensaver to ask ssh-add to drop its keys when it blanked the
> > screen. Would the attached script (which does just that) be worth
> > adding to the contrib directory?
> 
> You committed the capital crime of not attaching the script. Stand still,
> a squad is on its way to you now.

D'oh! I'll try again.

Cheerio,

Andrew Stribblehill
Systems programmer, IT Service, University of Durham, England
-------------- next part --------------
#!/usr/bin/perl -w
#
# screenwatch. Watches xscreensaver and drops keys when screen blanks.
# Adds the default key on unblank.
#
# Typical usage: Put this command in your .xsession
#
# BUGS: Only adds the default key, not all the keys that it had before.
#       [Matter-of-taste] Drops keys on both blank and lock.

use strict;
use POSIX 'setsid';

sub daemonise {
    chdir '/' or die "Can't chdir to /: $!";
    open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
    open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
    defined(my $pid = fork) or die "Can't fork: $!";
    exit if $pid;
    setsid or die "Can't start a new session: $!";
    open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
}

daemonise();
my $blanked = 0;
open (IN, "/usr/bin/X11/xscreensaver-command -watch |");
while (<IN>) {
    if (m/^(BLANK|LOCK)/) {
        if (!$blanked) {
            system("/usr/bin/ssh-add -D");
            $blanked = 1;
        }
    } elsif (m/^UNBLANK/) {
        system("ssh-add");
        $blanked = 0;
    }
}


More information about the openssh-unix-dev mailing list