mount: change mounted() check - ubase - suckless linux base utils | |
git clone git://git.suckless.org/ubase | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 710081b07abac0f2f8c9a5502e93c24384b98959 | |
parent a248370eb6b11330426bb6e91515d08b031924bc | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Fri, 20 Feb 2015 16:16:55 +0100 | |
mount: change mounted() check | |
- use getmntent_r instead of getmntent: because getmntent was nested it | |
overwrote the previous internal mntent structure. | |
- check mounted() first, if not try to mount: this also makes sure filesystems | |
were not mounted multiple times (like tmpfs) and errno is not overwritten in | |
mounted(). For this reason also mount() errno EBUSY can't be used (tested). | |
Diffstat: | |
M mount.c | 26 ++++++++++++++------------ | |
1 file changed, 14 insertions(+), 12 deletions(-) | |
--- | |
diff --git a/mount.c b/mount.c | |
@@ -74,20 +74,21 @@ static int | |
mounted(const char *dir) | |
{ | |
FILE *fp; | |
- struct mntent *me; | |
+ struct mntent *me, mebuf; | |
struct stat st1, st2; | |
+ char linebuf[256]; | |
if (stat(dir, &st1) < 0) { | |
- weprintf("stat %s:", dir); | |
- return 0; | |
+ weprintf("stat %s:", dir); | |
+ return 0; | |
} | |
- fp = setmntent("/proc/mounts", "r"); | |
- if (!fp) | |
+ if (!(fp = setmntent("/proc/mounts", "r"))) | |
eprintf("setmntent %s:", "/proc/mounts"); | |
- while ((me = getmntent(fp)) != NULL) { | |
+ | |
+ while ((me = getmntent_r(fp, &mebuf, linebuf, sizeof(linebuf)))) { | |
if (stat(me->mnt_dir, &st2) < 0) { | |
- weprintf("stat %s:", me->mnt_dir); | |
- continue; | |
+ weprintf("stat %s:", me->mnt_dir); | |
+ continue; | |
} | |
if (st1.st_dev == st2.st_dev && | |
st1.st_ino == st2.st_ino) | |
@@ -224,13 +225,14 @@ mountall: | |
if (!(fp = setmntent("/etc/fstab", "r"))) | |
eprintf("setmntent %s:", "/etc/fstab"); | |
while ((me = getmntent(fp))) { | |
+ /* already mounted, skip */ | |
+ if (mounted(me->mnt_dir)) | |
+ continue; | |
flags = 0; | |
parseopts(me->mnt_opts, &flags, data, datasiz); | |
if (mount(me->mnt_fsname, me->mnt_dir, me->mnt_type, flags, da… | |
- if (mounted(me->mnt_dir) == 0) { | |
- weprintf("mount: %s:", me->mnt_fsname); | |
- status = 1; | |
- } | |
+ weprintf("mount: %s:", me->mnt_fsname); | |
+ status = 1; | |
} | |
} | |
endmntent(fp); |