]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-umount.c
tests: various small fixes for strict systems
[thirdparty/systemd.git] / src / test / test-umount.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "alloc-util.h"
4 #include "errno-util.h"
5 #include "log.h"
6 #include "path-util.h"
7 #include "string-util.h"
8 #include "tests.h"
9 #include "umount.h"
10 #include "util.h"
11
12 static void test_mount_points_list(const char *fname) {
13 _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
14 _cleanup_free_ char *testdata_fname = NULL;
15 MountPoint *m;
16
17 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
18
19 if (fname) {
20 assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
21 fname = testdata_fname;
22 }
23
24 LIST_HEAD_INIT(mp_list_head);
25 assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
26
27 LIST_FOREACH(mount_point, m, mp_list_head)
28 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
29 m->path,
30 strempty(m->remount_options),
31 m->remount_flags,
32 yes_no(m->try_remount_ro),
33 major(m->devnum), minor(m->devnum));
34 }
35
36 static void test_swap_list(const char *fname) {
37 _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
38 _cleanup_free_ char *testdata_fname = NULL;
39 MountPoint *m;
40 int r;
41
42 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
43
44 if (fname) {
45 assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
46 fname = testdata_fname;
47 }
48
49 LIST_HEAD_INIT(mp_list_head);
50 r = swap_list_get(fname, &mp_list_head);
51 if (ERRNO_IS_PRIVILEGE(r))
52 return;
53 assert_se(r >= 0);
54
55 LIST_FOREACH(mount_point, m, mp_list_head)
56 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
57 m->path,
58 strempty(m->remount_options),
59 m->remount_flags,
60 yes_no(m->try_remount_ro),
61 major(m->devnum), minor(m->devnum));
62 }
63
64 int main(int argc, char **argv) {
65 test_setup_logging(LOG_DEBUG);
66
67 test_mount_points_list(NULL);
68 test_mount_points_list("/test-umount/empty.mountinfo");
69 test_mount_points_list("/test-umount/garbled.mountinfo");
70 test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
71
72 test_swap_list(NULL);
73 test_swap_list("/test-umount/example.swaps");
74 }