mount: fix "duplicate mount options in mtab" bug
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 17 Sep 2006 15:08:12 +0000 (15:08 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 17 Sep 2006 15:08:12 +0000 (15:08 -0000)
util-linux/mount.c

index 57d2d04308781cfe8f8cf169fc1865ba28d824dd..430ec9bacfa1affc4b62cd74947743ae6e892bfc 100644 (file)
@@ -102,9 +102,27 @@ struct {
 static void append_mount_options(char **oldopts, char *newopts)
 {
        if (*oldopts && **oldopts) {
-               char *temp = xasprintf("%s,%s",*oldopts,newopts);
-               free(*oldopts);
-               *oldopts = temp;
+               /* do not insert options which are already there */
+               while (newopts[0]) {
+                       char *p;
+                       int len = strlen(newopts);
+                       p = strchr(newopts, ',');
+                       if (p) len = p - newopts;
+                       p = *oldopts;
+                       while (1) {
+                               if (!strncmp(p,newopts,len) && (p[len]==',' || p[len]==0))
+                                       goto skip;
+                               p = strchr(p,',');
+                               if(!p) break;
+                               p++;
+                       }
+                       p = xasprintf("%s,%.*s", *oldopts, len, newopts);
+                       free(*oldopts);
+                       *oldopts = p;
+skip:
+                       newopts += len;
+                       while (newopts[0] == ',') newopts++;
+               }
        } else {
                if (ENABLE_FEATURE_CLEAN_UP) free(*oldopts);
                *oldopts = xstrdup(newopts);