Skip to content

Commit c271a55

Browse files
ahunter6acmel
authored andcommitted
perf inject: Fix segfault due to perf_data__fd() without open
The fixed commit attempts to get the output file descriptor even if the file was never opened e.g. $ perf record uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (7 samples) ] $ perf inject -i perf.data --vm-time-correlation=dry-run Segmentation fault (core dumped) $ gdb --quiet perf Reading symbols from perf... (gdb) r inject -i perf.data --vm-time-correlation=dry-run Starting program: /home/ahunter/bin/perf inject -i perf.data --vm-time-correlation=dry-run [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Program received signal SIGSEGV, Segmentation fault. __GI___fileno (fp=0x0) at fileno.c:35 35 fileno.c: No such file or directory. (gdb) bt #0 __GI___fileno (fp=0x0) at fileno.c:35 #1 0x00005621e48dd987 in perf_data__fd (data=0x7fff4c68bd08) at util/data.h:72 #2 perf_data__fd (data=0x7fff4c68bd08) at util/data.h:69 #3 cmd_inject (argc=<optimized out>, argv=0x7fff4c69c1f0) at builtin-inject.c:1017 #4 0x00005621e4936783 in run_builtin (p=0x5621e4ee6878 <commands+600>, argc=4, argv=0x7fff4c69c1f0) at perf.c:313 #5 0x00005621e4897d5c in handle_internal_command (argv=<optimized out>, argc=<optimized out>) at perf.c:365 #6 run_argv (argcp=<optimized out>, argv=<optimized out>) at perf.c:409 #7 main (argc=4, argv=0x7fff4c69c1f0) at perf.c:539 (gdb) Fixes: 0ae0389 ("perf tools: Pass a fd to perf_file_header__read_pipe()") Signed-off-by: Adrian Hunter <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Riccardo Mancini <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 0c8e32f commit c271a55

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/perf/builtin-inject.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,12 +755,16 @@ static int parse_vm_time_correlation(const struct option *opt, const char *str,
755755
return inject->itrace_synth_opts.vm_tm_corr_args ? 0 : -ENOMEM;
756756
}
757757

758+
static int output_fd(struct perf_inject *inject)
759+
{
760+
return inject->in_place_update ? -1 : perf_data__fd(&inject->output);
761+
}
762+
758763
static int __cmd_inject(struct perf_inject *inject)
759764
{
760765
int ret = -EINVAL;
761766
struct perf_session *session = inject->session;
762-
struct perf_data *data_out = &inject->output;
763-
int fd = inject->in_place_update ? -1 : perf_data__fd(data_out);
767+
int fd = output_fd(inject);
764768
u64 output_data_offset;
765769

766770
signal(SIGINT, sig_handler);
@@ -1015,7 +1019,7 @@ int cmd_inject(int argc, const char **argv)
10151019
}
10161020

10171021
inject.session = __perf_session__new(&data, repipe,
1018-
perf_data__fd(&inject.output),
1022+
output_fd(&inject),
10191023
&inject.tool);
10201024
if (IS_ERR(inject.session)) {
10211025
ret = PTR_ERR(inject.session);

0 commit comments

Comments
 (0)