[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1253779628.10513.8.camel@marge.simson.net>
Date: Thu, 24 Sep 2009 10:07:08 +0200
From: Mike Galbraith <efault@....de>
To: Avi Kivity <avi@...hat.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>, rostedt@...dmis.org,
LKML <linux-kernel@...r.kernel.org>, Ingo Molnar <mingo@...e.hu>,
Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Frederic Weisbecker <fweisbec@...il.com>,
Thomas Gleixner <tglx@...utronix.de>,
Masami Hiramatsu <mhiramat@...hat.com>
Subject: Re: [patch] Re: [perf] Finding uninstalled modules Was Re: mailing
list for trace users
On Wed, 2009-09-23 at 18:09 +0300, Avi Kivity wrote:
> On 09/23/2009 06:05 PM, Mike Galbraith wrote:
> >
> > So, I just need to check whether it's full path or not, prepend or take
> > the path as is, and hope there aren't several other ways to get screwed
> > up by modules.dep content.
> >
>
> Maybe we should fix that then (though I prefer relative paths myself).
Ok, the below should (knock wood) handle your relative paths. May look
a little overly paranoid, but it's not... they _are_ out to get me ;-)
perf_counter tools: handle relative paths while loading module symbols.
Inform util/module.c::mod_dso__load_module_paths() that relative paths do exist
in some modules.dep, and make it fail noisily should it encounter a path that it
doesn't understand, or a module it cannot open.
Signed-off-by: Mike Galbraith <efault@....de>
Cc: Ingo Molnar <mingo@...e.hu>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Reported-by: Avi Kivity <avi@...hat.com>
LKML-Reference: <new-submission>
---
tools/perf/util/module.c | 100 +++++++++++++++++++++++++++++++----------------
1 file changed, 67 insertions(+), 33 deletions(-)
Index: linux-2.6/tools/perf/util/module.c
===================================================================
--- linux-2.6.orig/tools/perf/util/module.c
+++ linux-2.6/tools/perf/util/module.c
@@ -4,6 +4,7 @@
#include "module.h"
#include <libelf.h>
+#include <libgen.h>
#include <gelf.h>
#include <elf.h>
#include <dirent.h>
@@ -409,35 +410,40 @@ out_failure:
static int mod_dso__load_module_paths(struct mod_dso *self)
{
struct utsname uts;
- int count = 0, len;
+ int count = 0, len, err = -1;
char *line = NULL;
FILE *file;
- char *path;
+ char *dpath, *dir;
size_t n;
if (uname(&uts) < 0)
- goto out_failure;
+ return err;
len = strlen("/lib/modules/");
len += strlen(uts.release);
len += strlen("/modules.dep");
- path = calloc(1, len);
- if (path == NULL)
- goto out_failure;
-
- strcat(path, "/lib/modules/");
- strcat(path, uts.release);
- strcat(path, "/modules.dep");
+ dpath = calloc(1, len);
+ if (dpath == NULL)
+ return err;
+
+ strcat(dpath, "/lib/modules/");
+ strcat(dpath, uts.release);
+ strcat(dpath, "/modules.dep");
- file = fopen(path, "r");
- free(path);
+ file = fopen(dpath, "r");
if (file == NULL)
goto out_failure;
+ dir = dirname(dpath);
+ if (!dir)
+ goto out_failure;
+ strcat(dir, "/");
+
while (!feof(file)) {
- char *name, *tmp;
struct module *module;
+ char *name, *path, *tmp;
+ FILE *modfile;
int line_len;
line_len = getline(&line, &n, file);
@@ -445,44 +451,65 @@ static int mod_dso__load_module_paths(st
break;
if (!line)
- goto out_failure;
+ break;
line[--line_len] = '\0'; /* \n */
- path = strtok(line, ":");
+ path = strchr(line, ':');
if (!path)
- goto out_failure;
+ break;
+ *path = '\0';
- name = strdup(path);
- name = strtok(name, "/");
+ path = strdup(line);
+ if (!path)
+ break;
- tmp = name;
+ if (!strstr(path, dir)) {
+ if (strncmp(path, "kernel/", 7))
+ break;
+
+ free(path);
+ path = calloc(1, strlen(dir) + strlen(line) + 1);
+ if (!path)
+ break;
+ strcat(path, dir);
+ strcat(path, line);
+ }
+
+ modfile = fopen(path, "r");
+ if (modfile == NULL)
+ break;
+ fclose(modfile);
+
+ name = strdup(path);
+ if (!name)
+ break;
+ tmp = name = strtok(name, "/");
while (tmp) {
tmp = strtok(NULL, "/");
if (tmp)
name = tmp;
}
+
name = strsep(&name, ".");
+ if (!name)
+ break;
- /* Quirk: replace '-' with '_' in sound modules */
+ /* Quirk: replace '-' with '_' in all modules */
for (len = strlen(name); len; len--) {
if (*(name+len) == '-')
*(name+len) = '_';
}
module = module__new(name, path);
- if (!module) {
- fprintf(stderr, "load_module_paths: allocation error\n");
- goto out_failure;
- }
+ if (!module)
+ break;
mod_dso__insert_module(self, module);
module->sections = sec_dso__new_dso("sections");
- if (!module->sections) {
- fprintf(stderr, "load_module_paths: allocation error\n");
- goto out_failure;
- }
+ if (!module->sections)
+ break;
module->active = mod_dso__load_sections(module);
@@ -490,13 +517,20 @@ static int mod_dso__load_module_paths(st
count++;
}
- free(line);
- fclose(file);
-
- return count;
+ if(feof(file))
+ err = count;
+ else
+ fprintf(stderr, "load_module_paths: modules.dep parse failure!\n");
out_failure:
- return -1;
+ if (dpath)
+ free(dpath);
+ if (file)
+ fclose(file);
+ if (line)
+ free(line);
+
+ return err;
}
int mod_dso__load_modules(struct mod_dso *dso)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists