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,
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;
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;
}
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
- file_opened = 1;
writer = config_writer_create(fd, 1);
if (!writer) {
}
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");
session_lock(session);
ret = save_session(session, attr, creds);
session_unlock(session);
+ session_put(session);
if (ret) {
goto end;
}
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;