X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttng-sessiond%2Fmain.c;h=7d63656e4c401b9d66037d2c9d8126974cf6f4c5;hb=4fba72199030f1171956ad2ebf18ee7a8903eba6;hp=ec45c6676bed50b8934287130011a93b55fef0f8;hpb=7885e399f12affe1933fcacce7f2dab311ed6761;p=lttng-tools.git diff --git a/lttng-sessiond/main.c b/lttng-sessiond/main.c index ec45c6676..7d63656e4 100644 --- a/lttng-sessiond/main.c +++ b/lttng-sessiond/main.c @@ -92,8 +92,10 @@ const char *progname; const char *opt_tracing_group; static int opt_sig_parent; static int opt_daemon; +static int opt_no_kernel; static int is_root; /* Set to 1 if the daemon is running as root */ static pid_t ppid; /* Parent PID for --sig-parent option */ +static char *rundir; /* Consumer daemon specific control data */ static struct consumer_data kconsumer_data = { @@ -423,19 +425,18 @@ static void cleanup(void) DBG("Cleaning up"); - if (is_root) { - DBG("Removing %s directory", LTTNG_RUNDIR); - ret = asprintf(&cmd, "rm -rf " LTTNG_RUNDIR); - if (ret < 0) { - ERR("asprintf failed. Something is really wrong!"); - } + DBG("Removing %s directory", rundir); + ret = asprintf(&cmd, "rm -rf %s", rundir); + if (ret < 0) { + ERR("asprintf failed. Something is really wrong!"); + } - /* Remove lttng run directory */ - ret = system(cmd); - if (ret < 0) { - ERR("Unable to clean " LTTNG_RUNDIR); - } + /* Remove lttng run directory */ + ret = system(cmd); + if (ret < 0) { + ERR("Unable to clean %s", rundir); } + free(cmd); DBG("Cleaning up all session"); @@ -457,10 +458,9 @@ static void cleanup(void) pthread_mutex_destroy(&kconsumer_data.pid_mutex); - DBG("Closing kernel fd"); - close(kernel_tracer_fd); - - if (is_root) { + if (is_root && !opt_no_kernel) { + DBG2("Closing kernel fd"); + close(kernel_tracer_fd); DBG("Unloading kernel modules"); modprobe_remove_kernel_modules(); } @@ -1580,7 +1580,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) } } DBG("Using 64-bit UST consumer at: %s", consumerd64_bin); - ret = execl(consumerd64_bin, verbosity, "-u", + ret = execl(consumerd64_bin, "lttng-consumerd", verbosity, "-u", "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, "--consumerd-err-sock", consumer_data->err_unix_sock_path, NULL); @@ -1624,7 +1624,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) } } DBG("Using 32-bit UST consumer at: %s", consumerd32_bin); - ret = execl(consumerd32_bin, verbosity, "-u", + ret = execl(consumerd32_bin, "lttng-consumerd", verbosity, "-u", "--consumerd-cmd-sock", consumer_data->cmd_unix_sock_path, "--consumerd-err-sock", consumer_data->err_unix_sock_path, NULL); @@ -2772,8 +2772,11 @@ static int cmd_start_trace(struct ltt_session *session) ksession = session->kernel_session; usess = session->ust_session; - if (session->enabled) - return LTTCOMM_UST_START_FAIL; + if (session->enabled) { + ret = LTTCOMM_UST_START_FAIL; + goto error; + } + session->enabled = 1; /* Kernel tracing */ @@ -2861,8 +2864,11 @@ static int cmd_stop_trace(struct ltt_session *session) ksession = session->kernel_session; usess = session->ust_session; - if (!session->enabled) - return LTTCOMM_UST_START_FAIL; + if (!session->enabled) { + ret = LTTCOMM_UST_START_FAIL; + goto error; + } + session->enabled = 0; /* Kernel tracer */ @@ -2994,7 +3000,7 @@ static int cmd_register_consumer(struct ltt_session *session, int domain, switch (domain) { case LTTNG_DOMAIN_KERNEL: /* Can't register a consumer if there is already one */ - if (session->kernel_session->consumer_fd != 0) { + if (session->kernel_session->consumer_fds_sent != 0) { ret = LTTCOMM_KERN_CONSUMER_FAIL; goto error; } @@ -3156,6 +3162,11 @@ static int process_client_msg(struct command_ctx *cmd_ctx) DBG("Processing client command %d", cmd_ctx->lsm->cmd_type); + if (opt_no_kernel && cmd_ctx->lsm->domain.type == LTTNG_DOMAIN_KERNEL) { + ret = LTTCOMM_KERN_NA; + goto error; + } + /* * Check for command that don't needs to allocate a returned payload. We do * this here so we don't have to make the call for no payload at each @@ -3725,6 +3736,7 @@ static void usage(void) fprintf(stderr, " -q, --quiet No output at all.\n"); fprintf(stderr, " -v, --verbose Verbose mode. Activate DBG() macro.\n"); fprintf(stderr, " --verbose-consumer Verbose mode for consumer. Activate DBG() macro.\n"); + fprintf(stderr, " --no-kernel Disable kernel tracer\n"); } /* @@ -3755,12 +3767,13 @@ static int parse_args(int argc, char **argv) { "quiet", 0, 0, 'q' }, { "verbose", 0, 0, 'v' }, { "verbose-consumer", 0, 0, 'Z' }, + { "no-kernel", 0, 0, 'N' }, { NULL, 0, 0, 0 } }; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "dhqvVS" "a:c:g:s:C:E:D:F:Z:u:t", + c = getopt_long(argc, argv, "dhqvVSN" "a:c:g:s:C:E:D:F:Z:u:t", long_options, &option_index); if (c == -1) { break; @@ -3812,6 +3825,9 @@ static int parse_args(int argc, char **argv) case 'G': snprintf(ustconsumer32_data.cmd_unix_sock_path, PATH_MAX, "%s", optarg); break; + case 'N': + opt_no_kernel = 1; + break; case 'q': opt_quiet = 1; break; @@ -3996,14 +4012,16 @@ static int create_apps_cmd_pipe(void) /* * Create the lttng run directory needed for all global sockets and pipe. */ -static int create_lttng_rundir(void) +static int create_lttng_rundir(const char *rundir) { int ret; - ret = mkdir(LTTNG_RUNDIR, S_IRWXU | S_IRWXG ); + DBG3("Creating LTTng run directory: %s", rundir); + + ret = mkdir(rundir, S_IRWXU | S_IRWXG ); if (ret < 0) { if (errno != EEXIST) { - ERR("Unable to create " LTTNG_RUNDIR); + ERR("Unable to create %s", rundir); goto error; } else { ret = 0; @@ -4018,20 +4036,21 @@ error: * Setup sockets and directory needed by the kconsumerd communication with the * session daemon. */ -static int set_consumer_sockets(struct consumer_data *consumer_data) +static int set_consumer_sockets(struct consumer_data *consumer_data, + const char *rundir) { int ret; - const char *path; + char path[PATH_MAX]; - switch (consumer_data->type) { + switch (consumer_data->type) { case LTTNG_CONSUMER_KERNEL: - path = KCONSUMERD_PATH; + snprintf(path, PATH_MAX, KCONSUMERD_PATH, rundir); break; case LTTNG_CONSUMER64_UST: - path = USTCONSUMERD64_PATH; + snprintf(path, PATH_MAX, USTCONSUMERD64_PATH, rundir); break; case LTTNG_CONSUMER32_UST: - path = USTCONSUMERD32_PATH; + snprintf(path, PATH_MAX, USTCONSUMERD32_PATH, rundir); break; default: ERR("Consumer type unknown"); @@ -4039,6 +4058,8 @@ static int set_consumer_sockets(struct consumer_data *consumer_data) goto error; } + DBG2("Creating consumer directory: %s", path); + ret = mkdir(path, S_IRWXU | S_IRWXG); if (ret < 0) { if (errno != EEXIST) { @@ -4062,7 +4083,7 @@ static int set_consumer_sockets(struct consumer_data *consumer_data) S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (ret < 0) { ERR("Set file permissions failed: %s", consumer_data->err_unix_sock_path); - perror("chmod"); + PERROR("chmod"); goto error; } @@ -4189,7 +4210,10 @@ int main(int argc, char **argv) is_root = !getuid(); if (is_root) { - ret = create_lttng_rundir(); + rundir = strdup(LTTNG_RUNDIR); + + /* Create global run dir with root access */ + ret = create_lttng_rundir(rundir); if (ret < 0) { goto error; } @@ -4209,6 +4233,17 @@ int main(int argc, char **argv) snprintf(wait_shm_path, PATH_MAX, DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH); } + + /* Setup kernel consumerd path */ + snprintf(kconsumer_data.err_unix_sock_path, PATH_MAX, + KCONSUMERD_ERR_SOCK_PATH, rundir); + snprintf(kconsumer_data.cmd_unix_sock_path, PATH_MAX, + KCONSUMERD_CMD_SOCK_PATH, rundir); + + DBG2("Kernel consumer err path: %s", + kconsumer_data.err_unix_sock_path); + DBG2("Kernel consumer cmd path: %s", + kconsumer_data.cmd_unix_sock_path); } else { home_path = get_home_dir(); if (home_path == NULL) { @@ -4218,6 +4253,21 @@ int main(int argc, char **argv) goto error; } + /* + * Create rundir from home path. This will create something like + * $HOME/.lttng + */ + ret = asprintf(&rundir, LTTNG_HOME_RUNDIR, home_path); + if (ret < 0) { + ret = -ENOMEM; + goto error; + } + + ret = create_lttng_rundir(rundir); + if (ret < 0) { + goto error; + } + if (strlen(apps_unix_sock_path) == 0) { snprintf(apps_unix_sock_path, PATH_MAX, DEFAULT_HOME_APPS_UNIX_SOCK, home_path); @@ -4238,6 +4288,29 @@ int main(int argc, char **argv) DBG("Client socket path %s", client_unix_sock_path); DBG("Application socket path %s", apps_unix_sock_path); + DBG("LTTng run directory path: %s", rundir); + + /* 32 bits consumerd path setup */ + snprintf(ustconsumer32_data.err_unix_sock_path, PATH_MAX, + USTCONSUMERD32_ERR_SOCK_PATH, rundir); + snprintf(ustconsumer32_data.cmd_unix_sock_path, PATH_MAX, + USTCONSUMERD32_CMD_SOCK_PATH, rundir); + + DBG2("UST consumer 32 bits err path: %s", + ustconsumer32_data.err_unix_sock_path); + DBG2("UST consumer 32 bits cmd path: %s", + ustconsumer32_data.cmd_unix_sock_path); + + /* 64 bits consumerd path setup */ + snprintf(ustconsumer64_data.err_unix_sock_path, PATH_MAX, + USTCONSUMERD64_ERR_SOCK_PATH, rundir); + snprintf(ustconsumer64_data.cmd_unix_sock_path, PATH_MAX, + USTCONSUMERD64_CMD_SOCK_PATH, rundir); + + DBG2("UST consumer 64 bits err path: %s", + ustconsumer64_data.err_unix_sock_path); + DBG2("UST consumer 64 bits cmd path: %s", + ustconsumer64_data.cmd_unix_sock_path); /* * See if daemon already exist. @@ -4260,28 +4333,30 @@ int main(int argc, char **argv) * kernel tracer. */ if (is_root) { - ret = set_consumer_sockets(&kconsumer_data); - if (ret < 0) { - goto exit; - } - - ret = set_consumer_sockets(&ustconsumer64_data); - if (ret < 0) { - goto exit; - } - - ret = set_consumer_sockets(&ustconsumer32_data); + ret = set_consumer_sockets(&kconsumer_data, rundir); if (ret < 0) { goto exit; } /* Setup kernel tracer */ - init_kernel_tracer(); + if (!opt_no_kernel) { + init_kernel_tracer(); + } /* Set ulimit for open files */ set_ulimit(); } + ret = set_consumer_sockets(&ustconsumer64_data, rundir); + if (ret < 0) { + goto exit; + } + + ret = set_consumer_sockets(&ustconsumer32_data, rundir); + if (ret < 0) { + goto exit; + } + if ((ret = set_signal_handler()) < 0) { goto exit; } @@ -4415,8 +4490,9 @@ exit: cleanup(); rcu_thread_offline(); rcu_unregister_thread(); - if (!ret) + if (!ret) { exit(EXIT_SUCCESS); + } error: exit(EXIT_FAILURE); }