Do not permit NULL pointer on enable API calls
[lttng-tools.git] / liblttngctl / lttngctl.c
index a1e577b2bb5f7f4bf14d1950c10928719fbc0eae..c91a242f32a246c9f021ac99ddb40f0c0ab66dde 100644 (file)
@@ -335,7 +335,9 @@ static int ask_sessiond(struct lttcomm_session_msg *lsm, void **buf)
        size = llm.data_size;
        if (size == 0) {
                /* If client free with size 0 */
-               *buf = NULL;
+               if (buf != NULL) {
+                       *buf = NULL;
+               }
                ret = 0;
                goto end;
        }
@@ -494,10 +496,11 @@ int lttng_enable_event(struct lttng_handle *handle,
 {
        struct lttcomm_session_msg lsm;
 
-       if (!handle || ev == NULL) {
+       if (handle == NULL || ev == NULL) {
                return -1;
        }
 
+       /* If no channel name, we put the default name */
        if (channel_name == NULL) {
                copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME,
                                sizeof(lsm.u.enable.channel_name));
@@ -564,13 +567,14 @@ int lttng_enable_channel(struct lttng_handle *handle,
 {
        struct lttcomm_session_msg lsm;
 
-       if (!handle) {
+       /*
+        * NULL arguments are forbidden. No default values.
+        */
+       if (handle == NULL || chan == NULL) {
                return -1;
        }
 
-       if (chan) {
-               memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan));
-       }
+       memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan));
 
        lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
 
@@ -782,10 +786,8 @@ int lttng_list_events(struct lttng_handle *handle,
 }
 
 /*
- *  lttng_set_tracing_group
- *
- *  Set tracing group variable with name. This function
- *  allocate memory pointed by tracing_group.
+ * Set tracing group variable with name. This function allocate memory pointed
+ * by tracing_group.
  */
 int lttng_set_tracing_group(const char *name)
 {
@@ -816,6 +818,46 @@ int lttng_calibrate(struct lttng_handle *handle,
        return ask_sessiond(&lsm, NULL);
 }
 
+/*
+ * Set default channel attributes.
+ */
+void lttng_channel_set_default_attr(struct lttng_domain *domain,
+               struct lttng_channel_attr *attr)
+{
+       /* Safety check */
+       if (attr == NULL || domain == NULL) {
+               return;
+       }
+
+       switch (domain->type) {
+       case LTTNG_DOMAIN_KERNEL:
+               attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
+               attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
+               attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
+
+               attr->subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE;
+               attr->num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
+               attr->output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
+               break;
+       case LTTNG_DOMAIN_UST:
+       case LTTNG_DOMAIN_UST_EXEC_NAME:
+       case LTTNG_DOMAIN_UST_PID:
+       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
+               attr->overwrite = DEFAULT_CHANNEL_OVERWRITE;
+               attr->switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
+               attr->read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
+
+               attr->subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE;
+               attr->num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM;
+               attr->output = DEFAULT_UST_CHANNEL_OUTPUT;
+               break;
+       default:
+               /* Default behavior */
+               memset(attr, 0, sizeof(struct lttng_channel_attr));
+               break;
+       }
+}
+
 /*
  * Check if session daemon is alive.
  *
This page took 0.026179 seconds and 4 git commands to generate.