summaryrefslogtreecommitdiff
path: root/umount.c
diff options
context:
space:
mode:
authorErik Andersen2000-01-26 20:06:48 +0000
committerErik Andersen2000-01-26 20:06:48 +0000
commit5cbdd712f5320ffc109053a94b7cf36c82292cf6 (patch)
tree77236e83cc0583411a75b752a6152d445eb680e0 /umount.c
parent3fe39dce5d1a0b0946878c66bbd7f694c5aa38ea (diff)
downloadbusybox-5cbdd712f5320ffc109053a94b7cf36c82292cf6.zip
busybox-5cbdd712f5320ffc109053a94b7cf36c82292cf6.tar.gz
mount and umount could leak loop device allocations causing the system to
quickly run out. Also disable init's SIGHUP handler during shutdown. -Erik
Diffstat (limited to 'umount.c')
-rw-r--r--umount.c70
1 files changed, 18 insertions, 52 deletions
diff --git a/umount.c b/umount.c
index 9ad6f26..68b27e3 100644
--- a/umount.c
+++ b/umount.c
@@ -28,14 +28,6 @@
#include <fstab.h>
#include <errno.h>
-#if defined BB_FEATURE_MOUNT_LOOP
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <linux/loop.h>
-
-static int del_loop(const char *device);
-#endif
-
static const char umount_usage[] =
"umount [flags] filesystem|directory\n\n"
"Flags:\n"
@@ -52,43 +44,34 @@ static int useMtab = TRUE;
static int umountAll = FALSE;
extern const char mtab_file[]; /* Defined in utility.c */
+#define MIN(x,y) (x > y ? x : y)
+
static int
do_umount(const char* name, int useMtab)
{
int status;
-
-#if defined BB_FEATURE_MOUNT_LOOP
- /* check to see if this is a loop device */
- struct stat fst;
- char dev[20];
- const char *oldname = NULL;
- int i;
-
- if (stat(name, &fst)) {
- fprintf(stderr, "umount: %s: %s\n", name, strerror(errno));
- exit(1);
- }
- for (i = 0 ; i <= 7 ; i++) {
- struct stat lst;
- sprintf(dev, "/dev/loop%d", i);
- if (stat(dev, &lst))
- continue;
- if (lst.st_dev == fst.st_dev) {
- oldname = name;
- name = dev;
- break;
+ struct mntent *m;
+ FILE *mountTable;
+ const char *blockDevice = NULL;
+
+ if ((mountTable = setmntent (mtab_file, "r"))) {
+ while ((m = getmntent (mountTable)) != 0) {
+ if (strncmp(m->mnt_dir, name,
+ MIN(strlen(m->mnt_dir),strlen(name))) == 0)
+ blockDevice = m->mnt_fsname;
+ else if (strcmp(m->mnt_fsname, name) == 0) {
+ blockDevice = name;
+ name = m->mnt_dir;
+ }
}
}
-#endif
status = umount(name);
#if defined BB_FEATURE_MOUNT_LOOP
- if (!strncmp("/dev/loop", name, 9)) { /* this was a loop device, delete it */
- del_loop(name);
- if (oldname != NULL)
- name = oldname;
- }
+ if (blockDevice != NULL && !strncmp("/dev/loop", blockDevice, 9))
+ /* this was a loop device, delete it */
+ del_loop(blockDevice);
#endif
#if defined BB_MTAB
if ( status == 0 ) {
@@ -178,20 +161,3 @@ umount_main(int argc, char** argv)
}
}
-#if defined BB_FEATURE_MOUNT_LOOP
-static int del_loop(const char *device)
-{
- int fd;
-
- if ((fd = open(device, O_RDONLY)) < 0) {
- perror(device);
- exit(1);
- }
- if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
- perror("ioctl: LOOP_CLR_FD");
- exit(1);
- }
- close(fd);
- return(0);
-}
-#endif