@@ -103,17 +103,26 @@ static struct {
103103void nltst_netns_fixture_setup (void )
104104{
105105 ck_assert (!_netns_fixture_global .nsdata );
106-
107106 _netns_fixture_global .nsdata = nltst_netns_enter ();
108- _assert_nltst_netns (_netns_fixture_global .nsdata );
109107}
110108
111109void nltst_netns_fixture_teardown (void )
112110{
113- _assert_nltst_netns (_netns_fixture_global .nsdata );
114111 _nl_clear_pointer (& _netns_fixture_global .nsdata , nltst_netns_leave );
115112}
116113
114+ bool nltst_netns_has_netns (void )
115+ {
116+ return !_netns_fixture_global .nsdata ;
117+ }
118+
119+ bool nltst_netns_skip_without_netns (void )
120+ {
121+ if (nltst_netns_has_netns ())
122+ return false;
123+ printf ("SKIP test: no netns\n" );
124+ return true;
125+ }
117126/*****************************************************************************/
118127
119128static void unshare_user (void )
@@ -149,7 +158,13 @@ static void unshare_user(void)
149158 }
150159 r = fprintf (f , "0 %d 1" , uid );
151160 _nltst_assert_errno (r > 0 );
152- _nltst_fclose (f );
161+ r = fclose (f );
162+ if (r != 0 && errno == EPERM ) {
163+ /* Seems this can happen during close . Ignore the inability to
164+ * unshare.
165+ * *sigh* */
166+ } else
167+ _nltst_assert_errno (r == 0 );
153168
154169 /* Map current GID to root in NS to be created. */
155170 f = fopen ("/proc/self/gid_map" , "we" );
@@ -172,6 +187,9 @@ struct nltst_netns *nltst_netns_enter(void)
172187 unshare_user ();
173188
174189 r = unshare (CLONE_NEWNET | CLONE_NEWNS );
190+ if (r == EPERM ) {
191+ return NULL ;
192+ }
175193 _nltst_assert_errno (r == 0 );
176194
177195 /* We need a read-only /sys so that the platform knows there's no udev. */
0 commit comments