X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconsumer.c;h=53806b08d8ee4a0dcd54b80ee71edaca221fd784;hb=55009a2289249d5d784c528234b0fbcd532f5551;hp=f4eaf705f0b811230d0a9bb1f2f74458c7f7e6d0;hpb=c30aaa51f34105a7f20b9ceb39866001843db6e6;p=lttng-tools.git diff --git a/src/common/consumer.c b/src/common/consumer.c index f4eaf705f..53806b08d 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -345,7 +345,8 @@ struct lttng_consumer_stream *consumer_allocate_stream( uid_t uid, gid_t gid, int net_index, - int metadata_flag) + int metadata_flag, + int *alloc_ret) { struct lttng_consumer_stream *stream; int ret; @@ -353,12 +354,13 @@ struct lttng_consumer_stream *consumer_allocate_stream( stream = zmalloc(sizeof(*stream)); if (stream == NULL) { perror("malloc struct lttng_consumer_stream"); - goto end; + *alloc_ret = -ENOMEM; + return NULL; } stream->chan = consumer_find_channel(channel_key); if (!stream->chan) { - perror("Unable to find channel key"); - goto end; + *alloc_ret = -ENOENT; + goto error; } stream->chan->refcount++; stream->key = stream_key; @@ -387,14 +389,14 @@ struct lttng_consumer_stream *consumer_allocate_stream( stream->cpu = stream->chan->cpucount++; ret = lttng_ustconsumer_allocate_stream(stream); if (ret) { - free(stream); - return NULL; + *alloc_ret = -EINVAL; + goto error; } break; default: ERR("Unknown consumer_data type"); - assert(0); - goto end; + *alloc_ret = -EINVAL; + goto error; } /* @@ -413,9 +415,11 @@ struct lttng_consumer_stream *consumer_allocate_stream( stream->shm_fd, stream->wait_fd, (unsigned long long) stream->mmap_len, stream->out_fd, stream->net_seq_idx); - -end: return stream; + +error: + free(stream); + return NULL; } /* @@ -1719,20 +1723,13 @@ restart: close(ctx->consumer_metadata_pipe[0]); continue; } else if (revents & LPOLLIN) { - stream = zmalloc(sizeof(struct lttng_consumer_stream)); - if (stream == NULL) { - PERROR("zmalloc metadata consumer stream"); - goto error; - } - do { - /* Get the stream and add it to the local hash table */ - ret = read(pollfd, stream, - sizeof(struct lttng_consumer_stream)); + /* Get the stream pointer received */ + ret = read(pollfd, &stream, sizeof(stream)); } while (ret < 0 && errno == EINTR); - if (ret < 0 || ret < sizeof(struct lttng_consumer_stream)) { + if (ret < 0 || + ret < sizeof(struct lttng_consumer_stream *)) { PERROR("read metadata stream"); - free(stream); /* * Let's continue here and hope we can still work * without stopping the consumer. XXX: Should we?