]> git.ipfire.org Git - thirdparty/libcgroup.git/log
thirdparty/libcgroup.git
6 months agolibcgroup.map: include cgroup_get_cgroup_name release-3.1
Kamalesh Babulal [Thu, 2 Jan 2025 12:58:56 +0000 (12:58 +0000)] 
libcgroup.map: include cgroup_get_cgroup_name

Using cgroup_get_cgroup_name() API, fails with:

gcc -o cgrp_get_cgrp_name cgrp_get_cgrp_name.c -lcgroup
/usr/bin/ld: /tmp/ccIyBv5c.o: in function `main':
cgrp_get_cgrp_name.c:(.text+0xaa): undefined reference to `cgroup_get_cgroup_name'
collect2: error: ld returned 1 exit status

The API was introduced by commit ca32d88ef56b1 ("wrappers: Add a
cgroup_get_cgroup_name API") but missed adding it to libcgroup.map file,
causing the linkage issue. Fix the issue by adding the API at the
libcgroup.map under version it was introduced.

Fixes: https://github.com/libcgroup/libcgroup/issues/459
Reported-by: Ron Nazarov <ron@noisytoot.org>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 861a9369d234739a9a3bcf8419ba6be9c8af40dc)

18 months agoman: update cgconfig.conf with systemd settings
Kamalesh Babulal [Mon, 1 Jan 2024 09:55:21 +0000 (15:25 +0530)] 
man: update cgconfig.conf with systemd settings

Update the cgconfig.conf for available systemd settings, along with an
example.

Fixes: https://github.com/libcgroup/libcgroup/issues/418
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Minor grammatical changes
(cherry picked from commit 77b9a528deb965be03043bbb27a66e9dd66ae4af)

18 months agoftests/081: add support for cgroup hybrid mode
Kamalesh Babulal [Wed, 1 Nov 2023 10:43:33 +0000 (16:13 +0530)] 
ftests/081: add support for cgroup hybrid mode

Add support for cgroup hybrid mode with controllers in cgroup v2.

-----------------------------------------------------------------
Test Results:
        Run Date:                          Nov 01 10:40:32
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                             Time (sec)
        -----------------------------------------------------------
        setup                                                  0.00
        081-pybindings-cgrp_get_curr_ctrl_path-v1.py           2.09
        teardown                                               0.00
        -----------------------------------------------------------
        Total Run Time                                         2.09

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 ca72882b1ddcadfaac8aa4a6432ed5e8f2b3c9f6)

19 months agoRFE: Bump actions/upload-artifact from 3 to 4
dependabot[bot] [Mon, 18 Dec 2023 22:51:48 +0000 (22:51 +0000)] 
RFE: Bump actions/upload-artifact from 3 to 4

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ba388afd577f4e35f56c607f8933a4762ce448ba)

19 months agoRFE: Bump github/codeql-action from 2 to 3
dependabot[bot] [Mon, 18 Dec 2023 22:51:45 +0000 (22:51 +0000)] 
RFE: Bump github/codeql-action from 2 to 3

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ca8ccaf3fc08d826e3cee8311c6cdee31f6d3236)

19 months agoRFE: Bump actions/setup-python from 4 to 5
dependabot[bot] [Mon, 11 Dec 2023 22:46:52 +0000 (22:46 +0000)] 
RFE: Bump actions/setup-python from 4 to 5

Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 11a0abb2023b3fc1e65886459803b5949fb934b1)

20 months agoapi: export cgroup_is_systemd_enabled()
Kamalesh Babulal [Wed, 6 Dec 2023 15:43:03 +0000 (15:43 +0000)] 
api: export cgroup_is_systemd_enabled()

export cgroup_is_systemd_enabled(), the function will helpful developers
to check if the systemd support is enabled.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit d84f5456961b4c5c6212af237719e37e38aa5d11)

20 months agoftests/088: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:44:51 +0000 (09:44 +0000)] 
ftests/088: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 6d5138cae69d4878c022f4335c1cde33931e4084)

20 months agoftests/086: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:43:48 +0000 (09:43 +0000)] 
ftests/086: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit facad4ea6259a27c0e47cf6c30f622b8bbb0117f)

20 months agoftests/085: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:42:55 +0000 (09:42 +0000)] 
ftests/085: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit bccb3f5bb76471417af1b9fe91fb698fb54653a8)

20 months agoftests/084: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:41:44 +0000 (09:41 +0000)] 
ftests/084: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 10e55c04ba77886785f5cdb866658dbf1edccc13)

20 months agoftests/079: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:40:30 +0000 (09:40 +0000)] 
ftests/079: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit d4a92649e3bd540ae066879e25aa82c7ef3308fc)

20 months agoftests/078: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:38:40 +0000 (09:38 +0000)] 
ftests/078: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 7a59e3529f51edeb2ca671acd07f81db6d83b156)

20 months agoftests/071: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:37:16 +0000 (09:37 +0000)] 
ftests/071: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit c3d49f54cdf2c0d491dead0365406303eae52a65)

20 months agoftests/070: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:35:26 +0000 (09:35 +0000)] 
ftests/070: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 4cac7d61838c1760dcf9acd9a9ac24eac6a619c6)

20 months agoftests/069: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:34:24 +0000 (09:34 +0000)] 
ftests/069: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit f784f734c9e0a6eb43c7283dce1afaae7f72769f)

20 months agoftests/068: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:33:21 +0000 (09:33 +0000)] 
ftests/068: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 2f9f8ac5463cd54d00ce02219a7796b58bb1e863)

20 months agoftests/067: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:32:28 +0000 (09:32 +0000)] 
ftests/067: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit a76cf51ae8979426feed704b071844232e6a34d7)

20 months agoftests/066: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:31:33 +0000 (09:31 +0000)] 
ftests/066: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit a4fba38e778e9419af9d2050151f9cf8531007b7)

20 months agoftests/065: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:30:36 +0000 (09:30 +0000)] 
ftests/065: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit bdf67be2d4abb177f02ee9a56b7e50be3eb20fe5)

20 months agoftests/064: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:28:14 +0000 (09:28 +0000)] 
ftests/064: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 7e8b5cdfcea3c5b5d20bf80fdc3f3b2cd1657406)

20 months agoftests/063: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:27:18 +0000 (09:27 +0000)] 
ftests/063: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit be57077ec1ead795b800ae2a5bf2c32b056e8222)

20 months agoftests/062: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:25:55 +0000 (09:25 +0000)] 
ftests/062: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 227120e8b9b88f0a187273ebf3e2b3d75bd3d9dc)

20 months agoftests/061: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:23:05 +0000 (09:23 +0000)] 
ftests/061: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit fd580a2ff2384e828a241c54f4fc8206165f7649)

20 months agoftests/060: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:22:11 +0000 (09:22 +0000)] 
ftests/060: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 1f4fa87c6326bf562d8c08c03b62ac7103906127)

20 months agoftests/059: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:20:34 +0000 (09:20 +0000)] 
ftests/059: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 93dcd53ebb106693f2f13393574dfda61c0505e5)

20 months agoftests/058: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:19:10 +0000 (09:19 +0000)] 
ftests/058: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit fb0265cce8f9d5d124834c08121fb9fff733dbca)

20 months agoftests/050: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:18:01 +0000 (09:18 +0000)] 
ftests/050: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 940d77f122c10c4092539e8f9dc663ee3ab150e5)

20 months agoftests/049: skip test on non-systemd configuration
Kamalesh Babulal [Wed, 29 Nov 2023 09:08:14 +0000 (09:08 +0000)] 
ftests/049: skip test on non-systemd configuration

Skip running the testcase, when compiled with --enable-systemd=no,
using Systemd.is_systemd_enabled().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 7c5d8d20db55ca2a46fcf0fa6dae8fef94598000)

20 months agoftests/systemd: add method to check if systemd support
Tom Hromatka [Wed, 6 Dec 2023 15:37:44 +0000 (15:37 +0000)] 
ftests/systemd: add method to check if systemd support

Add a method to check if libcgroup is compiled with --enable-systemd
support. The newly introduced is_systemd_enabled(), calls systemd C
function is_systemd_enabled(), that return true if configured with
--enable-systemd, false otherwise.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 342ae45c0038924ed937479fc07908782253a85b)

20 months agopython: Introduce is_systemd_enabled()
Tom Hromatka [Thu, 7 Dec 2023 04:20:13 +0000 (04:20 +0000)] 
python: Introduce is_systemd_enabled()

Add python interface for systemd C function cgroup_is_systemd_enabled(),
that return true if the --enable-systemd was set or false.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 45a36684facb8dcc75803ddcf09976730254a5f7)

20 months agopython: compile systemd support by default
Tom Hromatka [Thu, 7 Dec 2023 04:19:07 +0000 (04:19 +0000)] 
python: compile systemd support by default

Compile systemd support file by default, there are two versions of
systemd functions available now, those get called based on the
--enable-systemd configuration, hence remove the #ifdef WITH_SYSTEMD
guards from bindings.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 86217e811073bb02ebeb8d24cfc112142fe8fcd4)

20 months agoinclude/Makefile: install systemd.h by default
Kamalesh Babulal [Mon, 27 Nov 2023 14:37:33 +0000 (20:07 +0530)] 
include/Makefile: install systemd.h by default

Install systemd.h header file by default, as we have stub and defined
versions of the systemd functions for both non-systemd and systemd
enabled configurations.  This will help packagers to ship package
without systemd support (--enable-systemd=no).

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 592dcdcf243576bd2517d3da9bc18990de08e37e)

20 months agosrc/Makefile: compile systemd support by default
Kamalesh Babulal [Sat, 25 Nov 2023 14:32:34 +0000 (20:02 +0530)] 
src/Makefile: compile systemd support by default

Compile systemd support file by default, now we have stub and defined
versions of the systemd functions for both non-systemd and systemd
enabled configurations.  Pass linker flag WITH_SYSTEMD only when
--enable-systemd is set, that will call the defined function, otherwise
call the stub functions.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit f34e87adfb85d8aa53fea634b90dd91640ade411)

20 months agosystemd: add cgroup_is_systemd_enabled() helper
Tom Hromatka [Wed, 6 Dec 2023 15:07:15 +0000 (15:07 +0000)] 
systemd: add cgroup_is_systemd_enabled() helper

Add a helper function cgroup_is_systemd_enabled(), that would return
true, when compiled with --enabled-systemd option or false when
disabled.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 903e278f296fa265b209805bbc95b31e2196341c)

20 months agosystemd: add function stubs for non-systemd
Kamalesh Babulal [Mon, 27 Nov 2023 14:30:14 +0000 (20:00 +0530)] 
systemd: add function stubs for non-systemd

Add systemd function stubs for --enable-systemd=no configuration.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 07f038769e19b9c2e190a0c5c43d10dce6b6d26e)

20 months agotools/lscgroup: guard systemd default delegate slice
Kamalesh Babulal [Fri, 24 Nov 2023 08:49:51 +0000 (14:19 +0530)] 
tools/lscgroup: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 2dde191094f63e74119c3d285eed236737dfe1a8)

20 months agotools/cgxset: guard systemd default delegate slice
Kamalesh Babulal [Thu, 23 Nov 2023 08:48:50 +0000 (14:18 +0530)] 
tools/cgxset: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 44676c56ce132a6f43180eec92fbf70349307926)

20 months agotools/cgxget: guard systemd default delegate slice
Kamalesh Babulal [Wed, 22 Nov 2023 08:47:45 +0000 (14:17 +0530)] 
tools/cgxget: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 4480bf0b752affbdb0c5978e3b54c8dedf03197e)

20 months agotools/cgset: guard systemd default delegate slice
Kamalesh Babulal [Tue, 21 Nov 2023 08:46:47 +0000 (14:16 +0530)] 
tools/cgset: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 29dfcfb6768c5168b754bfe0471a820333802fe4)

20 months agotools/cgget: guard systemd default delegate slice
Kamalesh Babulal [Mon, 20 Nov 2023 08:45:54 +0000 (14:15 +0530)] 
tools/cgget: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 04d99ce4c75cfc74eee3f0a350a5e87b66457d24)

20 months agotools/cgexec: guard systemd default delegate slice
Kamalesh Babulal [Sun, 19 Nov 2023 08:44:57 +0000 (14:14 +0530)] 
tools/cgexec: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 49c65117d247e9697b19d6847df5678f6c27ea0f)

20 months agotools/cgdelete: guard systemd default delegate slice
Kamalesh Babulal [Sat, 18 Nov 2023 08:43:46 +0000 (14:13 +0530)] 
tools/cgdelete: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 6d7446606fd50df291be7820b0062a63694924aa)

20 months agotools/cgcreate: guard systemd default delegate slice
Kamalesh Babulal [Fri, 17 Nov 2023 08:42:26 +0000 (14:12 +0530)] 
tools/cgcreate: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 3b34789339f52c300bd188f2e1258a7c1e8a8869)

20 months agotools/cgclassify: guard systemd default delegate slice
Kamalesh Babulal [Thu, 16 Nov 2023 08:38:03 +0000 (14:08 +0530)] 
tools/cgclassify: guard systemd default delegate slice

Guard setting default systemd delegate slice with WITH_SYSTEMD, to limit
the systemd delegation only to --enable-systemd=yes only.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit cfe7354274f1d3de5b7d0d059ab67f217bdc2b3a)

21 months agoRFE: Bump actions/checkout from 3 to 4
dependabot[bot] [Mon, 4 Sep 2023 22:35:16 +0000 (22:35 +0000)] 
RFE: Bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 15057770fc3fdc02f3972dbf61a8b25fc35dc84e)

21 months agoRFE: Bump redhat-plumbers-in-action/differential-shellcheck from 4 to 5
dependabot[bot] [Mon, 9 Oct 2023 22:17:42 +0000 (22:17 +0000)] 
RFE: Bump redhat-plumbers-in-action/differential-shellcheck from 4 to 5

Bumps [redhat-plumbers-in-action/differential-shellcheck](https://github.com/redhat-plumbers-in-action/differential-shellcheck) from 4 to 5.
- [Release notes](https://github.com/redhat-plumbers-in-action/differential-shellcheck/releases)
- [Changelog](https://github.com/redhat-plumbers-in-action/differential-shellcheck/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/redhat-plumbers-in-action/differential-shellcheck/compare/v4...v5)

---
updated-dependencies:
- dependency-name: redhat-plumbers-in-action/differential-shellcheck
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit ebccb333621891d672b51ba175f7f72c7b212550)

2 years agogithub: Add a job to build libcgroup w/ systemd disabled
Tom Hromatka [Mon, 31 Jul 2023 17:12:49 +0000 (11:12 -0600)] 
github: Add a job to build libcgroup w/ systemd disabled

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit b79df0052565022f9f44eb8c963ca04baa43d3af)

2 years agopython: Surround systemd code with m4 conditionals
Tom Hromatka [Tue, 1 Aug 2023 21:17:35 +0000 (15:17 -0600)] 
python: Surround systemd code with m4 conditionals

Surround the systemd python logic with m4 ifdef(`WITH_SYSTEMD'...).
This will conditionally add the systemd code iff systemd is enabled
in configure.ac

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit a9d27eda52f25514688d434c4a13deac51a16cc4)

2 years agosamples: Wrap systemd samples with WITH_SYSTEMD automake variable
Tom Hromatka [Wed, 2 Aug 2023 18:40:47 +0000 (12:40 -0600)] 
samples: Wrap systemd samples with WITH_SYSTEMD automake variable

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit b055cfedcad70973cfd64de85fd1ce53c159a6a8)

2 years agoftests: Fix erroneous calls to log_error()
Tom Hromatka [Wed, 2 Aug 2023 18:39:06 +0000 (12:39 -0600)] 
ftests: Fix erroneous calls to log_error()

Two places in the functional tests were calling a nonexistent
logging function - log_error().  Replace these erroneous calls
with calls to log_critical().

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit a82f3c0344d95cd5b91a770b67e58b112fcd2b33)

2 years agoconfigure.ac: add check for systemd library and header files
Kamalesh Babulal [Mon, 31 Jul 2023 10:27:37 +0000 (15:57 +0530)] 
configure.ac: add check for systemd library and header files

systemd support is now enabled by default, unless explicitly disabled
during the ./configure by passing --enable-systemd=no. The make may
fail with:
systemd.c:9:10: fatal error: systemd/sd-bus.h: No such file or directory
    9 | #include <systemd/sd-bus.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.

if the host system is missing the systemd library and development files,
due to missing checks for their existence in ./configure.ac. This patch
add them.

Fixes: https://github.com/libcgroup/libcgroup/issues/387
Reported-by: Tomasz Kłoczko <kloczek@github.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 36d1d2226f3f3a089334c7a62a6e5890ae9d52be)

2 years agoconfigure: Roll version to 3.1.0 v3.1.0
Tom Hromatka [Fri, 28 Jul 2023 20:12:30 +0000 (14:12 -0600)] 
configure: Roll version to 3.1.0

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agotests: Delete test 066's config file
Tom Hromatka [Fri, 28 Jul 2023 15:04:50 +0000 (09:04 -0600)] 
tests: Delete test 066's config file

After the test has run, delete the config file that
was created in test 066-sudo-systemd_cgclassify-v2.py

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agodoc: update release-github.md
Tom Hromatka [Fri, 28 Jul 2023 14:39:25 +0000 (08:39 -0600)] 
doc: update release-github.md

Fix a typo, and clarify the coverity steps

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agocgsnapshot: Fix compiler truncation warning
Tom Hromatka [Thu, 20 Jul 2023 14:24:16 +0000 (19:54 +0530)] 
cgsnapshot: Fix compiler truncation warning

Fix the following warning when running make distcheck

../../../../src/tools/cgsnapshot.c: In function ‘is_ctlr_on_list’:
../../../../src/tools/cgsnapshot.c:532:57: warning: ‘%s’ directive output may be truncated writing up to 409599 bytes into a region of size 4096 [-Wformat-truncation=]
532 |                 snprintf(controllers[i], FILENAME_MAX, "%s", tmp_controllers[i]);
    |                                                         ^~

Suggested-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agoman/cgred.conf: fix spelling of --nodaemon option
Kamalesh Babulal [Wed, 19 Jul 2023 05:11:45 +0000 (10:41 +0530)] 
man/cgred.conf: fix spelling of --nodaemon option

Fix the spelling '--nodamon' -> '--nodaemon'

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agoapi.c: fix unused variable in cgroup_parse_rules_file()
Kamalesh Babulal [Wed, 19 Jul 2023 04:35:44 +0000 (10:05 +0530)] 
api.c: fix unused variable in cgroup_parse_rules_file()

Fix an unused variable warning, reported by the Coverity tool:

CID 320877 (#1 of 1): Unused value (UNUSED_VALUE) assigned_pointer:
Assigning value NULL to pwd here, but that stored value is overwritten
before it can be used.

Move the grp, pwd variables assignment to beginning of the while loop in
the cgroup_parse_rules_file().

Tested with following cgrules
-----------------------------
$ cat /etc/cgrules.conf
student         devices         /usergroup/students
@admin          *               admingroup/
peter           cpu             test1/
%               memory          test2/
*               *               default/

$ sudo CGROUP_LOGLEVEL=DEBUG ./src/daemon/cgrulesengd -d -n
Parsing configuration file /etc/cgrules.conf.
Added rule student (UID: 1001, GID: -1) -> /usergroup/students for
controllers: devices
Added rule @admin (UID: -1, GID: 1004) -> admingroup/ for controllers: *
Added rule peter (UID: 1003, GID: -1) -> test1/ for controllers: cpu
Added rule % (UID: 1003, GID: -1) -> test2/ for controllers: memory
Added rule * (UID: -2, GID: -2) -> default/ for controllers: *
Parsing of configuration file complete.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agotools/cgsnapshot: fix string null terminate in parse_controllers()
Kamalesh Babulal [Wed, 19 Jul 2023 07:05:50 +0000 (12:35 +0530)] 
tools/cgsnapshot: fix string null terminate in parse_controllers()

Fix string not null terminated warning, reported by the Coverity tool:

CID 258299 (#2 of 2): String not null terminated (STRING_NULL)18.
string_null: Passing unterminated string *controllers to
display_controller_data, which expects a null-terminated string.

use snprintf() instead of strncpy() and manually terminate the string to
keep Coverity happy.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agopython: Rename __set_default_systemd_cgroup()
Tom Hromatka [Tue, 18 Jul 2023 13:59:56 +0000 (07:59 -0600)] 
python: Rename __set_default_systemd_cgroup()

Rename __set_default_systemd_cgroup() to _set_default_systemd_cgroup()
to avoid Python name mangling

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agosrc/api.c fix TOCTOU in cg_mkdir_p()
Kamalesh Babulal [Mon, 17 Jul 2023 09:08:19 +0000 (14:38 +0530)] 
src/api.c fix TOCTOU in cg_mkdir_p()

Fix a TOCTOU issue, reported by Coverity tool:

CID 258294 (#1 of 1): Time of check time of use (TOCTOU)42.
fs_check_call: Calling function stat to perform check on real_path

Add new switch for EROFS, to explicitly check if the file exist on
mkdir()'s error path, using a new char pointer.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agosrc/api.c: fix TOCTOU in cg_get_procname_from_proc_cmdline()
Kamalesh Babulal [Sat, 15 Jul 2023 06:34:11 +0000 (12:04 +0530)] 
src/api.c: fix TOCTOU in cg_get_procname_from_proc_cmdline()

Fix a TOCTOU issue, reported by Coverity tool:

CID 258283 (#1 of 1): Time of check time of use (TOCTOU)1.
fs_check_call: Calling function readlink to perform check on path

Coverity gets confused when a char array is re-used for constructing
different paths and complains about TOCTOU for unrelated paths, fix it
by using different char arrays for different path, as a side effect it
also improves the readability of the code.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agosrc/api.c: fix TOCTOU in cgroup_get_cgroup()
Kamalesh Babulal [Sat, 15 Jul 2023 06:30:02 +0000 (12:00 +0530)] 
src/api.c: fix TOCTOU in cgroup_get_cgroup()

Fix a TOCTOU issue, reported by Coverity tool:

CID 258268 (#1 of 1): Time of check time of use (TOCTOU)28.
fs_check_call: Calling function access to perform check on path.

Coverity gets confused when a char array is re-used for constructing
different paths and complains about TOCTOU for unrelated paths, fix it
by using different char arrays for different path, as a side effect it
also improves the readability of the code.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agotools/cgxget: fix TOCTOU in fill_empty_controller()
Kamalesh Babulal [Fri, 14 Jul 2023 06:13:38 +0000 (11:43 +0530)] 
tools/cgxget: fix TOCTOU in fill_empty_controller()

Fix a TOCTOU issue, reported by Coverity tool:

CID 258277 (#1 of 1): Time of check time of use (TOCTOU)13.
fs_check_call: Calling function access to perform check on path

Coverity gets confused when a char array is re-used for constructing
different paths and complains about TOCTOU for unrelated paths, fix it
by using different char arrays for different path, as a side effect it
also improves the readability of the code.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agotools/cgget: fix TOCTOU in fill_empty_controller()
Kamalesh Babulal [Fri, 14 Jul 2023 06:13:32 +0000 (11:43 +0530)] 
tools/cgget: fix TOCTOU in fill_empty_controller()

Fix a TOCTOU issue, reported by Coverity tool:

CID 258277 (#2 of 2): Time of check time of use (TOCTOU)13.
fs_check_call: Calling function access to perform check on path

Coverity gets confused when a char array is re-used for constructing
different paths and complains about TOCTOU for unrelated paths, fix it
by using different char arrays for different path, as a side effect it
also improves the readability of the code.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agotools: cgconfig/cgrulesengd - skip parsing non .conf files
Kamalesh Babulal [Thu, 13 Jul 2023 07:44:41 +0000 (07:44 +0000)] 
tools: cgconfig/cgrulesengd - skip parsing non .conf files

Currently, the list of files to be parsed is constructed by reading the
directories passed with '-L' command line option or by cgrulesend from
'/etc/cgconfig.d'.  The directories might also host non-configuration
files, parsing them will result in failure.

Consider the following example:

 # ls /etc/cgconfig.d
 cgconfig-oradb.conf  cgconfig-oradb.conf.rpmsave test .conf e

 # /usr/sbin/cgconfigparser -l /etc/cgconfig.conf -L /etc/cgconfig.d -s 1664
 /usr/sbin/cgconfigparser; error loading /etc/cgconfig.d/cgconfig-oradb.conf.rpmsave:
 Cgroup, the requested group parameter does not exist

fix it by skipping files with non .conf extensions, while building the
list of files to be parsed for cgroup configurations.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agoapi: cg_move_task_files() - rearrange code to avoid extra check
Kamalesh Babulal [Sat, 8 Jul 2023 14:49:55 +0000 (20:19 +0530)] 
api: cg_move_task_files() - rearrange code to avoid extra check

Fix unused variables, reported by the Coverity tool:

CID 320878 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value 0 to ret here, but that stored value is overwritten
before it can be used.

Currently, in cg_move_task_files(), the ret is checked for ESRCH and set
to zero, if true, and for other error values it executes the error path
but immediately the ret is over-written without reading the set zero,
re-arrange the code to such that only the error path is executed and ret
is not set to zero.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agopython: libcgroup.pyx - fix lines, spaces lint warnings
Kamalesh Babulal [Mon, 10 Jul 2023 04:44:57 +0000 (10:14 +0530)] 
python: libcgroup.pyx - fix lines, spaces lint warnings

Fix following spaces, lines warnings reported by Cython-lint:
- libcgroup.pyx:14:13: E222 multiple spaces after operator
- libcgroup.pyx:50:1: E302 expected 2 blank lines, found 1
- libcgroup.pyx:53:1: E302 expected 2 blank lines, found 1
- libcgroup.pyx:57:1: E302 expected 2 blank lines, found 1
- libcgroup.pyx:85:1: E305 expected 2 blank lines after class or function definition, found 1

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agopython: libcgroup.pyx - remove non-Python constructs
Kamalesh Babulal [Mon, 10 Jul 2023 04:44:52 +0000 (10:14 +0530)] 
python: libcgroup.pyx - remove non-Python constructs

Fix few cython-lints non-Python constructs, reported by cython-lint
tool:
- libcgroup.pyx:222:26: E711 comparison to None should be 'if cond is None:'
- libcgroup.pyx:380:82: E703 statement ends with a semicolon

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agopython: libcgroup.pyx - remove unused import
Kamalesh Babulal [Mon, 10 Jul 2023 04:44:47 +0000 (10:14 +0530)] 
python: libcgroup.pyx - remove unused import

Remove unused import 'os', reported by cython-lint.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agopython: remove unused var in Cgroup::add_controller()
Kamalesh Babulal [Mon, 10 Jul 2023 04:44:39 +0000 (10:14 +0530)] 
python: remove unused var in Cgroup::add_controller()

In Cgroup::add_controller(), remove unused variable 'cgp', reported
cython-lint tool.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agopython: add cython-lint configuration file
Kamalesh Babulal [Mon, 10 Jul 2023 04:43:47 +0000 (10:13 +0530)] 
python: add cython-lint configuration file

Add configuration for cython-lint, to ignore errors such as:
- Allowed length of line to be 100
- Ignore error code 'E128' continuation line under-indented for visual
  indent

Cython-lint is available https://github.com/MarcoGorelli/cython-lint,
expects the file name to be pyproject.toml

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agotools/cgxset: fix unused value in main
Kamalesh Babulal [Fri, 7 Jul 2023 05:15:15 +0000 (10:45 +0530)] 
tools/cgxset: fix unused value in main

Fix unused value, reported by the Coverity tool:

CID 320876 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value 0 to ret here, but that stored value is overwritten
before it can be used.

If the mapping from v1->v2 and vice versa fail, with -i
(ignore-unmappable) set, ret is set to zero and is immediately
over-written, re-arrange the check, and adjust the commentary to avoid
clobbering ret, by taking the error path when -i is unset or else
continuing when set, skipping to set ret to zero.

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>
2 years agotools/cgxget: fix unused value in main
Kamalesh Babulal [Fri, 7 Jul 2023 05:10:27 +0000 (10:40 +0530)] 
tools/cgxget: fix unused value in main

Fix unused value, reported by the Coverity tool:

CID 320879 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value 0 to ret here, but that stored value is overwritten
before it can be used.

If the mapping from v1->v2 and vice versa fail, with -i
(ignore-unmappable) set, ret is set to zero and is immediately
over-written, re-arrange the check, and adjust the commentary to avoid
clobbering ret, by taking the error path when -i is unset or else
continuing when set, skipping to set ret to zero.

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>
2 years agoapi: fix missing goto in cgroup_get_current_controller_path()
Kamalesh Babulal [Tue, 4 Jul 2023 06:34:51 +0000 (12:04 +0530)] 
api: fix missing goto in cgroup_get_current_controller_path()

Fix missing goto on error in cgroup_get_current_controller_path(), it
was reported by Coverity tool as unused value:

CID 320875 (#1 of 1): Unused value (UNUSED_VALUE)assigned_value:
Assigning value ECGOTHER to ret here, but that stored value is
overwritten before it can be used.

It turns out that, it is more than an over-written value, the strdup()
was missing goto error path statement on failure, add it.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agocgsnapshot: Fix possible non-null-terminated array
Tom Hromatka [Mon, 3 Jul 2023 19:07:41 +0000 (13:07 -0600)] 
cgsnapshot: Fix possible non-null-terminated array

Coverity flagged a code path where the controllers[][] structure in
parse_controllers() may not have a '\0' string as its last entry.
This would break the logic in is_ctlr_on_list().

The function may iterate past the end of the buffer looking for
a null terminator.

In parse_controllers: A character buffer that has not been null
terminated is passed to a function expecting a null terminated
string (CWE-170)

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agosamples: Fix coverity warning in systemd C example
Tom Hromatka [Mon, 3 Jul 2023 18:26:26 +0000 (12:26 -0600)] 
samples: Fix coverity warning in systemd C example

Fix the following coverity warning in the systemd C example:

CID 1516633 (#1 of 1): Uninitialized pointer read (UNINIT)5.
uninit_use: Using uninitialized value cg.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agosamples: Fix coverity warning in systemd C example
Tom Hromatka [Mon, 3 Jul 2023 18:24:56 +0000 (12:24 -0600)] 
samples: Fix coverity warning in systemd C example

Fix the following coverity warning in the systemd C example:

CID 1516634 (#1 of 1): Uninitialized pointer read (UNINIT)5.
uninit_use: Using uninitialized value cg.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agoftests: skip test 002 on legacy, containerized test runs
Tom Hromatka [Mon, 3 Jul 2023 15:58:13 +0000 (09:58 -0600)] 
ftests: skip test 002 on legacy, containerized test runs

Skip test 002-cgdelete-recursive_delete.py on legacy (cgroup v1),
containerized test runs.  It occasionally fails in Github Actions, and
I think the failure is simply because the machine is underpowered.  In
these cases, the failure is usually reported as:
002-cgdelete-recursive_delete.py - Failed to get the pid of the child process:

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agoftests: Retry run() command after websocket failure
Tom Hromatka [Mon, 3 Jul 2023 15:51:58 +0000 (09:51 -0600)] 
ftests: Retry run() command after websocket failure

LXC/LXD will sometimes throw an "Error: websocket: bad handshake" error
on underpowered machines.  Wait a bit (arbitrarily chosen 5 seconds) and
retry the command.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agotools/cgclassify: fix controller overflow array range
Kamalesh Babulal [Mon, 3 Jul 2023 05:05:40 +0000 (10:35 +0530)] 
tools/cgclassify: fix controller overflow array range

Fix out-of-bounds write issue, reported by Coverity tool:

CID 321270 (#1 of 1): Out-of-bounds write (OVERRUN)47. overrun-local:
Overrunning array info of 16 4128-byte elements at element index 16
(byte offset 70175) using index i (which evaluates to 16).

MAX_MNT_ELEMENTS is an array that's allocated for array parsing and
populating the mount points, as per Linux Kernel, this can't be above
16 and it works fine while checking for index < MAX_MNT_ELEMENTS, but
in this case, we rely on the mount point name to be empty ('\0'), since
allowed maximum mount points are 16, increase the allocation index to
17 for the info structure, to accommodate 16 controllers, but that is
unlikely.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agopython: remove unused var in Cgroup::add_setting()
Kamalesh Babulal [Sun, 2 Jul 2023 14:38:51 +0000 (20:08 +0530)] 
python: remove unused var in Cgroup::add_setting()

In Cgroup::add_setting(), remove unused variable 'value'

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agosamples: Add automake files for the cmdline directory
Tom Hromatka [Sat, 20 May 2023 01:53:22 +0000 (19:53 -0600)] 
samples: Add automake files for the cmdline directory

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agosamples: Add a python example that creates a systemd scope
Tom Hromatka [Fri, 19 May 2023 22:16:46 +0000 (16:16 -0600)] 
samples: Add a python example that creates a systemd scope

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agoftests: Rework test 071 to use cgroup_write_systemd_default_cgroup()
Tom Hromatka [Wed, 24 May 2023 13:34:51 +0000 (07:34 -0600)] 
ftests: Rework test 071 to use cgroup_write_systemd_default_cgroup()

cgroup_write_systemd_default_cgroup() populates libcgroup's /var/run
file with the default slice/scope.  No verification is done at the time
of writing.

cgroup_set_default_systemd_cgroup() reads the /var/run file and verifies
that it points to a valid path.  If so, it populates libcgroup's global
variable, systemd_default_cgroup.  systemd_default_cgroup is then used
in any subsequent building of libcgroup paths.

Previously, test 071 tested cgroup_set_default_systemd_cgroup() but it
didn't exercise cgroup_write_systemd_default_cgroup().  Rework test 071
to exercise the most likely combinations of writing/setting the default
path that a user would encounter.

-----------------------------------------------------------------
Test Results:
Run Date:                          May 24 07:32:54
Passed:                                  1 test(s)
Skipped:                                 0 test(s)
Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
Test                                       Time (sec)
-----------------------------------------------------
setup                                            0.00
071-sudo-set_default_systemd_cgroup.py           4.67
teardown                                         0.00
-----------------------------------------------------
Total Run Time                                   4.67

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agopython: Add support for NULL controllers[] in get_processes()
Tom Hromatka [Fri, 19 May 2023 22:09:54 +0000 (16:09 -0600)] 
python: Add support for NULL controllers[] in get_processes()

Add support for an empty controllers list in the Python bindings.
The python method, get_processes(), will then send in a NULL pointer
in the controllers field into the C function cgroup_get_procs().

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agopython: Add cgroup v1 support to move_process()
Tom Hromatka [Wed, 24 May 2023 20:12:45 +0000 (14:12 -0600)] 
python: Add cgroup v1 support to move_process()

Add support for providing a single controller to Cgroup.move_process().
move_process() invokes cgroup_change_cgroup_path() which utilizes an
array of controller strings.

This change only adds support for a single controller via the python
bindings, but a list of controllers could be supported in the future.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agopython: Add method to clear the default slice/scope
Tom Hromatka [Thu, 25 May 2023 02:35:35 +0000 (20:35 -0600)] 
python: Add method to clear the default slice/scope

Add a convenience method to clear the default slice/scope.  This may be
useful in cases where the user is done with the slice/scope and wants to
resume operating at the root cgroup level.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agopython: Add bindings for cgroup_write_systemd_default_cgroup()
Tom Hromatka [Fri, 19 May 2023 22:05:25 +0000 (16:05 -0600)] 
python: Add bindings for cgroup_write_systemd_default_cgroup()

Add python bindings for cgroup_write_systemd_default_cgroup().  As part
of this change, demote cgroup_set_default_systemd_cgroup() to an
internal function - __set_default_systemd_cgroup().  I would expect
users to invoke write_default_systemd_scope() and utilize that to set
the default slice/scope.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agopython: Add bindings for cgroup_set_default_logger()
Tom Hromatka [Fri, 19 May 2023 21:59:36 +0000 (15:59 -0600)] 
python: Add bindings for cgroup_set_default_logger()

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agofix: malloc size off-by-one in cgroup_process_v2_mnt
Adriaan Schmidt [Wed, 28 Jun 2023 08:12:15 +0000 (10:12 +0200)] 
fix: malloc size off-by-one in cgroup_process_v2_mnt

need to allocate the length of both strings, plus the space added in
the sprintf, plus the terminating null byte.

Signed-off-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agocgcreate: cgget: Fix help spacing
Tom Hromatka [Tue, 27 Jun 2023 19:54:56 +0000 (13:54 -0600)] 
cgcreate: cgget: Fix help spacing

Fix spacing in cgcreate and cgget help where spaces were used instead
of tabs.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agoapi: fix build warning
Kamalesh Babulal [Fri, 23 Jun 2023 09:40:00 +0000 (15:10 +0530)] 
api: fix build warning

Fix a build warning:
cgcreate.c: In function ‘create_systemd_scope’:
cgcreate.c:81:17: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
   81 |                 strncpy(slice, cg->name, len);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cgcreate.c:80:23: note: length computed here
   80 |                 len = strlen(cg->name) - strlen(scope);

fix it by using, length of destination in the strncpy().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agoapi: add ret value check in cgroup_get_current_controller_path()
Kamalesh Babulal [Fri, 23 Jun 2023 06:19:04 +0000 (11:49 +0530)] 
api: add ret value check in cgroup_get_current_controller_path()

Fix unchecked return value, reported by the Coverity tool:

CID 320874 (#1 of 1): Unchecked return value from library
(CHECKED_RETURN)13. check_return: Calling fscanf(pid_cgroup_fd,
"%*[^\n]\n") without checking return value. This library function may
fail and return an error code.

add the missing return value check from fscanf() in
cgroup_get_current_controller_path()

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agocgcreate: fix null pointer dereference in create_systemd_scope()
Kamalesh Babulal [Wed, 21 Jun 2023 04:16:20 +0000 (09:46 +0530)] 
cgcreate: fix null pointer dereference in create_systemd_scope()

Fix a NULL pointer dereference, reported by the Coverity tool:

CID 321267 (#1 of 1): Dereference null return value (NULL_RETURNS)6.
dereference: Dereferencing a pointer that might be NULL scope when
calling strlen.

check for the return value from strstr(), before dereferencing it.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agotools/cgexec: fix uninitialized variable in find_scope_pid()
Kamalesh Babulal [Sun, 18 Jun 2023 07:35:38 +0000 (13:05 +0530)] 
tools/cgexec: fix uninitialized variable in find_scope_pid()

Fix uninitialized variable, reported by the Coverity tool:

CID 321266: Uninitialized scalar variable (UNINIT)

memset(), ctrl_name with every iteration, to avoid using the stale value
or uninitialized values.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agotools/cgexec: fix memory leak in find_scope_pid()
Kamalesh Babulal [Sun, 18 Jun 2023 07:10:33 +0000 (12:40 +0530)] 
tools/cgexec: fix memory leak in find_scope_pid()

Fix a memory leak, reported by the Coverity tool.

CID 321265 (#1-2 of 2): Resource leak (RESOURCE_LEAK)37. leaked_storage:
Variable pids going out of scope leaks the storage it points to.

find_scope_pid (), calls cgroup_get_procs() to get the pids of the
tasks under cgroup name, and it's up to the caller to free the allocated
pids. Fix it by calling free(pids) after every call to
cgroup_get_procs().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agoman: cgclassify: document -r option
Kamalesh Babulal [Thu, 1 Jun 2023 11:18:52 +0000 (11:18 +0000)] 
man: cgclassify: document -r option

Document -r option. It replaces the systemd scope's idle process with
the first pid of the list of pids provided.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agoftests: add test to replace scope idle_thread using cgclassify
Kamalesh Babulal [Thu, 15 Jun 2023 11:22:06 +0000 (16:52 +0530)] 
ftests: add test to replace scope idle_thread using cgclassify

Add a test to replace systemd scope default idle_thread using
cgclassify '-r' flag.
-----------------------------------------------------------------
Test Results:
        Run Date:                          Jun 15 11:20:25
        Passed:                                  1 test(s)
        Skipped:                                 0 test(s)
        Failed:                                  0 test(s)
-----------------------------------------------------------------
Timing Results:
        Test                                     Time (sec)
        ---------------------------------------------------
        setup                                          0.00
        088-sudo-cgclassify_systemd_scope.py          17.63
        teardown                                       0.00
        ---------------------------------------------------
        Total Run Time                                17.63

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agoftests: add support to replace idle_thread of systemd scope
Kamalesh Babulal [Thu, 1 Jun 2023 11:11:42 +0000 (11:11 +0000)] 
ftests: add support to replace idle_thread of systemd scope

Allow replacing the default idle_thread during process classification
into a cgroup using cgclassify by introducing replace_id flag, that
when unset(default) has no effect on the process created into systemd
scope cgroup, when set replaces the default idle_thread with the
process being created.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>