Commit dea3c49c authored by Thomas Haller's avatar Thomas Haller

utils: add nm_utils_get_boot_id() util to read "/proc/sys/kernel/random/boot_id"

parent 142009c6
......@@ -3040,6 +3040,39 @@ out:
return NULL;
}
/*****************************************************************************/
const char *
nm_utils_get_boot_id (void)
{
static const char *boot_id;
if (G_UNLIKELY (!boot_id)) {
gs_free char *contents = NULL;
nm_utils_file_get_contents (-1, "/proc/sys/kernel/random/boot_id", 0,
&contents, NULL, NULL);
if (contents) {
g_strstrip (contents);
if (contents[0]) {
/* clone @contents because we keep @boot_id until the program
* ends.
* nm_utils_file_get_contents() likely allocated a larger
* buffer chunk initially and (although using realloc to shrink
* the buffer) it might not be best to keep this memory
* around. */
boot_id = g_strdup (contents);
}
}
if (!boot_id)
boot_id = nm_utils_uuid_generate ();
}
return boot_id;
}
/*****************************************************************************/
/* Returns the "u" (universal/local) bit value for a Modified EUI-64 */
static gboolean
get_gre_eui64_u_bit (guint32 addr)
......
......@@ -322,6 +322,8 @@ gboolean nm_utils_machine_id_parse (const char *id_str, /*uuid_t*/ guchar *out_u
guint8 *nm_utils_secret_key_read (gsize *out_key_len, GError **error);
const char *nm_utils_get_boot_id (void);
/* IPv6 Interface Identifer helpers */
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment