/** * Obtains the machine UUID of the machine this process is running on. * * The returned string must be freed with dbus_free(). * * This UUID is guaranteed to remain the same until the next reboot * (unless the sysadmin foolishly changes it and screws themselves). * It will usually remain the same across reboots also, but hardware * configuration changes or rebuilding the machine could break that. * * The idea is that two processes with the same machine ID should be * able to use shared memory, UNIX domain sockets, process IDs, and other * features of the OS that require both processes to be running * on the same OS kernel instance. * * The machine ID can also be used to create unique per-machine * instances. For example, you could use it in bus names or * X selection names. * * The machine ID is preferred over the machine hostname, because * the hostname is frequently set to "localhost.localdomain" and * may also change at runtime. * * You can get the machine ID of a remote application by invoking the * method GetMachineId from interface org.freedesktop.DBus.Peer. * * If the remote application has the same machine ID as the one * returned by this function, then the remote application is on the * same machine as your application. * * The UUID is not a UUID in the sense of RFC4122; the details * are explained in the D-Bus specification. * * @returns a 32-byte-long hex-encoded UUID string, or #NULL if insufficient memory */ char* dbus_get_local_machine_id (void) { DBusString uuid; char *s; s = NULL; if (!_dbus_string_init (&uuid)) return NULL; /* The documentation says dbus_get_local_machine_id() only fails on OOM; * this can actually also fail if the D-Bus installation is faulty * (no UUID) *and* reading a new random UUID fails, but we have no way * to report that */ if (!_dbus_get_local_machine_uuid_encoded (&uuid, NULL) || !_dbus_string_steal_data (&uuid, &s)) { _dbus_string_free (&uuid); return NULL; } else { _dbus_string_free (&uuid); return s; } }
/** * Obtains the machine UUID of the machine this process is running on. * * The returned string must be freed with dbus_free(). * * This UUID is guaranteed to remain the same until the next reboot * (unless the sysadmin foolishly changes it and screws themselves). * It will usually remain the same across reboots also, but hardware * configuration changes or rebuilding the machine could break that. * * The idea is that two processes with the same machine ID should be * able to use shared memory, UNIX domain sockets, process IDs, and other * features of the OS that require both processes to be running * on the same OS kernel instance. * * The machine ID can also be used to create unique per-machine * instances. For example, you could use it in bus names or * X selection names. * * The machine ID is preferred over the machine hostname, because * the hostname is frequently set to "localhost.localdomain" and * may also change at runtime. * * You can get the machine ID of a remote application by invoking the * method GetMachineId from interface org.freedesktop.DBus.Peer. * * If the remote application has the same machine ID as the one * returned by this function, then the remote application is on the * same machine as your application. * * The UUID is not a UUID in the sense of RFC4122; the details * are explained in the D-Bus specification. * * @returns a 32-byte-long hex-encoded UUID string, or #NULL if insufficient memory */ char* dbus_get_local_machine_id (void) { DBusString uuid; char *s; s = NULL; if (!_dbus_string_init (&uuid)) return NULL; if (!_dbus_get_local_machine_uuid_encoded (&uuid) || !_dbus_string_steal_data (&uuid, &s)) { _dbus_string_free (&uuid); return NULL; } else { _dbus_string_free (&uuid); return s; } }