summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-04-21 06:41:03 (GMT)
committerThomas Haller <thaller@redhat.com>2022-04-21 07:40:33 (GMT)
commitec712a4514e667b6f7fc3a54a10d4d4f65d1b5c7 (patch)
tree16f20d59e121c1b466d46adcc78f46ae4e8db41e
parent85e3c5d423a0ab8f8414f892998323c886484725 (diff)
downloadlibnl-ec712a4514e667b6f7fc3a54a10d4d4f65d1b5c7.zip
libnl-ec712a4514e667b6f7fc3a54a10d4d4f65d1b5c7.tar.gz
libnl-ec712a4514e667b6f7fc3a54a10d4d4f65d1b5c7.tar.bz2
tests: cleanup unshare_user() and use _nltst_fclose()
-rw-r--r--tests/nl-test-util.c21
-rw-r--r--tests/nl-test-util.h8
2 files changed, 20 insertions, 9 deletions
diff --git a/tests/nl-test-util.c b/tests/nl-test-util.c
index c65d09b..345f504 100644
--- a/tests/nl-test-util.c
+++ b/tests/nl-test-util.c
@@ -65,24 +65,27 @@ static void unshare_user(void)
_nltst_assert_errno(r == 0);
/* Since Linux 3.19 we have to disable setgroups() in order to map users.
- * Just proceed if the file is not there. */
+ * Just proceed if the file is not there. */
f = fopen("/proc/self/setgroups", "we");
if (f) {
- fprintf(f, "deny");
- fclose(f);
+ r = fprintf(f, "deny");
+ _nltst_assert_errno(r > 0);
+ _nltst_fclose(f);
}
/* Map current UID to root in NS to be created. */
f = fopen("/proc/self/uid_map", "we");
- ck_assert(f);
- fprintf(f, "0 %d 1", uid);
- fclose(f);
+ _nltst_assert_errno(f);
+ r = fprintf(f, "0 %d 1", uid);
+ _nltst_assert_errno(r > 0);
+ _nltst_fclose(f);
/* Map current GID to root in NS to be created. */
f = fopen("/proc/self/gid_map", "we");
- ck_assert(f);
- fprintf(f, "0 %d 1", gid);
- fclose(f);
+ _nltst_assert_errno(f);
+ r = fprintf(f, "0 %d 1", gid);
+ _nltst_assert_errno(r > 0);
+ _nltst_fclose(f);
}
struct nltst_netns *nltst_netns_enter(void)
diff --git a/tests/nl-test-util.h b/tests/nl-test-util.h
index 15ec0b5..259ab59 100644
--- a/tests/nl-test-util.h
+++ b/tests/nl-test-util.h
@@ -34,6 +34,14 @@
_nltst_assert_errno(_r == 0); \
} while (0)
+#define _nltst_fclose(f) \
+ do { \
+ int _r; \
+ \
+ _r = fclose((f)); \
+ _nltst_assert_errno(_r == 0); \
+ } while (0)
+
/*****************************************************************************/
void nltst_netns_fixture_setup(void);