#include "traceable-app.h"
#include "lttng-kconsumerd.h"
#include "libustctl.h"
+#include "utils.h"
/*
* TODO:
/* Create all channel directories */
cds_list_for_each_entry(chan, &session->channel_list.head, list) {
DBG("Creating trace directory at %s", chan->pathname);
- // TODO: recursive create dir
- ret = mkdir(chan->pathname, S_IRWXU | S_IRWXG );
+ ret = mkdir_recursive(chan->pathname, S_IRWXU | S_IRWXG );
if (ret < 0) {
if (ret != EEXIST) {
- perror("mkdir trace path");
- ret = -errno;
+ ERR("Trace directory creation error");
goto error;
}
}
chan->attr.num_subbuf = DEFAULT_CHANNEL_SUBBUF_NUM;
chan->attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
chan->attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
+ chan->attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
error:
return chan;
DBG("Creating default kernel channel %s", DEFAULT_CHANNEL_NAME);
- ret = kernel_create_channel(session->kernel_session, chan);
+ ret = kernel_create_channel(session->kernel_session, chan, session->path);
if (ret < 0) {
ret = LTTCOMM_KERN_CHAN_FAIL;
goto error;
* Check kernel command for kernel session.
*/
switch (cmd_ctx->lsm->cmd_type) {
+ case LTTNG_KERNEL_ADD_CONTEXT:
case LTTNG_KERNEL_CREATE_CHANNEL:
case LTTNG_KERNEL_DISABLE_ALL_EVENT:
case LTTNG_KERNEL_DISABLE_CHANNEL:
/* Process by command type */
switch (cmd_ctx->lsm->cmd_type) {
+ case LTTNG_KERNEL_ADD_CONTEXT:
+ {
+ int found = 0, no_event = 0;
+ struct ltt_kernel_channel *chan;
+ struct ltt_kernel_event *event;
+
+ /* Setup lttng message with no payload */
+ ret = setup_lttng_msg(cmd_ctx, 0);
+ if (ret < 0) {
+ goto setup_error;
+ }
+
+ /* Check if event name is given */
+ if (strlen(cmd_ctx->lsm->u.context.event_name) == 0) {
+ no_event = 1;
+ }
+
+ if (strlen(cmd_ctx->lsm->u.context.channel_name) == 0) {
+ /* Go over all channels */
+ DBG("Adding context to all channels");
+ cds_list_for_each_entry(chan,
+ &cmd_ctx->session->kernel_session->channel_list.head, list) {
+ if (no_event) {
+ ret = kernel_add_channel_context(chan,
+ &cmd_ctx->lsm->u.context.ctx);
+ if (ret < 0) {
+ continue;
+ }
+ } else {
+ event = get_kernel_event_by_name(cmd_ctx->lsm->u.context.event_name, chan);
+ if (event != NULL) {
+ ret = kernel_add_event_context(event,
+ &cmd_ctx->lsm->u.context.ctx);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CONTEXT_FAIL;
+ goto error;
+ }
+ found = 1;
+ break;
+ }
+ }
+ }
+ } else {
+ chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.context.channel_name,
+ cmd_ctx->session->kernel_session);
+ if (chan == NULL) {
+ ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
+ goto error;
+ }
+
+ if (no_event) {
+ ret = kernel_add_channel_context(chan,
+ &cmd_ctx->lsm->u.context.ctx);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CONTEXT_FAIL;
+ goto error;
+ }
+ } else {
+ event = get_kernel_event_by_name(cmd_ctx->lsm->u.context.event_name, chan);
+ if (event != NULL) {
+ ret = kernel_add_event_context(event,
+ &cmd_ctx->lsm->u.context.ctx);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CONTEXT_FAIL;
+ goto error;
+ }
+ }
+ }
+ }
+
+ if (!found && !no_event) {
+ ret = LTTCOMM_NO_EVENT;
+ goto error;
+ }
+
+ ret = LTTCOMM_OK;
+ break;
+ }
case LTTNG_KERNEL_CREATE_CHANNEL:
{
/* Setup lttng message with no payload */
DBG("Creating kernel channel");
ret = kernel_create_channel(cmd_ctx->session->kernel_session,
- &cmd_ctx->lsm->u.channel.chan);
+ &cmd_ctx->lsm->u.channel.chan, cmd_ctx->session->path);
if (ret < 0) {
ret = LTTCOMM_KERN_CHAN_FAIL;
goto error;
ret = kernel_create_event(&ev_attr, chan);
if (ret < 0) {
/* Ignore error here and continue */
- continue;
}
}
if (cmd_ctx->session->kernel_session != NULL) {
if (cmd_ctx->session->kernel_session->metadata == NULL) {
DBG("Open kernel metadata");
- ret = kernel_open_metadata(cmd_ctx->session->kernel_session);
+ ret = kernel_open_metadata(cmd_ctx->session->kernel_session,
+ cmd_ctx->session->path);
if (ret < 0) {
ret = LTTCOMM_KERN_META_FAIL;
goto error;
return ret;
}
-/*
- * get_home_dir
- *
- * Return pointer to home directory path using
- * the env variable HOME.
- *
- * Default : /tmp
- */
-static const char *get_home_dir(void)
-{
- const char *home_path;
-
- if ((home_path = (const char *) getenv("HOME")) == NULL) {
- home_path = default_home_dir;
- }
-
- return home_path;
-}
-
/*
* set_permissions
*
* Set the tracing group gid onto the client socket.
*
* Race window between mkdir and chown is OK because we are going from
- * less permissive (root.root) to more permissive (root.tracing).
+ * more permissive (root.root) to les permissive (root.tracing).
*/
static int set_permissions(void)
{
(grp = getgrnam(default_tracing_group));
if (grp == NULL) {
- ERR("Missing tracing group. Aborting execution.\n");
- ret = -1;
+ if (is_root) {
+ WARN("No tracing group detected");
+ ret = 0;
+ } else {
+ ERR("Missing tracing group. Aborting execution.");
+ ret = -1;
+ }
goto end;
}
{
int ret = 0;
void *status;
+ const char *home_path;
/* Parse arguments */
progname = argv[0];
/* Set ulimit for open files */
set_ulimit();
} else {
+ home_path = get_home_dir();
+ if (home_path == NULL) {
+ ERR("Can't get HOME directory for sockets creation.\n \
+ Please specify --socket PATH.");
+ goto error;
+ }
+
if (strlen(apps_unix_sock_path) == 0) {
snprintf(apps_unix_sock_path, PATH_MAX,
- DEFAULT_HOME_APPS_UNIX_SOCK, get_home_dir());
+ DEFAULT_HOME_APPS_UNIX_SOCK, home_path);
}
/* Set the cli tool unix socket path */
if (strlen(client_unix_sock_path) == 0) {
snprintf(client_unix_sock_path, PATH_MAX,
- DEFAULT_HOME_CLIENT_UNIX_SOCK, get_home_dir());
+ DEFAULT_HOME_CLIENT_UNIX_SOCK, home_path);
}
}