From: Kamalesh Babulal Date: Mon, 28 Mar 2022 06:11:50 +0000 (+0530) Subject: samples/c: add empty cgroup v2 creation program X-Git-Tag: v3.0~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2571f378a87d09e5742ed8742448fe35787e7e0d;p=thirdparty%2Flibcgroup.git samples/c: add empty cgroup v2 creation program Add a simple program, that demonstrates the creation of an empty cgroup on cgroup v2. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/samples/c/empty_cgroup_v2.c b/samples/c/empty_cgroup_v2.c new file mode 100644 index 00000000..a6dcf688 --- /dev/null +++ b/samples/c/empty_cgroup_v2.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: LGPL-2.1-only +/** + * Simple program to add empty cgroup v2 + * + * Copyright (c) 2022 Oracle and/or its affiliates. + * Author: Kamalesh babulal + */ + +#include + +#include +#include + +#define CGRP_NAME "empty_cgrp" + +int main(int argc, char **argv) +{ + struct cgroup *cgroup = NULL; + int ret = 0; + + ret = cgroup_init(); + if (ret) { + fprintf(stderr, "cgroup_init failed\n"); + exit(1); + } + + cgroup = cgroup_new_cgroup(CGRP_NAME); + if (!cgroup) { + fprintf(stderr, "Failed to allocate cgroup %s\n", CGRP_NAME); + exit(1); + } + + ret = cgroup_create_cgroup(cgroup, 0); + if (ret) + fprintf(stderr, "Failed to create cgroup %s\n", CGRP_NAME); + + cgroup_free(&cgroup); + + return ret; +}