lttng-tools.git
3 years agoaction executor: use an execution context to validate enqueued action before execution
Jonathan Rajotte [Tue, 13 Apr 2021 18:49:52 +0000 (14:49 -0400)] 
action executor: use an execution context to validate enqueued action before execution

Problem
======

Let's walk over the following scenario:

Trigger my_trigger:
  condition: ust event a
  action: start session S

At time T, session S exists.

At T + 1, the event A is hit.

At T + 2, the tracer event notification is received and the work item is
queued. Here session S have an id of 1.

At T + 3, the session S is destroyed and a new session S is created,
with a resulting id of 200.

At T +4, the work item is popped from the queue and begin execution and
will start session S with an id of 200 instead of the session S id 1
that was present at the queuing phase.

We effectively want to assign an execution context to an action at the
queuing phase and validate that the execution context is still valid
upon actual execution.

Solution
=====

Instead of iterating over the trigger's actions, we prepare an array of
work sub-item (action_work_subitem) that effectively is a flattened and
augmented array of the trigger's action. For now only the session id is
an action level execution context.

Each action handler is responsible of validating the execution context
before performing the action.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I72fbe8d52d77d1d696fa7d99b662b77e9dad02d5

3 years agotrigger/action executor: move trigger registration state change to client thread
Jonathan Rajotte [Mon, 12 Apr 2021 20:38:16 +0000 (16:38 -0400)] 
trigger/action executor: move trigger registration state change to client thread

Set the unregistered state of the sessiond side trigger object in the
client thread since we want to minimize the possibility of the
notification thread being stalled due to a long execution of an action
in the action executor thread.

Stalling the client thread is, comparatively, less harmful.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7de875996b430e49ec50896f8b26a75af7993c74

3 years agonotification-thread: add `GET_TRIGGER` command
Francis Deslauriers [Mon, 8 Mar 2021 22:19:51 +0000 (17:19 -0500)] 
notification-thread: add `GET_TRIGGER` command

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ifc94ea894999b9da796aa4fda0d929d237e12d3e

3 years agoaction executor: execute action only if the associated trigger is registered
Jonathan Rajotte [Mon, 12 Apr 2021 19:41:36 +0000 (15:41 -0400)] 
action executor: execute action only if the associated trigger is registered

It was decided that a trigger removal should have immediate effect and
not result in a waiting on action queued to be executed.

There was two major way to do this:

1) On unregistrer trigger, lock the action executor queue and remove
all work-item related to the trigger ebing unregistered.

2) Mark the trigger as "unregistered" and validate its state when a work
item is ready for execution. If the trigger is marked as "unregistered",
simply consume and skip the work item.

To isolate the un-registration and the execution of a work item
depending on that trigger, we use the trigger lock to have exclusivity
during the execution for that trigger.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9f42a323e0ec0dc51339f39f07536ec8060dc02a

3 years agotrigger: keep state of if a trigger is currently registered
Jonathan Rajotte [Mon, 12 Apr 2021 18:45:24 +0000 (14:45 -0400)] 
trigger: keep state of if a trigger is currently registered

Since a trigger can be referenced even when is was "unregistered" in
other part of lttng-sessiond, namely the action executor queue, we must
keep track of the registration state.

This will allows us to easily skip any actions to be executed
if the associated trigger is "unregistered" at the moment of
execution. This is implemented in a following patch.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I06c9d437fce975c9c8393e8d1be3e66a24618af3

3 years agoTests: fix: leak of notification-client arguments
Jérémie Galarneau [Sat, 17 Apr 2021 22:47:16 +0000 (18:47 -0400)] 
Tests: fix: leak of notification-client arguments

Valgrind reports the following leaks:

==334435== HEAP SUMMARY:
==334435==     in use at exit: 8,568 bytes in 24 blocks
==334435==   total heap usage: 846 allocs, 822 frees, 1,425,964 bytes allocated
==334435==
==334435== 9 bytes in 1 blocks are definitely lost in loss record 1 of 11
==334435==    at 0x483E77F: malloc (vg_replace_malloc.c:307)
==334435==    by 0x4BCC5BE: strdup (in /usr/lib/libc-2.33.so)
==334435==    by 0x10A48B: main (notification-client.c:123)
==334435==
==334435== 13 bytes in 1 blocks are definitely lost in loss record 2 of 11
==334435==    at 0x483E77F: malloc (vg_replace_malloc.c:307)
==334435==    by 0x4BCC5BE: strdup (in /usr/lib/libc-2.33.so)
==334435==    by 0x10A473: main (notification-client.c:120)
==334435==
==334435== 27 bytes in 1 blocks are definitely lost in loss record 3 of 11
==334435==    at 0x483E77F: malloc (vg_replace_malloc.c:307)
==334435==    by 0x4BCC5BE: strdup (in /usr/lib/libc-2.33.so)
==334435==    by 0x10A444: main (notification-client.c:114)

Free the strdup()'ed' arguments.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I21523e847141aef50858d3018f37f0125dee0e2c

3 years agotests: trigger action firing policy
Jonathan Rajotte [Tue, 30 Mar 2021 02:00:37 +0000 (22:00 -0400)] 
tests: trigger action firing policy

Implements the regression tests for the trigger action firing polices.

For now the focus is put on the notify action behavior. In the future,
the ability to fetch the number of time an action was enqueued for
execution and the number of type it was executed should greatly
facilitate this work. For now, use the notify action for minimal
regression testing.

gen-ust-events is modified to allow a caller to specify that an `end`
event should be emitted at the end of the program. This is used to
guaranteed that all previous event tracer notifications should be
received when the `end` event notification is received. Note that
ordering is guaranteed for delivery of tracer notification and
notification for a given process.

notificiation-client is modified to allow reception of N notifications
and to validate that it received the count it expects.

notificiation-client is modified to allow reception of N notifications
and to exit only when an `end` event notification is received. This
allow us validate the firing policy.

The tests are pretty straightforward. We register 2 triggers, one with
an event rule condition on `tp:tptest` and the other one with a event
rule condition on `tp:end`. From there we perform a phase of event hits
were we expect no notification except for the `tp:end` then we force a
single event hit were we expect a notification for `tp:tptest`. For the
fire every N policy, we rinse and repeat to validate the behaviour. For
the once after N, we simply do a third phase were we generate N events
and expect no notification.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ia3c88f38dcca0389165e1416b06768338b2889b6

3 years agoMove firing policy from lttng_trigger to lttng_action
Jonathan Rajotte [Tue, 30 Mar 2021 01:43:12 +0000 (21:43 -0400)] 
Move firing policy from lttng_trigger to lttng_action

After some reflection on the future of the importance of the trigger
feature and the centralization we wish to carry around it, it is
required that the notion of firing policy be moved from the trigger
object to each action object of a trigger.

This is necessary since we plan on introducing tracer side actions, such
as increment value of map. Controlling the firing policy on the tracer
side is not an easy thing to do since for UST tracing a lot a
synchronizations must take place and also we must define the behaviour
when multiple apps are present. Hence, we need a way to ensure that we
are not painting ourself in a corner. The middle ground that was chosen
was to move the notion of firing policy to the action object level. This
allows us to scope the concept to the action and decide for each type if
firing policy can be supported and, as needed, define the behaviour per
action type.

Essentially this patch perform the complete transition. It removes the
notion of firing policy at the trigger level and exposes the firing
policy of each action type if applicable.

CLI
======

For the `add-trigger` command the change essentially boils down to
moving the `--fire-every` and `--fire-once-after` from a top-level
parsing to the parsing of each actions. Yes, for now all actions
supports the `--fire-*` options but it will not be the case in the
future. A side effect of this is that a user could decide to have
different firing policy for each actions, but this also mean that if a
user want to apply the same firing policy across actions, the user needs
to specify it for each actions. This could be solved in the future as
the trigger feature matures and that common ground are found in the
behaviour or implementation of the actions (tracer side action, async
action, sync actions etc.) such that "syntactic sugar" options emerge.

As for the `list-trigger`, we move the firing policy printing to each
actions.

Tests have been updated to reflect the changes.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib29d4319922096c0c4b3f00782f3bbefb17e2f40

3 years agoaction-executor: consider action firing policy on action execution
Jonathan Rajotte [Wed, 7 Apr 2021 13:19:18 +0000 (09:19 -0400)] 
action-executor: consider action firing policy on action execution

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I83f73e905e87a401187e243ed3beafa41964434a

3 years agotest: unit: snapshot session action
Jonathan Rajotte [Thu, 8 Apr 2021 19:48:39 +0000 (15:48 -0400)] 
test: unit: snapshot session action

Note that the introduced test are mostly toward the firing policy
parameter.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7685610f963576e50747a1801c4e0cd754e241b8

3 years agoImplement firing policy for the snapshot session action
Jonathan Rajotte [Thu, 8 Apr 2021 17:51:35 +0000 (13:51 -0400)] 
Implement firing policy for the snapshot session action

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ia849bf101cbdf09977adc0781809139a3c769ab2

3 years agotests: units: action: stop session
Jonathan Rajotte [Thu, 8 Apr 2021 13:35:05 +0000 (09:35 -0400)] 
tests: units: action: stop session

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib8b230857180966085d682a29e54f6baa525258f

3 years agoImplement firing policy for stop session action
Jonathan Rajotte [Thu, 8 Apr 2021 13:34:43 +0000 (09:34 -0400)] 
Implement firing policy for stop session action

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iaed5d8c3cc59b2284692ed56f1b4a8ba69736fd6

3 years agotests: unit: action: start_session
Jonathan Rajotte [Thu, 8 Apr 2021 13:14:22 +0000 (09:14 -0400)] 
tests: unit: action: start_session

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie224592426d286b6abd4c7b627853bef71862bb8

3 years agoImplement firing policy for the start session action
Jonathan Rajotte [Thu, 8 Apr 2021 13:14:06 +0000 (09:14 -0400)] 
Implement firing policy for the start session action

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ica842dbd9980e8dbf73e38cbb1136115394c001c

3 years agotests: unit: action: rotate_session
Jonathan Rajotte [Thu, 8 Apr 2021 01:17:13 +0000 (21:17 -0400)] 
tests: unit: action: rotate_session

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib412196dea5cb9617b4c56e8eb93698bcfaa40d7

3 years agoImplement firing policy for the rotate session action
Jonathan Rajotte [Thu, 8 Apr 2021 01:02:31 +0000 (21:02 -0400)] 
Implement firing policy for the rotate session action

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I0e2b50d6653cca7a33abc6ee68bed237950476a9

3 years agotests: unit: action: notify
Jonathan Rajotte [Fri, 9 Apr 2021 14:59:09 +0000 (10:59 -0400)] 
tests: unit: action: notify

Note: the added tests are mostly toward testing of the firing policy
parameter.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I2aec17175ac2fed4cf21a15f998b24dfd353e77b

3 years agoImplement firing policy for the notify action
Jonathan Rajotte [Fri, 9 Apr 2021 01:40:12 +0000 (21:40 -0400)] 
Implement firing policy for the notify action

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I40b25033868fd4ec9cb6764f3c47ef3e006bec3e

3 years agoMove test_action to its own file
Jonathan Rajotte [Fri, 9 Apr 2021 14:58:34 +0000 (10:58 -0400)] 
Move test_action to its own file

Further unit testing on action objects will be conducted in the
test_action.c file.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib17aed9eb02592d5c13bc2875d4203b81ab04cf3

3 years agotests: unit: add firing policy tests
Jonathan Rajotte [Tue, 6 Apr 2021 15:09:09 +0000 (11:09 -0400)] 
tests: unit: add firing policy tests

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ib92bd40b2c93f4e90ec430f2ac70ef2a5ce8f891

3 years agoIntroduce firing policy object
Jonathan Rajotte [Fri, 2 Apr 2021 01:20:23 +0000 (21:20 -0400)] 
Introduce firing policy object

Change-Id: I436ce58d083cd70178a51d0d9ebfddc814f2cd15
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoFix: test: start-stop trigger: test execution is invalid
Jonathan Rajotte [Tue, 30 Mar 2021 01:38:54 +0000 (21:38 -0400)] 
Fix: test: start-stop trigger: test execution is invalid

Observed issue
==============

The test expects the notification client to be a background process but
`&` is not used.

The notification client is expected to sync with its launcher via the
sync file but the invocation of mktemp already creates the file.

Solution
=======

Use `&` and `mktemp -u`.

While there a little cleanup in notification_client for error code path
was done.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iba80413d6ca36989cd967895d3330860cb4ef614

3 years agoFix: sessiond: session destroy hang in per-uid when context cannot be added
Jonathan Rajotte [Mon, 15 Mar 2021 21:52:24 +0000 (17:52 -0400)] 
Fix: sessiond: session destroy hang in per-uid when context cannot be added

Observed issue
==============

The system_test CI jobs hang on the perf test suite during the destroy
command steps of the ust perf raw subtest.

Cause
=====

The system_test are running inside a kvm as root. It turns out that the
PMU (UNHALTED_REFERENCE_CYCLES) the test suite is trying to add is
unavailable on the qemu host.

ustctl_add_context return -1024 since it fails to add the context.

This leads us down the error path for the callstack leading to the
ustctl_add_context call.

1) `ust_app_channel_create` returns `ret` != 0;
2) `find_or_create_ust_app_channel` returns `ret != 0`;
3) `ust_app_synchronize` based on the `ret` value goes directly to the
    end of the function to an error path without passing on the
    `create_ust_app_metadata` function and clean-up structure related to
    the app.

Note that being in per-uid mode, data and metadata
channel/streams/buffer allocation is done on the fly for the first app
during `ust_app_synchronize` and its callee. For the current problematic
scenario, only the data channels have been allocated on the consumer for
the uid at that point. The metadata for that uid is not yet created.

Now that we know more of what is going on during an ""add context""
let's take a look at the actual hang.

The client never complete the destroy command since the consumerd
indicates that the trace chunk for the session is not closed. The trace
chunk still exists despite the fact that a close chunk command has been
issued. This is the case since its refcount never reaches zero and thus
the release does not complete.

In a normal execution without the use of contexts, the release of the
trace hunk (refcount == 0) occurs during the final rotation on destroy.

Upon further comparison between a working execution and a non-working
execution, in a non-working execution the `cmd_rotate_session` does not
issue the rotation for the data channels since the loop detects that no
metadata is present. Which, as we discussed earlier, can happen if we
fail to add the context to the app channel.

[1]
```
  cds_list_for_each_entry(reg, &usess->buffer_reg_uid_list, lnode) {
    struct buffer_reg_channel *reg_chan;
    struct consumer_socket *socket;

    if (!reg->registry->reg.ust->metadata_key) {
      /* Skip since no metadata is present */
      continue;
    }

    ....

    /* Rotate the data channels. */
    cds_lfht_for_each_entry(reg->registry->channels->ht, &iter.iter,
        reg_chan, node.node) {
      ret = consumer_rotate_channel(socket,
          reg_chan->consumer_key,
          usess->uid, usess->gid,
          usess->consumer,
          /* is_metadata_channel */ false);
      if (ret < 0) {
        cmd_ret = LTTNG_ERR_ROTATION_FAIL_CONSUMER;
        goto error;
      }
    }

    ....
  }
```

Solution
========

Move the metadata check after the data channel rotation since it is
possible to have data channels but no metadata channel, although it is a
corner case.

Note that per-pid mode and kernel are not affected by the current bug
since a complete teardown of all objects is done. This only affect
per-uid due to the "on the fly" allocation nature of it since we need to
share the channel/stream/buffers across apps.

Known drawbacks
=========

None.

References
==========
[1] https://github.com/lttng/lttng-tools/blob/3d1384a4add389c38f8554130e8dec2e2d06009d/src/bin/lttng-sessiond/ust-app.c#L7057

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie8fd1167170706ec9abc5f31f3b33a7306e92cd9

3 years agoFix: backward relayd: path contains a leading "ust" folder
Jonathan Rajotte [Wed, 13 Jan 2021 15:09:06 +0000 (10:09 -0500)] 
Fix: backward relayd: path contains a leading "ust" folder

Observed issue
==============

test_output_path_relayd[lttng-tools-2.13-lttng-tools-2.10-uid] from
the lttng-ivc fails on path validation for the resulting trace.

Here lttng-sessiond is 2.13 and lttng-relayd is 2.10

Traces are generated and the following hierarchy is found in the
lttng-relayd trace folder.

 lttng_home
         └── lttng-traces
*            └── ust
                 └── joraj-alpa
                     ├── auto-20210113-165054
                     │   └── ust
                     │       └── uid

Note the extra "ust" (*) in the hierarchy.

The tests expects:
 lttng_home
         └── lttng-traces
                 └── joraj-alpa
                     ├── auto-20210113-165054
                     │   └── ust
                     │       └── uid

Cause
=====

Introduced by: 5da88b0f58d7f838068037ea449ddfb25d3e85ad [1]

relayd_add_stream now suffixes the domain_name to the pathname.
This is only necessary for cases where the corresponding
lttng-relayd version is greater than 2.10. In other cases, modification
of pathname is not necessary.

Solution
========

Perform domain suffixing only for relayd > 2.10.

Known drawbacks
=========

None.

References
==========

[1] https://github.com/lttng/lttng-tools/commit/5da88b0f58d7f838068037ea449ddfb25d3e85ad

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iaca4667074aaf7f4f20b50ddb4778fbc02156b5a

3 years agoFix: lttng_destroy_session_no_wait: return 0 on success
Christophe Bedard [Fri, 28 Aug 2020 15:00:30 +0000 (11:00 -0400)] 
Fix: lttng_destroy_session_no_wait: return 0 on success

lttng_destroy_session_no_wait() is supposed to behave like
lttng_destroy_session():

> Return 0 on success else a negative LTTNg error code.

However, it returns LTTNG_OK on success. Make it return 0 instead.

Signed-off-by: Christophe Bedard <christophe.bedard@apex.ai>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If51f6a2cc3ca77237f7cbac806c5206a807dadf5

3 years agoFix: notification: client with uid != trigger uid assert on gid check
Jonathan Rajotte [Wed, 3 Mar 2021 20:45:11 +0000 (15:45 -0500)] 
Fix: notification: client with uid != trigger uid assert on gid check

The gid was removed from the trigger object since gid is not an exposed
control measure anywhere in lttng except for the "tracing" group and
lttng-sessiond to client communication.

Also based on this:

 /*
 * As for privilieged users, they can register triggers against the objects of
 * other users. They can then subscribe to the notifications associated to their
 * triggers. Privilieged users _can't_ subscribe to the notifications of
 * triggers owned by other users; they must create their own triggers.
 * /

This is why the current check is not bypassed if the notification client
have a UID == 0 (root).

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I690ea355b0b1ab0bfe82b7db47275876afe622f2

3 years agoevent-rule: Normalize pattern for syscall and tracepoint
Jonathan Rajotte [Thu, 4 Mar 2021 21:10:18 +0000 (16:10 -0500)] 
event-rule: Normalize pattern for syscall and tracepoint

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If5bae2cd5df76db3f9bd626f95fcace114fcc420

3 years agoconfig: accept "0" and "1" as XML boolean values
Simon Marchi [Fri, 2 Apr 2021 19:52:46 +0000 (15:52 -0400)] 
config: accept "0" and "1" as XML boolean values

These are valid values when validating a "boolean" using a schema (XSD).
Somebody could therefore write a file with

    <started>0</started>

instead of

    <started>false</started>

The file would validate against session.xsd, but we would fail after
that:

    Warning: Invalid boolean value encoutered (0).
    Error: Invalid session configuration

Reference: https://www.w3.org/TR/xmlschema11-2/#boolean

Change-Id: Icea85b13233ec01aa09ef3b578906f4c0e482088
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoconfig: fix typo in error message
Simon Marchi [Fri, 2 Apr 2021 19:52:27 +0000 (15:52 -0400)] 
config: fix typo in error message

Change-Id: Ie02ccd1e79aecb87fbb9c308ffba09353d50b8f3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoCleanup: reuse `lttng_action_type_string()` to print action names
Francis Deslauriers [Fri, 19 Mar 2021 20:11:40 +0000 (16:11 -0400)] 
Cleanup: reuse `lttng_action_type_string()` to print action names

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I86be1201466a11510ded9da34311650a8aadd1e2

3 years agoTests: array expressions without contant index are invalid
Mathieu Desnoyers [Mon, 25 May 2020 20:19:18 +0000 (16:19 -0400)] 
Tests: array expressions without contant index are invalid

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I121387b63eb85851be59416c758b7ca12f823f45

3 years agoFix: validate that array expression contains constant
Mathieu Desnoyers [Mon, 25 May 2020 20:15:40 +0000 (16:15 -0400)] 
Fix: validate that array expression contains constant

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ic7ea2192b3bf0f5c32f5db8fce622f73b182906f

3 years agoFix: test: base-path tests are not run
Jonathan Rajotte [Wed, 2 Dec 2020 22:01:35 +0000 (17:01 -0500)] 
Fix: test: base-path tests are not run

Observed issue
==============

The base-path tests are never run during `make check`.

Cause
=====

Albeit 2a1668643ca94195d5c3889d0337e19165805a42 [1] introduces the tests,
the test file is not added to the test list.

Solution
========

Add the test file to the test list.

One of the substest is failing.

  not ok 20 - Snapshot recorded
  #   Failed test 'Snapshot recorded'
  #   in .//../../../utils/utils.sh:lttng_snapshot_record() at line 1468.
  ok 21 - Destroy session ust_app_snapshot_base_path
  not ok 22 - Validate trace for event tp:tptest

This is caused by the removal of `trace_path=$2` in
c28fcefd993b7539716bb5cd9557a08a217ec463 [2]. The removal is most
probably a merge error or simply a mistake on my end. This commit revert
that change.

Also add load-stream-extra-path.lttng in EXTRA_DIST.

Known drawbacks
=========

None

References
==========
[1] https://github.com/lttng/lttng-tools/commit/2a1668643ca94195d5c3889d0337e19165805a42
[2] https://github.com/lttng/lttng-tools/commit/2a1668643ca94195d5c3889d0337e19165805a42

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9a8040141c29e391363b17954a20155abdb3cc04

3 years agoFix: tests: handling of subprocesses on bail out
Jonathan Rajotte [Wed, 17 Feb 2021 14:19:50 +0000 (09:19 -0500)] 
Fix: tests: handling of subprocesses on bail out

Observed issue
==============

Background processes of the test_notification_ust tests are present on CI
worker after the jobs is finished.

Cause
=====

The usage of BAIL_OUT during the notap version of stop lttng-sessiond
would end up preventing the normal cleanup of background processes since
we exit directly when issuing the bail out.

Solution
========

Introduce LTTNG_BAIL_OUT.

LTTNG_BAIL_OUT ensure that we call the cleanup path that is normally
used when testing is interrupted.

Add the flag `is_cleanup` to all relevant `*stop_opts` functions.
And introduce the `*_cleanup` functions for relayd, sessiond, consumerd.

While at it, a small rework on how we kill the subprocesses of the
non-iteractive shell was done. This is useful because when using the
test runner the group id of the running process performing the kill is
not valid and result in simply not propagating the SIGTERM signal.

We now use "set -m" to enable monitor mode ensuring that all background
jobs is its own process group id, facilitating the usage of kill with
negative value to ensure that each background jobs subprocesses receives
the SIGTERM signal.

Known drawbacks
=========

We introduce a new lttng specific bail out directive instead of using
the BAIL_OUT from tap.sh

We could override the BAIL_OUT function based on [1].

[1] https://mharrison.org/post/bashfunctionoverride/

References
==========

https://linux.die.net/man/1/bash#:~:text=Monitor%20mode

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I42ce8659df3e1d9078cc1a46a11a33a2df9a145e

3 years agoFix: sessiond: fix memory leak in receive_lttng_trigger
Simon Marchi [Fri, 9 Apr 2021 16:04:13 +0000 (12:04 -0400)] 
Fix: sessiond: fix memory leak in receive_lttng_trigger

After adding a trigger, ASan reports this when exiting the sessiond:

    Direct leak of 128 byte(s) in 1 object(s) allocated from:
        #0 0x7ffff767783a in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
        #1 0x55555579a415 in lttng_dynamic_buffer_set_capacity /home/simark/src/lttng-tools/src/common/dynamic-buffer.c:166
#2 0x55555579a1df in lttng_dynamic_buffer_set_size /home/simark/src/lttng-tools/src/common/dynamic-buffer.c:118
        #3 0x5555556d3cc1 in receive_lttng_trigger /home/simark/src/lttng-tools/src/bin/lttng-sessiond/client.c:712
        #4 0x5555556dba46 in process_client_msg /home/simark/src/lttng-tools/src/bin/lttng-sessiond/client.c:2154
        #5 0x5555556deef7 in thread_manage_clients /home/simark/src/lttng-tools/src/bin/lttng-sessiond/client.c:2601
        #6 0x5555556c8a83 in launch_thread /home/simark/src/lttng-tools/src/bin/lttng-sessiond/thread.c:66
        #7 0x7ffff714c298 in start_thread (/usr/lib/libpthread.so.0+0x9298)

It seems like we don't free the payload in receive_lttng_trigger, fix
that.

Change-Id: Ie9bc3bad24fb55b98c8232c0cd63483a3e94bfb0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoFix: filter: memory leak in filter_parser_ctx
Simon Marchi [Fri, 9 Apr 2021 15:19:17 +0000 (11:19 -0400)] 
Fix: filter: memory leak in filter_parser_ctx

When running

  $ lttng add-trigger --condition on-event -u ust_tests_demo2:loop --capture intfield --action notify

I get the leaks pasted below. It seems like filter_parser_ctx_free
doesn't free everything in filter_parser_ctx. Add what's missing.
Re-order the frees so that they are in the same order as the members of
the struct, just because it's easier to follow and make sure we didn't
forget anything.

=================================================================
==1073803==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff767783a in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x5555556833be in bytecode_reserve /home/simark/src/lttng-tools/src/common/bytecode/bytecode.c:59
    #2 0x55555568360f in bytecode_push /home/simark/src/lttng-tools/src/common/bytecode/bytecode.c:79
    #3 0x5555556a3d61 in filter_visitor_bytecode_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-bytecode.c:667
    #4 0x55555569c9b1 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:394
    #5 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #6 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #7 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #8 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #9 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #10 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #11 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #12 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

Direct leak of 112 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff767783a in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x5555556833be in bytecode_reserve /home/simark/src/lttng-tools/src/common/bytecode/bytecode.c:59
    #2 0x55555568360f in bytecode_push /home/simark/src/lttng-tools/src/common/bytecode/bytecode.c:79
    #3 0x5555556a1b94 in visit_node_load_expression_legacy /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-bytecode.c:198
    #4 0x5555556a1d18 in visit_node_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-bytecode.c:231
    #5 0x5555556a2540 in visit_node_load /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-bytecode.c:399
    #6 0x5555556a3a8b in recursive_visit_gen_bytecode /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-bytecode.c:622
    #7 0x5555556a12fa in visit_node_root /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-bytecode.c:53
    #8 0x5555556a3a76 in recursive_visit_gen_bytecode /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-bytecode.c:620
    #9 0x5555556a3c55 in filter_visitor_bytecode_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-bytecode.c:661
    #10 0x55555569c9b1 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:394
    #11 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #12 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #13 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #14 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #15 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #16 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #17 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #18 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff7677639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x5555556a3dd2 in make_op_root /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:35
    #2 0x5555556a73a5 in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:874
    #3 0x5555556a74d6 in filter_visitor_ir_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:903
    #4 0x55555569c859 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:353
    #5 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #6 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #7 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #8 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #9 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #10 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #11 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #12 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

Indirect leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff7677639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x5555556a4f1d in make_op_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:280
    #2 0x5555556a696f in make_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:637
    #3 0x5555556a73df in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:882
    #4 0x5555556a7382 in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:870
    #5 0x5555556a74d6 in filter_visitor_ir_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:903
    #6 0x55555569c859 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:353
    #7 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #8 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #9 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #10 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #11 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #12 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #13 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #14 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff7677639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x5555556a484d in create_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:201
    #2 0x5555556a5040 in make_op_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:287
    #3 0x5555556a696f in make_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:637
    #4 0x5555556a73df in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:882
    #5 0x5555556a7382 in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:870
    #6 0x5555556a74d6 in filter_visitor_ir_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:903
    #7 0x55555569c859 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:353
    #8 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #9 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #10 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #11 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #12 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #13 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #14 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #15 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff7677639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x5555556a4e64 in create_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:262
    #2 0x5555556a5040 in make_op_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:287
    #3 0x5555556a696f in make_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:637
    #4 0x5555556a73df in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:882
    #5 0x5555556a7382 in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:870
    #6 0x5555556a74d6 in filter_visitor_ir_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:903
    #7 0x55555569c859 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:353
    #8 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #9 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #10 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #11 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #12 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #13 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #14 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #15 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff7677639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x5555556a4bbc in create_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:233
    #2 0x5555556a5040 in make_op_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:287
    #3 0x5555556a696f in make_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:637
    #4 0x5555556a73df in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:882
    #5 0x5555556a7382 in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:870
    #6 0x5555556a74d6 in filter_visitor_ir_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:903
    #7 0x55555569c859 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:353
    #8 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #9 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #10 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #11 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #12 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #13 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #14 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #15 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

Indirect leak of 9 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff761fa69 in __interceptor_strdup /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:452
    #1 0x5555556a4c41 in create_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:238
    #2 0x5555556a5040 in make_op_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:287
    #3 0x5555556a696f in make_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:637
    #4 0x5555556a73df in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:882
    #5 0x5555556a7382 in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:870
    #6 0x5555556a74d6 in filter_visitor_ir_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:903
    #7 0x55555569c859 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:353
    #8 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #9 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #10 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #11 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #12 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #13 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #14 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #15 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

Indirect leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7ffff7677639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x5555556a4829 in create_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:196
    #2 0x5555556a5040 in make_op_load_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:287
    #3 0x5555556a696f in make_expression /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:637
    #4 0x5555556a73df in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:882
    #5 0x5555556a7382 in generate_ir_recursive /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:870
    #6 0x5555556a74d6 in filter_visitor_ir_generate /home/simark/src/lttng-tools/src/common/filter/filter-visitor-generate-ir.c:903
    #7 0x55555569c859 in filter_parser_ctx_create_from_filter_expression /home/simark/src/lttng-tools/src/common/filter/filter-parser.y:353
    #8 0x55555560542e in parse_event_rule /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:704
    #9 0x555555607429 in handle_condition_event /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1088
    #10 0x555555608760 in parse_condition /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1326
    #11 0x55555560bca0 in cmd_add_trigger /home/simark/src/lttng-tools/src/bin/lttng/commands/add_trigger.c:1925
    #12 0x555555616b55 in handle_command /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:237
    #13 0x555555617516 in parse_args /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:421
    #14 0x555555617812 in main /home/simark/src/lttng-tools/src/bin/lttng/lttng.c:470
    #15 0x7ffff700bb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

SUMMARY: AddressSanitizer: 409 byte(s) leaked in 9 allocation(s).

Change-Id: I04f9eb5ab7b18ae4ffdf7a49842768a6fdae5dbc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoconfigure: enable -Wshadow diagnostic
Simon Marchi [Wed, 31 Mar 2021 14:42:42 +0000 (10:42 -0400)] 
configure: enable -Wshadow diagnostic

The codebase should compile cleanly with this flag, enable it by
default.

Change-Id: Ia9581845aec079347616fccd554d7199d012c2f1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: tests: fix -Wshadow error in run_active_set_combination
Simon Marchi [Wed, 31 Mar 2021 19:14:44 +0000 (15:14 -0400)] 
Clean-up: tests: fix -Wshadow error in run_active_set_combination

... by renaming one of the pipe variables.

Change-Id: I550c4c4c8c71171f435bdc1fb6afffdd68d1147b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng-session: fix -Wshadow error in unregister_all_triggers
Simon Marchi [Wed, 31 Mar 2021 19:10:13 +0000 (15:10 -0400)] 
Clean-up: lttng-session: fix -Wshadow error in unregister_all_triggers

We can safely re-use the variable at function scope.

Change-Id: I0c357c328325853842d599b2d79dc2076c48365e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng-sessiond: fix -Wshadow error in check_session_rotation_pending
Simon Marchi [Wed, 31 Mar 2021 19:08:05 +0000 (15:08 -0400)] 
Clean-up: lttng-sessiond: fix -Wshadow error in check_session_rotation_pending

We can safely re-use the variable at function scope.

Change-Id: I2f9440c676a5458a063212d7143b0b69635fec87
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoFix: sessiond: fix -Wshadow error in save.c
Simon Marchi [Wed, 31 Mar 2021 19:06:34 +0000 (15:06 -0400)] 
Fix: sessiond: fix -Wshadow error in save.c

I think this actually fixes a bug. Because of the second ret variable,
the return value from init_ust_event_from_agent_event or save_ust_event
would not be forwarded correctly, in case of error.

Change-Id: I6aad9e36f31ae5abf8ef487680af7c79853ffa3b
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng-relayd: prepend `the_` to global variable names tcp_keep_alive.c
Simon Marchi [Wed, 31 Mar 2021 19:05:53 +0000 (15:05 -0400)] 
Clean-up: lttng-relayd: prepend `the_` to global variable names tcp_keep_alive.c

To avoid clashing with function parameter names.

Change-Id: Ib8be1640d74101b21ee5921c2b966ed8b90cd9e1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng-crash: prepend `the_` to input_path global variable
Simon Marchi [Wed, 31 Mar 2021 19:02:58 +0000 (15:02 -0400)] 
Clean-up: lttng-crash: prepend `the_` to input_path global variable

... to avoid clashing with a function parameter name.

Change-Id: I96ca04576b4cc18adff7e5e19483d4fb74a7c669
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng: fix -Wshadow error in run_command_string
Simon Marchi [Wed, 31 Mar 2021 18:59:43 +0000 (14:59 -0400)] 
Clean-up: lttng: fix -Wshadow error in run_command_string

We can safely re-use the `ret` variable.

Change-Id: Iba98715bf0c2810df7510eeb6a00b17ed56c9f58
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng: prepend `the_` to global variables in load.c
Simon Marchi [Wed, 31 Mar 2021 18:57:53 +0000 (14:57 -0400)] 
Clean-up: lttng: prepend `the_` to global variables in load.c

This avoids name clashes between the global variable `session_name` and
function parameters of the same name. Change all global variables of the
file while at it.

Change-Id: I79fe01e22b5797f156d47dbf425baa8f1fc4a6b0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng: fix -Wshadow error in cmd_snapshot
Simon Marchi [Wed, 31 Mar 2021 18:56:14 +0000 (14:56 -0400)] 
Clean-up: lttng: fix -Wshadow error in cmd_snapshot

... by renaming a local variable.

Change-Id: If0aeb5adc71a0cc72efa60582df5447e12ad74d0
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng: fix -Wshadow error in lttng_session_descriptor
Simon Marchi [Wed, 31 Mar 2021 18:55:41 +0000 (14:55 -0400)] 
Clean-up: lttng: fix -Wshadow error in lttng_session_descriptor

... by moving variable declaractions to narrower scopes.

Change-Id: I2ae3586596f543706b8e2ee5c7d4ce52e0658a9e
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: lttng: prepend `the_` to global variables in list.c
Simon Marchi [Wed, 31 Mar 2021 18:54:08 +0000 (14:54 -0400)] 
Clean-up: lttng: prepend `the_` to global variables in list.c

This avoids name clashes between the global variable `handle` and
function parameters of the same name. Change all global variables of the
file while at it.

Change-Id: Ice1a4f98270f439f5e5001014d9b3d6f2d8a5803
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: liblttng-ctl: fix two trivial -Wshadow errors
Simon Marchi [Wed, 31 Mar 2021 18:53:04 +0000 (14:53 -0400)] 
Clean-up: liblttng-ctl: fix two trivial -Wshadow errors

Fix two similar cases by declaring a variable in a narrower scope.

Change-Id: I6e36f4cf07086ccb5e58a175aff04671cc64323d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: liblttng-ctl: fix -Wshadow error in lttng_enable_event_with_exclusions
Simon Marchi [Wed, 31 Mar 2021 18:51:12 +0000 (14:51 -0400)] 
Clean-up: liblttng-ctl: fix -Wshadow error in lttng_enable_event_with_exclusions

The local variable `handle` shadows the parameter, rename the local
variable.

Change-Id: Ic1f3b8ae9fd6ac356eeee691c0328d6e8e1d0216
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: common: fix -Wshadow error in lttng_trace_chunk_set_as_owner
Simon Marchi [Wed, 31 Mar 2021 18:50:28 +0000 (14:50 -0400)] 
Clean-up: common: fix -Wshadow error in lttng_trace_chunk_set_as_owner

We can safely re-use the reference_acquired variable at function scope.

Change-Id: I4e45c4995d07188d48f5aa36280859ebb3ed2233
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: common: fix -Wshadow errors in event-field-value.c
Simon Marchi [Wed, 31 Mar 2021 18:44:06 +0000 (14:44 -0400)] 
Clean-up: common: fix -Wshadow errors in event-field-value.c

We get this when building with -Wshadow:

      CC       event-field-value.lo
    In file included from /home/simark/src/lttng-tools/src/common/error.h:19,
                     from /home/simark/src/lttng-tools/src/common/event-field-value.c:17:
    /home/simark/src/lttng-tools/src/common/event-field-value.c: In function ‘lttng_event_field_value_unsigned_int_get_value’:
    /home/simark/src/lttng-tools/src/common/macros.h:55:42: error: declaration of ‘__ptr’ shadows a previous local [-Werror=shadow]
       55 |   const typeof(((type *)NULL)->member) * __ptr = (ptr); \
          |                                          ^~~~~
    /home/simark/src/lttng-tools/src/common/event-field-value.c:390:10: note: in expansion of macro ‘container_of’
      390 |   *val = container_of(
          |          ^~~~~~~~~~~~
    /home/simark/src/lttng-tools/src/common/event-field-value.c:391:5: note: in expansion of macro ‘container_of’
      391 |     container_of(field_val,
          |     ^~~~~~~~~~~~
    /home/simark/src/lttng-tools/src/common/macros.h:55:42: note: shadowed declaration is here
       55 |   const typeof(((type *)NULL)->member) * __ptr = (ptr); \
          |                                          ^~~~~
    /home/simark/src/lttng-tools/src/common/event-field-value.c:390:10: note: in expansion of macro ‘container_of’
      390 |   *val = container_of(
          |          ^~~~~~~~~~~~

This is because of the nested use of container_of, causing two temporary
__ptr variables to be declared in the same scope. Fix it by assigning
results of container_of to temporary variables. I think the temporary
variables make it more readable anyway, showing what's going on.

Change-Id: I7b66bc40227a4c76b7f5416a911dcdc696f4efc8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: common: fix -Wshadow error in lttng_daemonize
Simon Marchi [Wed, 31 Mar 2021 18:41:48 +0000 (14:41 -0400)] 
Clean-up: common: fix -Wshadow error in lttng_daemonize

There are two ret variables in the function, not of the same type. Fix
it by moving one to a narrower scope.

Change-Id: If09dc67e95f3d01f9796555fa005638bcb172279
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: consumer: prepend `the_` to global variable
Simon Marchi [Wed, 31 Mar 2021 18:40:13 +0000 (14:40 -0400)] 
Clean-up: consumer: prepend `the_` to global variable

This avoids name clashes between the global variable and local variables
/ function parameters. This is a step towards enabling -Wshadow.

This also helps readability, in my opinion, as it helps quickly spot
that some code is using a global variable.

Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I20eb47b91e3500bf1aebee17fdb995940cae7a33

3 years agoClean-up: consumer: fix -Wshadow error in lttng_consumer_trace_chunk_exists
Simon Marchi [Wed, 31 Mar 2021 18:39:24 +0000 (14:39 -0400)] 
Clean-up: consumer: fix -Wshadow error in lttng_consumer_trace_chunk_exists

We can safely re-use the ret variable.

Change-Id: Icac6922acac8ca590c8f6b37df3fa07c90fd94dd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: consumer: fix -Wshadow error in lttng_consumer_rotate_channel
Simon Marchi [Wed, 31 Mar 2021 18:38:26 +0000 (14:38 -0400)] 
Clean-up: consumer: fix -Wshadow error in lttng_consumer_rotate_channel

We can safely re-use the chunk_status declared in the broader scope.

Change-Id: I0dc501168b1c35522a2ce4805d4514854162cefc
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: config: fix -Wshadow error in config_load_session
Simon Marchi [Wed, 31 Mar 2021 18:37:15 +0000 (14:37 -0400)] 
Clean-up: config: fix -Wshadow error in config_load_session

Fix:

      CC       libconfig_la-session-config.lo
    /home/simark/src/lttng-tools/src/common/config/session-config.c: In function ‘config_load_session’:
    /home/simark/src/lttng-tools/src/common/config/session-config.c:4020:9: error: declaration of ‘path’ shadows a parameter [-Werror=shadow]
     4020 |    char path[PATH_MAX];
          |         ^~~~
    /home/simark/src/lttng-tools/src/common/config/session-config.c:3999:37: note: shadowed declaration is here
     3999 | int config_load_session(const char *path, const char *session_name,
          |                         ~~~~~~~~~~~~^~~~

Change-Id: Id7d5f6fcf0e88f43dee420dfb174d9bf01aa8fbd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: ust-consumer: fix -Wshadow issues in lttng_ustconsumer_recv_cmd
Simon Marchi [Wed, 31 Mar 2021 16:08:41 +0000 (12:08 -0400)] 
Clean-up: ust-consumer: fix -Wshadow issues in lttng_ustconsumer_recv_cmd

Same rationale and idea as previous patch, but for UST.

To differentiante the top-level `channel` variable, which owns a
channel, and the non-owning `channel` variables used when looking up
existing channels, the latter are renamed `found_channel`.

Change-Id: I6bf94be8d4368b5716756f4e12bae17c3e0d7cee
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: kernel-consumer: fix -Wshadow issues in lttng_kconsumer_recv_cmd
Simon Marchi [Wed, 31 Mar 2021 15:10:30 +0000 (11:10 -0400)] 
Clean-up: kernel-consumer: fix -Wshadow issues in lttng_kconsumer_recv_cmd

There is a "ret" variable declared at the top and used throughout, but
there are also some other "ret" variables declared in narrower scopes.

Most of the time, the return value is not communicated from the "case"s
to the return value of the function. On failure, they goto an error
label which overrides ret to -1. There is one exception in "case
LTTNG_CONSUMER_ADD_STREAM", which goes directly to label end, not sure
if that's on purpose or not.

So what I did is: declare variables in narrower scopes when possible,
name them according to their intended use (e.g. ret_send, ret_recv). In
the end, there is no variable simply named "ret". The variable holding
the function's return value is "ret_func".

Change-Id: Ic02067c23757bd98d4b2d3d0f2b77384b4b0d743
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: kernel-ctl: rename local variables in LTTNG_IOCTL_{,NO_}CHECK
Simon Marchi [Wed, 31 Mar 2021 14:48:13 +0000 (10:48 -0400)] 
Clean-up: kernel-ctl: rename local variables in LTTNG_IOCTL_{,NO_}CHECK

Same rationale as previous patch.

Change-Id: Ie1782adad99616b3705c015360fa31d7e9273718
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: common: rename local variables in PERROR
Simon Marchi [Wed, 31 Mar 2021 14:46:20 +0000 (10:46 -0400)] 
Clean-up: common: rename local variables in PERROR

If PERROR is used in a function where a `buf` or `tmp` variable already
exists, we get this when enabling -Wshadow:

      CC       poll.lo
    In file included from /home/simark/src/lttng-tools/src/common/compat/poll.c:15:
    /home/simark/src/lttng-tools/src/common/compat/poll.c: In function ‘compat_epoll_set_max_size’:
    /home/simark/src/lttng-tools/src/common/error.h:247:9: error: declaration of ‘buf’ shadows a previous local [-Werror=shadow]
      247 |   char *buf; \
          |         ^~~
    /home/simark/src/lttng-tools/src/common/compat/poll.c:335:3: note: in expansion of macro ‘PERROR’
      335 |   PERROR("read set max size");
          |   ^~~~~~
    /home/simark/src/lttng-tools/src/common/compat/poll.c:313:7: note: shadowed declaration is here
      313 |  char buf[64];
          |       ^~~

Avoid that by giving PERROR's variables names that are unlikely to be
used elsewhere.

Change-Id: I167491fd3b232e6cfd86d13c0003ad4facb40c58
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: filter: fix variable shadowing in visit_node_load_expression
Simon Marchi [Wed, 31 Mar 2021 14:45:01 +0000 (10:45 -0400)] 
Clean-up: filter: fix variable shadowing in visit_node_load_expression

It seems safe to just re-use the `ret` variable at the function-level
scope.

Change-Id: I7826edf2b8bb41f9c202af75a8b5e7dff9cbbcc8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: filter: rename variable in filter-grammar-test.c
Simon Marchi [Wed, 31 Mar 2021 14:43:46 +0000 (10:43 -0400)] 
Clean-up: filter: rename variable in filter-grammar-test.c

... to avoid variable shadowing.

Change-Id: If5781b7e2f41ab5b1df361b9b247714b17751a32
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: sessiond: remove some declarations from lttng-sessiond.h
Simon Marchi [Wed, 31 Mar 2021 14:40:44 +0000 (10:40 -0400)] 
Clean-up: sessiond: remove some declarations from lttng-sessiond.h

As far as I can see, they aren't used anymore, there is no corresponding
definition.

Change-Id: Ie72e643e04da033bd590525de617201303f6dd23
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: sessiond: prepend `the_` to global variable names
Simon Marchi [Wed, 31 Mar 2021 14:36:33 +0000 (10:36 -0400)] 
Clean-up: sessiond: prepend `the_` to global variable names

This avoids name clashes between global variables and local variables or
function parameters (notification_thread_handle, for example). This is a
step towards enabling -Wshadow.

This also helps readability, in my opinion, as it helps quickly spot
that some code is using a global variable.

Change-Id: Ib0e35ad7efcc54fa88e1900cab3388b98a06b8d9
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoFix: utils: avoid strncpy overlap in utils_partial_realpath
Simon Marchi [Mon, 12 Apr 2021 17:23:39 +0000 (13:23 -0400)] 
Fix: utils: avoid strncpy overlap in utils_partial_realpath

When running the test_utils_expand_path test with ASan enabled, I get:

➜  lttng-tools ./tests/unit/test_utils_expand_path
1..29
INPUT: /a/b/c/d/e
=================================================================
==1485873==ERROR: AddressSanitizer: strncpy-param-overlap: memory ranges [0x621000021d00,0x621000021d0b) and [0x621000021d00, 0x621000021d0b) overlap
    #0 0x7ffff761fd97 in __interceptor_strncpy /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:481
    #1 0x555555573834 in utils_partial_realpath /home/simark/src/lttng-tools/src/common/utils.c:195
    #2 0x55555557410b in _utils_expand_path /home/simark/src/lttng-tools/src/common/utils.c:374
    #3 0x555555574340 in utils_expand_path /home/simark/src/lttng-tools/src/common/utils.c:420
    #4 0x555555570b28 in test_utils_expand_path /home/simark/src/lttng-tools/tests/unit/test_utils_expand_path.c:274
    #5 0x55555557119e in main /home/simark/src/lttng-tools/tests/unit/test_utils_expand_path.c:345
    #6 0x7ffff725fb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
    #7 0x55555556fa3d in _start (/home/simark/build/lttng-tools/tests/unit/test_utils_expand_path+0x1ba3d)

0x621000021d00 is located 0 bytes inside of 4096-byte region [0x621000021d00,0x621000022d00)
allocated by thread T0 here:
    #0 0x7ffff7677639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x55555557269d in zmalloc /home/simark/src/lttng-tools/src/common/macros.h:45
    #2 0x555555573d34 in _utils_expand_path /home/simark/src/lttng-tools/src/common/utils.c:335
    #3 0x555555574340 in utils_expand_path /home/simark/src/lttng-tools/src/common/utils.c:420
    #4 0x555555570b28 in test_utils_expand_path /home/simark/src/lttng-tools/tests/unit/test_utils_expand_path.c:274
    #5 0x55555557119e in main /home/simark/src/lttng-tools/tests/unit/test_utils_expand_path.c:345
    #6 0x7ffff725fb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

0x621000021d00 is located 0 bytes inside of 4096-byte region [0x621000021d00,0x621000022d00)
allocated by thread T0 here:
    #0 0x7ffff7677639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x55555557269d in zmalloc /home/simark/src/lttng-tools/src/common/macros.h:45
    #2 0x555555573d34 in _utils_expand_path /home/simark/src/lttng-tools/src/common/utils.c:335
    #3 0x555555574340 in utils_expand_path /home/simark/src/lttng-tools/src/common/utils.c:420
    #4 0x555555570b28 in test_utils_expand_path /home/simark/src/lttng-tools/tests/unit/test_utils_expand_path.c:274
    #5 0x55555557119e in main /home/simark/src/lttng-tools/tests/unit/test_utils_expand_path.c:345
    #6 0x7ffff725fb24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)

The sole caller of utils_partial_realpath, _utils_expand_path, passes
the same buffer (resolved_path) for the input and output.  This causes
utils_partial_realpath to call strncpy with overlapping strings.

Fix it by making utils_partial_realpath allocate new memory for the
returned string itself.  This causes one more allocation than the
current code, because we don't re-use the existing buffer, but this
should be fine since this isn't exactly performance-critical code.
I think the code is easier to follow as a result.

Change-Id: I98a9aafc08d3bef45e3a83cbeef049f249b86f59
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoClean-up: utils: make utils_partial_realpath static
Simon Marchi [Mon, 12 Apr 2021 17:18:15 +0000 (13:18 -0400)] 
Clean-up: utils: make utils_partial_realpath static

It is only used within its file.

Change-Id: I3e9b01e0cb765c74d3564a7c57598dace8104a29
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoFix: lttng: list_triggers: use proper format specifier for uint64_t
Michael Jeanson [Fri, 9 Apr 2021 17:48:16 +0000 (13:48 -0400)] 
Fix: lttng: list_triggers: use proper format specifier for uint64_t

This fixes a warning on 32 bit systems.

Change-Id: Ie00e340cbe5a2b4e82bb544275bea914708d8e38
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 years agoFix: sessiond: error accounting: wrong sizeof argument cpu_counters
Jérémie Galarneau [Wed, 7 Apr 2021 17:01:44 +0000 (13:01 -0400)] 
Fix: sessiond: error accounting: wrong sizeof argument cpu_counters

1452205 Wrong sizeof argument

The wrong sizeof value is used in an expression or as argument to a function. The result is an incorrect value that may cause unexpected program behaviors.

In create_uid_accounting_entry: The sizeof operator is invoked on the wrong argument (CWE-569)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I1912964bd1579f3b1ff013000848c28cea6a9d52

3 years agoFix: sessiond: error accounting: wrong sizeof argument cpu_counters
Jérémie Galarneau [Wed, 7 Apr 2021 16:54:09 +0000 (12:54 -0400)] 
Fix: sessiond: error accounting: wrong sizeof argument cpu_counters

`cpu_counters` is an array of `struct lttng_ust_abi_object_data *`, not
of `struct lttng_ust_abi_object_data`. This didn't cause any problems
since the structure is larger than a pointer.

1452203 Wrong sizeof argument

The wrong sizeof value is used in an expression or as argument to a function. The result is an incorrect value that may cause unexpected program behaviors.

In event_notifier_error_accounting_register_app: The sizeof operator is invoked on the wrong argument (CWE-569)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9278949aab0a98f050ec232d7b8ce024240020d0

3 years agoFix: sessiond: notification: missing unlock on client list on error
Jérémie Galarneau [Wed, 7 Apr 2021 16:51:36 +0000 (12:51 -0400)] 
Fix: sessiond: notification: missing unlock on client list on error

1452204 Missing unlock

May result in deadlock if there is another attempt to acquire the lock.

In notification_thread_client_subscribe: Missing a release of a lock on a path (CWE-667)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iabfe3eecfbea89c96c7f16fbb25a0beef48f78b7

3 years agoDocs: sessiond: document the rationale for the iteration on triggers list
Jérémie Galarneau [Wed, 7 Apr 2021 16:50:51 +0000 (12:50 -0400)] 
Docs: sessiond: document the rationale for the iteration on triggers list

Document the reason why an iteration is performed on the list of
triggers of a "client list" when a client subscribes to a condition.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I7d1c15016064ff2f6498c925f4933450fc7da30b

3 years agoFix: added missing test_channel and removed double defined test_syscall
Anders Wallin via lttng-dev [Wed, 31 Mar 2021 18:54:39 +0000 (20:54 +0200)] 
Fix: added missing test_channel and removed double defined test_syscall

Signed-off-by: Anders Wallin <wallinux@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I3f4963e3e10d81f18e4327e8189f9cb8316fe5ed

3 years agoClean-up: sessiond: blasphemous declaration of variable in code
Jérémie Galarneau [Wed, 7 Apr 2021 16:12:25 +0000 (12:12 -0400)] 
Clean-up: sessiond: blasphemous declaration of variable in code

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I5200a2a3e077e3e33f6773a2b0ada1db04261a9f

3 years agoFix: sessiond: error accounting: leak of cpu_counter array on error path
Jérémie Galarneau [Wed, 7 Apr 2021 16:07:43 +0000 (12:07 -0400)] 
Fix: sessiond: error accounting: leak of cpu_counter array on error path

1452202 Resource leak

The system resource will not be reclaimed and reused, reducing the future availability of the resource.

In event_notifier_error_accounting_register_app: Leak of memory or pointers to system resources (CWE-404)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I07cc8808b05c497b9bc3099deca58e14f721c5a1

3 years agoFix: sessiond: error accounting: dereference of null pointer on error path
Jérémie Galarneau [Wed, 7 Apr 2021 16:04:58 +0000 (12:04 -0400)] 
Fix: sessiond: error accounting: dereference of null pointer on error path

1452201 Dereference after null check

Either the check against null is unnecessary, or there may be a null pointer dereference.

In event_notifier_error_accounting_register_app: Pointer is checked against null but then dereferenced anyway (CWE-476)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I169fd6434606b2a35e076ae9258de6597565effe

3 years agoFix: sessiond: error accounting: unchecked lttng_ht_del return value
Jérémie Galarneau [Wed, 7 Apr 2021 16:01:33 +0000 (12:01 -0400)] 
Fix: sessiond: error accounting: unchecked lttng_ht_del return value

There is no reason for this deletion to fail; assert that it succeeds
to detect any internal error.

1451556 Unchecked return value

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

In event_notifier_error_accounting_unregister_event_notifier: 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 <jeremie.galarneau@efficios.com>
Change-Id: I3d0f8995608ac96cd3c94b5e92c4459fff592702

3 years agoFix: sessiond: kernel: invalid error code check
Jérémie Galarneau [Wed, 7 Apr 2021 15:55:26 +0000 (11:55 -0400)] 
Fix: sessiond: kernel: invalid error code check

The `EEXIST` error code does not make sense for a kernctl_disable()
operation. In fact, not existing would be an error.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iae193c9c8d8697af3154a9862bf14d4398c60b60

3 years agoFix: sessiond: kernel: missing check for unregistration error
Jérémie Galarneau [Wed, 7 Apr 2021 15:54:17 +0000 (11:54 -0400)] 
Fix: sessiond: kernel: missing check for unregistration error

1451463 Unused value

An assigned value that is never used may represent unnecessary computation, an incorrect algorithm, or possibly the need for cleanup or refactoring.

In synchronize_tracer_notifier_unregister: A value assigned to a variable is never used. (CWE-563)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Iaea550a2d70730cc4c90f8d1bdcd8cc0a4af6bd8

3 years agoTests: fix: unchecked sscanf return value
Jérémie Galarneau [Wed, 7 Apr 2021 15:49:39 +0000 (11:49 -0400)] 
Tests: fix: unchecked sscanf return value

1407934 Unchecked return value

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

In parse_arguments: 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 <jeremie.galarneau@efficios.com>
Change-Id: I7733e88ea6af6313379bd8d4ca131cd243cda401

3 years agoon-event evaluation: remove trigger name accessor
Jérémie Galarneau [Wed, 7 Apr 2021 02:05:26 +0000 (22:05 -0400)] 
on-event evaluation: remove trigger name accessor

The trigger name accessor on an on-event evaluation is no longer needed
as the originating trigger is now accessible on a notification.

The tests are adapted to use the name of the trigger as returned by
the lttng_notification received by the client.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I57bd64d7f5ec35f015dfb115ecfadd75806b9a75

3 years agonotification: add trigger accessor to lttng_notification
Jérémie Galarneau [Wed, 7 Apr 2021 01:10:35 +0000 (21:10 -0400)] 
notification: add trigger accessor to lttng_notification

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: If154de643f0d3ec0978b96551b3c3873f4b3380b

3 years agonotification: transmit originating trigger as part of evaluation
Jérémie Galarneau [Wed, 7 Apr 2021 00:41:25 +0000 (20:41 -0400)] 
notification: transmit originating trigger as part of evaluation

Transmit the full trigger object instead of its condition when sending a
notification to a client. This allows clients to reliably filter on
triggers as, currently, only the name of a trigger is made available to
clients as part of the "on_event" evaluation object (the owner uid is
needed to perform a correct comparison for filtering).

This will also make the trigger accessible for all condition types.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I61d587436177eb34744487a1d3c486d87fe2e1f1

3 years agoFix: .gitignore: use full paths for test binaries
Mathieu Desnoyers [Tue, 6 Apr 2021 18:58:28 +0000 (14:58 -0400)] 
Fix: .gitignore: use full paths for test binaries

Using only the binary name in the .gitignore paths yields confusion
for git and search tools relying on this file's content (e.g. ag
silversearcher), because the binary file name may also be part of a
path, e.g. the filename "gen-ust-events" is also part of the path
leading to the .c file implementing this test:
"./tests/utils/testapp/gen-ust-events/gen-ust-events.c", which means
this .c file is ignored, even though it should not be.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I309b268fed8e66b693c1e0670044b40bf90593c4

3 years agoTests: use TRACEPOINT_INCLUDE
Mathieu Desnoyers [Tue, 6 Apr 2021 18:26:03 +0000 (14:26 -0400)] 
Tests: use TRACEPOINT_INCLUDE

The macro TRACEPOINT_INCLUDE_FILE is deprecated since LTTng-UST 2.1. In
preparation for LTTng-UST 2.13, this compatibility macro is finally
removed.

The tests in lttng-tools need to keep up with times and start using its
replacement: TRACEPOINT_INCLUDE.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Id2bb15062f37878de03656dc5a47d9dd35687b41

3 years agoFix: sessiond: ust-app: assertion failure on registration of dead app
Jérémie Galarneau [Fri, 2 Apr 2021 17:11:34 +0000 (13:11 -0400)] 
Fix: sessiond: ust-app: assertion failure on registration of dead app

While setting up the event notifier group of a newly registered
application (see `ust_app_setup_event_notifier_group()`), communications
with the application can fail (generally because the application exited)
while sending the error counter configuration. This causes the UST
handle to the event notifier group to be released.

However, a second release is performed which results in undefined
behaviour (I have seen it succeed, assert, and crash under different
circumstances) while disposing of the application (see
`delete_ust_app()`).

Set the event notifier group ust handle to NULL to mark it as invalid
and prevent a second release during the clean-up.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ia5623a8d3f57174effa51c278e9654b6adc43289

3 years agocommon: credentials: hide symbols
Jérémie Galarneau [Fri, 2 Apr 2021 13:07:00 +0000 (09:07 -0400)] 
common: credentials: hide symbols

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I089502d46bdd0cf34b0721703a08fdd28f61b8f7

3 years agotrigger: consider name in trigger _is_equal()`
Francis Deslauriers [Mon, 8 Mar 2021 21:11:37 +0000 (16:11 -0500)] 
trigger: consider name in trigger _is_equal()`

For the moment, this is a breaking change since, before 2.13, users
could not register two identical triggers.

Triggers were previously unnamed, but a name is now generated
automatically. This means that a pre-2.13 user that could expect
a TRIGGER_ALREADY_EXISTS reply when registering a trigger that already
existed will now get "OK".

However, since it doesn't know about trigger names, it could now fail
to unregister a trigger (if the instance used to register the trigger
was not kept around).

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9549980677e2387a7cc0f275233a3b5717fb915e

3 years agoFix: sessiond: notification: use after free of trigger object
Francis Deslauriers [Tue, 23 Mar 2021 23:50:30 +0000 (19:50 -0400)] 
Fix: sessiond: notification: use after free of trigger object

Background
==========
* Clients can subscribe to certain specific conditions (e.g. buffer
  usage) using the `lttng_notification_channel_subscribe()` function.

* This subscription is only useful once a trigger with that condition
  AND at least one notify action is registered.

* The sessiond keeps a list for client subscribed to each registered
  condition.

* More than one trigger with the same condition may be registered
  the sessiond at the same time if they have different actions.

Issue
=====
Currently, when registering a trigger (T1) the sessiond looks if there
is already a client list for the condition of this trigger. If not, the
sessiond links the newly created client list object to that trigger T1
by keeping a pointer to it.

This means that if another trigger (T2) is registered with the same
condition (but a different name, or different actions) it will reuse the
same client list object and use the pointer to the T1.

This causes problems if T1 is unregistered before T2. In that case, the
pointer to T1 in the client list object is pointing to a deallocated
trigger object.

This issue is not encountered with the current test suite, namely the
`test_notification_multi_app` test case, because triggers with the same
condition also had the same action, so they are considered identical and
are not registered.

This issue was first witnessed when adding a trigger name comparison in
the `lttng_trigger_is_equal()` function.

Fix
===
Change the client list object so that it has its own copy of the
condition and a list of dependent triggers. Each trigger with that
condition has a reference on this client list object.

When unregistering a trigger, the notification thread removes it for the
client list's triggers list and put its reference on the client list
object.

Tests
=====
This commit adds a parameter to the base_client that dictates if the
notify action should be in a group. This is a trick to create triggers
that are not equal but have the same behaviour.

The `test_notification_multi_app` test case is modified to turn on this
option every other trigger registration.

Semi-related cleanups
=====================
* Merge `notification_client_list_create()` and
  `publish_notification_client_list()` functions since they are used
  together anyway. This removes the need to call
  `notification_client_list_put()` at the end of the
  `_register_trigger()` function

* Rename `trigger_applies_to_client()` to `condition_applies_to_client()`.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I3ebb90a1a64236a440a085e6fc1b82726a0e5af9

3 years agosessiond: Extract `{setup,teardown}_tracer_notifier()` functions
Francis Deslauriers [Thu, 5 Nov 2020 19:55:26 +0000 (14:55 -0500)] 
sessiond: Extract `{setup,teardown}_tracer_notifier()` functions

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ic394b1a50f166afc911b58607aece6ae69422841

3 years agoClean-up: sessiond: Extract trigger_ht_element removal function
Francis Deslauriers [Thu, 5 Nov 2020 17:25:44 +0000 (12:25 -0500)] 
Clean-up: sessiond: Extract trigger_ht_element removal function

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I4994d1dce7a8fc188b6df6ad72e5cd1081cb0cc7

3 years agoTests: event notifier error counters
Francis Deslauriers [Mon, 31 Aug 2020 15:05:41 +0000 (11:05 -0400)] 
Tests: event notifier error counters

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9e2a4bab833d9204717029c1d5f594455c2262ce

3 years agosessiond: Implement UST event notifier error counter
Francis Deslauriers [Wed, 14 Oct 2020 19:33:46 +0000 (15:33 -0400)] 
sessiond: Implement UST event notifier error counter

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I254b2cec39b8c61ad945376043b5b9053de98f6f

3 years agocommon: document why spawn_viewer() is public
Jérémie Galarneau [Thu, 1 Apr 2021 03:38:07 +0000 (23:38 -0400)] 
common: document why spawn_viewer() is public

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I09574ebd82bb583db5a7acec2b8f129a7dcd36fc

3 years agoDocs: document trigger condition and action ownership in 2.13+
Jérémie Galarneau [Mon, 1 Mar 2021 20:40:48 +0000 (15:40 -0500)] 
Docs: document trigger condition and action ownership in 2.13+

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I8a52f166565efc87c6073713ce0f6569ba6d3661

3 years agoFix: sessiond: kernel: close on badfd on initialization error
Jérémie Galarneau [Mon, 29 Mar 2021 16:17:12 +0000 (12:17 -0400)] 
Fix: sessiond: kernel: close on badfd on initialization error

The various kernel tracer file descriptors are closed during an
initialization error, but are not set to `-1` which causes them to
be closed again when the session daemon performs its clean-up.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I11d3ce7accea51394c34b9ca7ea0445e4ee422fc

3 years agoFix: sessiond: kernel error accounting fd still open when unloading modules
Francis Deslauriers [Fri, 26 Mar 2021 21:06:12 +0000 (17:06 -0400)] 
Fix: sessiond: kernel error accounting fd still open when unloading modules

Issue
=====
I noticed that some kernel modules were not unloading properly when
shutting down the sessiond. Namely those modules:
  lttng_counter_client_percpu_64_modular
  lttng_ring_buffer_event_notifier_client

The call to `modprobe -r` for those modules is failing because the
kernel error accounting fd has not been closed.

Fix
===
Only call `modprobe -r` after all kernel resources (file descriptors)
have been released.

Side note
=========
The `modprobe_remove_lttng()` is currently printing that the removal of a
_OPTIONAL module was a success even if it failed. I rework this function
to print a debug message in such situation. I used the
`modprobe_lttng()` as a template for this function.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ibb51425ef3deedf6e982084ef879bc83ac823ba3

3 years agosessiond: Implement kernel event notifier error counter
Francis Deslauriers [Wed, 14 Oct 2020 19:33:19 +0000 (15:33 -0400)] 
sessiond: Implement kernel event notifier error counter

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I390113873567a98d7e53db605d48b59a60a1074e

3 years agoFix: on-event condition: don't abort() on invalid event expression type
Jérémie Galarneau [Fri, 26 Mar 2021 22:39:30 +0000 (18:39 -0400)] 
Fix: on-event condition: don't abort() on invalid event expression type

Protocol errors should not result in crashes. Simply report the
failure to deserialize the event expression.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ic5a0be6b248c430fcf1fe487cd734d9bdf5dd36a

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