X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsave.c;h=00cdd9364d5f4ff6c7b438debfb66972b9084e4b;hb=df4f5a87a21110a5f9447bcfd7ffeb25098a5fd4;hp=c0684711ac9c818ea43a13d2945c4f168c1d876b;hpb=9d82c4c2efc657618039baf1b9150f82b388ca96;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index c0684711a..00cdd9364 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -504,8 +504,8 @@ int save_kernel_userspace_probe_tracepoint_event(struct config_writer *writer, { int ret = 0; const char *probe_name, *provider_name, *binary_path; - struct lttng_userspace_probe_location *userspace_probe_location; - struct lttng_userspace_probe_location_lookup_method *lookup_method; + const struct lttng_userspace_probe_location *userspace_probe_location; + const struct lttng_userspace_probe_location_lookup_method *lookup_method; enum lttng_userspace_probe_location_lookup_method_type lookup_type; /* Get userspace probe location from the event. */ @@ -618,8 +618,8 @@ int save_kernel_userspace_probe_function_event(struct config_writer *writer, { int ret = 0; const char *function_name, *binary_path; - struct lttng_userspace_probe_location *userspace_probe_location; - struct lttng_userspace_probe_location_lookup_method *lookup_method; + const struct lttng_userspace_probe_location *userspace_probe_location; + const struct lttng_userspace_probe_location_lookup_method *lookup_method; enum lttng_userspace_probe_location_lookup_method_type lookup_type; /* Get userspace probe location from the event. */ @@ -2245,6 +2245,9 @@ int save_session_rotation_schedules(struct config_writer *writer, ret = config_writer_open_element(writer, config_element_rotation_schedules); + if (ret) { + goto end; + } if (session->rotate_timer_period) { ret = save_session_rotation_schedule(writer, LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC, @@ -2281,8 +2284,7 @@ static 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 */ + int ret, fd = -1; char config_file_path[PATH_MAX]; size_t len; struct config_writer *writer = NULL; @@ -2298,7 +2300,7 @@ int save_session(struct ltt_session *session, if (!session_access_ok(session, LTTNG_SOCK_GET_UID_CRED(creds), - LTTNG_SOCK_GET_GID_CRED(creds))) { + LTTNG_SOCK_GET_GID_CRED(creds)) || session->destroyed) { ret = LTTNG_ERR_EPERM; goto end; } @@ -2375,7 +2377,6 @@ int save_session(struct ltt_session *session, ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - file_opened = 1; writer = config_writer_create(fd, 1); if (!writer) { @@ -2489,12 +2490,12 @@ end: } if (ret) { /* Delete file in case of error */ - if (file_opened && unlink(config_file_path)) { + if ((fd >= 0) && unlink(config_file_path)) { PERROR("Unlinking XML session configuration."); } } - if (file_opened) { + if (fd >= 0) { ret = close(fd); if (ret) { PERROR("Closing XML session configuration"); @@ -2524,6 +2525,7 @@ int cmd_save_sessions(struct lttng_save_session_attr *attr, session_lock(session); ret = save_session(session, attr, creds); session_unlock(session); + session_put(session); if (ret) { goto end; } @@ -2531,10 +2533,13 @@ int cmd_save_sessions(struct lttng_save_session_attr *attr, struct ltt_session_list *list = session_get_list(); cds_list_for_each_entry(session, &list->head, list) { + if (!session_get(session)) { + continue; + } session_lock(session); ret = save_session(session, attr, creds); session_unlock(session); - + session_put(session); /* Don't abort if we don't have the required permissions. */ if (ret && ret != LTTNG_ERR_EPERM) { goto end;