session dbus for root user.
Simon McVittie
smcv at collabora.com
Wed Aug 15 12:59:23 UTC 2018
On Wed, 15 Aug 2018 at 14:48:31 +0530, deepan muthusamy wrote:
> Why echo $DBUS_SESSION_BUS_ADDRESS prints nothing for root user?
The obvious answer is "because you didn't set it" but presumably that
isn't the answer you were looking for.
How did the root user log in?
If the root user did not log in and you are running processes as root
in some other way (for instance from a system service), then those
processes are not part of a session, so you can't expect them to have
a session bus.
> How to start session dbus at boot time for root user ?
I assume you're making some sort of embedded system. The session bus is
designed to be used by interactive graphical desktop sessions, so it is
not really applicable to embedded systems; but perhaps you have a group
of cooperating processes that behave a bit like a desktop session?
This is really more a question about how you design your system than
a question about D-Bus.
First, consider what you are trying to achieve and whether it could be
done without pretending to be in a session. If you can do it differently,
you probably should. If starting a session for the root user is really
the only way to do what you wanted to achieve, read on.
On systemd systems, ideally the D-Bus session bus matches the concept
of user sessions in systemd-logind. One route is that you could enable
"lingering" for uid 0, for example with "loginctl enable-linger root",
and start processes in that session with systemd-run(1). Alternatively,
if a "desktop-like" system service on an embedded device needs to behave
as though it is part of root's session, configuring it to start a login
session for itself via PAM (by setting PAMName to the name of a PAM
configuration that includes pam_systemd) might help.
The non-systemd-specific answer is that a hierarchy of cooperating
processes can create a D-Bus session bus for themselves by wrapping
dbus-run-session(1) around the parent process, so that instead of
some process
\- some parent process for the "session"
\- child process
\- child process
\- etc.
you have
some process
\- dbus-run-session
\- some parent process for the "session"
| \- child process
| \- child process
| \- etc.
\- dbus-daemon --session
and the dbus-daemon will run for as long as the "parent process" does.
Regards,
smcv
More information about the dbus
mailing list