[lxc-devel] [lxc/master] [RFC] api extension: lxc_config_item_is_supported()

brauner on Github lxc-bot at linuxcontainers.org
Wed May 3 10:25:58 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 935 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170503/f6a416c5/attachment.bin>
-------------- next part --------------
From 12461428889932e8918553a111bbedaf8fce2db6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 May 2017 12:12:22 +0200
Subject: [PATCH 1/2] lxccontainer: add lxc_config_item_is_supported()

This adds lxc_config_item_is_supported() as API extension. It allows to check
whether a given config item (e.g. lxc.autodev) is supported by this LXC
instance. The function is useful in the following scenarios:
1. Users have compiled liblxc from source and have removed a config items from
   the corresponding struct in confile.c. (For example, embedded users might
   decide to gut a bunch of options that they cannot use.)
2. Callers that want to check for a specific configuration item independent of
   the version numbers exposed in our version.h header.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/lxccontainer.c | 5 +++++
 src/lxc/lxccontainer.h | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 4786908..3cee18c 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -4522,3 +4522,8 @@ int list_all_containers(const char *lxcpath, char ***nret,
 	free(ct_name);
 	return ret;
 }
+
+bool lxc_config_item_is_supported(const char *key)
+{
+	return !!lxc_getconfig(key);
+}
diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
index 06bec58..57301e6 100644
--- a/src/lxc/lxccontainer.h
+++ b/src/lxc/lxccontainer.h
@@ -1022,6 +1022,13 @@ int list_all_containers(const char *lxcpath, char ***names, struct lxc_container
  */
 void lxc_log_close(void);
 
+/*!
+ * \brief Check if the configuration item is supported by this LXC instance.
+ *
+ * \param key Configuration item to check for.
+ */
+bool lxc_config_item_is_supported(const char *key);
+
 #ifdef  __cplusplus
 }
 #endif

From add40e6270ae06cbdde6ad5c19daa51d05fa3c42 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 3 May 2017 12:24:39 +0200
Subject: [PATCH 2/2] test: add lxc_config_item_is_supported() tests

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/tests/get_item.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/tests/get_item.c b/src/tests/get_item.c
index cb4ba42..4e4a511 100644
--- a/src/tests/get_item.c
+++ b/src/tests/get_item.c
@@ -391,6 +391,17 @@ int main(int argc, char *argv[])
 		fprintf(stderr, "%d: failed clearing lxc.hook\n", __LINE__);
 		goto out;
 	}
+
+	if (!lxc_config_item_is_supported("lxc.arch")) {
+		fprintf(stderr, "%d: failed to report \"lxc.arch\" as supported configuration item\n", __LINE__);
+		goto out;
+	}
+
+	if (lxc_config_item_is_supported("lxc.nonsense")) {
+		fprintf(stderr, "%d: failed to detect \"lxc.nonsense\" as unsupported configuration item\n", __LINE__);
+		goto out;
+	}
+
 	printf("All get_item tests passed\n");
 	ret = EXIT_SUCCESS;
 out:


More information about the lxc-devel mailing list