memcpy(dst, src, sizeof(struct lttng_domain));
break;
default:
+ memset(dst, 0, sizeof(struct lttng_domain));
dst->type = LTTNG_DOMAIN_KERNEL;
break;
}
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;
}
}
/*
- * 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.
*/
return -1;
}
+ memset(&lsm, 0, sizeof(lsm));
+
lsm.cmd_type = LTTNG_ADD_CONTEXT;
/* Copy channel name */
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,
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));
return -1;
}
+ memset(&lsm, 0, sizeof(lsm));
+
memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan));
lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
return -1;
}
+ memset(&lsm, 0, sizeof(lsm));
+
lsm.cmd_type = LTTNG_DISABLE_CHANNEL;
copy_string(lsm.u.disable.channel_name, name,
/*
* 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;
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;
}
}