Fix: check illegal combinations of ctrl-url/data-url/ouput/set-url
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 22 Mar 2019 21:51:40 +0000 (17:51 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 29 Mar 2019 15:49:24 +0000 (11:49 -0400)
The lttng CLI must check for illegal combinations of the
--ctrl-url, --data-url, --set-url, and --output options.

The following combinations are mutually exclusive:
  1) --set-url
  2) --ctrl-url + --data-url
  3) --output

Combining these incompatible options resulted in unhelpful
generic error messages since the error is catched a lot farther
than it should.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/create.c

index faf9f3e0d780274d2beb69ab838d2302e4713dcd..1ec77ae6f64800841b6fa2e17bd84f5ba1f2eedf 100644 (file)
@@ -616,6 +616,22 @@ end:
        return ret;
 }
 
+int validate_url_option_combination(void)
+{
+       int ret = 0;
+       int used_count = 0;
+
+       used_count += !!opt_url;
+       used_count += !!opt_output_path;
+       used_count += (opt_data_url || opt_ctrl_url);
+       if (used_count > 1) {
+               ERR("Only one of the --set-url, --ctrl-url/data-url, or --output options may be used at once.");
+               ret = -1;
+       }
+
+       return ret;
+}
+
 /*
  *  The 'create <options>' first level command
  *
@@ -685,6 +701,12 @@ int cmd_create(int argc, const char **argv)
                goto end;
        }
 
+       ret = validate_url_option_combination();
+       if (ret) {
+               ret = CMD_ERROR;
+               goto end;
+       }
+
        /* Spawn a session daemon if needed */
        if (!opt_no_sessiond) {
                ret = launch_sessiond();
This page took 0.026579 seconds and 4 git commands to generate.