return 0;
}
-static int swap_list_get(MountPoint **head) {
+int swap_list_get(const char *swaps, MountPoint **head) {
_cleanup_fclose_ FILE *proc_swaps = NULL;
unsigned int i;
int r;
assert(head);
- proc_swaps = fopen("/proc/swaps", "re");
+ proc_swaps = fopen(swaps ?: "/proc/swaps", "re");
if (!proc_swaps)
return (errno == ENOENT) ? 0 : -errno;
LIST_HEAD_INIT(swap_list_head);
- r = swap_list_get(&swap_list_head);
+ r = swap_list_get(NULL, &swap_list_head);
if (r < 0)
return r;
int mount_points_list_get(const char *mountinfo, MountPoint **head);
void mount_points_list_free(MountPoint **head);
+int swap_list_get(const char *swaps, MountPoint **head);
major(m->devnum), minor(m->devnum));
}
+static void test_swap_list(const char *fname) {
+ _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
+ MountPoint *m;
+
+ log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
+
+ 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));
+}
+
int main(int argc, char **argv) {
log_set_max_level(LOG_DEBUG);
log_parse_environment();
test_mount_points_list(get_testdata_dir("/test-umount/empty.mountinfo"));
test_mount_points_list(get_testdata_dir("/test-umount/garbled.mountinfo"));
test_mount_points_list(get_testdata_dir("/test-umount/rhbug-1554943.mountinfo"));
+
+ test_swap_list(NULL);
+ test_swap_list(get_testdata_dir("/test-umount/example.swaps"));
}
test-umount/empty.mountinfo
test-umount/garbled.mountinfo
test-umount/rhbug-1554943.mountinfo
+ test-umount/example.swaps
'''.split()
if conf.get('ENABLE_RESOLVE') == 1
--- /dev/null
+Filename Type Size Used Priority
+/dev/dm-2 partition 8151036 2283436 -2
+/some/swapfile file 111 111 0
+/some/swapfile2 (deleted) file 111 111 0