From 9dc3fb39e45c336cd3e22ab902f362a36f3ae509 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Sat, 26 Mar 2011 22:06:08 +0100 Subject: 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 Signed-off-by: Amit Kucheria --- clocks.c | 68 ++++++++++++++++++++++++++++------------------------------------ 1 file changed, 30 insertions(+), 38 deletions(-) (limited to 'clocks.c') 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 +#include + #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; -} -- cgit v1.2.1