diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-10-22 16:11:41 -0400 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-07-17 17:58:34 +0200 |
commit | 910c586574a52c6b4cbc6638193797008da076c7 (patch) | |
tree | 43e6d4842f185439c9e22eeb45e56aea851f40aa | |
parent | 3b148b365934f5baf2c9162e2454ca416b666531 (diff) |
tree-wide: use startswith return value to avoid hardcoded offset
I think it's an antipattern to have to count the number of bytes in
the prefix by hand. We should do this automatically to avoid wasting
programmer time, and possible errors. I didn't any offsets that were
wrong, so this change is mostly to make future development easier.
-rw-r--r-- | src/core/cgroup.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 9e4e99326..a524a4110 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -930,7 +930,7 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) { } LIST_FOREACH(device_allow, a, c->device_allow) { - char acc[4]; + char acc[4], *val; unsigned k = 0; if (a->r) @@ -947,10 +947,10 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) { if (startswith(a->path, "/dev/")) whitelist_device(path, a->path, acc); - else if (startswith(a->path, "block-")) - whitelist_major(path, a->path + 6, 'b', acc); - else if (startswith(a->path, "char-")) - whitelist_major(path, a->path + 5, 'c', acc); + else if ((val = startswith(a->path, "block-"))) + whitelist_major(path, val, 'b', acc); + else if ((val = startswith(a->path, "char-"))) + whitelist_major(path, val, 'c', acc); else log_unit_debug(u, "Ignoring device %s while writing cgroup attribute.", a->path); } |