summaryrefslogtreecommitdiff
path: root/src/shared/cgroup-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-09-25 20:58:23 +0200
committerLennart Poettering <lennart@poettering.net>2013-09-25 21:04:35 +0200
commitfecffe5d0a1bd66d80e5a8728ff8a89673be0df7 (patch)
tree133a9f9b0dc791723a1e63fa6efb5fafa4a8ba60 /src/shared/cgroup-util.c
parentbc5fb0809e6f5784888f30057708548f14dcb459 (diff)
util: add macro for iterating through all prefixes of a path
Syntactic sugar in a macro PATH_FOREACH_PREFIX.
Diffstat (limited to 'src/shared/cgroup-util.c')
-rw-r--r--src/shared/cgroup-util.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 2e630d4708..dc0fe85ee2 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -456,23 +456,14 @@ int cg_migrate_recursive_fallback(
/* This didn't work? Then let's try all prefixes of the destination */
- strcpy(prefix, pto);
- for (;;) {
- char *slash;
-
- slash = strrchr(prefix, '/');
- if (!slash)
- break;
-
- *slash = 0;
-
+ PATH_FOREACH_PREFIX(prefix, pto) {
r = cg_migrate_recursive(cfrom, pfrom, cto, prefix, ignore_self, rem);
if (r >= 0)
break;
}
}
- return r;
+ return 0;
}
static const char *normalize_controller(const char *controller) {
@@ -661,23 +652,14 @@ int cg_attach_fallback(const char *controller, const char *path, pid_t pid) {
/* This didn't work? Then let's try all prefixes of
* the destination */
- strcpy(prefix, path);
- for (;;) {
- char *slash;
-
- slash = strrchr(prefix, '/');
- if (!slash)
- break;
-
- *slash = 0;
-
+ PATH_FOREACH_PREFIX(prefix, path) {
r = cg_attach(controller, prefix, pid);
if (r >= 0)
break;
}
}
- return r;
+ return 0;
}
int cg_set_group_access(