]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
samples/c: add sample program for cgroup_setup_mode()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 25 Apr 2023 12:27:02 +0000 (12:27 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 26 Apr 2023 19:25:25 +0000 (13:25 -0600)
Add a sample program to demonstrate the usage of the cgroup_setup_mode()
to the developers.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
samples/c/Makefile.am
samples/c/get_setup_mode.c [new file with mode: 0644]

index 7a73bcb4cda01785c9c3ed1f26a3f65a984a3e13..28d4ddd6ccfa967031296df325873f3cb2de3de8 100644 (file)
@@ -6,7 +6,8 @@ if WITH_SAMPLES
 noinst_PROGRAMS = setuid walk_test read_stats walk_task get_controller \
                  get_mount_point proctest get_all_controller           \
                  get_variable_names test_named_hierarchy               \
-                 get_procs wrapper_test logger empty_cgroup_v2
+                 get_procs wrapper_test logger empty_cgroup_v2         \
+                 get_setup_mode
 
 setuid_SOURCES=setuid.c
 walk_test_SOURCES=walk_test.c
@@ -22,5 +23,6 @@ get_procs_SOURCES=get_procs.c
 wrapper_test_SOURCES=wrapper_test.c
 logger_SOURCES=logger.c
 empty_cgroup_v2_SOURCES=empty_cgroup_v2.c
+get_setup_mode=get_setup_mode.c
 
 endif
diff --git a/samples/c/get_setup_mode.c b/samples/c/get_setup_mode.c
new file mode 100644 (file)
index 0000000..e983f4f
--- /dev/null
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: LGPL-2.1-only
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates
+ *
+ * Author: Kamalesh Babulal <kamalesh.babulal@oracle.com>
+ *
+ * Description: This file contains the sample code to demonstrate usage of
+ *             cgroup_setup_mode() API.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libcgroup.h>
+
+int main(void)
+{
+       enum cg_setup_mode_t setup_mode;
+       int ret;
+
+       ret = cgroup_init();
+       if (ret) {
+               printf("cgroup_init failed with %s\n", cgroup_strerror(ret));
+               exit(1);
+       }
+
+       setup_mode = cgroup_setup_mode();
+       switch(setup_mode) {
+       case CGROUP_MODE_LEGACY:
+               printf("cgroup mode: Legacy\n");
+               break;
+       case CGROUP_MODE_HYBRID:
+               printf("cgroup mode: Hybrid\n");
+               break;
+       case CGROUP_MODE_UNIFIED:
+               printf("cgroup mode: Unified\n");
+               break;
+       default:
+               printf("cgroup mode: Unknown\n");
+               break;
+       }
+
+       return 0;
+}