summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2020-05-28 12:09:32 -0700
committerAnita Zhang <the.anitazha@gmail.com>2020-07-03 02:33:50 -0700
commit640f3b143d77b02612dc694a6a2be08f98d6c0e4 (patch)
treec757369a2e6088a31b78a3035d662ff1c308e850 /src/test
parenta68da222571789414b86d6bfa67aa7d38c63b19a (diff)
downloadsystemd-640f3b143d77b02612dc694a6a2be08f98d6c0e4.tar.gz
core: check null_or_empty for masked units instead of /dev/null
There's some inconsistency in the what is considered a masked unit: some places (i.e. load-fragment.c) use `null_or_empty()` while others check if the file path is symlinked to "/dev/null". Since the latter doesn't account for things like non-absolute symlinks to "/dev/null", this commit switches the check for "/dev/null" to use `null_or_empty_path()`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-install-root.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
index 515f14b8ca..d437686bae 100644
--- a/src/test/test-install-root.c
+++ b/src/test/test-install-root.c
@@ -4,6 +4,7 @@
#include "alloc-util.h"
#include "fileio.h"
+#include "fs-util.h"
#include "install.h"
#include "mkdir.h"
#include "rm-rf.h"
@@ -23,6 +24,7 @@ static void test_basic_mask_and_enable(const char *root) {
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) == -ENOENT);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", NULL) == -ENOENT);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", NULL) == -ENOENT);
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "e.service", NULL) == -ENOENT);
p = strjoina(root, "/usr/lib/systemd/system/a.service");
assert_se(write_string_file(p,
@@ -150,6 +152,22 @@ static void test_basic_mask_and_enable(const char *root) {
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_ALIAS);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_ALIAS);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_ALIAS);
+
+ /* Test masking with relative symlinks */
+
+ p = strjoina(root, "/usr/lib/systemd/system/e.service");
+ assert_se(symlink("../../../../../../dev/null", p) >= 0);
+
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "e.service", NULL) >= 0);
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "e.service", &state) >= 0 && state == UNIT_FILE_MASKED);
+
+ assert_se(unlink(p) == 0);
+ assert_se(symlink("/usr/../dev/null", p) >= 0);
+
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "e.service", NULL) >= 0);
+ assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "e.service", &state) >= 0 && state == UNIT_FILE_MASKED);
+
+ assert_se(unlink(p) == 0);
}
static void test_linked_units(const char *root) {
@@ -1227,6 +1245,12 @@ int main(int argc, char *argv[]) {
p = strjoina(root, "/usr/lib/systemd/system-preset/");
assert_se(mkdir_p(p, 0755) >= 0);
+ p = strjoina(root, "/dev/");
+ assert_se(mkdir_p(p, 0755) >= 0);
+
+ p = strjoina(root, "/dev/null");
+ assert_se(touch(p) >= 0);
+
test_basic_mask_and_enable(root);
test_linked_units(root);
test_default(root);