bin: compile lttng as C++ Compile the code of the lttng binary as C++ source. - start by renaming all files under src/bin/lttng to have the .cpp extension, adjust Makefile.am accordingly - apply the sophisticated algorithm: while does_not_build(): fix_error() until completion Fixes fall in these categories: - add extern "C" to headers of functions implemented in C. This is likely temporary: at some point some of these things will be implemented in C++, at which point we'll remove the extern "C". - rename mi_lttng_version to mi_lttng_version_data, to avoid a -Wshadow warning about the mi_lttng_version function hiding the mi_lttng_version's struct constructor - we have the same warning about lttng_calibrate, but we can't rename it, it's exposed in a public header. Add some pragmas to disable the warning around there. We will need more macro smartness in case we need to support a compiler that doesn't understand these pragmas. - in filter-ast.h, add a dummy field to the empty struct, to avoid a -Wextern-c-compat warning with clang++ (it warns us that the struct has size 0 in C but size 1 in C++). - in add_context.cpp, we can't initialize ctx_opts' union field like we did in C. Fix that by adding a ctx_opts constructor for each kind of context and implement the PERF_* macros to use them. - need to explicitly cast void pointer to type of the destination, for example the eturn value of allocation functions, or parameter of "destroy" functions - need to explicitly cast when passing an int to an enum parameter, for example an lttng_error_code parameter - remove use of designated array initializers, for example for schedule_type_str in disable_rotation.cpp - fix order of struct initializers to match order of field declarations, for example in list_triggers.cpp, function cmd_list_triggers - rename some things to avoid clashing with keywords, for example in runas.h Change-Id: Id743b141552a412b4104af4dda8969eef5032388 Signed-off-by: Simon Marchi <simon.marchi@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
port: FreeBSD has no ENODATA, alias it to ENOATTR According to 'the internet' ENOATTR is used in a similar fashion to ENODATA on the BSDs and we used it internally only anyway. Change-Id: Ia4e77fd6d28c9dfb43f99ddba6c32369384827f0 Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Move to kernel style SPDX license identifiers The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. See https://spdx.org/ids-how for details. Signed-off-by: Michael Jeanson <mjeanson@efficios.com> Change-Id: I62e7038e191a061286abcef5550b58f5ee67149d Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Cleanup: mark utils_get_home_dir as returning a const string utils_get_home_dir() returns a string obtained from getenv() that should not be modified nor free'd. However, utils_get_user_home_dir() returns the path as a copy. The return parameter of utils_get_home_dir() is marked as const to underline this difference and prevent mix-ups in the use of those functions. Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Prevent channel buffer allocation larger than memory Background ========== Until recently (before lttng-modules commit 1f0ab1e) it was possible to trigger an Out-Of-Memory crash by creating a kernel channel buffer larger than the currently usable memory on the system. The following commands was triggering the issue on my laptop: lttng create lttng enable-channel -k --subbuf-size=100G --num-subbuf=1 chan0 The lttng-modules commit 1f0ab1e adds a verification based on an estimate to prevent this from happening. Since this kernel tracer sanity check is based on an estimate, it would safer to do a similar check on the session daemon side. Approach ======== Verify that there is enough memory available on the system to do all the allocations needed to enable the channel. If the available memory is insufficient for the buffer allocation, return an error to the user without trying to allocate the buffers. Use the `/proc/meminfo` procfile to get an estimate of the current size of available memory (using `MemAvailable`). The `MemAvailable` field was added in the Linux kernel 3.14, so if it's absent, fallback to verifying that the requested buffer is smaller than the physical memory on the system. Compute the size of the requested buffers using the following equation: requested_memory = number_subbuffer * size_subbuffer * number_cpu The following error is returned to the command line user: lttng enable-channel -k --subbuf-size=100G --num-subbuf=1 chan0 Error: Channel chan0: Not enough memory (session auto-20181121-161146) Side effect =========== This patch has the interesting side effect to alerting the user with an error that buffer allocation has failed because of memory availability in both --kernel and --userspace channel creation. Drawback ======== The fallback check on older kernels is imperfect and is only to prevent obvious user errors. Note ==== In the future, there might be a need for a way to deactivate this check (by using an environment variable) if a case arises where `/proc/meminfo` doesn't accurately reflect the state of memory for a particular use case. Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Fix: destroy session removes the default config file Destroy session command by default removes the default config file without checking the current session. As a result when we call any other command which expects a default session by calling get_session_name() function, it fails. This patch will fix this by checking that the default config file gets removed only when destroy session is called with the current session. Fixes: #887 Signed-off-by: Partha Pratim Mukherjee <ppm.floss@gmail.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Fix: define _LGPL_SOURCE in C files Defining this in headers is a bad practice, since the header is not necessarily the first in the include list. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>