]>
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"
4 #include "errno-util.h"
7 #include "string-util.h"
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
;
17 log_info("/* %s(\"%s\") */", __func__
, fname
?: "/proc/self/mountinfo");
20 assert_se(get_testdata_dir(fname
, &testdata_fname
) >= 0);
21 fname
= testdata_fname
;
24 LIST_HEAD_INIT(mp_list_head
);
25 assert_se(mount_points_list_get(fname
, &mp_list_head
) >= 0);
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",
30 strempty(m
->remount_options
),
32 yes_no(m
->try_remount_ro
),
33 major(m
->devnum
), minor(m
->devnum
));
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
;
42 log_info("/* %s(\"%s\") */", __func__
, fname
?: "/proc/swaps");
45 assert_se(get_testdata_dir(fname
, &testdata_fname
) >= 0);
46 fname
= testdata_fname
;
49 LIST_HEAD_INIT(mp_list_head
);
50 r
= swap_list_get(fname
, &mp_list_head
);
51 if (ERRNO_IS_PRIVILEGE(r
))
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",
58 strempty(m
->remount_options
),
60 yes_no(m
->try_remount_ro
),
61 major(m
->devnum
), minor(m
->devnum
));
64 int main(int argc
, char **argv
) {
65 test_setup_logging(LOG_DEBUG
);
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");
73 test_swap_list("/test-umount/example.swaps");