Fix: deny the same port for data and control URL
authorDavid Goulet <dgoulet@efficios.com>
Thu, 11 Apr 2013 20:01:20 +0000 (16:01 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 11 Apr 2013 20:19:11 +0000 (16:19 -0400)
This also adds the LTTNG_ERR_NOMEM code and fix a double lttng strerror
print in the lttng create command code.

Fixes #451

Signed-off-by: David Goulet <dgoulet@efficios.com>
include/lttng/lttng-error.h
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/consumer.c
src/bin/lttng/commands/create.c
src/common/error.c

index 4e9b37f6c738eb86569fd500957c9909ee0489b8..be96d9f61f7b8d53cd42bb5a54bd5f7cd5f9dab1 100644 (file)
@@ -56,7 +56,7 @@ enum lttng_error_code {
        LTTNG_ERR_SESS_NOT_FOUND         = 23,  /* Session by name not found */
        LTTNG_ERR_BUFFER_TYPE_MISMATCH   = 24,  /* Buffer type mismatched. */
        LTTNG_ERR_FATAL                  = 25,  /* Fatal error */
-       /* 26 */
+       LTTNG_ERR_NOMEM                  = 26,  /* Not enough memory. */
        LTTNG_ERR_SELECT_SESS            = 27,  /* Must select a session */
        LTTNG_ERR_EXIST_SESS             = 28,  /* Session name already exist */
        LTTNG_ERR_NO_EVENT               = 29,  /* No event found */
index f130f5ebfb17f74f10ec87b1d784359504e99d63..7819002d04472b3f67cfd2501f3f87deb0cf251c 100644 (file)
@@ -397,7 +397,7 @@ static int add_uri_to_consumer(struct consumer_output *consumer,
                /* Set URI into consumer output object */
                ret = consumer_set_network_uri(consumer, uri);
                if (ret < 0) {
-                       ret = LTTNG_ERR_FATAL;
+                       ret = -ret;
                        goto error;
                } else if (ret == 1) {
                        /*
@@ -438,6 +438,8 @@ static int add_uri_to_consumer(struct consumer_output *consumer,
                break;
        }
 
+       ret = LTTNG_OK;
+
 error:
        return ret;
 }
@@ -1646,7 +1648,7 @@ int cmd_set_consumer_uri(int domain, struct ltt_session *session,
 
        for (i = 0; i < nb_uri; i++) {
                ret = add_uri_to_consumer(consumer, &uris[i], domain, session->name);
-               if (ret < 0) {
+               if (ret != LTTNG_OK) {
                        goto error;
                }
        }
index 0cf43d2ca3da002ffb7d68aef558316c75b9006a..e3d1be0ccc3446133746ba3db595242204c355ab 100644 (file)
@@ -504,6 +504,12 @@ int consumer_set_network_uri(struct consumer_output *obj,
                if (uri->port == 0) {
                        /* Assign default port. */
                        uri->port = DEFAULT_NETWORK_CONTROL_PORT;
+               } else {
+                       if (obj->dst.net.data_isset && uri->port ==
+                                       obj->dst.net.data.port) {
+                               ret = -LTTNG_ERR_INVALID;
+                               goto error;
+                       }
                }
                DBG3("Consumer control URI set with port %d", uri->port);
                break;
@@ -513,11 +519,18 @@ int consumer_set_network_uri(struct consumer_output *obj,
                if (uri->port == 0) {
                        /* Assign default port. */
                        uri->port = DEFAULT_NETWORK_DATA_PORT;
+               } else {
+                       if (obj->dst.net.control_isset && uri->port ==
+                                       obj->dst.net.control.port) {
+                               ret = -LTTNG_ERR_INVALID;
+                               goto error;
+                       }
                }
                DBG3("Consumer data URI set with port %d", uri->port);
                break;
        default:
                ERR("Set network uri type unknown %d", uri->stype);
+               ret = -LTTNG_ERR_INVALID;
                goto error;
        }
 
@@ -553,6 +566,7 @@ int consumer_set_network_uri(struct consumer_output *obj,
                }
                if (ret < 0) {
                        PERROR("snprintf set consumer uri subdir");
+                       ret = -LTTNG_ERR_NOMEM;
                        goto error;
                }
 
@@ -564,7 +578,7 @@ int consumer_set_network_uri(struct consumer_output *obj,
 equal:
        return 1;
 error:
-       return -1;
+       return ret;
 }
 
 /*
index 02aaf40f487d471645e12d05d5e224916d68cfa2..bdd180ebb3af3c7517d1413f1c1840cb9168dc87 100644 (file)
@@ -293,7 +293,6 @@ static int create_session(void)
                        WARN("Session %s already exists", session_name);
                        break;
                default:
-                       ERR("%s", lttng_strerror(ret));
                        break;
                }
                goto error;
index 4b9b46e4ec004ac6c2b3bd0b4ef04047d6bb246d..36907c942896e539c49615f6b79763445633e7da 100644 (file)
@@ -107,6 +107,7 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_URL_EXIST) ] = "URL already exists",
        [ ERROR_INDEX(LTTNG_ERR_BUFFER_NOT_SUPPORTED)] = "Buffer type not supported",
        [ ERROR_INDEX(LTTNG_ERR_BUFFER_TYPE_MISMATCH)] = "Buffer type mismatch for session",
+       [ ERROR_INDEX(LTTNG_ERR_NOMEM)] = "Not enough memory",
 
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
This page took 0.032017 seconds and 4 git commands to generate.