aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2011-08-25 15:46:13 +0200
committerDaniel Lezcano <daniel.lezcano@linaro.org>2011-08-25 15:46:13 +0200
commit25fc4a3e710aec3632a6f34a073427fe90b365a9 (patch)
treec59cf3e55966ae5e973655e70037aaa623acabd0
parentc80da0255e5d9e99da95b38d1c078887f6020e40 (diff)
downloadpowerdebugV2-25fc4a3e710aec3632a6f34a073427fe90b365a9.tar.gz
follow symlinks when browsing the directory tree
Sometime we are interested in following the symlinks, sometime not. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--clocks.c2
-rw-r--r--regulator.c2
-rw-r--r--sensor.c2
-rw-r--r--tree.c11
-rw-r--r--tree.h2
5 files changed, 10 insertions, 9 deletions
diff --git a/clocks.c b/clocks.c
index 20a245c..364c0af 100644
--- a/clocks.c
+++ b/clocks.c
@@ -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;
diff --git a/regulator.c b/regulator.c
index e9b01bb..55bd3e9 100644
--- a/regulator.c
+++ b/regulator.c
@@ -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;
diff --git a/sensor.c b/sensor.c
index e172f88..ff1e3dd 100644
--- a/sensor.c
+++ b/sensor.c
@@ -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;
diff --git a/tree.c b/tree.c
index aefe0fe..d331c60 100644
--- a/tree.c
+++ b/tree.c
@@ -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;
}
diff --git a/tree.h b/tree.h
index c7f3ca9..5c1c697 100644
--- a/tree.h
+++ b/tree.h
@@ -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);