X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=ltt-sessiond%2Fmain.c;h=0effeb1f5ab51a0c91973505c7efd9629dee5a3c;hp=75215b3f23039bb16caa3d5e45af5c854f3689db;hb=2b1173d8cb43cb5d7c9ce3772dbdbef3436c407e;hpb=b082db07f0c522527fc95fc97f3e99eb0579c0cc diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 75215b3f2..0effeb1f5 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -580,7 +581,7 @@ static pid_t spawn_kconsumerd(void) /* * Exec kconsumerd. */ - execlp("kconsumerd", "kconsumerd", "--verbose", NULL); + execlp("ltt-kconsumerd", "ltt-kconsumerd", "--verbose", NULL); if (errno != 0) { perror("kernel start consumer exec"); } @@ -641,6 +642,58 @@ error: return ret; } +/* + * modprobe_kernel_modules + */ +static int modprobe_kernel_modules(void) +{ + int ret = 0, i = 0; + char modprobe[256]; + + while (kernel_modules_list[i] != NULL) { + ret = snprintf(modprobe, sizeof(modprobe), "/sbin/modprobe %s", + kernel_modules_list[i]); + if (ret < 0) { + perror("snprintf modprobe"); + goto error; + } + ret = system(modprobe); + if (ret < 0) { + ERR("Unable to load module %s", kernel_modules_list[i]); + } + DBG("Modprobe successfully %s", kernel_modules_list[i]); + i++; + } + +error: + return ret; +} + +/* + * mount_debugfs + */ +static int mount_debugfs(char *path) +{ + int ret; + char *type = "debugfs"; + + ret = mkdir_recursive(path, S_IRWXU | S_IRWXG); + if (ret < 0) { + goto error; + } + + ret = mount(type, path, type, 0, NULL); + if (ret < 0) { + perror("mount debugfs"); + goto error; + } + + DBG("Mounted debugfs successfully at %s", path); + +error: + return ret; +} + /* * init_kernel_tracer * @@ -648,14 +701,80 @@ error: */ static void init_kernel_tracer(void) { - /* Set the global kernel tracer fd */ - kernel_tracer_fd = open(DEFAULT_KERNEL_TRACER_PATH, O_RDWR); + int ret; + char *proc_mounts = "/proc/mounts"; + char line[256]; + char *debugfs_path = NULL, *lttng_path; + FILE *fp; + + /* Detect debugfs */ + fp = fopen(proc_mounts, "r"); + if (fp == NULL) { + ERR("Unable to probe %s", proc_mounts); + goto error; + } + + while (fgets(line, sizeof(line), fp) != NULL) { + if (strstr(line, "debugfs") != NULL) { + /* Remove first string */ + strtok(line, " "); + /* Dup string here so we can reuse line later on */ + debugfs_path = strdup(strtok(NULL, " ")); + DBG("Got debugfs path : %s", debugfs_path); + break; + } + } + + fclose(fp); + + /* Mount debugfs if needded */ + if (debugfs_path == NULL) { + ret = asprintf(&debugfs_path, "/mnt/debugfs"); + if (ret < 0) { + perror("asprintf debugfs path"); + goto error; + } + ret = mount_debugfs(debugfs_path); + if (ret < 0) { + goto error; + } + } + + /* Modprobe lttng kernel modules */ + ret = modprobe_kernel_modules(); + if (ret < 0) { + goto error; + } + + /* Setup lttng kernel path */ + ret = asprintf(<tng_path, "%s/lttng", debugfs_path); + if (ret < 0) { + perror("asprintf lttng path"); + goto error; + } + + /* Open debugfs lttng */ + kernel_tracer_fd = open(lttng_path, O_RDWR); if (kernel_tracer_fd < 0) { - WARN("No kernel tracer available"); - kernel_tracer_fd = 0; + DBG("Failed to open %s", lttng_path); + goto error; } + free(lttng_path); + free(debugfs_path); DBG("Kernel tracer fd %d", kernel_tracer_fd); + return; + +error: + if (lttng_path) { + free(lttng_path); + } + if (debugfs_path) { + free(debugfs_path); + } + WARN("No kernel tracer available"); + kernel_tracer_fd = 0; + return; } /* @@ -1225,7 +1344,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx) if (cmd_ctx->session->kernel_session != NULL) { if (cmd_ctx->session->kernel_session->metadata == NULL) { DBG("Open kernel metadata"); - ret = kernel_open_metadata(cmd_ctx->session->kernel_session); + ret = kernel_open_metadata(cmd_ctx->session->kernel_session, + cmd_ctx->session->path); if (ret < 0) { ret = LTTCOMM_KERN_META_FAIL; goto error; @@ -1760,7 +1880,7 @@ static int check_existing_daemon() * Set the tracing group gid onto the client socket. * * Race window between mkdir and chown is OK because we are going from - * less permissive (root.root) to more permissive (root.tracing). + * more permissive (root.root) to les permissive (root.tracing). */ static int set_permissions(void) { @@ -1773,8 +1893,13 @@ static int set_permissions(void) (grp = getgrnam(default_tracing_group)); if (grp == NULL) { - ERR("Missing tracing group. Aborting execution.\n"); - ret = -1; + if (is_root) { + WARN("No tracing group detected"); + ret = 0; + } else { + ERR("Missing tracing group. Aborting execution."); + ret = -1; + } goto end; } @@ -1989,7 +2114,6 @@ int main(int argc, char **argv) /* Check if daemon is UID = 0 */ is_root = !getuid(); - /* Set all sockets path */ if (is_root) { ret = create_lttng_rundir(); if (ret < 0) {