From d12f5c6a4bd9d081ff72320092a8cbad4e543742 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 26 Sep 2008 14:53:23 +0000 Subject: do not crash if DBus isn't reachable (might fix #40801 as well as #42627 as side effect git-svn-id: http://svn.mandriva.com/svn/soft/draksnapshot/trunk@246739 99302b65-d5f7-0310-b3dd-f8cd6f4e3d94 --- draksnapshot-applet | 57 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'draksnapshot-applet') diff --git a/draksnapshot-applet b/draksnapshot-applet index d7050b0..41e6df0 100755 --- a/draksnapshot-applet +++ b/draksnapshot-applet @@ -91,31 +91,38 @@ my $hal_dn = 'org.freedesktop.Hal'; my $hal_manager = "$hal_dn.Manager"; my $manager_path = '/org/freedesktop/Hal/Manager'; -my $dbus = dbus_object::system_bus(); - -my $do = dbus_object->new($dbus, $hal_dn, $manager_path, $hal_manager); - -my $con = $dbus->{connection}; -my $old_time; -$con->add_filter(sub { - my ($_bus, $msg) = @_; - return 0 if $msg->get_member ne 'DeviceAdded'; - my $hal = $dbus->get_service($hal_dn); - my $bool; - eval { - my $device = $hal->get_object(($msg->get_args_list)[0], "$hal_dn.Device"); - $bool = - $device->QueryCapability('volume') && !$device->GetProperty('volume.is_disc') && - $device->GetProperty('volume.is_mounted'); - }; - if ($bool) { - my $time = time(); - go2State('disk_found') if 5 < abs($time - $old_time); +my $dbus = eval { dbus_object::system_bus() }; +my $dbus_error = $@; + + + +# initializing DBus/HAL: +my ($do, $con); +if ($dbus) { + $do = dbus_object->new($dbus, $hal_dn, $manager_path, $hal_manager); + + $con = eval { $dbus->{connection} }; + my $old_time; + $con->add_filter(sub { + my ($_bus, $msg) = @_; # perl_checker: Net::DBus::Binding::Message::Signal + return 0 if $msg->get_member ne 'DeviceAdded'; + my $hal = $dbus->get_service($hal_dn); + my $bool; + eval { + my $device = $hal->get_object(($msg->get_args_list)[0], "$hal_dn.Device"); + $bool = + $device->QueryCapability('volume') && !$device->GetProperty('volume.is_disc') && + $device->GetProperty('volume.is_mounted'); + }; + if ($bool) { + my $time = time(); + go2State('disk_found') if 5 < abs($time - $old_time); $old_time = $time; - } - 0; - }); -$con->add_match("type='signal',interface='$hal_manager'"); + } + 0; + }); + $con->add_match("type='signal',interface='$hal_manager'"); +} my ($opt) = @ARGV; @@ -134,7 +141,7 @@ $SIG{CHLD} = \&harvester; run_program::raw({ detach => 1 }, 'ionice', '-p', $$, '-n7'); -$do->set_gtk2_watch; +$do and $do->set_gtk2_watch; Gtk2->main; ugtk2::exit(0); -- cgit v1.2.1