Fix: Delete UST app session on ustctl create error

This has been updated in upstream master (see commit:
0f83395d5e0e927fdab025eae023e68e9021af26).

There was also a check missing at one of the callsite.

http://lists.lttng.org/pipermail/lttng-dev/2012-December/019208.html

Reported-by: David OShea <David.OShea@quantum.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
compat fcntl.h: add cygwin support

commit c345f883983ae8d187c6e3bb087fba9d33d8d72b upstream.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
fix: add missing parenthesis

commit b1c900e9d222629937cb1a42e769318e88f28664 upstream.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
cygwin support: only freebsd needs to typedef loff_t

commit 15d3d5d89e2ca0656e653323c053d29e72674d32 upstream.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Update fcntl cygwin support

commit 4443d2b1356a787069fb75a5598f5fda660d37dd upstream.

cygwin has posix_fadvise

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
poll compat wrapper: add cygwin support

commit 3247be18440ddc45bbc45f0cf9cdbc5691aae08e upstream.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
kernel-ctl: cygwin compatibility compile fix

commit 95ba0f2fffd50c6d52e028cbb72ab1fcd43db876 upstream.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
compat socket.h: add cygwin support

commit 5db8b7b1b6c49bfb25ffc438c95941eecee060f5 upstream.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
compat mman.h: add cygwin support

commit 2667678617cac0d49c3f72343955827d29719ec6 upstream.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Fix: Remove dependency to urcu-cds in tools tests

The -lurcu-cds link flag is not mandatory to link any of the tests.
Also, adding this flag can cause multiple symbol definition errors when
linking statically because the libhashtable contains symbol names that
are also present in urcu-cds.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Cygwin: Add clone compat layer

Cygwin doesn't support the clone() syscall [1].
Users must explicitly set the LTTNG_DEBUG_NOCLONE environment variable.

[1] - http://cygwin.com/ml/cygwin/2009-05/msg00172.html

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Cygwin: Removed useless includes

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Add max() and min() macro in common

commit cf3f19ae5f634bf07dcdb771e66d40f805700a17 upstream.

Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Add default subbuf sizes getter functions

commit 8b3bd7a32e514aae56e718491a10f582b03140c3 upstream.

This patch adds functions to retrieve defaults subbuf sizes. It uses the
DEFAULT_*_SUBBUF_SIZE defines from defaults.h but also make sure that
the values are at least as big as the page size.

The functions are defined as static inline in defaults.h.

[ Edit by Christian Babeux: Resolved conflict in src/common/Makefile.am
  and src/common/defaults.h ]

Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Use the new functions for default subbuf sizes

commit 3e230f922d67f7a47b66631f7a8cf458002b3727 upstream.

Use the functions added by the previous commit. All the occurences of
the previous defines were replaced.

[ Edit by Christian Babeux: Changes to tests/tools/Makefile.am were
  not applied because this file is not present in the stable 2.0 branch.
  Also added the relevant *_LDADD = $(top_builddir)/src/common/libcommon.la
  to the differents Makefile.am where the new functions are used. ]

Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Signed-off-by: David Goulet <dgoulet@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Force the ld "no-undefined" flag on Cygwin

In order to build shared libraries on Cygwin/MinGW/Windows, all
symbols must be defined at link time. Activating the "-no-undefined"
flag will fail the build if it's not the case.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Cygwin: Pass file paths instead of file descriptors over UNIX sockets

Cygwin doesn't support file descriptors passing over UNIX sockets [1].
LTTng-ust and LTTng-tools make extensive use of this feature to pass
the shm and the wakeup pipe file descriptor from the userspace tracer
to the session daemon. The sessiond then pass those file descriptors
to the consumer.

To workaround this limitation, we pass the file paths of the shm and the
named wakeup pipe. These paths are relayed by the sessiond to the
consumer. The consumer then needs to open these paths.

The files are created in /tmp/lttng-fds and have the following format:

SHM         : ust-shm-<pid>-<uuid>
Wakeup pipe : ust-wait-<pid>-<uuid>

[1] - http://cygwin.com/ml/cygwin/2009-10/msg00403.html

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Cygwin: Introduce new LTTNG_UST_STREAM_PIPE command to open wakeup pipe

Normally, the userspace tracer open the wakeup pipe, and the resulting
fd is passed to the consumer via the session daemon. Since we can't pass
fds via UNIX socket, the pipe need to be opened separately in the tracer
and in the consumer. The only way to open the write side of a named pipe
*before* the read side without blocking is to open it in read/write mode.
This is supported on Linux, but POSIX leave this behavior undefined [1].

The Cygwin named pipe implementation doesn't seem to allow multiple
readers/writers on a named pipe. Opening a pipe in RW mode in the tracer
and then opening the read side in the consumer won't work because the
consumer will get a "Device or ressource busy" error. Thus arise the need
to open the named pipe read side *before* the write side.

In order to accomplish this task, a new command must be introduced to signal
to the tracer that a specific named pipe should be opened in write mode.

Proper care must be taken to issue this command *after* the named pipe paths
have been sent to the consumer or else the sessiond or tracer will block
indefinitely.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Cygwin: Fix handling of wait pipe hangup by properly detecting EOF

On Linux, the POLLHUP poll(3) event is used to signal that the other end
of a pipe has been disconnected. Due to poor wording in the Single UNIX
Specification, differents UNIX implementation signal the EOF with
conflicting poll events [1].

This is the case on Cygwin. A pipe close sends the POLLIN poll(3) event.
The actual consumer implementation sees this has a wakeup for data
ready to be consumed. The current hangup handling leads to infinite looping
in the consumer because the hangup is never detected and the POLLIN event
is never cleared.

To fix this issue, the consumer must read on the pipe, check for EOF
(read(3) shall return 0 to indicate EOF) and proceed to force the POLLHUP
poll(3) event if this is indeed the case.

[1] - http://www.greenend.org.uk/rjk/tech/poll.html

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Cygwin: Fixup of wait pipe hangup commit

The condition in lttng_ustconsumer_check_pipe was wrong.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>