5 weeks agoFix: waiter: futex wait: handle spurious futex wakeups master
Mathieu Desnoyers [Thu, 23 Jun 2022 20:27:41 +0000 (16:27 -0400)] 
Fix: waiter: futex wait: handle spurious futex wakeups

Observed issue

The waiter lttng_waiter_wait() implements a futex wait/wakeup
scheme similar to the liburcu workqueue code, which has an issue with
spurious wakeups.

A spurious wakeup on lttng_waiter_wait can cause
lttng_waiter_wait to reach label skip_futex_wait with a
waiter->state state of WAITER_WAITING, which is unexpected. It would
cause busy-waiting on WAITER_TEARDOWN state to start early. The
wait-teardown stage is done with WAIT_ATTEMPTS active attempts,
following by attempts spaced by 10ms sleeps. I do not expect that these
spurious wakeups will cause user-observable effects other than being
slightly less efficient that it should be.

This issue will cause spurious unexpected high CPU use, but will not
lead to data corruption.


From futex(5):

              Returns 0 if the caller was woken up.  Note that a  wake-up  can
              also  be caused by common futex usage patterns in unrelated code
              that happened to have previously used the  futex  word's  memory
              location  (e.g., typical futex-based implementations of Pthreads
              mutexes can cause this under some conditions).  Therefore, call‐
              ers should always conservatively assume that a return value of 0
              can mean a spurious wake-up, and  use  the  futex  word's  value
              (i.e.,  the user-space synchronization scheme) to decide whether
              to continue to block or not.


We therefore need to validate whether the value differs from
WAITER_WAITING in user-space after the call to FUTEX_WAIT returns 0.

Known drawbacks


Signed-off-by: Mathieu Desnoyers <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: Ida9905d1f0b5d9543c8b85ecbd7d748a6f7c1c97

5 weeks agoFix: futex wait: handle spurious futex wakeups
Mathieu Desnoyers [Thu, 23 Jun 2022 20:15:51 +0000 (16:15 -0400)] 
Fix: futex wait: handle spurious futex wakeups

Observed issue

The futex futex_nto1_wait() implements a futex wait/wakeup scheme
identical to the liburcu workqueue code, which has an issue with
spurious wakeups.

A spurious wakeup on futex_nto1_wait can cause futex_nto1_wait to return
with a futex state of -1, which is unexpected.

futex_nto1_wait is used by the relayd live dispatcher thread, by the
relayd main dispatcher thread, as well as by the sessiond dispatcher

Given that following a futex_nto1_wait returning due to a spurious
wakeup futex_nto1_prepare will set the futex value to -1, things go
back to normal for the following futex_nto1_wait calls.

Therefore, the only impact of this issue is to spuriously use slightly
more CPU time than strictly required.

The effect is even shorter-lasting that in the liburcu counterparts
because futex_nto1_prepare explicitly sets the futex state to -1 rather
than use an atomic decrement, which immediately sets to state back to
a consistent state.


From futex(5):

              Returns 0 if the caller was woken up.  Note that a  wake-up  can
              also  be caused by common futex usage patterns in unrelated code
              that happened to have previously used the  futex  word's  memory
              location  (e.g., typical futex-based implementations of Pthreads
              mutexes can cause this under some conditions).  Therefore, call‐
              ers should always conservatively assume that a return value of 0
              can mean a spurious wake-up, and  use  the  futex  word's  value
              (i.e.,  the user-space synchronization scheme) to decide whether
              to continue to block or not.


We therefore need to validate whether the value differs from -1 in
user-space after the call to FUTEX_WAIT returns 0.

Known drawbacks


Signed-off-by: Mathieu Desnoyers <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: I8a1b6aaf77b6a2f941fd4f89b61bed71cf17906b

5 weeks agoFix: ust metadata: resample clock on regenerate metadata
Jonathan Rajotte [Fri, 8 Jul 2022 21:19:32 +0000 (17:19 -0400)] 
Fix: ust metadata: resample clock on regenerate metadata

Observed issue
The system test jobs complain that the clock regeneration is broken
since the move to the tsdl visitor approach for metadata generation.

 # Test UST local with metadata regeneration
 # destructive//../../src/bin/lttng/lttng create regen -o /tmp/tmp.metadata_regen_after_data_change.Vzb0vL
 ok 23 - Create session regen in -o /tmp/tmp.metadata_regen_after_data_change.Vzb0vL
 # destructive//../../src/bin/lttng/lttng enable-event tp:tptest -s regen -u
 ok 24 - Enable ust event tp:tptest for session regen
 # destructive//../../src/bin/lttng/lttng start regen
 ok 25 - Start tracing for session regen
 # destructive//../../src/bin/lttng/lttng stop regen
 ok 26 - Stop lttng tracing for session regen
 ok 27 - Validate trace at date 1970-02-02
 # destructive//../../src/bin/lttng/lttng start regen
 ok 28 - Start tracing for session regen
 # destructive//../../src/bin/lttng/lttng regenerate metadata -s regen
 ok 29 - Metadata regenerate regen
 # destructive//../../src/bin/lttng/lttng stop regen
 ok 30 - Stop lttng tracing for session regen
 # destructive//../../src/bin/lttng/lttng destroy regen
 ok 31 - Destroy session regen
 not ok 32 - The trace is not at the expected date
 #   Failed test 'The trace is not at the expected date'
 #   in destructive//../utils/tap/ at line 159.


Previously the clock was sampled on each call to `ust_metadata_session_statedump`
, currently the clock is only sampled on creation of the
`lttng::sessiond::ust::registry_session::registry_session` object.


On `lsu::registry_session::regenerate_metadata`, sample the clock and
replace the registry_session _clock object.

Signed-off-by: Jérémie Galarneau <>
Signed-off-by: Jonathan Rajotte <>
Change-Id: I6f671e4c01f71e1574824236cef03915a9c79b36

5 weeks agoFix: utils: unhandled close return value
Jérémie Galarneau [Mon, 22 Aug 2022 15:25:21 +0000 (11:25 -0400)] 
Fix: utils: unhandled close return value

Signed-off-by: Jérémie Galarneau <>
Change-Id: I3f932ac53e6b39c86babe726d5ec8e9ba999e561

6 weeks agoFix: agent port file is o+w when launching as root
Jonathan Rajotte [Thu, 21 Jul 2022 13:30:27 +0000 (09:30 -0400)] 
Fix: agent port file is o+w when launching as root

Observed issue

When starting as root, the following permissions are observed:

[-rw-rw-rw-]  agent.port

When starting as user:

[-rw-rw----]  agent.port

Note that despite being created by the same function,
`utils_create_pid_file`, the permissions are not the same.


`get_wait_shm` manipulates the umask and does not restore it, thus
influencing the outcome of following file creations that don't enforce
specific permissions (using chmod).

Also `fopen` defaults to mode `0666 & ~umask`, thus resulting in
unnecessarily lax permissions when the session daemon is started as a
non-privileged user (umask = 0002, most of the time).


Mimic other call sites of umask(), modify then revert the umask.

Open the pid and agent port files as 0644 letting the umask to do its
job as necessary for those files.

Remove unnecessary umask() usage when chmod is directly used.

Known drawbacks

Use of umask in a multi-threaded process is not recommended. Still our
current usage is limited and mostly happens during the initialization
phase. The usage of umask() is required for the `wait_shm` since on
FreeBSD it is not possible to chmod an shm file descriptor. The default
umask would interfere here.


The usage in run-as is valid even when in no-clone mode (valgrind) since
it is the sole user of umask() following the initialization phase. When
spawned as a separate process the clearing of umask is totally valid
even if it is not ideal since we are ignoring any umask set by the user.

It seems like the current usage is the lesser evil here.

Signed-off-by: Jonathan Rajotte <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: Ie224d254714fff05f4bced471ebfa8f19eede26a

6 weeks agoFix: tests: don't assume sequential cpuids
Michael Jeanson [Tue, 9 Aug 2022 15:38:16 +0000 (15:38 +0000)] 
Fix: tests: don't assume sequential cpuids

On Linux CPU ids aren't sequential if a CPU is offlined or unplugged.
Get the list of currently available CPU ids from sysfs and pick a random
one, if sysfs is not available use the previous behavior.

Signed-off-by: Michael Jeanson <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: Ibdb63c7d036389104ac2f629827a6dce59e06983

2 months agoFix: sessiond: null pointer dereference on initial evaluation of session
Jérémie Galarneau [Fri, 8 Jul 2022 15:45:01 +0000 (11:45 -0400)] 
Fix: sessiond: null pointer dereference on initial evaluation of session

Coverity reports:
1490492 Dereference after null check
Either the check against null is unnecessary, or there may be a null
pointer dereference.

In evaluate_session_condition(lttng_condition const *, session_info const *, session_state_sample const *, lttng_evaluation **): Pointer is checked against null but then dereferenced anyway (CWE-476)

This function is used to evaluate the initial state of a session and its
transitions against a given condition.

In the case of an initial evaluation, the wrong state sample is used
which results in a null dereference.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ia465e26d2bf0dae725504915fa62332ecf8c7784

2 months agoTests: size-based rotation: implement a trace size cutoff protection
Jérémie Galarneau [Tue, 5 Jul 2022 20:43:26 +0000 (16:43 -0400)] 
Tests: size-based rotation: implement a trace size cutoff protection

Stop waiting for rotations when the trace exceeds a certain size cutoff.
This prevents those tests from filling a hard drive when they fail.

However, this check is racy since it is possible for an arbitrary number
of apps to run before the session daemon gets a chance to perform the
scheduled rotations.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I465462e6f1d5c17ada2b3aceb68662d8663254eb

2 months agoFix: sessiond: handle empty scheduled rotations
Jérémie Galarneau [Wed, 6 Jul 2022 16:09:41 +0000 (12:09 -0400)] 
Fix: sessiond: handle empty scheduled rotations

A number of error codes were added to cmd_rotate_session since the
implementation of size-based rotations. The rotation thread doesn't
LTTNG_ERR_ROTATION_AFTER_STOP_CLEAR which are not fatal failures.

These rotations would simply result in an empty trace archive and are,
therefore, not produced. In both cases, it is safe to wait for the next
size cycle.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ib90526b586de17c0b14d16970c862d9f981ed464

2 months agoClean-up: sessiond: remove left-over code
Jérémie Galarneau [Tue, 5 Jul 2022 22:31:15 +0000 (18:31 -0400)] 
Clean-up: sessiond: remove left-over code

ust_metadata_channel_statedump no longer exists and _metadata_dumped
is unused.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I2fa3f3bcb8d1c5a779ab1cfa0375174b479ed21f

2 months agoTests: rotation: add a kernel size-based rotation test
Jérémie Galarneau [Wed, 22 Jun 2022 19:05:55 +0000 (15:05 -0400)] 
Tests: rotation: add a kernel size-based rotation test

Change-Id: I035814dcbe5e74227f907bae300eacffd132d80f
Signed-off-by: Jérémie Galarneau <>
2 months agoTests: rotation: add a per-pid size-based rotation test
Jérémie Galarneau [Wed, 22 Jun 2022 17:52:43 +0000 (13:52 -0400)] 
Tests: rotation: add a per-pid size-based rotation test

Signed-off-by: Jérémie Galarneau <>
Change-Id: I8f6875567d52dd7d28000ff34fff47f992cdab3f

2 months agoTests: add a local size-based rotation test in per-uid buffering mode
Jérémie Galarneau [Tue, 21 Jun 2022 04:42:34 +0000 (00:42 -0400)] 
Tests: add a local size-based rotation test in per-uid buffering mode

This test runs an application up until we observe four archived traces.
Unfortunately, we can't validate their size since they are approximative.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Iecdbf3ee33ed02745a99e7af22c0645b4375413e

2 months agoFix: sessiond: report client list allocation failure as a fatal error
Jérémie Galarneau [Thu, 30 Jun 2022 16:03:23 +0000 (12:03 -0400)] 
Fix: sessiond: report client list allocation failure as a fatal error

Report the failure to allocate a notification client list as a fatal
notification thread error.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I8f2654020d0d890cc9275d445fdeccde940d2ae0

2 months agoFix: leak of channel-bound trigger list element
Jérémie Galarneau [Wed, 29 Jun 2022 20:37:54 +0000 (16:37 -0400)] 
Fix: leak of channel-bound trigger list element

The list element is never free'd when a channel-bound trigger
is unregistered.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I32c4ee4512c460363e3384c2e3aac9feff4343b1

2 months agoFix: sessiond: size-based rotation threshold exceeded in per-pid tracing (2/2)
Jérémie Galarneau [Tue, 28 Jun 2022 03:36:22 +0000 (23:36 -0400)] 
Fix: sessiond: size-based rotation threshold exceeded in per-pid tracing (2/2)

For a complete description of the original problem, refer to the previous

This change implements the second part of the fix.

Buffer statistic samples are augmented to include the channel's session
id. Since a session can outlive its channels (on the session daemon
side), the consumed size conditions are now bound to the session.

This means that the "total consumed" state is now part of the
session_info structure exclusively which, overall, is cleaner.

A side-effect of this change is that consumed size conditions are now
also evaluated when a trigger is registered or when a client subscribes
to it via a notification channel instead of waiting until the next
monitoring sample.

The buffer statistics sample also expresses a "consumed size" that is
relative to the last sample that was successfully sent.

Finally, the consumer daemon sends a final buffer statistics sample when
a channel is torn down. As explained in more detail in the previous
commit, this makes the accounting of per-pid sessions more reliable when
short-live applications are traced.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I322b9f20977e59c63cf2a4254c97c4ee657e933e

2 months agoFix: sessiond: size-based rotation threshold exceeded in per-pid tracing (1/2)
Jérémie Galarneau [Mon, 27 Jun 2022 16:01:48 +0000 (12:01 -0400)] 
Fix: sessiond: size-based rotation threshold exceeded in per-pid tracing (1/2)

Issue observed

When tracing short-lived applications with buffers configured in per-pid
mode, the size-based rotation threshold is often greatly exceeded. In
the CI, this occasionally causes the size-based rotation tests to
timeout for the per-pid case.


There is a scenario where a session's consumed size is miscalculated.

When an application exits during per-pid tracing, both the session and
consumer daemons notice it. The session daemon sees the application's
command pipe hanging-up, while the consumer daemon sees the
application's data-ready pipe hanging-up.

Upon handling these events, both daemons tear down their representation of
the channels.

In an ideal world, we'd want to sample the streams' "consumed_size" at
the last possible moment to get the size of all consumed data for this
stream. However, this is problematic in the following scenario:
  - the sessiond destroys the channel before the consumer daemon,
  - the consumer daemon sends a final buffer stats sample on tear down,
  - the sessiond can do nothing with the sample as it doesn't know that
    channel anymore.

(Note that the session daemon gracefully handles the case where it
doesn't know a channel.)

When applications have a short lifetime and are traced in per-PID
buffering mode, there is a high likelihood that the last buffer
statistics sample sent for a given channel will target a channel that
the session daemon has already torn down.


Consumed-size conditions are somewhat special: they are bound to a
session, but they are evaluated through a per-channel event (buffer
statistics samples taken by the channels' monitoring timer).

To work around the problem of lifetime of channels, we can rely
on the fact that sessions outlive channels to perform the accounting
of the consumed size.

This patch is the first step to implement this fix: new
notification-thread commands are introduced to announce the creation and
destruction of an `ltt_session`. Currently, the notification thread
implies the existence of a session by tracking its channels' creation
and destruction.

With this change, it no longer needs to do so; session are explicitly
created and destroyed. Their unique ID is also kept stored.

The key of `sessions_ht` becomes the `id` of the session to allow
efficient look-ups on the reception of a buffer statistics sample.

The existing callsites that make use of the session's name to perform a
look-up are modified to look-up the id by name (see

The add/remove channel commands and rotation ongoing/completed commands
are modified to refer to sessions by ID since they can assume the
notification thread knows about the session.


In a follow-up patch, buffer statistics samples are modified to include
the session's ID and the consumed size is modified to become a "delta"
relative to the previous sample associated with a given channel.

This makes it possible to perform the accounting of a session's consumed
size beyond the lifetime of its channels.

The follow-up patch is the "core" of the fix, but it requires these
prior changes.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I865e9ac5e1a63e62123209be63957dad28c588a8

2 months agoconsumerd: send a buffer static sample on flush command
Jérémie Galarneau [Tue, 21 Jun 2022 20:56:23 +0000 (16:56 -0400)] 
consumerd: send a buffer static sample on flush command

When application exits during per-pid tracing, both the session and
consumer daemons notice it. The session daemon sees the application's
command pipe hanging-up, while the consumer daemon sees the
application's data-ready pipe hanging-up.

Upon handling this event, both daemons tear down their representation of
the channels.

In an ideal world, we'd want to sample the streams' "consumed_size" at the
last possible moment to get the size of all consumed data for this
stream. However, this is problematic in the following scenario:
  - the sessiond destroys the channel before the consumer daemon,
  - the consumer daemon sends a final buffer stats sample on tear down,
  - the sessiond can do nothing with the sample as it doesn't know that
    channel anymore.

Note that the session daemon handles the case where it doesn't know a
channel gracefully.

When an application being traced in per-pid mode is torn down, the
session requests a flush of its buffers to the consumer daemon. We can
use this opportunity to emit a buffer stats sample.

This is still racy since the tear down of the channel could complete on
the session daemon's end before that last sample can be processed. In
practice, though, it markedly improves the precision of size-based
rotations in per-pid tracing mode.

On my work machine, I see the size-based rotation tests pass with
archive sizes within ~10% of the size threshold. Before this, we lost a
lot of samples from short-lived buffers and it would not be rare to see
archives end-up multiple times (5x-10x) larger than the size-threshold.

Another problem is that the consumed_size returned by the consumer
daemon will not include the packets that have yet to be consumed.

Whether or not this is a fix is debatable since it arguably just
improves the precision of size-based rotations.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I8a72328ba1733ac2f50c77a1ff81d7a6aaac095c

2 months agoconsumerd: rename `data_read` to `has_data_left_to_be_read_before_teardown`
Jérémie Galarneau [Tue, 21 Jun 2022 20:46:29 +0000 (16:46 -0400)] 
consumerd: rename `data_read` to `has_data_left_to_be_read_before_teardown`

Document the sequence of events after a stream hangs up and rename
the `data_read` stream attribute to give it a more specific name.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Id7d26fa04fc0d2f0875dced18b6a3f6a7fe7d139

2 months agoFix: ust-consumerd: set `hangup_flush_done` in a locked context
Jérémie Galarneau [Tue, 21 Jun 2022 20:21:17 +0000 (16:21 -0400)] 
Fix: ust-consumerd: set `hangup_flush_done` in a locked context

hangup_flush_done is updated after releasing the stream lock. This
doesn't appear to be a problem right now since this attribute is
apparently always accessed by the same thread, but it is conceptually

Signed-off-by: Jérémie Galarneau <>
Change-Id: I191cb01b02c3d96e19034e0d0e80cb7f8dff2140

3 months agoFix: sessiond: size-based rotations never trigger
Jérémie Galarneau [Fri, 17 Jun 2022 20:53:53 +0000 (16:53 -0400)] 
Fix: sessiond: size-based rotations never trigger

Issue observed

Size-based scheduled rotations have no effect.


Since c08136a3f, the rotation thread's handle_condition() checks that
the notification received matches the trigger that was registered.

As part of the equality check, the triggers' credentials are compared.

This checks fails systematically since the group id of a trigger's
credentials is not transported by the serialize/create_from functions.
The trigger that is received through the notification thus has an unset
group id, while the rotation trigger of the `ltt_session` has a group id
set; it was not stripped by the communication layer.

The check also fails since the trigger registered for the size-based
rotation is "hidden". This internal attribute is not propagated through
the communication layer, which causes the comparison to fail.


Since triggers only use the 'uid' part of lttng_credentials, we ensure
that lttng_trigger_set_credentials only sets this part of the structure.

Also, the `is_hidden` attribute of a trigger is now propagated through
the communication layer. This has no effect for external applications
since this attribute is not exposed through the API. However, it is
useful for internal triggers which use the same communication

This allows the equality check in rotation-thread.cpp to go through as

Signed-off-by: Jérémie Galarneau <>
Change-Id: I216f5cb9297ecd1a867dc292c10b8da595efce34

3 months agoBump URCU dependency to 0.14
Michael Jeanson [Tue, 12 Apr 2022 20:55:50 +0000 (16:55 -0400)] 
Bump URCU dependency to 0.14

Complete C++ support was introduced in Userspace-RCU 0.14, using earlier
versions results in a build failure, this should be reflected in the
configure check.

Change-Id: I1b708bd9b04784deb9f2c8768a331911c3ebb891
Signed-off-by: Michael Jeanson <>
Signed-off-by: Jérémie Galarneau <>
3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
channel.cpp:584:2: warning: missing initializer for member 'lttng_notification_channel_message::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ia5a5f37f6fe6977169771e4a298d1ce73ab74ea4

3 months agoBuild fix: missing initializer for member 'override_name'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'override_name'

gcc 5.4.0 complains that:
relayd/relayd.cpp:1353:2: warning: missing initializer for member 'lttcomm_relayd_create_trace_chunk::override_name' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I6607c46e4aa98017183f41fc8be9b0226b70cf29

3 months agoBuild fix: missing initializer for member 'rotate_positions'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'rotate_positions'

gcc 5.4.0 complains that:
relayd/relayd.cpp:1221:2: warning: missing initializer for member 'lttcomm_relayd_rotate_streams::rotation_positions' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: If0ecd9c9b2c5a0861463e93a2a52b0d2b3a36712

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
notification.cpp:43:57: warning: missing initializer for member 'lttng_notification_comm::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Iebb2f14df21f6db9dceaf708af6ef12efda1b929

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
event.cpp:1238:53: warning: missing initializer for member 'lttng_event_context_comm::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Id7c01cd19cbf884efd16734239cae8476b798c20

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
event.cpp:769:3: warning: missing initializer for member 'lttng_event_exclusion_comm::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I22ccd0c84669951f6e0a13663e47b1d2a204d3a8

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
event.cpp:769:3: warning: missing initializer for member 'lttng_event_exclusion_comm::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Iac3eedff2d79843c910b4da5edec4d7f10fa062a

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
error-query.cpp:777:2: warning: missing initializer for member '{anonymous}::lttng_error_query_comm::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I1264bc2da7e8ff6ec6c740341a381b33bae643d1

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
error-query.cpp:570:2: warning: missing initializer for member '{anonymous}::lttng_error_query_results_comm::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ib1a297eaf2fd75b908573ac252b433a14423add5

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
error-query.cpp:318:2: warning: missing initializer for member '{anonymous}::lttng_error_query_result_comm::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ie194864415bc3bc32bda6b2ac17150bd3f163394

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
evaluation.cpp:30:2: warning: missing initializer for member 'lttng_evaluation_comm::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I2784138b00af34b2bc47ed28097ab32afaa379d2

3 months agoBuild fix: missing initializer for member 'indexes'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'indexes'

gcc 5.4.0 complains that:
actions/path.cpp:191:7: warning: missing initializer for member '{anonymous}::lttng_action_path_comm::indexes' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I3b365e89c6a11cf65f609a4e14ae972faa2a518d

3 months agoBuild fix: missing initializer for member 'payload'
Jérémie Galarneau [Thu, 16 Jun 2022 21:36:41 +0000 (17:36 -0400)] 
Build fix: missing initializer for member 'payload'

gcc 5.4.0 complains that:
notification-thread-events.cpp:3755:2: warning: missing initializer for member 'lttng_notification_channel_message::payload' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I4e3f32da956764cd9beba6f4c72cfc48251b8203

3 months agoBuild fix: missing initializer for member 'rotation_positions'
Jérémie Galarneau [Thu, 16 Jun 2022 21:31:20 +0000 (17:31 -0400)] 
Build fix: missing initializer for member 'rotation_positions'

gcc 5.4.0 complains that:
  main.cpp: In function 'ssize_t relay_unpack_rotate_streams_header(const lttng_buffer_view*, lttcomm_relayd_rotate_streams*)':
  main.cpp:2547:2: warning: missing initializer for member 'lttcomm_relayd_rotate_streams::rotation_positions' [-Wmissing-field-initializers]

The structure's members are initialized one by one.

At the same time, the use of the address of a packed
member (stream_count) is eliminated, which fixes another unrelated
warning emited by clang.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I5fd90d75cc6e0ba17350fc8092929f476e93757e

3 months agoBuild fix: specialization of template in different namespace
Jonathan Rajotte [Wed, 15 Jun 2022 19:09:03 +0000 (15:09 -0400)] 
Build fix: specialization of template in different namespace

Observed issue

On older g++, such as gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413:

make[3]: Entering directory '/tmp/virtenv/src/lttng-tools/src/bin/lttng-sessiond'
  CXX      utils.lo
In file included from ust-app.hpp:15:0,
                 from lttng-sessiond.hpp:22,
                 from utils.cpp:17:
../../../src/common/format.hpp:17:24: warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]
In file included from ust-app.hpp:15:0,
                 from lttng-sessiond.hpp:22,
                 from utils.cpp:17:
../../../src/common/format.hpp:23:13: error: specialization of 'template<class T, class Char, class Enable> struct fmt::v8::formatter' in different namespace [-fpermissive]
 struct fmt::formatter<std::type_info> : fmt::formatter<std::string> {
In file included from ../../../src/common/format.hpp:19:0,
                 from ust-app.hpp:15,
                 from lttng-sessiond.hpp:22,
                 from utils.cpp:17:
../../../src/vendor/fmt/core.h:707:8: error:   from definition of 'template<class T, class Char, class Enable> struct fmt::v8::formatter' [-fpermissive]
 struct formatter {
In file included from ust-registry.hpp:20:0,
                 from ust-app.hpp:19,
                 from lttng-sessiond.hpp:22,
                 from utils.cpp:17:
ust-registry-event.hpp:66:13: error: specialization of 'template<class T, class Char, class Enable> struct fmt::v8::formatter' in different namespace [-fpermissive]
 struct fmt::formatter<lttng::sessiond::ust::registry_event> : fmt::formatter<std::string> {
In file included from ../../../src/common/format.hpp:19:0,
                 from ust-app.hpp:15,
                 from lttng-sessiond.hpp:22,
                 from utils.cpp:17:
../../../src/vendor/fmt/core.h:707:8: error:   from definition of 'template<class T, class Char, class Enable> struct fmt::v8::formatter' [-fpermissive]
 struct formatter {
In file included from ust-app.hpp:19:0,
                 from lttng-sessiond.hpp:22,
                 from utils.cpp:17:
ust-registry.hpp: In constructor 'lttng::sessiond::ust::registry_typed_enum<MappingIntegerType>::registry_typed_enum(const char*, const lttng_ust_ctl_enum_entry*, size_t)':
ust-registry.hpp:111:45: error: 'lttng::sessiond::trace::integer_type::signedness' is not a class, namespace, or enumeration
       lttng::sessiond::trace::integer_type::signedness::SIGNED :
ust-registry.hpp:112:51: error: 'lttng::sessiond::trace::integer_type::signedness' is not a class, namespace, or enumeration
In file included from lttng-sessiond.hpp:22:0,
                 from utils.cpp:17:
ust-app.hpp: At global scope:
ust-app.hpp:330:13: error: specialization of 'template<class T, class Char, class Enable> struct fmt::v8::formatter' in different namespace [-fpermissive]
 struct fmt::formatter<ust_app> : fmt::formatter<std::string> {
In file included from ../../../src/common/format.hpp:19:0,
                 from ust-app.hpp:15,
                 from lttng-sessiond.hpp:22,
                 from utils.cpp:17:
../../../src/vendor/fmt/core.h:707:8: error:   from definition of 'template<class T, class Char, class Enable> struct fmt::v8::formatter' [-fpermissive]
 struct formatter {
cc1plus: warning: unrecognized command line option '-Wno-gnu-folding-constant'
cc1plus: warning: unrecognized command line option '-Wno-incomplete-setjmp-declaration'
Makefile:855: recipe for target 'utils.lo' failed
make[3]: *** [utils.lo] Error 1

This also applies to the following specializations:
  void lst::signed_enumeration_type::accept(type_visitor& visitor) const
  void lst::unsigned_enumeration_type::accept(type_visitor& visitor) const


This is due to a now-fixed gcc bug:


Put the template specializations inside the proper namespace.

Signed-off-by: Jonathan Rajotte <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: I6b931065b37e6e9ba97f87c754c15808506c2ba8

3 months agoBuild fix: old gcc does not recognize hidden/shadowed enumeration as valid
Jérémie Galarneau [Wed, 15 Jun 2022 20:09:05 +0000 (16:09 -0400)] 
Build fix: old gcc does not recognize hidden/shadowed enumeration as valid

The build fails on GCC < 6 with:

ust-registry.hpp: In constructor 'lttng::sessiond::ust::registry_typed_enum<MappingIntegerType>::registry_typed_enum(const char*, const lttng_ust_ctl_enum_entry*, size_t)':
ust-registry.hpp:111:45: error: 'lttng::sessiond::trace::integer_type::signedness' is not a class, namespace, or enumeration
       lttng::sessiond::trace::integer_type::signedness::SIGNED :

The same error occurs for stream_class::header_type.

This is due to a bug fixed in gcc 6:

In both cases, the member is suffixed to disambiguate the reference to
the inner-enumeration.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Id0f2f98a147be589b9c70740660c7fb911dfc22c

3 months agoBuild fix: unknown warning -Wduplicated-branches
Jérémie Galarneau [Wed, 15 Jun 2022 19:00:35 +0000 (15:00 -0400)] 
Build fix: unknown warning -Wduplicated-branches

-Wduplicated-branches was introduced in GCC 7. Only define
DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES for those more recent versions.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I3b50a671867a74629519375801bf2b4f3c597cd8

3 months agoFix: pthread::mutex unlock must not throw
Jérémie Galarneau [Tue, 14 Jun 2022 16:11:54 +0000 (12:11 -0400)] 
Fix: pthread::mutex unlock must not throw

unlock() is often called by destructors (e.g. lock guard); it must not
throw. We don't expect unlock to fail given our current usage anyhow.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I5dfd856f8a2dd29fd7c480c6ab6289b5b91c4391

3 months agoClean-up: common: uuid: uninitialized output parameter on error
Jérémie Galarneau [Tue, 14 Jun 2022 16:04:07 +0000 (12:04 -0400)] 
Clean-up: common: uuid: uninitialized output parameter on error

1490018 Uninitialized scalar variable
The variable will contain an arbitrary value left from earlier

In lttng_uuid_from_str(char const *, std::​array<unsigned char, 16ul> &):
Use of an uninitialized variable (CWE-457)

Callers should not use the return parameter anyhow on error.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Idd863d219da840a0c291478733f7b931967a5e56

3 months agoFix: sessiond: registry_channel: initialize _rcu_head and _node
Jérémie Galarneau [Tue, 14 Jun 2022 16:01:22 +0000 (12:01 -0400)] 
Fix: sessiond: registry_channel: initialize _rcu_head and _node

1490020 Uninitialized pointer field
The pointer field will point to an arbitrary memory location, any
attempt to write may cause corruption.

In lttng::​sessiond::​ust::​registry_channel::​registry_channel(unsigned int, std::​function<void (lttng::​sessiond::​ust::​registry_channel const &)>, std::​function<void (lttng::​sessiond::​ust::​registry_channel const &, lttng::​sessiond::​ust::​registry_event const &)>): A pointer field is not initialized in the constructor (CWE-457)

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ie043af750941a02a65ba69e70fe2620349989398

3 months agosessiond: registry_event: remove lttng_ht_node_u64 wrapper
Jérémie Galarneau [Tue, 14 Jun 2022 15:56:51 +0000 (11:56 -0400)] 
sessiond: registry_event: remove lttng_ht_node_u64 wrapper

Use rcu_head and cds_lfht_node directly since the lttng_ht_node_u64
utils is unused anyhow: its key is never initialized.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Id8b8d4b2f9ca9137b859844bc70e9d02e9fa2975

3 months agoTests: test_uuid: unchecked return value
Jérémie Galarneau [Tue, 14 Jun 2022 14:56:35 +0000 (10:56 -0400)] 
Tests: test_uuid: unchecked return value

1490026 Unchecked return value
If the function returns an error value, the error value may be mistaken
for a normal value.

In run_test_lttng_uuid_is_equal(): Value returned from a function is not
checked for errors before being used (CWE-252)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <>
Change-Id: Id9558a07ebcc47f5630deed32f5a457ba002bfe6

3 months agoFix: common: uninitialized lttng::ctl:error field
Jérémie Galarneau [Tue, 14 Jun 2022 14:54:09 +0000 (10:54 -0400)] 
Fix: common: uninitialized lttng::ctl:error field

Signed-off-by: Jérémie Galarneau <>
Change-Id: I456d1811c3827472533d0531af7148ee6e7eb34b

3 months agocommon: replace container_of with a C++ safe implementation
Jérémie Galarneau [Fri, 10 Jun 2022 19:10:32 +0000 (15:10 -0400)] 
common: replace container_of with a C++ safe implementation

As more code moves to a more idiomatic C++ style, structures like
typically end up becoming classes that use different access controls,
virtual functions, etc. This, in turn, makes them adopt a non standard
layout and causes GCC and clang to emit the following warning when
container_of is used:

error: 'offsetof' within non-standard-layout type 'foo' is conditionally-supported [-Werror=invalid-offsetof]

This new implementation of container_of makes use of a pointer to a data
member to find the parent's address.

The use of ptr_to_member against the null dummy_parent makes me uneasy
as it seems equivalent to performing arithmetic on a null pointer, which
I understand is undefined behavior (C++11 Standard 5.7.5).

However, Boost.Instrusive uses an approach that seems roughly equivalent
to lttng::utils::container_of() [1].

It seems like a reasonable compromise that works on all mainstream


Change-Id: Ia6287e1648bce85dfe6de936f17ec5df46ea648d
Signed-off-by: Jérémie Galarneau <>
3 months agosessiond: registry_session: mark functions as noexcept
Jérémie Galarneau [Thu, 9 Jun 2022 16:16:39 +0000 (12:16 -0400)] 
sessiond: registry_session: mark functions as noexcept

Mark functions destroy_channel and _destroy_enum as noexcept as they are
used by the registry_session destructor (which must not throw).

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ie7bbbf349f14f5691b52873fe8ba6556be143d93

3 months agoClean-up: sessiond: move registry_session free functions under class
Jérémie Galarneau [Wed, 8 Jun 2022 19:50:07 +0000 (15:50 -0400)] 
Clean-up: sessiond: move registry_session free functions under class

Move a number of registry_session methods implemented as c-style
free functions under the `registry_session` class. This makes it
possible to make a large number of attributes private.

This leaves only the metadata storage and locking facilities
publicly accessible. Making them private requires a bit more

Signed-off-by: Jérémie Galarneau <>
Change-Id: I6bdd4cc8918e5d7025fc3d735fadbf1ce2e9b7c8

3 months agoClean-up: sessiond: move ust_registry_session under lttng::sessiond::ust
Jérémie Galarneau [Wed, 8 Jun 2022 17:10:26 +0000 (13:10 -0400)] 
Clean-up: sessiond: move ust_registry_session under lttng::sessiond::ust

The ust_registry_session* class hierarchy is namespaced under

The registry session classes are also moved to their own headers.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I3be5aa3239bbff9b385ab942f749748b4d6cb352

3 months agosessiond: transition from lttng-ust to tracer agnostic API
Jérémie Galarneau [Mon, 13 Jun 2022 16:01:21 +0000 (12:01 -0400)] 
sessiond: transition from lttng-ust to tracer agnostic API

Refactor the session daemon's user space tracer management to use the
tracer-agnostic trace hierarchy description API. Since the API
introduced under lttng::sessiond::trace is closer to idiomatic C++,
some changes are needed to make use of it.

The biggest changes make the ust_registry* structures inherit from the
trace descriptions classes (trace_class, stream_class, event_class,
clock_class). This effectively isolates the members of the
`ust_registry` structures that describe their corresponding CTF class
to a base class and leaves only the implementation guts in the
`ust_registry` objects (moved under lttng::sessiond::ust).

Since the generation of TSDL metadata directly used the lttng_ust_ctl
API, it is replaced by a new implementation that is based around a trace
class visitor that serializes the tracer agnostic trace description

The TSDL environment visitor is moved under the TSDL implementation
of the trace class visitor.

Some little changes are also made to the existing code to make it
exception-safe, as needed.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I6562ef12e85afa91780337e8c6fdbb13568d9ece

3 months agosessiond: add tracer-agnostic trace hierarchy classes
Jérémie Galarneau [Thu, 12 May 2022 18:34:30 +0000 (14:34 -0400)] 
sessiond: add tracer-agnostic trace hierarchy classes

The session daemon receives the fields present in events from the
instrumented applications in the form of an array of lttng_ust_ctl_field
structures and uses them directly in a number of code paths.

This makes it impossible to extend the structures which makes a number of
features harder to implement than they should be.

The session daemon also implements various CTF concepts (clock, trace,
event, stream classes) as part of various structures defined under
`ust_registry*`. This makes it hard to isolate which attributes are
"internal" and which are visible to the external world through the

Tracer-agnostic trace hierachy classes are introduced under the
lttng::sessiond::trace namespace. Those classes don't cover the full
functionality of CTF: they expose what the tracers can currently

The top-level elements of the trace hierarchy -- trace, event, stream,
clock classes -- are visited using the trace_class_visitor interface.

Seperate field and type visitor interfaces are used to make it easier to
visit this subset of the trace hierarchy. This will be useful to
implement the listing of event fields through liblttng-ctl, for example.

In the short term, these classes will be used to implement the
serialization of the layout descriptions of CTF 1.8 and 2.

Change-Id: I6d99f0ec93082259bf64434c440a720ed9a49bf8
Signed-off-by: Jérémie Galarneau <>
3 months agocommon: macros: missing include of pthread.h
Jérémie Galarneau [Thu, 2 Jun 2022 15:01:23 +0000 (11:01 -0400)] 
common: macros: missing include of pthread.h

A number of macros in this file make use of pthread APIs. However, the
header is not included.

Signed-off-by: Jérémie Galarneau <>
Change-Id: If13df2434bd08269984c9589ff60a2bae4484ab3

3 months agocommon: uuid: add `uuid_to_str` which returns an std::string
Jérémie Galarneau [Thu, 2 Jun 2022 15:00:40 +0000 (11:00 -0400)] 
common: uuid: add `uuid_to_str` which returns an std::string

Signed-off-by: Jérémie Galarneau <>
Change-Id: Id915ba7dbe8128d492d92faa05bbf12770a49f8d

3 months agosessiond: session registry: use pthread::lock_guard instead of raw lock
Jérémie Galarneau [Thu, 12 May 2022 19:22:50 +0000 (15:22 -0400)] 
sessiond: session registry: use pthread::lock_guard instead of raw lock

Signed-off-by: Jérémie Galarneau <>
Change-Id: I3f5227782701a82257b710232fc02bd3c61a2e20

3 months agoTests fix: metadata event: print expected and actual event match count
Jérémie Galarneau [Mon, 16 May 2022 22:49:05 +0000 (18:49 -0400)] 
Tests fix: metadata event: print expected and actual event match count

The validate_metadata_event() function prints the actual event match
count twice when a test fails. Printing the expected vs actual counts
was probably the intention of the original author.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ideac2593a5d4d239ee24f98f954dddf2b5be91fa

3 months agoAdd lttng::locked_reference
Jérémie Galarneau [Mon, 16 May 2022 21:50:08 +0000 (17:50 -0400)] 
Add lttng::locked_reference

A locked reference is a wrapper that allows functions to return a
protected/synchronized version of an object. My immediate use-case for
this helper is making it easier to call functions that return an
rcu-protected object (require the caller to hold the RCU reader lock for
the duration of its use of that object) in an exception safe manner.

As such, these functions can now return
lttng::locked_reference<MyType, lttng::urcu::unique_read_lock> which
ensures the RCU reader lock is held for as long as the object is used.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I9f4b7f918ba01491d3de14a1a570c83586f407ae

3 months agosessiond: ust: remove unused `is_sent` attribute of ust_app_channel
Jérémie Galarneau [Wed, 25 May 2022 19:26:31 +0000 (15:26 -0400)] 
sessiond: ust: remove unused `is_sent` attribute of ust_app_channel

Signed-off-by: Jérémie Galarneau <>
Change-Id: If97146367f62edf739d1228908c21346c2dae231

3 months agoformat: add a custom formatter for std::type_info
Jérémie Galarneau [Thu, 12 May 2022 18:32:32 +0000 (14:32 -0400)] 
format: add a custom formatter for std::type_info

The name() returned by std::type_info is implementation-dependant. In
practice, it is typically the type's mangled name. For GCC and clang, it
is possible to use abi::__cxa_demangle to demangle the name at runtime
while formatting a string.

If this poses any compatibility problem on other platforms, we can
fallback to using name() directly.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ib80babe4039c91ce6fdf6d9a9442c31645a43b08

3 months agocommon: add macros to silence invalid offsetof warnings
Jérémie Galarneau [Thu, 12 May 2022 18:29:25 +0000 (14:29 -0400)] 
common: add macros to silence invalid offsetof warnings

Implementations are not forced to support offsetof for non-trivial types
in C++. gcc and clang both appear to support its use, but we should move
away from that. unfortunately that is not easy since offsetof is used
all over the place to use intrusive data structures.

I am unsure of the proper fix for this at the moment.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I6f2cedb0da235ff3756248f370add13d46438cec

3 months agoAdd new exception types: communication, protocol, and invalid argument
Jérémie Galarneau [Thu, 12 May 2022 18:27:06 +0000 (14:27 -0400)] 
Add new exception types: communication, protocol, and invalid argument

These new exception types are useful to expess communication errors
and are used in later patches when an application doesn't honor the
liblttng-ust-ctl protocol.

Signed-off-by: Jérémie Galarneau <>
Change-Id: If5cd92c2f2fc31c6e68d49ade9e66f16e50394a3

3 months agoAdd lttng::make_unique
Jérémie Galarneau [Thu, 12 May 2022 18:24:07 +0000 (14:24 -0400)] 
Add lttng::make_unique

Add an equivalent to std::make_unique introduced in C++14.

See for more details.

Change-Id: I67e5b54d883e311869d7c1272f9a2905dc349212
Signed-off-by: Jérémie Galarneau <>
3 months agoconsumerd: Rename global ctx variable to the_consumer_context
Jérémie Galarneau [Thu, 5 May 2022 20:12:45 +0000 (16:12 -0400)] 
consumerd: Rename global ctx variable to the_consumer_context

Signed-off-by: Jérémie Galarneau <>
Change-Id: Iba386af30616ac193106cb36a4ad0e9b03fb02de

3 months agosessiond: add smart pointer utils for ltt_session
Jérémie Galarneau [Thu, 5 May 2022 19:25:39 +0000 (15:25 -0400)] 
sessiond: add smart pointer utils for ltt_session

Add `find_session_by_id` and `find_locked_session_by_id` which return
smart pointers to ltt_session. In both cases, the smart pointers make
use of ltt_session's underlying reference counting mechanism.

In the case of `find_locked_session_by_id`, the session that is returned
is locked; it is automatically unlocked (and a reference is released)
when the pointer goes out of scope. This makes it easier to write
exception-safe code that uses the ltt_session API.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I125dc7592b8ef2de1da645029f311bf429a21767

3 months agoAdd C++ wrappers for pthread mutex and rcu read lock
Jérémie Galarneau [Thu, 5 May 2022 19:16:53 +0000 (15:16 -0400)] 
Add C++ wrappers for pthread mutex and rcu read lock

Add two wrappers that are similar and provide the "Mutex" named
requirements[1] around pthread_mutex_t and liburcu's RCU reader lock.

In both cases, the intention is to either use the `mutex` or `read_lock`
interface with the standard concurrency support library (e.g. std::lock,
etc.) or, more likely, use the lock_guard wrappers.

The lock_guard[2] wrappers make it easier to convert existing code to be
exception-safe and generally makes the use of those locks less


Signed-off-by: Jérémie Galarneau <>
Change-Id: I26cfc2e954d1d4cc1f7e0973cdcd1b9881ef181a

3 months agoAdd lttng::utils::time_to_iso8601_str
Jérémie Galarneau [Thu, 5 May 2022 19:15:44 +0000 (15:15 -0400)] 
Add lttng::utils::time_to_iso8601_str

lttng::utils::time_to_iso8601_str implements the same formatting
as time_to_iso8601_str, but returns an std::string.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I0bd7dbbdc2c3bae6fdef7917936450953af72175

3 months agoAdd vendor/fmt
Jérémie Galarneau [Tue, 3 May 2022 20:20:26 +0000 (16:20 -0400)] 
Add vendor/fmt

Add fmt 8.1.1 headers (we will use it in header-only mode). fmt is made
available under the MIT license, which is already in the LICENSES

Note that an lttng-format.hpp header is added to disable a warning which
prevents us from building with -Werror.

../../../src/vendor/fmt/format-inl.h:2457:11: error: target of initialization might be a candidate for a format attribute [-Werror=suggest-attribute=format]
 2457 |     int (*snprintf_ptr)(char*, size_t, const char*, ...) = FMT_SNPRINTF;
      |           ^~~~~~~~~~~~

The header also ensures that FMT_HEADER_ONLY is defined for all uses of

Signed-off-by: Jérémie Galarneau <>
Change-Id: I5696c09d6e07716b955091922bb27ce082fb2686

3 months agosessiond: Move trace_ust_clock to a clock_attributes_sample class
Jérémie Galarneau [Mon, 2 May 2022 19:35:40 +0000 (15:35 -0400)] 
sessiond: Move trace_ust_clock to a clock_attributes_sample class

Move trace clock functions to a class that samples the clock's
attributes on creation. This makes it easier to implement trace format
agnostic serialization facilities in follow-up patches.

Change-Id: Id75b2c6e00779710e02691da107b2e93bf33ff12
Signed-off-by: Jérémie Galarneau <>
3 months agoChange backing type of lttng_uuid to std::array
Jérémie Galarneau [Mon, 2 May 2022 19:33:09 +0000 (15:33 -0400)] 
Change backing type of lttng_uuid to std::array

Changing the backing type of lttng_uuid to std::array allows us to
return lttng_uuid from a function. This, in return, makes it possible to
initialize const attributes from the return value of a function
returning a UUID.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ie092eab4a848a41ddd9c63f779514f1e4ca2a441

3 months agosessiond: Split ust_registry_session into per-type classes
Jérémie Galarneau [Fri, 29 Apr 2022 02:06:25 +0000 (22:06 -0400)] 
sessiond: Split ust_registry_session into per-type classes

This is a preliminary refactoring step to implement support for the
conditional generation of CTF 1.8/2.0 stream description layouts.

Splitting the registry session will simplify the implementation of a
serialization visitor by segregating per-type environment attributes.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ia95dd0c67f2ff41ce4f771ce776ff84a214098b9

3 months agosessiond: Replace uses of session_trylock_list by a dedicated assert macro
Jérémie Galarneau [Thu, 5 May 2022 19:00:10 +0000 (15:00 -0400)] 
sessiond: Replace uses of session_trylock_list by a dedicated assert macro

Signed-off-by: Jérémie Galarneau <>
Change-Id: I925a2f4052149b3a9ff91a80c7541dc8ed226c70

3 months agoAdd basic exception types and throwing facilities
Jérémie Galarneau [Fri, 29 Apr 2022 19:43:14 +0000 (15:43 -0400)] 
Add basic exception types and throwing facilities

Add two LTTng-specific exception types:
  - lttng::ctl::error
  - lttng::posix_error

These types are meant to help transition from error code-based
error handling in RAII-safe functions.

lttng::ctl::error wraps `enum lttng_error_code`. It is meant to be
thrown using the `LTTNG_THROW_CTL` macro which samples the throw-site
(file name, function name, line number). This should be used only
in code paths dealing providing the liblttng-ctl interface.

It should, ultimately, be thrown in code that is specific to the
implementation of the various liblttng-ctl commands and not all over the
place since it contains very little information beyond the error code.

lttng::posix_error wraps `errno` values that are used in various places
to report errors involving (mostly) syscalls.

Over time, more specific exception types will be added.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I02e104f28dd8149aee70211b5849f3502f16d58b

3 months ago.clang-format: tweak C++ style
Jérémie Galarneau [Thu, 28 Apr 2022 23:18:12 +0000 (19:18 -0400)] 
.clang-format: tweak C++ style

Don't indent namespaces nor after access modifiers.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ifb67843c7c89d1f49dca9f59a76273f3b0b8fb3a

3 months agoAdd make_unique_wrapper()
Jérémie Galarneau [Thu, 28 Apr 2022 15:28:15 +0000 (11:28 -0400)] 
Add make_unique_wrapper()

make_unique_wrapper is intended to facilitate the use of std::unique_ptr
to wrap C-style APIs that don't provide RAII resource management facilities.

Usage example:

   // API
   struct my_c_struct {
           // ...

   struct my_c_struct *create_my_c_struct(void);
   void destroy_my_c_struct(struct my_c_struct *value);

   // Creating a unique_ptr to my_c_struct.
   auto safe_c_struct =
           lttng::make_unique_wrapper<my_c_struct, destroy_my_c_struct>(

Note that this facility is intended for use in the scope of a function.
If you need to return this unique_ptr instance, you should consider writting
a proper, idiomatic, wrapper.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I429fc6f62896efb04af95fc26143096043206265

3 months agoAdd vendor/optional.hpp
Simon Marchi [Fri, 12 Nov 2021 15:09:35 +0000 (10:09 -0500)] 
Add vendor/optional.hpp

Taken from:

The BSL-1.0 license is already in the LICENSES directory, so no need to
add it.

Change-Id: I47e9a3264b771b0a6aaefc022ada9e051b6b6d20
Signed-off-by: Simon Marchi <>
Signed-off-by: Jérémie Galarneau <>
3 months agoClean-up: ust-consumer: replace ad-hoc channel destruction
Jérémie Galarneau [Wed, 27 Apr 2022 22:08:48 +0000 (18:08 -0400)] 
Clean-up: ust-consumer: replace ad-hoc channel destruction

Signed-off-by: Jérémie Galarneau <>
Change-Id: I5018d841035eb302c0f3c092efc570b3eaa71198

3 months agoTests: test_session: include tap.h last
Jérémie Galarneau [Mon, 6 Jun 2022 16:07:15 +0000 (12:07 -0400)] 
Tests: test_session: include tap.h last

tap.h defines a number of macros that are very likely to clash with
other headers (e.g. ok, fail, etc.). On gcc 7.5.0, builds fail whenever
tap.h is included before an header that transitively includes

This clash doesn't occur with more recent gcc releases (tested with 11.2
on my local machine).

Signed-off-by: Jérémie Galarneau <>
Change-Id: I62aaa14a6d1f20c77073ab2e481eddcb28fb78f3

4 months agoFix: lttng-snapshot: use after free of max size argument
Jérémie Galarneau [Tue, 17 May 2022 17:41:49 +0000 (13:41 -0400)] 
Fix: lttng-snapshot: use after free of max size argument

gcc 12.1.0 reports:

commands/snapshot.cpp: In function ‘int cmd_snapshot(int, const char**)’:
../../../src/common/error.hpp:139:32: error: pointer ‘max_size_arg’ may be used after ‘void free(void*)’ [-Werror=use-after-free]

free max_size_arg on both paths.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I3775e835e10b364f32f4797afb9c090ac4dc133c

4 months agoFix: test: lttng kernel modules still loaded after running test_clock_override
Jonathan Rajotte [Fri, 25 Mar 2022 18:26:38 +0000 (14:26 -0400)] 
Fix: test: lttng kernel modules still loaded after running test_clock_override

Observed issue

After running test_clock_override, some lttng modules are still loaded.

$ lsmod | ag lttng
  lttng_test             32768  0
  lttng_tracer         2326528  1 lttng_test
  lttng_statedump       749568  1 lttng_tracer
  lttng_wrapper          16384  2 lttng_statedump,lttng_tracer
  lttng_uprobes          16384  1 lttng_tracer
  lttng_kprobes          16384  1 lttng_tracer
  lttng_lib_ring_buffer    61440  1 lttng_tracer
  lttng_kretprobes       16384  1 lttng_tracer
  lttng_clock_plugin_test    16384  1
  lttng_clock            16384  2 lttng_tracer,lttng_clock_plugin_test


The order in which the modules are removed is important.

In `test_clock_override_timestamp` the last `modprobe --remove order` is

  modprobe --remove lttng-clock-plugin-test lttng-clock lttng-test

While other callsites order is:

  modprobe --remove lttng-test lttng-clock-plugin-test lttng-clock



  modprobe --remove lttng-test lttng-clock-plugin-test lttng-clock

Signed-off-by: Jonathan Rajotte <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: I528df2e3e90664433337a547a74cdbe476d4ee62

5 months agoFix: lttng: snapshot: add-output: leak of max size parameter
Jérémie Galarneau [Fri, 15 Apr 2022 06:09:53 +0000 (02:09 -0400)] 
Fix: lttng: snapshot: add-output: leak of max size parameter

==1920281==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 6 byte(s) in 1 object(s) allocated from:
    #0 0x7fa95633add9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7fa955e90c09  (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: I87ce90a77d9624add0cab5d3090a7e83734da7f4

5 months agoTests: fix: lttng-create: leaked command parameter
Jérémie Galarneau [Fri, 15 Apr 2022 05:55:45 +0000 (01:55 -0400)] 
Tests: fix: lttng-create: leaked command parameter

==1853705==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 3 byte(s) in 1 object(s) allocated from:
    #0 0x7fb67ee0edd9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7fb67e964c09  (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: I2f3346157cb26de6712c6e6ebd5fafa6b51fac08

5 months agoFix: sessiond: rotation trigger leak
Jérémie Galarneau [Fri, 15 Apr 2022 05:30:50 +0000 (01:30 -0400)] 
Fix: sessiond: rotation trigger leak

==1801304==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 224 byte(s) in 2 object(s) allocated from:
    #0 0x7fe0f4e73fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x559fbeb64175 in zmalloc_internal ../../src/common/macros.hpp:60
    #2 0x559fbeb6a291 in lttng_trigger* zmalloc<lttng_trigger>() ../../src/common/macros.hpp:89
    #3 0x559fbeb64aa6 in lttng_trigger_create /home/jgalar/EfficiOS/src/lttng-tools/src/common/trigger.cpp:58
    #4 0x559fbe9dc417 in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:87
    #5 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993
    #6 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246
    #7 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624
    #8 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68
    #9 0x7fe0f44935c1 in start_thread (/usr/lib/

Indirect leak of 208 byte(s) in 2 object(s) allocated from:
    #0 0x7fe0f4e73fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x559fbeb16e21 in zmalloc_internal ../../src/common/macros.hpp:60
    #2 0x559fbeb16e31 in lttng_action_notify* zmalloc<lttng_action_notify>() ../../src/common/macros.hpp:89
    #3 0x559fbeb168a0 in lttng_action_notify_create actions/notify.cpp:135
    #4 0x559fbe9dc34b in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:80
    #5 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993
    #6 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246
    #7 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624
    #8 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68
    #9 0x7fe0f44935c1 in start_thread (/usr/lib/

Indirect leak of 160 byte(s) in 2 object(s) allocated from:
    #0 0x7fe0f4e73fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x559fbeb3d7a1 in zmalloc_internal ../../src/common/macros.hpp:60
    #2 0x559fbeb3fa35 in lttng_condition_session_consumed_size* zmalloc<lttng_condition_session_consumed_size>() ../../src/common/macros.hpp:89
    #3 0x559fbeb3e6fd in lttng_condition_session_consumed_size_create conditions/session-consumed-size.cpp:206
    #4 0x559fbe9dc0f1 in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:54
    #5 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993
    #6 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246
    #7 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624
    #8 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68
    #9 0x7fe0f44935c1 in start_thread (/usr/lib/

Indirect leak of 112 byte(s) in 2 object(s) allocated from:
    #0 0x7fe0f4e73fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x559fbeb242ad in zmalloc_internal ../../src/common/macros.hpp:60
    #2 0x559fbeb27062 in zmalloc<(anonymous namespace)::lttng_rate_policy_every_n> ../../src/common/macros.hpp:89
    #3 0x559fbeb25e9f in lttng_rate_policy_every_n_create actions/rate-policy.cpp:492
    #4 0x559fbeb168b9 in lttng_action_notify_create actions/notify.cpp:141
    #5 0x559fbe9dc34b in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:80
    #6 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993
    #7 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246
    #8 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624
    #9 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68
    #10 0x7fe0f44935c1 in start_thread (/usr/lib/

Indirect leak of 34 byte(s) in 2 object(s) allocated from:
    #0 0x7fe0f4e19319 in __interceptor_strdup /usr/src/debug/gcc/libsanitizer/asan/asan_interceptors.cpp:454
    #1 0x559fbeb3f603 in lttng_condition_session_consumed_size_set_session_name conditions/session-consumed-size.cpp:442
    #2 0x559fbe9dc2c4 in subscribe_session_consumed_size_rotation(ltt_session*, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/rotate.cpp:71
    #3 0x559fbe995d6f in cmd_rotation_set_schedule(ltt_session*, bool, lttng_rotation_schedule_type, unsigned long, notification_thread_handle*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/cmd.cpp:5993
    #4 0x559fbe9fe559 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2246
    #5 0x559fbea01378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624
    #6 0x559fbe9ea642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68
    #7 0x7fe0f44935c1 in start_thread (/usr/lib/

The rotation trigger of a session (used for size-based rotations) is
never cleaned-up. It is now cleaned up every time its condition is
hit and whenever the session is destroyed.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I5a89341535f87b7851b548ded9838c18bd1ccb95

5 months agoTests: fix: schedule api: leak of rotation schedule list
Jérémie Galarneau [Fri, 15 Apr 2022 05:34:54 +0000 (01:34 -0400)] 
Tests: fix: schedule api: leak of rotation schedule list

==1769573==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7fef37a29fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fef37792f2f in zmalloc_internal ../../../src/common/macros.hpp:60
    #2 0x7fef3779573a in lttng_rotation_schedules* zmalloc<lttng_rotation_schedules>() ../../../src/common/macros.hpp:89
    #3 0x7fef377947cc in lttng_rotation_schedules_create /home/jgalar/EfficiOS/src/lttng-tools/src/lib/lttng-ctl/rotate.cpp:353
    #4 0x7fef37794aa0 in get_schedules /home/jgalar/EfficiOS/src/lttng-tools/src/lib/lttng-ctl/rotate.cpp:392
    #5 0x7fef377956dc in lttng_session_list_rotation_schedules /home/jgalar/EfficiOS/src/lttng-tools/src/lib/lttng-ctl/rotate.cpp:665
    #6 0x5646131713f2 in test_add_list_remove_schedule /home/jgalar/EfficiOS/src/lttng-tools/tests/regression/tools/rotation/schedule_api.c:252
    #7 0x56461317157b in test_add_list_remove_size_schedule /home/jgalar/EfficiOS/src/lttng-tools/tests/regression/tools/rotation/schedule_api.c:270
    #8 0x564613171680 in main /home/jgalar/EfficiOS/src/lttng-tools/tests/regression/tools/rotation/schedule_api.c:307
    #9 0x7fef373ae30f in __libc_start_call_main (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: I9b7eb537d158791db76f9a7676ffeb5d4a1f2203

5 months agoFix: lttng: enable-rotation: leak of command parameter
Jérémie Galarneau [Fri, 15 Apr 2022 05:29:46 +0000 (01:29 -0400)] 
Fix: lttng: enable-rotation: leak of command parameter

==1759491==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 6 byte(s) in 1 object(s) allocated from:
    #0 0x7fdbdc94add9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7fdbdc4a0c09  (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: I29cc6ec4390e71829107f309f162247b9be2868c

5 months agoFix: lttng: track: leaked command parameter
Jérémie Galarneau [Fri, 15 Apr 2022 04:35:35 +0000 (00:35 -0400)] 
Fix: lttng: track: leaked command parameter

==1676099==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 5 byte(s) in 1 object(s) allocated from:
    #0 0x7f19429d9dd9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7f19425342ad in poptGetNextOpt (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ibafcaf42ad4f842b3fa74cf91dc5ecc8acb3487d

5 months agoFix: lttng: add-trigger: leak of parser context on capture
Jérémie Galarneau [Fri, 15 Apr 2022 03:43:10 +0000 (23:43 -0400)] 
Fix: lttng: add-trigger: leak of parser context on capture

==1501334==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 16386 byte(s) in 1 object(s) allocated from:
    #0 0x7f95efc3cdd9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x55acb0681ed3 in lttng_filter_yyalloc(unsigned long, void*) filter/filter-lexer.cpp:2511
    #2 0x55acb067f2f2 in lttng_filter_yy_create_buffer(_IO_FILE*, int, void*) filter/filter-lexer.cpp:1895
    #3 0x55acb067ea44 in yyrestart(_IO_FILE*, void*) filter/filter-lexer.cpp:1824
    #4 0x55acb0649a43 in filter_parser_ctx_alloc(_IO_FILE*) filter/filter-parser.ypp:271
    #5 0x55acb0649e7f in filter_parser_ctx_create_from_filter_expression(char const*, filter_parser_ctx**) filter/filter-parser.ypp:332
    #6 0x55acb058ee89 in parse_event_rule commands/add_trigger.cpp:783
    #7 0x55acb05920c0 in handle_condition_event commands/add_trigger.cpp:1361
    #8 0x55acb0592739 in parse_condition commands/add_trigger.cpp:1457
    #9 0x55acb0596b56 in cmd_add_trigger(int, char const**) commands/add_trigger.cpp:2304
    #10 0x55acb05a5b80 in handle_command /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng/lttng.cpp:238
    #11 0x55acb05a6643 in parse_args /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng/lttng.cpp:427
    #12 0x55acb05a694a in main /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng/lttng.cpp:476
    #13 0x7f95ef28730f in __libc_start_call_main (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: I6fa21e7d066e0cf48afc3f91ceefbfd19c6b86fd

5 months agoTests: fix: leak of trigger in trigger listing tests
Jérémie Galarneau [Fri, 15 Apr 2022 03:26:12 +0000 (23:26 -0400)] 
Tests: fix: leak of trigger in trigger listing tests

==1480456==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 112 byte(s) in 1 object(s) allocated from:
    #0 0x7fdb9260cfb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fdb9242348d in zmalloc_internal ../../src/common/macros.hpp:60
    #2 0x7fdb924295a9 in lttng_trigger* zmalloc<lttng_trigger>() ../../src/common/macros.hpp:89
    #3 0x7fdb92423dbe in lttng_trigger_create /home/jgalar/EfficiOS/src/lttng-tools/src/common/trigger.cpp:58
    #4 0x56304832331f in register_trigger /home/jgalar/EfficiOS/src/lttng-tools/tests/regression/tools/trigger/utils/register-some-triggers.cpp:24
    #5 0x5630483233f1 in register_trigger_action_list_notify /home/jgalar/EfficiOS/src/lttng-tools/tests/regression/tools/trigger/utils/register-some-triggers.cpp:46
    #6 0x5630483239a0 in test_session_rotation_conditions /home/jgalar/EfficiOS/src/lttng-tools/tests/regression/tools/trigger/utils/register-some-triggers.cpp:246
    #7 0x563048323d4d in main /home/jgalar/EfficiOS/src/lttng-tools/tests/regression/tools/trigger/utils/register-some-triggers.cpp:309
    #8 0x7fdb91c6630f in __libc_start_call_main (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ie163989a70f65f9c2c4e93c36cc9fc6ba6bdeeb5

5 months agoFix: action error query: leak of action path
Jérémie Galarneau [Fri, 15 Apr 2022 03:21:27 +0000 (23:21 -0400)] 
Fix: action error query: leak of action path

==1429021==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7fe305f031b2 in __interceptor_realloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x559f1b022238 in lttng_dynamic_buffer_set_capacity(lttng_dynamic_buffer*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:159
    #2 0x559f1b021d9f in lttng_dynamic_buffer_append(lttng_dynamic_buffer*, void const*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:52
    #3 0x559f1b02144a in lttng_dynamic_array_add_element(lttng_dynamic_array*, void const*) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-array.cpp:58
    #4 0x559f1b07d07b in lttng_action_path_copy(lttng_action_path const*, lttng_action_path*) actions/path.cpp:116
    #5 0x559f1b02383f in lttng_error_query_action_create /home/jgalar/EfficiOS/src/lttng-tools/src/common/error-query.cpp:232
    #6 0x559f1b02760e in lttng_error_query_create_from_payload(lttng_payload_view*, lttng_error_query**) /home/jgalar/EfficiOS/src/lttng-tools/src/common/error-query.cpp:911
    #7 0x559f1af5c361 in receive_lttng_error_query /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:740
    #8 0x559f1af64eba in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2336
    #9 0x559f1af67378 in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2624
    #10 0x559f1af50642 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:68
    #11 0x7fe3055225c1 in start_thread (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: I7a6f7d2a9746124581eebf30877466f16db67a6b

5 months agoFix: lttng: enable-channel: leak of popt arguments
Jérémie Galarneau [Fri, 15 Apr 2022 00:22:03 +0000 (20:22 -0400)] 
Fix: lttng: enable-channel: leak of popt arguments

==1245463==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 5 byte(s) in 1 object(s) allocated from:
    #0 0x7fe7c494fdd9 in __interceptor_malloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7fe7c44a5c09  (/usr/lib/

Arguments obtained with poptGetOptArg() must be free'd.

Signed-off-by: Jérémie Galarneau <>
Change-Id: I5a65ca6fbaa18f7717ea918a5bc7f42daeb1009a

5 months agoTests: clean-up: rate policy: remove stale comment
Jérémie Galarneau [Fri, 15 Apr 2022 00:09:58 +0000 (20:09 -0400)] 
Tests: clean-up: rate policy: remove stale comment

Signed-off-by: Jérémie Galarneau <>
Change-Id: Idd030c765b0a4afa2d13ff015a17bd52493204a6

5 months agoTests: fix: leak of rate policy in rate policy unit tests
Jérémie Galarneau [Fri, 15 Apr 2022 00:09:24 +0000 (20:09 -0400)] 
Tests: fix: leak of rate policy in rate policy unit tests

==1198508==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7f8b62634fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x557871869adb in zmalloc_internal ../../src/common/macros.hpp:60
    #2 0x55787186c8a0 in zmalloc<(anonymous namespace)::lttng_rate_policy_once_after_n> ../../src/common/macros.hpp:89
    #3 0x55787186c173 in lttng_rate_policy_once_after_n_create actions/rate-policy.cpp:707
    #4 0x55787186a368 in lttng_rate_policy_once_after_n_create_from_payload actions/rate-policy.cpp:183
    #5 0x55787186ad02 in lttng_rate_policy_create_from_payload(lttng_payload_view*, lttng_rate_policy**) actions/rate-policy.cpp:287
    #6 0x557871865b5b in test_rate_policy_once_after_n /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_rate_policy.cpp:231
    #7 0x557871865dc9 in main /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_rate_policy.cpp:250
    #8 0x7f8b61c7130f in __libc_start_call_main (/usr/lib/

Direct leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7f8b62634fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x557871869adb in zmalloc_internal ../../src/common/macros.hpp:60
    #2 0x55787186c890 in zmalloc<(anonymous namespace)::lttng_rate_policy_every_n> ../../src/common/macros.hpp:89
    #3 0x55787186b6cd in lttng_rate_policy_every_n_create actions/rate-policy.cpp:492
    #4 0x55787186a699 in lttng_rate_policy_every_n_create_from_payload actions/rate-policy.cpp:220
    #5 0x55787186ad02 in lttng_rate_policy_create_from_payload(lttng_payload_view*, lttng_rate_policy**) actions/rate-policy.cpp:287
    #6 0x557871864cae in test_rate_policy_every_n /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_rate_policy.cpp:122
    #7 0x557871865dc4 in main /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_rate_policy.cpp:249
    #8 0x7f8b61c7130f in __libc_start_call_main (/usr/lib/

SUMMARY: AddressSanitizer: 112 byte(s) leaked in 2 allocation(s).

Signed-off-by: Jérémie Galarneau <>
Change-Id: I3a9b4d99e93f355ddb8623a289f8397907486ab0

5 months agoTests: fix: leak of payload in serdes test of log level rule
Jérémie Galarneau [Fri, 15 Apr 2022 00:06:19 +0000 (20:06 -0400)] 
Tests: fix: leak of payload in serdes test of log level rule

==1190137==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f40a9d4c1b2 in __interceptor_realloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x55ab716e1def in lttng_dynamic_buffer_set_capacity(lttng_dynamic_buffer*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:159
    #2 0x55ab716e1956 in lttng_dynamic_buffer_append(lttng_dynamic_buffer*, void const*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:52
    #3 0x55ab716ca64e in lttng_log_level_rule_serialize(lttng_log_level_rule const*, lttng_payload*) /home/jgalar/EfficiOS/src/lttng-tools/src/common/log-level-rule.cpp:177
    #4 0x55ab716c760f in test_log_level_rule_serialize_deserialize /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_log_level_rule.cpp:60
    #5 0x55ab716c8457 in test_log_level_rule_at_least_as_severe_as /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_log_level_rule.cpp:177
    #6 0x55ab716c84d3 in main /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_log_level_rule.cpp:185
    #7 0x7f40a938830f in __libc_start_call_main (/usr/lib/

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f40a9d4c1b2 in __interceptor_realloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x55ab716e1def in lttng_dynamic_buffer_set_capacity(lttng_dynamic_buffer*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:159
    #2 0x55ab716e1956 in lttng_dynamic_buffer_append(lttng_dynamic_buffer*, void const*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:52
    #3 0x55ab716ca64e in lttng_log_level_rule_serialize(lttng_log_level_rule const*, lttng_payload*) /home/jgalar/EfficiOS/src/lttng-tools/src/common/log-level-rule.cpp:177
    #4 0x55ab716c760f in test_log_level_rule_serialize_deserialize /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_log_level_rule.cpp:60
    #5 0x55ab716c8135 in test_log_level_rule_exactly /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_log_level_rule.cpp:154
    #6 0x55ab716c84ce in main /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_log_level_rule.cpp:184
    #7 0x7f40a938830f in __libc_start_call_main (/usr/lib/

Signed-off-by: Jérémie Galarneau <>
Change-Id: I2d1eafabbd5c101c188bad8a2137615b29c0ef68

5 months agoTests: fix: leak of some attributes of ltt_ust_session
Jérémie Galarneau [Fri, 15 Apr 2022 00:02:18 +0000 (20:02 -0400)] 
Tests: fix: leak of some attributes of ltt_ust_session

==1175545==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8696 byte(s) in 1 object(s) allocated from:
    #0 0x7efed0f39fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x55707ddc6004 in zmalloc_internal ../../../src/common/macros.hpp:60
    #2 0x55707ddceb17 in ltt_ust_session* zmalloc<ltt_ust_session>() ../../../src/common/macros.hpp:89
    #3 0x55707ddc81e7 in trace_ust_create_session(unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/trace-ust.cpp:274
    #4 0x55707ddc2bea in test_create_one_ust_session /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_ust_data.cpp:63
    #5 0x55707ddc4941 in main /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_ust_data.cpp:283
    #6 0x7efed04f930f in __libc_start_call_main (/usr/lib/

Indirect leak of 24672 byte(s) in 1 object(s) allocated from:
    #0 0x7efed0f39fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x55707dee4ec1 in zmalloc_internal ../../../src/common/macros.hpp:60
    #2 0x55707def774e in consumer_output* zmalloc<consumer_output>() ../../../src/common/macros.hpp:89
    #3 0x55707dee90df in consumer_create_output(consumer_dst_type) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:523
    #4 0x55707ddc8821 in trace_ust_create_session(unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/trace-ust.cpp:321
    #5 0x55707ddc2bea in test_create_one_ust_session /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_ust_data.cpp:63
    #6 0x55707ddc4941 in main /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_ust_data.cpp:283
    #7 0x7efed04f930f in __libc_start_call_main (/usr/lib/

Indirect leak of 1024 byte(s) in 1 object(s) allocated from:
    #0 0x7efed0f39fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7efed0bf985f in alloc_split_items_count /home/jgalar/EfficiOS/src/userspace-rcu/src/rculfhash.c:688
    #2 0x7efed0bf985f in _cds_lfht_new /home/jgalar/EfficiOS/src/userspace-rcu/src/rculfhash.c:1642

Indirect leak of 656 byte(s) in 1 object(s) allocated from:
    #0 0x7efed0f39fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7efed0bfac68 in __default_alloc_cds_lfht ../src/rculfhash-internal.h:172
    #2 0x7efed0bfac68 in alloc_cds_lfht /home/jgalar/EfficiOS/src/userspace-rcu/src/rculfhash-mm-order.c:81

Indirect leak of 48 byte(s) in 2 object(s) allocated from:
    #0 0x7efed0f39fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7efed0bfabd4 in cds_lfht_alloc_bucket_table /home/jgalar/EfficiOS/src/userspace-rcu/src/rculfhash-mm-order.c:35
    #2 0x7efed0bfabd4 in cds_lfht_alloc_bucket_table /home/jgalar/EfficiOS/src/userspace-rcu/src/rculfhash-mm-order.c:28

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7efed0f39fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x55707de3a9af in zmalloc_internal ../../src/common/macros.hpp:60
    #2 0x55707de3a9bf in lttng_ht* zmalloc<lttng_ht>() ../../src/common/macros.hpp:89
    #3 0x55707de38461 in lttng_ht_new(unsigned long, lttng_ht_type) hashtable/hashtable.cpp:113
    #4 0x55707dee9340 in consumer_create_output(consumer_dst_type) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/consumer.cpp:535
    #5 0x55707ddc8821 in trace_ust_create_session(unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/trace-ust.cpp:321
    #6 0x55707ddc2bea in test_create_one_ust_session /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_ust_data.cpp:63
    #7 0x55707ddc4941 in main /home/jgalar/EfficiOS/src/lttng-tools/tests/unit/test_ust_data.cpp:283
    #8 0x7efed04f930f in __libc_start_call_main (/usr/lib/

Indirect leak of 16 byte(s) in 1 object(s) allocated from:
    #0 0x7efed0f39fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7efed0bfac15 in cds_lfht_alloc_bucket_table /home/jgalar/EfficiOS/src/userspace-rcu/src/rculfhash-mm-order.c:31

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ib2ad82a197f2a4ccb86ae5799c1d93ff059888e3

5 months agoFix: liblttng-ctl: leak of payload on field listing
Jérémie Galarneau [Thu, 14 Apr 2022 23:45:28 +0000 (19:45 -0400)] 
Fix: liblttng-ctl: leak of payload on field listing

LeakSanitizer reports the following leak:

==974957==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7fdb86fcd1b2 in __interceptor_realloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x7fdb86d7c296 in lttng_dynamic_buffer_set_capacity(lttng_dynamic_buffer*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:159
    #2 0x7fdb86d7c060 in lttng_dynamic_buffer_set_size(lttng_dynamic_buffer*, unsigned long) /home/jgalar/EfficiOS/src/lttng-tools/src/common/dynamic-buffer.cpp:112
    #3 0x7fdb86d2589a in recv_payload_sessiond /home/jgalar/EfficiOS/src/lttng-tools/src/lib/lttng-ctl/lttng-ctl.cpp:230
    #4 0x7fdb86d26fa5 in lttng_ctl_ask_sessiond_payload(lttng_payload_view*, lttng_payload*) /home/jgalar/EfficiOS/src/lttng-tools/src/lib/lttng-ctl/lttng-ctl.cpp:662
    #5 0x7fdb86d2cd8d in lttng_list_tracepoint_fields /home/jgalar/EfficiOS/src/lttng-tools/src/lib/lttng-ctl/lttng-ctl.cpp:1767
    #6 0x56481623cb4c in list_ust_event_fields commands/list.cpp:850
    #7 0x5648162448d9 in cmd_list(int, char const**) commands/list.cpp:2394
    #8 0x56481628fb3e in handle_command /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng/lttng.cpp:238
    #9 0x564816290601 in parse_args /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng/lttng.cpp:427
    #10 0x564816290908 in main /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng/lttng.cpp:476
    #11 0x7fdb8661730f in __libc_start_call_main (/usr/lib/

SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).

The session daemon's reply is indeed never released in

Signed-off-by: Jérémie Galarneau <>
Change-Id: Idd244b52a69f3b74e5c131c1c36c6ee6d76f4285

5 months agoFix: sessiond: ODR violation results in memory corruption
Jérémie Galarneau [Thu, 14 Apr 2022 23:01:25 +0000 (19:01 -0400)] 
Fix: sessiond: ODR violation results in memory corruption

Issue observed

Address sanitizer reports the following invalid accesses while running
the test_mi test.

❯ ASAN_OPTIONS=detect_odr_violation=0 lttng-sessiond
==289173==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60400000e280 at pc 0x55cbbe35e2e0 bp 0x7f01672f1550 sp 0x7f01672f1540
WRITE of size 4 at 0x60400000e280 thread T13
    #0 0x55cbbe35e2df in mark_thread_as_ready /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/manage-consumer.cpp:32
    #1 0x55cbbe360160 in thread_consumer_management /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/manage-consumer.cpp:267
    #2 0x55cbbe336ac4 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:66
    #3 0x7f01729c15c1 in start_thread (/usr/lib/
    #4 0x7f0172a46583 in __clone (/usr/lib/

0x60400000e280 is located 8 bytes to the right of 40-byte region [0x60400000e250,0x60400000e278)
allocated by thread T7 here:
    #0 0x7f01733b1fb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x55cbbe33adf3 in zmalloc_internal ../../../src/common/macros.hpp:60
    #2 0x55cbbe33ae03 in thread_notifiers* zmalloc<thread_notifiers>() ../../../src/common/macros.hpp:89
    #3 0x55cbbe3617f9 in launch_consumer_management_thread(consumer_data*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/manage-consumer.cpp:440
    #4 0x55cbbe33cf49 in spawn_consumer_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:188
    #5 0x55cbbe33f7cf in start_consumerd /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:394
    #6 0x55cbbe345713 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:1277
    #7 0x55cbbe34d74b in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2622
    #8 0x55cbbe336ac4 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:66
    #9 0x7f01729c15c1 in start_thread (/usr/lib/

Thread T13 created by T7 here:
    #0 0x7f0173353eb7 in __interceptor_pthread_create /usr/src/debug/gcc/libsanitizer/asan/asan_interceptors.cpp:216
    #1 0x55cbbe336f9e in lttng_thread_create(char const*, void* (*)(void*), bool (*)(void*), void (*)(void*), void*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:106
    #2 0x55cbbe3618cc in launch_consumer_management_thread(consumer_data*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/manage-consumer.cpp:453
    #3 0x55cbbe33cf49 in spawn_consumer_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:188
    #4 0x55cbbe33f7cf in start_consumerd /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:394
    #5 0x55cbbe345713 in process_client_msg /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:1277
    #6 0x55cbbe34d74b in thread_manage_clients /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2622
    #7 0x55cbbe336ac4 in launch_thread /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:66
    #8 0x7f01729c15c1 in start_thread (/usr/lib/

Thread T7 created by T0 here:
    #0 0x7f0173353eb7 in __interceptor_pthread_create /usr/src/debug/gcc/libsanitizer/asan/asan_interceptors.cpp:216
    #1 0x55cbbe336f9e in lttng_thread_create(char const*, void* (*)(void*), bool (*)(void*), void (*)(void*), void*) /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/thread.cpp:106
    #2 0x55cbbe34eebf in launch_client_thread() /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/client.cpp:2756
    #3 0x55cbbe27f31a in main /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/main.cpp:1838
    #4 0x7f017296130f in __libc_start_call_main (/usr/lib/

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/jgalar/EfficiOS/src/lttng-tools/src/bin/lttng-sessiond/manage-consumer.cpp:32 in mark_thread_as_ready
Shadow bytes around the buggy address:
  0x0c087fff9c00: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x0c087fff9c10: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x0c087fff9c20: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x0c087fff9c30: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
  0x0c087fff9c40: fa fa fd fd fd fd fd fa fa fa 00 00 00 00 00 fa
=>0x0c087fff9c50:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff9c60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff9c70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff9c80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff9c90: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c087fff9ca0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc


The start functions of the various worker threads of the session daemon
are implemented in separate translation units (TU). To make use of the
lttng_thread API, they all define different control structures to
control their shutdown.

Those structures are all named 'thread_notifiers' and are all allocated
using zmalloc<>. The various instances of zmalloc<thread_notifiers> all
end up having the same mangled name (e.g.

At link time, only one instance of zmalloc<thread_notifiers> is kept.
Since those structures all have different layout/sizes, this is
problematic. However, it is an acceptable behaviour according to the ODR

I first considered making the various memory allocation functions in
macros.hpp 'static' which results in each TU holding the appropriate
specialization of the various functions. While this works, it doesn't
make us ODR-compliant. To make a long story short, a program defining
multiple types sharing the same name, in the same namespace, is

Another concern is that marking all templated free-functions as static
will eventually result in code bloat.


All structures defined in TUs (but not in a header) are placed in
unnamed namespaces (also called anonymous namespaces) [2].

This results in separate copies of the templated functions being
generated when specialized using a structure in an anonymous
namespace (e.g. _Z7zmallocIN12_GLOBAL__N_116thread_notifiersEEPT_v).

We could have renamed the various `thread_notifiers` structures to give
them different names. However, I found those are not the only structures
sharing a name in different TUs. For instance, the same problem applies
to `struct lttng_index` (index in a stream, index in a map).

I propose we systematically namespace structures defined in TUs in the

This will also save us trouble if those POD structures eventually become
non-POD: we would experience the same "clashes" if those structures had
constructors, for example.



Signed-off-by: Jérémie Galarneau <>
Change-Id: I867e5a287ad8cf3ada617335bc1a80b800bf0833

5 months agoFix: liblttng-ctl: non-packed structure used for tracker serialization
Jérémie Galarneau [Thu, 14 Apr 2022 21:36:54 +0000 (17:36 -0400)] 
Fix: liblttng-ctl: non-packed structure used for tracker serialization

Using unpacked structures in liblttng-ctl's protocol can cause issues
when mixing sessiond and client of different bitness. In this specific
case I doubt it causes a problem, but it could rightfully do on some

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ie17096a55a4b7508c604e184cae877b83df6e451

5 months agoFix: sessiond: assert on empty payload when handling client out event
Jérémie Galarneau [Fri, 8 Apr 2022 23:34:04 +0000 (19:34 -0400)] 
Fix: sessiond: assert on empty payload when handling client out event

Observed issue

When servicing a large number of tracer notifications and sending
notifications to clients, the session daemon occasionally hits
an assertion:

  #4  0x00007fb224d7d116 in __assert_fail () from /usr/lib/
  #5  0x000056038b2fe4d7 in client_flush_outgoing_queue (client=0x7fb21400c3b0) at notification-thread-events.cpp:3586
  #6  0x000056038b2ff819 in handle_notification_thread_client_out (state=0x7fb221974090, socket=77) at notification-thread-events.cpp:4104
  #7  0x000056038b2f3d77 in thread_notification (data=0x56038cc7fe90) at notification-thread.cpp:763
  #8  0x000056038b30ca7d in launch_thread (data=0x56038cc7e220) at thread.cpp:66
  #9  0x00007fb224dcf5c2 in start_thread () from /usr/lib/
  #10 0x00007fb224e54584 in clone () from /usr/lib/


A client "out" event can be received when no payload is left
to send under some circumstances.

Many threads can flush a client's outgoing queue and, if they
had to queue their message (socket was full), will use the
"communication update" command to signal the (e)poll thread
to monitor for space being made available in the socket.

Commands are sent over an internal pipe serviced by the same
thread as the client sockets.

When space is made available in the socket, there is a race
between the (e)poll thread and the other threads that may
wish to use the client's socket to flush its outgoing queue.

A non-(e)poll thread may attempt (and succeed) in flushing
the queue before the (e)poll thread gets a chance to service
the client's "out" event.

In this situation, the (e)poll thread processing the client
out event will see an empty payload: there is nothing to do.


The (e)poll thread can simply ignore the "client out" event
when an empty payload is seen.

There is also no need to update the transmission status as
the other thread has already enqueued a "communication
update" command to do so.

Known drawbacks


Signed-off-by: Jérémie Galarneau <>
Change-Id: I8a181bea1e37e8e14cc67b624b76d139b488eded

5 months agoBump minimum kernel version to 2.6.30 to use EFD_SEMAPHORE
Jonathan Rajotte [Wed, 6 Apr 2022 19:32:44 +0000 (15:32 -0400)] 
Bump minimum kernel version to 2.6.30 to use EFD_SEMAPHORE

The bump in the kernel version allows the use of EFD_SEMAPHORE for

Adjust the to reflect this. No need to provide direct
instruction for older kernel. We leave the '--disable-epoll' switch
available and the code behind it simply because other platform might not
have epoll available.

Signed-off-by: Jonathan Rajotte <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: Id512f018c5394c9cc699e19c3d5a0d753e56414b

5 months agoFix: Revert of 814b4934e2604a419bcb8eec57c0450dbb47e2c3
Jonathan Rajotte [Wed, 6 Apr 2022 13:17:38 +0000 (09:17 -0400)] 
Fix: Revert of 814b4934e2604a419bcb8eec57c0450dbb47e2c3

Observed issue

During high throughput event notification generation scenarios the
following deadlock happens:

 Thread 14 (Thread 0x7f74b4ff9700 (LWP 76062)):
 #0  __lll_lock_wait (futex=futex@entry=0x56408765dde8, private=0) at lowlevellock.c:52
 #1  0x00007f74c941a0a3 in __GI___pthread_mutex_lock (mutex=0x56408765dde8) at ../nptl/pthread_mutex_lock.c:80
 #2  0x000056408704b207 in run_command_wait (handle=0x56408765ddd0, cmd=0x7f74b4ff7f70) at notification-thread-commands.cpp:31
 #3  0x000056408704bcef in notification_thread_command_remove_tracer_event_source (handle=0x56408765ddd0, tracer_event_source_fd=54) at notification-thread-commands.cpp:319
 #4  0x000056408708a0c1 in delete_ust_app (app=0x7f749c000bf0) at ust-app.cpp:1059
 #5  0x000056408708a511 in delete_ust_app_rcu (head=0x7f749c000ca0) at ust-app.cpp:1122
 #6  0x00007f74c988b4a7 in call_rcu_thread (arg=0x7f74b8004a80) at ../src/urcu-call-rcu-impl.h:369
 #7  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #8  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 13 (Thread 0x7f74b57fa700 (LWP 76047)):
 #0  0x00007f74c933a49e in epoll_wait (epfd=48, events=0x7f74a4000b60, maxevents=2, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
 #1  0x00005640870eafa6 in compat_epoll_wait (events=0x7f74b57f9240, timeout=-1, interruptible=false) at compat/poll.cpp:280
 #2  0x00005640870abb65 in thread_agent_management (data=0x56408765f0b0) at agent-thread.cpp:424
 #3  0x0000564087062b1a in launch_thread (data=0x56408765f150) at thread.cpp:66
 #4  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #5  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 12 (Thread 0x7f74b5ffb700 (LWP 76046)):                                                                                                                                       [630/709]
 #0  0x00007f74c933a49e in epoll_wait (epfd=47, events=0x7f74a0000b60, maxevents=2, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
 #1  0x00005640870eafa6 in compat_epoll_wait (events=0x7f74b5ffa170, timeout=-1, interruptible=false) at compat/poll.cpp:280
 #2  0x00005640870a4095 in thread_application_notification (data=0x56408765ee40) at notify-apps.cpp:78
 #3  0x0000564087062b1a in launch_thread (data=0x56408765eed0) at thread.cpp:66
 #4  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #5  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 11 (Thread 0x7f74b67fc700 (LWP 76045)):
 #0  0x00007f74c933a49e in epoll_wait (epfd=44, events=0x7f74ac000b60, maxevents=2, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
 #1  0x00005640870eafa6 in compat_epoll_wait (events=0x7f74b67fb170, timeout=-1, interruptible=false) at compat/poll.cpp:280
 #2  0x00005640870723db in thread_application_management (data=0x56408765ebd0) at manage-apps.cpp:93
 #3  0x0000564087062b1a in launch_thread (data=0x56408765ec60) at thread.cpp:66
 #4  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #5  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 10 (Thread 0x7f74b6ffd700 (LWP 76044)):
 #0  0x00007f74c933a49e in epoll_wait (epfd=39, events=0x7f74a8000b60, maxevents=2, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
 #1  0x00005640870eafa6 in compat_epoll_wait (events=0x7f74b6ffc130, timeout=-1, interruptible=false) at compat/poll.cpp:280
 #2  0x0000564087070a27 in thread_application_registration (data=0x56408765e940) at register.cpp:214
 #3  0x0000564087062b1a in launch_thread (data=0x56408765e9f0) at thread.cpp:66
 #4  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #5  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 9 (Thread 0x7f74b77fe700 (LWP 76043)):                                                                                                                                        [654/709]
 #0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
 #1  0x00005640870c8e25 in futex (uaddr=0x5640871e2800 <ust_cmd_queue>, op=0, val=-1, timeout=0x0, uaddr2=0x0, val3=0) at /home/joraj/lttng/master/install/include/urcu/futex.h:72
 #2  0x00005640870c8e6d in futex_async (uaddr=0x5640871e2800 <ust_cmd_queue>, op=0, val=-1, timeout=0x0, uaddr2=0x0, val3=0) at /home/joraj/lttng/master/install/include/urcu/futex.h:104
 #3  0x00005640870c939a in futex_nto1_wait (futex=0x5640871e2800 <ust_cmd_queue>) at futex.cpp:77
 #4  0x000056408706f2af in thread_dispatch_ust_registration (data=0x56408765e740) at dispatch.cpp:453
 #5  0x0000564087062b1a in launch_thread (data=0x56408765e760) at thread.cpp:66
 #6  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #7  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 8 (Thread 0x7f74b7fff700 (LWP 76042)):
 #0  0x00007f74c933a49e in epoll_wait (epfd=33, events=0x7f74b0000b60, maxevents=2, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
 #1  0x00005640870eafa6 in compat_epoll_wait (events=0x7f74b7ffad40, timeout=-1, interruptible=false) at compat/poll.cpp:280
 #2  0x000056408706c424 in thread_manage_clients (data=0x56408765e4f0) at client.cpp:2528
 #3  0x0000564087062b1a in launch_thread (data=0x56408765e560) at thread.cpp:66
 #4  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #5  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 7 (Thread 0x7f74c4b8f700 (LWP 76041)):                                                                                                                                        [672/709]
 #0  0x00007f74c933a49e in epoll_wait (epfd=31, events=0x7f74bc000b60, maxevents=3, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
 #1  0x00005640870eafa6 in compat_epoll_wait (events=0x7f74c4b8e240, timeout=-1, interruptible=false) at compat/poll.cpp:280
 #2  0x000056408705f2b6 in thread_rotation (data=0x56408765e280) at rotation-thread.cpp:804
 #3  0x0000564087062b1a in launch_thread (data=0x56408765e310) at thread.cpp:66
 #4  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #5  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 6 (Thread 0x7f74c5390700 (LWP 76040)):
 #0  0x00007f74c925f1d2 in __GI___sigtimedwait (set=0x7f74c538f090, info=0x7f74c538f110, timeout=0x0) at ../sysdeps/unix/sysv/linux/sigtimedwait.c:29
 #1  0x000056408706138a in thread_timer (data=0x7ffc1fcbe3f0) at timer.cpp:359
 #2  0x0000564087062b1a in launch_thread (data=0x56408765e0a0) at thread.cpp:66
 #3  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #4  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 5 (Thread 0x7f74c5b91700 (LWP 76039)):
 #0  __libc_write (nbytes=8, buf=0x7f74c5b8fc88, fd=24) at ../sysdeps/unix/sysv/linux/write.c:26
 #1  __libc_write (fd=24, buf=0x7f74c5b8fc88, nbytes=8) at ../sysdeps/unix/sysv/linux/write.c:24
 #2  0x00005640870eeb4f in lttng_write (fd=24, buf=0x7f74c5b8fc88, count=8) at readwrite.cpp:77
 #3  0x000056408704b535 in run_command_no_wait (handle=0x56408765ddd0, in_cmd=0x7f74c5b8fdf0) at notification-thread-commands.cpp:92
 #4  0x000056408704bf49 in notification_thread_client_communication_update (handle=0x56408765ddd0, id=2, transmission_status=CLIENT_TRANSMISSION_STATUS_QUEUED) at notification-thread-command
 #5  0x000056408707bc62 in client_handle_transmission_status (client=0x7f74b80050d0, status=CLIENT_TRANSMISSION_STATUS_QUEUED, user_data=0x7f74b8004410) at action-executor.cpp:258
 #6  0x0000564087057525 in notification_client_list_send_evaluation (client_list=0x7f74b8004df0, trigger=0x7f74b0001030, evaluation=0x7f74b815d1d0, source_object_creds=0x0, client_report=0x5
 #7  0x000056408707bce9 in action_executor_notify_handler (executor=0x7f74b8004410, work_item=0x7f74b815d430, item=0x7f74b80e48e0) at action-executor.cpp:269
 #8  0x000056408707dd6d in action_executor_generic_handler (executor=0x7f74b8004410, work_item=0x7f74b815d430, item=0x7f74b80e48e0) at action-executor.cpp:670
 #9  0x000056408707df01 in action_work_item_execute (executor=0x7f74b8004410, work_item=0x7f74b815d430) at action-executor.cpp:689

 #10 0x000056408707e525 in action_executor_thread (_data=0x7f74b8004410) at action-executor.cpp:771                                                                                   [698/709]
 #11 0x0000564087062b1a in launch_thread (data=0x7f74b80044b0) at thread.cpp:66
 #12 0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #13 0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 4 (Thread 0x7f74c6392700 (LWP 76038)):
 #0  __lll_lock_wait (futex=futex@entry=0x56408765dde8, private=0) at lowlevellock.c:52
 #1  0x00007f74c941a0a3 in __GI___pthread_mutex_lock (mutex=0x56408765dde8) at ../nptl/pthread_mutex_lock.c:80
 #2  0x0000564087053c89 in handle_notification_thread_command (handle=0x56408765ddd0, state=0x7f74c63911b0) at notification-thread-events.cpp:3142
 #3  0x000056408704ac81 in thread_notification (data=0x56408765ddd0) at notification-thread.cpp:715
 #4  0x0000564087062b1a in launch_thread (data=0x56408765dec0) at thread.cpp:66
 #5  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #run_command_no_wait6  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 3 (Thread 0x7f74c6b93700 (LWP 76037)):
 #0  0x00007f74c933a49e in epoll_wait (epfd=21, events=0x7f74c0000b60, maxevents=2, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
 #1  0x00005640870eafa6 in compat_epoll_wait (events=0x7f74c6b92170, timeout=-1, interruptible=false) at compat/poll.cpp:280
 #2  0x000056408706400a in thread_manage_health (data=0x56408765db50) at health.cpp:140
 #3  0x0000564087062b1a in launch_thread (data=0x56408765dbf0) at thread.cpp:66
 #4  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #5  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 2 (Thread 0x7f74c7394700 (LWP 76036)):
 #0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
 #1  0x00007f74c987d238 in futex (uaddr=0x564087659b10, op=0, val=-1, timeout=0x0, uaddr2=0x0, val3=0) at ../include/urcu/futex.h:72
 #2  futex_async (uaddr=0x564087659b10, op=0, val=-1, timeout=0x0, uaddr2=0x0, val3=0) at ../include/urcu/futex.h:104
 #3  futex_wait (futex=0x564087659b10) at workqueue.c:136
 #4  0x00007f74c987ced2 in workqueue_thread (arg=0x564087659ad0) at workqueue.c:237
 #5  0x00007f74c9417609 in start_thread (arg=<optimized out>) at pthread_create.c:477
 #6  0x00007f74c933a163 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

 Thread 1 (Thread 0x7f74c73cd300 (LWP 76034)):
 #0  0x00007f74c933a49e in epoll_wait (epfd=50, events=0x564087666880, maxevents=1, timeout=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
 #1  0x00005640870eafa6 in compat_epoll_wait (events=0x7ffc1fcbe280, timeout=-1, interruptible=false) at compat/poll.cpp:280
 #2  0x0000564087062244 in sessiond_wait_for_quit_pipe (timeout_ms=-1) at thread-utils.cpp:83
 #3  0x00005640870127dc in main (argc=1, argv=0x7ffc1fcbe668) at main.cpp:1921


The event_pipe used to notify the notification poll loop is full and the
lttng_write call blocks with the locks for both the client and the
cmd_queue held.


Go back to using eventfd but without the use of EFD_SEMAPHORE (linux
2.6.30) to continue supporting kernel between 2.6.27 and 2.6.29.

The EFD_SEMAPHORE is emulated with a read, decrement, write as explained
by the initial committer of EFD_SEMAPHORE [1].

Known drawbacks

This does not solve the actual block+lock problem but simply push it
back further. The lttng_write on the eventfd can block when reaching
UINT64_MAX. This would represent, at 1 command queued per ns (which is
ridiculous), ~584 years of queueing without a dequeue operation.


Signed-off-by: Jonathan Rajotte <>
Signed-off-by: Jérémie Galarneau <>
Change-Id: Ie749c4169708f57463fe3cfab2366f1015bae4e0

5 months agoBuild fix: missing type traits on gcc < 5.0
Jérémie Galarneau [Fri, 8 Apr 2022 19:09:16 +0000 (15:09 -0400)] 
Build fix: missing type traits on gcc < 5.0

gcc versions before 5.0 lack some type traits defined in C++11. Since in
this instance we use the trait to prevent misuses of certain functions
to statically assert at build time and not to generate different code
based on this property, it is preferable to simply set value to true and
allow the code to compile. Anyone using a contemporary compiler will
catch the error.

I have not replaced the type trait checks with macros using gcc-specific
checks (__has_trivial_copy(), for example) since their semantics diverge
subtly from the standard and their use could introduce bugs.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Id57cc1cff67847c725f75eb3404443732de1c531

5 months agoBuild fix: poll compatibility mode: zmalloc prototype changed
Jérémie Galarneau [Fri, 8 Apr 2022 18:22:11 +0000 (14:22 -0400)] 
Build fix: poll compatibility mode: zmalloc prototype changed

The build fails on platforms that don't support the epoll system
call (or when building with --disable-epoll on Linux):

  compat/poll.cpp:458:35: error: no matching function for call to 'zmalloc'
          wait->events = (struct pollfd *) zmalloc(size * sizeof(struct pollfd));
  ./macros.hpp:85:4: note: candidate template ignored: couldn't infer template argument 'T'
  T *zmalloc(size_t size)
  ./macros.hpp:74:4: note: candidate function template not viable: requires 0 arguments, but 1 was provided
  T *zmalloc()
  compat/poll.cpp:466:38: error: no matching function for call to 'zmalloc'
          current->events = (struct pollfd *) zmalloc(size * sizeof(struct pollfd));
  ./macros.hpp:85:4: note: candidate template ignored: couldn't infer template argument 'T'
  T *zmalloc(size_t size)
  ./macros.hpp:74:4: note: candidate function template not viable: requires 0 arguments, but 1 was provided
  T *zmalloc()

Replace the uses of "old style" malloc with the new type-safe
function introduced recently.

Signed-off-by: Jérémie Galarneau <>
Change-Id: Ib1660f6a548c155f021843b7476d5d64c06c6e5a

This page took 0.100837 seconds and 4 git commands to generate.