diff options
| author | Jiri Olsa <jolsa@kernel.org> | 2014-05-07 15:35:02 -0400 |
|---|---|---|
| committer | Jiri Olsa <jolsa@kernel.org> | 2014-06-12 10:53:21 -0400 |
| commit | a08cae03f430b971afa508a32662dc476d42d8cb (patch) | |
| tree | 3258591c03af54b3392fc3292baa194e63b45296 /tools | |
| parent | c3fbd2a606c5f88de0079b027727a1fb0ae27b65 (diff) | |
perf tools: Allow to close dso fd in case of open failure
Adding do_open function that tries to close opened
dso objects in case we fail to open the dso due to
to crossing the allowed RLIMIT_NOFILE limit.
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jean Pihet <jean.pihet@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1401892622-30848-9-git-send-email-jolsa@kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/util/dso.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index db634383156c..c30752c7eebb 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c | |||
| @@ -159,6 +159,27 @@ static void dso__list_del(struct dso *dso) | |||
| 159 | dso__data_open_cnt--; | 159 | dso__data_open_cnt--; |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | static void close_first_dso(void); | ||
| 163 | |||
| 164 | static int do_open(char *name) | ||
| 165 | { | ||
| 166 | int fd; | ||
| 167 | |||
| 168 | do { | ||
| 169 | fd = open(name, O_RDONLY); | ||
| 170 | if (fd >= 0) | ||
| 171 | return fd; | ||
| 172 | |||
| 173 | pr_debug("dso open failed, mmap: %s\n", strerror(errno)); | ||
| 174 | if (!dso__data_open_cnt || errno != EMFILE) | ||
| 175 | break; | ||
| 176 | |||
| 177 | close_first_dso(); | ||
| 178 | } while (1); | ||
| 179 | |||
| 180 | return -1; | ||
| 181 | } | ||
| 182 | |||
| 162 | static int __open_dso(struct dso *dso, struct machine *machine) | 183 | static int __open_dso(struct dso *dso, struct machine *machine) |
| 163 | { | 184 | { |
| 164 | int fd; | 185 | int fd; |
| @@ -177,7 +198,7 @@ static int __open_dso(struct dso *dso, struct machine *machine) | |||
| 177 | return -EINVAL; | 198 | return -EINVAL; |
| 178 | } | 199 | } |
| 179 | 200 | ||
| 180 | fd = open(name, O_RDONLY); | 201 | fd = do_open(name); |
| 181 | free(name); | 202 | free(name); |
| 182 | return fd; | 203 | return fd; |
| 183 | } | 204 | } |
