Fix: check illegal combinations of ctrl-url/data-url/ouput/set-url
[lttng-tools.git] / src / bin / lttng / commands / create.c
index faf9f3e0d780274d2beb69ab838d2302e4713dcd..d3e5b9a84106f84fbde44c50eb8376bcd8faae94 100644 (file)
@@ -49,7 +49,7 @@ static char *opt_shm_path;
 static int opt_no_consumer;
 static int opt_no_output;
 static int opt_snapshot;
-static unsigned int opt_live_timer;
+static uint32_t opt_live_timer;
 
 #ifdef LTTNG_EMBED_HELP
 static const char help_msg[] =
@@ -442,7 +442,7 @@ static int create_session(void)
                MSG("Traces will be written in %s", print_str_url);
 
                if (opt_live_timer) {
-                       MSG("Live timer set to %u usec", opt_live_timer);
+                       MSG("Live timer set to %u %s", opt_live_timer, USEC_UNIT);
                }
        } else if (opt_snapshot) {
                if (print_str_url) {
@@ -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
  *
@@ -641,7 +657,7 @@ int cmd_create(int argc, const char **argv)
                        goto end;
                case OPT_LIVE_TIMER:
                {
-                       unsigned long v;
+                       uint64_t v;
 
                        errno = 0;
                        opt_arg = poptGetOptArg(pc);
@@ -653,22 +669,24 @@ int cmd_create(int argc, const char **argv)
                                break;
                        }
 
-                       v = strtoul(opt_arg, NULL, 0);
-                       if (errno != 0 || !isdigit(opt_arg[0])) {
-                               ERR("Wrong value in --live parameter: %s", opt_arg);
+                       if (utils_parse_time_suffix(opt_arg, &v) < 0) {
+                               ERR("Wrong value for --live parameter: %s", opt_arg);
                                ret = CMD_ERROR;
                                goto end;
                        }
+
                        if (v != (uint32_t) v) {
                                ERR("32-bit overflow in --live parameter: %s", opt_arg);
                                ret = CMD_ERROR;
                                goto end;
                        }
+
                        if (v == 0) {
                                ERR("Live timer interval must be greater than zero");
                                ret = CMD_ERROR;
                                goto end;
                        }
+
                        opt_live_timer = (uint32_t) v;
                        DBG("Session live timer interval set to %d", opt_live_timer);
                        break;
@@ -685,6 +703,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.027033 seconds and 5 git commands to generate.