int lttng_event_serialize(const struct lttng_event *event,
unsigned int exclusion_count,
- char **exclusion_list,
- char *filter_expression,
+ const char **exclusion_list,
+ const char *filter_expression,
size_t bytecode_len,
struct lttng_bytecode *bytecode,
struct lttng_payload *payload);
#include "utils.hpp"
#include <common/compat/getenv.hpp>
+#include <common/exception.hpp>
#include <common/tracker.hpp>
#include <common/unix.hpp>
#include <common/utils.hpp>
* informations for the client. The command context struct contains
* everything this function may needs.
*/
- ret = process_client_msg(&cmd_ctx, &sock, &sock_error);
- rcu_thread_offline();
- if (ret < 0) {
- if (sock >= 0) {
- ret = close(sock);
- if (ret) {
- PERROR("close");
+ try {
+ ret = process_client_msg(&cmd_ctx, &sock, &sock_error);
+ rcu_thread_offline();
+ if (ret < 0) {
+ if (sock >= 0) {
+ ret = close(sock);
+ if (ret) {
+ PERROR("close");
+ }
}
+ sock = -1;
+ /*
+ * TODO: Inform client somehow of the fatal error. At
+ * this point, ret < 0 means that a zmalloc failed
+ * (ENOMEM). Error detected but still accept
+ * command, unless a socket error has been
+ * detected.
+ */
+ continue;
}
- sock = -1;
- /*
- * TODO: Inform client somehow of the fatal error. At
- * this point, ret < 0 means that a zmalloc failed
- * (ENOMEM). Error detected but still accept
- * command, unless a socket error has been
- * detected.
- */
- continue;
+ } catch (const std::bad_alloc& ex) {
+ WARN_FMT("Failed to allocate memory while handling client request: {}",
+ ex.what());
+ ret = LTTNG_ERR_NOMEM;
+ } catch (const lttng::ctl::error& ex) {
+ WARN_FMT("Client request failed: {}", ex.what());
+ ret = ex.code();
+ } catch (const std::exception& ex) {
+ WARN_FMT("Client request failed: {}", ex.what());
+ ret = LTTNG_ERR_UNK;
}
if (ret < LTTNG_OK || ret >= LTTNG_ERR_NR) {
tmp_event->exclusion = 1;
}
+ std::vector<const char *> exclusion_names;
+ if (uevent->exclusion) {
+ for (int i = 0; i < uevent->exclusion->count; i++) {
+ exclusion_names.emplace_back(
+ LTTNG_EVENT_EXCLUSION_NAME_AT(uevent->exclusion, i));
+ }
+ }
+
/*
* We do not care about the filter bytecode and the fd from the
* userspace_probe_location.
*/
- ret = lttng_event_serialize(tmp_event,
- uevent->exclusion ? uevent->exclusion->count : 0,
- uevent->exclusion ? (char **) uevent->exclusion->names :
- nullptr,
- uevent->filter_expression,
- 0,
- nullptr,
- reply_payload);
+ ret = lttng_event_serialize(
+ tmp_event,
+ exclusion_names.size(),
+ exclusion_names.size() ?
+ exclusion_names.data() :
+ nullptr,
+ uevent->filter_expression,
+ 0,
+ nullptr,
+ reply_payload);
lttng_event_destroy(tmp_event);
if (ret) {
ret_code = LTTNG_ERR_FATAL;
int lttng_event_serialize(const struct lttng_event *event,
unsigned int exclusion_count,
- char **exclusion_list,
- char *filter_expression,
+ const char **exclusion_list,
+ const char *filter_expression,
size_t bytecode_len,
struct lttng_bytecode *bytecode,
struct lttng_payload *payload)
serialize:
ret = lttng_event_serialize(ev,
exclusion_count,
- exclusion_list,
+ const_cast<const char **>(exclusion_list),
filter_expression,
bytecode_len,
(ctx && bytecode_len) ? &ctx->bytecode->b : nullptr,