aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@free.fr>2011-03-26 22:06:08 +0100
committerAmit Kucheria <amit.kucheria@linaro.org>2011-04-04 02:53:32 +0300
commit9dc3fb39e45c336cd3e22ab902f362a36f3ae509 (patch)
tree164274a048a5c2acfc3740649e8320bb3fc20bfa
parent6e0c9c87cf38301f8dbf0b0f1ec9bf97dcb5fff6 (diff)
downloadpowerdebug-9dc3fb39e45c336cd3e22ab902f362a36f3ae509.tar.gz
change debugfs finder function
Change the debugfs_locate_mpoint function to be nicer and more efficient. Another effect is that fixes a segmentation fault when calling powerdebug --dump Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
-rw-r--r--clocks.c68
-rw-r--r--clocks.h7
-rw-r--r--powerdebug.h1
3 files changed, 30 insertions, 46 deletions
diff --git a/clocks.c b/clocks.c
index c42f589..ff79235 100644
--- a/clocks.c
+++ b/clocks.c
@@ -13,6 +13,9 @@
* - initial API and implementation
*******************************************************************************/
+#include <stdio.h>
+#include <mntent.h>
+
#include "powerdebug.h"
#include "clocks.h"
@@ -20,14 +23,36 @@ static char clk_dir_path[PATH_MAX];
static char clk_name[NAME_MAX];
static int bold[MAX_LINES];
+static int locate_debugfs(char *clk_path)
+{
+ const char *mtab = "/proc/mounts";
+ struct mntent *mntent;
+ int ret = -1;
+ FILE *file = NULL;
+
+ file = setmntent(mtab, "r");
+ if (!file)
+ return -1;
+
+ while ((mntent = getmntent(file))) {
+
+ if (strcmp(mntent->mnt_type, "debugfs"))
+ continue;
+
+ strcpy(clk_path, mntent->mnt_dir);
+ ret = 0;
+ break;
+ }
+
+ fclose(file);
+ return ret;
+}
+
int init_clock_details(bool dump, int selectedwindow)
{
- char *path = debugfs_locate_mpoint();
struct stat buf;
- if (path)
- strcpy(clk_dir_path, path);
- else {
+ if (locate_debugfs(clk_dir_path)) {
if (!dump) {
create_selectedwindow(selectedwindow);
sprintf(clock_lines[0], "Unable to locate debugfs "
@@ -43,6 +68,7 @@ int init_clock_details(bool dump, int selectedwindow)
exit(1);
}
}
+
sprintf(clk_dir_path, "%s/clock", clk_dir_path);
//strcpy(clk_dir_path, "/debug/clock"); // Hardcoded for testing..
if (stat(clk_dir_path, &buf)) {
@@ -539,37 +565,3 @@ void dump_clock_info(struct clock_info *clk, int level, int bmp)
}
}
}
-
-char *debugfs_locate_mpoint(void)
-{
- int ret;
- FILE *filep;
- char **path;
- char fsname[64];
- struct statfs sfs;
-
- path = likely_mpoints;
- while (*path) {
- ret = statfs(*path, &sfs);
- if (ret >= 0 && sfs.f_type == (long)DEBUGFS_MAGIC)
- return *path;
- path++;
- }
-
- filep = fopen("/proc/mounts", "r");
- if (filep == NULL) {
- fprintf(stderr, "powerdebug: Error opening /proc/mounts.");
- exit(1);
- }
-
- while (fscanf(filep, "%*s %s %s %*s %*d %*d\n",
- debugfs_mntpoint, fsname) == 2)
- if (!strcmp(fsname, "debugfs"))
- break;
- fclose(filep);
-
- if (strcmp(fsname, "debugfs"))
- return NULL;
-
- return debugfs_mntpoint;
-}
diff --git a/clocks.h b/clocks.h
index 4b176d0..dd9216a 100644
--- a/clocks.h
+++ b/clocks.h
@@ -36,17 +36,10 @@ struct clock_info {
struct clock_info **children;
} *clocks_info;
-char debugfs_mntpoint[1024];
char clock_lines[MAX_LINES][128];
int clock_line_no;
int old_clock_line_no;
-char *likely_mpoints[] = {
- "/sys/kernel/debug",
- "/debug",
- NULL
-};
-
void add_clock_details_recur(struct clock_info *clk, int hrow, int selected);
void destroy_clocks_info(void);
void destroy_clocks_info_recur(struct clock_info *clock);
diff --git a/powerdebug.h b/powerdebug.h
index d2bd4ec..f424c1f 100644
--- a/powerdebug.h
+++ b/powerdebug.h
@@ -42,7 +42,6 @@ extern void print_string_val(char *name, char *val);
extern int init_clock_details(bool dump, int selectedwindow);
extern void print_clock_header(void);
extern void print_one_clock(int line, char *str, int bold, int highlight);
-extern char *debugfs_locate_mpoint(void);
extern void get_sensor_info(char *path, char *name, char *sensor, int verbose);
extern int read_and_print_sensor_info(int verbose);