Add a function, cgroup_version(), that returns the current
version of the libcgroup library.

Signed-off-by: Tom Hromatka <tom.hroma...@oracle.com>
---
 configure.ac                            |  1 +
 include/libcgroup/.gitignore            |  1 +
 include/libcgroup/{init.h => init.h.in} | 19 +++++++++++++++++++
 src/api.c                               | 11 +++++++++++
 src/libcgroup.map                       |  1 +
 5 files changed, 33 insertions(+)
 create mode 100644 include/libcgroup/.gitignore
 rename include/libcgroup/{init.h => init.h.in} (80%)

diff --git a/configure.ac b/configure.ac
index 7b43a9ec16b6..2d10a527c1d4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -201,6 +201,7 @@ AC_CONFIG_FILES([Makefile
        scripts/init.d/cgred
        samples/Makefile
        include/Makefile
+       include/libcgroup/init.h
        doc/Makefile
        doc/man/Makefile
        dist/Makefile
diff --git a/include/libcgroup/.gitignore b/include/libcgroup/.gitignore
new file mode 100644
index 000000000000..6d7255a8ce8a
--- /dev/null
+++ b/include/libcgroup/.gitignore
@@ -0,0 +1 @@
+init.h
diff --git a/include/libcgroup/init.h b/include/libcgroup/init.h.in
similarity index 80%
rename from include/libcgroup/init.h
rename to include/libcgroup/init.h.in
index ea2dcc98bc60..9c63e684ada6 100644
--- a/include/libcgroup/init.h
+++ b/include/libcgroup/init.h.in
@@ -13,6 +13,25 @@
 extern "C" {
 #endif
 
+#define CGROUP_VER_MAJOR       @LIBRARY_VERSION_MAJOR@
+#define CGROUP_VER_MINOR       @LIBRARY_VERSION_MINOR@
+#define CGROUP_VER_RELEASE     @LIBRARY_VERSION_RELEASE@
+
+struct cgroup_library_version {
+       unsigned int major;
+       unsigned int minor;
+       unsigned int release;
+};
+
+/**
+ * Query the library version information
+ *
+ * This function returns a pointer to a populated cgroup_library_version
+ * struct.  The caller does not need to free the structure when finished.
+ *
+ */
+const struct cgroup_library_version *cgroup_version(void);
+
 /**
  * @defgroup group_init 1. Initialization
  * @{
diff --git a/src/api.c b/src/api.c
index bd77b54da7d5..91f4615a2f43 100644
--- a/src/api.c
+++ b/src/api.c
@@ -50,6 +50,12 @@
 #include <linux/un.h>
 #include <grp.h>
 
+const struct cgroup_library_version library_version = {
+       .major = CGROUP_VER_MAJOR,
+       .minor = CGROUP_VER_MINOR,
+       .release = CGROUP_VER_RELEASE,
+};
+
 /*
  * The errno which happend the last time (have to be thread specific)
  */
@@ -5680,3 +5686,8 @@ int cgroup_get_controller_version(const char * const 
controller,
 
        return ECGROUPNOTEXIST;
 }
+
+const struct cgroup_library_version *cgroup_version(void)
+{
+       return &library_version;
+}
diff --git a/src/libcgroup.map b/src/libcgroup.map
index 3ce7e1b00c58..99788ac56f45 100644
--- a/src/libcgroup.map
+++ b/src/libcgroup.map
@@ -144,4 +144,5 @@ CGROUP_3.0 {
        cgroup_convert_cgroup;
        cgroup_cgxget;
        cgroup_cgxset;
+       cgroup_version;
 } CGROUP_2.0;
-- 
2.31.1



_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to