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
This commit is contained in:
Ruslan Ermilov 2006-10-24 22:02:29 +00:00
parent 9f5cc52fb6
commit 3cbf527e8d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=163671

View File

@ -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: