Tom Hromatka [Fri, 27 Jan 2023 21:10:45 +0000 (14:10 -0700)]
github: Roll back distcheck and v1 functests to Ubuntu 20.04
Ubuntu 22.04 VMs hosted by Github cannot find the LXD package.
Revert back to Ubuntu 20.04 for the Dist Check and the v1
Functional Test jobs until Github gets this sorted out.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 6b83b7f200ee1b110c526e17c15ecd954e1e363f)
Tom Hromatka [Fri, 27 Jan 2023 21:10:36 +0000 (14:10 -0700)]
ftests: Add a test to exercise invalid systemd parameters
Add a test that exercises invalid parameters to
cgroup_create_scope2().
-----------------------------------------------------------------
Test Results:
Run Date: Jan 25 09:32:58
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
--------------------------------------------------------
setup 0.00
059-sudo-invalid_systemd_create_scope2.py 0.00
teardown 0.00
--------------------------------------------------------
Total Run Time 0.00
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 8012757a76d1d9f179ca33fa156397c0ea53e72b)
Tom Hromatka [Fri, 27 Jan 2023 21:10:18 +0000 (14:10 -0700)]
ftests: Add a test for creating a systemd scope
Add a test to exercise cgroup_create_scope2().
-----------------------------------------------------------------
Test Results:
Run Date: Nov 18 16:12:16
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
------------------------------------------------
setup 0.00
058-sudo-systemd_create_scope2.py 2.05
teardown 0.00
------------------------------------------------
Total Run Time 2.05
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit e6d6a5e441ad6a3a55ddd54892caeca3b032efe3)
Tom Hromatka [Fri, 27 Jan 2023 21:09:47 +0000 (14:09 -0700)]
ftests: Add a test for setting permissions
Add a test to exercise the python bindings to set permissions on
a cgroup.
-----------------------------------------------------------------
Test Results:
Run Date: Nov 17 22:00:51
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------
setup 0.00
057-sudo-set_permissions_v1.py 0.05
teardown 0.00
---------------------------------------------
Total Run Time 0.05
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 1a5e4d894800ea686ecd8fd43faba983e7d4585d)
Tom Hromatka [Fri, 27 Jan 2023 21:09:32 +0000 (14:09 -0700)]
ftests: Add a test for setting permissions
Add a test to exercise the python bindings to set permissions on
a cgroup.
-----------------------------------------------------------------
Test Results:
Run Date: Nov 17 21:55:52
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------
setup 0.00
056-sudo-set_permissions_v2.py 0.05
teardown 0.00
---------------------------------------------
Total Run Time 0.05
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 6bd95ff4ced4be209f0b505df5a0dcc95e8bbc89)
Tom Hromatka [Fri, 27 Jan 2023 21:09:23 +0000 (14:09 -0700)]
ftests: Add a test for set uid/gid
Add a test to exercise the python bindings to set the uid/gid on
a cgroup.
-----------------------------------------------------------------
Test Results:
Run Date: Nov 17 21:10:08
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------
setup 0.00
055-sudo-set_uid_gid_v1.py 0.05
teardown 0.00
-----------------------------------------
Total Run Time 0.05
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 9d2dbb7f22a5bbb9d3c32f405b0d954e1fb77081)
Tom Hromatka [Fri, 27 Jan 2023 21:09:12 +0000 (14:09 -0700)]
ftests: Add a test for set uid/gid
Add a test to exercise the python bindings to set the uid/gid on
a cgroup.
-----------------------------------------------------------------
Test Results:
Run Date: Nov 16 23:12:25
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------
setup 0.00
054-sudo-set_uid_gid_v2.py 0.02
teardown 0.00
-----------------------------------------
Total Run Time 0.02
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit a7b6d6d0690aaa1f9d54736ca69c5fe84fe9a30b)
Tom Hromatka [Fri, 27 Jan 2023 21:08:52 +0000 (14:08 -0700)]
ftests: Change util get uid/gid functions to return an int
get_file_owner_uid() and get_file_owner_gid() previously returned
the owning uid and gid as strings, respectively. Change them to
return the uid and gid as ints.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 3db22a7aec2bc3e6a5f896b57abfffc46cc677e5)
Tom Hromatka [Fri, 27 Jan 2023 21:08:25 +0000 (14:08 -0700)]
systemd: Add cgroup_create_scope2()
Add cgroup_create_scope2() as a wrapper function around
cgroup_create_scope(). cgroup_create_scope2() is more libcgroup-ish
and utilizes struct cgroup rather than systemd-style parameters.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit a1ec6c4ec58710451ef73a2043fdfb192028babc)
Kamalesh Babulal [Tue, 24 Jan 2023 19:43:20 +0000 (12:43 -0700)]
ftests: Add recursive cgdelete function test on shared mount
Add a test that tries deleting non-existing cgroups on shared mount
mount shared by controllers on cgroup v1.
-----------------------------------------------------------------
Test Results:
Run Date: Jan 23 09:21:48
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
----------------------------------------------------------------
setup 0.00
098-cgdelete-non-existing-shared-mnt-cgroup-v1.py 0.03
teardown 0.00
----------------------------------------------------------------
Total Run Time 0.03
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Fix minor variable name typo. Also, add the new test to the EXTRA
DIST list in Makefile.am
(cherry picked from commit 01fc4107de92ea2818de82399cae41ded527addf)
Kamalesh Babulal [Tue, 24 Jan 2023 19:43:02 +0000 (12:43 -0700)]
tests-047: adopt the change to cgroup_delete_cgroup_ext()
With the bug fix to the cgroup_delete_cgroup_ext(), where calling
cgdelete twice back to back (not using -r option) on the cgroup created
on the mount point shared by the controller will fail. Adopt the
change in the API to testcase too.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 1179fa92a66e763db878a963336a154d5acb5fd7)
Kamalesh Babulal [Tue, 24 Jan 2023 19:42:19 +0000 (12:42 -0700)]
src/api: Fix cgroup_delete_cgroup_ext() on shared mount point
In cgroup v1, the controllers can share mount points and when the cgroup
is deleted on one of controller mount point (symlink), as the side effect
are deleted for the controllers sharing the mount point. But this might
not true always, the user might try call cgroup_delete_cgroup_ext() with
a cgroup that doesn't exist over the share mount point and still get the
return code to be zero.
Fix this issue by introducing cgrp_del_shared_mnt flag, that gets set
when deleting the cgroup on the first of the controllers sharing the
mount point and check the flag on the second controller mount point
to ensure that cgroup existed.
Tom Hromatka [Fri, 13 Jan 2023 21:09:55 +0000 (14:09 -0700)]
ftests/cgroup.py: add support to list shared mount point
Cgroup::get_cgroup_mounts(), could create a list of mount points and in
the case of shared mount points such as cpu,cpuacct in the cgroup v1. It
would only add a mount point for the last of the two controllers listed
as the mount point, for example:
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0
mount list will look over cpu controller. Add support to recognize and
add both controllers to the list of mount points.
Reported-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ae6b2682f10eab1366b42566715bce58056827f8)
Khem Raj [Fri, 13 Jan 2023 20:36:35 +0000 (13:36 -0700)]
api: Use GNU strerror_r when available
GNU strerror_r is only available in glibc, musl impelents the XSI
version which is slightly different, therefore check if GNU version is
available before using it, otherwise use the XSI compliant version.
Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Minor formatting change so that the line doesn't exceed 100 chars
(cherry picked from commit 942ef655237b90909edf53eafd121842cdc07ce1)
Kamalesh Babulal [Wed, 11 Jan 2023 17:40:49 +0000 (10:40 -0700)]
tools/cgxset: fix help/usage formatting
The help/usage output is misaligned, which is a mix of tabs and spaces.
Fix it by using only spaces for the alignment, so that we have a visual
representation of output in the code too, instead of having unaligned
info()'s needing to calculate the tabs stops always.
Before:
-------
Usage: cgxset [-r <name=value>] <cgroup_path> ...
or: cgxset --copy-from <source_cgroup_path> <cgroup_path> ...
Set the parameters of given cgroup(s)
-1, --v1 Provided parameters are in v1 format
-2, --v2 Provided parameters are in v2 format
-i, --ignore-unmappable Do not return an error for settings that cannot be converted
-r, --variable <name> Define parameter to set
--copy-from <source_cgroup_path> Control group whose parameters will be copied
After:
------
Usage: cgxset [-r <name=value>] <cgroup_path> ...
or: cgxset --copy-from <source_cgroup_path> <cgroup_path> ...
Set the parameters of given cgroup(s)
-1, --v1 Provided parameters are in v1 format
-2, --v2 Provided parameters are in v2 format
-i, --ignore-unmappable Do not return an error for settings that cannot be converted
-r, --variable <name> Define parameter to set
--copy-from <source_cgroup_path> Control group whose parameters will be copied
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 44a90415da4ee96bee2d7b51673cd53fe54824a1)
Tom Hromatka [Wed, 4 Jan 2023 21:08:18 +0000 (21:08 +0000)]
ftests: Add a test for cgroup_attach_task_pid()
Add a functional test for cgroup_attach_task_pid().
-----------------------------------------------------------------
Test Results:
Run Date: Jan 04 21:06:16
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-------------------------------------------------
setup 0.00
053-sudo-cgroup_attach_task_pid.py 2.06
teardown 0.00
-------------------------------------------------
Total Run Time 2.06
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 4 Jan 2023 21:07:43 +0000 (21:07 +0000)]
ftests: Add a test for cgroup_attach_task()
Add a functional test for cgroup_attach_task()
-----------------------------------------------------------------
Test Results:
Run Date: Jan 04 21:03:14
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
---------------------------------------------
setup 0.00
052-sudo-cgroup_attach_task.py 0.02
teardown 0.00
---------------------------------------------
Total Run Time 0.02
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Tue, 20 Dec 2022 22:41:22 +0000 (22:41 +0000)]
ftests: Add a test for cgroup_get_cgroup()
Add a functional test to exercise cgroup_get_cgroup()
-----------------------------------------------------------------
Test Results:
Run Date: Dec 20 22:41:28
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
--------------------------------------------
setup 0.00
051-sudo-cgroup_get_cgroup.py 0.03
teardown 0.00
--------------------------------------------
Total Run Time 0.03
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Tue, 20 Dec 2022 22:38:43 +0000 (22:38 +0000)]
python: Add python bindings for several functions
Add python bindings for several C functions:
cgroup_get_cgroup()
cgroup_delete_cgroup()
cgroup_get_controller_count()
cgroup_get_controller_by_index()
cgroup_get_controller_name()
Also add two python methods to wrap cgroup_get_cgroup() and cgroup_delete() to
make these interfaces more pythonic. The other three C functions are used
internally to implement these pythonic methods.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Tue, 20 Dec 2022 22:35:54 +0000 (22:35 +0000)]
api: Add functions for iterating through the cgroup struct
Add functions to iterate through the cgroup structure:
cgroup_get_controller_count() - returns the number of controllers
within the cgroup struct
cgroup_get_controller_by_index() - returns the cgroup_controller
pointer corresponding with the requested index
cgroup_get_controller_name() - given a cgroup_controller pointer,
get the controller's name
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Tom Hromatka [Wed, 21 Dec 2022 21:00:21 +0000 (14:00 -0700)]
cgsnapshot: Close tags in output file on errors
Close tags in the output file when cgsnapshot encounters an
error. For example, if cgsnapshot cannot translate a uid to a
username, the "perm {" tag still needs a closing "}".
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Kamalesh Babulal [Wed, 21 Dec 2022 15:46:26 +0000 (21:16 +0530)]
tools/cgsnapshot: limit the controller to search to user lists
is_ctlr_on_list(), returns on the first match of the list of controllers
the user has passed on the command line, this might serve as an
optimization but as a side effect we search through the whole list of
controllers, those the user has not asked for. Let's reset the list of
controllers to controllers available on wanted_consts array (list of
controllers required by the user) and controllers array (list of
available controllers).
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 20 Dec 2022 16:09:19 +0000 (21:39 +0530)]
gunit/test-015: Populate subtree_control for leaf cgroup
We no more rely on the cgroup's parent subtree_control file to verify
if a controller is enabled for a cgroup. So, populate the leaf/child
cgroups with subtree_control file similar to the parent cgroup.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 20 Dec 2022 16:09:13 +0000 (21:39 +0530)]
gunit/test-012: Create subtree_control for leaf cgroup
The test case relies on the parent cgroup's subtree_control file, while
creating a cgroup to verify the controllers enabled in created cgroup v2
and the current code cleverly emulates it. With the change to enable
the controller at the leaf cgroup this emulation gets difficult, so
introduce a dummy cgroup v2 mount that will help in the construction of
the path when the cgroup v2 is created with the empty controller because
the brilliance lies in emulating it by manually creating the
subtree_control file to give the impression of enabling the controller
in the cgroup v2 cgroup.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 20 Dec 2022 16:09:08 +0000 (21:39 +0530)]
api: cgroup v2 – read subtree_control of the leaf node
With cgroup v2, while checking if a controller is enabled for cgroup,
the tree is walked and checked up to the parent cgroup of the leaf node,
this guarantees that the controller available for the leaf cgroups in
the cgroup.controllers file, but this is incomplete because of the
controller can be both either enabled or disabled in the
cgroups.subtree_control file of the leaf cgroup.
Fix this ambiguity by reading until the leaf node's
cgroup.subtree_control file, instead.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Kamalesh Babulal [Tue, 20 Dec 2022 16:09:02 +0000 (21:39 +0530)]
api: cgroup v2 – enable controller at the leaf node
With cgroup v2, while creating a cgroup with a controller, the whole
hierarchy tree is walked, and the controller is enabled up to the parent
cgroup of the leaf node, this guarantees that the attached controller is
available in the leaf cgroups cgroup.controllers file, but this is
incomplete because the controller is not enabled in the leaf cgroup.
We do not have a separate API that is called to enable the controllers
but as a workaround, one can always call the
cgroup_set_values_recursive() to enable the controller in the leaf node.
To maintain the idea/compatibility with the cgroup v1, where creating a
cgroup on the controller mount point/hierarchy is equivalent to enabling
the controller in the cgroup v2, let's enable the controller in the leaf
node too.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
The cgxget was forked from cgget and messages/warnings printed to the
user still carry cgget keyword, which might get confusing to the user.
Replace the warnings/errors/info displayed to the user, along with
non-history occurrences of 'cgget' -> 'cgxget' throughout the file.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 15fcda71fd6d8bc0e8196ee7a283859f7a63653e)
Kamalesh Babulal [Mon, 19 Dec 2022 16:20:46 +0000 (09:20 -0700)]
api.c: fix segfault in cgroup_attach_task_pid()
When the user passes NULL in place of struct cgroup argument, the pid
passed as the second parameter is expected to be attached to root
hierarchies of the controllers in the case of legacy/hybrid modes and
to the root hierarchy in the case of unified mode.
The current code will segfault, while attempting to dereference a NULL
pointer, fix it by using the controller names, from cg_mount_table(),
that is already populated with the information and also remove the
controller_is_enabled check is specific to the cgroup v2 hierarchy.
With the root cgroup v2 hierarchy, all the controllers are enabled by
default, hence the check returns true always.
Reproducer:
int main(int argc, char *argv[]) {
pid_t pid = atoi(argv[1]);
int ret;
ret = cgroup_init();
if (ret) {
printf("Failed to initialize: %s\n", cgroup_strerror(ret));
exit(1);
}
ret = cgroup_attach_task_pid(NULL, pid);
if (ret) {
printf("Failed to attach %d to root cgroup(s): %s\n", pid, cgroup_strerror(ret));
exit(1);
}
exit (0);
}
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 5ab9fb86e5b863f54454b64eeb9066848b994f37)
Tom Hromatka [Tue, 1 Nov 2022 22:14:44 +0000 (16:14 -0600)]
ftests: Add a test to create a systemd scope
-----------------------------------------------------------------
Test Results:
Run Date: Sep 06 14:46:15
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
-----------------------------------------------------
setup 0.00
049-sudo-systemd_create_scope.py 0.08
teardown 0.00
-----------------------------------------------------
Total Run Time 0.03
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit c311f7cc6d0fc67e29be853ff767ee969838d67d)
Tom Hromatka [Tue, 1 Nov 2022 22:14:30 +0000 (16:14 -0600)]
ftests: Add support for running 'sudo' suite of tests
Some tests require sudo support for python/C bindings. This is
awkward to implement using the Run() class and error prone.
Instead, invoke the entire test with sudo permissions via a separate
invocation of ftests.py. This ensures that existing tests (that
don't require sudo) remain the same and don't accidentally get
elevated privileges.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 986b4ab0afd551c232b5337195d60dab6405379b)
Tom Hromatka [Tue, 1 Nov 2022 22:13:38 +0000 (16:13 -0600)]
systemd: Add function to create a systemd scope
Add a function, cgroup_create_scope(), to create a systemd
scope. This scope can be delegated, in other words the cgroup
management of this scope can be delegated away from systemd.
This is the official way to create a cgroup that systemd will
not interfere with.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 74680bf4a65bb9badcbe784bedd7067ed2fa0dbe)
Kamalesh Babulal [Mon, 31 Oct 2022 17:19:29 +0000 (11:19 -0600)]
github/workflows/continuous-intergation: Adopt SPDX License tag
Adopt SPDX license tag for all the source files, those already have
LGPL 2.1 boilerplate in them and those missing license information.
All the files in the project fall under project license, hence
explicitly adding LGPL-2.1-only identifier to the files missing license
information. Adopting SPDX license helps the compliance tools to
determine the license and also helps in reducing the repetitive license
boilerplate across source files.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit c9f92c6beb7a435f4c99e45d33eefaa11ca42b5d)
Kamalesh Babulal [Mon, 31 Oct 2022 17:19:15 +0000 (11:19 -0600)]
github/actions/setup-libcgroup: Adopt SPDX License tag
Adopt SPDX license tag for all the source files, those already have
LGPL 2.1 boilerplate in them and those missing license information.
All the files in the project fall under project license, hence
explicitly adding LGPL-2.1-only identifier to the files missing license
information. Adopting SPDX license helps the compliance tools to
determine the license and also helps in reducing the repetitive license
boilerplate across source files.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 8153c89b66b039ce321bdcd941bbc143db81e2a5)
Kamalesh Babulal [Mon, 31 Oct 2022 17:19:01 +0000 (11:19 -0600)]
github/actions/code-coverage: Adopt SPDX License tag
Adopt SPDX license tag for all the source files, those already have
LGPL 2.1 boilerplate in them and those missing license information.
All the files in the project fall under project license, hence
explicitly adding LGPL-2.1-only identifier to the files missing license
information. Adopting SPDX license helps the compliance tools to
determine the license and also helps in reducing the repetitive license
boilerplate across source files.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 5917d46164139cf9709fd9a20230abcf9c63772d)
Kamalesh Babulal [Mon, 31 Oct 2022 17:10:29 +0000 (11:10 -0600)]
tests: remove github/{actions,workflows}
Remove the GitHub actions and workflows from the tests directory, they
are not run anymore after the movement of libcgroup-tests into libcgroup
repo. Also, the libcgroup repo covers all the steps executed by
libcgroup-test actions/workflows.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 206f96d01122430c6b48cde93df84ec68f1a3c0a)
Kamalesh Babulal [Mon, 31 Oct 2022 17:07:13 +0000 (11:07 -0600)]
workflows/ci: add Python lint
Add Python lint to the GitHub workflow. This was previously part of
the libcgroup-test project GitHub workflow, which hosted most of the
python source code. Now that libcgroup-test is part of libcgroup repo,
let's add the lint workflow here too.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit e211970c9ee24f3d4967737536f06264d03c24b9)
Kamalesh Babulal [Tue, 25 Oct 2022 21:27:39 +0000 (15:27 -0600)]
api.c: fix resource leak in cg_chmod_path()
Fix resource leak, reported by Coverity Tool:
CID 276160 (#1 of 1): Resource leak (RESOURCE_LEAK)10. leaked_handle:
Handle variable fd going out of scope leaks the handle.
In cg_chmod_path(), the file descriptor checks for fd > 0, Coverity
warns about the possibility of the file descriptor being 0, fix it by
changing the check from '0' -> '-1'.
Fixes: 91cf2e4b7ceb ("api.c: fix file open in cg_chmod_path()") Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit f2e192adfb6c6824163b4db8da07efe6d01f617b)
Tom Hromatka [Tue, 25 Oct 2022 21:20:21 +0000 (15:20 -0600)]
ftests: Add test for cgroup_setup_mode()
Add a python bindings test for cgroup_setup_mode()
-----------------------------------------------------------------
Test Results:
Run Date: Oct 18 19:28:31
Passed: 1 test(s)
Skipped: 0 test(s)
Failed: 0 test(s)
-----------------------------------------------------------------
Timing Results:
Test Time (sec)
------------------------------------------------
setup 0.00
048-pybindings-get_cgroup_mode.py 0.00
teardown 0.00
------------------------------------------------
Total Run Time 0.00
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 40293e5466cfa3f6900d83e642c2847b1b32ebe2)
Tom Hromatka [Tue, 18 Oct 2022 19:27:06 +0000 (19:27 +0000)]
ftests: Add function to get the cgroup mode
Add a function to the Cgroup class to get the cgroup mode. This
function is analogous to the C function, cgroup_setup_mode() and
can be used to verify the behavior of cgroup_setup_mode().
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
(cherry picked from commit 4cc7e611477d7c88f95afe2b39c85605af17b834)
Kamalesh Babulal [Tue, 25 Oct 2022 21:18:55 +0000 (15:18 -0600)]
tools/cgget: add support to print cgroup setup
Add a new switch (-m), that will print the current cgroup mode the
system/VM is booted it. It uses the API, cgroup_setup_mode() that
returns one of the modes (Legacy/Unified/Hybrid) the system is
booted with.
$ cgget -m
Legacy Mode (Cgroup v1 only).
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ca42f62cdf5e4b0c3bb3920ab5aa52476cbe8096)
Kamalesh Babulal [Tue, 25 Oct 2022 21:18:40 +0000 (15:18 -0600)]
api: Introduce a new API to find the cgroup setup mode
This patch introduces a new API to detect the current cgroup setup
mode (Legacy/Unified/Hybrid). The setup will depend on the Linux
Kernel's grub command line, the system/VM is booted with.
Uses cases:
Depending upon the cgroup setup, the users can enable or disable
features in their applications. Like some controllers are only available
on cgroup v2, so they might need to set/get settings for those available
controllers only.
Suggested-by: Tom Hromatka <tom.hromatka@oracle.com> Suggested-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 4aefa6d04f5e8a4b3914bdcdf2825943c4aef3fc)
Make the --enable-samples option's bash code POSIX-complaint. There
might be warnings issued while running configure on other shells like
/bin/sh, those default on Debian systems.
Fixes: 6197ca3d693f ("configure: introduce --enable-samples option") Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit d3ac1bb4cd0ab94fb168bbcaa917496a7d537c64)
Control the building and testing (make check) of the tests using the
if/endif WITH_TESTS guard based on the configuration options passed.
If the --enable-tests (default on) is passed during ./configure step,
the SUBDIRS directories (ftests/gunit) are recused into build and
make check are run.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ce2717610acff6384b161787591533591fb42228)
As per automake manual[1], DIST_SUBDIRS should be used to recurse into
the subdirectories those we want to ship as part of make dist and use
SUBDIRS for conditionally building the directories. Adopt this rule
across the source.
tools/lssubsys: use exit code 129 on invalid usage
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit f074adb0dfee3f4fdbb2eec4a930b93cbe9cbc0a)
tools/lscgroup: use exit code 129 on invalid usage
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit fc51374a90897b20096c4986dae3800815b2a968)
tools/cgconfig: use exit code 129 on invalid usage
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 946f92b6042faa539d2a146eb4c42aa61e061b1f)
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 6e4850f1a8b9f19f5b98aab49d88d29c369d23af)
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit f46f811f55d0218d0450998c74e98c4b3578607c)
tools/cgsnapshot: use exit code 129 on invalid usage
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 8af5441bcbfee6e624455f124ef2273251f7c111)
tools/cgcreate: use exit code 129 on invalid usage
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit c6f59dce4f5ef39a70e7775ab8a6ea89dc5ce469)
tools/cgclassify: use exit code 129 on invalid usage
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit f9c9d39c12c21fd6168a212b36625e9b24384b68)
tools/cgdelete: use exit code 129 on invalid usage
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 1020f6279444f016f8e12816f827d14cd5a8d525)
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 13f8ddd305a24a17934f467244f0dc3887f45a48)
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit d7abb100847f94cdb1328a26f3b92627b2cbf38e)
The exit code 1 refers to general error and using -1 wraps to
255, both codes do not signify bad arguments. Let's use exit code 129
(EXIT_BADARGS) for hinting to the users about invalid usage.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 8c2b005b4544fea075b92d609d792d76913836db)
Introduce EXIT_BADARGS (129) error code to return, when the user passes
an invalid list of arguments. Currently, we return exit 1 which refers
to a general error, or exit -1 which wraps to 255, both codes do not
signify bad arguments. Let's use EXIT_BADARGS (exit code 129), from
tools hinting to the users about invalid usage.
Suggested-by: Tom Hromatka <tom.hromatka@oracle.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 38d48493df8b5cba30b7ae29d738b11f4e1958e1)
Running ./bootstrap.sh step, throws bunch of warnings related to
samples/c:
samples/c/Makefile.am:23: warning: variable 'empty_cgroup_v2_SOURCES' is defined but no program or
samples/c/Makefile.am:23: library has 'empty_cgroup_v2' as canonical name (possible typo)
samples/c/Makefile.am:17: warning: variable 'get_all_controller_SOURCES' is defined but no program or
samples/c/Makefile.am:17: library has 'get_all_controller' as canonical name (possible typo)
samples/c/Makefile.am:14: warning: variable 'get_controller_SOURCES' is defined but no program or
samples/c/Makefile.am:14: library has 'get_controller' as canonical name (possible typo)
samples/c/Makefile.am:15: warning: variable 'get_mount_point_SOURCES' is defined but no program or
samples/c/Makefile.am:15: library has 'get_mount_point' as canonical name (possible typo)
samples/c/Makefile.am:20: warning: variable 'get_procs_SOURCES' is defined but no program or
samples/c/Makefile.am:20: library has 'get_procs' as canonical name (possible typo)
samples/c/Makefile.am:18: warning: variable 'get_variable_names_SOURCES' is defined but no program or
samples/c/Makefile.am:18: library has 'get_variable_names' as canonical name (possible typo)
samples/c/Makefile.am:22: warning: variable 'logger_SOURCES' is defined but no program or
samples/c/Makefile.am:22: library has 'logger' as canonical name (possible typo)
samples/c/Makefile.am:16: warning: variable 'proctest_SOURCES' is defined but no program or
samples/c/Makefile.am:16: library has 'proctest' as canonical name (possible typo)
samples/c/Makefile.am:12: warning: variable 'read_stats_SOURCES' is defined but no program or
samples/c/Makefile.am:12: library has 'read_stats' as canonical name (possible typo)
samples/c/Makefile.am:10: warning: variable 'setuid_SOURCES' is defined but no program or
samples/c/Makefile.am:10: library has 'setuid' as canonical name (possible typo)
samples/c/Makefile.am:19: warning: variable 'test_named_hierarchy_SOURCES' is defined but no program or
samples/c/Makefile.am:19: library has 'test_named_hierarchy' as canonical name (possible typo)
samples/c/Makefile.am:13: warning: variable 'walk_task_SOURCES' is defined but no program or
samples/c/Makefile.am:13: library has 'walk_task' as canonical name (possible typo)
samples/c/Makefile.am:11: warning: variable 'walk_test_SOURCES' is defined but no program or
samples/c/Makefile.am:11: library has 'walk_test' as canonical name (possible typo)
samples/c/Makefile.am:21: warning: variable 'wrapper_test_SOURCES' is defined but no program or
samples/c/Makefile.am:21: library has 'wrapper_test' as canonical name (possible typo)
src/Makefile.am: installing 'build-aux/depcomp'
fix this by introducing --enable-samples option at configure, which by
default is disabled. If the user wishes to run the sample code, they
can build them by passing the configure option.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 6197ca3d693ff063e70a9065bd4e8d9a2c7802fa)
cgget segfaulted on v2.0.2 branch, with:
cgget: cannot find controller 'incal' in group '016cgget'
Fatal error: glibc detected an invalid stdio handle
Aborted (core dumped)
It was caught by ftests/016-cgget-invalid_options.py on Ubuntu 22.04, a
simple reproducer on the v2.0.2 branch:
$ sudo ./src/tools/cgget -n -v -r invalid.setting 016cgget
assuming 016cgget cgroup exists.
It is due to the invalid controller name passed to the
cgroup_read_value_begin(), which returns failure and callee
get_cv_value() in the error clean up path, does a fclose(handle).
If (handle != NULL) succeeds because its uninitialized and has some
garbage value. Fix this by initializing the handle to NULL.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit c8af263a8802b48a3fdc0de68e6408d72619e172)
Tom Hromatka [Fri, 16 Sep 2022 17:34:45 +0000 (11:34 -0600)]
github: Add more dependencies to the apt install command
Add a few more dependencies - cmake, bison, flex, byacc, g++, autoconf,
libtool, and automake - to the apt-get install list. Also add a '-y'
flag to automatically install them.
Tom Hromatka [Fri, 16 Sep 2022 17:28:05 +0000 (11:28 -0600)]
tests: Merge libcgroup-tests repo back into libcgroup repo
Merge the libcgroup-tests repo back into the main libcgroup repo.
The submodules logic has been deleted and the tests are now directly
hosted within the libcgroup repo.
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Sam James [Wed, 14 Sep 2022 14:16:36 +0000 (08:16 -0600)]
configure.ac: fix bashism
configure scripts need to be runnable with a POSIX-compliant /bin/sh.
On many (but not all!) systems, /bin/sh is provided by Bash, so errors
like this aren't spotted. Notably Debian defaults to /bin/sh provided
by dash which doesn't tolerate such bashisms as '=='.
This retains compatibility with bash.
Fixes configure warnings/errors like:
```
checking whether to build static libraries... no
./configure: 14089: test: xno: unexpected operator
checking for x86_64-pc-linux-gnu-g++... x86_64-pc-linux-gnu-g++
```
Signed-off-by: Sam James <sam@gentoo.org> Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 4fc7dc1036676901d555fe296cca661a783e405b)
tools/cgsnapshot: fix wrong array size in is_ctrl_on_list()
GCC throws -Wstringop-overflow warning:
CC cgsnapshot-cgsnapshot.o
cgsnapshot.c: In function 'parse_controllers':
cgsnapshot.c:540:53: warning: 'is_ctlr_on_list' accessing 16777216 bytes in a region of size 409600 [-Wstringop-overflow=]
540 | if ((!(flags & FL_LIST) || (is_ctlr_on_list(controllers, cont_names))) &&
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cgsnapshot.c:540:53: note: referencing argument 2 of type 'char (*)[4096]'
cgsnapshot.c:495:12: note: in a call to function 'is_ctlr_on_list'
495 | static int is_ctlr_on_list(char controllers[CG_CONTROLLER_MAX][FILENAME_MAX],
| ^~~~~~~~~~~~~~~
cgsnapshot.c:560:37: warning: 'is_ctlr_on_list' accessing 16777216 bytes in a region of size 409600 [-Wstringop-overflow=]
560 | if ((!(flags & FL_LIST) || (is_ctlr_on_list(controllers, cont_names))) &&
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cgsnapshot.c:560:37: note: referencing argument 2 of type 'char(*)[4096]'
cgsnapshot.c:495:12: note: in a call to function 'is_ctlr_on_list'
495 | static int is_ctlr_on_list(char controllers[CG_CONTROLLER_MAX][FILENAME_MAX],
| ^~~~~~~~~~~~~~~
the warning is seen due to the mismatch in the array size of the second
argument passed to is_ctlr_on_list() from parse_controllers(). Fix,
this long standing warning by chaging the size of the second function
argument in is_ctrl_on_list().
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 4362c8d32d5d8813a9a40bebe744aeaec5fbf953)
Kamalesh Babulal [Wed, 31 Aug 2022 21:09:45 +0000 (15:09 -0600)]
src/api.c: support /proc mounted with subset=pid
/proc filesystem can be mounted with subset=pid as one of its mount
options. This option hides all the top-level files and directories,
those are not related to processes. The cgroup v1 filesystem depends
on the /proc/cgroups to populate the cgroups controllers and will fail
during the cgroup_init() phase, when not available, whereas cgroup v2
considers this as a deprecated file and recommends reading the list of
controller from <unified mount point>/cgroup.controllers[1].
Support this valid /proc mount point only when the system is booted with
the unified mode and will fail to initialize in the case we find the
cgroup v1 mounted, i.e, the system booted with legacy or hybrid mode.
Kamalesh Babulal [Wed, 31 Aug 2022 21:09:30 +0000 (15:09 -0600)]
api.c: use /proc/self/mounts
Use /proc/self/mount instead of /proc/mounts, which is a symbolic link
to the former. The symbolic link creation can be traced back to Linux
Kernel commit 59c7572e82d6 ("proc: remove fs/proc/proc_misc.c"). Also,
the /proc/mounts are not available in the cases where the /proc is
mounted with subset=pid option.
As per kernel docs filesystems/procs.rst:
"subset=pid hides all top level files and directories in the procfs that
are not related to tasks."
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 16be308b037bbe11a54b692c227e160f1132eabe)
Kamalesh Babulal [Wed, 31 Aug 2022 20:28:53 +0000 (14:28 -0600)]
configure: remove AM_COND for --disable-tests
With the usage of DIST_SUBDIRS, the makefiles for the tests/* will be
generated, and building the tests/* should be controlled using SUBDIRS.
Remove the AM_COND condition for --disable-tests in the AC_CONFIG_FILES
list.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 9830b92f5a5e821aa80d350faa5bf7e54be060f4)
Kamalesh Babulal [Wed, 31 Aug 2022 20:28:35 +0000 (14:28 -0600)]
make: use DIST_SUBDIRS
As per automake manual[1], DIST_SUBDIRS should be used to recurse into
the subdirectories those we want to ship as part of make dist and use
SUBDIRS for conditionally building the directories. Adopt this rule
across the source.
Kamalesh Babulal [Wed, 31 Aug 2022 14:31:34 +0000 (08:31 -0600)]
github/workflows: add support for testing different cgroup setups
Add support to run the Github workflow on three parallel runners, each
of them have a unique cgroup setup:
cgroup v1 only (legacy), cgroup v1/v2 (hybrid), cgroup v2 only (unified).
With this change, we should be able to run every patch against all
combination of cgroup setups.
Suggested-by: Tom Hromatka <tom.hromatka@oracle.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Remove the clean logic and instead use the Github Actions
$ACTIONS_RUNNER_HOOK_JOB_STARTED environment variable
(cherry picked from commit 995202c4f53fe6c7d5b90e95c58f77c7a4280d71)
Kamalesh Babulal [Mon, 29 Aug 2022 21:08:38 +0000 (15:08 -0600)]
api.c: fix file open in cg_chmod_path()
In cg_chmod_path(), the commit 8b9665c29cb8 ("api.c: fix TOCTOU in
cg_chmod_path()), converted the file operations from stat -> fstat and
chmod -> fchmod to fix a Coverity warning. The newly replaced file
operations operate on file descriptors and hence introduced a side
effect of opening the file at the wrong code block, that would only work
as expected when the caller calls cg_chmod_path() with owner_is_umask
set.
Fix it by moving the file operation out of the conditional block, so it
works in both of the cases of owner_is_umask being set or unset.
Fixes: 8b9665c29cb8 ("api.c: fix TOCTOU in cg_chmod_path()) Suggested-by: Tom Hromatka <tom.hromatka@oracle.com> Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 91cf2e4b7ceb19c02d66af717c18d7bc64fa5df9)
Kamalesh Babulal [Wed, 24 Aug 2022 18:46:35 +0000 (12:46 -0600)]
api.c: fix TOCTOU in cg_chmod_path()
Fix TOCTOU warning, reported by Coverity Tool:
CID 258267 (#1 of 1): Time of check time of use (TOCTOU).
fs_check_call: Calling function stat to perform check on path.
in cg_chmod_path(), the file name is stat() and not immediately followed
by the file operation. One way to fix it, open the file and use the file
descriptor to manipulate the file.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 8b9665c29cb812c255687d6e5cb5262a6fe30a40)
Kamalesh Babulal [Tue, 23 Aug 2022 17:24:50 +0000 (11:24 -0600)]
tools/tools-common.h: introduce CGROUP_LOG_CONT level for logging
There are cases, where we might want to print a very long/multiline log
message to the user. We could call the cgroup_log(), multiple times
to fit the log message, but the downside is that every time the
cgroup_log() called, the log level is prefixed to the message, hence
introducing loglevel char string in the mid of the log message.
Introduce a new logging level, CGROUP_LOG_CONT and cgroup_cont() macro,
that will continue printing the log message, when loglevel is set to
other than default log level. The above code can be rewritten as:
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Fix typo in commit message
(cherry picked from commit db2039f6ad75988e0aad3f5306d5d8c02aa4b040)
Kamalesh Babulal [Tue, 23 Aug 2022 17:24:32 +0000 (11:24 -0600)]
log: introduce CGROUP_LOG_CONT level for logging
There are cases, where we might want to print a very long/multiline log
message to the user. We could call the cgroup_log(), multiple times to
fit the log message, but the downside is that every time the
cgroup_log() called, the log level is prefixed to the message, hence
introducing loglevel char string in the mid of the log message.
For example, calling the cgroup_warn() twice to print a long warning:
cgroup_warn("cgroup v1 expects /proc/cgroup, check if ");
cgroup_warn("/proc mounted with subset=pid option\n");
Introduce a new logging level, CGROUP_LOG_CONT and cgroup_cont() macro,
that will continue printing the log message, when loglevel is set to other
than default log level. The above code can be rewritten as:
cgroup_warn("cgroup v1 expects/proc/cgroup, check if ");
cgroup_cont("/proc mounted with subset=pid option\n");
Kamalesh Babulal [Wed, 10 Aug 2022 17:13:19 +0000 (11:13 -0600)]
daemon/cgrulesengd: check the bytes read in cgre_receive_unix_domain_msg()
Fix ignoring the number of bytes read, warning reported by Coverity
tool:
CID 258286 (#1 of 1): Ignoring number of bytes read (CHECKED_RETURN).
check_return: read(int, void *, size_t) returns the number of bytes
read, but it is ignored.
In cgre_receive_unix_domain_msg(), the number of bytes read() is
ignored, while reading from the flag value of the pid. Coverity warns on
not checking the number of bytes read, fix it.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ed283eab173addd3b5c2dd666de8f3086125e106)
Kamalesh Babulal [Wed, 10 Aug 2022 17:03:55 +0000 (11:03 -0600)]
api.c: add precision to fscanf(), in cgroup_get_current_controller_path()
Fix calling risky function warning, reported by Coverity tool:
CID 258301 (#1 of 1): Calling risky function
(DC.STREAM_BUFFER)dont_call: fscanf assumes an arbitrarily long string,
so callers must use correct precision specifiers or never use fscanf.
As per secure coding standard, using '%s' in the fscanf() is not
recommend, hence fix it by using the precision of macro
FILENAME_MAX borrowed from Linux Kernel for the maximum
allowed controller/subsys_name length.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ac05eb49c498aa5047070a4620456fa7a10e1910)
TJH: Small fix in the commit comment.