I
I
Ivan Komarov2011-07-23 13:05:56
Perl
Ivan Komarov, 2011-07-23 13:05:56

Perl, Net::DBus, session bus usage?

I understand with Net:: DBus, for testing I want to write two simple programs, one provides an interface, the other uses it.
I wrote a simple test code:

#!/usr/bin/perl
use strict;
use warnings;

package MyObj;
use Net::DBus::Exporter qw(org.example.Tao);
use base qw(Net::DBus::Object);

sub new {
    my $class = shift;
    my $service = shift;
    my $self = $class->SUPER::new($service, '/MyObj');
    bless $self, $class;
    return $self;
}

dbus_method("Hello", ["string"]);

sub Hello {
    return 'Hello';
}

package main;
use Net::DBus;
use Net::DBus::Reactor;

my $bus = Net::DBus->session;
my $service = $bus->export_service("org.example.Tao");
my $object = MyObj->new($service);
my $reactor = Net::DBus::Reactor->main();
$reactor->run();

return 0;

Details about my environment:
I work via ssh, and I use:
Perl, v5.8.8 built for x86_64-linux-thread-multi<br/>
Linux example.com 2.6.32.19-0.2.99.17.22250fd-xen #1 SMP 2010-09-13 10:16:50 +0200 x86_64 x86_64 x86_64 GNU/Linux<br/>
CentOS release 5.4 (Final)<br/>

When I try to run test.pl I get an error:
org.freedesktop.DBus.Error.Spawn.ExecFailed:<br/>
Failed to execute dbus-launch to autolaunch D-Bus session<br/>

The line that causes the error:
my $bus = Net::DBus->session;
I searched in Google, found that dbus-launch is needed for happiness.
Did yum install dbus-x11.
Question one: why package from x11?
Tried to run mine again, test.pl. Got another error:
org.freedesktop.DBus.Error.Spawn.ExecFailed: <br/>
dbus-launch failed to autolaunch D-Bus session: <br/>
Autolaunch error: X11 initialization failed.<br/>

I read the manuals again, I realized that I did not have the DBUS_SESSION_BUS_ADDRESS variable set and that the session bus was not running at all.
DBUS_SESSION_BUS_ADDRESS is empty:<br/>
[[email protected] perl]# ps ax|grep dbus|grep -v grep<br/>
1019 ? Ss 0:00 dbus-daemon --system<br/>

Although the same wiki says that the session bus starts for each user.
Tried to start it with dbus-launch
[[email protected] perl]# dbus-launch --sh-syntax<br/>
DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/dbus-smHadq6yxV,guid=101ccd74fb75ae501485ed004e2a9043';<br/>
export DBUS_SESSION_BUS_ADDRESS;<br/>
DBUS_SESSION_BUS_PID=5037;<br/>
[[email protected] perl]# ps ax|grep dbus|grep -v grep<br/>
1019 ? Ss 0:00 dbus-daemon --system<br/>
5037 ? Ss 0:00 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session<br/>

But DBUS_SESSION_BUS_ADDRESS is still empty.
So, the question is:
What preparatory steps need to be taken in order for my program to work on behalf of any user in the Net:: DBus system and use its session bus. Or maybe you can do nothing and start the bus directly from my program?
In general, how to work with DBus?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question