Fix a null pointer dereference in the kernel session teardown.
Signed-off-by: David Goulet <david.goulet@polymtl.ca>
*/
int lttng_kernel_enable_channel(char *name)
{
+ strncpy(lsm.u.enable.channel_name, name, NAME_MAX);
return ask_sessiond(LTTNG_KERNEL_ENABLE_CHANNEL, NULL);
}
[ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_SESS_FAIL) ] = "Kernel create session failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_FAIL) ] = "Kernel create channel failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_NOT_FOUND) ] = "Kernel channel not found",
+ [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_ENABLE_FAIL) ] = "Enable kernel channel failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_ENABLE_FAIL) ] = "Enable kernel event failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DISABLE_FAIL) ] = "Disable kernel event failed",
[ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_META_FAIL) ] = "Opening metadata failed",
LTTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */
LTTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */
LTTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */
+ LTTCOMM_KERN_CHAN_ENABLE_FAIL, /* Kernel enable channel failed */
LTTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */
LTTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */
LTTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */
}
event->fd = ret;
- event->enabled = 1;
/* Prevent fd duplication after execlp() */
ret = fcntl(event->fd, F_SETFD, FD_CLOEXEC);
if (ret < 0) {
return -1;
}
+/*
+ * kernel_enable_channel
+ *
+ * Enable a kernel channel.
+ */
+int kernel_enable_channel(struct ltt_kernel_channel *chan)
+{
+ int ret;
+
+ ret = kernctl_enable(chan->fd);
+ if (ret < 0) {
+ perror("enable chan ioctl");
+ ret = errno;
+ goto error;
+ }
+
+ chan->enabled = 1;
+ DBG("Kernel channel %s enabled (fd: %d)", chan->channel->name, chan->fd);
+
+ return 0;
+
+error:
+ return ret;
+}
+
/*
* kernel_enable_event
*
return 0;
error:
- return -1;
+ return ret;
}
/*
return 0;
error:
- return -1;
+ return ret;
}
/*
int kernel_create_event(struct lttng_event *ev, struct ltt_kernel_channel *channel);
int kernel_disable_event(struct ltt_kernel_event *event);
int kernel_enable_event(struct ltt_kernel_event *event);
+int kernel_enable_channel(struct ltt_kernel_channel *chan);
int kernel_open_metadata(struct ltt_kernel_session *session);
int kernel_open_metadata_stream(struct ltt_kernel_session *session);
int kernel_open_channel_stream(struct ltt_kernel_channel *channel);
ret = LTTCOMM_OK;
break;
}
+ case LTTNG_KERNEL_ENABLE_CHANNEL:
+ {
+ struct ltt_kernel_channel *chan;
+
+ /* Setup lttng message with no payload */
+ ret = setup_lttng_msg(cmd_ctx, 0);
+ if (ret < 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;
+ } else if (chan->enabled == 0) {
+ ret = kernel_enable_channel(chan);
+ if (ret < 0) {
+ if (ret != EEXIST) {
+ ret = LTTCOMM_KERN_CHAN_ENABLE_FAIL;
+ }
+ goto error;
+ }
+ }
+
+ kernel_wait_quiescent(kernel_tracer_fd);
+ ret = LTTCOMM_OK;
+ break;
+ }
case LTTNG_KERNEL_ENABLE_EVENT:
{
struct ltt_kernel_channel *chan;
lkc->fd = 0;
lkc->stream_count = 0;
+ lkc->enabled = 1;
/* Init linked list */
CDS_INIT_LIST_HEAD(&lkc->events_list.head);
CDS_INIT_LIST_HEAD(&lkc->stream_list.head);
/* Setting up a kernel event */
lke->fd = 0;
lke->event = attr;
+ lke->enabled = 1;
return lke;
close(session->metadata_stream_fd);
}
- trace_destroy_kernel_metadata(session->metadata);
+ if (session->metadata != NULL) {
+ trace_destroy_kernel_metadata(session->metadata);
+ }
cds_list_for_each_entry(channel, &session->channel_list.head, list) {
trace_destroy_kernel_channel(channel);
/* Kernel channel */
struct ltt_kernel_channel {
int fd;
+ int enabled;
char *pathname;
unsigned int stream_count;
struct lttng_channel *channel;
lttng_SOURCES = conf.c commands/start.c commands/add_channel.c \
commands/list.c commands/create.c commands/destroy.c \
commands/stop.c commands/enable_events.c \
- commands/disable_events.c utils.c lttng.c
+ commands/disable_events.c commands/enable_channels.c \
+ utils.c lttng.c
lttng_LDADD = \
$(top_builddir)/liblttngctl/liblttngctl.la
extern int cmd_stop(int argc, const char **argv);
extern int cmd_enable_events(int argc, const char **argv);
extern int cmd_disable_events(int argc, const char **argv);
+extern int cmd_enable_channels(int argc, const char **argv);
#endif /* _LTTNG_CMD_H */
--- /dev/null
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define _GNU_SOURCE
+#include <popt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "cmd.h"
+#include "conf.h"
+#include "utils.h"
+
+static char *opt_channels;
+static char *opt_kernel;
+static int opt_pid_all;
+static int opt_userspace;
+static pid_t opt_pid;
+
+enum {
+ OPT_HELP = 1,
+ OPT_USERSPACE,
+};
+
+static struct poptOption long_options[] = {
+ /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
+ {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
+ {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
+ {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
+ {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0}
+};
+
+/*
+ * usage
+ */
+static void usage(FILE *ofp)
+{
+ fprintf(ofp, "usage: lttng enable-channel NAME[,NAME2,...] [options]\n");
+ fprintf(ofp, "\n");
+ fprintf(ofp, " -h, --help Show this help\n");
+ fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
+ fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n");
+ fprintf(ofp, " --all If -u, apply on all traceable apps\n");
+ fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n");
+ fprintf(ofp, "\n");
+}
+
+/*
+ * enable_channels
+ *
+ * Enabling channel using the lttng API.
+ */
+static int enable_channels(void)
+{
+ int ret = CMD_SUCCESS;
+ char *channel_name;
+
+ if (set_session_name() < 0) {
+ ret = CMD_ERROR;
+ goto error;
+ }
+
+ /* Strip event list */
+ channel_name = strtok(opt_channels, ",");
+ while (channel_name != NULL) {
+ /* Kernel tracer action */
+ if (opt_kernel) {
+ DBG("Enabling kernel channel %s", channel_name);
+ ret = lttng_kernel_enable_channel(channel_name);
+ if (ret < 0) {
+ goto error;
+ } else {
+ MSG("Kernel channel enabled %s", channel_name);
+ }
+ } else if (opt_userspace) { /* User-space tracer action */
+ /*
+ * TODO: Waiting on lttng UST 2.0
+ */
+ if (opt_pid_all) {
+ } else if (opt_pid != 0) {
+ }
+ ret = CMD_NOT_IMPLEMENTED;
+ goto error;
+ } else {
+ ERR("Please specify a tracer (kernel or user-space)");
+ goto error;
+ }
+
+ /* Next event */
+ channel_name = strtok(NULL, ",");
+ }
+
+error:
+ return ret;
+}
+
+/*
+ * cmd_enable_channels
+ *
+ * Enable channel to trace session
+ */
+int cmd_enable_channels(int argc, const char **argv)
+{
+ int opt, ret;
+ static poptContext pc;
+
+ pc = poptGetContext(NULL, argc, argv, long_options, 0);
+ poptReadDefaultConfig(pc, 0);
+
+ while ((opt = poptGetNextOpt(pc)) != -1) {
+ switch (opt) {
+ case OPT_HELP:
+ usage(stderr);
+ ret = CMD_SUCCESS;
+ goto end;
+ case OPT_USERSPACE:
+ opt_userspace = 1;
+ break;
+ default:
+ usage(stderr);
+ ret = CMD_UNDEFINED;
+ goto end;
+ }
+ }
+
+ opt_channels = (char*) poptGetArg(pc);
+ if (opt_channels == NULL) {
+ ERR("Missing channel name(s).\n");
+ usage(stderr);
+ ret = CMD_SUCCESS;
+ goto end;
+ }
+
+ ret = enable_channels();
+
+end:
+ return ret;
+}
{ "stop", cmd_stop},
{ "enable-event", cmd_enable_events},
{ "disable-event", cmd_disable_events},
+ { "enable-channel", cmd_enable_channels},
{ NULL, NULL} /* Array closure */
};
fprintf(ofp, " create Create tracing session\n");
fprintf(ofp, " destroy Teardown tracing session\n");
fprintf(ofp, " enable-event Enable tracing event\n");
+ fprintf(ofp, " enable-channel Enable tracing channel\n");
fprintf(ofp, " disable-event Disable tracing event\n");
fprintf(ofp, " list List possible tracing options\n");
fprintf(ofp, " start Start tracing\n");