lttng-tools.git
4 years agoFix: fd-tracker: error path lead to null dereference of handle
Jérémie Galarneau [Mon, 25 Nov 2019 19:37:54 +0000 (14:37 -0500)] 
Fix: fd-tracker: error path lead to null dereference of handle

A number of fd_tracker_open_fs_handle() error paths can lead to a NULL
pointer dereference. The error paths are separated to cover the
various initialization stages of an fs_handle.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: fd-tracker: crash on close of partially initialized handle
Jérémie Galarneau [Mon, 25 Nov 2019 19:37:38 +0000 (14:37 -0500)] 
Fix: fd-tracker: crash on close of partially initialized handle

A number of internal functions are used in the error path of the
creation of an fs_handle. Since the fs_handle is partially
initialized, those functions need to be adapted to handle cases where
internal members are NULL.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: add fd-tracker tests for the unlink operation
Jérémie Galarneau [Sat, 23 Nov 2019 00:30:39 +0000 (19:30 -0500)] 
Tests: add fd-tracker tests for the unlink operation

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agofd-tracker: use lttng_inode to store fs_handle's path
Jérémie Galarneau [Sat, 23 Nov 2019 00:25:36 +0000 (19:25 -0500)] 
fd-tracker: use lttng_inode to store fs_handle's path

Storing paths as part of the lttng_inode object, which may be shared
by multiple fs_handles reduces the number of copies of the path.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agofd-tracker: add the lttng-inode interface
Jérémie Galarneau [Sat, 23 Nov 2019 00:12:27 +0000 (19:12 -0500)] 
fd-tracker: add the lttng-inode interface

The lttng-inode interface is internal to the fd-tracker. It allows
unlink operations on an fs_handle to determine if another fs_handle
refers to the same file.

When this is deemed to be the case, the unlink can be delayed by
renaming the file to a temporary name and, finally, unlinking it
when all references have been released.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agofd-tracker: add the unlink operation to fs handles
Jérémie Galarneau [Sat, 23 Nov 2019 00:08:18 +0000 (19:08 -0500)] 
fd-tracker: add the unlink operation to fs handles

The unlink method allows user to unlink the file refered-to by
an fs_handle. As indicated in the comments, the unlink operation
leverages the lttng_inode to ensure the actual unlink system call
is only performed when the last reference to an lttng_inode is
released by an fs_handle.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTest: add a unit test for the fd tracker
Jérémie Galarneau [Fri, 22 Nov 2019 23:54:58 +0000 (18:54 -0500)] 
Test: add a unit test for the fd tracker

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agofd-tracker: add pipe management wrappers to fd-tracker
Jérémie Galarneau [Fri, 22 Nov 2019 23:52:03 +0000 (18:52 -0500)] 
fd-tracker: add pipe management wrappers to fd-tracker

Add wrappers to allow the creation of a pipe the two ends of
which are tracked by an fd-tracker.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agofd-tracker: add epoll/poll management wrappers to fd-tracker
Jérémie Galarneau [Fri, 22 Nov 2019 23:46:47 +0000 (18:46 -0500)] 
fd-tracker: add epoll/poll management wrappers to fd-tracker

Add wrappers which create an lttng_poll_event object, tracking
any file descriptor created in the process of initializing
the object.

When the build is configured to use the epoll interface, the
underlying epoll fd is tracked by the fd-tracker.

If the build is configured to use the poll interace, the fd tracker is
not involved in the process and the utility will simply defer the call
to lttng_poll_create() directly.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agofd-tracker: add an fd-tracker util to common
Jérémie Galarneau [Fri, 22 Nov 2019 23:41:09 +0000 (18:41 -0500)] 
fd-tracker: add an fd-tracker util to common

This commit adds an fd-tracker utility to the common libs.
This interface allows a process to keep track of its open
file descriptors and enforce a limit to the number of file
descriptors that may be simultaneously opened.

The intent is to use this interface as part of the relay daemon
to mitigate file descriptors exhaustion problems that are
encountered when the relay has to handle a large number of streams.

The fd-tracker defines two classes of file descriptors: suspendable
and unsuspendable file descriptors.

Suspendable file descriptors are handles to filesystem objects
(e.g. regular files) that may be closed and re-opened later without
affecting the application.

A suspendable file descriptor can be opened by creating a filesystem
handle (fs_handle) using the fd-tracker. The raw file descritptor
must then be obtained and released using that handle. Closing the
handle will effectively ensure that the file descritptor is closed.

Unsuspendable file descriptors are file descriptors that cannot
be closed without affecting the application's state. For instance,
it is not possible to close and re-open a pipe, a TCP socket, or
an epoll fd without involving some app-specific logic. Thus, the
fd-tracker considers those file descriptors as unsuspendable.

Opening an unsuspendable file descritptor will return a raw file
decriptor to the application. It is its responsability to notify the
fd-tracker of the file descriptor's closing to ensure the number
of active file descriptors can be tracked accurately.

If a request to open a new file descriptors is made to the fd-tracker
and the process has already reached its maximal count of
simultaneously opened file descriptors, an attempt will be made to
suspend a suspendable file descriptor to release a slot.

Suspending a file descriptor involves:
  - verifying that the file is still available on the FS (restorable),
  - sampling its current position,
  - closing the file descriptor.

Note that suspending a file descriptor eliminates the POSIX guarantee
that a file may be unlinked at any time without affecting the
application (provided that it holds an open FD to that
file). Applications using the fd-tracker that need to maintain this
guarantee should open those files as unsuspendable file descriptors.

To protect against unlinking and file replacement scenarios, the
fd-tracker samples the files' inode number when a fs_handle is
created. This inode number will then be checked anytime the handle
is suspended or restored to ensure that the application is made
aware of the file's unavailability. This is preferable to
inadvertently opening another file of the same name if the original
file was unlinked and/or replaced between a fs_handle's suspension
and restoration.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agorelayd: close stdin on launch
Jérémie Galarneau [Sat, 23 Nov 2019 00:20:22 +0000 (19:20 -0500)] 
relayd: close stdin on launch

The relay daemon has no use for the standard input; it can be safely
closed early on launch.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: fully initialize viewer stream before publishing it
Jérémie Galarneau [Sat, 23 Nov 2019 00:04:16 +0000 (19:04 -0500)] 
Fix: relayd: fully initialize viewer stream before publishing it

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoClean-up relayd: session_release can be marked as static
Jérémie Galarneau [Fri, 22 Nov 2019 23:37:28 +0000 (18:37 -0500)] 
Clean-up relayd: session_release can be marked as static

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: don't send streams if there is no metadata
Francis Deslauriers [Tue, 12 Nov 2019 22:55:25 +0000 (17:55 -0500)] 
Fix: relayd: don't send streams if there is no metadata

Issue
=====
When tracing short-live UST apps in per-pid mode, it happens that traces
are closed before we can send all the streams to the viewer. This can
place the viewer in an uncomfortable position where it is aware of data
streams of a trace but can't get the metadata stream to decode the
events.

Solution
========
Only send the data streams if we have the metadata stream or if the
metadata stream was already sent. This ensures that the viewer will
either have all the {data,metadata} streams or none of them.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: update apps on untrack only when session is active
Jonathan Rajotte [Mon, 18 Nov 2019 20:12:20 +0000 (15:12 -0500)] 
Fix: update apps on untrack only when session is active

This mimics what is done on the track side.

Fixes #1210

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: consumerd: assert on null trace chunk on session restart
Jérémie Galarneau [Fri, 22 Nov 2019 20:08:15 +0000 (15:08 -0500)] 
Fix: consumerd: assert on null trace chunk on session restart

The consumer daemon asserts on
`stream->net_seq_idx != (uint64_t) 1ULL || stream>trace_chunk'
when a session is re-started following a rotation.

Steps to reproduce, while an instrumented application is running:
$ lttng create
$ lttng enable-event -u -a
$ lttng start
$ lttng stop
$ lttng rotate
$ lttng start
-> assertion fails

The trace chunk of a stream can be null in this scenario as the
"create trace chunk" consumer command immediately sets the streams'
current trace chunk when they are transitioning from a "null" trace
chunk.

Since 1f4962443, a session restart will cause a rotation to occur from
"null" to the streams' new trace chunk. When this rotation occurs, the
channel and their streams are seen to be in the same trace chunk.
This is unexpected as this should only occur when transitioning from a
trace chunk to the "null" trace chunk (no output). In that case, the
streams are considered to have reached the point where they should
discard their current trace chunk to enter the "null trace chunk"
state (having no current output). This is exactly the opposite of
the situation here as streams are transitioning from a null to a
non-null trace chunk.

Hence, the immediate assignation of the trace chunk to the streams
should no longer be performed on creation of a trace chunk on the
consumer daemon. The streams transition from the "null" trace chunk to
a new trace chunk through the "rotate channel" command as is done for
all other rotation operations. Removing this bypass also ensures that
the rotation behaviour of both the consumer and relay daemons match.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: don't wait for a rotation from a null chunk to finish
Jérémie Galarneau [Wed, 20 Nov 2019 21:09:50 +0000 (16:09 -0500)] 
Fix: sessiond: don't wait for a rotation from a null chunk to finish

The rotation completion checking does not handle waiting for the
completion of a rotation _from_ a NULL trace chunk. This is correct as
there is essentially nothing to check. Streams always rotate out of a
null trace chunk immediately as it means the stream had no output and
could not receive data.

Concretely, this happens when stopping a session, rotating, and
re-starting a session.

The fix consists in simply re-working the logic of the "rotate"
command to not launch a rotation completion check job and not put the
session in the "rotation ongoing" state.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: duplicated rotation notification sent
Jérémie Galarneau [Wed, 20 Nov 2019 21:06:30 +0000 (16:06 -0500)] 
Fix: sessiond: duplicated rotation notification sent

A duplicate notification that a rotation was launched and completed
is sent by the rotation thread when a rotation is performed after
a session was stopped.

This code is removed at it is a left-over from the time when the
rotation thread had to explicitly rename trace output folders
when a rotation had completed.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: remove assert of non-null stream trace chunk on rotate
Jérémie Galarneau [Tue, 19 Nov 2019 18:41:51 +0000 (13:41 -0500)] 
Fix: relayd: remove assert of non-null stream trace chunk on rotate

A stream can rotate from a "NULL" trace chunk to a new trace chunk
and the relay daemon should not assert on this condition.

This happens when a session is stopped, rotated, and started again
later on.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoDocs: verb/noun confusion in comment
Jérémie Galarneau [Mon, 18 Nov 2019 21:09:21 +0000 (16:09 -0500)] 
Docs: verb/noun confusion in comment

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: no rotation performed from null chunk to new chunk
Jérémie Galarneau [Mon, 18 Nov 2019 21:01:44 +0000 (16:01 -0500)] 
Fix: sessiond: no rotation performed from null chunk to new chunk

The session daemon must rotate from a null trace chunk to a new trace
chunk when a session's current trace chunk is null. This situation
happens when a session is stopped, rotated, and started again.

This bug leaves existing streams in the "null" trace chunk and causes
the relay daemon to report a protocol error on the reception of the
first data packet following such a start.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: invalid use of destructor in dynamic pointer array
Jérémie Galarneau [Mon, 18 Nov 2019 19:43:06 +0000 (14:43 -0500)] 
Fix: invalid use of destructor in dynamic pointer array

A dynamic pointer array is built on top of a dynamic array and uses
the dynamic array's internal "destructor" field to store the
user-specified destructor.

lttng_dynamic_pointer_array_remove_pointer currently uses
the dynamic array's remove_element directly which causes the
user destructor to be called with the underlying storage of the
pointer rather than with the pointer itself.

This change re-uses the same pattern as
lttng_dynamic_pointer_array_reset(), namely using the destructor
explicitly and setting it to NULL for the duration of the call to
the dynamic array API.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: check for a trace chunk before writing a packet
Jérémie Galarneau [Fri, 15 Nov 2019 22:16:32 +0000 (17:16 -0500)] 
Fix: relayd: check for a trace chunk before writing a packet

Protocol errors can cause a packet to be written to a stream that
doesn't have an active trace chunk. Validate this condition for the
init and write packet operations on a stream.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: viewer session trace chunk not released on detach
Jérémie Galarneau [Thu, 14 Nov 2019 22:12:08 +0000 (17:12 -0500)] 
Fix: relayd: viewer session trace chunk not released on detach

The 'attach' command on a viewer session expects (asserts) the trace
chunk of the viewer session to be NULL. This is reasonable as there is
no reason to hold a reference to a trace chunk while no clients are
attached.

Release the reference to the trace chunk on detach. The relay
session's trace chunk will be re-sampled (copied) when the next client
attaches to the viewer session.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoRequire automake >= 1.12
Michael Jeanson [Thu, 7 Nov 2019 19:02:55 +0000 (14:02 -0500)] 
Require automake >= 1.12

The test suite LOG_DRIVER statement requires that automake >= 1.12 be used
during bootstrap.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agorelayd: rename viewer_session_set_trace_chunk and hide it
Jérémie Galarneau [Tue, 12 Nov 2019 21:28:50 +0000 (16:28 -0500)] 
relayd: rename viewer_session_set_trace_chunk and hide it

viewer_session_set_trace_chunk() is renamed to
viewer_session_set_trace_chunk_copy() as it creates a copy of the
source trace chunk before setting it on a viewer_session.

The function is also marked static as it is only needed within
the viewer-session.c TU.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: session trace chunk is copied too late
Jérémie Galarneau [Tue, 12 Nov 2019 04:38:25 +0000 (23:38 -0500)] 
Fix: relayd: session trace chunk is copied too late

In per-pid buffering mode, a viewer can attach to a session while it
is active and find it has been closed by the time it requests new
streams. The viewer session's trace chunk is created as a side-effect
of the "get_new_streams" command and can find that the relay_session's
trace chunk has now been closed, causing the creation of the viewer
session trace chunk to fail.

This results in an unexpected error being reported to the live client.
This fix moves the creation of the viewer session's trace chunk to the
"attach" command. If the creation fails, the session is reported as
being "unknown".

Reported-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Tested-by: Francis Deslauriers <francis.deslauriers@efficios.com>
4 years agoFix: overly restrictive datetime regexp rejects valid dates
Jérémie Galarneau [Mon, 11 Nov 2019 23:53:56 +0000 (18:53 -0500)] 
Fix: overly restrictive datetime regexp rejects valid dates

The patch introducting backward_compat_group_by_session() was
edited (by me) before being merged and the regular expression was
made stricter. However, one of the changes was erroneous and
restricted the range of the second digit of the 'month' field
to [0-1].

Change it back to [0-9] to accept all months from 1-12.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: disallow 0-length session names for 2.4+ peers
Jérémie Galarneau [Fri, 8 Nov 2019 22:45:20 +0000 (17:45 -0500)] 
Fix: relayd: disallow 0-length session names for 2.4+ peers

The group-by-session-name feature assumes sessions are named for peers
more recent than 2.3. Enforce this assumption at session creation
time.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoDocs: RELAYD(8): document the --group-output-by-session/host options
Jonathan Rajotte [Wed, 27 Jun 2018 00:48:24 +0000 (20:48 -0400)] 
Docs: RELAYD(8): document the --group-output-by-session/host options

Add the description of the newly-introduced --group-output-by-session
and --group-output-by-host options.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: unit testing for backward compatibility of group-output-by-session
Jonathan Rajotte [Thu, 19 Sep 2019 21:26:06 +0000 (17:26 -0400)] 
Tests: unit testing for backward compatibility of group-output-by-session

These unit tests aim to reproduce the stream path received by
lttng-relayd when dealing with a producer using a protocol version < 2.11.

We then pass them through the transform function for
--group-output-by-session used when producer are using protocol version
greater or equal to 2.4 and small than 2.11.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agorelayd: Add backward compatibility for --group-output-by-session
Jonathan Rajotte [Thu, 19 Sep 2019 20:56:53 +0000 (16:56 -0400)] 
relayd: Add backward compatibility for --group-output-by-session

The current implementation works for producer (consumerd/lttng-sessiond)
using protocol version >= 2.11.

For producer using protocol version >= 2.4 and < 2.11, we can use the
session name passed on the RELAYD_CREATE_SESSION command to infer
information (creation datetime, base path) from the stream path passed on
the RELAYD_ADD_STREAM command. That information is then used to craft a
stream path, in a best effort manner, that comply with the
--group-output-by-session requirements:

  <session_name>/<hostname>-<datetime>/trace

Prior to protocol version 2.4, the session name is unknown on lttng-relayd
side. In those cases, we do not perform any transformation and leave the
provided stream path as is. A warning (lttng-relayd) is emitted on such
occasions.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: regression testing for lttng-relayd --group-output-by-*
Jonathan Rajotte [Thu, 19 Sep 2019 21:00:51 +0000 (17:00 -0400)] 
Tests: regression testing for lttng-relayd --group-output-by-*

Each test is run for --group-output-by-host and
--group-output-by-session and also with automatic session name and
specific session name.

No need to test against kernel. Tracing domain does not have any influence
at lttng-relayd level.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: lttng_snapshot_add_output_ok: allow specifying output type
Jonathan Rajotte [Fri, 22 Jun 2018 17:51:58 +0000 (13:51 -0400)] 
Tests: lttng_snapshot_add_output_ok: allow specifying output type

Also add support for additional options.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agorelayd: introduce --group-output-by-session
Jonathan Rajotte [Thu, 19 Sep 2019 20:56:11 +0000 (16:56 -0400)] 
relayd: introduce --group-output-by-session

LTTng-relayd now support the grouping of traces per session.
This mode can be used via the "--group-output-per-session" switch.

The default, and current way, of grouping is done around the host
(hostname) of the traced system.

When grouped by host the following folder hierarchy is mostly found on the filesystem:

    <hostname>/<session_name>-<datetime>/<trace>

When using "--group-output-per-session", the following hierarchy is
found on the filesystem:

    <session_name>/<hostname>-<datetime>/<trace>

We also need to support base path information that come from the URIs
set at the client level:

    lttng create --set-url=net://localhost/extra/path/information

When grouping by host (current behaviour), it result in the following
hierarchy:

    <hostname>/<base_path>/<trace>

e.g:
    <hostname>/extra/path/information/<trace>

We want to part from this way of handling the base path since it can lead
to unexpected conflict between session.

When grouping by session using a base path, the following hierarchy is
produced:

    <session_name>/<hostname>-<datetime>/<base_path>/<trace>

e.g:
    <session_name>/<hostname>-<datetime>/extra/path/information/<trace>

We encourage user to move away from using base path entirely as it
bypasses introduces potential name clashes and completely bypasses the
relay daemon's storage policy.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: ust: deadlock with per-pid buffers
Mathieu Desnoyers [Fri, 1 Nov 2019 20:23:05 +0000 (16:23 -0400)] 
Fix: sessiond: ust: deadlock with per-pid buffers

Do not hold the registry lock while communicating with the consumerd,
because doing so causes inter-process deadlocks between consumerd and
sessiond with the metadata request notification.

The deadlock involves both sessiond and consumerd:

* lttng-sessiond:

thread 11 - thread_application_management

close_metadata()
  pthread_mutex_lock(&registry->lock);
  consumer_close_metadata()
    pthread_mutex_lock(socket->lock);

thread 15 - thread_consumer_management

ust_consumer_metadata_request()
  pthread_mutex_lock(&ust_reg->lock);

thread 8 - thread_manage_clients

consumer_is_data_pending
  pthread_mutex_lock(socket->lock);
  consumer_socket_recv()

* lttng-consumerd:

thread 4 - consumer_timer_thread

sample_channel_positions()
  pthread_mutex_lock(&stream->lock);

thread 8 - consumer_thread_sessiond_poll
  consumer_data_pending
  pthread_mutex_lock(&consumer_data.lock);
  pthread_mutex_lock(&stream->lock);

thread 7 - consumer_thread_data_poll

lttng_consumer_read_subbuffer
  pthread_mutex_lock(&stream->chan->lock);
  pthread_mutex_lock(&stream->lock);
  do_sync_metadata
    pthread_mutex_lock(&metadata->lock);
    lttng_ustconsumer_sync_metadata
      pthread_mutex_unlock(&metadata_stream->lock);
      lttng_ustconsumer_request_metadata()
        pthread_mutex_lock(&ctx->metadata_socket_lock);
        lttcomm_recv_unix_sock()

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agorelayd: close viewer stream trace chunk earlier on release
Jérémie Galarneau [Wed, 6 Nov 2019 19:43:18 +0000 (14:43 -0500)] 
relayd: close viewer stream trace chunk earlier on release

A viewer stream puts its references to its stream and index files
within its "release" method (called when its reference count reaches
0).

However, the reference to its trace chunk is only released during the
RCU reclamation of the viewer stream. This unnecessarily delays the
clean-up of the viewer trace chunk.

For cleanliness' sake, move the release of the viewer stream's trace
chunk to the release method, just after the release of the various
file handles of that stream.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: put chunk reference when closing stream
Mathieu Desnoyers [Fri, 1 Nov 2019 20:23:04 +0000 (16:23 -0400)] 
Fix: relayd: put chunk reference when closing stream

If a stream is closed by an application exiting (per-pid buffers), it
needs to put its reference on the stream trace chunk right away, because
otherwise still holding the reference on the trace chunk could allow a
viewer stream (which holds a reference to the stream) to postpone
destroy waiting for the chunk to cease to exist endlessly until the
viewer is detached.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: tracefile rotation: viewer opening missing index file
Mathieu Desnoyers [Fri, 1 Nov 2019 20:23:03 +0000 (16:23 -0400)] 
Fix: relayd: tracefile rotation: viewer opening missing index file

Moving the head position of the tracefile array when the data is
received opens a window where a viewer attaching to the session could
try to open a missing index file (which has not been received yet).

However, we want to bump the tail position as soon as we receive
data, because the prior tail is not valid anymore.

Solve this by introducing two head positions: the "read" head
and the "write" head. The "write" head is the position of the
newest data file (equivalent to the prior "head" position). We
also introduce a "read" head position, which is only moved
forward when the index is received.

The viewer now uses the "read" head position as upper bound, which
ensures it never attempts to open a non-existing index file.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: fix shellcheck warning
Jonathan Rajotte [Fri, 25 Oct 2019 22:12:04 +0000 (18:12 -0400)] 
Tests: fix shellcheck warning

No need to use random string for session name here, use the test name.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: base path: lttng load for session configuration
Jonathan Rajotte [Fri, 25 Oct 2019 22:12:03 +0000 (18:12 -0400)] 
Tests: base path: lttng load for session configuration

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoCleanup: remove unused internal lttng_session_descriptor_get_base_path
Jonathan Rajotte [Fri, 25 Oct 2019 22:12:02 +0000 (18:12 -0400)] 
Cleanup: remove unused internal lttng_session_descriptor_get_base_path

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoRefactor: Move set session path to own function
Jonathan Rajotte [Fri, 25 Oct 2019 22:12:01 +0000 (18:12 -0400)] 
Refactor: Move set session path to own function

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: move set base_path of session to URI configuration
Jonathan Rajotte [Fri, 25 Oct 2019 22:12:00 +0000 (18:12 -0400)] 
Fix: move set base_path of session to URI configuration

The load code still uses the "old" API to create and configure network
session output (lttng_create_session followed by
lttng_set_consumer_url). The session base_path is only set in the
cmd_create_session_from_descriptor function. This results in invalid
network output paths when using a loaded session configuration (xml).

While we might want to move the load code to the new API, there is a
case to be made in not breaking the previous API behaviour.

To restore the expected behaviour of lttng_set_consumer_url, move the
assignation of the session base_path to the cmd_set_consumer_uri
function (LTTNG_SET_CONSUMER_URI).

Both the previous and session descriptor based creation API uses this
code path when needed (network output).

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: tests: re-add link to urcu-bp for _LGPL_SOURCE tests
Michael Jeanson [Tue, 5 Nov 2019 16:30:24 +0000 (11:30 -0500)] 
Fix: tests: re-add link to urcu-bp for _LGPL_SOURCE tests

Tests with tracepoints defined with _LGPL_SOURCE require to be
explicitly linked against urcu-bp.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: tests: use DL_LIBS variable in ust multi-lib test
Michael Jeanson [Thu, 24 Oct 2019 15:36:33 +0000 (11:36 -0400)] 
Fix: tests: use DL_LIBS variable in ust multi-lib test

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: lttng: initialize sessions pointer to NULL
Jonathan Rajotte [Fri, 25 Oct 2019 21:56:26 +0000 (17:56 -0400)] 
Fix: lttng: initialize sessions pointer to NULL

lttng_list_sessions does not set the passed pointer to NULL on empty
return. This leads to a deallocation of an invalid pointer (segfault).

For returns of size 0, the value of the passed argument should be
considered "undefined".

Refactor error handling a bit by removing the "error" jump. Always
call free on the 'sessions' object.

Fixes #1205

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoUse pkgconfig to detect and configure liblttng-ust
Michael Jeanson [Thu, 24 Oct 2019 15:36:22 +0000 (11:36 -0400)] 
Use pkgconfig to detect and configure liblttng-ust

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: check for dtrace and sdt.h before enabling SDT uprobe tests
Michael Jeanson [Thu, 31 Oct 2019 20:12:46 +0000 (16:12 -0400)] 
Fix: check for dtrace and sdt.h before enabling SDT uprobe tests

Add a configure switch '--enable-sdt-uprobe / --disable-sdt-uprobe', the
default behavior of enabling the test if the requirements are found is
kept but it's now possible to explicitly disable it.

Also add the detection of the dtrace binary and its override trough the
DTRACE environment variable.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: consumerd: crash occurs when taking snapshot of ust channel
Jérémie Galarneau [Wed, 30 Oct 2019 19:35:28 +0000 (15:35 -0400)] 
Fix: consumerd: crash occurs when taking snapshot of ust channel

Commit 8e1ef46e8 added an acquisition of the metadata_stream's lock
during consumer_metadata_cache_flushed() as stream attributes are
used. However, when this function is called, the metadata channel's
stream can already be NULL, as indicated by the function's comments.

Check if the stream is NULL before attempting to acquire its lock.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: trace-chunk: log the cause of file open failures
Jérémie Galarneau [Tue, 29 Oct 2019 19:57:59 +0000 (15:57 -0400)] 
Fix: trace-chunk: log the cause of file open failures

Use the PERROR macro instead of ERR to obtain the "errno" message
when an error occurs while opening a file relative to a trace
chunk.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: live: crash when creating viewer streams
Jérémie Galarneau [Tue, 29 Oct 2019 03:57:01 +0000 (23:57 -0400)] 
Fix: relayd: live: crash when creating viewer streams

Viewer streams can be creating while serving a "GET_STREAMS" viewer
client command for a session that is being destroyed. If this happens,
the viewer streams will be created with a NULL viewer trace chunk,
which would result in a crash.

The fix consists in returning a stream error when such a command
happens during the destruction of a session. This is the same
behaviour than if the session could not be found at all, introducing
no meaningful change in behaviour from the viewer's perspective.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: live: crash on attach to a session without trace chunk
Jérémie Galarneau [Tue, 29 Oct 2019 03:32:36 +0000 (23:32 -0400)] 
Fix: relayd: live: crash on attach to a session without trace chunk

Attaching to a session that doesn't have a current trace chunk results
in a crash when the viewer streams are created from a NULL viewer
trace chunk.

Live clients are prevented from attaching to sessions without a
current trace chunk as those sessions are either being destroyed or
too young to have a trace chunk, meaning that they don't have streams
yet. Live clients will receive the "unknown" status code that they
already receive when asking an unknown session. Since such sessions
are not listed, this shouldn't change any exposed behaviour.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: live: some listed sessions are not attacheable
Jérémie Galarneau [Tue, 29 Oct 2019 03:29:53 +0000 (23:29 -0400)] 
Fix: relayd: live: some listed sessions are not attacheable

The list sessions command currently returns sessions that do not
have a current trace chunk. This can be caused by the session
either being destroyed or being so young that it hasn't had a
trace chunk created against it yet.

In both cases, such sessions would not be attacheable in their
current condition. This fix omits them from from the listing
to reduce the number of failures at the "attach session" and
"attach stream" step.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: don't put un-acquired trace chunk reference
Jérémie Galarneau [Mon, 28 Oct 2019 20:53:48 +0000 (16:53 -0400)] 
Fix: relayd: don't put un-acquired trace chunk reference

stream_create() should not release (put) the reference to the current
trace chunk in its error path if it could not acquire a new reference
in the first place.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: relayd: don't put un-acquired viewer trace chunk reference
Jérémie Galarneau [Mon, 28 Oct 2019 20:26:48 +0000 (16:26 -0400)] 
Fix: relayd: don't put un-acquired viewer trace chunk reference

viewer_stream_create() should not release (put) the reference to
the viewer_trace_chunk in its error path if it could not acquire
a new reference in the first place.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: consumerd: NULL pointer dereference during metadata sync
Jérémie Galarneau [Mon, 28 Oct 2019 19:37:34 +0000 (15:37 -0400)] 
Fix: consumerd: NULL pointer dereference during metadata sync

The following crash was reported when short-lived applications
are traced in a live session with per-pid buffering channels.

From the original report:

```
 Thread 1 (Thread 0x7f72b67fc700 (LWP 1912155)):
 #0  0x00005650b3f6ccbd in commit_one_metadata_packet (stream=0x7f729c010bf0) at ust-consumer.c:2537
 #1  0x00005650b3f6cf58 in lttng_ustconsumer_sync_metadata (ctx=0x5650b588ce60, metadata=0x7f729c010bf0) at ust-consumer.c:2608
 #2  0x00005650b3f4dba3 in do_sync_metadata (metadata=0x7f729c010bf0, ctx=0x5650b588ce60) at consumer-stream.c:471
 #3  0x00005650b3f4dd3c in consumer_stream_sync_metadata (ctx=0x5650b588ce60, session_id=0) at consumer-stream.c:548
 #4  0x00005650b3f6de78 in lttng_ustconsumer_read_subbuffer (stream=0x7f729c0058e0, ctx=0x5650b588ce60) at ust-consumer.c:2917
 #5  0x00005650b3f45196 in lttng_consumer_read_subbuffer (stream=0x7f729c0058e0, ctx=0x5650b588ce60) at consumer.c:3524
 #6  0x00005650b3f42da7 in consumer_thread_data_poll (data=0x5650b588ce60) at consumer.c:2894
 #7  0x00007f72bdc476db in start_thread (arg=0x7f72b67fc700) at pthread_create.c:463
 #8  0x00007f72bd97088f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

The segfault happen on the access to 'stream->chan->metadata_cache->lock'
chan value here is zero.
```

The problem is easily reproducible if a sleep(1) is added just after
the call to lttng_ustconsumer_request_metadata(), before the metadata
stream lock is re-acquired.

During the execution of the "request_metadata", an application can
close. This will cause the session daemon to push any remaining
metadata to the consumer daemon and to close the metadata channel.

Closing the metadata channel closes the metadata stream's wait_fd,
which is an internal pipe. The closure of the metadata pipe is
detected by the metadata_poll thread, which will ensure that all
metadata has been consumed before issuing the deletion of the metadata
stream and channel.

During the deletion, the channel's "stream" attribute the stream's
"chan" attribute are set to NULL as both are logically deleted and
should not longer be used.

Meanwhile, the thread executing commit_one_metadata_packet()
re-acquires the metadata stream lock and trips on the now-NULL "chan"
member.

The fix consists in checking if the metadata stream is logically
deleted after its lock is re-acquired. It is correct for the
sync_metadata operation to then complete successfully as the metadata
is synced: the metadata guarantees this before deleting the
stream/channel.

Since the metadata stream's lifetime is protected by its lock, there
may be other sites that need such a check. The lock and deletion check
could be combined into a single consumer_stream_lock() helper in
follow-up fixes.

Reported-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoconsumerd: clean-up: stream attribute accessed without locking stream
Jérémie Galarneau [Mon, 28 Oct 2019 18:52:44 +0000 (14:52 -0400)] 
consumerd: clean-up: stream attribute accessed without locking stream

consumer_metadata_cache_flushed makes use of the metadata stream's
ust_metadata_pushed attribute without locking while it is updated by
commit_one_metadata_packet() which holds the metadata stream lock.

This is marked as a clean-up since the attribute appears to always be
accessed while the metadata cache lock is held. However this is a
_channel_ attribute and the stream and channel lifetimes do not match,
making the locking assumptions conceptually dubious.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: namespace tests fail to build on older libc
Jérémie Galarneau [Thu, 24 Oct 2019 21:06:17 +0000 (17:06 -0400)] 
Tests: namespace tests fail to build on older libc

The namespace tests fail to build on older libcs that don't define the
various namespace clone flags. To circumvent this problem, local
definitions from Linux's sched.h are added.

The kernel's support of the various namespaces is tested by the test
runner. Hence, it is not a problem to build these test application
against a kernel that isn't configured to support (some of) those
namespaces; the applications are not invoked for unsupported
namespaces.

Acked-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: check for lttng-ust >= 2.11 at configure
Michael Jeanson [Wed, 23 Oct 2019 15:08:34 +0000 (11:08 -0400)] 
Fix: check for lttng-ust >= 2.11 at configure

We don't support building lttng-tools against an older version of
lttng-ust, make this check explicitly at configure.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agosessiond: build fails in --without-lttng-ust configuration
Jérémie Galarneau [Thu, 24 Oct 2019 00:27:12 +0000 (20:27 -0400)] 
sessiond: build fails in --without-lttng-ust configuration

The include of macros.h was changed when syncing with the latest
usb-abi.h header and caused the build to fail in the
--without-lttng-ust configuration.

Changed the include to refer to common/macros.h.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: use "kill -0" for app existence check in NS tests
Jonathan Rajotte [Tue, 15 Oct 2019 20:50:46 +0000 (16:50 -0400)] 
Tests: use "kill -0" for app existence check in NS tests

Removing the sleep 0.5 we hit a race where the "-f /proc/$pid_app"
test returns false immediately. Using "kill -0" protects us against
such races. From kill (2):

If sig is 0, then no signal is sent, but existence and permission
checks are still performed; this can be used to check for the
existence of a process ID or process group ID that the caller is
permitted to signal.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: add kernel namespace context change tests
Michael Jeanson [Tue, 2 Apr 2019 17:38:07 +0000 (13:38 -0400)] 
Tests: add kernel namespace context change tests

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: add UST namespace context change tests
Michael Jeanson [Mon, 1 Apr 2019 15:53:57 +0000 (11:53 -0400)] 
Tests: add UST namespace context change tests

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: add kernel namespace contexts tests
Michael Jeanson [Mon, 1 Apr 2019 15:53:20 +0000 (11:53 -0400)] 
Tests: add kernel namespace contexts tests

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: add UST namespace contexts tests
Michael Jeanson [Mon, 1 Apr 2019 15:51:52 +0000 (11:51 -0400)] 
Tests: add UST namespace contexts tests

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoMI: add support for namespace and uid/gid contexts
Jonathan Rajotte [Tue, 2 Apr 2019 21:51:01 +0000 (17:51 -0400)] 
MI: add support for namespace and uid/gid contexts

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoAdd UST uid/gid contexts
Michael Jeanson [Tue, 12 Feb 2019 16:51:55 +0000 (11:51 -0500)] 
Add UST uid/gid contexts

Add the following userspace tracer context fields:
  - vuid
    Virtual real user ID: real user ID as seen from the point of view of
    the current user namespace

  - veuid
    Virtual effective user ID: effective user ID as seen from the point of
    view of the current user namespace

  - vsuid
    Virtual saved set-user ID: saved set-user ID as seen from the point of
    view of the current user namespace

  - vgid
    Virtual real group ID: real group ID as seen from the point of view of
    the current user namespace

  - vegid
    Virtual effective group ID: effective group ID as seen from the point of
    view of the current user namespace

  - vsgid
    Virtual saved set-group ID: saved set-group ID as seen from the point of
    view of the current user namespace

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoAdd kernel uid/gid contexts
Michael Jeanson [Tue, 12 Feb 2019 16:51:42 +0000 (11:51 -0500)] 
Add kernel uid/gid contexts

Add the following kernel tracer context fields:
  - uid
    Real user ID

  - euid
    Effective user ID

  - uid
    Real user ID

  - suid
    Saved set-user ID

  - gid
    Real group ID

  - egid
    Effective group ID

  - sgid
    Effective saved set-user group ID

  - vuid
    Virtual real user ID: real user ID as seen from the point of view of
    the current user namespace

  - veuid
    Virtual effective user ID: effective user ID as seen from the point of
    view of the current user namespace

  - vsuid
    Virtual saved set-user ID: saved set-user ID as seen from the point of
    view of the current user namespace

  - vgid
    Virtual real group ID: real group ID as seen from the point of view of
    the current user namespace

  - vegid
    Virtual effective group ID: effective group ID as seen from the point of
    view of the current user namespace

  - vsgid
    Virtual saved set-group ID: saved set-group ID as seen from the point of
    view of the current user namespace

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoAdd UST namespace contexts
Michael Jeanson [Tue, 12 Feb 2019 16:51:21 +0000 (11:51 -0500)] 
Add UST namespace contexts

Add the following userspace namespace contexts:
  - cgroup_ns
    Cgroup root directory namespace: inode number of the current
    cgroup namespace in the proc filesystem.

  - ipc_ns
    System V IPC, POSIX message queues namespace: inode number of the
    current IPC namespace in the proc filesystem.

  - mnt_ns
    Mount points namespace: inode number of the current mount
    namespace in the proc filesystem.

  - net_ns
    Network devices, stacks, ports namespace: inode number of the
    current network namespace in the proc filesystem.

  - pid_ns
    Process IDs namespace: inode number of the current pid namespace
    in the proc filesystem.

  - user_ns
    User and group IDs namespace: inode number of the current user
    namespace in the proc filesystem.

  - uts_ns
    Hostname and NIS domain name namespace: inode number of the
    current uts namespace in the proc filesystem.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoAdd kernel namespace contexts
Michael Jeanson [Tue, 12 Feb 2019 16:51:05 +0000 (11:51 -0500)] 
Add kernel namespace contexts

Add the following kernel namespace contexts:

  - cgroup_ns
    Cgroup root directory namespace: inode number of the current
    cgroup namespace in the proc filesystem.

  - ipc_ns
    System V IPC, POSIX message queues namespace: inode number of the
    current IPC namespace in the proc filesystem.

  - mnt_ns
    Mount points namespace: inode number of the current mount
    namespace in the proc filesystem.

  - net_ns
    Network devices, stacks, ports namespace: inode number of the
    current network namespace in the proc filesystem.

  - pid_ns
    Process IDs namespace: inode number of the current pid namespace
    in the proc filesystem.

  - user_ns
    User and group IDs namespace: inode number of the current user
    namespace in the proc filesystem.

  - uts_ns
    Hostname and NIS domain name namespace: inode number of the
    current uts namespace in the proc filesystem.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoUpdate local copy of ust-abi.h to reflect addition of ns contexts
Jérémie Galarneau [Tue, 22 Oct 2019 20:41:18 +0000 (16:41 -0400)] 
Update local copy of ust-abi.h to reflect addition of ns contexts

New contexts were added to LTTng-UST and will be used by
LTTng-Tools. Re-sync this LTTng-UST header to ensure the build
doesn't break in the --without-lttng-ust configuration.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: fix: tmp dir can be a symlink
Jonathan Rajotte [Tue, 22 Oct 2019 16:05:28 +0000 (12:05 -0400)] 
Tests: fix: tmp dir can be a symlink

Get the real path to perform valid comparison.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoDocs: relayd: document LTTNG_RELAYD_WORKING_DIRECTORY env variable
Jonathan Rajotte [Tue, 22 May 2018 18:33:37 +0000 (14:33 -0400)] 
Docs: relayd: document LTTNG_RELAYD_WORKING_DIRECTORY env variable

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoDocs: relayd: document the --working-directory/-w option in man page
Jonathan Rajotte [Tue, 22 May 2018 18:25:32 +0000 (14:25 -0400)] 
Docs: relayd: document the --working-directory/-w option in man page

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoIntroduce LTTNG_RELAYD_WORKING_DIRECTORY environment variable
Jonathan Rajotte [Tue, 22 May 2018 17:48:07 +0000 (13:48 -0400)] 
Introduce LTTNG_RELAYD_WORKING_DIRECTORY environment variable

LTTNG_RELAYD_WORKING_DIRECTORY is equivalent to the --working-directory
command line options.

Note: when using --working-directory, the command line option always
overwrite the environment configuration, LTTNG_RELAYD_WORKING_DIRECTORY
in this case.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTests: add an lttng-relayd working directory test
Jonathan Rajotte [Fri, 18 May 2018 20:24:04 +0000 (16:24 -0400)] 
Tests: add an lttng-relayd working directory test

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agorelayd: introduce --working-directory/-w options
Jonathan Rajotte [Wed, 16 May 2018 22:24:01 +0000 (18:24 -0400)] 
relayd: introduce --working-directory/-w options

This new option allows the user to specify the working directory (CWD) of the
lttng-relayd process. This is especially useful when lttng-relayd is
started in daemon mode (-d) because by default the CWD is set to "/".
This can help control where coredumps, if any, get generated.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: compile fails for x32 arch
Kai Kang [Thu, 13 Dec 2018 02:55:36 +0000 (10:55 +0800)] 
Fix: compile fails for x32 arch

LTTng-Tools fails to compile for the x32 ABI:

| .../src/common/utils.c: Assembler messages:
| .../src/common/utils.c:1026: Error: register type mismatch for `bsr'
| .../src/common/utils.c:1028: Error: operand type mismatch for `movq'

Add a macro to only use the x86_64 inline assembly version of fls_u64()
when the LP64 ABI is used.

Signed-off-by: Kai Kang <kai.kang@windriver.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoTypo: occured -> occurred
Michael Jeanson [Fri, 18 Oct 2019 21:40:06 +0000 (17:40 -0400)] 
Typo: occured -> occurred

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix typo 'Attemp' -> 'Attempt'
Michael Jeanson [Fri, 18 Oct 2019 21:12:22 +0000 (17:12 -0400)] 
Fix typo 'Attemp' -> 'Attempt'

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: use system LTTng-UST headers when available
Jérémie Galarneau [Fri, 18 Oct 2019 20:39:00 +0000 (16:39 -0400)] 
Fix: sessiond: use system LTTng-UST headers when available

The LTTng-Tools tree includes a local copy of three LTTng-UST headers:
  * ust-error.h
  * ust-ctl.h
  * ust-abi.h

The system headers should be used when UST support is configured to
ensure the appropriate ABI definitions are used. The local copies of
the headers should only be used when LTTng-Tools is built with the
--without-lttng-ust configuration option. Those headers are needed
since some UST support code is compiled-in even though the support
is deactivated.

A misconfiguration in the CI setup allowed us to notice that
sessiond-config.c is using the internal header unconditionally.

To ensure this doesn't happen in the future, the local copies
are renamed:
  * ust-error.h -> ust-error-internal.h
  * ust-ctl.h   -> ust-ctl-internal.h
  * ust-abi.h   -> ust-abi-internal.h

All code should use the `lttng-` prefixed versions of the headers
which include either the local or "system" copy of the headers
depending on the build configuration.

Reported-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agodoc/man: use specific revision date for each manual page
Philippe Proulx [Fri, 18 Oct 2019 19:53:05 +0000 (15:53 -0400)] 
doc/man: use specific revision date for each manual page

This patch makes each manual page indicate its own revision date with
the `revdate` AsciiDoc attribute.

In `asciidoc.conf`, we use this attribute to specify the DocBook
reference page date (see
<https://tdg.docbook.org/tdg/4.5/refentryinfo.html> and
<https://tdg.docbook.org/tdg/4.5/date.html>).

Without the DocBook date tag, `xmlto` uses the current date. You can
see this date at the bottom of the rendered manual page:

    ...

    SEE ALSO
           lttng-enable-rotation(1), lttng-disable-rotation(1), lttng(1)

    LTTng 2.12.0-pre             10/18/2019              LTTNG-ROTATE(1)

Using the manual page generation date seems unexpected for the reader
here.

For this initial change, I used the last commit date for each source
file.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agolttng-rotate.1.txt: update voice and document the `archives` subdir.
Philippe Proulx [Fri, 18 Oct 2019 19:29:31 +0000 (15:29 -0400)] 
lttng-rotate.1.txt: update voice and document the `archives` subdir.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: unbalanced health register/unregister on error
Jérémie Galarneau [Thu, 17 Oct 2019 18:37:37 +0000 (14:37 -0400)] 
Fix: sessiond: unbalanced health register/unregister on error

A number of threads do not correctly pair registrations and
unregistrations to the health monitoring subsystem when an error
forces them to abort early. Since the pattern is mostly the same
in the notification and rotation thread, they are both fixed in
the same commit.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: NULL thread_state provided to pthread_cleanup callback
Jérémie Galarneau [Thu, 17 Oct 2019 18:35:34 +0000 (14:35 -0400)] 
Fix: sessiond: NULL thread_state provided to pthread_cleanup callback

The callback registered through pthread_cleanup_push(...),
thread_init_cleanup, now expects a non-NULL thread_state argument.

The thread_state is passed to match this recent change.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: leak of trace chunk on destruction error
Jérémie Galarneau [Wed, 16 Oct 2019 22:53:47 +0000 (18:53 -0400)] 
Fix: sessiond: leak of trace chunk on destruction error

By design, a trace chunk can be leaked on the consumer daemon's end if
the session daemon does not close it. This is because the consumer
daemon has no "top-level" session object which could bound the
lifetime of a trace chunk.

It was reported that errors during a session destruction operation
could result in a trace chunk leak being reported by the consumer
daemon on shut down.

In the case that was reported, the failure to launch an application
caused the metadata channel to never be created. When the session was
destroyed, the rotation of the metadata channel failed with a "channel
does not exist" error. This error caused cmd_rotate_session() to abort
before the trace chunk close command was sent to the consumer
daemon(s). This ultimately results in the leak described earlier.

The fix consists in performing the trace chunk close command on the
consumer daemon even if the rotation itself fails.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agocommon: cleanup error message mentioning mkdir
Jérémie Galarneau [Wed, 16 Oct 2019 22:25:57 +0000 (18:25 -0400)] 
common: cleanup error message mentioning mkdir

While there is a good chance that mkdir is the actual syscall that
fails when this error code is returned, the error messages should
describe the operation that failed and not its implementation.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: session destruction errors are unreported
Jérémie Galarneau [Wed, 16 Oct 2019 22:22:32 +0000 (18:22 -0400)] 
Fix: sessiond: session destruction errors are unreported

The session daemon does not report errors which occur while setting-up
a session's destruction. For instance, if the implicit rotation or
rotation to the "null" chunk fails. While the session will be
destroyed (it will no longer appear in session listings), the session
daemon could have failed to destroy it properly and it could be
corrupted/unreadable.

This reports those errors so the user does not expect the session to
be readable (but it _could_ be).

This was discovered while investigating another, unrelated, issue.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: consumer: double unlock of rcu read lock on error
Jérémie Galarneau [Wed, 16 Oct 2019 16:35:23 +0000 (12:35 -0400)] 
Fix: consumer: double unlock of rcu read lock on error

Commit 6b584c2e changed the implementation of the "trace_chunk_exists"
command to use the then-new "exists" method of the trace chunk
registry. Before this change, the trace chunks were looked-up to check
for their existence.

Since the "exists" method doesn't require the caller to hold the rcu
read lock, it is acquired later on in the function. However, the rcu
read lock is still released on error when this function fails,
resulting in a double-unlock.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: application channel creation failure stops start cmd
Jérémie Galarneau [Tue, 15 Oct 2019 20:56:22 +0000 (16:56 -0400)] 
Fix: sessiond: application channel creation failure stops start cmd

The creation of an application's channel can fail when, for instance,
a context can't be created. This causes applications that would have
been started _after_ it to never be started.

This keeps the iteration going on error and starts all applications
that could be started. This is more in line with the behaviour of
2.10 (and earlier) since those channel creations would occur as
applications registered and not on tracing "start".

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agosessiond: clean-up: enhance logging on event allocation failure
Jérémie Galarneau [Fri, 11 Oct 2019 21:12:26 +0000 (17:12 -0400)] 
sessiond: clean-up: enhance logging on event allocation failure

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: don't assert on event creation error
Jérémie Galarneau [Fri, 11 Oct 2019 20:26:29 +0000 (16:26 -0400)] 
Fix: sessiond: don't assert on event creation error

Don't assert if an application tracer reports that an event already
exists. This could be caused by a bug on the tracer end or memory
corruption on the application's end. In either case, an assert() is
too strict; simply report the error.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agosessiond: clean-up: typo in ust-app.c comment
Jérémie Galarneau [Fri, 11 Oct 2019 20:08:24 +0000 (16:08 -0400)] 
sessiond: clean-up: typo in ust-app.c comment

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years ago.gitignore: ignore vscode files
Jérémie Galarneau [Thu, 10 Oct 2019 19:32:08 +0000 (15:32 -0400)] 
.gitignore: ignore vscode files

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: lttng-elf.c: dereferencing pointer before null check
Francis Deslauriers [Wed, 9 Oct 2019 13:32:40 +0000 (09:32 -0400)] 
Fix: lttng-elf.c: dereferencing pointer before null check

Coverity report:
  CID 1405899 (#1 of 1): Dereference before null check (REVERSE_INULL)
  check_after_deref: Null-checking elf suggests that it may be null, but it has
  already been dereferenced on all paths leading to the check.

Reported-by: Coverity (1405899) Dereference before null check
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: unbounded elf section data size allocation
Jérémie Galarneau [Tue, 8 Oct 2019 21:34:51 +0000 (17:34 -0400)] 
Fix: sessiond: unbounded elf section data size allocation

The size of ELF sections is read from a user-provided file descriptor
to an ELF file which could be malformed. In theory it would not
really be a problem as the run-as process is automatically restarted
after a crash (e.g. SIGBUS).

The alloctions are now bounded to the smallest of 512MB or the
file's size. The limit is kept high to accomodate very large
binaries and not impose an artificial limitation.

In time, this should be replaced by an mmap() of the section's
data rather than copying to a private set of pages.

1405558 Untrusted value as argument

The argument could be controlled by an attacker, who could invoke the
function with arbitrary values (for example, a very high or negative
buffer size).

In lttng_elf_get_sdt_probe_offsets: An unscrutinized value from an
untrusted source used as argument to a function (for example, a buffer
size) (CWE-20)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: double socket close on allocation failure
Jérémie Galarneau [Tue, 8 Oct 2019 19:15:28 +0000 (15:15 -0400)] 
Fix: sessiond: double socket close on allocation failure

The application registration thread performs a double close() on
an application socket whenever it fails to allocate a ust_command.

Assign `-1` to `sock` after the initial close() to follow the
pattern of other close paths.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: sessiond: TOCTOU error on save of session configuration
Jérémie Galarneau [Tue, 8 Oct 2019 18:18:31 +0000 (14:18 -0400)] 
Fix: sessiond: TOCTOU error on save of session configuration

The session_save() function checks for the existance and access rights
on the target session configuration filename before opening it. This
results in a TOCTOU (Time of check, time of use) problem.

Defer the check and error reporting to the run_as_open() call.

1191754 Time of check time of use
An attacker could change the filename's file association or other
attributes between the check and use.  In save_session: A check occurs
on a file's attributes before the file is used in a privileged
operation, but things may have changed (CWE-367)

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 years agoFix: tests: replace truncation-prone logging helper
Jérémie Galarneau [Tue, 8 Oct 2019 18:01:54 +0000 (14:01 -0400)] 
Fix: tests: replace truncation-prone logging helper

The printerr() error logging scheme in test_utils_expand_path
is prone to unexpected truncations which results in a lot of
warnings when building using GCC 9.2.

It is replaced by a variable-argument macro that uses fprintf()
directly.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
This page took 0.049477 seconds and 5 git commands to generate.