X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fmain.c;h=a6c45c2ed90942e03ba45a36f79a9ca6af538112;hb=00fb02ace5151a6546f4e97e5439512913a50e68;hp=10802aa7b2cc66d87d0946ee53623b05b47a1c0f;hpb=e6142f2e647e83238b1e399b1264e8adb05409f9;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 10802aa7b..a6c45c2ed 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -94,6 +94,9 @@ static int lockfile_fd = -1; /* Set to 1 when a SIGUSR1 signal is received. */ static int recv_child_signal; +static struct lttng_kernel_tracer_version kernel_tracer_version; +static struct lttng_kernel_tracer_abi_version kernel_tracer_abi_version; + /* * Consumer daemon specific control data. Every value not initialized here is * set to 0 by the static definition. @@ -1270,6 +1273,7 @@ restart: if (!cmd_socket_wrapper) { goto error; } + cmd_socket_wrapper->lock = &consumer_data->lock; ret = consumer_send_channel_monitor_pipe(cmd_socket_wrapper, consumer_data->channel_monitor_pipe); @@ -1445,7 +1449,17 @@ error_poll: } /* - * This thread manage application communication. + * This thread receives application command sockets (FDs) on the + * apps_cmd_pipe and waits (polls) on them until they are closed + * or an error occurs. + * + * At that point, it flushes the data (tracing and metadata) associated + * with this application and tears down ust app sessions and other + * associated data structures through ust_app_unregister(). + * + * Note that this thread never sends commands to the applications + * through the command sockets; it merely listens for hang-ups + * and errors on those sockets and cleans-up as they occur. */ static void *thread_manage_apps(void *data) { @@ -2413,9 +2427,9 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) * fallback on the 32-bit one, */ DBG3("Looking for a kernel consumer at these locations:"); - DBG3(" 1) %s", config.consumerd64_bin_path.value); + DBG3(" 1) %s", config.consumerd64_bin_path.value ? : "NULL"); DBG3(" 2) %s/%s", INSTALL_BIN_PATH, DEFAULT_CONSUMERD_FILE); - DBG3(" 3) %s", config.consumerd32_bin_path.value); + DBG3(" 3) %s", config.consumerd32_bin_path.value ? : "NULL"); if (stat(config.consumerd64_bin_path.value, &st) == 0) { DBG3("Found location #1"); consumer_to_use = config.consumerd64_bin_path.value; @@ -2440,33 +2454,30 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) break; case LTTNG_CONSUMER64_UST: { - char *tmpnew = NULL; - - if (config.consumerd64_lib_dir.value[0] != '\0') { + if (config.consumerd64_lib_dir.value) { char *tmp; size_t tmplen; + char *tmpnew; tmp = lttng_secure_getenv("LD_LIBRARY_PATH"); if (!tmp) { tmp = ""; } - tmplen = strlen("LD_LIBRARY_PATH=") - + strlen(config.consumerd64_lib_dir.value) + 1 /* : */ + strlen(tmp); + tmplen = strlen(config.consumerd64_lib_dir.value) + 1 /* : */ + strlen(tmp); tmpnew = zmalloc(tmplen + 1 /* \0 */); if (!tmpnew) { ret = -ENOMEM; goto error; } - strcpy(tmpnew, "LD_LIBRARY_PATH="); strcat(tmpnew, config.consumerd64_lib_dir.value); if (tmp[0] != '\0') { strcat(tmpnew, ":"); strcat(tmpnew, tmp); } - ret = putenv(tmpnew); + ret = setenv("LD_LIBRARY_PATH", tmpnew, 1); + free(tmpnew); if (ret) { ret = -errno; - free(tmpnew); goto error; } } @@ -2476,40 +2487,34 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) "--consumerd-err-sock", consumer_data->err_unix_sock_path, "--group", config.tracing_group_name.value, NULL); - if (config.consumerd64_lib_dir.value[0] != '\0') { - free(tmpnew); - } break; } case LTTNG_CONSUMER32_UST: { - char *tmpnew = NULL; - - if (config.consumerd32_lib_dir.value[0] != '\0') { + if (config.consumerd32_lib_dir.value) { char *tmp; size_t tmplen; + char *tmpnew; tmp = lttng_secure_getenv("LD_LIBRARY_PATH"); if (!tmp) { tmp = ""; } - tmplen = strlen("LD_LIBRARY_PATH=") - + strlen(config.consumerd32_lib_dir.value) + 1 /* : */ + strlen(tmp); + tmplen = strlen(config.consumerd32_lib_dir.value) + 1 /* : */ + strlen(tmp); tmpnew = zmalloc(tmplen + 1 /* \0 */); if (!tmpnew) { ret = -ENOMEM; goto error; } - strcpy(tmpnew, "LD_LIBRARY_PATH="); strcat(tmpnew, config.consumerd32_lib_dir.value); if (tmp[0] != '\0') { strcat(tmpnew, ":"); strcat(tmpnew, tmp); } - ret = putenv(tmpnew); + ret = setenv("LD_LIBRARY_PATH", tmpnew, 1); + free(tmpnew); if (ret) { ret = -errno; - free(tmpnew); goto error; } } @@ -2519,14 +2524,11 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data) "--consumerd-err-sock", consumer_data->err_unix_sock_path, "--group", config.tracing_group_name.value, NULL); - if (config.consumerd32_lib_dir.value[0] != '\0') { - free(tmpnew); - } break; } default: - PERROR("unknown consumer type"); - exit(EXIT_FAILURE); + ERR("unknown consumer type"); + errno = 0; } if (errno != 0) { PERROR("Consumer execl()"); @@ -2622,7 +2624,8 @@ static int init_kernel_tracer(void) } /* Validate kernel version */ - ret = kernel_validate_version(kernel_tracer_fd); + ret = kernel_validate_version(kernel_tracer_fd, &kernel_tracer_version, + &kernel_tracer_abi_version); if (ret < 0) { goto error_version; } @@ -2829,20 +2832,6 @@ static int create_kernel_session(struct ltt_session *session) goto error; } - /* Create directory(ies) on local filesystem. */ - if (session->kernel_session->consumer->type == CONSUMER_DST_LOCAL && - strlen(session->kernel_session->consumer->dst.trace_path) > 0) { - ret = run_as_mkdir_recursive( - session->kernel_session->consumer->dst.trace_path, - S_IRWXU | S_IRWXG, session->uid, session->gid); - if (ret < 0) { - if (errno != EEXIST) { - ERR("Trace directory creation error"); - goto error; - } - } - } - session->kernel_session->uid = session->uid; session->kernel_session->gid = session->gid; session->kernel_session->output_traces = session->output_traces; @@ -5584,12 +5573,13 @@ int main(int argc, char **argv) /* Check if daemon is UID = 0 */ is_root = !getuid(); + if (create_lttng_rundir()) { + retval = -1; + goto exit_init_data; + } + if (is_root) { /* Create global run dir with root access */ - if (create_lttng_rundir()) { - retval = -1; - goto exit_init_data; - } kernel_channel_monitor_pipe = lttng_pipe_open(0); if (!kernel_channel_monitor_pipe) {