implemented numeric sort (sort -g)
[oweals/busybox.git] / umount.c
index e749c5f0feceaab74676e8d183c6dbb863062978..ab76be4da35db8245c4bfca67102dbc8dd6092b7 100644 (file)
--- a/umount.c
+++ b/umount.c
@@ -29,8 +29,8 @@
 #include <errno.h>
 
 static const char umount_usage[] = 
-"Usage: umount [flags] filesystem|directory\n"
-"Optional Flags:\n"
+"Usage: umount [flags] filesystem|directory\n\n"
+"Flags:\n"
 "\t-a:\tUnmount all file systems"
 #ifdef BB_MTAB
 " in /etc/mtab\n\t-n:\tDon't erase /etc/mtab entries\n"
@@ -73,9 +73,18 @@ umount_all(int useMtab)
             while ((m = getmntent (mountTable)) != 0) {
                 char *blockDevice = m->mnt_fsname;
 #if ! defined BB_MTAB
-                if (strcmp (blockDevice, "/dev/root") == 0)
-                    blockDevice = (getfsfile ("/"))->fs_spec;
+               if (strcmp (blockDevice, "/dev/root") == 0) {
+                   struct fstab* fstabItem;
+                   fstabItem = getfsfile ("/");
+                   if (fstabItem != NULL) {
+                       blockDevice = fstabItem->fs_spec;
+                   }
+               }
 #endif
+               /* Don't umount /proc when doing umount -a */
+                if (strcmp (blockDevice, "proc") == 0)
+                   continue;
+
                status=do_umount (m->mnt_dir, useMtab);
                if (status!=0) {
                    /* Don't bother retrying the umount on busy devices */
@@ -83,9 +92,6 @@ umount_all(int useMtab)
                        perror(m->mnt_dir); 
                        continue;
                    }
-                   printf ("Trying to umount %s failed: %s\n", 
-                           m->mnt_dir, strerror(errno)); 
-                   printf ("Instead trying to umount %s\n", blockDevice); 
                    status=do_umount (blockDevice, useMtab);
                    if (status!=0) {
                        printf ("Couldn't umount %s on %s (type %s): %s\n", 
@@ -101,13 +107,12 @@ umount_all(int useMtab)
 extern int
 umount_main(int argc, char** argv)
 {
-
     if (argc < 2) {
        usage( umount_usage); 
     }
 
     /* Parse any options */
-    while (argc-- > 0 && **(++argv) == '-') {
+    while (--argc > 0 && **(++argv) == '-') {
        while (*++(*argv)) switch (**argv) {
            case 'a':
                umountAll = TRUE;
@@ -123,7 +128,7 @@ umount_main(int argc, char** argv)
     }
 
 
-    if(umountAll) {
+    if(umountAll==TRUE) {
        exit(umount_all(useMtab));
     }
     if ( do_umount(*argv,useMtab) == 0 )