[lttng-dev] [PATCH lttng-tools 08/10] Add environment variable to allow abort on error

Jérémie Galarneau jeremie.galarneau at efficios.com
Thu May 19 04:45:45 UTC 2016


Merged with some documentation changes, thanks!

Jérémie

On Wed, May 18, 2016 at 2:04 PM, Mathieu Desnoyers
<mathieu.desnoyers at efficios.com> wrote:
> The new environment variable LTTNG_ABORT_ON_ERROR allows each
> lttng-tools program to call abort() on PERROR() and ERR() after the
> error message has been printed to stderr.
>
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
> ---
>  doc/man/common-cmd-footer.txt |  3 +++
>  doc/man/lttng-relayd.8.txt    |  3 +++
>  doc/man/lttng-sessiond.8.txt  |  2 ++
>  src/common/error.c            | 28 ++++++++++++++++++++++++++++
>  src/common/error.h            |  5 +++++
>  5 files changed, 41 insertions(+)
>
> diff --git a/doc/man/common-cmd-footer.txt b/doc/man/common-cmd-footer.txt
> index d776cc4..8b1b66f 100644
> --- a/doc/man/common-cmd-footer.txt
> +++ b/doc/man/common-cmd-footer.txt
> @@ -19,6 +19,9 @@ ENVIRONMENT VARIABLES
>  The genoption:--sessiond-path option has precedence over this
>  environment variable.
>
> +`LTTNG_ABORT_ON_ERROR`::
> +    Abort process after the first error is encountered.
> +
>  Note that the man:lttng-create(1) command can spawn an LTTng
>  session daemon automatically if none is running. See
>  man:lttng-sessiond(8) for the environment variables influencing
> diff --git a/doc/man/lttng-relayd.8.txt b/doc/man/lttng-relayd.8.txt
> index d667be1..d3e5b3e 100644
> --- a/doc/man/lttng-relayd.8.txt
> +++ b/doc/man/lttng-relayd.8.txt
> @@ -159,6 +159,9 @@ ENVIRONMENT VARIABLES
>  `LTTNG_RELAYD_HEALTH`::
>      Path to relay daemon health's socket.
>
> +`LTTNG_ABORT_ON_ERROR`::
> +    Abort the relay daemon after the first error is encountered.
> +
>
>  FILES
>  -----
> diff --git a/doc/man/lttng-sessiond.8.txt b/doc/man/lttng-sessiond.8.txt
> index f4348d8..949d566 100644
> --- a/doc/man/lttng-sessiond.8.txt
> +++ b/doc/man/lttng-sessiond.8.txt
> @@ -275,6 +275,8 @@ The option:--kmod-probes option overrides this variable.
>  `LTTNG_SESSION_CONFIG_XSD_PATH`::
>      Tracing session configuration XML schema definition (XSD) path.
>
> +`LTTNG_ABORT_ON_ERROR`::
> +    Abort the session daemon after the first error is encountered.
>
>  FILES
>  -----
> diff --git a/src/common/error.c b/src/common/error.c
> index f7e11e1..84bc04f 100644
> --- a/src/common/error.c
> +++ b/src/common/error.c
> @@ -18,14 +18,23 @@
>  #define _LGPL_SOURCE
>  #include <assert.h>
>  #include <inttypes.h>
> +#include <stdlib.h>
> +#include <string.h>
>
>  #include <lttng/lttng-error.h>
>  #include <common/common.h>
> +#include <common/compat/getenv.h>
>
>  #include "error.h"
>
>  #define ERROR_INDEX(code) (code - LTTNG_OK)
>
> +/*
> + * lttng_opt_abort_on_error: unset: -1, disabled: 0, enabled: 1.
> + * Controlled by the LTTNG_ABORT_ON_ERROR environment variable.
> + */
> +static int lttng_opt_abort_on_error = -1;
> +
>  /* TLS variable that contains the time of one single log entry. */
>  DEFINE_URCU_TLS(struct log_time, error_log_time);
>
> @@ -196,3 +205,22 @@ const char *error_get_str(int32_t code)
>
>         return error_string_array[ERROR_INDEX(code)];
>  }
> +
> +LTTNG_HIDDEN
> +void lttng_abort_on_error(void)
> +{
> +       if (lttng_opt_abort_on_error < 0) {
> +               /* Use lttng_secure_getenv() to query its state. */
> +               const char *value;
> +
> +               value = lttng_secure_getenv("LTTNG_ABORT_ON_ERROR");
> +               if (value && !strcmp(value, "1")) {
> +                       lttng_opt_abort_on_error = 1;
> +               } else {
> +                       lttng_opt_abort_on_error = 0;
> +               }
> +       }
> +       if (lttng_opt_abort_on_error > 0) {
> +               abort();
> +       }
> +}
> diff --git a/src/common/error.h b/src/common/error.h
> index 9c9d2a7..6c239fe 100644
> --- a/src/common/error.h
> +++ b/src/common/error.h
> @@ -89,6 +89,9 @@ extern int lttng_opt_mi;
>                                 ((type) & (PRINT_WARN | PRINT_ERR | PRINT_BUG))) { \
>                         fprintf(stderr, fmt, ## args);                             \
>                 }                                                                  \
> +               if ((type) & (PRINT_ERR | PRINT_BUG)) {                            \
> +                       lttng_abort_on_error();                                    \
> +               }                                                                  \
>         } while (0);
>
>  /* Three level of debug. Use -v, -vv or -vvv for the levels */
> @@ -174,4 +177,6 @@ const char *error_get_str(int32_t code);
>   */
>  const char *log_add_time();
>
> +void lttng_abort_on_error(void);
> +
>  #endif /* _ERROR_H */
> --
> 2.1.4
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list