Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [lttng-dev] [PATCH lttng-tools 08/10] Add environment variable to allow abort on error
Date: Wed, 18 May 2016 14:04:17 -0400	[thread overview]
Message-ID: <1463594659-10964-9-git-send-email-mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <1463594659-10964-1-git-send-email-mathieu.desnoyers@efficios.com>

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



  parent reply	other threads:[~2016-05-18 18:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-18 18:04 [lttng-dev] [PATCH lttng-tools 00/10] Fix: tracefile rotation rm-after-destroy race Mathieu Desnoyers
2016-05-18 18:04 ` [lttng-dev] [PATCH lttng-tools 06/10] Fix: error.h: add missing parenthesis around macro parameter Mathieu Desnoyers
2016-05-19  4:13   ` Jérémie Galarneau
2016-05-18 18:04 ` [lttng-dev] [PATCH lttng-tools 07/10] Fix: WARN() should print as WARN level, not ERR Mathieu Desnoyers
2016-05-19  4:14   ` Jérémie Galarneau
2016-05-18 18:04 ` Mathieu Desnoyers [this message]
2016-05-19  4:45   ` [lttng-dev] [PATCH lttng-tools 08/10] Add environment variable to allow abort on error Jérémie Galarneau
2016-05-18 18:04 ` [lttng-dev] [PATCH lttng-tools 09/10] test: kernel tracing destroy flush behavior with tracefile rotation Mathieu Desnoyers
2016-05-19  4:45   ` Jérémie Galarneau
2016-05-18 18:04 ` [lttng-dev] [PATCH lttng-tools 10/10] test: UST " Mathieu Desnoyers
2016-05-19  4:46   ` Jérémie Galarneau
     [not found] ` <1463594659-10964-2-git-send-email-mathieu.desnoyers@efficios.com>
2016-05-19  2:57   ` [lttng-dev] [PATCH lttng-tools 01/10] Fix: bad file descriptors on close after rotation error Jérémie Galarneau
     [not found] ` <1463594659-10964-3-git-send-email-mathieu.desnoyers@efficios.com>
2016-05-19  4:09   ` [lttng-dev] [PATCH lttng-tools 02/10] Fix: UST should not generate packet at destroy after stop Jérémie Galarneau
     [not found] ` <1463594659-10964-4-git-send-email-mathieu.desnoyers@efficios.com>
2016-05-19  4:09   ` [lttng-dev] [PATCH lttng-tools 03/10] Fix: kernel tracing: flush " Jérémie Galarneau
     [not found] ` <1463594659-10964-5-git-send-email-mathieu.desnoyers@efficios.com>
2016-05-19  4:12   ` [lttng-dev] [PATCH lttng-tools 04/10] Fix: ust-consumer: flush empty packets on snapshot channel Jérémie Galarneau
     [not found] ` <1463594659-10964-6-git-send-email-mathieu.desnoyers@efficios.com>
2016-05-19  4:12   ` [lttng-dev] [PATCH lttng-tools 05/10] Fix: bogus mask on error.h PRINT types Jérémie Galarneau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463594659-10964-9-git-send-email-mathieu.desnoyers@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox