tree-wide: use SPECIAL_ROOT_SLICE
This commit is contained in:
parent
a789420775
commit
e5af6e0e2d
|
@ -28,6 +28,7 @@
|
|||
#include "glob-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "path-util.h"
|
||||
#include "special.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "unit-name.h"
|
||||
|
@ -673,7 +674,7 @@ int slice_build_parent_slice(const char *slice, char **ret) {
|
|||
if (!slice_name_is_valid(slice))
|
||||
return -EINVAL;
|
||||
|
||||
if (streq(slice, "-.slice")) {
|
||||
if (streq(slice, SPECIAL_ROOT_SLICE)) {
|
||||
*ret = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
@ -686,7 +687,7 @@ int slice_build_parent_slice(const char *slice, char **ret) {
|
|||
if (dash)
|
||||
strcpy(dash, ".slice");
|
||||
else {
|
||||
r = free_and_strdup(&s, "-.slice");
|
||||
r = free_and_strdup(&s, SPECIAL_ROOT_SLICE);
|
||||
if (r < 0) {
|
||||
free(s);
|
||||
return r;
|
||||
|
@ -710,7 +711,7 @@ int slice_build_subslice(const char *slice, const char*name, char **ret) {
|
|||
if (!unit_prefix_is_valid(name))
|
||||
return -EINVAL;
|
||||
|
||||
if (streq(slice, "-.slice"))
|
||||
if (streq(slice, SPECIAL_ROOT_SLICE))
|
||||
subslice = strappend(name, ".slice");
|
||||
else {
|
||||
char *e;
|
||||
|
@ -735,7 +736,7 @@ bool slice_name_is_valid(const char *name) {
|
|||
if (!unit_name_is_valid(name, UNIT_NAME_PLAIN))
|
||||
return false;
|
||||
|
||||
if (streq(name, "-.slice"))
|
||||
if (streq(name, SPECIAL_ROOT_SLICE))
|
||||
return true;
|
||||
|
||||
e = endswith(name, ".slice");
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "machined.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "special.h"
|
||||
|
||||
Manager *manager_new(void) {
|
||||
Manager *m;
|
||||
|
@ -112,7 +113,7 @@ static int manager_add_host_machine(Manager *m) {
|
|||
if (!rd)
|
||||
return log_oom();
|
||||
|
||||
unit = strdup("-.slice");
|
||||
unit = strdup(SPECIAL_ROOT_SLICE);
|
||||
if (!unit)
|
||||
return log_oom();
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "parse-util.h"
|
||||
#include "proc-cmdline.h"
|
||||
#include "process-util.h"
|
||||
#include "special.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-util.h"
|
||||
#include "test-helper.h"
|
||||
|
@ -141,10 +142,10 @@ static void check_p_g_slice(const char *path, int code, const char *result) {
|
|||
|
||||
static void test_path_get_slice(void) {
|
||||
check_p_g_slice("/user.slice", 0, "user.slice");
|
||||
check_p_g_slice("/foobar", 0, "-.slice");
|
||||
check_p_g_slice("/foobar", 0, SPECIAL_ROOT_SLICE);
|
||||
check_p_g_slice("/user.slice/user-waldo.slice", 0, "user-waldo.slice");
|
||||
check_p_g_slice("", 0, "-.slice");
|
||||
check_p_g_slice("foobar", 0, "-.slice");
|
||||
check_p_g_slice("", 0, SPECIAL_ROOT_SLICE);
|
||||
check_p_g_slice("foobar", 0, SPECIAL_ROOT_SLICE);
|
||||
check_p_g_slice("foobar.slice", 0, "foobar.slice");
|
||||
check_p_g_slice("foo.slice/foo-bar.slice/waldo.service", 0, "foo-bar.slice");
|
||||
}
|
||||
|
@ -165,10 +166,10 @@ static void test_path_get_user_slice(void) {
|
|||
check_p_g_u_slice("foobar.slice", -ENXIO, NULL);
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/waldo.service", -ENXIO, NULL);
|
||||
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service", 0, "-.slice");
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/", 0, "-.slice");
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service///", 0, "-.slice");
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/waldo.service", 0, "-.slice");
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service", 0, SPECIAL_ROOT_SLICE);
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/", 0, SPECIAL_ROOT_SLICE);
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service///", 0, SPECIAL_ROOT_SLICE);
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/waldo.service", 0, SPECIAL_ROOT_SLICE);
|
||||
check_p_g_u_slice("foo.slice/foo-bar.slice/user@1000.service/piep.slice/foo.service", 0, "piep.slice");
|
||||
check_p_g_u_slice("/foo.slice//foo-bar.slice/user@1000.service/piep.slice//piep-pap.slice//foo.service", 0, "piep-pap.slice");
|
||||
}
|
||||
|
@ -274,7 +275,7 @@ static void test_slice_to_path(void) {
|
|||
test_slice_to_path_one("foobar.slice", "foobar.slice", 0);
|
||||
test_slice_to_path_one("foobar-waldo.slice", "foobar.slice/foobar-waldo.slice", 0);
|
||||
test_slice_to_path_one("foobar-waldo.service", NULL, -EINVAL);
|
||||
test_slice_to_path_one("-.slice", "", 0);
|
||||
test_slice_to_path_one(SPECIAL_ROOT_SLICE, "", 0);
|
||||
test_slice_to_path_one("--.slice", NULL, -EINVAL);
|
||||
test_slice_to_path_one("-", NULL, -EINVAL);
|
||||
test_slice_to_path_one("-foo-.slice", NULL, -EINVAL);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "manager.h"
|
||||
#include "path-util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "special.h"
|
||||
#include "specifier.h"
|
||||
#include "string-util.h"
|
||||
#include "test-helper.h"
|
||||
|
@ -338,7 +339,7 @@ static void test_unit_name_build(void) {
|
|||
}
|
||||
|
||||
static void test_slice_name_is_valid(void) {
|
||||
assert_se(slice_name_is_valid("-.slice"));
|
||||
assert_se(slice_name_is_valid(SPECIAL_ROOT_SLICE));
|
||||
assert_se(slice_name_is_valid("foo.slice"));
|
||||
assert_se(slice_name_is_valid("foo-bar.slice"));
|
||||
assert_se(slice_name_is_valid("foo-bar-baz.slice"));
|
||||
|
@ -356,7 +357,7 @@ static void test_build_subslice(void) {
|
|||
char *a;
|
||||
char *b;
|
||||
|
||||
assert_se(slice_build_subslice("-.slice", "foo", &a) >= 0);
|
||||
assert_se(slice_build_subslice(SPECIAL_ROOT_SLICE, "foo", &a) >= 0);
|
||||
assert_se(slice_build_subslice(a, "bar", &b) >= 0);
|
||||
free(a);
|
||||
assert_se(slice_build_subslice(b, "barfoo", &a) >= 0);
|
||||
|
@ -378,8 +379,8 @@ static void test_build_parent_slice_one(const char *name, const char *expect, in
|
|||
}
|
||||
|
||||
static void test_build_parent_slice(void) {
|
||||
test_build_parent_slice_one("-.slice", NULL, 0);
|
||||
test_build_parent_slice_one("foo.slice", "-.slice", 1);
|
||||
test_build_parent_slice_one(SPECIAL_ROOT_SLICE, NULL, 0);
|
||||
test_build_parent_slice_one("foo.slice", SPECIAL_ROOT_SLICE, 1);
|
||||
test_build_parent_slice_one("foo-bar.slice", "foo.slice", 1);
|
||||
test_build_parent_slice_one("foo-bar-baz.slice", "foo-bar.slice", 1);
|
||||
test_build_parent_slice_one("foo-bar--baz.slice", NULL, -EINVAL);
|
||||
|
|
Loading…
Reference in a new issue