lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1431676290-1230-38-git-send-email-wangnan0@huawei.com>
Date:	Fri, 15 May 2015 07:51:30 +0000
From:	Wang Nan <wangnan0@...wei.com>
To:	<paulus@...ba.org>, <a.p.zijlstra@...llo.nl>, <mingo@...hat.com>,
	<acme@...nel.org>, <namhyung@...nel.org>, <jolsa@...nel.org>,
	<adrian.hunter@...el.com>, <dsahern@...il.com>, <ast@...mgrid.com>,
	<daniel@...earbox.net>, <brendan.d.gregg@...il.com>,
	<masami.hiramatsu.pt@...achi.com>
CC:	<linux-kernel@...r.kernel.org>, <lizefan@...wei.com>,
	<pi3orama@....com>, <wangnan0@...wei.com>
Subject: [RFC PATCH v2 37/37] tools perf bpf: passes generated arguments to cmd_record.

This patch utilizes previous introduced bpf_load_gen_argv() to generate
arguments for cmd_record.

We should try to avoid triggering atexit() unprobe handler because the
state of the process is uncommon. For example, stdio and stderr are
closed. Moreover, we are unable to ensure atexit() handler will be
called at every situations.

Signed-off-by: Wang Nan <wangnan0@...wei.com>
---
 tools/perf/builtin-bpf.c | 36 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/tools/perf/builtin-bpf.c b/tools/perf/builtin-bpf.c
index 94978c7..c818c9f 100644
--- a/tools/perf/builtin-bpf.c
+++ b/tools/perf/builtin-bpf.c
@@ -78,36 +78,20 @@ static int add_bpf_object_file(const struct option *opt,
 
 static int start_bpf_record(int argc, const char **argv)
 {
-	int i, new_argc, err, pos = 0;
+	int new_argc, err;
 	const char **new_argv;
 
-	new_argc = argc + 1;
-	new_argv = malloc((new_argc + 1) * sizeof(const char *));
-	if (!new_argv) {
-		pr_err("malloc failed\n");
-		return -ENOMEM;
-	}
-	bzero(new_argv, sizeof(const char *) * (new_argc + 1));
-
-	new_argv[pos++] = strdup("bpf record --");
-
-	for (i = 0; i < argc; i++) {
-		new_argv[pos++] = strdup(argv[i]);
-		if (!new_argv[pos - 1]) {
-			pr_err("strdup failed\n");
-			err = -ENOMEM;
-			goto errout;
-		}
+	if ((err = bpf_load_gen_argv(&new_argc, &new_argv,
+				     argc, argv,
+				     "bpf record --")))
+	{
+		pr_err("Failed to generate arguments for record\n");
+		return err;
 	}
 
-	return cmd_record(new_argc, new_argv, NULL);
-
-errout:
-	if (new_argv) {
-		for (i = 0; i < pos; i++)
-			free((void *)new_argv[i]);
-		free(new_argv);
-	}
+	/* new_argv won't be freed because cmd_record may change it. */
+	err = cmd_record(new_argc, new_argv, NULL);
+	bpf_unprobe();
 	return err;
 }
 
-- 
1.8.3.4

--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ