2018-03-14 11:03:36 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
|
|
|
2018-09-12 08:15:09 +02:00
|
|
|
#include "alloc-util.h"
|
2018-03-14 11:03:36 +01:00
|
|
|
#include "log.h"
|
2018-09-12 08:15:09 +02:00
|
|
|
#include "path-util.h"
|
2018-03-14 11:03:36 +01:00
|
|
|
#include "string-util.h"
|
|
|
|
#include "tests.h"
|
|
|
|
#include "umount.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void test_mount_points_list(const char *fname) {
|
2018-03-14 11:32:13 +01:00
|
|
|
_cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
|
2018-09-12 08:15:09 +02:00
|
|
|
_cleanup_free_ char *testdata_fname = NULL;
|
2018-03-14 11:03:36 +01:00
|
|
|
MountPoint *m;
|
|
|
|
|
|
|
|
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
|
|
|
|
|
2019-12-06 21:51:59 +01:00
|
|
|
if (fname) {
|
|
|
|
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
|
|
|
|
fname = testdata_fname;
|
|
|
|
}
|
2018-09-12 08:15:09 +02:00
|
|
|
|
2018-03-14 11:03:36 +01:00
|
|
|
LIST_HEAD_INIT(mp_list_head);
|
|
|
|
assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
|
|
|
|
|
|
|
|
LIST_FOREACH(mount_point, m, mp_list_head)
|
|
|
|
log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
|
|
|
|
m->path,
|
|
|
|
strempty(m->remount_options),
|
|
|
|
m->remount_flags,
|
|
|
|
yes_no(m->try_remount_ro),
|
|
|
|
major(m->devnum), minor(m->devnum));
|
|
|
|
}
|
|
|
|
|
2018-03-14 12:06:34 +01:00
|
|
|
static void test_swap_list(const char *fname) {
|
|
|
|
_cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
|
2018-09-12 08:15:09 +02:00
|
|
|
_cleanup_free_ char *testdata_fname = NULL;
|
2018-03-14 12:06:34 +01:00
|
|
|
MountPoint *m;
|
|
|
|
|
2018-03-14 12:22:27 +01:00
|
|
|
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
|
2018-03-14 12:06:34 +01:00
|
|
|
|
2019-12-06 21:51:59 +01:00
|
|
|
if (fname) {
|
|
|
|
assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
|
|
|
|
fname = testdata_fname;
|
|
|
|
}
|
2018-09-12 08:15:09 +02:00
|
|
|
|
2018-03-14 12:06:34 +01:00
|
|
|
LIST_HEAD_INIT(mp_list_head);
|
|
|
|
assert_se(swap_list_get(fname, &mp_list_head) >= 0);
|
|
|
|
|
|
|
|
LIST_FOREACH(mount_point, m, mp_list_head)
|
|
|
|
log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",
|
|
|
|
m->path,
|
|
|
|
strempty(m->remount_options),
|
|
|
|
m->remount_flags,
|
|
|
|
yes_no(m->try_remount_ro),
|
|
|
|
major(m->devnum), minor(m->devnum));
|
|
|
|
}
|
|
|
|
|
2018-03-14 11:03:36 +01:00
|
|
|
int main(int argc, char **argv) {
|
2018-09-13 14:31:13 +02:00
|
|
|
test_setup_logging(LOG_DEBUG);
|
2018-03-14 11:03:36 +01:00
|
|
|
|
|
|
|
test_mount_points_list(NULL);
|
2018-09-12 08:15:09 +02:00
|
|
|
test_mount_points_list("/test-umount/empty.mountinfo");
|
|
|
|
test_mount_points_list("/test-umount/garbled.mountinfo");
|
|
|
|
test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
|
2018-03-14 12:06:34 +01:00
|
|
|
|
|
|
|
test_swap_list(NULL);
|
2018-09-12 08:15:09 +02:00
|
|
|
test_swap_list("/test-umount/example.swaps");
|
2018-03-14 11:03:36 +01:00
|
|
|
}
|