Hi,

The attached patch remedies the problem.

John Holland

___________________________________________

Cellent Finance Solutions AG

Firmensitz: Calwer Straße 33, 70173 Stuttgart
Registergericht: Amtsgericht Stuttgart, HRB 720743
Vorstand: Thomas Wild
Vorsitzender des Aufsichtsrats: Rudolf Zipf
Index: util-linux/mdev.c
===================================================================
--- util-linux/mdev.c	(revision 22793)
+++ util-linux/mdev.c	(working copy)
@@ -35,6 +35,30 @@
 	return s;
 }
 
+/* builds an alias path
+ * This function potentionally reallocates the alias parameter.
+ */
+static char *build_alias(char *alias, const char *device_name)
+{
+	char *dest;
+
+	/* ">bar/": rename to bar/device_name */
+	/* ">bar[/]baz": rename to bar[/]baz */
+	dest = strrchr(alias, '/');
+	if (dest) { /* ">bar/[baz]" ? */
+		*dest = '\0'; /* mkdir bar */
+		bb_make_directory(alias, 0755, FILEUTILS_RECUR);
+		*dest = '/';
+		if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
+			dest = alias;
+			alias = concat_path_file(alias, device_name);
+			free(dest);
+		}
+	}
+
+	return alias;
+}
+
 /* mknod in /dev based on a path like "/sys/block/hda/hda1" */
 /* NB: "mdev -s" may call us many times, do not leak memory/fds! */
 static void make_device(char *path, int delete)
@@ -257,22 +281,8 @@
 			chown(device_name, uid, gid);
 
 			if (ENABLE_FEATURE_MDEV_RENAME && alias) {
-				char *dest;
+				alias = build_alias(alias, device_name);
 
-				/* ">bar/": rename to bar/device_name */
-				/* ">bar[/]baz": rename to bar[/]baz */
-				dest = strrchr(alias, '/');
-				if (dest) { /* ">bar/[baz]" ? */
-					*dest = '\0'; /* mkdir bar */
-					bb_make_directory(alias, 0755, FILEUTILS_RECUR);
-					*dest = '/';
-					if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
-						dest = alias;
-						alias = concat_path_file(alias, device_name);
-						free(dest);
-					}
-				}
-
 				/* move the device, and optionally
 				 * make a symlink to moved device node */
 				if (rename(device_name, alias) == 0 && aliaslink == '>')
@@ -295,8 +305,14 @@
 		free(command);
 	}
 
-	if (delete)
+	if (delete) {
 		unlink(device_name);
+		if (ENABLE_FEATURE_MDEV_RENAME && alias) {
+			alias = build_alias(alias, device_name);
+			unlink(alias);
+			free(alias);
+		}
+	}
 }
 
 /* File callback for /sys/ traversal */
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to