mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-05 13:40:40 +02:00
utils: add nm_utils_get_boot_id() util to read "/proc/sys/kernel/random/boot_id"
This commit is contained in:
parent
142009c6a5
commit
dea3c49ce2
2 changed files with 35 additions and 0 deletions
|
|
@ -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 */
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue