]> git.ipfire.org Git - thirdparty/libcgroup.git/log
thirdparty/libcgroup.git
2 years agotools/cgxget: use exit code 129 on invalid usage
Kamalesh Babulal [Fri, 30 Sep 2022 14:40:07 +0000 (08:40 -0600)] 
tools/cgxget: 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 f46f811f55d0218d0450998c74e98c4b3578607c)

2 years agotools/cgsnapshot: use exit code 129 on invalid usage
Kamalesh Babulal [Fri, 30 Sep 2022 14:38:46 +0000 (08:38 -0600)] 
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)

2 years agotools/cgcreate: use exit code 129 on invalid usage
Kamalesh Babulal [Fri, 30 Sep 2022 14:38:31 +0000 (08:38 -0600)] 
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)

2 years agotools/cgclassify: use exit code 129 on invalid usage
Kamalesh Babulal [Fri, 30 Sep 2022 14:38:18 +0000 (08:38 -0600)] 
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)

2 years agotools/cgdelete: use exit code 129 on invalid usage
Kamalesh Babulal [Fri, 30 Sep 2022 14:38:06 +0000 (08:38 -0600)] 
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)

2 years agotools/cgexec: use exit code 129 on invalid usage
Kamalesh Babulal [Fri, 30 Sep 2022 14:37:54 +0000 (08:37 -0600)] 
tools/cgexec: 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 13f8ddd305a24a17934f467244f0dc3887f45a48)

2 years agotools/cgset: use exit code 129 on invalid usage
Kamalesh Babulal [Fri, 30 Sep 2022 14:37:43 +0000 (08:37 -0600)] 
tools/cgset: 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 d7abb100847f94cdb1328a26f3b92627b2cbf38e)

2 years agotools/cgget: use exit code 129 on invalid usage
Kamalesh Babulal [Fri, 30 Sep 2022 14:37:28 +0000 (08:37 -0600)] 
tools/cgget: 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 8c2b005b4544fea075b92d609d792d76913836db)

2 years agotools: introduce bad arguments exit code
Kamalesh Babulal [Fri, 30 Sep 2022 14:37:15 +0000 (08:37 -0600)] 
tools: introduce bad arguments exit code

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)

2 years agotools/cgdelete: add check for the cmdline arguments
Kamalesh Babulal [Fri, 30 Sep 2022 14:36:59 +0000 (08:36 -0600)] 
tools/cgdelete: add check for the cmdline arguments

Like other tools, throw an error and exit if the minimum required
arguments are not passed.

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

2 years agoconfigure: introduce --enable-samples option
Kamalesh Babulal [Wed, 28 Sep 2022 15:22:47 +0000 (09:22 -0600)] 
configure: introduce --enable-samples option

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)

2 years agoci(lint): add shell linter - Differential ShellCheck
Jan Macku [Tue, 27 Sep 2022 23:03:21 +0000 (17:03 -0600)] 
ci(lint): add shell linter - Differential ShellCheck

It performs differential ShellCheck scans and report results directly in pull request.

documentation: https://github.com/redhat-plumbers-in-action/differential-shellcheck

Signed-off-by: Jan Macku <jamacku@redhat.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit f8590647e6a901bfac455b6caac1c25363ac8a07)

2 years agoMerge pull request #249 from drakenclimber/merge-tests-3.0
Tom Hromatka [Tue, 27 Sep 2022 21:51:11 +0000 (15:51 -0600)] 
Merge pull request #249 from drakenclimber/merge-tests-3.0

Merge libcgroup-tests repo back into libcgroup repo [release-3.0]

2 years agotools/cgget: fix segfault in get_cv_value()
Kamalesh Babulal [Mon, 19 Sep 2022 13:56:09 +0000 (07:56 -0600)] 
tools/cgget: fix segfault in get_cv_value()

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)

2 years agogithub: Add more dependencies to the apt install command 249/head
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.

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

2 years agogithub: Don't delete the tests/ subdir
Tom Hromatka [Fri, 16 Sep 2022 17:34:28 +0000 (11:34 -0600)] 
github: Don't delete the tests/ subdir

Now that the tests are part of the libcgroup git repo, don't
delete the tests/ subdirectory.

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

2 years agotests: Merge libcgroup-tests repo back into libcgroup repo
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>
2 years agosubmodules: Delete the tests/ git submodule
Tom Hromatka [Fri, 16 Sep 2022 17:26:34 +0000 (11:26 -0600)] 
submodules: Delete the tests/ git submodule

Delete the tests/ git submodule.  The entire libcgroup-tests git
repo will be merged back into the libcgroup git repo in a subsequent
commit.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
2 years agoftests: Update the container to Ubuntu 22.04
Tom Hromatka [Thu, 15 Sep 2022 19:05:25 +0000 (13:05 -0600)] 
ftests: Update the container to Ubuntu 22.04

Switch to the latest stable Ubuntu for the functional tests.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
2 years agoconfigure.ac: fix bashism
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)

2 years agotools/cgsnapshot: fix wrong array size in is_ctrl_on_list()
Kamalesh Babulal [Wed, 14 Sep 2022 14:05:38 +0000 (08:05 -0600)] 
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)

2 years agosrc/api.c: support /proc mounted with subset=pid
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.

[1] https://docs.kernel.org/admin-guide/cgroup-v2.html#deprecated-v1-core-features

Fixes: https://github.com/libcgroup/libcgroup/issues/234
Reported-by: @0n-s (github username)
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit c83cb5a2d2ff02bb42f1db4a559ccf4d432b0419)

2 years agoapi.c: use /proc/self/mounts
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)

2 years agoconfigure: remove AM_COND for --disable-tests
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)

2 years agomake: use DIST_SUBDIRS
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.

[1] https://www.gnu.org/software/automake/manual/html_node/SUBDIRS-vs-DIST_005fSUBDIRS.html

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

2 years agogithub/workflows: add support for testing different cgroup setups
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)

2 years agoapi.c: fix file open in cg_chmod_path()
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)

2 years agoapi.c: fix TOCTOU in cg_chmod_path()
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)

2 years agotools/tools-common.h: introduce CGROUP_LOG_CONT level for logging
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)

2 years agolog: introduce CGROUP_LOG_CONT level for logging
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");

output:
-------
$ sudo CGROUP_LOGLEVEL=DEBUG ./src/tools/cgget -g cpu:user.slice
...
Warning: cgroup v1 expects /proc/cgroup, check if Warning: /proc mounted
with subset=pid option

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");

output:
-------
$ sudo CGROUP_LOGLEVEL=DEBUG ./src/tools/cgget -g cpu:user.slice
...
Warning: cgroup v1 expects /proc/cgroup, check if /proc mounted with
subset=pid option

Also, make comsetic changes to cgroup_*().

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

3 years agodaemon/cgrulesengd: check the bytes read in cgre_receive_unix_domain_msg()
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)

3 years agoapi.c: add precision to fscanf(), in cgroup_get_current_controller_path()
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.

3 years agoapi.c: add precision to fscanf(), in cgroup_populate_controllers()
Kamalesh Babulal [Mon, 8 Aug 2022 17:02:59 +0000 (11:02 -0600)] 
api.c: add precision to fscanf(), in cgroup_populate_controllers()

Fix calling risky function warning, reported by Coverity tool:

CID 258305 (#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
MAX_CGROUP_TYPE_NAMELEN 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 04169a9bef0ee77c18cd5a2e2d9f6e49f6057e32)

3 years agoapi.c: add precision to fscanf(), in cgroup_get_all_controller_next()
Kamalesh Babulal [Mon, 8 Aug 2022 16:37:25 +0000 (10:37 -0600)] 
api.c: add precision to fscanf(), in cgroup_get_all_controller_next()

Fix calling risky function warning, reported by Coverity tool:

CID 258300 (#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
MAX_CGROUP_TYPE_NAMELEN 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 4036f4fe4334572a4669dfece01ff24dbdd56477)

3 years agoconfigure.ac: Update version number to v3.0.0 v3.0 v3.0.0
Tom Hromatka [Thu, 4 Aug 2022 21:17:50 +0000 (15:17 -0600)] 
configure.ac: Update version number to v3.0.0

Update both the package and library version numbers to v3.0.0

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agodoc: Update the github release process
Tom Hromatka [Thu, 4 Aug 2022 19:48:32 +0000 (13:48 -0600)] 
doc: Update the github release process

Add a step to update the libcgroup-tests submodule

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotests: Update submodule to the latest commit on libcgroup-tests main branch
Tom Hromatka [Thu, 4 Aug 2022 19:33:02 +0000 (13:33 -0600)] 
tests: Update submodule to the latest commit on libcgroup-tests main branch

For future reference, here are the steps to do this:
$ ./bootstrap.sh
$ git submodule update  --remote tests
$ git add tests

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoMerge pull request #220 from drakenclimber/add-cgx-man-pages
Tom Hromatka [Thu, 4 Aug 2022 19:24:51 +0000 (13:24 -0600)] 
Merge pull request #220 from drakenclimber/add-cgx-man-pages

Add man pages for cgxget and cgxset

3 years agoman/cgxset: add man page for cgxset 220/head
Tom Hromatka [Wed, 3 Aug 2022 19:49:02 +0000 (13:49 -0600)] 
man/cgxset: add man page for cgxset

Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoman/cgxget: add man page for cgxget
Tom Hromatka [Wed, 3 Aug 2022 19:33:18 +0000 (13:33 -0600)] 
man/cgxget: add man page for cgxget

Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgxget: de-allocate cg_convert_list[] in convert_cgroup()
Kamalesh Babulal [Thu, 4 Aug 2022 18:56:00 +0000 (12:56 -0600)] 
tools/cgxget: de-allocate cg_convert_list[] in convert_cgroup()

The commit 66799b867c7 (tools/cgxget: fix the resource leak in
convert_cgroup()), is a partial fix. It de-allocated the array members
of the dynamically allocated cg_converted_list[], but fails to free()
the cg_converted_list.  Fix the resource leak by de-allocating it.

Fixes: 66799b867c7 (tools/cgxget: fix the resource leak in convert_group)
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoapi.c: fix dereference after null check
Kamalesh Babulal [Wed, 3 Aug 2022 18:36:48 +0000 (12:36 -0600)] 
api.c: fix dereference after null check

Fix dereference after null check warning, reported by Coverity tool:

CID 258308 (#1 of 1): Dereference after null check (FORWARD_NULL).
var_deref_model: Passing null pointer controller to strncmp, which
dereferences it.

Fix the warning in cgroup_get_controller_version(), by checking for the
an empty controller in the case of cgroup v1.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agodaemon/cgrulesengd: check the bytes read in cgre_receive_unix_domain_msg()
Kamalesh Babulal [Wed, 3 Aug 2022 18:20:36 +0000 (12:20 -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 (#2 of 2): 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 from the socket. 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>
3 years agoapi.c: check the bytes read in cgroup_register_unchanged_process()
Kamalesh Babulal [Thu, 28 Jul 2022 19:32:05 +0000 (13:32 -0600)] 
api.c: check the bytes read in cgroup_register_unchanged_process()

Fix ignoring the number of bytes read, warning reported by Coverity
tool:

CID 258288 (#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 cgroup_register_unchanged_process(), the number of byte read/written
using read()/write() are ignored but coverity it warns about the read()
only, let's fix it.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoapi.c: fix null deference in is_cgrp_ctrl_shared_mnt()
Kamalesh Babulal [Wed, 27 Jul 2022 19:34:45 +0000 (13:34 -0600)] 
api.c: fix null deference in is_cgrp_ctrl_shared_mnt()

Fix explicit null dereferenced warning, reported by Coverity tool:

CID 258306 (#1 of 1): Explicit null dereferenced (FORWARD_NULL).
var_deref_model: Passing null pointer controller_name to
cgroup_find_parent, which dereferences it.

the code path which leads to the null dereference:
cgroup_delete_cgroup_ext()
- cgroup_find_parent()
  - is_cgrp_ctrl_shared_mnt()

is_cgrp_ctrl_shared_mnt(), assumes that the controller_name is non-NULL
but there are changes that, this static function might be called with
NULL controller_name, let's fix it with a check.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgsnapshot: fix out-of-bounds write in parse_controllers()
Kamalesh Babulal [Wed, 27 Jul 2022 19:28:04 +0000 (13:28 -0600)] 
tools/cgsnapshot: fix out-of-bounds write in parse_controllers()

Fix Out-of-bounds write warning, reported by Coverity tool:

CID 258289 (#2 of 2): Out-of-bounds write (OVERRUN)16. overrun-local:
Overrunning array controllers of 100 4096-byte elements at element index
100 (byte offset 413695) using index max (which evaluates to 100).

there are chances, that the index variable max dereferences controller
array might be over the array size of 100. Add upper bound checks
to index variable max, so that it doesn't overrun the controller array.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoapi.c: check for invalid error code in cgroup_strerror()
Kamalesh Babulal [Wed, 27 Jul 2022 19:13:59 +0000 (13:13 -0600)] 
api.c: check for invalid error code in cgroup_strerror()

Fix array overflow warning, reported by the Coverity tool:

CID 258309 (#1 of 1): Out-of-bounds read (OVERRUN). overrun-local:
Overrunning array cgroup_strerror_codes of 32 8-byte elements at element
index 49999 (byte offset 399999) using index code % ECGROUPNOTCOMPILED
(which evaluates to 49999).

there are chances of users passing error codes, resulting in crossing
the upper bound of the cgroup_strerror_codes[], fix it by introducing
bound checks.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgxget: fix the resource leak in convert_cgroup()
Kamalesh Babulal [Wed, 27 Jul 2022 19:01:31 +0000 (13:01 -0600)] 
tools/cgxget: fix the resource leak in convert_cgroup()

Fix a resource leak warning reported by the Coverity tool:

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

while free'ing() the cg_converted_list() via cgroup_free(), wrong array
index variable was passed, causing the resource leak. Fix it by passing
the right index variable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgxget: fix resource leak in get_cv_value()
Kamalesh Babulal [Wed, 27 Jul 2022 18:55:20 +0000 (12:55 -0600)] 
tools/cgxget: fix resource leak in get_cv_value()

Fix a resource leak, reported by the Coverity tool:

CID 258291 (#1 of 1): Resource leak (RESOURCE_LEAK)8. leaked_storage:
Variable handle going out of scope leaks the storage it points to.

In get_cv_value(), currently, we goto end label, on the failure of
strdup() before closing the handle, leaking the resource. Fix it by
removing the goto, that allows the code flow to close the handle and
execute the code under the end label.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgget: fix resource leak in get_cv_value()
Kamalesh Babulal [Wed, 27 Jul 2022 18:48:19 +0000 (12:48 -0600)] 
tools/cgget: fix resource leak in get_cv_value()

Fix a resource leak, reported by the Coverity tool:

CID 258291 (#1 of 1): Resource leak (RESOURCE_LEAK)8. leaked_storage:
Variable handle going out of scope leaks the storage it points to.

In get_cv_value(), currently, we goto end label, on the failure of
strdup() before closing the handle, leaking the resource. Fix it by
removing the goto, that allows the code flow to close the handle and
execute the code under the end label.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoapi: null terminate readlink buffer in cgroup_get_procname_from_procfs()
Kamalesh Babulal [Wed, 27 Jul 2022 18:43:37 +0000 (12:43 -0600)] 
api: null terminate readlink buffer in cgroup_get_procname_from_procfs()

Fix readlink buffer null termination warning, reported by Coverity tool:

CID 258273 (#2 of 2): String not null terminated (STRING_NULL).
string_null: Passing unterminated string buf to strdup, which expects a
null-terminated string.

As per the man pages (man 2 readlink):
"readlink() does not append a null byte to buf.  It  will (silently)
truncate the contents (to a length of bufsiz characters), in case the
buffer is too small to hold all of the contents."

Explicitly null terminate the buffer passed to readlink() in
cgroup_get_procname_from_procfs()

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoapi: null terminate readlink buffer in cg_get_procname_from_proc_cmdline()
Kamalesh Babulal [Wed, 20 Jul 2022 17:22:01 +0000 (11:22 -0600)] 
api: null terminate readlink buffer in cg_get_procname_from_proc_cmdline()

Fix readlink buffer null termination warning, reported by Coverity tool:

CID 258276 (#1 of 1): String not null terminated (STRING_NULL).
string_null: Passing unterminated string buf_cwd to strcat, which
expects a null-terminated string.

As per the man pages (man 2 readlink):
"readlink() does not append a null byte to buf.  It  will  (silently)
truncate the contents (to a length of bufsiz characters), in case the
buffer is too small to hold all of the contents."

Explicitly null terminate the buffer passed to readlink() in
cg_get_procname_from_proc_cmdline().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoapi.c: fix string termination in cgroup_get_procname_from_procfs()
Kamalesh Babulal [Wed, 20 Jul 2022 17:15:27 +0000 (11:15 -0600)] 
api.c: fix string termination in cgroup_get_procname_from_procfs()

Fix non-terminated string warning, reported by Coverity tool:

CID 258273 (#2 of 2): String not null terminated (STRING_NULL)6.
string_null: Passing unterminated string buf to strdup, which expects a
null-terminated string.

use snprintf() instead of sprintf(), to string terminate
cgroup_get_procname_from_procfs().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agowrapper.c: null terminate string in cgroup_new_cgroup()
Kamalesh Babulal [Wed, 20 Jul 2022 17:10:03 +0000 (11:10 -0600)] 
wrapper.c: null terminate string in cgroup_new_cgroup()

Fix non-terminated string warning, reported by Coverity tool:

CID 258290 (#1 of 1): String not null terminated (STRING_NULL)46.
string_null: Passing unterminated string aux_cgroup->name to
cgroup_create_cgroup, which expects a null-terminated string.

The call patch leading to this warning:
config.c::cgroup_config_create_template_group()
- wrapper.c::cgroup_new_cgroup()

fix it by null terminating the string.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoabstraction-cpu: fix resource leak in read_setting()
Kamalesh Babulal [Wed, 20 Jul 2022 17:06:02 +0000 (11:06 -0600)] 
abstraction-cpu: fix resource leak in read_setting()

Fix a resource leak, reported by Coverity tool:

CID 258274 (#1 of 1): Resource leak (RESOURCE_LEAK)6. leaked_storage:
Variable handle going out of scope leaks the storage it points to

In read_setting(), currently, we goto end label, on the failure of
strdup() before closing the handle, leaking the resource. Fix it by
removing the goto, that allows the code flow to close the handle and
execute the code under the end label.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgsnapshot: add ret value fix in parse_controllers()
Kamalesh Babulal [Wed, 20 Jul 2022 16:56:05 +0000 (10:56 -0600)] 
tools/cgsnapshot: add ret value fix in parse_controllers()

Fix the unused ret value warning, reported by Coverity:

CID 258275 (#1 of 1): Unused value (UNUSED_VALUE)returned_value:
Assigning value from display_controller_data(controllers, program_name)
to ret here, but that stored value is overwritten before it can be used.

The parse_controllers(), doesn't check for errors in the value returned
by display_controller_data(). The return value might very well contain
an error, that might go unnoticed. Fix it by adding a check for the
return value.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotest-013: add support for newer cpu.* output
Kamalesh Babulal [Tue, 19 Jul 2022 12:16:41 +0000 (17:46 +0530)] 
test-013: add support for newer cpu.* output

With Ubuntu 5.15.0-1014 kernel, there are a few changes to the output
of cgget -g cpu:<cgroup> provides for both cgroup V1 and V2:
cgroup V1:
----------
- new stat files cpu.cfs_burst_us. cpu.idle

cgroup V2:
----------
- new stat files cpu.idle, cpu.max.burst

adopt these changes while looking for expected out based on the cgroup
version. Also, convert the expected out templates into per cgroup
version list[], making it easier to match using a for loop, instead of
nested if else. Using a list also makes it easier to append any new
changes to the output template.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotest-010: add support for newer cpu.* output
Kamalesh Babulal [Tue, 19 Jul 2022 12:15:32 +0000 (17:45 +0530)] 
test-010: add support for newer cpu.* output

With Ubuntu 5.15.0-1014 kernel, there are a few changes to the output
of cgget -g cpu:<cgroup> provides for both cgroup V1 and V2:
cgroup V1:
----------
- new stat files cpu.cfs_burst_us. cpu.idle

cgroup V2:
----------
- new stat files cpu.idle, cpu.max.burst

adopt these changes while looking for expected out based on the cgroup
version. Also, convert the expected out templates into per cgroup
version list[], making it easier to match using a for loop, instead of
nested if else. Using a list also makes it easier to append any new
changes to the output template.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotest-009: add support for newer cpu.* output
Kamalesh Babulal [Tue, 19 Jul 2022 12:15:28 +0000 (17:45 +0530)] 
test-009: add support for newer cpu.* output

With Ubuntu 5.15.0-1014 kernel, there are a few changes to the output
of cgget -g cpu:<cgroup> provides for both cgroup V1 and V2:
cgroup V1:
----------
- new stat files cpu.cfs_burst_us, cpu.idle

cgroup V2:
----------
- new stat files cpu.idle, cpu.max.burst

adopt these changes while looking for expected out based on the cgroup
version. Also, convert the expected out templates into per cgroup
version list[], making it easier to match using a for loop, instead of
nested if else. Using a list also makes it easier to append any new
changes to the output template.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotest-020: fix issues on unsuccessful no-container runs
Kamalesh Babulal [Tue, 19 Jul 2022 20:48:55 +0000 (14:48 -0600)] 
test-020: fix issues on unsuccessful no-container runs

Running the test with --no-container, might cause an issue with useradd
or groupadd command if the home directory of the test user exists/test
user group exists.

The home directory of the user doesn't get removed by default on all
distros, so explicitly pass the '-r' flag to userdel to remove the
directory.  Whereas user group might exist due to unsuccessful test
runs, address it by passing '-f' flags to groupadd command, that
returns success even if the group exists, that will be removed
by the groupdel command at the exit.

This is not an issue with containers test cases, because they are
created and destroyed for every test case execution.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotest-019: fix issues on unsuccessful no-container runs
Kamalesh Babulal [Tue, 19 Jul 2022 20:48:39 +0000 (14:48 -0600)] 
test-019: fix issues on unsuccessful no-container runs

Running the test with --no-container, might cause an issue with useradd
or groupadd command if the home directory of the test user exists/test
user group exists.

The home directory of the user doesn't get removed by default on all
distros, so explicitly pass the '-r' flag to userdel to remove the
directory.  Whereas user group might exist due to unsuccessful test
runs, address it by passing '-f' flags to groupadd command, that
returns success even if the group exists, that will be removed
by the groupdel command at the exit.

This is not an issue with containers test cases, because they are
created and destroyed for every test case execution.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoapi.c: add ret value fix in cgroup_change_cgroup_flags()
Kamalesh Babulal [Wed, 13 Jul 2022 19:42:11 +0000 (13:42 -0600)] 
api.c: add ret value fix in cgroup_change_cgroup_flags()

Fix the unused ret value warning, reported by Coverity:

CID 258304 (#1 of 1): Unused value (UNUSED_VALUE)returned_value:
Assigning value from cgroup_create_template_group(newdest, tmp, flags)
to ret here, but that stored value is overwritten before it can be used.

It turns out that cgroup_change_cgroup_flags(), calls the function
cgroup_create_template_group() to a cgroup based on a template, which
may fail and we don't check the return value for the error. Â This fix
adds the check and bails out on error.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgget: replace strcat() with strncat()
Kamalesh Babulal [Tue, 12 Jul 2022 17:23:58 +0000 (11:23 -0600)] 
tools/cgget: replace strcat() with strncat()

Fix copy into fixed size buffer warning, reported by Coverity tool:

CID 258284 (#4 of 4): Copy into fixed size buffer (STRING_OVERFLOW)1.
fixed_size_dest: You might overrun the 4096-character fixed-size string
tmp_val by copying tok without checking the length.

In indent_multiline_value(), warned about the usage of strcat(), that
might overwrite the string. Fix it by replacing strcat() -> strncat()
in the function.

Signed-off-by: Kamalesh Babulal kamalesh.babulal@oracle.com
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgxget: replace strcat() with strncat()
Kamalesh Babulal [Tue, 12 Jul 2022 17:21:57 +0000 (11:21 -0600)] 
tools/cgxget: replace strcat() with strncat()

Fix copy into fixed size buffer warning, reported by Coverity tool:

CID 258284 (#4 of 4): Copy into fixed size buffer (STRING_OVERFLOW)1.
fixed_size_dest: You might overrun the 4096-character fixed-size string
tmp_val by copying tok without checking the length.

In indent_multiline_value(), warned about the usage of strcat(), that
might overwrite the string. Fix it by replacing strcat() -> strncat()
in the function.

Signed-off-by: Kamalesh Babulal kamalesh.babulal@oracle.com
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgget: fix a resource leak get_cv_value()
Kamalesh Babulal [Mon, 11 Jul 2022 19:40:08 +0000 (13:40 -0600)] 
tools/cgget: fix a resource leak get_cv_value()

Fix a resource leak in get_cv_value(), reported by Coverity tool:

CID 258291 (#1 of 1): Resource leak (RESOURCE_LEAK). leaked_storage:
Variable handle going out of scope leaks the storage it points to.

failure on the realloc(), doesn't free the *handle. Fix it by using
the goto read_end(), that does the job of freeing the handle.

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>
3 years agotools/tools-common.h: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:38:54 +0000 (20:08 +0530)] 
tools/tools-common.h: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/tools-common.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:36:17 +0000 (20:06 +0530)] 
tools/tools-common.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/lssubsys: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:32:44 +0000 (20:02 +0530)] 
tools/lssubsys: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/lscgroup: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:30:18 +0000 (20:00 +0530)] 
tools/lscgroup: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgxget: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:27:41 +0000 (19:57 +0530)] 
tools/cgxget: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgxset: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:22:42 +0000 (19:52 +0530)] 
tools/cgxset: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgsnapshot: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:21:09 +0000 (19:51 +0530)] 
tools/cgsnapshot: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgset: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:16:13 +0000 (19:46 +0530)] 
tools/cgset: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgget: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:14:25 +0000 (19:44 +0530)] 
tools/cgget: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgexec: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:08:53 +0000 (19:38 +0530)] 
tools/cgexec: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgcreate: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 14:02:56 +0000 (19:32 +0530)] 
tools/cgcreate: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgconfig: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 08:30:09 +0000 (14:00 +0530)] 
tools/cgconfig: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgdelete: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 08:29:11 +0000 (13:59 +0530)] 
tools/cgdelete: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgclassify: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 08:26:34 +0000 (13:56 +0530)] 
tools/cgclassify: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agopam/pam_cgroup.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 08:23:38 +0000 (13:53 +0530)] 
pam/pam_cgroup.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agodaemon/Makefile.am: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 08:22:11 +0000 (13:52 +0530)] 
daemon/Makefile.am: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agodaemon/cgruleseng.h: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 08:21:22 +0000 (13:51 +0530)] 
daemon/cgruleseng.h: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agodaemon/cgruleseng.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 08:18:46 +0000 (13:48 +0530)] 
daemon/cgruleseng.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoMakefile.am: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
Makefile.am: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agowrapper.c: increase the column width to 100
Kamalesh Babulal [Sat, 9 Jul 2022 13:24:29 +0000 (18:54 +0530)] 
wrapper.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoparse.y: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
parse.y: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agolibcgroup-internal.h: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
libcgroup-internal.h: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoconfig.c: increase the column width to 100
Kamalesh Babulal [Sat, 9 Jul 2022 13:21:20 +0000 (18:51 +0530)] 
config.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoabstraction-map.h: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
abstraction-map.h: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoabstraction-map.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
abstraction-map.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoabstraction-cpuset.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
abstraction-cpuset.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoabstraction-cpu.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
abstraction-cpu.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoabstraction-common.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
abstraction-common.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across
the file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoabstraction-common.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
abstraction-common.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across the
file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoapi.c: increase the column width to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:33:11 +0000 (13:03 +0530)] 
api.c: increase the column width to 100

100 column width is more comfortable to read over 80 columns, lets
increase it.  This patch, also introduced/removes empty lines across the
file, making it more readable.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agocheckpatch.conf: increase the character limit to 100
Kamalesh Babulal [Thu, 30 Jun 2022 07:03:57 +0000 (12:33 +0530)] 
checkpatch.conf: increase the character limit to 100

100 column width is more comfortable to read over 80 columns, lets
increase the value in the configuration file.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agotools/cgxget: fix a resource leak get_cv_value()
Kamalesh Babulal [Fri, 8 Jul 2022 16:50:00 +0000 (10:50 -0600)] 
tools/cgxget: fix a resource leak get_cv_value()

Fix a resource leak in get_cv_value(), reported by Coverity tool:

CID 258291 (#1 of 1): Resource leak (RESOURCE_LEAK). leaked_storage:
Variable handle going out of scope leaks the storage it points to.

failure on the realloc(), doesn't free the *handle. Fix it by using the
goto read_end(), that does the job of freeing the handle.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agowrapper.c: return on failure in cgroup_add_all_controllers()
Kamalesh Babulal [Fri, 8 Jul 2022 16:37:09 +0000 (10:37 -0600)] 
wrapper.c: return on failure in cgroup_add_all_controllers()

Add missing goto statement, to return on failure, reported by Coverity
tool:

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

the tool reported about unused ret value, but it turned out that the
NULL ret value is for failed attempt to add a controller to the desired
cgroup and needs bailing out after losing the handle. Fix it by
introducing the goto statement in cgroup_add_all_controllers()

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
TJH: Also fix unrelated grammar error near this change.

3 years agoconfig: remove dead code in config_validate_namespaces()
Kamalesh Babulal [Fri, 8 Jul 2022 16:28:49 +0000 (10:28 -0600)] 
config: remove dead code in config_validate_namespaces()

Remove the logically dead code, reported by the Coverity tool:

CID 258280 (#1 of 1): Logically dead code (DEADCODE)dead_error_begin:
Execution cannot reach this statement: last_errno = *__errno_locat....

cg_mount_table[i].mount.path can never be NULL, so remove that check in
the config_validate_namespaces().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
3 years agoconfig: fix string termination issues
Kamalesh Babulal [Wed, 6 Jul 2022 20:18:03 +0000 (14:18 -0600)] 
config: fix string termination issues

Fix non-terminated string warnings, reported by the Coverity tool:

CID 258293 (#2 of 2): Copy into fixed size buffer (STRING_OVERFLOW).
fixed_size_dest: You might overrun the 32-character fixed-size string
config_namespace_table[namespace_table_index].name by copying name
without checking the length.

fix one another similar string
config_namespace_table[namespace_table_index].mount.path in the same
function cgroup_config_insert_into_namespace_table() by explicitly
terminating by appending '\0';

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