From: Nathan F. <nf...@au...> - 2009-07-16 16:17:11
|
When removing nodes from the device tree in /proc the recusrsive routine can fail with a bad pointer to the DIR struct. The DIR struct should be rewound after each remove to avoid this. Signed-off-by: Nathan Fontenot <nf...@au...> --- Index: powerpc-utils/src/drmgr/common.c =================================================================== --- powerpc-utils.orig/src/drmgr/common.c 2009-07-10 14:46:25.000000000 -0500 +++ powerpc-utils/src/drmgr/common.c 2009-07-16 15:32:19.000000000 -0500 @@ -427,6 +427,7 @@ DIR *d; struct dirent *de; struct stat sb; + int found = 1; int rc; rc = lstat(path, &sb); @@ -439,28 +440,39 @@ return -1; } - /* Remove any subdirectories */ - while ((de = readdir(d)) != NULL) { + while (found) { char subdir_name[DR_PATH_MAX]; - if (is_dot_dir(de->d_name)) - continue; + found = 0; - sprintf(subdir_name, "%s/%s", path, de->d_name); - rc = lstat(subdir_name, &sb); - if (!rc && (S_ISDIR(sb.st_mode)) && (! S_ISLNK(sb.st_mode))) + /* Remove any subdirectories */ + while ((de = readdir(d)) != NULL) { + if (is_dot_dir(de->d_name)) + continue; + + sprintf(subdir_name, "%s/%s", path, de->d_name); + rc = lstat(subdir_name, &sb); + if (!rc && (S_ISDIR(sb.st_mode)) + && (!S_ISLNK(sb.st_mode))) { + found = 1; + break; + } + } + + if (found) { rc = remove_device_tree_nodes(subdir_name); + rewinddir(d); + } if (rc) break; - } + } closedir(d); - if (rc) - return rc; + if (!rc) + rc = remove_node(path); - rc = remove_node(path); return rc; } |