Add environment variable to allow abort on error
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 18 May 2016 18:04:17 +0000 (14:04 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 19 May 2016 04:37:52 +0000 (00:37 -0400)
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@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
doc/man/common-cmd-footer.txt
doc/man/lttng-relayd.8.txt
doc/man/lttng-sessiond.8.txt
src/common/error.c
src/common/error.h

index d776cc4a4306fb126c7e0108fa627d1d2eb6331d..6d16c035152f3ade5052de9184c70faea1bd035e 100644 (file)
@@ -1,5 +1,8 @@
 ENVIRONMENT VARIABLES
 ---------------------
 ENVIRONMENT VARIABLES
 ---------------------
+`LTTNG_ABORT_ON_ERROR`::
+    Set to 1 to abort the process after the first error is encountered.
+
 `LTTNG_HOME`::
     Overrides the `$HOME` environment variable. Useful when the user
     running the commands has a non-writable home directory.
 `LTTNG_HOME`::
     Overrides the `$HOME` environment variable. Useful when the user
     running the commands has a non-writable home directory.
index d667be1785956a83125439dea1ba4fe861c6ed20..4326daba393e53cd477ef92c6b1de508ef8395d1 100644 (file)
@@ -152,6 +152,9 @@ option:-V, option:--version::
 
 ENVIRONMENT VARIABLES
 ---------------------
 
 ENVIRONMENT VARIABLES
 ---------------------
+`LTTNG_ABORT_ON_ERROR`::
+    Set to 1 to abort the process after the first error is encountered.
+
 `LTTNG_NETWORK_SOCKET_TIMEOUT`::
     Socket connection, receive and send timeout (milliseconds). A value
     of 0 or -1 uses the timeout of the operating system (default).
 `LTTNG_NETWORK_SOCKET_TIMEOUT`::
     Socket connection, receive and send timeout (milliseconds). A value
     of 0 or -1 uses the timeout of the operating system (default).
index f4348d85b14c0e3eac7cabdfefe4557daa420481..d57f5fe1c0de225f49d66ea71c8726fdc9693bbc 100644 (file)
@@ -224,6 +224,9 @@ ENVIRONMENT VARIABLES
 Note that command-line options override their equivalent environment
 variable.
 
 Note that command-line options override their equivalent environment
 variable.
 
+`LTTNG_ABORT_ON_ERROR`::
+    Set to 1 to abort the process after the first error is encountered.
+
 `LTTNG_APP_SOCKET_TIMEOUT`::
     Application socket's timeout (seconds) when sending/receiving
     commands. After this period of time, the application is unregistered
 `LTTNG_APP_SOCKET_TIMEOUT`::
     Application socket's timeout (seconds) when sending/receiving
     commands. After this period of time, the application is unregistered
index f7e11e163fbdd9eabe76badf662faa7bee7d2321..84bc04facc7a5baea689d839aa0db85a0f1dfdb2 100644 (file)
 #define _LGPL_SOURCE
 #include <assert.h>
 #include <inttypes.h>
 #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 <lttng/lttng-error.h>
 #include <common/common.h>
+#include <common/compat/getenv.h>
 
 #include "error.h"
 
 #define ERROR_INDEX(code) (code - LTTNG_OK)
 
 
 #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);
 
 /* 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)];
 }
 
        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();
+       }
+}
index 9c9d2a7b15c0b39a5c1b64e4c4dd153d56817278..6c239fe56e2ea2c041069490a79d3fff1d3f0284 100644 (file)
@@ -89,6 +89,9 @@ extern int lttng_opt_mi;
                                ((type) & (PRINT_WARN | PRINT_ERR | PRINT_BUG))) { \
                        fprintf(stderr, fmt, ## args);                             \
                }                                                                  \
                                ((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 */
        } 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();
 
  */
 const char *log_add_time();
 
+void lttng_abort_on_error(void);
+
 #endif /* _ERROR_H */
 #endif /* _ERROR_H */
This page took 0.027136 seconds and 4 git commands to generate.