Fix: Wrong poll events on UST application socket

The thread manage apps was adding UST sockets to the poll set with the
POLLIN event registered. However, the thread was not handling this event
which could ultimately cause an infinite loop if the application sends
data.

This has been observed with the bug386 when an application is stopped
and a lttng command is sent.

https://bugs.lttng.org/issues/386

Furthermore, a time window between the send and the reply recv of an UST
command was making the app manager loop actively because of a POLLIN
event on the socket caused by the reply from the application which is
finally handled a bit after by the client thread. This was not that
problematic but lead to a lot of repeated debug message and CPU time
lost.

This application thread is *only* handling error event usually triggered
by a close() on the UST socket thus OK to *not* wait for POLLIN/POLLOUT
event.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Channel creation error return code was not set

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Add EPIPE error handling on buffer splice

Even though this is _not_ documented in splice(2), if the fd_out is a
socket but closed on one end, splice returns a negative value and set
errno to EPIPE. The man page specifies a EBADF but I guess both are
possible (and it is according to the kernel 3.6.2 source).

So, when streaming a kernel session (using splice), if the relayd quits,
a splice on the socket returns an EPIPE.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Support new liblttng-ust-ctl error code

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Create default channel on add-context if none

For both kernel and UST, if no channel exists and an add-context command
is sent, the default channel0 is created and the context(es) are set.

Fixes #391

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Do not install health tests helper libraries

The libraries libhealthexit and libhealthstall should not be installed
on the user system. They are only useful for the health check tests.

Furthermore, when adding libraries to noinst_LTLIBRARIES, libtool will
only build these as static libraries (see [1] for a workaround). This is
fine for most use cases, but for the health tests, we _must_ have shared
libraries (the nature of the tests require LD_PRELOAD), hence we force
the build of a shared object.

Forcing shared object has the unfortunate side-effect of breaking builds
where configure was invoked with "--disable-shared" flag.  Instead of
failing badly, detect this flag and skip the health tests altogether.

noinst shared libs:
[1] - https://lists.gnu.org/archive/html/libtool/2008-06/msg00082.html

Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: RCU hash table seed

Remove the dangerous static value 0x42UL. Use time(NULL) value to set
the new lttng_ht_seed variable when the hash table library constructor
is called.

Fixes #388

Signed-off-by: David Goulet <dgoulet@efficios.com>
Remove consumer poll timeout in data thread

This was originally used to stop any poll() after a grace period when a
session daemon dies in case of weird stuck fd(s).

However, things have changed a bit especially on the UST tracer side
where all stream handles are now cleaned up if the session daemon socket
hang up which than release every stream on the consumer and finally
quits gracefully.

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Set CLOEXEC flag on every created sockets

Every new socket created by an accept() in the session daemon is set
with the CLOEXEC flag so when the consumer is spawned we don't leak.

Fixes #367

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Consumerd error socket connect race

Fixes #366

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

configure.ac should use --target, not --host to get the target info we
want to compile for. --host is for the host that does the build.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Revert "Fix cross-compile"

This reverts commit 5692e22beeb7119d68055d6450b924972b5f20d0.

Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Add a timeout to UST application socket

By default, a 5 seconds timeout is set on every UST application socket
just after the accept() for both recv and send operation.

This value can be changed through a new environment variable (seconds)
of the session daemon.

This is the first step to fix bug386 where a stopped application can
stalls indefinitely the session daemon when a new command is sent.

The bug 386 is also fixed with the lttng-ust commit:
7bc53e94a229963972aa78880b361b1510fdd268

Fixes #386

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Teardown of thread_manage_clients on failure of listen/create_poll

Currently, if the call to lttcomm_listen_unix_sock or
create_thread_poll_set fails, the error handling and thread teardown
code path is triggered via a jump to an error label. This error handling
path closes the sockets that were used and cleanup the poll set. If the
listen fails, the poll set will tentatively be cleaned even though it
has never been initialized.

This patch add 2 labels to differentiate the error handling paths needed
in case of failure of lttcomm_listen_unix_sock or
create_thread_poll_set.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Enable event after start command

Refer to the bug tracker for more information on this bug. In a
nutshell, it was not possible to enable channel/event after a start
command has been issued (for both kernel and UST).

Note that it is still NOT possible to enable a channel after a start but
the use case here was the following:

$ lttng create
$ lttng start
$ lttng enable-event -a -u (or -k)

The first starts does NOT create a kernel or UST session so the
following enable event creates the session for the given domain but
failed to start the session after.

https://bugs.lttng.org/issues/346
https://bugs.lttng.org/issues/394

Fixes #346 #394

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Wrong data port when listing session

Fixes #377

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Don't set filter if enable event fails

Furthermore, the session daemon now returns an already exist error if
the event is enabled twice. Since we can now set filter, it's misleading
the user to tell him/her that the event was enabled but the filter
failed and than disabling the already enabled event by a previous
command.

Fixes #363 #364

Signed-off-by: David Goulet <dgoulet@efficios.com>
Support new lttng-ust error code

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: Wrong fd used by kernel_wait_quiescent

Signed-off-by: David Goulet <dgoulet@efficios.com>
Fix: FD leak on thread error

Also, don't spawn the kernel thread if not root and the no-kernel option
is set.

Fixes #316

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