From f5d15b9ea0fd7d28cc86f95efbb4c1d0b1c7a7a1 Mon Sep 17 00:00:00 2001 From: ru Date: Tue, 24 Oct 2006 22:02:29 +0000 Subject: Revert rev. 1.86 by jmallett@ as it breaks "ro" mounts specified in /etc/fstab. This has been happening due to the priority inversion; options specified on the command line should take precedence over options from fstab over default "noro" option, but since both the default "noro" and options specified on the command line (-w, -r, -o ...) were put into the same "options" variable, "noro" took precedence over fstab "ro" (this is easily visible with "mount -d"). PR: bin/100164 --- sbin/mount/mount.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'sbin/mount') diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index 3d25b7b..a51e171 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -183,6 +183,26 @@ exec_mountprog(const char *name, const char *execname, char *const argv[]) return (0); } +static +int specified_ro(const char *arg) +{ + char *optbuf, *opt; + int ret = 0; + + optbuf = strdup(arg); + if (optbuf == NULL) + err(1, NULL); + + for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { + if (strcmp(opt, "ro") == 0) { + ret = 1; + break; + } + } + free(optbuf); + return (ret); +} + int main(int argc, char *argv[]) { @@ -191,14 +211,12 @@ main(int argc, char *argv[]) struct statfs *mntbuf; FILE *mountdfp; pid_t pid; - int all, ch, i, init_flags, late, mntsize, rval, have_fstab; + int all, ch, i, init_flags, late, mntsize, rval, have_fstab, ro; char *cp, *ep, *options; - options = strdup("noro"); - if (options == NULL) - errx(1, "malloc failed"); - all = init_flags = late = 0; + ro = 0; + options = NULL; vfslist = NULL; vfstype = "ufs"; while ((ch = getopt(argc, argv, "adlF:fo:prwt:uv")) != -1) @@ -219,7 +237,11 @@ main(int argc, char *argv[]) late = 1; break; case 'o': - options = catopt(options, optarg); + if (*optarg) { + options = catopt(options, optarg); + if (specified_ro(optarg)) + ro = 1; + } break; case 'p': fstab_style = 1; @@ -227,6 +249,7 @@ main(int argc, char *argv[]) break; case 'r': options = catopt(options, "ro"); + ro = 1; break; case 't': if (vfslist != NULL) @@ -255,6 +278,9 @@ main(int argc, char *argv[]) (strcmp(type, FSTAB_RO) && \ strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ)) + if ((init_flags & MNT_UPDATE) && (ro == 0)) + options = catopt(options, "noro"); + rval = 0; switch (argc) { case 0: -- cgit v1.1