SIGN IN SIGN UP

unix-ffi/machine: Retrieve a unique identifier if one is known.

This commit adds a proper implementation for "machine.unique_id" for
selected systems, as opposed to returning a fixed value in every case.

On a Unix system there are several incompatible ways to retrieve
something that can be called an unique machine identifier.  However, the
only semblance of a specification comes from freedesktop.org, which says
that a file called "/etc/machine-id" has to exist and must contain a
32-digits long hexadecimal identifier.

Given that the current specification is the DBus unique identifier
retrieval mechanism made official, if the identifier file is not found
the code will attempt to read the file provided by DBus.

These changes only apply to Linux and recent BSD systems.  On other
systems the old, fixed value for the machine identifier will be returned
instead - to avoid breaking compatibility with existing code.

The specification used in this commit is available at
https://www.freedesktop.org/software/systemd/man/latest/machine-id.html.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
A
Alessandro Gatti committed
75eb4aa331696161dbb244c813d967b2bbbbaae2
Parent: 47fec41
Committed by Damien George <damien@micropython.org> on 3/19/2026, 11:38:23 AM