diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-05 04:25:19 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-05 04:25:19 +0100 |
commit | a7329667b4c19fbe8ba077062f14a96038c094db (patch) | |
tree | d9a7b98355e92523c444345e397d97670d83dfd4 /util-linux/mount.c | |
parent | 14b0f4feb3648378acb5eba12c8fcd8fa291b231 (diff) | |
download | busybox-w32-a7329667b4c19fbe8ba077062f14a96038c094db.tar.gz busybox-w32-a7329667b4c19fbe8ba077062f14a96038c094db.tar.bz2 busybox-w32-a7329667b4c19fbe8ba077062f14a96038c094db.zip |
mount: prevent second mount -a from mounting everything again
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | util-linux/mount.c | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index d7ca7da37..c2b508e5b 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -1829,7 +1829,8 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1829 | llist_t *lst_o = NULL; | 1829 | llist_t *lst_o = NULL; |
1830 | const char *fstabname; | 1830 | const char *fstabname; |
1831 | FILE *fstab; | 1831 | FILE *fstab; |
1832 | int i, j, rc = 0; | 1832 | int i, j; |
1833 | int rc = EXIT_SUCCESS; | ||
1833 | unsigned opt; | 1834 | unsigned opt; |
1834 | struct mntent mtpair[2], *mtcur = mtpair; | 1835 | struct mntent mtpair[2], *mtcur = mtpair; |
1835 | IF_NOT_DESKTOP(const int nonroot = 0;) | 1836 | IF_NOT_DESKTOP(const int nonroot = 0;) |
@@ -1893,7 +1894,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1893 | mtpair->mnt_type = fstype; | 1894 | mtpair->mnt_type = fstype; |
1894 | mtpair->mnt_opts = cmdopts; | 1895 | mtpair->mnt_opts = cmdopts; |
1895 | resolve_mount_spec(&mtpair->mnt_fsname); | 1896 | resolve_mount_spec(&mtpair->mnt_fsname); |
1896 | rc = singlemount(mtpair, 0); | 1897 | rc = singlemount(mtpair, /*ignore_busy:*/ 0); |
1897 | return rc; | 1898 | return rc; |
1898 | } | 1899 | } |
1899 | storage_path = bb_simplify_path(argv[0]); // malloced | 1900 | storage_path = bb_simplify_path(argv[0]); // malloced |
@@ -1949,10 +1950,13 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1949 | if (argv[0]) { | 1950 | if (argv[0]) { |
1950 | 1951 | ||
1951 | // Is this what we're looking for? | 1952 | // Is this what we're looking for? |
1952 | if (strcmp(argv[0], mtcur->mnt_fsname) && | 1953 | if (strcmp(argv[0], mtcur->mnt_fsname) != 0 |
1953 | strcmp(storage_path, mtcur->mnt_fsname) && | 1954 | && strcmp(storage_path, mtcur->mnt_fsname) != 0 |
1954 | strcmp(argv[0], mtcur->mnt_dir) && | 1955 | && strcmp(argv[0], mtcur->mnt_dir) != 0 |
1955 | strcmp(storage_path, mtcur->mnt_dir)) continue; | 1956 | && strcmp(storage_path, mtcur->mnt_dir) != 0 |
1957 | ) { | ||
1958 | continue; // no | ||
1959 | } | ||
1956 | 1960 | ||
1957 | // Remember this entry. Something later may have | 1961 | // Remember this entry. Something later may have |
1958 | // overmounted it, and we want the _last_ match. | 1962 | // overmounted it, and we want the _last_ match. |
@@ -1960,6 +1964,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1960 | 1964 | ||
1961 | // If we're mounting all | 1965 | // If we're mounting all |
1962 | } else { | 1966 | } else { |
1967 | struct mntent *mp; | ||
1963 | // No, mount -a won't mount anything, | 1968 | // No, mount -a won't mount anything, |
1964 | // even user mounts, for mere humans | 1969 | // even user mounts, for mere humans |
1965 | if (nonroot) | 1970 | if (nonroot) |
@@ -1969,7 +1974,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1969 | if (!match_fstype(mtcur, fstype)) | 1974 | if (!match_fstype(mtcur, fstype)) |
1970 | continue; | 1975 | continue; |
1971 | 1976 | ||
1972 | // Skip noauto and swap anyway. | 1977 | // Skip noauto and swap anyway |
1973 | if ((parse_mount_options(mtcur->mnt_opts, NULL) & (MOUNT_NOAUTO | MOUNT_SWAP)) | 1978 | if ((parse_mount_options(mtcur->mnt_opts, NULL) & (MOUNT_NOAUTO | MOUNT_SWAP)) |
1974 | // swap is bogus "fstype", parse_mount_options can't check fstypes | 1979 | // swap is bogus "fstype", parse_mount_options can't check fstypes |
1975 | || strcasecmp(mtcur->mnt_type, "swap") == 0 | 1980 | || strcasecmp(mtcur->mnt_type, "swap") == 0 |
@@ -1987,10 +1992,23 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1987 | // NFS mounts want this to be xrealloc-able | 1992 | // NFS mounts want this to be xrealloc-able |
1988 | mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); | 1993 | mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); |
1989 | 1994 | ||
1990 | // Mount this thing | 1995 | // If nothing is mounted on this directory... |
1991 | if (singlemount(mtcur, 1)) { | 1996 | // (otherwise repeated "mount -a" mounts everything again) |
1992 | // Count number of failed mounts | 1997 | mp = find_mount_point(mtcur->mnt_dir, /*subdir_too:*/ 0); |
1993 | rc++; | 1998 | // We do not check fsname match of found mount point - |
1999 | // "/" may have fsname of "/dev/root" while fstab | ||
2000 | // says "/dev/something_else". | ||
2001 | if (mp) { | ||
2002 | bb_error_msg("according to %s, " | ||
2003 | "%s is already mounted on %s", | ||
2004 | bb_path_mtab_file, | ||
2005 | mp->mnt_fsname, mp->mnt_dir); | ||
2006 | } else { | ||
2007 | // ...mount this thing | ||
2008 | if (singlemount(mtcur, /*ignore_busy:*/ 1)) { | ||
2009 | // Count number of failed mounts | ||
2010 | rc++; | ||
2011 | } | ||
1994 | } | 2012 | } |
1995 | free(mtcur->mnt_opts); | 2013 | free(mtcur->mnt_opts); |
1996 | } | 2014 | } |
@@ -1998,7 +2016,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
1998 | 2016 | ||
1999 | // End of fstab/mtab is reached. | 2017 | // End of fstab/mtab is reached. |
2000 | // Were we looking for something specific? | 2018 | // Were we looking for something specific? |
2001 | if (argv[0]) { | 2019 | if (argv[0]) { // yes |
2002 | long l; | 2020 | long l; |
2003 | 2021 | ||
2004 | // If we didn't find anything, complain | 2022 | // If we didn't find anything, complain |
@@ -2031,13 +2049,24 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
2031 | bb_error_msg_and_die(bb_msg_you_must_be_root); | 2049 | bb_error_msg_and_die(bb_msg_you_must_be_root); |
2032 | } | 2050 | } |
2033 | 2051 | ||
2034 | // Mount the last thing we found | 2052 | //util-linux-2.12 does not do this check. |
2035 | mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); | 2053 | //// If nothing is mounted on this directory... |
2036 | append_mount_options(&(mtcur->mnt_opts), cmdopts); | 2054 | //// (otherwise repeated "mount FOO" mounts FOO again) |
2037 | resolve_mount_spec(&mtpair->mnt_fsname); | 2055 | //mp = find_mount_point(mtcur->mnt_dir, /*subdir_too:*/ 0); |
2038 | rc = singlemount(mtcur, 0); | 2056 | //if (mp) { |
2039 | if (ENABLE_FEATURE_CLEAN_UP) | 2057 | // bb_error_msg("according to %s, " |
2040 | free(mtcur->mnt_opts); | 2058 | // "%s is already mounted on %s", |
2059 | // bb_path_mtab_file, | ||
2060 | // mp->mnt_fsname, mp->mnt_dir); | ||
2061 | //} else { | ||
2062 | // ...mount the last thing we found | ||
2063 | mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); | ||
2064 | append_mount_options(&(mtcur->mnt_opts), cmdopts); | ||
2065 | resolve_mount_spec(&mtpair->mnt_fsname); | ||
2066 | rc = singlemount(mtcur, /*ignore_busy:*/ 0); | ||
2067 | if (ENABLE_FEATURE_CLEAN_UP) | ||
2068 | free(mtcur->mnt_opts); | ||
2069 | //} | ||
2041 | } | 2070 | } |
2042 | 2071 | ||
2043 | //ret: | 2072 | //ret: |
@@ -2047,5 +2076,15 @@ int mount_main(int argc UNUSED_PARAM, char **argv) | |||
2047 | free(storage_path); | 2076 | free(storage_path); |
2048 | free(cmdopts); | 2077 | free(cmdopts); |
2049 | } | 2078 | } |
2079 | |||
2080 | //TODO: exitcode should be ORed mask of (from "man mount"): | ||
2081 | // 0 success | ||
2082 | // 1 incorrect invocation or permissions | ||
2083 | // 2 system error (out of memory, cannot fork, no more loop devices) | ||
2084 | // 4 internal mount bug or missing nfs support in mount | ||
2085 | // 8 user interrupt | ||
2086 | //16 problems writing or locking /etc/mtab | ||
2087 | //32 mount failure | ||
2088 | //64 some mount succeeded | ||
2050 | return rc; | 2089 | return rc; |
2051 | } | 2090 | } |