X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsave.c;h=18d303cac9184cbd82ba0671c4b92e75b8eb91e0;hp=0c91239931ad6125049687ea411fad8c52bddea7;hb=cba45edad79e4812a8dcac583778e25509c5e13b;hpb=d2992717e6c3df45a80c8529e50ab18b4415a0ac diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index 0c9123993..18d303cac 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 @@ -679,7 +678,7 @@ int save_kernel_context(struct config_writer *writer, 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; @@ -1239,6 +1238,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 +1397,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 +1409,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,6 +1420,7 @@ 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 >= sizeof(config_file_path)) { ret = LTTNG_ERR_SET_URL; @@ -1470,9 +1473,12 @@ int save_session(struct ltt_session *session, 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; } @@ -1484,6 +1490,7 @@ int save_session(struct ltt_session *session, ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } + file_opened = 1; writer = config_writer_create(fd); if (!writer) { @@ -1516,7 +1523,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; @@ -1578,7 +1585,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."); } }