From: David Goulet Date: Mon, 25 Nov 2013 19:16:39 +0000 (-0500) Subject: Fix: implicit conversion of enum types in consumer X-Git-Tag: v2.3.2~32 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3f84e025445a0cb91a16a89b0c932b5bbe614cfc;p=lttng-tools.git Fix: implicit conversion of enum types in consumer This actually remove the use of LTTNG_ERR* code in the sessiond/consumer protocol since it should NOT be used and some comparison of enum (lttng_error_code vs lttcomm_return_code) were broken and dangerous. Signed-off-by: David Goulet Conflicts: src/bin/lttng-sessiond/ust-consumer.c src/common/kernel-consumer/kernel-consumer.c --- diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 8f05476a7..d4455e5c8 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -141,7 +141,7 @@ int consumer_recv_status_reply(struct consumer_socket *sock) goto end; } - if (reply.ret_code == LTTNG_OK) { + if (reply.ret_code == LTTCOMM_CONSUMERD_SUCCESS) { /* All good. */ ret = 0; } else { @@ -177,13 +177,14 @@ int consumer_recv_status_channel(struct consumer_socket *sock, } /* An error is possible so don't touch the key and stream_count. */ - if (reply.ret_code != LTTNG_OK) { + if (reply.ret_code != LTTCOMM_CONSUMERD_SUCCESS) { ret = -1; goto end; } *key = reply.key; *stream_count = reply.stream_count; + ret = 0; end: return ret; diff --git a/src/bin/lttng-sessiond/ust-consumer.c b/src/bin/lttng-sessiond/ust-consumer.c index 78f29f497..2bbc5b43b 100644 --- a/src/bin/lttng-sessiond/ust-consumer.c +++ b/src/bin/lttng-sessiond/ust-consumer.c @@ -102,7 +102,7 @@ static int ask_channel_creation(struct ust_app_session *ua_sess, struct ust_app_channel *ua_chan, struct consumer_output *consumer, struct consumer_socket *socket, struct ust_registry_session *registry) { - int ret; + int ret, output; uint32_t chan_id; uint64_t key, chan_reg_key; char *pathname = NULL; @@ -141,13 +141,20 @@ static int ask_channel_creation(struct ust_app_session *ua_sess, chan_id = chan_reg->chan_id; } + switch (ua_chan->attr.output) { + case LTTNG_UST_MMAP: + default: + output = LTTNG_EVENT_MMAP; + break; + } + consumer_init_ask_channel_comm_msg(&msg, ua_chan->attr.subbuf_size, ua_chan->attr.num_subbuf, ua_chan->attr.overwrite, ua_chan->attr.switch_timer_interval, ua_chan->attr.read_timer_interval, - (int) ua_chan->attr.output, + output, (int) ua_chan->attr.type, ua_sess->tracing_id, pathname, diff --git a/src/common/consumer.c b/src/common/consumer.c index da24f81c5..bd4eba093 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -854,13 +854,26 @@ struct lttng_consumer_channel *consumer_allocate_channel(uint64_t key, channel->uid = uid; channel->gid = gid; channel->relayd_id = relayd_id; - channel->output = output; channel->tracefile_size = tracefile_size; channel->tracefile_count = tracefile_count; channel->monitor = monitor; pthread_mutex_init(&channel->lock, NULL); pthread_mutex_init(&channel->timer_lock, NULL); + switch (output) { + case LTTNG_EVENT_SPLICE: + channel->output = CONSUMER_CHANNEL_SPLICE; + break; + case LTTNG_EVENT_MMAP: + channel->output = CONSUMER_CHANNEL_MMAP; + break; + default: + assert(0); + free(channel); + channel = NULL; + goto end; + } + /* * In monitor mode, the streams associated with the channel will be put in * a special list ONLY owned by this channel. So, the refcount is set to 1 @@ -3078,7 +3091,7 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type, struct lttcomm_relayd_sock *relayd_sock, uint64_t sessiond_id) { int fd = -1, ret = -1, relayd_created = 0; - enum lttng_error_code ret_code = LTTNG_OK; + enum lttcomm_return_code ret_code = LTTCOMM_CONSUMERD_SUCCESS; struct consumer_relayd_sock_pair *relayd = NULL; assert(ctx); @@ -3114,7 +3127,7 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type, } /* First send a status message before receiving the fds. */ - ret = consumer_send_status_msg(sock, LTTNG_OK); + ret = consumer_send_status_msg(sock, LTTCOMM_CONSUMERD_SUCCESS); if (ret < 0) { /* Somehow, the session daemon is not responding anymore. */ lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_FATAL); @@ -3497,9 +3510,9 @@ int consumer_send_status_channel(int sock, assert(sock >= 0); if (!channel) { - msg.ret_code = -LTTNG_ERR_UST_CHAN_FAIL; + msg.ret_code = LTTCOMM_CONSUMERD_CHANNEL_FAIL; } else { - msg.ret_code = LTTNG_OK; + msg.ret_code = LTTCOMM_CONSUMERD_SUCCESS; msg.key = channel->key; msg.stream_count = channel->streams.count; } diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index bfec4d2f0..712ca90f3 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -408,7 +408,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, int sock, struct pollfd *consumer_sockpoll) { ssize_t ret; - enum lttng_error_code ret_code = LTTNG_OK; + enum lttcomm_return_code ret_code = LTTCOMM_CONSUMERD_SUCCESS; struct lttcomm_consumer_msg msg; ret = lttcomm_recv_unix_sock(sock, &msg, sizeof(msg)); @@ -540,7 +540,8 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, /* Somehow, the session daemon is not responding anymore. */ goto error_fatal; } - if (ret_code != LTTNG_OK) { + + if (ret_code != LTTCOMM_CONSUMERD_SUCCESS) { /* Channel was not found. */ goto end_nosignal; } diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index b98e4f747..736d97809 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -108,6 +108,7 @@ enum lttcomm_relayd_command { * lttcomm error code. */ enum lttcomm_return_code { + LTTCOMM_CONSUMERD_SUCCESS = 0, /* Everything went fine. */ LTTCOMM_CONSUMERD_COMMAND_SOCK_READY = 1, /* Command socket ready */ LTTCOMM_CONSUMERD_SUCCESS_RECV_FD, /* Success on receiving fds */ LTTCOMM_CONSUMERD_ERROR_RECV_FD, /* Error on receiving fds */ @@ -126,6 +127,7 @@ enum lttcomm_return_code { LTTCOMM_CONSUMERD_ERROR_METADATA, /* Error with metadata. */ LTTCOMM_CONSUMERD_FATAL, /* Fatal error. */ LTTCOMM_CONSUMERD_RELAYD_FAIL, /* Error on remote relayd */ + LTTCOMM_CONSUMERD_CHANNEL_FAIL, /* Channel creation failed. */ /* MUST be last element */ LTTCOMM_NR, /* Last element */ @@ -412,11 +414,11 @@ struct lttcomm_consumer_msg { * Status message returned to the sessiond after a received command. */ struct lttcomm_consumer_status_msg { - enum lttng_error_code ret_code; + enum lttcomm_return_code ret_code; } LTTNG_PACKED; struct lttcomm_consumer_status_channel { - enum lttng_error_code ret_code; + enum lttcomm_return_code ret_code; uint64_t key; unsigned int stream_count; } LTTNG_PACKED; diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 6a692b9ba..6be3ed976 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -399,7 +399,7 @@ static int send_sessiond_channel(int sock, struct lttng_consumer_channel *channel, struct lttng_consumer_local_data *ctx, int *relayd_error) { - int ret, ret_code = LTTNG_OK; + int ret, ret_code = LTTCOMM_CONSUMERD_SUCCESS; struct lttng_consumer_stream *stream; assert(channel); @@ -427,7 +427,7 @@ static int send_sessiond_channel(int sock, /* Inform sessiond that we are about to send channel and streams. */ ret = consumer_send_status_msg(sock, ret_code); - if (ret < 0 || ret_code != LTTNG_OK) { + if (ret < 0 || ret_code != LTTCOMM_CONSUMERD_SUCCESS) { /* * Either the session daemon is not responding or the relayd died so we * stop now. @@ -466,7 +466,7 @@ static int send_sessiond_channel(int sock, return 0; error: - if (ret_code != LTTNG_OK) { + if (ret_code != LTTCOMM_CONSUMERD_SUCCESS) { ret = -1; } return ret; @@ -615,7 +615,7 @@ error: */ static int _close_metadata(struct lttng_consumer_channel *channel) { - int ret = LTTNG_OK; + int ret = LTTCOMM_CONSUMERD_SUCCESS; assert(channel); assert(channel->type == CONSUMER_CHANNEL_TYPE_METADATA); @@ -1024,7 +1024,7 @@ int lttng_ustconsumer_recv_metadata(int sock, uint64_t key, uint64_t offset, uint64_t len, struct lttng_consumer_channel *channel, int timer) { - int ret, ret_code = LTTNG_OK; + int ret, ret_code = LTTCOMM_CONSUMERD_SUCCESS; char *metadata_str; DBG("UST consumer push metadata key %" PRIu64 " of len %" PRIu64, key, len); @@ -1079,7 +1079,7 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, int sock, struct pollfd *consumer_sockpoll) { ssize_t ret; - enum lttng_error_code ret_code = LTTNG_OK; + enum lttcomm_return_code ret_code = LTTCOMM_CONSUMERD_SUCCESS; struct lttcomm_consumer_msg msg; struct lttng_consumer_channel *channel = NULL; @@ -1212,9 +1212,16 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, attr.switch_timer_interval = msg.u.ask_channel.switch_timer_interval; attr.read_timer_interval = msg.u.ask_channel.read_timer_interval; attr.chan_id = msg.u.ask_channel.chan_id; - attr.output = msg.u.ask_channel.output; memcpy(attr.uuid, msg.u.ask_channel.uuid, sizeof(attr.uuid)); + /* Match channel buffer type to the UST abi. */ + switch (msg.u.ask_channel.output) { + case LTTNG_EVENT_MMAP: + default: + attr.output = LTTNG_UST_MMAP; + break; + } + /* Translate and save channel type. */ switch (msg.u.ask_channel.type) { case LTTNG_UST_CHAN_PER_CPU: @@ -1389,7 +1396,7 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, } /* Tell session daemon we are ready to receive the metadata. */ - ret = consumer_send_status_msg(sock, LTTNG_OK); + ret = consumer_send_status_msg(sock, LTTCOMM_CONSUMERD_SUCCESS); if (ret < 0) { /* Somehow, the session daemon is not responding anymore. */ goto error_fatal; @@ -1868,7 +1875,7 @@ int lttng_ustconsumer_request_metadata(struct lttng_consumer_local_data *ctx, { struct lttcomm_metadata_request_msg request; struct lttcomm_consumer_msg msg; - enum lttng_error_code ret_code = LTTNG_OK; + enum lttcomm_return_code ret_code = LTTCOMM_CONSUMERD_SUCCESS; uint64_t len, key, offset; int ret; @@ -1948,7 +1955,7 @@ int lttng_ustconsumer_request_metadata(struct lttng_consumer_local_data *ctx, /* Tell session daemon we are ready to receive the metadata. */ ret = consumer_send_status_msg(ctx->consumer_metadata_socket, - LTTNG_OK); + LTTCOMM_CONSUMERD_SUCCESS); if (ret < 0 || len == 0) { /* * Somehow, the session daemon is not responding anymore or there is