Fix: allow empty URL for live session creation
authorDavid Goulet <dgoulet@efficios.com>
Mon, 24 Mar 2014 18:23:00 +0000 (14:23 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 24 Mar 2014 18:46:23 +0000 (14:46 -0400)
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 <dgoulet@efficios.com>
src/bin/lttng/commands/create.c
src/lib/lttng-ctl/lttng-ctl.c
tests/regression/tools/live/test_lttng_ust

index a5f92f14a31c37ddddce57a925f4f2772cf3e38d..4a47d6714f8f9b38f6f48b5f6363bfa1e4e17125 100644 (file)
@@ -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");
index 8e2593db125acb4f30c0a7e7b076395b685682f3..100e587d9e206905b1327bfd790f5b8f1888a8ac 100644 (file)
@@ -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;
index 70af04314393327d019c5c0720bb18393ecaa34b..db63b4b8757ebead092a3ac6604665f1b951b3db 100755 (executable)
@@ -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
This page took 0.029241 seconds and 5 git commands to generate.