mdev : bug corrected (patch attached)
Souf
souf_oued at yahoo.fr
Fri Jun 1 17:08:16 UTC 2007
Le vendredi 01 juin 2007 à 15:57 +0200, Bernhard Fischer a écrit :
> On Fri, Jun 01, 2007 at 03:15:10PM +0200, Renaud Cerrato wrote:
> >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;
>
> recursive_action() anyone?
I had already sent a large patch to improve mdev but it does not seem to
interest many people, in any case I resend it here, it uses:
xmalloc_getline()
last_char_is()
recursive_action()
bb_make_directory()
remove_file()
bb_get_last_path_component()
xmalloc_readlink_or_warn()
xmalloc_readlink_or_warn()
all that for only 5.9 KB
RFC:
http://busybox.net/lists/busybox/2007-May/027367.html
http://busybox.net/lists/busybox/2007-May/027515.html
Malek.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mdev.patch
Type: text/x-patch
Size: 10977 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20070601/e9b3423e/attachment-0002.bin
More information about the busybox
mailing list