mirror of
https://github.com/troglobit/finit.git
synced 2026-10-24 11:54:36 +00:00
Merge branch 'liuming50-fix-a-unmount-issue'
This commit is contained in:
commit
c71102f44e
1 file changed
+20
-14
+20
-14
@@ -59,46 +59,52 @@ static int is_protected(char *dir)
|
|||||||
return 0;
|
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;
|
static struct mntent *mnt;
|
||||||
|
|
||||||
if (!fp && fstab) {
|
if (!*fp && fstab) {
|
||||||
fp = setmntent(fstab, "r");
|
*fp = setmntent(fstab, "r");
|
||||||
if (!fp)
|
if (!*fp)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((mnt = getmntent(fp))) {
|
while ((mnt = getmntent(*fp))) {
|
||||||
if (is_protected(mnt->mnt_dir))
|
if (is_protected(mnt->mnt_dir))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return mnt;
|
return mnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
endmntent(fp);
|
iterator_end(fp);
|
||||||
fp = NULL;
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unmount_tmpfs(void)
|
void unmount_tmpfs(void)
|
||||||
{
|
{
|
||||||
struct mntent *mnt;
|
struct mntent *mnt;
|
||||||
|
FILE *fp = NULL;
|
||||||
|
|
||||||
while ((mnt = iterator("/proc/mounts"))) {
|
while ((mnt = iterator("/proc/mounts", &fp))) {
|
||||||
if (!strcmp("tmpfs", mnt->mnt_fsname))
|
if (!strcmp("tmpfs", mnt->mnt_fsname) && !umount(mnt->mnt_dir))
|
||||||
umount(mnt->mnt_dir);
|
iterator_end(&fp); /* Restart iteration */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unmount_regular(void)
|
void unmount_regular(void)
|
||||||
{
|
{
|
||||||
struct mntent *mnt;
|
struct mntent *mnt;
|
||||||
|
FILE *fp = NULL;
|
||||||
|
|
||||||
while ((mnt = iterator("/proc/mounts"))) {
|
while ((mnt = iterator("/proc/mounts", &fp))) {
|
||||||
umount(mnt->mnt_dir);
|
if (!umount(mnt->mnt_dir))
|
||||||
|
iterator_end(&fp); /* Restart iteration */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user