X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=liblttngctl%2Flttngctl.c;h=c91a242f32a246c9f021ac99ddb40f0c0ab66dde;hp=42f3ad2ae9950729c3c53922c759d53173d59ee5;hb=5117eeecf9d4b04ebe5a4e46b48c0d6186bb429b;hpb=2269e89ed1579f2d4fb0bc9a801af03c5c39fa52 diff --git a/liblttngctl/lttngctl.c b/liblttngctl/lttngctl.c index 42f3ad2ae..c91a242f3 100644 --- a/liblttngctl/lttngctl.c +++ b/liblttngctl/lttngctl.c @@ -21,18 +21,17 @@ */ #define _GNU_SOURCE -#include #include +#include #include #include #include #include -#include - #include -#include "lttngerr.h" -#include "lttng-share.h" +#include +#include +#include /* Socket to session daemon for communication */ static int sessiond_socket; @@ -153,6 +152,10 @@ static int check_tracing_group(const char *grp_name) /* Alloc group list of the right size */ grp_list = malloc(grp_list_size * sizeof(gid_t)); + if (!grp_list) { + ret = -1; + goto end; + } grp_id = getgroups(grp_list_size, grp_list); if (grp_id < -1) { perror("getgroups"); @@ -331,6 +334,10 @@ static int ask_sessiond(struct lttcomm_session_msg *lsm, void **buf) size = llm.data_size; if (size == 0) { + /* If client free with size 0 */ + if (buf != NULL) { + *buf = NULL; + } ret = 0; goto end; } @@ -344,6 +351,16 @@ static int ask_sessiond(struct lttcomm_session_msg *lsm, void **buf) goto end; } + /* + * Extra protection not to dereference a NULL pointer. If buf is NULL at + * this point, an error is returned and data is freed. + */ + if (buf == NULL) { + ret = -1; + free(data); + goto end; + } + *buf = data; ret = size; @@ -479,10 +496,11 @@ int lttng_enable_event(struct lttng_handle *handle, { struct lttcomm_session_msg lsm; - if (!handle) { + 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)); @@ -493,12 +511,12 @@ int lttng_enable_event(struct lttng_handle *handle, copy_lttng_domain(&lsm.domain, &handle->domain); - if (ev) { + if (ev->name[0] != '\0') { lsm.cmd_type = LTTNG_ENABLE_EVENT; - memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event)); } else { lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT; } + memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event)); copy_string(lsm.session.name, handle->session_name, sizeof(lsm.session.name)); @@ -528,7 +546,7 @@ int lttng_disable_event(struct lttng_handle *handle, const char *name, copy_lttng_domain(&lsm.domain, &handle->domain); - if (name == NULL) { + if (name != NULL) { copy_string(lsm.u.disable.name, name, sizeof(lsm.u.disable.name)); lsm.cmd_type = LTTNG_DISABLE_EVENT; } else { @@ -549,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; @@ -623,7 +642,7 @@ int lttng_list_tracepoints(struct lttng_handle *handle, /* * Return a human readable string of code */ -const char *lttng_get_readable_code(int code) +const char *lttng_strerror(int code) { if (code > -LTTCOMM_OK) { return "Ended with errors"; @@ -767,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) { @@ -801,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. *