diff -r ecc9043b9124 dbus/dbus-internals.c --- a/dbus/dbus-internals.c Thu Sep 03 11:52:26 2009 +0800 +++ b/dbus/dbus-internals.c Thu Sep 03 18:03:17 2009 +0800 @@ -518,6 +518,50 @@ _dbus_generate_random_bytes_buffer (uuid->as_bytes, DBUS_UUID_LENGTH_BYTES - 4); } +/* generate the DBUS UUID from Linux unique boot ID */ +#define LINUX_BOOT_UID_MAXLEN 40 +static int +uuid_from_linux_boot_id(char *buf, size_t buflen) +{ + const char *boot_id_file = "/proc/sys/kernel/random/boot_id"; + char uuid[LINUX_BOOT_UID_MAXLEN], *p; + FILE *f; + size_t len, copied; + int rv = FALSE; + + if (buflen < 33) + return rv; + + f = fopen (boot_id_file, "r"); + if (f == NULL) + return FALSE; + + if (fgets (uuid, LINUX_BOOT_UID_MAXLEN, f) == NULL) + goto out; + + len = strlen (uuid); + if (len < 36) + goto out; + + /* copy ignoring '-' characters */ + for (copied = 0, p = uuid; + *p && (copied < (buflen - 1)); + ++p) + { + if ((*p != '-') && (*p != '\n')) + { + buf[copied] = (*p); + ++copied; + } + } + buf[copied] = '\0'; + rv = TRUE; + +out: + fclose(f); + return rv; +} + /** * Hex-encode a UUID. * @@ -555,9 +599,17 @@ _DBUS_SET_OOM (error); return FALSE; } - - if (!_dbus_file_get_contents (&contents, filename, error)) - goto error; + + + /* attempt to get DBUS UUID from Linux /proc file */ + _dbus_string_set_length (&contents, DBUS_UUID_LENGTH_HEX); + if (!uuid_from_linux_boot_id(_dbus_string_get_data (&contents), + DBUS_UUID_LENGTH_HEX+1)) + { + _dbus_string_set_length (&contents, 0); + if (!_dbus_file_get_contents (&contents, filename, error)) + goto error; + } _dbus_string_chop_white (&contents); diff -r ecc9043b9124 tools/dbus-launch.c --- a/tools/dbus-launch.c Thu Sep 03 11:52:26 2009 +0800 +++ b/tools/dbus-launch.c Thu Sep 03 18:03:17 2009 +0800 @@ -63,6 +63,51 @@ } #define UUID_MAXLEN 40 + +/* generate the DBUS UUID from Linux unique boot ID */ +static int +uuid_from_linux_boot_id(char *buf, size_t buflen) +{ + const char *boot_id_file = "/proc/sys/kernel/random/boot_id"; + char uuid[UUID_MAXLEN], *p; + FILE *f; + size_t len, copied; + int rv = FALSE; + + if (buflen < 33) + return rv; + + f = fopen (boot_id_file, "r"); + if (f == NULL) + return FALSE; + + if (fgets (uuid, UUID_MAXLEN, f) == NULL) + goto out; + + len = strlen (uuid); + if (len < 36) + goto out; + + /* copy ignoring '-' characters */ + for (copied = 0, p = uuid; + *p && (copied < (buflen - 1)); + ++p) + { + if ((*p != '-') && (*p != '\n')) + { + buf[copied] = (*p); + ++copied; + } + } + buf[copied] = '\0'; + + rv = TRUE; + +out: + fclose(f); + return rv; +} + /* Read the machine uuid from file if needed. Returns TRUE if machine_uuid is * set after this function */ static int @@ -75,6 +120,11 @@ if (machine_uuid != NULL) return TRUE; + + /* try and generate from Linux /proc file */ + ret = uuid_from_linux_boot_id(uuid, UUID_MAXLEN); + if (ret) + return ret; f = fopen (DBUS_MACHINE_UUID_FILE, "r"); if (f == NULL) @@ -104,7 +154,6 @@ return ret; } - void verbose (const char *format, ...)