[LTP] [PATCH 5/6] tools: Implement tst_cgctl binary utility
Luke Nowakowski-Krijger
luke.nowakowskikrijger@canonical.com
Wed Jan 5 11:00:06 CET 2022
Implement a binary utility that creates an interface to make calls to
the cgroup C API.
This will effectively allow shell scripts to make calls to the cgroup C
api.
Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
tools/cgroup/Makefile | 7 ++++
tools/cgroup/tst_cgctl.c | 69 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
create mode 100644 tools/cgroup/Makefile
create mode 100644 tools/cgroup/tst_cgctl.c
diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile
new file mode 100644
index 000000000..81810bf4d
--- /dev/null
+++ b/tools/cgroup/Makefile
@@ -0,0 +1,7 @@
+top_srcdir ?= ../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+MAKE_TARGETS := tst_cgctl
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
\ No newline at end of file
diff --git a/tools/cgroup/tst_cgctl.c b/tools/cgroup/tst_cgctl.c
new file mode 100644
index 000000000..ef20e7485
--- /dev/null
+++ b/tools/cgroup/tst_cgctl.c
@@ -0,0 +1,69 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include "tst_cgroup.h"
+
+static int cgctl_require(const char *ctrl, int test_pid)
+{
+ struct tst_cgroup_opts opts;
+
+ memset(&opts, 0, sizeof(opts));
+ opts.test_pid = test_pid;
+
+ tst_cgroup_require(ctrl, &opts);
+ tst_cgroup_print_config();
+
+ return 0;
+}
+
+static int cgctl_cleanup(const char *config)
+{
+ tst_cgroup_scan();
+ tst_cgroup_load_config(config);
+ tst_cgroup_cleanup();
+
+ return 0;
+}
+
+static int cgctl_print(void)
+{
+ tst_cgroup_scan();
+ tst_cgroup_print_config();
+
+ return 0;
+}
+
+static int cgctl_process_cmd(int argc, char *argv[])
+{
+ int test_pid;
+ const char *cmd_name = argv[1];
+
+ if (!strcmp(cmd_name, "require")) {
+ test_pid = atoi(argv[3]);
+ if (!test_pid) {
+ fprintf(stderr, "tst_cgctl: Invalid test_pid '%s' given\n",
+ argv[3]);
+ return 1;
+ }
+ return cgctl_require(argv[2], test_pid);
+ } else if (!strcmp(cmd_name, "cleanup")) {
+ return cgctl_cleanup(argv[2]);
+ } else if (!strcmp(cmd_name, "print")) {
+ return cgctl_print();
+ }
+
+ fprintf(stderr, "tst_cgctl: Unknown command '%s' given\n", cmd_name);
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ if (argc < 2 || argc > 4) {
+ fprintf(stderr, "tst_cgctl: Invalid number of arguements given");
+ return 1;
+ }
+
+ return cgctl_process_cmd(argc, argv);
+}
\ No newline at end of file
--
2.32.0
More information about the ltp
mailing list