2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include <linux/magic.h>
24 #include "alloc-util.h"
29 #include "mount-util.h"
30 #include "stat-util.h"
32 static void test_files_same(void) {
33 _cleanup_close_ int fd = -1;
34 char name[] = "/tmp/test-files_same.XXXXXX";
35 char name_alias[] = "/tmp/test-files_same.alias";
37 fd = mkostemp_safe(name);
39 assert_se(symlink(name, name_alias) >= 0);
41 assert_se(files_same(name, name, 0));
42 assert_se(files_same(name, name, AT_SYMLINK_NOFOLLOW));
43 assert_se(files_same(name, name_alias, 0));
44 assert_se(!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW));
50 #if 0 /// UNNEEDED by elogind
51 static void test_is_symlink(void) {
52 char name[] = "/tmp/test-is_symlink.XXXXXX";
53 char name_link[] = "/tmp/test-is_symlink.link";
54 _cleanup_close_ int fd = -1;
56 fd = mkostemp_safe(name);
58 assert_se(symlink(name, name_link) >= 0);
60 assert_se(is_symlink(name) == 0);
61 assert_se(is_symlink(name_link) == 1);
62 assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0);
69 static void test_path_is_os_tree(void) {
70 assert_se(path_is_os_tree("/") > 0);
71 assert_se(path_is_os_tree("/etc") == 0);
72 assert_se(path_is_os_tree("/idontexist") == -ENOENT);
75 static void test_path_check_fstype(void) {
76 /* run might not be a mount point in build chroots */
77 if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
78 assert_se(path_check_fstype("/run", TMPFS_MAGIC) > 0);
79 assert_se(path_check_fstype("/run", BTRFS_SUPER_MAGIC) == 0);
81 assert_se(path_check_fstype("/proc", PROC_SUPER_MAGIC) > 0);
82 assert_se(path_check_fstype("/proc", BTRFS_SUPER_MAGIC) == 0);
83 assert_se(path_check_fstype("/proc", BTRFS_SUPER_MAGIC) == 0);
84 assert_se(path_check_fstype("/i-dont-exist", BTRFS_SUPER_MAGIC) == -ENOENT);
87 static void test_path_is_temporary_fs(void) {
88 /* run might not be a mount point in build chroots */
89 if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
90 assert_se(path_is_temporary_fs("/run") > 0);
91 assert_se(path_is_temporary_fs("/proc") == 0);
92 assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT);
96 int main(int argc, char *argv[]) {
98 #if 0 /// UNNEEDED by elogind
100 test_path_is_os_tree();
101 test_path_check_fstype();
102 test_path_is_temporary_fs();