shared: Drop 'name=' prefix from SYSTEMD_CGROUP_CONTROLLER define.

In cgtop,mount-setup,nspawn the name= prefix is hard-coded in the
mount options, and the define is not used.

Everywhere else, we explicitly white-list allow 'name=' prefix to be
used with all controllers, and strip it out to 'normalise' the
controller name. That work is mostly inflicted on us due to 'name='
prefix in the define. Dropping this prefix makes everything more sane
overall.
This commit is contained in:
Dimitri John Ledkov 2015-06-01 12:46:52 +01:00
parent 80979f1ce4
commit 185a087459
4 changed files with 22 additions and 26 deletions

View file

@ -441,9 +441,7 @@ static const char *normalize_controller(const char *controller) {
assert(controller); assert(controller);
if (streq(controller, SYSTEMD_CGROUP_CONTROLLER)) if (startswith(controller, "name="))
return "systemd";
else if (startswith(controller, "name="))
return controller + 5; return controller + 5;
else else
return controller; return controller;
@ -483,7 +481,7 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch
assert(fs); assert(fs);
if (controller && !cg_controller_is_valid(controller, true)) if (controller && !cg_controller_is_valid(controller))
return -EINVAL; return -EINVAL;
if (_unlikely_(!good)) { if (_unlikely_(!good)) {
@ -526,7 +524,7 @@ int cg_get_path_and_check(const char *controller, const char *path, const char *
assert(fs); assert(fs);
if (!cg_controller_is_valid(controller, true)) if (!cg_controller_is_valid(controller))
return -EINVAL; return -EINVAL;
/* Normalize the controller syntax */ /* Normalize the controller syntax */
@ -742,7 +740,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
assert(pid >= 0); assert(pid >= 0);
if (controller) { if (controller) {
if (!cg_controller_is_valid(controller, true)) if (!cg_controller_is_valid(controller))
return -EINVAL; return -EINVAL;
controller = normalize_controller(controller); controller = normalize_controller(controller);
@ -971,7 +969,7 @@ int cg_split_spec(const char *spec, char **controller, char **path) {
e = strchr(spec, ':'); e = strchr(spec, ':');
if (!e) { if (!e) {
if (!cg_controller_is_valid(spec, true)) if (!cg_controller_is_valid(spec))
return -EINVAL; return -EINVAL;
if (controller) { if (controller) {
@ -994,7 +992,7 @@ int cg_split_spec(const char *spec, char **controller, char **path) {
t = strdup(normalize_controller(v)); t = strdup(normalize_controller(v));
if (!t) if (!t)
return -ENOMEM; return -ENOMEM;
if (!cg_controller_is_valid(t, true)) { if (!cg_controller_is_valid(t)) {
free(t); free(t);
return -EINVAL; return -EINVAL;
} }
@ -1610,17 +1608,15 @@ char *cg_unescape(const char *p) {
DIGITS LETTERS \ DIGITS LETTERS \
"_" "_"
bool cg_controller_is_valid(const char *p, bool allow_named) { bool cg_controller_is_valid(const char *p) {
const char *t, *s; const char *t, *s;
if (!p) if (!p)
return false; return false;
if (allow_named) { s = startswith(p, "name=");
s = startswith(p, "name="); if (s)
if (s) p = s;
p = s;
}
if (*p == 0 || *p == '_') if (*p == 0 || *p == '_')
return false; return false;

View file

@ -122,7 +122,7 @@ int cg_path_decode_unit(const char *cgroup, char **unit);
char *cg_escape(const char *p); char *cg_escape(const char *p);
char *cg_unescape(const char *p) _pure_; char *cg_unescape(const char *p) _pure_;
bool cg_controller_is_valid(const char *p, bool allow_named); bool cg_controller_is_valid(const char *p);
int cg_slice_to_path(const char *unit, char **ret); int cg_slice_to_path(const char *unit, char **ret);

View file

@ -35,7 +35,7 @@
* the watchdog pings will keep the loop busy. */ * the watchdog pings will keep the loop busy. */
#define DEFAULT_EXIT_USEC (30*USEC_PER_SEC) #define DEFAULT_EXIT_USEC (30*USEC_PER_SEC)
#define SYSTEMD_CGROUP_CONTROLLER "name=systemd" #define SYSTEMD_CGROUP_CONTROLLER "systemd"
#define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT #define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT
#define SIGNALS_IGNORE SIGPIPE #define SIGNALS_IGNORE SIGPIPE

View file

@ -244,16 +244,16 @@ static void test_escape(void) {
} }
static void test_controller_is_valid(void) { static void test_controller_is_valid(void) {
assert_se(cg_controller_is_valid("foobar", false)); assert_se(cg_controller_is_valid("foobar"));
assert_se(cg_controller_is_valid("foo_bar", false)); assert_se(cg_controller_is_valid("foo_bar"));
assert_se(cg_controller_is_valid("name=foo", true)); assert_se(cg_controller_is_valid("name=foo"));
assert_se(!cg_controller_is_valid("", false)); assert_se(!cg_controller_is_valid(""));
assert_se(!cg_controller_is_valid("name=", true)); assert_se(!cg_controller_is_valid("name="));
assert_se(!cg_controller_is_valid("=", false)); assert_se(!cg_controller_is_valid("="));
assert_se(!cg_controller_is_valid("cpu,cpuacct", false)); assert_se(!cg_controller_is_valid("cpu,cpuacct"));
assert_se(!cg_controller_is_valid("_", false)); assert_se(!cg_controller_is_valid("_"));
assert_se(!cg_controller_is_valid("_foobar", false)); assert_se(!cg_controller_is_valid("_foobar"));
assert_se(!cg_controller_is_valid("tatü", false)); assert_se(!cg_controller_is_valid("tatü"));
} }
static void test_slice_to_path_one(const char *unit, const char *path, int error) { static void test_slice_to_path_one(const char *unit, const char *path, int error) {