summary refs log tree commit diff
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/nm-glib-aux/nm-ref-string.c24
-rw-r--r--shared/nm-platform/nmp-netns.c19
-rw-r--r--shared/nm-utils/nm-test-utils.h17
3 files changed, 43 insertions, 17 deletions
diff --git a/shared/nm-glib-aux/nm-ref-string.c b/shared/nm-glib-aux/nm-ref-string.c
index 902f1c80..1084c47f 100644
--- a/shared/nm-glib-aux/nm-ref-string.c
+++ b/shared/nm-glib-aux/nm-ref-string.c
@@ -49,20 +49,28 @@ _ref_string_equal(gconstpointer pa, gconstpointer pb)
 static void
 _ASSERT(const RefString *rstr0)
 {
-#if NM_MORE_ASSERTS
     int r;
 
     nm_assert(rstr0);
 
-    G_LOCK(gl_lock);
-    r = g_atomic_int_get(&rstr0->ref_count);
+    if (NM_MORE_ASSERTS > 0) {
+        r = g_atomic_int_get(&rstr0->ref_count);
+        nm_assert(r > 0);
+        nm_assert(r < G_MAXINT);
+    }
 
-    nm_assert(r > 0);
-    nm_assert(r < G_MAXINT);
+    nm_assert(rstr0->r.str == rstr0->str_data);
+    nm_assert(rstr0->r.str[rstr0->r.len] == '\0');
 
-    nm_assert(rstr0 == g_hash_table_lookup(gl_hash, rstr0));
-    G_UNLOCK(gl_lock);
-#endif
+    if (NM_MORE_ASSERTS > 10) {
+        G_LOCK(gl_lock);
+        r = g_atomic_int_get(&rstr0->ref_count);
+        nm_assert(r > 0);
+        nm_assert(r < G_MAXINT);
+
+        nm_assert(rstr0 == g_hash_table_lookup(gl_hash, rstr0));
+        G_UNLOCK(gl_lock);
+    }
 }
 
 /**
diff --git a/shared/nm-platform/nmp-netns.c b/shared/nm-platform/nmp-netns.c
index c7cb617b..f97339a7 100644
--- a/shared/nm-platform/nmp-netns.c
+++ b/shared/nm-platform/nmp-netns.c
@@ -158,25 +158,26 @@ _netns_stack_get_impl(void)
     g_array_set_clear_func(s, _netns_stack_clear_cb);
     _netns_stack = s;
 
+    /* register a destructor function to cleanup the array. If we fail
+     * to do so, we will leak NMPNetns instances (and their file descriptor) when the
+     * thread exits. */
+    if (pthread_key_create(&key, (void (*)(void *)) g_array_unref) != 0)
+        _LOGE(NULL, "failure to initialize thread-local storage");
+    else if (pthread_setspecific(key, s) != 0)
+        _LOGE(NULL, "failure to set thread-local storage");
+
     /* at the bottom of the stack we must try to create a netns instance
      * that we never pop. It's the base to which we need to return. */
     netns = _netns_new(&error);
+
     if (!netns) {
-        _LOGE(NULL, "failed to create initial netns: %s", error->message);
+        _LOGD(NULL, "failed to create initial netns: %s", error->message);
         return s;
     }
 
     /* we leak this instance inside the stack. */
     _stack_push(s, netns, _CLONE_NS_ALL);
 
-    /* finally, register a destructor function to cleanup the array. If we fail
-     * to do so, we will leak NMPNetns instances (and their file descriptor) when the
-     * thread exits. */
-    if (pthread_key_create(&key, (void (*)(void *)) g_array_unref) != 0)
-        _LOGE(NULL, "failure to initialize thread-local storage");
-    else if (pthread_setspecific(key, s) != 0)
-        _LOGE(NULL, "failure to set thread-local storage");
-
     return s;
 }
 
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h
index 6b41c11e..d51f972e 100644
--- a/shared/nm-utils/nm-test-utils.h
+++ b/shared/nm-utils/nm-test-utils.h
@@ -624,6 +624,23 @@ __nmtst_init(int *       argc,
         g_setenv("G_MESSAGES_DEBUG", "all", TRUE);
     }
 
+    /* "tc" is in /sbin, which might not be in $PATH of a regular user. Unconditionally
+     * add "/bin" and "/sbin" to $PATH for all tests. */
+    {
+        static char *path_new;
+        const char * path_old;
+
+        g_assert(!path_new);
+
+        path_old = g_getenv("PATH");
+        path_new = g_strjoin("",
+                             path_old ?: "",
+                             (nm_str_is_empty(path_old) ? "" : ":"),
+                             "/bin:/sbin",
+                             NULL);
+        g_setenv("PATH", path_new, TRUE);
+    }
+
     /* Delay messages until we setup logging. */
     for (i = 0; i < debug_messages->len; i++)
         __NMTST_LOG(g_message, "%s", g_array_index(debug_messages, const char *, i));