From 1a2416565951eff19530564c552931cc71866e8c Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 24 Mar 2014 14:23:00 -0400 Subject: [PATCH 1/1] Fix: allow empty URL for live session creation This is actually very important so -C/-D can be used with lttng create --live command and also the load command can set the control and data URL independently. This also adds a small test to make sure -C/-D works in live mode. Fixes #769 Signed-off-by: David Goulet --- src/bin/lttng/commands/create.c | 24 +++++++++++++--------- src/lib/lttng-ctl/lttng-ctl.c | 22 ++++++++++++-------- tests/regression/tools/live/test_lttng_ust | 15 ++++++++++++-- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index a5f92f14a..4a47d6714 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -291,6 +291,12 @@ static int create_session(void) } } + 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; + } + if (opt_output_path != NULL) { traces_path = utils_expand_path(opt_output_path); if (traces_path == NULL) { @@ -311,6 +317,12 @@ static int create_session(void) } else if (opt_url) { /* Handling URL (-U opt) */ url = opt_url; print_str_url = url; + } else if (opt_data_url && opt_ctrl_url) { + /* + * With both control and data, we'll be setting the consumer URL after + * session creation thus use no URL. + */ + url = NULL; } else if (!opt_no_output) { /* Auto output path */ alloc_path = utils_get_home_dir(); @@ -332,22 +344,14 @@ static int create_session(void) } url = alloc_url; - if (!opt_data_url && !opt_ctrl_url) { - print_str_url = alloc_url + strlen("file://"); - } + print_str_url = alloc_url + strlen("file://"); } else { /* No output means --no-output or --snapshot mode. */ url = NULL; } - 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; - } - + /* Use default live URL if NO url is/are found. */ if ((opt_live_timer && !opt_url) && (opt_live_timer && !opt_data_url)) { - /* Use default live URL if none is found. */ ret = asprintf(&alloc_url, "net://127.0.0.1"); if (ret < 0) { PERROR("asprintf default live URL"); diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 8e2593db1..100e587d9 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -1572,16 +1572,20 @@ int lttng_create_session_live(const char *name, const char *url, lsm.cmd_type = LTTNG_CREATE_SESSION_LIVE; lttng_ctl_copy_string(lsm.session.name, name, sizeof(lsm.session.name)); - size = uri_parse_str_urls(url, NULL, &uris); - if (size <= 0) { - ret = -LTTNG_ERR_INVALID; - goto end; - } + if (url) { + size = uri_parse_str_urls(url, NULL, &uris); + if (size <= 0) { + ret = -LTTNG_ERR_INVALID; + goto end; + } - /* file:// is not accepted for live session. */ - if (uris[0].dtype == LTTNG_DST_PATH) { - ret = -LTTNG_ERR_INVALID; - goto end; + /* file:// is not accepted for live session. */ + if (uris[0].dtype == LTTNG_DST_PATH) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + } else { + size = 0; } lsm.u.session_live.nb_uri = size; diff --git a/tests/regression/tools/live/test_lttng_ust b/tests/regression/tools/live/test_lttng_ust index 70af04314..db63b4b87 100755 --- a/tests/regression/tools/live/test_lttng_ust +++ b/tests/regression/tools/live/test_lttng_ust @@ -38,7 +38,7 @@ TRACE_PATH=$(mktemp -d) DIR=$(readlink -f $TESTDIR) -NUM_TESTS=10 +NUM_TESTS=11 source $TESTDIR/utils/utils.sh @@ -47,6 +47,14 @@ plan_tests $NUM_TESTS print_test_banner "$TEST_DESC" +function test_custom_url() +{ + # Create session with custom URL + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live $DELAY_USEC \ + -C tcp://localhost:1819 -D tcp://localhost:9187 >/dev/null 2>&1 + ok $? "Create session in live mode with delay $DELAY_USEC and custom URLs" +} + function setup_live_tracing() { # Create session with default path @@ -80,6 +88,9 @@ clean_live_tracing trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH rm -rf $TRACE_PATH - stop_lttng_relayd + +test_custom_url +pkill $RELAYD_BIN + stop_lttng_sessiond -- 2.34.1