static int swapoff_all(void) { int status = 0; struct libmnt_table *tb; struct libmnt_fs *fs; struct libmnt_iter *itr = mnt_new_iter(MNT_ITER_BACKWARD); if (!itr) err(EXIT_FAILURE, _("failed to initialize libmount iterator")); /* * In case /proc/swaps exists, unswap stuff listed there. We are quiet * but report errors in status. Errors might mean that /proc/swaps * exists as ordinary file, not in procfs. do_swapoff() exits * immediately on EPERM. */ tb = get_swaps(); while (tb && mnt_table_find_next_fs(tb, itr, match_swap, NULL, &fs) == 0) status |= do_swapoff(mnt_fs_get_source(fs), QUIET, CANONIC); /* * Unswap stuff mentioned in /etc/fstab. Probably it was unmounted * already, so errors are not bad. Doing swapoff -a twice should not * give error messages. */ tb = get_fstab(); mnt_reset_iter(itr, MNT_ITER_FORWARD); while (tb && mnt_table_find_next_fs(tb, itr, match_swap, NULL, &fs) == 0) { if (!is_active_swap(mnt_fs_get_source(fs))) do_swapoff(mnt_fs_get_source(fs), QUIET, !CANONIC); } mnt_free_iter(itr); return status; }
int main(const int argc, const char* argv[]) { if (argc == 2) { if (strcmp(argv[1], "--verbose") == 0) { verbose_mode = 1; } } prepare(); clearSupplementaryGroups(); selfCheck(); struct libmnt_table* mt = mnt_new_table_from_file("/opt/xware_desktop/mounts"); if (mt == NULL) { fprintf(stderr, "mnt_new_table_from_file failed.\n"); exit(EXIT_FAILURE); } struct libmnt_iter* itr = mnt_new_iter(MNT_ITER_FORWARD); struct libmnt_fs* fs = NULL; while(1) { int tmp = mnt_table_find_next_fs(mt, itr, &matchAll, NULL, &fs); if (tmp < 0) { // error fprintf(stderr, "mnt_table_find_next_fs failed.\n"); break; } else { if (tmp == 1) { // reach EOF break; } const char* target = mnt_fs_get_target(fs); if (target == NULL) { fprintf(stderr, "mnt_fs_get_target failed.\n"); } else { printf("%s%s%s\n", BOLD, target, NOSTYLE); printf("================================\n"); if (checkDirXPermissions(target)) { checkTargetDirPermissions(target); } printf("\n"); } } } printf("%s", NOSTYLE); mnt_free_fs(fs); mnt_free_iter(itr); mnt_free_table(mt); return 0; }