mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
test-cgroup-util: Check return values (#36024)
Reported by Coverity and Fixes CID#1587767
This commit is contained in:
commit
b330824e59
@ -198,7 +198,14 @@ TEST(get_paths, .sd_booted = true) {
|
||||
log_info("Root = %s", a);
|
||||
}
|
||||
|
||||
TEST(proc) {
|
||||
static inline bool hidden_cgroup(const char *p) {
|
||||
assert(p);
|
||||
|
||||
/* Consider top-level cgroup hidden from us */
|
||||
return p[0] == '/' && p[strspn(p, "/")] == '.';
|
||||
}
|
||||
|
||||
TEST(proc, .sd_booted = true) {
|
||||
_cleanup_closedir_ DIR *d = NULL;
|
||||
int r;
|
||||
|
||||
@ -218,14 +225,24 @@ TEST(proc) {
|
||||
if (pidref_is_kernel_thread(&pid) != 0)
|
||||
continue;
|
||||
|
||||
cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &pid, &path);
|
||||
cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted);
|
||||
cg_pidref_get_owner_uid(&pid, &uid);
|
||||
cg_pidref_get_session(&pid, &session);
|
||||
cg_pidref_get_unit(&pid, &unit);
|
||||
cg_pid_get_user_unit(pid.pid, &user_unit);
|
||||
cg_pid_get_machine_name(pid.pid, &machine);
|
||||
cg_pid_get_slice(pid.pid, &slice);
|
||||
ASSERT_OK_ZERO(cg_pidref_get_path(SYSTEMD_CGROUP_CONTROLLER, &pid, &path));
|
||||
/* Test may run in a container with supervising/monitor processes that don't belong to our
|
||||
* cgroup tree (slices/leaves) */
|
||||
if (hidden_cgroup(path))
|
||||
continue;
|
||||
ASSERT_OK_ZERO(cg_pid_get_path_shifted(pid.pid, NULL, &path_shifted));
|
||||
ASSERT_OK_ZERO(cg_pidref_get_unit(&pid, &unit));
|
||||
ASSERT_OK_ZERO(cg_pid_get_slice(pid.pid, &slice));
|
||||
|
||||
/* Not all processes belong to a specific user or a machine */
|
||||
r = cg_pidref_get_owner_uid(&pid, &uid);
|
||||
ASSERT_TRUE(r == 0 || r == -ENXIO);
|
||||
r = cg_pidref_get_session(&pid, &session);
|
||||
ASSERT_TRUE(r == 0 || r == -ENXIO);
|
||||
r = cg_pid_get_user_unit(pid.pid, &user_unit);
|
||||
ASSERT_TRUE(r == 0 || r == -ENXIO);
|
||||
r = cg_pid_get_machine_name(pid.pid, &machine);
|
||||
ASSERT_TRUE(r == 0 || r == -ENOENT);
|
||||
|
||||
printf(PID_FMT"\t%s\t%s\t"UID_FMT"\t%s\t%s\t%s\t%s\t%s\n",
|
||||
pid.pid,
|
||||
|
Loading…
x
Reference in New Issue
Block a user