diff mbox series

[5/7] mount: options in config file shouldn't over-ride command-line options.

Message ID 160809378308.7232.5025347167008614005.stgit@noble (mailing list archive)
State New, archived
Headers show
Series Assorted improvements to handling nfsmount.conf | expand

Commit Message

NeilBrown Dec. 16, 2020, 4:43 a.m. UTC
When reading from the config file, we already ignore options that exist
on the command line, or that were already found earlier in the config
file.  However this only works for exact matches of options.

e.g. if "noac" is on the command line and "ac=true" is in the config file,
then "ac" will be added, and this will be used.

Add tests for the "no" prefix, and also for "fg" vs "bg", so that if
"fg" is set on the command line, a "bg" or "background" setting in the
config file does not over-ride it.

Note that this *doesn't* handle the different protocol version
specifiers.  That will come later.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 utils/mount/configfile.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/utils/mount/configfile.c b/utils/mount/configfile.c
index 8c68ff2c1323..40378ab247fc 100644
--- a/utils/mount/configfile.c
+++ b/utils/mount/configfile.c
@@ -204,6 +204,27 @@  conf_parse_mntopts(char *section, char *arg, struct mount_options *options)
 		field = mountopts_alias(node->field, &argtype);
 		if (po_contains(options, field) == PO_FOUND)
 			continue;
+		/* Some options can be inverted by a "no" prefix.
+		 * Check for these.
+		 * "no" prefixes are unlikely in the config file as
+		 * "option=false" is preferred, but still possible.
+		 */
+		if (strncmp(field, "no", 2) == 0 &&
+		    po_contains(options, field+2) == PO_FOUND)
+			continue;
+		if (strlen(field) < BUFSIZ-3) {
+			strcat(strcpy(buf, "no"), field);
+			if (po_contains(options, buf) == PO_FOUND)
+				continue;
+		}
+
+		/* If fg or bg already present, ignore bg or fg */
+		if (strcmp(field, "fg") == 0 &&
+		    po_contains(options, "bg") == PO_FOUND)
+			continue;
+		if (strcmp(field, "bg") == 0 &&
+		    po_contains(options, "fg") == PO_FOUND)
+			continue;
 
 		buf[0] = '\0';
 		value = conf_get_section(section, arg, node->field);