*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation; only version 2
+ * of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "session.h"
#include "traceable-app.h"
#include "lttng-kconsumerd.h"
-#include "libustctl.h"
#include "utils.h"
/*
*
* Free memory of a command context structure.
*/
-static void clean_command_ctx(struct command_ctx *cmd_ctx)
+static void clean_command_ctx(struct command_ctx **cmd_ctx)
{
- DBG("Clean command context structure %p", cmd_ctx);
- if (cmd_ctx) {
- if (cmd_ctx->llm) {
- free(cmd_ctx->llm);
+ DBG("Clean command context structure");
+ if (*cmd_ctx) {
+ if ((*cmd_ctx)->llm) {
+ free((*cmd_ctx)->llm);
}
- if (cmd_ctx->lsm) {
- free(cmd_ctx->lsm);
+ if ((*cmd_ctx)->lsm) {
+ free((*cmd_ctx)->lsm);
}
- free(cmd_ctx);
- cmd_ctx = NULL;
+ free(*cmd_ctx);
+ *cmd_ctx = NULL;
}
}
return ret;
}
+#ifdef DISABLED
/*
* ust_connect_app
*
return sock;
}
+#endif /* DISABLED */
/*
* notify_apps
DBG("Updating kernel_pollfd");
/* Get the number of channel of all kernel session */
- pthread_mutex_lock(&session_list_ptr->lock);
+ lock_session_list();
cds_list_for_each_entry(session, &session_list_ptr->head, list) {
lock_session(session);
if (session->kernel_session == NULL) {
}
unlock_session(session);
}
- pthread_mutex_unlock(&session_list_ptr->lock);
+ unlock_session_list();
/* Adding wake up pipe */
kernel_pollfd[nb_fd - 2].fd = kernel_poll_pipe[0];
return nb_fd;
error:
- pthread_mutex_unlock(&session_list_ptr->lock);
+ unlock_session_list();
return -1;
}
DBG("Updating kernel streams for channel fd %d", fd);
- pthread_mutex_lock(&session_list_ptr->lock);
+ lock_session_list();
cds_list_for_each_entry(session, &session_list_ptr->head, list) {
lock_session(session);
if (session->kernel_session == NULL) {
}
end:
+ unlock_session_list();
if (session) {
unlock_session(session);
}
- pthread_mutex_unlock(&session_list_ptr->lock);
return ret;
}
/*
* Exec kconsumerd.
*/
- execlp("ltt-kconsumerd", "ltt-kconsumerd", "--verbose", NULL);
+ execl(INSTALL_BIN_PATH "/ltt-kconsumerd", "ltt-kconsumerd", "--quiet", NULL);
if (errno != 0) {
perror("kernel start consumer exec");
}
*/
static int start_kernel_trace(struct ltt_kernel_session *session)
{
- int ret;
+ int ret = 0;
if (session->kconsumer_fds_sent == 0) {
ret = send_kconsumerd_fds(kconsumerd_cmd_sock, session);
static int create_kernel_session(struct ltt_session *session)
{
int ret;
- struct lttng_channel *chan;
DBG("Creating kernel session");
goto error;
}
- chan = init_default_channel();
- if (chan == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
ret = mkdir_recursive(session->path, S_IRWXU | S_IRWXG );
if (ret < 0) {
if (ret != EEXIST) {
}
}
- DBG("Creating default kernel channel %s", DEFAULT_CHANNEL_NAME);
-
- ret = kernel_create_channel(session->kernel_session, chan, session->path);
- if (ret < 0) {
- ret = LTTCOMM_KERN_CHAN_FAIL;
- goto error;
- }
-
- ret = notify_kernel_pollfd();
-
error:
return ret;
}
+/*
+ * Using the session list, filled a lttng_session array to send back to the
+ * client for session listing.
+ *
+ * The session list lock MUST be acquired before calling this function. Use
+ * lock_session_list() and unlock_session_list().
+ */
+static void list_lttng_sessions(struct lttng_session *sessions)
+{
+ int i = 0;
+ struct ltt_session *session;
+
+ DBG("Getting all available session");
+ /*
+ * Iterate over session list and append data after the control struct in
+ * the buffer.
+ */
+ cds_list_for_each_entry(session, &session_list_ptr->head, list) {
+ strncpy(sessions[i].path, session->path, PATH_MAX);
+ strncpy(sessions[i].name, session->name, NAME_MAX);
+ i++;
+ }
+}
+
/*
* process_client_msg
*
*/
static int process_client_msg(struct command_ctx *cmd_ctx)
{
- int ret;
+ int ret = LTTCOMM_OK;
DBG("Processing client command %d", cmd_ctx->lsm->cmd_type);
*/
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:
case LTTNG_KERNEL_DISABLE_EVENT:
}
}
+#ifdef DISABLED
/* Connect to ust apps if available pid */
if (cmd_ctx->lsm->pid > 0) {
/* Connect to app using ustctl API */
goto error;
}
}
+#endif /* DISABLED */
/* Process by command type */
switch (cmd_ctx->lsm->cmd_type) {
int found = 0, no_event = 0;
struct ltt_kernel_channel *chan;
struct ltt_kernel_event *event;
+ struct lttng_kernel_context ctx;
/* Setup lttng message with no payload */
ret = setup_lttng_msg(cmd_ctx, 0);
no_event = 1;
}
+ /* Create Kernel context */
+ ctx.ctx = cmd_ctx->lsm->u.context.ctx.ctx;
+ ctx.u.perf_counter.type = cmd_ctx->lsm->u.context.ctx.u.perf_counter.type;
+ ctx.u.perf_counter.config = cmd_ctx->lsm->u.context.ctx.u.perf_counter.config;
+ strncpy(ctx.u.perf_counter.name,
+ cmd_ctx->lsm->u.context.ctx.u.perf_counter.name,
+ sizeof(ctx.u.perf_counter.name));
+
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);
+ ret = kernel_add_channel_context(chan, &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);
+ ret = kernel_add_event_context(event, &ctx);
if (ret < 0) {
ret = LTTCOMM_KERN_CONTEXT_FAIL;
goto error;
}
if (no_event) {
- ret = kernel_add_channel_context(chan,
- &cmd_ctx->lsm->u.context.ctx);
+ ret = kernel_add_channel_context(chan, &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);
+ ret = kernel_add_event_context(event, &ctx);
if (ret < 0) {
ret = LTTCOMM_KERN_CONTEXT_FAIL;
goto error;
ret = LTTCOMM_OK;
break;
}
- case LTTNG_KERNEL_CREATE_CHANNEL:
- {
- /* Setup lttng message with no payload */
- ret = setup_lttng_msg(cmd_ctx, 0);
- if (ret < 0) {
- goto setup_error;
- }
-
- /* Kernel tracer */
- DBG("Creating kernel channel");
-
- ret = kernel_create_channel(cmd_ctx->session->kernel_session,
- &cmd_ctx->lsm->u.channel.chan, cmd_ctx->session->path);
- if (ret < 0) {
- ret = LTTCOMM_KERN_CHAN_FAIL;
- goto error;
- }
-
- ret = notify_kernel_pollfd();
- if (ret < 0) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- ret = LTTCOMM_OK;
- break;
- }
case LTTNG_KERNEL_DISABLE_CHANNEL:
{
struct ltt_kernel_channel *chan;
chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.enable.channel_name,
cmd_ctx->session->kernel_session);
if (chan == NULL) {
- ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
- goto error;
+ /* Channel not found, creating it */
+ DBG("Creating kernel channel");
+
+ ret = kernel_create_channel(cmd_ctx->session->kernel_session,
+ &cmd_ctx->lsm->u.channel.chan, cmd_ctx->session->path);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CHAN_FAIL;
+ goto error;
+ }
+
+ /* Notify kernel thread that there is a new channel */
+ ret = notify_kernel_pollfd();
+ if (ret < 0) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
} else if (chan->enabled == 0) {
ret = kernel_enable_channel(chan);
if (ret < 0) {
}
case LTTNG_KERNEL_ENABLE_EVENT:
{
- struct ltt_kernel_channel *chan;
+ char *channel_name;
+ struct ltt_kernel_channel *kchan;
struct ltt_kernel_event *ev;
+ struct lttng_channel *chan;
/* Setup lttng message with no payload */
ret = setup_lttng_msg(cmd_ctx, 0);
goto setup_error;
}
- chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.enable.channel_name,
- cmd_ctx->session->kernel_session);
- if (chan == NULL) {
- ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
- goto error;
- }
+ channel_name = cmd_ctx->lsm->u.enable.channel_name;
+
+ do {
+ kchan = get_kernel_channel_by_name(channel_name,
+ cmd_ctx->session->kernel_session);
+ if (kchan == NULL) {
+ DBG("Creating default channel");
+
+ chan = init_default_channel();
+ if (chan == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ ret = kernel_create_channel(cmd_ctx->session->kernel_session,
+ chan, cmd_ctx->session->path);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CHAN_FAIL;
+ goto error;
+ }
+ }
+ } while (kchan == NULL);
- ev = get_kernel_event_by_name(cmd_ctx->lsm->u.enable.event.name, chan);
+ ev = get_kernel_event_by_name(cmd_ctx->lsm->u.enable.event.name, kchan);
if (ev == NULL) {
DBG("Creating kernel event %s for channel %s.",
- cmd_ctx->lsm->u.enable.event.name, chan->channel->name);
- ret = kernel_create_event(&cmd_ctx->lsm->u.enable.event, chan);
+ cmd_ctx->lsm->u.enable.event.name, channel_name);
+ ret = kernel_create_event(&cmd_ctx->lsm->u.enable.event, kchan);
} else {
DBG("Enabling kernel event %s for channel %s.",
- cmd_ctx->lsm->u.enable.event.name, chan->channel->name);
+ cmd_ctx->lsm->u.enable.event.name, channel_name);
ret = kernel_enable_event(ev);
+ if (ret == -EEXIST) {
+ ret = LTTCOMM_KERN_EVENT_EXIST;
+ goto error;
+ }
}
if (ret < 0) {
case LTTNG_KERNEL_ENABLE_ALL_EVENT:
{
int pos, size;
- char *event_list, *event, *ptr;
- struct ltt_kernel_channel *chan;
+ char *event_list, *event, *ptr, *channel_name;
+ struct ltt_kernel_channel *kchan;
struct ltt_kernel_event *ev;
struct lttng_event ev_attr;
+ struct lttng_channel *chan;
/* Setup lttng message with no payload */
ret = setup_lttng_msg(cmd_ctx, 0);
DBG("Enabling all kernel event");
- chan = get_kernel_channel_by_name(cmd_ctx->lsm->u.enable.channel_name,
- cmd_ctx->session->kernel_session);
- if (chan == NULL) {
- ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
- goto error;
- }
+ channel_name = cmd_ctx->lsm->u.enable.channel_name;
+
+ do {
+ kchan = get_kernel_channel_by_name(channel_name,
+ cmd_ctx->session->kernel_session);
+ if (kchan == NULL) {
+ DBG("Creating default channel");
+
+ chan = init_default_channel();
+ if (chan == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ ret = kernel_create_channel(cmd_ctx->session->kernel_session,
+ chan, cmd_ctx->session->path);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CHAN_FAIL;
+ goto error;
+ }
+ }
+ } while (kchan == NULL);
/* For each event in the kernel session */
- cds_list_for_each_entry(ev, &chan->events_list.head, list) {
+ cds_list_for_each_entry(ev, &kchan->events_list.head, list) {
DBG("Enabling kernel event %s for channel %s.",
- ev->event->name, chan->channel->name);
+ ev->event->name, channel_name);
ret = kernel_enable_event(ev);
if (ret < 0) {
continue;
ptr = event_list;
while ((size = sscanf(ptr, "event { name = %m[^;]; };%n\n", &event, &pos)) == 1) {
- ev = get_kernel_event_by_name(event, chan);
+ ev = get_kernel_event_by_name(event, kchan);
if (ev == NULL) {
strncpy(ev_attr.name, event, LTTNG_SYM_NAME_LEN);
/* Default event type for enable all */
- ev_attr.type = LTTNG_EVENT_TRACEPOINTS;
+ ev_attr.type = LTTNG_EVENT_TRACEPOINT;
/* Enable each single tracepoint event */
- ret = kernel_create_event(&ev_attr, chan);
+ ret = kernel_create_event(&ev_attr, kchan);
if (ret < 0) {
/* Ignore error here and continue */
}
*/
case LTTNG_LIST_SESSIONS:
{
- unsigned int session_count;
+ lock_session_list();
- session_count = get_session_count();
- if (session_count == 0) {
+ if (session_list_ptr->count == 0) {
ret = LTTCOMM_NO_SESSION;
goto error;
}
- ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_session) * session_count);
+ ret = setup_lttng_msg(cmd_ctx, sizeof(struct lttng_session) *
+ session_list_ptr->count);
if (ret < 0) {
goto setup_error;
}
- get_lttng_session((struct lttng_session *)(cmd_ctx->llm->payload));
+ /* Filled the session array */
+ list_lttng_sessions((struct lttng_session *)(cmd_ctx->llm->payload));
+
+ unlock_session_list();
ret = LTTCOMM_OK;
break;
/* TODO: Inform client somehow of the fatal error. At this point,
* ret < 0 means that a malloc failed (ENOMEM). */
/* Error detected but still accept command */
- clean_command_ctx(cmd_ctx);
+ clean_command_ctx(&cmd_ctx);
continue;
}
ERR("Failed to send data back to client");
}
- clean_command_ctx(cmd_ctx);
+ clean_command_ctx(&cmd_ctx);
/* End of transmission */
close(sock);
unlink(client_unix_sock_path);
- clean_command_ctx(cmd_ctx);
+ clean_command_ctx(&cmd_ctx);
return NULL;
}