Bug 23679

Summary: Set DBUS UUID from Linux random boot ID
Product: dbus Reporter: Grahame Bowland <grahame>
Component: coreAssignee: D-Bus Maintainers <dbus>
Status: RESOLVED MOVED QA Contact: D-Bus Maintainers <dbus>
Severity: enhancement    
Priority: low CC: grahame, msniko14, smcv, walters
Version: 1.2.xKeywords: patch
Hardware: All   
OS: Linux (All)   
Whiteboard: review- (Thiago/Colin)
i915 platform: i915 features:
Attachments: patch to provide dbus UUID from /proc on linux

Description Grahame Bowland 2009-09-03 03:36:26 UTC
Created attachment 29167 [details] [review]
patch to provide dbus UUID from /proc on linux

Linux provides a file, /proc/sys/kernel/random/boot_id, which provides a 32 character hex random UUID which remains constant after the machine has booted. I'm running some software using DBUS on machines with NFS mounted filesystems, and want to avoid having to make widespread system changes to allow the UUID to be unique on each machine.

We have an application using D-BUS that runs over remote X back to a thin-terminal display. The user will generally launch it from an Xterm, and it will pick up an autolaunched dbus session daemon.

Unfortunately as the UUIDs on the servers are in common, the autolaunch code picks up the dbus session bus that has been started on a completely different machine (via X atom).

Attached patch uses the Linux provided boot UUID instead of relying on a file. It might need tidying up but hopefully it's useful and can be merged. It falls back to reading the UUID file if it can't use /proc.

Cheers
Comment 1 Thiago Macieira 2009-09-03 03:48:16 UTC
The patch changes existing behaviour.

We recommend that D-Bus installations over network simply create /var/lib/dbus/machine-id on boot. You can cat the contents of the unique boot ID into the file yourself, or you can run dbus-uuidgen --ensure in a boot script.
Comment 2 Grahame Bowland 2009-09-03 04:17:13 UTC
(In reply to comment #1)
> The patch changes existing behaviour.
> 
> We recommend that D-Bus installations over network simply create
> /var/lib/dbus/machine-id on boot. You can cat the contents of the unique boot
> ID into the file yourself, or you can run dbus-uuidgen --ensure in a boot
> script.

Hi Thiago

This D-Bus installation is into a prefix, as a 'stack' of software provided so we can use recent versions of all the libraries even on ancient Linux distributions (eg. RHEL 3/4). At the moment D-Bus tries to read $PREFIX/var/lib/dbus/machine-id; in our case that's some file in eg. /opt/package/

It'd be nice to avoid the need to install a system-wide init script to get this software working. I've had an idea though; what if I changed D-Bus to optionally take the UUID from a file named by an environment variable; maybe DBUS_UUID_FILE. If the environment variable is not set, the default file is read.

Then I could make the UUID reading code ignore '-' characters in the file contents, so that you can specify the Linux /proc file via that environment variable. Existing behaviour doesn't change, but it's suddenly easier to use D-Bus for software like this on a cluster.

Thanks for the feedback on the patch!




Comment 3 Thiago Macieira 2009-09-03 05:00:09 UTC
You should install software properly. Set D-Bus to search /var/lib/dbus/machine-id, not $PREFIX/var/lib/..... When configuring it:

./configure --localstatedir=/var

The default-supplied init script already runs dbus-uuidgen --ensure. All you need to do is configure it properly before installing.
Comment 4 Colin Walters 2011-01-07 09:54:40 UTC
The main problem with this is that we actually need the uuid to be persistent across restarts.

The machine uuid allows, for example, saving user per-machine preferences (think e.g. per-user monitor state).

You may not care about breaking this kind of thing if your home directories are also fixed to a machine, but rather than generating a random one from each boot, you could write a script to generate a predictable one from e.g. the machine MAC address.  The UUID doesn't need to be secret, just available and persistent.
Comment 5 Thiago Macieira 2011-07-27 05:45:33 UTC
Actually, I don't mind using the boot ID as the D-Bus machine ID. I even suggested a way for the the reporter do exactly that.

What I disagree with is making this the fix for improper installation. Therefore, I don't see the need to accept this patch.

Colin: the D-Bus machine ID is not guaranteed to be persistent across reboots. Some machines generate it on boot already, such as terminal clients or network boots.
Comment 6 Colin Walters 2011-07-27 09:47:37 UTC
(In reply to comment #5)
>
> Colin: the D-Bus machine ID is not guaranteed to be persistent across reboots.
> Some machines generate it on boot already, such as terminal clients or network
> boots.

Of course, anyone can do anything by hacking arbitrary changes into custom network boot scripts.

The point though is that the machine UUID is presently a good thing to use for software that wants, well, a machine-specific arbitrary unique key.  Useful for implementing something equivalent to HKEY_LOCAL_MACHINE if you're familiar with the Windows registry for example.

Concretely, say in GNOME we wanted to save the per-user monitor configuration (sizing, rotation).  It's very convenient to key this off of the machine UUID, so it works even in shared home directory scenarios.

People doing network boots could, for whatever their deployment is, generate a *stable* uuid from some machine characteristic (ethernet MAC e.g.).

If we add a configure or runtime option to make it random, this important characteristic of the DBus UUID is lost.
Comment 7 Colin Walters 2011-07-27 10:55:17 UTC
Sorry, I just repeated comment 4 without realizing I'd posted it here earlier.

It's funny how similar my new and old comments are...anyways =)
Comment 8 Thiago Macieira 2011-07-27 11:38:38 UTC
The UUID is guaranteed to remain stable within one boot session. But we've never promised it remains stable across them. Therefore, it must never be committed to permanent storage.

It has never had that characteristic.

We may want to add it, but we haven't yet.
Comment 9 Simon McVittie 2011-11-03 09:42:09 UTC
Bug #42531 (Android support) has a related patch.
Comment 10 Simon McVittie 2011-11-03 09:44:30 UTC
(In reply to comment #8)
> Therefore, it must never be committed to permanent storage.

From context, I think Thiago meant: it is not guaranteed to be committed to permanent storage.
Comment 11 GitLab Migration User 2018-10-12 21:06:01 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/dbus/dbus/issues/20.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.