Bug #827

Babeltrace prints an error and segfaults if SIGTERM is received while adding traces in live mode.

Added by Jérémie Galarneau almost 6 years ago. Updated over 5 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:


Babeltrace reports an error and segfaults when SIGTERM (ctrl-c) is used while adding traces in live mode.

To reproduce, simply connect to a live session and use "ctrl-c" to exit before events are output to the console. The session must be started to reproduce the crash.

[error] Stream 18446744073709551615 is not declared in metadata.
[error] Open file mmap stream error.
[error] [Context] Cannot open_mmap_trace of format ctf.

[error] Error adding trace
Segmentation Fault

The problem appears to be caused by the failure to handle an error in packet_seek in the prepare_mmap_stream_definition() function (formats/ctf/ctf.c:2257). This leaves the stream_id uninitialized.

Moreover, the error is not reported to the calling code since add_traces() (see formats/lttng-live/lttng-live-comm.c:1357) does not report an error. This function is always used by g_hash_table_foreach() which needs a function which does not return.

The fix shall ensure that we propagate the error from prepare_mmap_stream_definition() and call add_traces() explicitly by iterating over the hash tables and handle errors as we go.

Back trace leading to the segfault:

Using host libthread_db library "/usr/lib/".
Core was generated by `babeltrace -i lttng-live net://'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f0a413eb6b5 in bt_iter_init (iter=0x20f7c70, ctx=0x20fa1c0, begin_pos=0x7fff887903e0, end_pos=0x0) at iterator.c:740
740        for (i = 0; i < ctx->tc->array->len; i++) {
(gdb) bt
#0  0x00007f0a413eb6b5 in bt_iter_init (iter=0x20f7c70, ctx=0x20fa1c0, begin_pos=0x7fff887903e0, end_pos=0x0) at iterator.c:740
#1  0x00007f0a411a9c91 in bt_ctf_iter_create (ctx=0x20fa1c0, begin_pos=0x7fff887903e0, end_pos=0x0) at iterator.c:53
#2  0x00007f0a40788717 in lttng_live_read (ctx=0x20f9e90) at lttng-live-comm.c:1662
#3  0x00007f0a407845e2 in lttng_live_open_trace_read (path=0x7fff88790c86 "net://") at lttng-live-plugin.c:233
#4  0x00007f0a40784703 in lttng_live_open_trace (path=0x7fff88790c86 "net://", flags=0, packet_seek=0x0, metadata_fp=0x0)
    at lttng-live-plugin.c:271
#5  0x00007f0a413eba99 in bt_context_add_trace (ctx=0x20f6ad0, path=0x7fff88790c86 "net://", format_name=0x20f1e80 "lttng-live", 
    packet_seek=0x0, stream_list=0x0, metadata=0x0) at context.c:95
#6  0x0000000000402b8b in bt_context_add_traces_recursive (ctx=0x20f6ad0, path=0x7fff88790c86 "net://", 
    format_str=0x20f1e80 "lttng-live", packet_seek=0x0) at babeltrace.c:507
#7  0x0000000000403367 in main (argc=4, argv=0x7fff887906c8) at babeltrace.c:736

This happens because the array in the TraceCollection is NULL.


Updated by Julien Desfossez over 5 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Applied in changeset babeltrace|commit:bf6c9bd641ef760014da5efd23085f5e93507990.

Also available in: Atom PDF