This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KApplication DBus registration

Tags: None
(comma "," separated)
dzs
Registered Member
Posts
4
Karma
0
OS

KApplication DBus registration

Sun Jul 19, 2009 11:58 am
Hi!

I'm trying to migrate my KDE app to KDE4.
The KApplication instance in the app is registering at DBus with a name generated from the web page of the app and the PID.
When running without debugger it works fine, however, when trying to execute under gdb I got the following message when stepping over the KApplication constructor and the process exits:

<app>(20533): Couldn't register name ' "<app>-20533" ' with DBUS - another process owns it already!

I listed the registered service names on the system and session buses but no registration was present with that name.
Checking the KDE sources, the registration is done and this error message comes from KApplicationPrivate::init, which is called by the KApplication constructors.

Any idea why this happens?

Thanks in advance!
dzs
Registered Member
Posts
4
Karma
0
OS

Re: KApplication DBus registration

Sun Jul 19, 2009 7:51 pm
OK, let me answer my own question. I think this is a bug in KApplication anyway.

In fact, KApplication is not telling the truth :)

Noone has registered with the given name so far, but the QDBusConnectionInterface::registerService() call which fails during initialization will only tell you that the service was not registered but not giving any reason.

KApplication in this case wrongly assumes that the fail reason is that the name is already in use, in fact the name was an invalid service name.

Unfortunatelly I cut out the name in my post, so no one could point out this by just looking :( It was like net.sourceforge/path/to/exe-PID, which turns out to be invalid because it contains slashes.

KApplication sets up the service name as
Code: Select all
const QString serviceName = reversedDomain + q->applicationName() + pidSuffix;

so I suppose, under gdb the q->applicationName() returns the full path. Why is to be examined, but I'd suggest to add some check here and use only the end of this string, after the last slash.
dzs
Registered Member
Posts
4
Karma
0
OS

Re: KApplication DBus registration

Sun Jul 19, 2009 8:16 pm
Answer to why is as easy as I passed argv[0] to KAboutData as the application name, which is also incorrect I think. Changing this to a fixed string solved my problem.

Conclusion: Application name set in KAboutData and passed to KCmdLineArgs::init will be used directly as part of KApplication's DBus service name, so have to be set with care.
dzs
Registered Member
Posts
4
Karma
0
OS

Re: KApplication DBus registration

Sun Jul 19, 2009 8:29 pm
One final comment :)

According to the --help-qt message of any KDE app, the --name <name> argument should set the application name. This means, by writing e.g.
kate --name what/ever

you can screw up the starting of any KDE application.
Fortunatelly (?) the --name does not work (at least on my system), or sets some different app name, I could not find any difference in a short time checking, on a few KDE programs.

Does it work for anybody? (I'm using KDE 4.2.2)
User avatar
vHanda
KDE Developer
Posts
84
Karma
0
OS

Re: KApplication DBus registration

Wed Feb 03, 2010 11:03 am
I know this is an old post, but I just want to point out that you get this error if you initialize KAboutData's appName parameter with some name which includes a space.
Eg - "Sample App" won't work. "SampleApp" will.
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

Re: KApplication DBus registration

Fri Feb 12, 2010 9:03 pm
Interesting observations. Maybe this could be checked somewhere, e.g. in KAboutData or before the value is passed to QtDBus.

I am pretty sure a patch doing such a check would be accepted and applied.
Chance to get some code into kdelibs ;D

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]