67a202
From df8ee48f722d8252bf2556b69e1a42c52dcd86d0 Mon Sep 17 00:00:00 2001
67a202
From: Giuseppe Scrivano <gscrivan@redhat.com>
67a202
Date: Sat, 15 Apr 2023 18:13:57 +0200
67a202
Subject: [PATCH] criu: check if the criu_join_ns_add function exists
67a202
67a202
check that the current libcriu library has the criu_join_ns_add
67a202
function before attempting to use it.
67a202
67a202
Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2184221
67a202
67a202
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
67a202
---
67a202
 src/libcrun/criu.c | 29 ++++++++++++++++-------------
67a202
 1 file changed, 16 insertions(+), 13 deletions(-)
67a202
67a202
diff --git a/src/libcrun/criu.c b/src/libcrun/criu.c
67a202
index 66b50234..a0f01471 100644
67a202
--- a/src/libcrun/criu.c
67a202
+++ b/src/libcrun/criu.c
67a202
@@ -63,7 +63,9 @@ struct libcriu_wrapper_s
67a202
   int (*criu_dump) (void);
67a202
   int (*criu_get_orphan_pts_master_fd) (void);
67a202
   int (*criu_init_opts) (void);
67a202
+#  ifdef CRIU_JOIN_NS_SUPPORT
67a202
   int (*criu_join_ns_add) (const char *ns, const char *ns_file, const char *extra_opt);
67a202
+#  endif
67a202
 #  ifdef CRIU_PRE_DUMP_SUPPORT
67a202
   int (*criu_feature_check) (struct criu_feature_check *features, size_t size);
67a202
   int (*criu_pre_dump) (void);
67a202
@@ -135,7 +137,17 @@ load_wrapper (struct libcriu_wrapper_s **wrapper_out, libcrun_error_t *err)
67a202
   LOAD_CRIU_FUNCTION (criu_dump);
67a202
   LOAD_CRIU_FUNCTION (criu_get_orphan_pts_master_fd);
67a202
   LOAD_CRIU_FUNCTION (criu_init_opts);
67a202
-  LOAD_CRIU_FUNCTION (criu_join_ns_add);
67a202
+
67a202
+#  ifdef CRIU_JOIN_NS_SUPPORT
67a202
+  /* criu_join_ns_add() API was introduced with CRIU version 3.16.1
67a202
+   * Here we check if this API is available at build time to support
67a202
+   * compiling with older version of CRIU, and at runtime to support
67a202
+   * running crun with older versions of libcriu.so.2.
67a202
+   */
67a202
+  if (wrapper->criu_check_version (31601) == 1)
67a202
+    LOAD_CRIU_FUNCTION (criu_join_ns_add);
67a202
+#  endif
67a202
+
67a202
 #  ifdef CRIU_PRE_DUMP_SUPPORT
67a202
   LOAD_CRIU_FUNCTION (criu_feature_check);
67a202
   LOAD_CRIU_FUNCTION (criu_pre_dump);
67a202
@@ -873,15 +885,6 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
67a202
       goto out_umount;
67a202
     }
67a202
 
67a202
-#  ifdef CRIU_JOIN_NS_SUPPORT
67a202
-  /* criu_join_ns_add() API was introduced with CRIU version 3.16.1
67a202
-   * Here we check if this API is available at build time to support
67a202
-   * compiling with older version of CRIU, and at runtime to support
67a202
-   * running crun with older versions of libcriu.so.2.
67a202
-   */
67a202
-  bool join_ns_support = libcriu_wrapper->criu_check_version (31601) == 1;
67a202
-#  endif
67a202
-
67a202
   /* If a namespace defined in config.json we are telling
67a202
    * CRIU use that namespace when restoring the process tree.
67a202
    *
67a202
@@ -915,7 +918,7 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
67a202
 #  ifdef CRIU_JOIN_NS_SUPPORT
67a202
       if (value == CLONE_NEWTIME && def->linux->namespaces[i]->path != NULL)
67a202
         {
67a202
-          if (join_ns_support)
67a202
+          if (libcriu_wrapper->criu_join_ns_add != NULL)
67a202
             libcriu_wrapper->criu_join_ns_add ("time", def->linux->namespaces[i]->path, NULL);
67a202
           else
67a202
             return crun_make_error (err, 0, "shared time namespace restore is supported in CRIU >= 3.16.1");
67a202
@@ -923,7 +926,7 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
67a202
 
67a202
       if (value == CLONE_NEWIPC && def->linux->namespaces[i]->path != NULL)
67a202
         {
67a202
-          if (join_ns_support)
67a202
+          if (libcriu_wrapper->criu_join_ns_add != NULL)
67a202
             libcriu_wrapper->criu_join_ns_add ("ipc", def->linux->namespaces[i]->path, NULL);
67a202
           else
67a202
             return crun_make_error (err, 0, "shared ipc namespace restore is supported in CRIU >= 3.16.1");
67a202
@@ -931,7 +934,7 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
67a202
 
67a202
       if (value == CLONE_NEWUTS && def->linux->namespaces[i]->path != NULL)
67a202
         {
67a202
-          if (join_ns_support)
67a202
+          if (libcriu_wrapper->criu_join_ns_add != NULL)
67a202
             libcriu_wrapper->criu_join_ns_add ("uts", def->linux->namespaces[i]->path, NULL);
67a202
           else
67a202
             return crun_make_error (err, 0, "shared uts namespace restore is supported in CRIU >= 3.16.1");
67a202
-- 
67a202
2.40.0
67a202