X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Flttng-ctl.c;h=dafe085dc9bc40b81f53a35b13fbc6791969492f;hb=441c16a7f0bbab56a5e783059d0cddab68544a9a;hp=c62dcfa1d4b335748f5c192fe8b712120a71decb;hpb=1c8d13c8a4111fcfd4cc00c335d47506ab98bb33;p=lttng-tools.git diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index c62dcfa1d..dafe085dc 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -74,6 +74,7 @@ static void copy_lttng_domain(struct lttng_domain *dst, struct lttng_domain *src memcpy(dst, src, sizeof(struct lttng_domain)); break; default: + memset(dst, 0, sizeof(struct lttng_domain)); dst->type = LTTNG_DOMAIN_KERNEL; break; } @@ -227,35 +228,33 @@ static int set_session_daemon_path(void) in_tgroup = check_tracing_group(tracing_group); } - if (uid == 0) { - /* Root */ - copy_string(sessiond_sock_path, - DEFAULT_GLOBAL_CLIENT_UNIX_SOCK, - sizeof(sessiond_sock_path)); - } else if (in_tgroup) { - /* Tracing group */ - copy_string(sessiond_sock_path, - DEFAULT_GLOBAL_CLIENT_UNIX_SOCK, + if ((uid == 0) || in_tgroup) { + copy_string(sessiond_sock_path, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK, sizeof(sessiond_sock_path)); + } - ret = try_connect_sessiond(sessiond_sock_path); - if (ret < 0) { - /* Global session daemon not available */ - if (snprintf(sessiond_sock_path, sizeof(sessiond_sock_path), - DEFAULT_HOME_CLIENT_UNIX_SOCK, - getenv("HOME")) < 0) { - return -ENOMEM; + if (uid != 0) { + if (in_tgroup) { + /* Tracing group */ + ret = try_connect_sessiond(sessiond_sock_path); + if (ret >= 0) { + goto end; } + /* Global session daemon not available... */ } - } else { - /* Not in tracing group and not root, default */ - if (snprintf(sessiond_sock_path, PATH_MAX, - DEFAULT_HOME_CLIENT_UNIX_SOCK, - getenv("HOME")) < 0) { + /* ...or not in tracing group (and not root), default */ + + /* + * With GNU C < 2.1, snprintf returns -1 if the target buffer is too small; + * With GNU C >= 2.1, snprintf returns the required size (excluding closing null) + */ + ret = snprintf(sessiond_sock_path, sizeof(sessiond_sock_path), + DEFAULT_HOME_CLIENT_UNIX_SOCK, getenv("HOME")); + if ((ret < 0) || (ret >= sizeof(sessiond_sock_path))) { return -ENOMEM; } } - +end: return 0; } @@ -468,7 +467,10 @@ int lttng_stop_tracing(const char *session_name) } /* - * Add context to event or/and channel. + * Add context to event and/or channel. + * If event_name is NULL, the context is applied to all events of the channel. + * If channel_name is NULL, a lookup of the event's channel is done. + * If both are NULL, the context is applied to all events of all channels. * * Returns the size of the returned payload data or a negative error code. */ @@ -483,6 +485,8 @@ int lttng_add_context(struct lttng_handle *handle, return -1; } + memset(&lsm, 0, sizeof(lsm)); + lsm.cmd_type = LTTNG_ADD_CONTEXT; /* Copy channel name */ @@ -517,6 +521,8 @@ int lttng_enable_event(struct lttng_handle *handle, return -1; } + memset(&lsm, 0, sizeof(lsm)); + /* If no channel name, we put the default name */ if (channel_name == NULL) { copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME, @@ -556,6 +562,8 @@ int lttng_disable_event(struct lttng_handle *handle, const char *name, return -1; } + memset(&lsm, 0, sizeof(lsm)); + if (channel_name) { copy_string(lsm.u.disable.channel_name, channel_name, sizeof(lsm.u.disable.channel_name)); @@ -595,6 +603,8 @@ int lttng_enable_channel(struct lttng_handle *handle, return -1; } + memset(&lsm, 0, sizeof(lsm)); + memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan)); lsm.cmd_type = LTTNG_ENABLE_CHANNEL; @@ -620,6 +630,8 @@ int lttng_disable_channel(struct lttng_handle *handle, const char *name) return -1; } + memset(&lsm, 0, sizeof(lsm)); + lsm.cmd_type = LTTNG_DISABLE_CHANNEL; copy_string(lsm.u.disable.channel_name, name, @@ -860,11 +872,13 @@ int lttng_calibrate(struct lttng_handle *handle, /* * Set default channel attributes. - * If either or both of the arguments are null, nothing happens. + * If either or both of the arguments are null, attr content is zeroe'd. */ void lttng_channel_set_default_attr(struct lttng_domain *domain, struct lttng_channel_attr *attr) { + memset(attr, 0, sizeof(struct lttng_channel_attr)); + /* Safety check */ if (attr == NULL || domain == NULL) { return; @@ -895,8 +909,7 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain, attr->output = DEFAULT_UST_CHANNEL_OUTPUT; break; default: - /* Default behavior */ - memset(attr, 0, sizeof(struct lttng_channel_attr)); + /* Default behavior: leave set to 0. */ break; } }