[nftables,1/8] src: libnftnl: run single-initcalls only once
diff mbox series

Message ID 20190816144241.11469-2-fw@strlen.de
State Accepted
Delegated to: Pablo Neira
Headers show
Series
  • add typeof keyword
Related show

Commit Message

Florian Westphal Aug. 16, 2019, 2:42 p.m. UTC
---
 src/libnftables.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/src/libnftables.c b/src/libnftables.c
index a693c0c69075..b169dd2f2afe 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -90,11 +90,6 @@  static void nft_init(struct nft_ctx *ctx)
 	realm_table_rt_init(ctx);
 	devgroup_table_init(ctx);
 	ct_label_table_init(ctx);
-
-	gmp_init();
-#ifdef HAVE_LIBXTABLES
-	xt_init();
-#endif
 }
 
 static void nft_exit(struct nft_ctx *ctx)
@@ -142,8 +137,17 @@  static void nft_ctx_netlink_init(struct nft_ctx *ctx)
 EXPORT_SYMBOL(nft_ctx_new);
 struct nft_ctx *nft_ctx_new(uint32_t flags)
 {
+	static bool init_once;
 	struct nft_ctx *ctx;
 
+	if (!init_once) {
+		init_once = true;
+		gmp_init();
+#ifdef HAVE_LIBXTABLES
+		xt_init();
+#endif
+	}
+
 	ctx = xzalloc(sizeof(struct nft_ctx));
 	nft_init(ctx);