From a74934bae19f96845f7af4b95a8fae5c2f860747 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 11 Apr 2013 16:01:20 -0400 Subject: [PATCH] Fix: deny the same port for data and control URL 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 --- include/lttng/lttng-error.h | 2 +- src/bin/lttng-sessiond/cmd.c | 6 ++++-- src/bin/lttng-sessiond/consumer.c | 16 +++++++++++++++- src/bin/lttng/commands/create.c | 1 - src/common/error.c | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index 4e9b37f6c..be96d9f61 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -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 */ diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index f130f5ebf..7819002d0 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -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; } } diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 0cf43d2ca..e3d1be0cc 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -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; } /* diff --git a/src/bin/lttng/commands/create.c b/src/bin/lttng/commands/create.c index 02aaf40f4..bdd180ebb 100644 --- a/src/bin/lttng/commands/create.c +++ b/src/bin/lttng/commands/create.c @@ -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; diff --git a/src/common/error.c b/src/common/error.c index 4b9b46e4e..36907c942 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -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" -- 2.34.1