summaryrefslogtreecommitdiffstats
path: root/bin/watch-lock
diff options
context:
space:
mode:
Diffstat (limited to 'bin/watch-lock')
-rwxr-xr-xbin/watch-lock37
1 files changed, 37 insertions, 0 deletions
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";
+ }
+}