summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-04-24 19:12:46 -0500
committerJesse Luehrs <doy@tozt.net>2012-04-24 19:14:04 -0500
commit9e0329425621932f59674baeedc7df95254e541e (patch)
tree47c45fa0f540d6598d7e42ee95a6ad46774a6351 /bin
parent80fc09e2ba830b4ad3510e2fee958ed43d238b38 (diff)
downloadconf-9e0329425621932f59674baeedc7df95254e541e.tar.gz
conf-9e0329425621932f59674baeedc7df95254e541e.zip
handle SIGTERM properly (also, modernize)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/watch_lock21
1 files changed, 16 insertions, 5 deletions
diff --git a/bin/watch_lock b/bin/watch_lock
index b6ef333..6de654f 100755
--- a/bin/watch_lock
+++ b/bin/watch_lock
@@ -1,9 +1,20 @@
#!/usr/bin/perl
-open (IN, "xscreensaver-command -watch |");
-while (<IN>) {
- if (m/^LOCK/) {
- system "$ENV{HOME}/.bin/on_lock"
- } elsif (m/^UNBLANK/) {
+use strict;
+use warnings;
+
+my $pid = open my $in, '-|', 'xscreensaver-command -watch'
+ or die "Couldn't spawn process: $!";
+$SIG{TERM} = sub { kill TERM => $pid; exit };
+while (<$in>) {
+ if (/^LOCK/) {
+ system "$ENV{HOME}/.bin/on_lock";
+ if ($? == -1) {
+ warn "Couldn't exec on_lock: $!";
+ }
+ elsif ($? != 0) {
+ warn "on_lock exited with value " . ($? >> 8);
+ }
+ } elsif (/^UNBLANK/) {
#system "on_unlock"
}
}