Fix: epoll attributes used outside of compat layer

This was breaking the poll() support. A lttng_poll_init is added which
basically resets the lttng poll event data structure and in the case of
epoll sets the epfd to -1.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Update README

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: use memset instead of poll reset for poll init

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: update tracer version in lttng-sessiond.8 and lttng.1

Fixes #535

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: increment UST channel refcount at stream creation

Having the channel refcount incremented only when the stream is sent to a
thread could triggered a segfault with a race between a channel destroyed by
the channel thread and the stream pointers being inflight in the thread pipe.

Once read from the pipe, the streams are added to the data thread poll set and
immediately destroyed since the channel has hung up previously but the flush
buffer segfaulted on the channel that was already deleted by the channel thread
with a refcount set to 0.

This is fixed by incrementing the channel refcount once the stream is created
and the channel reference is set to it. This is done *before* the channel
object is visible in the channel thread. Now the channel thread detects the
hang up but will not destroy the channel because of the refcount > 0. The
channel cleanup will be done by the last stream hanging up.

Fixes #530

Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Add wrappers for pipe

This is to help use pipes in a way where partial read/write and EINTR
are handled in one single call site.

Two new files are created, pipe.c/.h which are part of libcommon. The
open, close, read_close, write_close, read and write calls are
implemented using a custom lttng_pipe data structure and protected by
operation's mutex. A destroy function is also available to cleanup
memory once done with a pipe.

The motivation behind this patch is for some upcoming fixes that deals
with a race condition between read and write on a pipe in the consumer.

Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Change consumer_data_pipe to be a lttng_pipe

Also, an important change here is that this pipe is no longer in non
block mode. Before sending stream's pointer over this pipe, only one
byte was written thus making it unlikely to fail in a read/write race
condition between threads. Now, 4 bytes are written so keeping this pipe
non block with threads is a bit of a "looking for trouble situation".

The lttng pipe wrappers make sure that the read and write side are
synchronized between threads using a mutex for each side. Furthermore,
the read and write handle partial I/O and EINTR meaning that once the
call returns we are sure that either everything was read/written or an
error occured thus making it not possible for the read side to block
indefinitely after a poll event.

Fixes #475

Signed-off-by: David Goulet <dgoulet@efficios.com>
Change consumer_metadata_pipe to be a lttng_pipe

The read() call in the metadata thread is also changed to use the lttng
pipe read wrapper.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: use lttng pipe to send new stream to thread

Signed-off-by: David Goulet <dgoulet@efficios.com>
Tests: Fix possible segfault in health check thread exit test

The testpoints in the thread_manage_clients and thread_manage_apps are
called after a rcu_register_thread() call. The testpoints were not
unregistering their respective thread which could later on cause a
segfault when shutting down the session daemon.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: close wait_fd on kernel tracing

The wait_fd in the kernel consumer streams was not closed causing a leak
of FDs in the consumer and never triggering the teardown mechanism in
the kernel tracer. This applies for metadata and data stream.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: error handling in kernel add_channel

consumer_add_channel can return an error, it needs to be handled. Also,
init_kernel_tracing returns a positive lttng_error_code on error, so the
check in start_kernel_session needs to be for ret != 0.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: increment channel refcount on add_stream

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: set channel key to message on notify channel

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: get consumer lock before closing/pushing metadata

This is to ensure the validity of the metadata stream in the channel
before closing or pushing the metadata on it.

Fixes #536

Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Tests: Add stress test for multi session per UID

For this test, 10 applications are used with 5 sessions set with per UID
buffers.

A helper script is also added which launch applications with given
parameters. A README file is also present to help developers/users use
the stress tests correctly.

Stress tests save the stderr/stdout of the session daemon in a log file
and core dump created using the name found in core_pattern (in /proc).

Signed-off-by: David Goulet <dgoulet@efficios.com>
Tests: Add multi session per UID with 5 app in streaming mode

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: typo when closing the consumer client socket

Issue 1019917 of covertiry scan.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: wrong size in memcpy of kernel channel padding

Issue 1019925 of coverity scan.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: remove dead code

Signed-off-by: David Goulet <dgoulet@efficios.com>