X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsave.c;h=2c38df97292fd34fc3619d0c8bdc20d15a1ac1d6;hb=da6c3a50492fd90c5dec03183ce504228292bb3b;hp=2d8af38217754916ea7080dba0604f479c88027a;hpb=7e078ad1e690a390671a52e321276a03e3088fde;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 2d8af3821..2c38df972 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -259,8 +258,12 @@ const char *get_ust_context_type_string( case LTTNG_UST_CONTEXT_PTHREAD_ID: context_type_string = config_event_context_pthread_id; break; + case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER: + context_type_string = config_event_context_perf_thread_counter; + break; default: context_type_string = NULL; + break; } return context_type_string; @@ -667,19 +670,13 @@ int save_kernel_context(struct config_writer *writer, goto end; } - ret = config_writer_open_element(writer, config_element_contexts); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - ret = config_writer_open_element(writer, config_element_context); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) { + if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) { ret = config_writer_open_element(writer, config_element_perf); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; @@ -738,6 +735,30 @@ int save_kernel_context(struct config_writer *writer, goto end; } +end: + return ret; +} + +static +int save_kernel_contexts(struct config_writer *writer, + struct ltt_kernel_channel *kchan) +{ + int ret; + struct ltt_kernel_context *ctx; + + ret = config_writer_open_element(writer, config_element_contexts); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + cds_list_for_each_entry(ctx, &kchan->ctx_list, list) { + ret = save_kernel_context(writer, &ctx->ctx); + if (ret) { + goto end; + } + } + /* /contexts */ ret = config_writer_close_element(writer); if (ret) { @@ -845,7 +866,7 @@ int save_kernel_channel(struct config_writer *writer, goto end; } - ret = save_kernel_context(writer, kchan->ctx); + ret = save_kernel_contexts(writer, kchan); if (ret) { goto end; } @@ -990,7 +1011,7 @@ end: static int save_ust_session(struct config_writer *writer, - struct ltt_session *session, int save_jul) + struct ltt_session *session, int save_agent) { int ret; struct ltt_ust_channel *ust_chan; @@ -1002,7 +1023,7 @@ int save_ust_session(struct config_writer *writer, assert(session); ret = config_writer_write_element_string(writer, config_element_type, - save_jul ? config_domain_type_jul : config_domain_type_ust); + save_agent ? config_domain_type_jul : config_domain_type_ust); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; @@ -1032,11 +1053,12 @@ int save_ust_session(struct config_writer *writer, rcu_read_lock(); cds_lfht_for_each_entry(session->ust_session->domain_global.channels->ht, &iter.iter, node, node) { - int jul_channel; + int agent_channel; ust_chan = caa_container_of(node, struct ltt_ust_channel, node); - jul_channel = !strcmp(DEFAULT_JUL_CHANNEL_NAME, ust_chan->name); - if (!(save_jul ^ jul_channel)) { + agent_channel = !strcmp(DEFAULT_JUL_CHANNEL_NAME, ust_chan->name) || + !strcmp(DEFAULT_LOG4J_CHANNEL_NAME, ust_chan->name); + if (!(save_agent ^ agent_channel)) { ret = save_ust_channel(writer, ust_chan, session->ust_session); if (ret) { rcu_read_unlock(); @@ -1118,7 +1140,7 @@ int save_domains(struct config_writer *writer, struct ltt_session *session) } if (session->ust_session && - session->ust_session->domain_jul.being_used) { + lttng_ht_get_count(session->ust_session->agents) > 0) { ret = config_writer_open_element(writer, config_element_domain); if (ret) { @@ -1239,6 +1261,7 @@ end_net_output: ret = !output->dst.net.control_isset ? LTTNG_ERR_URL_CTRL_MISS : LTTNG_ERR_URL_DATA_MISS; + free(uri); goto end; } @@ -1397,6 +1420,7 @@ int save_session(struct ltt_session *session, struct lttng_save_session_attr *attr, lttng_sock_cred *creds) { int ret, fd; + unsigned int file_opened = 0; /* Indicate if the file has been opened */ char config_file_path[PATH_MAX]; size_t len; struct config_writer *writer = NULL; @@ -1408,6 +1432,7 @@ int save_session(struct ltt_session *session, assert(creds); session_name_len = strlen(session->name); + memset(config_file_path, 0, sizeof(config_file_path)); if (!session_access_ok(session, LTTNG_SOCK_GET_UID_CRED(creds), @@ -1418,8 +1443,9 @@ int save_session(struct ltt_session *session, provided_path = lttng_save_session_attr_get_output_url(attr); if (provided_path) { + DBG3("Save session in provided path %s", provided_path); len = strlen(provided_path); - if (len > PATH_MAX) { + if (len >= sizeof(config_file_path)) { ret = LTTNG_ERR_SET_URL; goto end; } @@ -1433,7 +1459,7 @@ int save_session(struct ltt_session *session, goto end; } - ret_len = snprintf(config_file_path, PATH_MAX, + ret_len = snprintf(config_file_path, sizeof(config_file_path), DEFAULT_SESSION_HOME_CONFIGPATH, home_dir); free(home_dir); if (ret_len < 0) { @@ -1445,11 +1471,12 @@ int save_session(struct ltt_session *session, } /* - * Check the path fits in PATH_MAX, including the / followed by trailing - * .lttng extension and the NULL terminated string. + * Check the path fits in the config file path dst including the '/' + * followed by trailing .lttng extension and the NULL terminated string. */ - if (len + session_name_len + 2 + - sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION) > PATH_MAX) { + if ((len + session_name_len + 2 + + sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION)) + > sizeof(config_file_path)) { ret = LTTNG_ERR_SET_URL; goto end; } @@ -1461,13 +1488,20 @@ int save_session(struct ltt_session *session, goto end; } + /* + * At this point, we know that everything fits in the buffer. Validation + * was done just above. + */ config_file_path[len++] = '/'; strncpy(config_file_path + len, session->name, session_name_len); len += session_name_len; strcpy(config_file_path + len, DEFAULT_SESSION_CONFIG_FILE_EXTENSION); + len += sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION); + config_file_path[len] = '\0'; if (!access(config_file_path, F_OK) && !attr->overwrite) { - /* A file with the same name already exists, skip */ + /* File exists, notify the user since the overwrite flag is off. */ + ret = LTTNG_ERR_SAVE_FILE_EXIST; goto end; } @@ -1479,8 +1513,9 @@ int save_session(struct ltt_session *session, ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } + file_opened = 1; - writer = config_writer_create(fd); + writer = config_writer_create(fd, 1); if (!writer) { ret = LTTNG_ERR_NOMEM; goto end; @@ -1511,7 +1546,7 @@ int save_session(struct ltt_session *session, } ret = config_writer_write_element_bool(writer, config_element_started, - session->enabled); + session->active); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; @@ -1532,7 +1567,7 @@ int save_session(struct ltt_session *session, goto end; } } else { - ret = config_writer_write_element_signed_int(writer, + ret = config_writer_write_element_unsigned_int(writer, config_element_live_timer_interval, session->live_timer); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; @@ -1573,7 +1608,7 @@ end: } if (ret) { /* Delete file in case of error */ - if (unlink(config_file_path)) { + if (file_opened && unlink(config_file_path)) { PERROR("Unlinking XML session configuration."); } }