From 4f50c803f026f217d37588c46265b5c2fb9a1195 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 11 Apr 2013 15:00:45 -0400 Subject: [PATCH] Fix: don't allow different control and data destination The lttng create command does not allow anymore different destination when using -C and -D. Fixes #455 Signed-off-by: David Goulet --- src/bin/lttng/commands/create.c | 30 +++++++++++++++------------- src/lib/lttng-ctl/lttng-ctl.c | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index b14b45cd6..02aaf40f4 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -253,7 +253,7 @@ static int create_session(void) } else if (opt_url) { /* Handling URL (-U opt) */ url = opt_url; print_str_url = url; - } else if (opt_ctrl_url == NULL && opt_data_url == NULL) { + } else { /* Auto output path */ alloc_path = config_get_default_path(); if (alloc_path == NULL) { @@ -274,10 +274,16 @@ static int create_session(void) } url = alloc_url; - print_str_url = alloc_url + strlen("file://"); + if (!opt_data_url && !opt_ctrl_url) { + print_str_url = alloc_url + strlen("file://"); + } } - assert(url); + if ((!opt_ctrl_url && opt_data_url) || (opt_ctrl_url && !opt_data_url)) { + ERR("You need both control and data URL."); + ret = CMD_ERROR; + goto error; + } ret = _lttng_create_session_ext(session_name, url, datetime); if (ret < 0) { @@ -293,22 +299,19 @@ static int create_session(void) goto error; } - MSG("Session %s created.", session_name); - if (print_str_url) { - MSG("Traces will be written in %s", print_str_url); - } - if (opt_ctrl_url && opt_data_url) { /* Setting up control URI (-C or/and -D opt) */ ret = set_consumer_url(session_name, opt_ctrl_url, opt_data_url); if (ret < 0) { + /* Destroy created session because the URL are not valid. */ + lttng_destroy_session(session_name); goto error; } - } else if ((!opt_ctrl_url && opt_data_url) || - (opt_ctrl_url && !opt_data_url)) { - ERR("You need both control and data URL."); - ret = CMD_ERROR; - goto error; + } + + MSG("Session %s created.", session_name); + if (print_str_url) { + MSG("Traces will be written in %s", print_str_url); } /* Init lttng session config */ @@ -318,7 +321,6 @@ static int create_session(void) goto error; } - ret = CMD_SUCCESS; error: diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index f2a61072b..3b67923b9 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -73,6 +73,33 @@ static int connected; int lttng_opt_quiet; int lttng_opt_verbose; +/* + * Compare two URL destination. + * + * Return 0 is equal else is not equal. + */ +static int compare_destination(struct lttng_uri *ctrl, struct lttng_uri *data) +{ + int ret; + + assert(ctrl); + assert(data); + + switch (ctrl->dtype) { + case LTTNG_DST_IPV4: + ret = strncmp(ctrl->dst.ipv4, data->dst.ipv4, sizeof(ctrl->dst.ipv4)); + break; + case LTTNG_DST_IPV6: + ret = strncmp(ctrl->dst.ipv6, data->dst.ipv6, sizeof(ctrl->dst.ipv6)); + break; + default: + ret = -1; + break; + } + + return ret; +} + static void set_default_url_attr(struct lttng_uri *uri, enum lttng_stream_type stype) { @@ -158,6 +185,8 @@ static ssize_t parse_str_urls_to_uri(const char *ctrl_url, const char *data_url, } if (data_url) { + int ret; + /* We have to parse the data URL in this case */ size_data = uri_parse(data_url, &data_uris); if (size_data < 1) { @@ -169,6 +198,12 @@ static ssize_t parse_str_urls_to_uri(const char *ctrl_url, const char *data_url, } set_default_url_attr(&data_uris[0], LTTNG_STREAM_DATA); + + ret = compare_destination(&ctrl_uris[0], &data_uris[0]); + if (ret != 0) { + ERR("Control and data destination mismatch"); + goto error; + } } /* Compute total size */ -- 2.34.1