From patchwork Thu Aug 25 13:47:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 3674 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0F55523F22 for ; Thu, 25 Aug 2011 13:47:08 +0000 (UTC) Received: from mail-gy0-f180.google.com (mail-gy0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id BCEF6A188C7 for ; Thu, 25 Aug 2011 13:47:07 +0000 (UTC) Received: by gyc15 with SMTP id 15so2498774gyc.11 for ; Thu, 25 Aug 2011 06:47:07 -0700 (PDT) Received: by 10.150.98.4 with SMTP id v4mr257311ybb.326.1314280027195; Thu, 25 Aug 2011 06:47:07 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.151.27.20 with SMTP id e20cs238186ybj; Thu, 25 Aug 2011 06:47:06 -0700 (PDT) Received: by 10.216.168.137 with SMTP id k9mr5808717wel.46.1314280025305; Thu, 25 Aug 2011 06:47:05 -0700 (PDT) Received: from mtagate2.uk.ibm.com (mtagate2.uk.ibm.com [194.196.100.162]) by mx.google.com with ESMTPS id j44si1602213wed.31.2011.08.25.06.47.02 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Aug 2011 06:47:05 -0700 (PDT) Received-SPF: neutral (google.com: 194.196.100.162 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=194.196.100.162; Authentication-Results: mx.google.com; spf=neutral (google.com: 194.196.100.162 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p7PDl20Q020690 for ; Thu, 25 Aug 2011 13:47:02 GMT Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p7PDl2M72109442 for ; Thu, 25 Aug 2011 14:47:02 +0100 Received: from d06av06.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p7PDl1CF003101 for ; Thu, 25 Aug 2011 07:47:01 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p7PDl1PN002886; Thu, 25 Aug 2011 07:47:01 -0600 Received: from localhost.localdomain (sig-9-145-110-19.uk.ibm.com [9.145.110.19]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id C2C8521101F; Thu, 25 Aug 2011 15:47:00 +0200 (CEST) From: Daniel Lezcano To: linaro-dev@lists.linaro.org Subject: [powerdebug 1/7] follow symlinks when browsing the directory tree Date: Thu, 25 Aug 2011 15:47:01 +0200 Message-Id: <1314280027-7547-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.4.1 Sometime we are interested in following the symlinks, sometime not. Signed-off-by: Daniel Lezcano --- clocks.c | 2 +- regulator.c | 2 +- sensor.c | 2 +- tree.c | 11 ++++++----- tree.h | 2 +- 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 #undef _GNU_SOURCE #include +#include #include #include #include @@ -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);