X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fclient.cpp;h=a89c61e9c54d166a1eb106d202ffba5d9c699775;hb=f0a9c004f8ee3766394e8764da85dd56f2bf5dd4;hp=6c3f696f01cc3fb12ba246116c7f9beb692850fa;hpb=28f23191dcbf047429d51950a337a57d7a3f866a;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/client.cpp b/src/bin/lttng-sessiond/client.cpp index 6c3f696f0..a89c61e9c 100644 --- a/src/bin/lttng-sessiond/client.cpp +++ b/src/bin/lttng-sessiond/client.cpp @@ -30,6 +30,7 @@ #include "utils.hpp" #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include +#include #include #include #include @@ -1946,12 +1948,12 @@ skip_domain: * ret will be set to LTTNG_OK at the end of * this function. */ - } else if (pending_ret < 0) { + } else if (pending_ret <= LTTNG_OK || pending_ret >= LTTNG_ERR_NR) { ret = LTTNG_ERR_UNK; - goto setup_error; + goto error; } else { ret = pending_ret; - goto setup_error; + goto error; } pending_ret_byte = (uint8_t) pending_ret; @@ -2582,24 +2584,36 @@ static void *thread_manage_clients(void *data) * 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) {