ikent f4af6b
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
ikent f4af6b
index 0494e76..99961c3 100644
ikent f4af6b
--- a/modules/parse_sun.c
ikent f4af6b
+++ b/modules/parse_sun.c
ikent f4af6b
@@ -264,7 +264,7 @@ int parse_init(int argc, const char *const *argv, void **context)
ikent f4af6b
 {
ikent f4af6b
 	struct parse_context *ctxt;
ikent f4af6b
 	char buf[MAX_ERR_BUF];
ikent f4af6b
-	char *noptstr, *def, *val, *macros;
ikent f4af6b
+	char *noptstr, *def, *val, *macros, *gbl_options;
ikent f4af6b
 	const char *xopt;
ikent f4af6b
 	int optlen, len, offset;
ikent f4af6b
 	int i, bval;
ikent f4af6b
@@ -397,25 +397,31 @@ int parse_init(int argc, const char *const *argv, void **context)
ikent f4af6b
 		}
ikent f4af6b
 	}
ikent f4af6b
 
ikent f4af6b
+	gbl_options = NULL;
ikent f4af6b
 	if (global_options) {
ikent f4af6b
+		if (ctxt->optstr && strstr(ctxt->optstr, global_options))
ikent f4af6b
+			goto options_done;
ikent f4af6b
+		gbl_options = strdup(global_options);
ikent f4af6b
+	}
ikent f4af6b
+
ikent f4af6b
+	if (gbl_options) {
ikent f4af6b
 		append_options = defaults_get_append_options();
ikent f4af6b
 		if (append_options) {
ikent f4af6b
-			char *tmp = concat_options(global_options, ctxt->optstr);
ikent f4af6b
+			char *tmp = concat_options(gbl_options, ctxt->optstr);
ikent f4af6b
 			if (!tmp) {
ikent f4af6b
 				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
ikent f4af6b
 				error(LOGOPT_ANY, MODPREFIX "concat_options: %s", estr);
ikent f4af6b
+				free(gbl_options);
ikent f4af6b
 			} else
ikent f4af6b
 				ctxt->optstr = tmp;
ikent f4af6b
 		} else {
ikent f4af6b
 			if (!ctxt->optstr)
ikent f4af6b
-				ctxt->optstr = strdup(global_options);
ikent f4af6b
-			if (!ctxt->optstr) {
ikent f4af6b
-				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
ikent f4af6b
-				warn(LOGOPT_ANY, MODPREFIX "%s", estr);
ikent f4af6b
-			}
ikent f4af6b
+				ctxt->optstr = gbl_options;
ikent f4af6b
+			else
ikent f4af6b
+				free(gbl_options);
ikent f4af6b
 		}
ikent f4af6b
 	}
ikent f4af6b
-
ikent f4af6b
+options_done:
ikent f4af6b
 	debug(LOGOPT_NONE,
ikent f4af6b
 	      MODPREFIX "init gathered global options: %s", ctxt->optstr);
ikent f4af6b
 
ikent f4af6b
@@ -799,18 +805,23 @@ static int parse_mapent(const char *ent, char *g_options, char **options, char *
ikent f4af6b
 			char *tmp, *newopt = NULL;
ikent f4af6b
 
ikent f4af6b
 			p = parse_options(p, &newopt, logopt);
ikent f4af6b
-			tmp = concat_options(myoptions, newopt);
ikent f4af6b
-			if (!tmp) {
ikent f4af6b
-				char *estr;
ikent f4af6b
-				estr = strerror_r(errno, buf, MAX_ERR_BUF);
ikent f4af6b
-				error(logopt, MODPREFIX
ikent f4af6b
-				      "concat_options: %s", estr);
ikent f4af6b
-				if (newopt)
ikent f4af6b
-					free(newopt);
ikent f4af6b
+			if (newopt && strstr(newopt, myoptions)) {
ikent f4af6b
 				free(myoptions);
ikent f4af6b
-				return 0;
ikent f4af6b
+				myoptions = newopt;
ikent f4af6b
+			} else {
ikent f4af6b
+				tmp = concat_options(myoptions, newopt);
ikent f4af6b
+				if (!tmp) {
ikent f4af6b
+					char *estr;
ikent f4af6b
+					estr = strerror_r(errno, buf, MAX_ERR_BUF);
ikent f4af6b
+					error(logopt, MODPREFIX
ikent f4af6b
+					      "concat_options: %s", estr);
ikent f4af6b
+					if (newopt)
ikent f4af6b
+						free(newopt);
ikent f4af6b
+					free(myoptions);
ikent f4af6b
+					return 0;
ikent f4af6b
+				}
ikent f4af6b
+				myoptions = tmp;
ikent f4af6b
 			}
ikent f4af6b
-			myoptions = tmp;
ikent f4af6b
 
ikent f4af6b
 			p = skipspace(p);
ikent f4af6b
 		} while (*p == '-');
ikent f4af6b
@@ -1042,19 +1053,24 @@ int parse_mount(struct autofs_point *ap, const char *name,
ikent f4af6b
 			char *noptions = NULL;
ikent f4af6b
 
ikent f4af6b
 			p = parse_options(p, &noptions, ap->logopt);
ikent f4af6b
-			tmp = concat_options(mnt_options, noptions);
ikent f4af6b
-			if (!tmp) {
ikent f4af6b
-				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
ikent f4af6b
-				error(ap->logopt,
ikent f4af6b
-				      MODPREFIX "concat_options: %s", estr);
ikent f4af6b
-				if (noptions)
ikent f4af6b
-					free(noptions);
ikent f4af6b
-				if (mnt_options)
ikent f4af6b
-					free(mnt_options);
ikent f4af6b
-				free(options);
ikent f4af6b
-				return 1;
ikent f4af6b
+			if (mnt_options && noptions && strstr(noptions, mnt_options)) {
ikent f4af6b
+				free(mnt_options);
ikent f4af6b
+				mnt_options = noptions;
ikent f4af6b
+			} else {
ikent f4af6b
+				tmp = concat_options(mnt_options, noptions);
ikent f4af6b
+				if (!tmp) {
ikent f4af6b
+					char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
ikent f4af6b
+					error(ap->logopt,
ikent f4af6b
+					      MODPREFIX "concat_options: %s", estr);
ikent f4af6b
+					if (noptions)
ikent f4af6b
+						free(noptions);
ikent f4af6b
+					if (mnt_options)
ikent f4af6b
+						free(mnt_options);
ikent f4af6b
+					free(options);
ikent f4af6b
+					return 1;
ikent f4af6b
+				}
ikent f4af6b
+				mnt_options = tmp;
ikent f4af6b
 			}
ikent f4af6b
-			mnt_options = tmp;
ikent f4af6b
 
ikent f4af6b
 			p = skipspace(p);
ikent f4af6b
 		} while (*p == '-');
ikent f4af6b
@@ -1065,17 +1081,22 @@ int parse_mount(struct autofs_point *ap, const char *name,
ikent f4af6b
 		}
ikent f4af6b
 
ikent f4af6b
 		if (append_options) {
ikent f4af6b
-			tmp = concat_options(options, mnt_options);
ikent f4af6b
-			if (!tmp) {
ikent f4af6b
-				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
ikent f4af6b
-				error(ap->logopt, MODPREFIX "concat_options: %s", estr);
ikent f4af6b
-				if (options)
ikent f4af6b
-					free(options);
ikent f4af6b
-				if (mnt_options)
ikent f4af6b
-					free(mnt_options);
ikent f4af6b
-				return 1;
ikent f4af6b
+			if (options && mnt_options && strstr(mnt_options, options)) {
ikent f4af6b
+				free(options);
ikent f4af6b
+				options = mnt_options;
ikent f4af6b
+			} else {
ikent f4af6b
+				tmp = concat_options(options, mnt_options);
ikent f4af6b
+				if (!tmp) {
ikent f4af6b
+					char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
ikent f4af6b
+					error(ap->logopt, MODPREFIX "concat_options: %s", estr);
ikent f4af6b
+					if (options)
ikent f4af6b
+						free(options);
ikent f4af6b
+					if (mnt_options)
ikent f4af6b
+						free(mnt_options);
ikent f4af6b
+					return 1;
ikent f4af6b
+				}
ikent f4af6b
+				options = tmp;
ikent f4af6b
 			}
ikent f4af6b
-			options = tmp;
ikent f4af6b
 		} else
ikent f4af6b
 			options = mnt_options;
ikent f4af6b
 	}