Skip to content

Commit

Permalink
perf tools: Allow to close dso fd in case of open failure
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jiri Olsa committed Jun 12, 2014
1 parent c3fbd2a commit a08cae0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tools/perf/util/dso.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ static void dso__list_del(struct dso *dso)
dso__data_open_cnt--;
}

static void close_first_dso(void);

static int do_open(char *name)
{
int fd;

do {
fd = open(name, O_RDONLY);
if (fd >= 0)
return fd;

pr_debug("dso open failed, mmap: %s\n", strerror(errno));
if (!dso__data_open_cnt || errno != EMFILE)
break;

close_first_dso();
} while (1);

return -1;
}

static int __open_dso(struct dso *dso, struct machine *machine)
{
int fd;
Expand All @@ -177,7 +198,7 @@ static int __open_dso(struct dso *dso, struct machine *machine)
return -EINVAL;
}

fd = open(name, O_RDONLY);
fd = do_open(name);
free(name);
return fd;
}
Expand Down

0 comments on commit a08cae0

Please sign in to comment.