Relayd: disallow-clear option parsing clear-base
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 11 Feb 2019 17:53:08 +0000 (12:53 -0500)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Mon, 18 Feb 2019 19:25:02 +0000 (14:25 -0500)
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 <jonathan.rajotte-julien@efficios.com>
src/bin/lttng-relayd/main.c
src/common/defaults.h

index de14cdb432d977c6fb1fa2cf982e435a5c0063d5..2900e2fe0a040912ebcf1bc81afd5932bb4e1a3e 100644 (file)
@@ -94,6 +94,7 @@ enum relay_connection_status {
 /* 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
@@ -179,6 +180,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, },
 };
 
@@ -300,6 +302,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 */
@@ -375,6 +381,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));
@@ -487,6 +494,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;
@@ -4092,6 +4113,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 != '/') {
index 5c93e498ddf39c86007c8b07d58ec8e64ec8324f..11150845f95c858a0b5c8a0957ff4243a0058cbd 100644 (file)
 #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"
 
 /*
  * Default timer value in usec for the rotate pending polling check on the
This page took 0.030064 seconds and 5 git commands to generate.