]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-umount.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "alloc-util.h"
6 #include "string-util.h"
11 static void test_mount_points_list(const char *fname
) {
12 _cleanup_(mount_points_list_free
) LIST_HEAD(MountPoint
, mp_list_head
);
13 _cleanup_free_
char *testdata_fname
= NULL
;
16 log_info("/* %s(\"%s\") */", __func__
, fname
?: "/proc/self/mountinfo");
19 fname
= testdata_fname
= path_join(get_testdata_dir(), fname
);
21 LIST_HEAD_INIT(mp_list_head
);
22 assert_se(mount_points_list_get(fname
, &mp_list_head
) >= 0);
24 LIST_FOREACH(mount_point
, m
, mp_list_head
)
25 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
27 strempty(m
->remount_options
),
29 yes_no(m
->try_remount_ro
),
30 major(m
->devnum
), minor(m
->devnum
));
33 static void test_swap_list(const char *fname
) {
34 _cleanup_(mount_points_list_free
) LIST_HEAD(MountPoint
, mp_list_head
);
35 _cleanup_free_
char *testdata_fname
= NULL
;
38 log_info("/* %s(\"%s\") */", __func__
, fname
?: "/proc/swaps");
41 fname
= testdata_fname
= path_join(get_testdata_dir(), fname
);
43 LIST_HEAD_INIT(mp_list_head
);
44 assert_se(swap_list_get(fname
, &mp_list_head
) >= 0);
46 LIST_FOREACH(mount_point
, m
, mp_list_head
)
47 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
49 strempty(m
->remount_options
),
51 yes_no(m
->try_remount_ro
),
52 major(m
->devnum
), minor(m
->devnum
));
55 int main(int argc
, char **argv
) {
56 test_setup_logging(LOG_DEBUG
);
58 test_mount_points_list(NULL
);
59 test_mount_points_list("/test-umount/empty.mountinfo");
60 test_mount_points_list("/test-umount/garbled.mountinfo");
61 test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
64 test_swap_list("/test-umount/example.swaps");