[PATCH 12/13] perf tools: replace on_exit with atexit

From: Irina Tirdea
Date: Tue Aug 28 2012 - 18:07:04 EST


on_exit() is only available in new versions of glibc.
Using on_exit on Android leads to errors at compile time.

Replacing on_exit with its more portable version atexit.
This leads to using a global variable since on_exit supports
sending a parameters while atexit does not.

Signed-off-by: Irina Tirdea <irina.tirdea@xxxxxxxxx>
---
tools/perf/builtin-record.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3fc9bf9..f5daedf 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -66,6 +66,9 @@ struct perf_record {
off_t post_processing_offset;
};

+/* for atexit */
+static struct perf_record *saved_rec;
+
static void advance_output(struct perf_record *rec, size_t size)
{
rec->bytes_written += size;
@@ -143,9 +146,9 @@ static void sig_handler(int sig)
signr = sig;
}

-static void perf_record__sig_exit(int exit_status __maybe_unused, void *arg)
+static void perf_record__sig_exit(void)
{
- struct perf_record *rec = arg;
+ struct perf_record *rec = saved_rec;
int status;

if (rec->evlist->workload.pid > 0) {
@@ -335,9 +338,9 @@ static int process_buildids(struct perf_record *rec)
size, &build_id__mark_dso_hit_ops);
}

-static void perf_record__exit(int status __maybe_unused, void *arg)
+static void perf_record__exit(void)
{
- struct perf_record *rec = arg;
+ struct perf_record *rec = saved_rec;

if (!rec->opts.pipe_output) {
rec->session->header.data_size += rec->bytes_written;
@@ -424,7 +427,8 @@ static int __cmd_record(struct perf_record *rec,
int argc, const char **argv)

rec->page_size = sysconf(_SC_PAGE_SIZE);

- on_exit(perf_record__sig_exit, rec);
+ saved_rec = rec;
+ atexit(perf_record__sig_exit);
signal(SIGCHLD, sig_handler);
signal(SIGINT, sig_handler);
signal(SIGUSR1, sig_handler);
@@ -508,7 +512,7 @@ static int __cmd_record(struct perf_record *rec,
int argc, const char **argv)
/*
* perf_session__delete(session) will be called at perf_record__exit()
*/
- on_exit(perf_record__exit, rec);
+ atexit(perf_record__exit);

if (opts->pipe_output) {
err = perf_header__write_pipe(output);
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/