diff options
author | dakkar <dakkar@thenautilus.net> | 2021-04-10 12:42:29 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2021-04-10 12:54:50 +0100 |
commit | 4c2f66d8fb0992082ac6ed7343ace8f277e2ba70 (patch) | |
tree | b7880b8aa9d650fec73cfb99b7f2d805f2a33fec /xscreensaver-dbus | |
parent | more debug (diff) | |
download | xscreensaver-dbus-4c2f66d8fb0992082ac6ed7343ace8f277e2ba70.tar.gz xscreensaver-dbus-4c2f66d8fb0992082ac6ed7343ace8f277e2ba70.tar.bz2 xscreensaver-dbus-4c2f66d8fb0992082ac6ed7343ace8f277e2ba70.zip |
cope with inhibitor dying
not great, since a different process may be running with that pid by
the time we checkā¦
Diffstat (limited to 'xscreensaver-dbus')
-rwxr-xr-x | xscreensaver-dbus | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/xscreensaver-dbus b/xscreensaver-dbus index f4dcfa2..002c0d9 100755 --- a/xscreensaver-dbus +++ b/xscreensaver-dbus @@ -90,12 +90,18 @@ package SaverImpl { return $self; } + our $_message; + sub _dispatch_object($self,$connection,$message,@etc) { + local $_message = $message; + return $self->SUPER::_dispatch_object($connection,$message,@etc); + } + sub Inhibit($self,$name,$reason) { - return $self->{__inhibit_cb}->($name,$reason); + return $self->{__inhibit_cb}->($name,$reason,$_message); } sub UnInhibit($self,$cookie) { - return $self->{__uninhibit_cb}->($cookie); + return $self->{__uninhibit_cb}->($cookie,$_message); } }; @@ -104,9 +110,13 @@ package Saver { use experimental 'signatures'; use curry; use Log::Any '$log'; + use Try::Tiny; has reactor => ( is => 'ro', required => 1 ); has bus => ( is => 'lazy', builder => sub { Net::DBus->session() } ); + has dbus_srv => ( is => 'lazy', builder => sub { shift->bus->get_service('org.freedesktop.DBus') }); + has dbus_obj => ( is => 'lazy', builder => sub { shift->dbus_srv->get_object('/org/freedesktop/DBus') }); + has service => ( is => 'lazy', builder => sub { @@ -149,12 +159,22 @@ package Saver { return; } - sub inhibit($self,$name,$reason) { + sub inhibit($self,$name,$reason,$message) { + my $sender_pid = try { + return $self->dbus_obj->GetConnectionUnixProcessID( + $message->get_sender, + ); + } catch { + $log->warning('problems getting PID of inhibitor',{error=>$_}); + return undef; + }; + my $cookie; do { $cookie = int(rand(2**31)) } until !exists $self->_inhibits->{$cookie}; - $self->_inhibits->{$cookie} = [ $name, $reason ]; + + $self->_inhibits->{$cookie} = [ $name, $reason, $sender_pid ]; $log->debugf( '<%s> stops screensaver for <%s> (cookie %d) - %d active', @@ -165,13 +185,14 @@ package Saver { return $cookie; } - sub uninhibit($self,$cookie) { + sub uninhibit($self,$cookie,$message) { my $inhibit = delete $self->_inhibits->{$cookie} or return; + my ($name, $reason, $sender_pid) = @$inhibit; $log->debugf( '<%s> resumed screensaver for <%s> (cookie %d) - %d left', - @$inhibit, $cookie, scalar(keys $self->_inhibits->%*), + $name, $reason, $cookie, scalar(keys $self->_inhibits->%*), ); $self->reactor->toggle_timeout($self->_prod_id, 0) @@ -181,6 +202,23 @@ package Saver { } sub prod_screensaver($self) { + for my $cookie (sort keys $self->_inhibits->%*) { + my ($name, $reason, $sender_pid) = @{$self->_inhibits->{$cookie}}; + next if kill 0, $sender_pid; + # uh oh, caller is dead + my $inhibit = delete $self->_inhibits->{$cookie}; + + $log->debugf( + '<%s> is dead (it stopped screensaver for <%s>, cookie %d) - %d left', + $name, $reason, $cookie, scalar(keys $self->_inhibits->%*), + ); + } + + unless ($self->_inhibits->%*) { + $self->reactor->toggle_timeout($self->_prod_id, 0); + return; + } + $log->debug('prodding xscreensaver'); system(qw(xscreensaver-command -deactivate)); } |