Fix: validate number of subbuffers after tweaking properties
[lttng-tools.git] / src / bin / lttng-sessiond / channel.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
This page took 0.026231 seconds and 5 git commands to generate.