#include <urcu/list.h> /* URCU list library (-lurcu) */
#include <lttng/lttng.h>
+#include <lttng/lttng-kconsumerd.h>
#include <lttng-sessiond-comm.h>
#include "context.h"
#include "ust-ctl.h"
#include "session.h"
#include "traceable-app.h"
-#include "lttng-kconsumerd.h"
+#include "ltt-kconsumerd.h"
#include "utils.h"
/* Const values */
lkm.fd = stream->fd;
lkm.state = stream->state;
lkm.max_sb_size = channel->channel->attr.subbuf_size;
- lkm.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
+ lkm.output = channel->channel->attr.output;
strncpy(lkm.path_name, stream->pathname, PATH_MAX);
lkm.path_name[PATH_MAX - 1] = '\0';
goto error;
}
+ /* Kconsumerd err socket */
+ pollfd[1].fd = sock;
+ pollfd[1].events = POLLIN;
+
+ /* Inifinite blocking call, waiting for transmission */
+ ret = poll(pollfd, 2, -1);
+ if (ret < 0) {
+ perror("poll kconsumerd thread");
+ goto error;
+ }
+
+ /* Thread quit pipe has been closed. Killing thread. */
+ if (pollfd[0].revents == POLLNVAL) {
+ goto error;
+ } else if (pollfd[1].revents == POLLERR) {
+ ERR("Kconsumerd err socket second poll error");
+ goto error;
+ }
+
/* Wait for any kconsumerd error */
ret = lttcomm_recv_unix_sock(sock, &code, sizeof(enum lttcomm_return_code));
if (ret <= 0) {
}
/*
- * Basic recv here to handle the very simple data
- * that the libust send to register (reg_msg).
+ * Using message-based transmissions to ensure we don't
+ * have to deal with partially received messages.
*/
- ret = recv(sock, ®_msg, sizeof(reg_msg), 0);
+ ret = lttcomm_recv_unix_sock(sock, ®_msg, sizeof(reg_msg));
if (ret < 0) {
perror("recv");
continue;
/* Add application to the global traceable list */
if (reg_msg.reg == 1) {
/* Registering */
+ /*
+ * TODO: socket should be either passed to a
+ * listener thread (for more messages) or
+ * closed. It currently leaks.
+ */
ret = register_traceable_app(reg_msg.pid, reg_msg.uid);
if (ret < 0) {
/* register_traceable_app only return an error with
/*
* Allocate a channel structure and fill it.
*/
-static struct lttng_channel *init_default_channel(char *name)
+static struct lttng_channel *init_default_channel(enum lttng_domain_type domain_type,
+ char *name)
{
struct lttng_channel *chan;
if (snprintf(chan->name, NAME_MAX, "%s", name) < 0) {
perror("snprintf channel name");
- return NULL;
+ goto error;
}
chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
- chan->attr.subbuf_size = DEFAULT_CHANNEL_SUBBUF_SIZE;
- 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:
+ switch (domain_type) {
+ case LTTNG_DOMAIN_KERNEL:
+ chan->attr.subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE;
+ chan->attr.num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
+ chan->attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
+ break;
+ /* TODO: add UST */
+ default:
+ goto error; /* Not implemented */
+ }
+
return chan;
+
+error:
+ free(chan);
+ return NULL;
}
/*
switch (cmd_ctx->lsm->domain.type) {
case LTTNG_DOMAIN_KERNEL:
- do {
+ kchan = get_kernel_channel_by_name(channel_name,
+ cmd_ctx->session->kernel_session);
+ if (kchan == NULL) {
+ DBG("Channel not found. Creating channel %s", channel_name);
+
+ chan = init_default_channel(cmd_ctx->lsm->domain.type, channel_name);
+ if (chan == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ ret = kernel_create_channel(cmd_ctx->session->kernel_session,
+ chan, cmd_ctx->session->kernel_session->trace_path);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CHAN_FAIL;
+ goto error;
+ }
kchan = get_kernel_channel_by_name(channel_name,
cmd_ctx->session->kernel_session);
if (kchan == NULL) {
- DBG("Channel not found. Creating channel %s", channel_name);
-
- chan = init_default_channel(channel_name);
- if (chan == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- ret = kernel_create_channel(cmd_ctx->session->kernel_session,
- chan, cmd_ctx->session->kernel_session->trace_path);
- if (ret < 0) {
- ret = LTTCOMM_KERN_CHAN_FAIL;
- goto error;
- }
+ ERR("Channel %s not found after creation. Internal error, giving up.",
+ channel_name);
+ ret = LTTCOMM_FATAL;
+ goto error;
}
- } while (kchan == NULL);
+ }
kevent = get_kernel_event_by_name(cmd_ctx->lsm->u.enable.event.name, kchan);
if (kevent == NULL) {
switch (cmd_ctx->lsm->domain.type) {
case LTTNG_DOMAIN_KERNEL:
- do {
+ kchan = get_kernel_channel_by_name(channel_name,
+ cmd_ctx->session->kernel_session);
+ if (kchan == NULL) {
+ DBG("Channel not found. Creating channel %s", channel_name);
+
+ chan = init_default_channel(cmd_ctx->lsm->domain.type, channel_name);
+ if (chan == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ ret = kernel_create_channel(cmd_ctx->session->kernel_session,
+ chan, cmd_ctx->session->kernel_session->trace_path);
+ if (ret < 0) {
+ ret = LTTCOMM_KERN_CHAN_FAIL;
+ goto error;
+ }
kchan = get_kernel_channel_by_name(channel_name,
cmd_ctx->session->kernel_session);
if (kchan == NULL) {
- DBG("Channel not found. Creating channel %s", channel_name);
-
- chan = init_default_channel(channel_name);
- if (chan == NULL) {
- ret = LTTCOMM_FATAL;
- goto error;
- }
-
- ret = kernel_create_channel(cmd_ctx->session->kernel_session,
- chan, cmd_ctx->session->kernel_session->trace_path);
- if (ret < 0) {
- ret = LTTCOMM_KERN_CHAN_FAIL;
- goto error;
- }
+ ERR("Channel %s not found after creation. Internal error, giving up.",
+ channel_name);
+ ret = LTTCOMM_FATAL;
+ goto error;
}
- } while (kchan == NULL);
+ }
/* For each event in the kernel session */
cds_list_for_each_entry(kevent, &kchan->events_list.head, list) {
}
}
- DBG("Start kernel tracing");
- ret = kernel_start_session(cmd_ctx->session->kernel_session);
+ ret = start_kernel_trace(cmd_ctx->session->kernel_session);
if (ret < 0) {
- ERR("Kernel start session failed");
ret = LTTCOMM_KERN_START_FAIL;
goto error;
}
- ret = start_kernel_trace(cmd_ctx->session->kernel_session);
+ DBG("Start kernel tracing");
+ ret = kernel_start_session(cmd_ctx->session->kernel_session);
if (ret < 0) {
+ ERR("Kernel start session failed");
ret = LTTCOMM_KERN_START_FAIL;
goto error;
}