summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/on-lock5
-rwxr-xr-xbin/on_lock3
-rwxr-xr-xbin/watch-lock37
-rwxr-xr-xservices/available/watch-lock/log/run3
-rwxr-xr-xservices/available/watch-lock/run5
5 files changed, 50 insertions, 3 deletions
diff --git a/bin/on-lock b/bin/on-lock
new file mode 100755
index 0000000..b9fa1fe
--- /dev/null
+++ b/bin/on-lock
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+sudo -K
+ssh-add -D
+echo RELOADAGENT | gpg-connect-agent
diff --git a/bin/on_lock b/bin/on_lock
deleted file mode 100755
index a0bb411..0000000
--- a/bin/on_lock
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-sudo -k
diff --git a/bin/watch-lock b/bin/watch-lock
new file mode 100755
index 0000000..8545efc
--- /dev/null
+++ b/bin/watch-lock
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.020;
+
+use POSIX ":sys_wait_h";
+
+$|++;
+
+my $pid = open my $fh, '-|', (
+ 'dbus-monitor',
+ '--system',
+ 'type=signal,interface=org.freedesktop.login1.Session'
+) or die "couldn't spawn dbus-monitor: $!";
+$SIG{CHLD} = sub {
+ while ((my $child = waitpid -1, WNOHANG) > 0) {
+ if ($child == $pid) {
+ undef $pid;
+ }
+ }
+ exit unless $pid;
+};
+
+sub cleanup {
+ kill KILL => $pid if $pid;
+ undef $pid;
+}
+
+$SIG{TERM} = $SIG{INT} = sub { cleanup; exit; };
+END { cleanup }
+
+while (<$fh>) {
+ if (/\bmember=Lock\b/) {
+ system("on-lock") && say "on-lock failed";
+ say "LOCK";
+ }
+}
diff --git a/services/available/watch-lock/log/run b/services/available/watch-lock/log/run
new file mode 100755
index 0000000..fd51f06
--- /dev/null
+++ b/services/available/watch-lock/log/run
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec multilog t s16777215 $HOME/.log/watch-lock
diff --git a/services/available/watch-lock/run b/services/available/watch-lock/run
new file mode 100755
index 0000000..f36a7e7
--- /dev/null
+++ b/services/available/watch-lock/run
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -eu
+set -o pipefail
+
+exec watch-lock