From f5a36babeecda62a4ee87537febe06d53c8cd442 Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Mon, 11 Feb 2019 12:53:08 -0500 Subject: [PATCH] Relayd: disallow-clear option parsing Parse LTTNG_RELAYD_DISALLOW_CLEAR env variable if present. LTTNG_RELAYD_DISALLOW_CLEAR have priority on the command line argument. Signed-off-by: Jonathan Rajotte --- src/bin/lttng-relayd/main.c | 25 +++++++++++++++++++++++++ src/common/defaults.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 6f439176f..705b5d6c5 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -83,6 +83,7 @@ NULL /* command line options */ char *opt_output_path; static int opt_daemon, opt_background; +static int opt_allow_clear = 1; /* * We need to wait for listener and live listener threads, as well as @@ -171,6 +172,7 @@ static struct option long_options[] = { { "verbose", 0, 0, 'v', }, { "config", 1, 0, 'f' }, { "version", 0, 0, 'V' }, + { "disallow-clear", 0, 0, 'x' }, { NULL, 0, 0, 0, }, }; @@ -292,6 +294,10 @@ static int set_option(int opt, const char *arg, const char *optname) } } break; + case 'x': + /* Disallow clear */ + opt_allow_clear = 0; + break; default: /* Unknown option or other error. * Error is printed by getopt, just return */ @@ -367,6 +373,7 @@ static int set_options(int argc, char **argv) int orig_optopt = optopt, orig_optind = optind; char *default_address, *optstring; const char *config_path = NULL; + const char *value = NULL; optstring = utils_generate_optstring(long_options, sizeof(long_options) / sizeof(struct option)); @@ -479,6 +486,20 @@ static int set_options(int argc, char **argv) } } + if (opt_allow_clear) { + /* Check if env variable exists. */ + value = lttng_secure_getenv(DEFAULT_LTTNG_RELAYD_DISALLOW_CLEAR_ENV); + if (value) { + ret = config_parse_value(value); + if (ret < 0) { + ERR("Invalid value for %s specified", DEFAULT_LTTNG_RELAYD_DISALLOW_CLEAR_ENV); + retval = -1; + goto exit; + } + opt_allow_clear = !ret; + } + } + exit: free(optstring); return retval; @@ -2784,6 +2805,10 @@ int main(int argc, char **argv) goto exit_options; } + if (!opt_allow_clear) { + DBG("Clear command disallowed."); + } + /* Try to create directory if -o, --output is specified. */ if (opt_output_path) { if (*opt_output_path != '/') { diff --git a/src/common/defaults.h b/src/common/defaults.h index e8ce419e6..8643147f6 100644 --- a/src/common/defaults.h +++ b/src/common/defaults.h @@ -338,6 +338,7 @@ #define DEFAULT_LTTNG_RELAYD_TCP_KEEP_ALIVE_MAX_PROBE_COUNT_ENV "LTTNG_RELAYD_TCP_KEEP_ALIVE_MAX_PROBE_COUNT" #define DEFAULT_LTTNG_RELAYD_TCP_KEEP_ALIVE_PROBE_INTERVAL_ENV "LTTNG_RELAYD_TCP_KEEP_ALIVE_PROBE_INTERVAL" #define DEFAULT_LTTNG_RELAYD_TCP_KEEP_ALIVE_ABORT_THRESHOLD_ENV "LTTNG_RELAYD_TCP_KEEP_ALIVE_ABORT_THRESHOLD" +#define DEFAULT_LTTNG_RELAYD_DISALLOW_CLEAR_ENV "LTTNG_RELAYD_DISALLOW_CLEAR" /* * Returns the default subbuf size. -- 2.34.1