diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-10-22 16:11:41 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-10-22 16:15:46 -0400 |
commit | fb4650aa346a57da3d20525ca2a3124099a1a307 (patch) | |
tree | ce7365ba81a89f676a3435138340fe24b6ea546c /src/core/cgroup.c | |
parent | d7f69e16f1a5b84e9acf1771a9b53da3787ae79d (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.
Diffstat (limited to 'src/core/cgroup.c')
-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 23a92f9651..09bbe038e9 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -928,7 +928,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) @@ -945,10 +945,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); } |