/*
* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
#include <urcu/list.h> /* URCU list library (-lurcu) */
#include <lttng/lttng.h>
+#include <lttng-sessiond-comm.h>
#include "context.h"
-#include "liblttsessiondcomm.h"
#include "ltt-sessiond.h"
#include "lttngerr.h"
#include "kernel-ctl.h"
*/
static struct ltt_session_list *session_list_ptr;
+static gid_t allowed_group(void)
+{
+ struct group *grp;
+
+ if (opt_tracing_group) {
+ grp = getgrnam(opt_tracing_group);
+ } else {
+ grp = getgrnam(default_tracing_group);
+ }
+ if (!grp) {
+ return -1;
+ } else {
+ return grp->gr_gid;
+ }
+}
+
/*
* Init quit pipe.
*
lkm.state = stream->state;
lkm.max_sb_size = channel->channel->attr.subbuf_size;
strncpy(lkm.path_name, stream->pathname, PATH_MAX);
+ lkm.path_name[PATH_MAX - 1] = '\0';
DBG("Sending fd %d to kconsumerd", lkm.fd);
lkm.state = ACTIVE_FD;
lkm.max_sb_size = session->metadata->conf->attr.subbuf_size;
strncpy(lkm.path_name, session->metadata->pathname, PATH_MAX);
+ lkm.path_name[PATH_MAX - 1] = '\0';
ret = lttcomm_send_fds_unix_sock(sock, &lkm, &lkm.fd, 1, sizeof(lkm));
if (ret < 0) {
int ret;
char *type = "debugfs";
- ret = mkdir_recursive(path, S_IRWXU | S_IRWXG);
+ ret = mkdir_recursive(path, S_IRWXU | S_IRWXG, geteuid(), getegid());
if (ret < 0) {
goto error;
}
goto error;
}
- ret = mkdir_recursive(session->path, S_IRWXU | S_IRWXG );
+ ret = asprintf(&session->kernel_session->trace_path, "%s/kernel",
+ session->path);
if (ret < 0) {
- if (ret != EEXIST) {
+ perror("asprintf kernel traces path");
+ goto error;
+ }
+
+ ret = mkdir_recursive(session->kernel_session->trace_path,
+ S_IRWXU | S_IRWXG, geteuid(), allowed_group());
+ if (ret < 0) {
+ if (ret != -EEXIST) {
ERR("Trace directory creation error");
goto error;
}
*/
cds_list_for_each_entry(session, &session_list_ptr->head, list) {
strncpy(sessions[i].path, session->path, PATH_MAX);
+ sessions[i].path[PATH_MAX - 1] = '\0';
strncpy(sessions[i].name, session->name, NAME_MAX);
+ sessions[i].name[NAME_MAX - 1] = '\0';
i++;
}
}
/* Kernel channels */
cds_list_for_each_entry(event, &kchan->events_list.head , list) {
strncpy(events[i].name, event->event->name, LTTNG_SYMBOL_NAME_LEN);
+ events[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
events[i].enabled = event->enabled;
switch (event->event->instrumentation) {
case LTTNG_KERNEL_TRACEPOINT:
DBG("Processing client command %d", cmd_ctx->lsm->cmd_type);
- /* Listing commands don't need a session */
+ /*
+ * Commands that DO NOT need a session.
+ */
switch (cmd_ctx->lsm->cmd_type) {
case LTTNG_CREATE_SESSION:
case LTTNG_LIST_SESSIONS:
strncpy(kctx.u.perf_counter.name,
cmd_ctx->lsm->u.context.ctx.u.perf_counter.name,
LTTNG_SYMBOL_NAME_LEN);
+ kctx.u.perf_counter.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
/* Add kernel context to kernel tracer. See context.c */
ret = add_kernel_context(cmd_ctx->session->kernel_session, &kctx,
DBG("Creating kernel channel");
ret = kernel_create_channel(cmd_ctx->session->kernel_session,
- &cmd_ctx->lsm->u.channel.chan, cmd_ctx->session->path);
+ &cmd_ctx->lsm->u.channel.chan,
+ cmd_ctx->session->kernel_session->trace_path);
if (ret < 0) {
ret = LTTCOMM_KERN_CHAN_FAIL;
goto error;
}
ret = kernel_create_channel(cmd_ctx->session->kernel_session,
- chan, cmd_ctx->session->path);
+ chan, cmd_ctx->session->kernel_session->trace_path);
if (ret < 0) {
ret = LTTCOMM_KERN_CHAN_FAIL;
goto error;
}
ret = kernel_create_channel(cmd_ctx->session->kernel_session,
- chan, cmd_ctx->session->path);
+ chan, cmd_ctx->session->kernel_session->trace_path);
if (ret < 0) {
ret = LTTCOMM_KERN_CHAN_FAIL;
goto error;
if (cmd_ctx->session->kernel_session->metadata == NULL) {
DBG("Open kernel metadata");
ret = kernel_open_metadata(cmd_ctx->session->kernel_session,
- cmd_ctx->session->path);
+ cmd_ctx->session->kernel_session->trace_path);
if (ret < 0) {
ret = LTTCOMM_KERN_META_FAIL;
goto error;
goto setup_error;
}
- DBG("Listing events (%ld events)", nb_event);
+ DBG("Listing events (%zu events)", nb_event);
list_lttng_events(kchan,
(struct lttng_event *)(cmd_ctx->llm->payload));
}
/*
- * Check if the global socket is available. If yes, error is returned.
+ * Check if the global socket is available, and if a daemon is answering
+ * at the other side. If yes, error is returned.
*/
static int check_existing_daemon(void)
{
- int ret;
-
- ret = access(client_unix_sock_path, F_OK);
- if (ret == 0) {
- ret = access(apps_unix_sock_path, F_OK);
- }
-
- return ret;
+ if (access(client_unix_sock_path, F_OK) < 0 &&
+ access(apps_unix_sock_path, F_OK) < 0)
+ return 0;
+ /* Is there anybody out there ? */
+ if (lttng_session_daemon_alive())
+ return -EEXIST;
+ else
+ return 0;
}
/*
static int set_permissions(void)
{
int ret;
- struct group *grp;
-
- /* Decide which group name to use */
- (opt_tracing_group != NULL) ?
- (grp = getgrnam(opt_tracing_group)) :
- (grp = getgrnam(default_tracing_group));
+ gid_t gid;
- if (grp == NULL) {
+ gid = allowed_group();
+ if (gid < 0) {
if (is_root) {
WARN("No tracing group detected");
ret = 0;
}
/* Set lttng run dir */
- ret = chown(LTTNG_RUNDIR, 0, grp->gr_gid);
+ ret = chown(LTTNG_RUNDIR, 0, gid);
if (ret < 0) {
ERR("Unable to set group on " LTTNG_RUNDIR);
perror("chown");
}
/* lttng client socket path */
- ret = chown(client_unix_sock_path, 0, grp->gr_gid);
+ ret = chown(client_unix_sock_path, 0, gid);
if (ret < 0) {
ERR("Unable to set group on %s", client_unix_sock_path);
perror("chown");
}
/* kconsumerd error socket path */
- ret = chown(kconsumerd_err_unix_sock_path, 0, grp->gr_gid);
+ ret = chown(kconsumerd_err_unix_sock_path, 0, gid);
if (ret < 0) {
ERR("Unable to set group on %s", kconsumerd_err_unix_sock_path);
perror("chown");
DBG("Application socket path %s", apps_unix_sock_path);
/*
- * See if daemon already exist. If any of the two socket needed by the
- * daemon are present, this test fails. However, if the daemon is killed
- * with a SIGKILL, those unix socket must be unlinked by hand.
+ * See if daemon already exist.
*/
- if ((ret = check_existing_daemon()) == 0) {
+ if ((ret = check_existing_daemon()) < 0) {
ERR("Already running daemon.\n");
/*
* We do not goto exit because we must not cleanup()