forked from liske/needrestart-session
-
Notifications
You must be signed in to change notification settings - Fork 0
/
needrestart-dbus-system
executable file
·100 lines (77 loc) · 2.46 KB
/
needrestart-dbus-system
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl -T
# needrestart-session - check for processes need to be restarted in user sessions
#
# Authors:
# Thomas Liske <[email protected]>
#
# Copyright Holder:
# 2014 - 2015 (C) Thomas Liske [http://fiasko-nw.net/~thomas/]
#
# License:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
use Net::DBus;
use Net::DBus::Service;
use Net::DBus::Reactor;
use Sys::Syslog qw(:standard :macros);
use warnings;
use strict;
$0 = q(needrestart-dbus-system);
BEGIN {
openlog(q(needrestart-dbus-system), 'pid', LOG_DAEMON);
}
END {
syslog(LOG_INFO, q(terminated));
}
sub WARN_handler {
my $signal = shift;
syslog(LOG_WARNING, q(%s), $signal);
}
sub DIE_handler {
my $signal = shift;
syslog(LOG_ERR, q(%s), $signal);
exit;
}
$SIG{__WARN__} = q(WARN_handler);
$SIG{__DIE__} = q(DIE_handler);
$SIG{TERM} = q(DIE_handler);
syslog(LOG_INFO, q(needrestart-dbus-system %s launched), $NeedRestart::VERSION);
package NeedRestart::DBus;
use NeedRestart;
use Net::DBus::Exporter qw(net.ibh.NeedRestart.System);
use Sys::Syslog qw(:standard :macros);
use base qw(Net::DBus::Object);
sub new {
my $class = shift;
my $service = shift;
my $self = $class->SUPER::new($service, q(/net/ibh/NeedRestart/System));
bless $self, $class;
syslog(LOG_INFO, q(new instance));
return $self;
}
dbus_signal(q(NotifySessions));
dbus_method(q(emitNotifySessions));
sub emitNotifySessions {
my $self = shift;
syslog(LOG_INFO, q(emit NotifySessions signal));
return $self->emit_signal(q(NotifySessions));
}
package main;
my $bus = Net::DBus->system;
my $service = $bus->export_service('net.ibh.NeedRestart.System');
my $object = NeedRestart::DBus->new($service);
syslog(LOG_INFO, q(entering event loop...));
Net::DBus::Reactor->main->run();
syslog(LOG_INFO, q(leaving event loop));