The officially official Devuan Forum!

You are not logged in.

#1 2023-03-14 19:23:52

boughtonp
Member
From: UK
Registered: 2023-01-19
Posts: 212  
Website

How to remove .dbus from home directory?

Installing Mousepad text editor resulted in a .dbus directory being added to my home directory.

This seems to be the fault of dbus-x11 which on Devuan is the only provider for "dbus-session-bus" (required by dconf, one of Mousepad's dependencies), and based on a 2011 dbus bug report I think I need to ensure DBUS_SESSION_BUS_ADDRESS is set correctly - specifically to unix:path=$XDG_RUNTIME_DIR/bus by a file in /etc/X11/Xsession.d/

I tried using 20dbus_xdg-runtime config file (from Debian's dbus-user-session package), but that fails because of [ -S "$XDG_RUNTIME_DIR/bus" ], (where "-S" checks that a file is a socket), but there is no such file/socket.

XDG_RUNTIME_DIR is set at login (to /run/user/1000), and is used by other things - there's even a dbus-1 directory in it, so if I can get the socket created I suspect the Debian config script will work.

But my searches are failing to reveal what is supposed to be creating the bus socket...?

Last edited by boughtonp (2023-03-14 19:25:09)


3.1415P265E589T932E846R64338

Offline

#2 2023-03-14 21:04:40

boughtonp
Member
From: UK
Registered: 2023-01-19
Posts: 212  
Website

Re: How to remove .dbus from home directory?

So I managed to work out that the socket is created by dbus-daemon which is configured by /usr/share/dbus-1/session.conf, and can be overridden by /etc/dbus-1/session.d/* or /etc/dbus-1/session-local.conf

So creating a config file like so...

egrep -zo '<!DOCTYPE[^>]+>' /usr/share/dbus-1/session.conf > /etc/dbus-1/session-local.conf
echo '
<busconfig>
<listen>unix:path=/run/user/1000/bus</listen>
</busconfig>' >> /etc/dbus-1/session-local.conf

...then logging out all user sessions and back in again.

Now the bus socket is being created, but it's still re-creating the $HOME/.dbus directory too. :@

Checking xsession-errors shows DBUS_SESSION_BUS_ADDRESS has two values, and paying closer attention to the relevant part of the documentation:

Add an address that the bus should listen on
...
If there are multiple <listen> elements, then the bus listens on multiple addresses.

FFS!

So I think I need to supply an --address param instead, which I thought was /etc/init.d/dbus and /etc/defaults/dbus but that's the system-wide one, not the per-session one, and I'm out of time for now so I'll try and figure out where that happens later.


3.1415P265E589T932E846R64338

Offline

#3 2023-03-15 00:09:09

boughtonp
Member
From: UK
Registered: 2023-01-19
Posts: 212  
Website

Re: How to remove .dbus from home directory?

Ok, so setting DBUS_SESSION_BUS_ADDRESS isn't the answer - that seems to be more of an informational variable and flag of whether the daemon is already running.

What I think I need to do is duplicate the whole /usr/share/dbus-1/session.conf file, edit the address, then modify /etc/X11/Xsession.d/75dbus_dbus-launch to pass --config-file=FILENAME to dbus-launch which should start the dbus-daemon with that config file only, and thus a single address.

Of course, since the D-Bus config files don't appear to support variables, it'll probably also require a mechanism to create a new config file per user.

Anyway, it's too late to try all that now, so I'll test it out tomorrow.

Tempting to just ditch Mousepad instead, but no doubt some other package is going to depend on dconf/dbus-x11 and have the same issue.


3.1415P265E589T932E846R64338

Offline

#4 2023-03-15 07:19:59

aluma
Member
Registered: 2022-10-26
Posts: 646  

Re: How to remove .dbus from home directory?

There is another problem with .dbus - the files are not deleted on exit and accumulate.
I just put them in tmpfs.
https://dev1galaxy.org/viewtopic.php?pid=38525#p38525

Offline

#5 2023-03-15 13:24:49

boughtonp
Member
From: UK
Registered: 2023-01-19
Posts: 212  
Website

Re: How to remove .dbus from home directory?

Yeah, XDG_RUNTIME_DIR defaults to within /run which is tmpfs, so would solve that.

D-Bus certainly seems to be a convoluted and inflexible mess, for something that should be simple.

There is a different implementation, dbus-broker, which doesn't write to disk at all, however it has a systemd dependency for the launcher part - they're open to alternative launchers, but aren't going to do it themselves:

https://github.com/bus1/dbus-broker/issues/256#issuecomment-775034205 wrote:

However, please note that you do need to write a considerable amount of code to write a replacement launcher and integrate the broker into your alternative system.

If you have a particular question regarding implementing a launcher, please feel free to contact us with further questions! But we do not intend to work on such replacements ourself.

The current launcher looks to be ~4k non-blank lines across 14 files of C - dunno how much is re-usable: https://github.com/bus1/dbus-broker/tre … src/launch

#270 remove dependency on libsystemd?
#256 Support for other init systems (s6 and runit)
#183 [question] Run dbus-broker without systemd running

-

Anyway, I'll go have lunch then see if I can configure the stupid thing to behave.

Last edited by boughtonp (2023-03-15 13:27:17)


3.1415P265E589T932E846R64338

Offline

#6 2023-03-15 13:29:33

F_Sauce
Member
From: Noreg
Registered: 2017-07-07
Posts: 87  

Re: How to remove .dbus from home directory?

Anyway, I'll go have lunch then see if I can configure the stupid thing to behave.

smile

Offline

#7 2023-03-15 14:46:32

boughtonp
Member
From: UK
Registered: 2023-01-19
Posts: 212  
Website

Re: How to remove .dbus from home directory?

Ok, so I reverted all previous changes, then modified /etc/X11/Xsession.d/75dbus_dbus-launch with:

if [ -n "$XDG_RUNTIME_DIR "]; then
    SESSION_CONF="/usr/share/dbus-1/session.conf"
    USER_CONF="$XDG_RUNTIME_DIR/dbus_user_session.conf"
    sed -r 's|<listen>[^<]+|<listen>unix:path='"$XDG_RUNTIME_DIR"'/bus|' "$SESSION_CONF" > "$USER_CONF"
    eval $($DBUSLAUNCH --exit-with-session --sh-syntax --config-file="$USER_CONF")
else
    eval $($DBUSLAUNCH --exit-with-session --sh-syntax)
fi

This creates the socket at /run/user/1000/bus and results in the expected single DBUS_SESSION_BUS_ADDRESS, but is still re-creating the ~/.dbus directory. :@


3.1415P265E589T932E846R64338

Offline

#8 2023-03-15 16:17:43

boughtonp
Member
From: UK
Registered: 2023-01-19
Posts: 212  
Website

Re: How to remove .dbus from home directory?

So the bus address stuff has been a red-herring - that actually gets placed inside the .dbus/session-bus/{uuid} files.

Looking at the relevant source code (dbus-launch-x11.c), it is hard-coded to create .dbus directly in the home directory, with no conditional "place it elsewhere if X" logic.

So basically everything I did yesterday and today was a waste of time, all because of another useless idiot from Red Hat.


3.1415P265E589T932E846R64338

Offline

#9 2023-03-15 19:29:07

boughtonp
Member
From: UK
Registered: 2023-01-19
Posts: 212  
Website

Re: How to remove .dbus from home directory?

Ok, so after a bunch of faff dealing with dbus's convoluted build process, I get it to output a dbus-launch binary.

Then I update the start of get_homedir in dbus-launch-x11.c to do:

home = getenv ("DBUS_HOME");
if ( home != null )
  return home;

Swap the executables over (because some things use absolute path):

mv /usr/bin/dbus-launch{,.orig}
cp /path/to/custom/dbus-launch /usr/local/bin/dbus-launch
cd /usr/bin && ln -vsiT /usr/local/bin/dbus-launch dbus-launch

And finally, reset /etc/X11/Xsession.d/75dbus_dbus-launch to default, before adding:

DBUS_HOME="$XDG_RUNTIME_DIR"
export DBUS_HOME

And now I don't get .dbus in my home directory, because it creates /run/user/1000/.dbus instead.

It is going to mean re-patching each time a relevant D-Bus release happens, but looks like there was only one security update with Chimaera so hopefully wont be too common.

-

One other change I made was to /etc/X11/Xsession.d/95dbus_update-activation-env - removing the --systemd argument stops a pointless warning being output to xsession-errors.

Last edited by boughtonp (2023-03-15 19:57:43)


3.1415P265E589T932E846R64338

Offline

Board footer