[git commit master 1/1] mount: pass NULL, not "", as "data" to mount syscall if we have no opts

Denys Vlasenko vda.linux at googlemail.com
Thu Oct 28 04:10:03 UTC 2010


commit: http://git.busybox.net/busybox/commit/?id=776509544123c68bbc128c0fdb2f699062d294cf
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

When mounting a filesystem without any additional options (data parameter
to the mount(2) syscall), pass NULL instead of an empty string like GNU
mount does. This fixes, for example mounting cgroup fs with bbox mount.

Signed-off-by: Alexander Shishkin <virtuoso at slind.org>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 util-linux/mount.c |   34 ++++++++++++++++++++++------------
 1 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/util-linux/mount.c b/util-linux/mount.c
index 3ac8ce0..0f213bb 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -332,7 +332,7 @@ static void append_mount_options(char **oldopts, const char *newopts)
 }
 
 // Use the mount_options list to parse options into flags.
-// Also return list of unrecognized options if unrecognized != NULL
+// Also update list of unrecognized options if unrecognized != NULL
 static long parse_mount_options(char *options, char **unrecognized)
 {
 	long flags = MS_SILENT;
@@ -348,25 +348,35 @@ static long parse_mount_options(char *options, char **unrecognized)
 // FIXME: use hasmntopt()
 		// Find this option in mount_options
 		for (i = 0; i < ARRAY_SIZE(mount_options); i++) {
-			if (!strcasecmp(option_str, options)) {
+			if (strcasecmp(option_str, options) == 0) {
 				long fl = mount_options[i];
-				if (fl < 0) flags &= fl;
-				else flags |= fl;
-				break;
+				if (fl < 0)
+					flags &= fl;
+				else
+					flags |= fl;
+				goto found;
 			}
 			option_str += strlen(option_str) + 1;
 		}
-		// If unrecognized not NULL, append unrecognized mount options
-		if (unrecognized && i == ARRAY_SIZE(mount_options)) {
+		// We did not recognize this option.
+		// If "unrecognized" is not NULL, append option there.
+		// Note that we should not append *empty* option -
+		// in this case we want to pass NULL, not "", to "data"
+		// parameter of mount(2) syscall.
+		// This is crucial for filesystems that don't accept
+		// any arbitrary mount options, like cgroup fs:
+		// "mount -t cgroup none /mnt"
+		if (options[0] && unrecognized) {
 			// Add it to strflags, to pass on to kernel
-			i = *unrecognized ? strlen(*unrecognized) : 0;
-			*unrecognized = xrealloc(*unrecognized, i + strlen(options) + 2);
+			char *p = *unrecognized;
+			unsigned len = p ? strlen(p) : 0;
+			*unrecognized = p = xrealloc(p, len + strlen(options) + 2);
 
 			// Comma separated if it's not the first one
-			if (i) (*unrecognized)[i++] = ',';
-			strcpy((*unrecognized)+i, options);
+			if (len) p[len++] = ',';
+			strcpy(p + len, options);
 		}
-
+ found:
 		if (!comma)
 			break;
 		// Advance to next option
-- 
1.7.1



More information about the busybox-cvs mailing list