/*
* 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/lttng-sessiond-comm.h>
#include "context.h"
-#include "liblttsessiondcomm.h"
#include "ltt-sessiond.h"
#include "lttngerr.h"
#include "kernel-ctl.h"
/* Variables */
int opt_verbose; /* Not static for lttngerr.h */
+int opt_verbose_kconsumerd; /* Not static for lttngerr.h */
int opt_quiet; /* Not static for lttngerr.h */
const char *progname;
*/
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) {
/*
* Exec kconsumerd.
*/
- if (opt_verbose > 1) {
+ if (opt_verbose > 1 || opt_verbose_kconsumerd) {
verbosity = "--verbose";
} else {
verbosity = "--quiet";
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 = mkdir_recursive(session->path, S_IRWXU | S_IRWXG,
+ geteuid(), allowed_group());
if (ret < 0) {
- if (ret != EEXIST) {
+ 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:
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,
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));
fprintf(stderr, " -S, --sig-parent Send SIGCHLD to parent pid to notify readiness.\n");
fprintf(stderr, " -q, --quiet No output at all.\n");
fprintf(stderr, " -v, --verbose Verbose mode. Activate DBG() macro.\n");
+ fprintf(stderr, " --verbose-kconsumerd Verbose mode for kconsumerd. Activate DBG() macro.\n");
}
/*
{ "version", 0, 0, 'V' },
{ "quiet", 0, 0, 'q' },
{ "verbose", 0, 0, 'v' },
+ { "verbose-kconsumerd", 0, 0, 'Z' },
{ NULL, 0, 0, 0 }
};
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "dhqvVS" "a:c:g:s:E:C:", long_options, &option_index);
+ c = getopt_long(argc, argv, "dhqvVS" "a:c:g:s:E:C:Z", long_options, &option_index);
if (c == -1) {
break;
}
/* Verbose level can increase using multiple -v */
opt_verbose += 1;
break;
+ case 'Z':
+ opt_verbose_kconsumerd += 1;
+ break;
default:
/* Unknown option or other error.
* Error is printed by getopt, just return */
}
/*
- * 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()