From: Mathieu Desnoyers Date: Wed, 20 Apr 2016 15:19:57 +0000 (-0400) Subject: Fix: validate number of subbuffers after tweaking properties X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=commitdiff_plain;h=da9d9d9c356b75f54a55b6691759269d5ebfd5cf Fix: validate number of subbuffers after tweaking properties There are properties that are tweaked by each of ust and kernel channel create functions after a validation on the number of subbuffers for overwrite channels. Move validation after those properties modifications. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c index 8ceb4e893..f35410e3a 100644 --- a/src/bin/lttng-sessiond/channel.c +++ b/src/bin/lttng-sessiond/channel.c @@ -179,6 +179,19 @@ error: return ret; } +static int channel_validate(struct lttng_channel *attr) +{ + /* + * The ringbuffer (both in user space and kernel) behaves badly + * in overwrite mode and with less than 2 subbuffers so block it + * right away and send back an invalid attribute error. + */ + if (attr->attr.overwrite && attr->attr.num_subbuf < 2) { + return -1; + } + return 0; +} + /* * Create kernel channel of the kernel session and notify kernel thread. */ @@ -207,6 +220,12 @@ int channel_kernel_create(struct ltt_kernel_session *ksession, attr->attr.output = LTTNG_EVENT_MMAP; } + /* Validate common channel properties. */ + if (channel_validate(attr) < 0) { + ret = LTTNG_ERR_INVALID; + goto error; + } + /* Channel not found, creating it */ ret = kernel_create_channel(ksession, attr); if (ret < 0) { @@ -305,6 +324,12 @@ int channel_ust_create(struct ltt_ust_session *usess, attr->attr.output = LTTNG_EVENT_MMAP; } + /* Validate common channel properties. */ + if (channel_validate(attr) < 0) { + ret = LTTNG_ERR_INVALID; + goto error; + } + /* * Validate UST buffer size and number of buffers: must both be power of 2 * and nonzero. We validate right here for UST, because applications will diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index cc26e6dae..c74da94f4 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1333,16 +1333,6 @@ int cmd_enable_channel(struct ltt_session *session, attr->attr.switch_timer_interval = 0; } - /* - * The ringbuffer (both in user space and kernel) behave badly in overwrite - * mode and with less than 2 subbuf so block it right away and send back an - * invalid attribute error. - */ - if (attr->attr.overwrite && attr->attr.num_subbuf < 2) { - ret = LTTNG_ERR_INVALID; - goto error; - } - switch (domain->type) { case LTTNG_DOMAIN_KERNEL: {