Dear,
Using mdev, we noticed that some devices were not attached to /dev/ using
"mdev -s".
Looking at the source code, the function which walk through the /sys/ tree
make use of lstat, but the /sys tree can use symlink as seen here :
$ ls -l /sys/class/misc/
lrwxrwxrwx 1 root root 0 Jan 1 1970 watchdog ->
../../devices/platform/at91sam9x_wdt/watchdog
Doing so, the function can't walk through symbolic links. By replacing lstat
by stat, the problem is corrected.
To avoid infinite loop, we added a walking through depth limit to 2 (see
udevstart.c).
Cheers
diff -Nru busybox-1.4.1/util-linux/mdev.c busybox-1.4.1_modified/util-linux/mdev.c
--- busybox-1.4.1/util-linux/mdev.c 2007-01-24 22:34:51.000000000 +0100
+++ busybox-1.4.1_modified/util-linux/mdev.c 2007-06-01 14:47:07.013533464 +0200
@@ -14,6 +14,10 @@
#define DEV_PATH "/dev"
+#define MAX_DEPTH 3
+
+static int depth;
+
struct mdev_globals
{
int root_major, root_minor;
@@ -195,18 +199,22 @@
}
/* Recursive search of /sys/block or /sys/class. path must be a writeable
- * buffer of size PATH_MAX containing the directory string to start at. */
+ * buffer of size PATH_MAX containing the directory string to start at.
+ * The recursive depth is limited to avoid inifinite loop (circular symlinks)
+ */
static void find_dev(char *path)
{
DIR *dir;
size_t len = strlen(path);
struct dirent *entry;
-
+
dir = opendir(path);
if (dir == NULL)
return;
+ depth++;
+
while ((entry = readdir(dir)) != NULL) {
struct stat st;
@@ -215,10 +223,11 @@
if (entry->d_name[0] == '.')
continue;
- // uClibc doesn't fill out entry->d_type reliably. so we use lstat().
+ // uClibc doesn't fill out entry->d_type reliably. so we use stat().
snprintf(path+len, PATH_MAX-len, "/%s", entry->d_name);
- if (!lstat(path, &st) && S_ISDIR(st.st_mode)) find_dev(path);
+ if (!stat(path, &st) && S_ISDIR(st.st_mode)
+ && (depth<MAX_DEPTH)) find_dev(path);
path[len] = 0;
/* If there's a dev entry, mknod it */
@@ -227,6 +236,7 @@
}
closedir(dir);
+ depth--;
}
int mdev_main(int argc, char *argv[])
@@ -235,6 +245,8 @@
char *env_path;
RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
+ depth=0;
+
xchdir(DEV_PATH);
/* Scan */
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox