This patch makes bt_common_abort() execute the value of the
`BABELTRACE_EXEC_ON_ABORT` environment variable, if it's set, as a shell
command line if the setuid/setgid flags are NOT set (for security).
The function uses g_spawn_command_line_sync() which claims to parse the
command line string like a UNIX 98 shell would, so that's what I wrote
in the environment variable's description in the manual page.
You can use this to execute any command when any part of the Babeltrace
project would abort, for example report it to some system.
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I78801460b316f04d805162af320ee30028dc90de
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2318
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
+`BABELTRACE_EXEC_ON_ABORT`='CMDLINE'::
+ Execute the command line 'CMDLINE', as parsed like a UNIX~98 shell,
+ when any part of the Babeltrace~2 project unexpectedly aborts.
++
+The application only aborts when the executed command returns, ignoring
+its exit status.
++
+This environment variable is ignored when the application has the
+`setuid` or the `setgid` access right flag set.
+
`BABELTRACE_TERM_COLOR`=(`AUTO` | `NEVER` | `ALWAYS`)::
Force the terminal color support for the man:babeltrace2(1) program
and the project's plugins.
BT_HIDDEN
void bt_common_abort(void)
{
+ static const char * const exec_on_abort_env_name =
+ "BABELTRACE_EXEC_ON_ABORT";
+ const char *env_exec_on_abort;
+
+ env_exec_on_abort = getenv(exec_on_abort_env_name);
+ if (env_exec_on_abort) {
+ if (bt_common_is_setuid_setgid()) {
+ goto do_abort;
+ }
+
+ (void) g_spawn_command_line_sync(env_exec_on_abort,
+ NULL, NULL, NULL, NULL);
+ }
+
+do_abort:
abort();
}