Make scanning of /dev work even if it is a symlink

We generally don't want to follow symlinks in /dev, but if
/dev itself is a symlink, we want to follow it.
So nftw needs a bit of help.

Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
Neil Brown 2006-03-27 06:54:31 +00:00
parent 06b0d78675
commit 0a416ec307
1 changed files with 8 additions and 1 deletions

9
util.c
View File

@ -384,6 +384,8 @@ int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s)
if ((stb->st_mode&S_IFMT)== S_IFBLK) {
char *n = strdup(name);
struct devmap *dm = malloc(sizeof(*dm));
if (strncmp(n, "/dev/.", 6)==0)
strcpy(n+4, name+6);
if (dm) {
dm->major = major(stb->st_rdev);
dm->minor = minor(stb->st_rdev);
@ -407,7 +409,12 @@ char *map_dev(int major, int minor)
struct devmap *p;
char *std = NULL, *nonstd=NULL;
if (!devlist_ready) {
nftw("/dev", add_dev, 10, FTW_PHYS);
char *dev = "/dev";
struct stat stb;
if (lstat(dev, &stb)==0 &&
S_ISLNK(stb.st_mode))
dev = "/dev/.";
nftw(dev, add_dev, 10, FTW_PHYS);
devlist_ready=1;
}