@@ -413,7 +413,7 @@ int clock_init(void)
if (access(clk_dir_path, F_OK))
return -1;
- clock_tree = tree_load(clk_dir_path, NULL);
+ clock_tree = tree_load(clk_dir_path, NULL, false);
if (!clock_tree)
return -1;
@@ -236,7 +236,7 @@ static struct display_ops regulator_ops = {
int regulator_init(void)
{
- reg_tree = tree_load(SYSFS_REGULATOR, regulator_filter_cb);
+ reg_tree = tree_load(SYSFS_REGULATOR, regulator_filter_cb, false);
if (!reg_tree)
return -1;
@@ -271,7 +271,7 @@ static struct display_ops sensor_ops = {
int sensor_init(void)
{
- sensor_tree = tree_load(SYSFS_SENSOR, sensor_filter_cb);
+ sensor_tree = tree_load(SYSFS_SENSOR, sensor_filter_cb, false);
if (!sensor_tree)
return -1;
@@ -17,6 +17,7 @@
#include <stdio.h>
#undef _GNU_SOURCE
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
@@ -111,7 +112,7 @@ static inline void tree_add_child(struct tree *parent, struct tree *child)
* @filter : a callback to filter out the directories
* Returns 0 on success, -1 otherwise
*/
-static int tree_scan(struct tree *tree, tree_filter_t filter)
+static int tree_scan(struct tree *tree, tree_filter_t filter, bool follow)
{
DIR *dir;
char *basedir, *newpath;
@@ -152,7 +153,7 @@ static int tree_scan(struct tree *tree, tree_filter_t filter)
if (ret)
goto out_free_newpath;
- if (S_ISDIR(s.st_mode)) {
+ if (S_ISDIR(s.st_mode) || (S_ISLNK(s.st_mode) && follow)) {
ret = -1;
@@ -164,7 +165,7 @@ static int tree_scan(struct tree *tree, tree_filter_t filter)
tree->nrchild++;
- ret = tree_scan(child, filter);
+ ret = tree_scan(child, filter, follow);
}
out_free_newpath:
@@ -190,7 +191,7 @@ static int tree_scan(struct tree *tree, tree_filter_t filter)
* Returns a tree structure corresponding to the root node of the
* directory tree representation on success, NULL otherwise
*/
-struct tree *tree_load(const char *path, tree_filter_t filter)
+struct tree *tree_load(const char *path, tree_filter_t filter, bool follow)
{
struct tree *tree;
@@ -198,7 +199,7 @@ struct tree *tree_load(const char *path, tree_filter_t filter)
if (!tree)
return NULL;
- if (tree_scan(tree, filter)) {
+ if (tree_scan(tree, filter, follow)) {
tree_free(tree);
return NULL;
}
@@ -41,7 +41,7 @@ typedef int (*tree_cb_t)(struct tree *t, void *data);
typedef int (*tree_filter_t)(const char *name);
-extern struct tree *tree_load(const char *path, tree_filter_t filter);
+extern struct tree *tree_load(const char *path, tree_filter_t filter, bool follow);
extern struct tree *tree_find(struct tree *tree, const char *name);
Sometime we are interested in following the symlinks, sometime not. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> --- clocks.c | 2 +- regulator.c | 2 +- sensor.c | 2 +- tree.c | 11 ++++++----- tree.h | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-)