The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/1535
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === 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 <[email protected]>
From 12461428889932e8918553a111bbedaf8fce2db6 Mon Sep 17 00:00:00 2001 From: Christian Brauner <[email protected]> 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 <[email protected]> --- 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 <[email protected]> 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 <[email protected]> --- 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:
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
