Merge branch 'liuming50-fix-a-unmount-issue'

This commit is contained in:
Joachim Wiberg
2021-09-09 08:51:41 +02:00
+20 -14
View File
@@ -59,46 +59,52 @@ static int is_protected(char *dir)
return 0;
}
static struct mntent *iterator(char *fstab)
static void iterator_end(FILE **fp)
{
endmntent(*fp);
*fp = NULL;
}
static struct mntent *iterator(char *fstab, FILE **fp)
{
static FILE *fp = NULL;
static struct mntent *mnt;
if (!fp && fstab) {
fp = setmntent(fstab, "r");
if (!fp)
if (!*fp && fstab) {
*fp = setmntent(fstab, "r");
if (!*fp)
return NULL;
}
while ((mnt = getmntent(fp))) {
while ((mnt = getmntent(*fp))) {
if (is_protected(mnt->mnt_dir))
continue;
return mnt;
}
endmntent(fp);
fp = NULL;
iterator_end(fp);
return NULL;
}
void unmount_tmpfs(void)
{
struct mntent *mnt;
FILE *fp = NULL;
while ((mnt = iterator("/proc/mounts"))) {
if (!strcmp("tmpfs", mnt->mnt_fsname))
umount(mnt->mnt_dir);
while ((mnt = iterator("/proc/mounts", &fp))) {
if (!strcmp("tmpfs", mnt->mnt_fsname) && !umount(mnt->mnt_dir))
iterator_end(&fp); /* Restart iteration */
}
}
void unmount_regular(void)
{
struct mntent *mnt;
FILE *fp = NULL;
while ((mnt = iterator("/proc/mounts"))) {
umount(mnt->mnt_dir);
while ((mnt = iterator("/proc/mounts", &fp))) {
if (!umount(mnt->mnt_dir))
iterator_end(&fp); /* Restart iteration */
}
}