Fix: validate number of subbuffers after tweaking properties
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 20 Apr 2016 15:19:57 +0000 (11:19 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 16 Jun 2016 13:26:26 +0000 (09:26 -0400)
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 <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/channel.c
src/bin/lttng-sessiond/cmd.c

index 8ceb4e8930321ed947ea1216c782558811f0b753..f35410e3ae3fe85c1a7b05e87d3c25e5865795ae 100644 (file)
@@ -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
index cc26e6dae004baeab4177f3589a0e837e7deba34..c74da94f4cc8ab8ebcbdcccb91fe72f37a125615 100644 (file)
@@ -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:
        {
This page took 0.028847 seconds and 5 git commands to generate.