mirror of
https://github.com/systemd/systemd.git
synced 2025-03-09 12:58:26 +03:00
cgroup-util: use path_find_first_component where appropriate
Prompted by 8922a728f732a716ecd17dd67cd39bc1a0fc4aa5
This commit is contained in:
parent
d3aa0af31a
commit
66d826026e
@ -1500,22 +1500,25 @@ int cg_path_get_slice(const char *p, char **ret_slice) {
|
|||||||
assert(p);
|
assert(p);
|
||||||
assert(ret_slice);
|
assert(ret_slice);
|
||||||
|
|
||||||
/* Finds the right-most slice unit from the beginning, but
|
/* Finds the right-most slice unit from the beginning, but stops before we come to
|
||||||
* stops before we come to the first non-slice unit. */
|
* the first non-slice unit. */
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
p += strspn(p, "/");
|
const char *s;
|
||||||
|
int n;
|
||||||
|
|
||||||
size_t n = strcspn(p, "/");
|
n = path_find_first_component(&p, /* accept_dot_dot = */ false, &s);
|
||||||
if (!valid_slice_name(p, n))
|
if (n < 0)
|
||||||
|
return n;
|
||||||
|
if (!valid_slice_name(s, n))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
e = p;
|
e = s;
|
||||||
p += n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e)
|
if (e)
|
||||||
return cg_path_decode_unit(e, ret_slice);
|
return cg_path_decode_unit(e, ret_slice);
|
||||||
|
|
||||||
return strdup_to(ret_slice, SPECIAL_ROOT_SLICE);
|
return strdup_to(ret_slice, SPECIAL_ROOT_SLICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user