diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-06-15 14:48:08 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-07-29 10:12:39 -0400 |
commit | 9955d0be161a9baa241ae7b98426a4c705cb21cb (patch) | |
tree | e5c7bcb48be0aaf21eb454c314b442c693444ca8 /tools/perf/util/annotate.c | |
parent | 7c48dcfd32b45b69aa8d5e81108fff8c7a2272ed (diff) |
perf annotate: Use pipe + fork instead of popen
We will need to redirect the stderr as well, so open code popen as
a starting point.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-k0zt9svg4bswiglem7ornts4@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/annotate.c')
-rw-r--r-- | tools/perf/util/annotate.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index e9825fe825fd..2dd396a1f64b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -1134,8 +1134,10 @@ int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize) | |||
1134 | char symfs_filename[PATH_MAX]; | 1134 | char symfs_filename[PATH_MAX]; |
1135 | struct kcore_extract kce; | 1135 | struct kcore_extract kce; |
1136 | bool delete_extract = false; | 1136 | bool delete_extract = false; |
1137 | int stdout_fd[2]; | ||
1137 | int lineno = 0; | 1138 | int lineno = 0; |
1138 | int nline; | 1139 | int nline; |
1140 | pid_t pid; | ||
1139 | 1141 | ||
1140 | if (filename) | 1142 | if (filename) |
1141 | symbol__join_symfs(symfs_filename, filename); | 1143 | symbol__join_symfs(symfs_filename, filename); |
@@ -1258,9 +1260,32 @@ fallback: | |||
1258 | 1260 | ||
1259 | pr_debug("Executing: %s\n", command); | 1261 | pr_debug("Executing: %s\n", command); |
1260 | 1262 | ||
1261 | file = popen(command, "r"); | 1263 | err = -1; |
1264 | if (pipe(stdout_fd) < 0) { | ||
1265 | pr_err("Failure creating the pipe to run %s\n", command); | ||
1266 | goto out_remove_tmp; | ||
1267 | } | ||
1268 | |||
1269 | pid = fork(); | ||
1270 | if (pid < 0) { | ||
1271 | pr_err("Failure forking to run %s\n", command); | ||
1272 | goto out_close_stdout; | ||
1273 | } | ||
1274 | |||
1275 | if (pid == 0) { | ||
1276 | close(stdout_fd[0]); | ||
1277 | dup2(stdout_fd[1], 1); | ||
1278 | close(stdout_fd[1]); | ||
1279 | execl("/bin/sh", "sh", "-c", command, NULL); | ||
1280 | perror(command); | ||
1281 | exit(-1); | ||
1282 | } | ||
1283 | |||
1284 | close(stdout_fd[1]); | ||
1285 | |||
1286 | file = fdopen(stdout_fd[0], "r"); | ||
1262 | if (!file) { | 1287 | if (!file) { |
1263 | pr_err("Failure running %s\n", command); | 1288 | pr_err("Failure creating FILE stream for %s\n", command); |
1264 | /* | 1289 | /* |
1265 | * If we were using debug info should retry with | 1290 | * If we were using debug info should retry with |
1266 | * original binary. | 1291 | * original binary. |
@@ -1286,9 +1311,11 @@ fallback: | |||
1286 | if (dso__is_kcore(dso)) | 1311 | if (dso__is_kcore(dso)) |
1287 | delete_last_nop(sym); | 1312 | delete_last_nop(sym); |
1288 | 1313 | ||
1289 | pclose(file); | 1314 | fclose(file); |
1290 | 1315 | err = 0; | |
1291 | out_remove_tmp: | 1316 | out_remove_tmp: |
1317 | close(stdout_fd[0]); | ||
1318 | |||
1292 | if (dso__needs_decompress(dso)) | 1319 | if (dso__needs_decompress(dso)) |
1293 | unlink(symfs_filename); | 1320 | unlink(symfs_filename); |
1294 | out_free_filename: | 1321 | out_free_filename: |
@@ -1297,6 +1324,10 @@ out_free_filename: | |||
1297 | if (free_filename) | 1324 | if (free_filename) |
1298 | free(filename); | 1325 | free(filename); |
1299 | return err; | 1326 | return err; |
1327 | |||
1328 | out_close_stdout: | ||
1329 | close(stdout_fd[1]); | ||
1330 | goto out_remove_tmp; | ||
1300 | } | 1331 | } |
1301 | 1332 | ||
1302 | static void insert_source_line(struct rb_root *root, struct source_line *src_line) | 1333 | static void insert_source_line(struct rb_root *root, struct source_line *src_line) |