415fc41cea
cg_[all_]unified() test whether a specific controller or all controllers are on the unified hierarchy. While what's being asked is a simple binary question, the callers must assume that the functions may fail any time, which unnecessarily complicates their usages. This complication is unnecessary. Internally, the test result is cached anyway and there are only a few places where the test actually needs to be performed. This patch simplifies cg_[all_]unified(). * cg_[all_]unified() are updated to return bool. If the result can't be decided, assertion failure is triggered. Error handlings from their callers are dropped. * cg_unified_flush() is updated to calculate the new result synchrnously and return whether it succeeded or not. Places which need to flush the test result are updated to test for failure. This ensures that all the following cg_[all_]unified() tests succeed. * Places which expected possible cg_[all_]unified() failures are updated to call and test cg_unified_flush() before calling cg_[all_]unified(). This includes functions used while setting up mounts during boot and manager_setup_cgroup().
56 lines
1.7 KiB
C
56 lines
1.7 KiB
C
/***
|
|
This file is part of systemd.
|
|
|
|
Copyright 2013 Lennart Poettering
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
(at your option) any later version.
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
***/
|
|
|
|
#include "sd-bus.h"
|
|
|
|
#include "bus-dump.h"
|
|
#include "bus-util.h"
|
|
#include "cgroup-util.h"
|
|
|
|
int main(int argc, char *argv[]) {
|
|
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
|
|
int r;
|
|
|
|
log_set_max_level(LOG_DEBUG);
|
|
log_parse_environment();
|
|
log_open();
|
|
|
|
if (cg_unified_flush() == -ENOMEDIUM) {
|
|
log_info("Skipping test: /sys/fs/cgroup/ not available");
|
|
return EXIT_TEST_SKIP;
|
|
}
|
|
|
|
r = sd_bus_creds_new_from_pid(&creds, 0, _SD_BUS_CREDS_ALL);
|
|
log_full_errno(r < 0 ? LOG_ERR : LOG_DEBUG, r, "sd_bus_creds_new_from_pid: %m");
|
|
assert_se(r >= 0);
|
|
|
|
bus_creds_dump(creds, NULL, true);
|
|
|
|
creds = sd_bus_creds_unref(creds);
|
|
|
|
r = sd_bus_creds_new_from_pid(&creds, 1, _SD_BUS_CREDS_ALL);
|
|
if (r != -EACCES) {
|
|
assert_se(r >= 0);
|
|
putchar('\n');
|
|
bus_creds_dump(creds, NULL, true);
|
|
}
|
|
|
|
return 0;
|
|
}
|