summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-12-12 11:03:02 +0100
committerThomas Haller <thaller@redhat.com>2018-12-12 12:52:55 +0100
commite9887d4816805d939e91215ad137b94ffa3c2c5d (patch)
treec94026470a846397ed2795c3a360d5eee6ac0dd0
parentd693e03a74bee600ba14ee8dad666ff6fe658ca2 (diff)
downloadNetworkManager-e9887d4816805d939e91215ad137b94ffa3c2c5d.tar.gz
core: split initializing host-id singleton out of nm_utils_host_id_get()
-rw-r--r--src/nm-core-utils.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index 22ca7afed1..8172933457 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -2675,6 +2675,31 @@ typedef struct {
bool is_good:1;
} HostIdData;
+static const HostIdData *
+_host_id_get (void)
+{
+ static const HostIdData *volatile host_id_static;
+ const HostIdData *host_id;
+
+again:
+ host_id = g_atomic_pointer_get (&host_id_static);
+ if (G_UNLIKELY (!host_id)) {
+ static HostIdData host_id_data;
+ static gsize init_value = 0;
+
+ if (!g_once_init_enter (&init_value))
+ goto again;
+
+ host_id_data.is_good = _host_id_read (&host_id_data.host_id,
+ &host_id_data.host_id_len);
+ host_id = &host_id_data;
+ g_atomic_pointer_set (&host_id_static, host_id);
+ g_once_init_leave (&init_value, 1);
+ }
+
+ return host_id;
+}
+
/**
* nm_utils_host_id_get:
* @out_host_id: (out) (transfer none): the binary host key
@@ -2694,25 +2719,9 @@ gboolean
nm_utils_host_id_get (const guint8 **out_host_id,
gsize *out_host_id_len)
{
- static const HostIdData *volatile host_id_static;
const HostIdData *host_id;
-again:
- host_id = g_atomic_pointer_get (&host_id_static);
- if (G_UNLIKELY (!host_id)) {
- static HostIdData host_id_data;
- static gsize init_value = 0;
-
- if (!g_once_init_enter (&init_value))
- goto again;
-
- host_id_data.is_good = _host_id_read (&host_id_data.host_id,
- &host_id_data.host_id_len);
- host_id = &host_id_data;
- g_atomic_pointer_set (&host_id_static, host_id);
- g_once_init_leave (&init_value, 1);
- }
-
+ host_id = _host_id_get ();
*out_host_id = host_id->host_id;
*out_host_id_len = host_id->host_id_len;
return host_id->is_good;
@@ -2722,10 +2731,8 @@ gint64
nm_utils_host_id_get_timestamp (void)
{
struct stat stat_buf;
- const guint8 *host_id;
- gsize host_id_len;
- if (!nm_utils_host_id_get (&host_id, &host_id_len))
+ if (!_host_id_get ()->is_good)
return 0;
if (stat (SECRET_KEY_FILE, &stat_buf) != 0)