X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Frotate.c;h=2dbaa46a3eaf9d955b3d50f030c0504421aa3260;hp=5c5b1b70cc05b2eecee78809cce1309d716b9a14;hb=25357057de5ae4dd2a572e8f9b893c1b90cbd60a;hpb=66ea93b10c703e1b3dda1e17109eed9138e4ece2 diff --git a/src/lib/lttng-ctl/rotate.c b/src/lib/lttng-ctl/rotate.c index 5c5b1b70c..2dbaa46a3 100644 --- a/src/lib/lttng-ctl/rotate.c +++ b/src/lib/lttng-ctl/rotate.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2017 - Julien Desfossez + * Copyright (C) 2017 Julien Desfossez * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License, version 2.1 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: LGPL-2.1-only * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define _LGPL_SOURCE @@ -233,7 +223,7 @@ int lttng_rotate_session(const char *session_name, sizeof(lsm.session.name)); ret = lttng_ctl_ask_sessiond(&lsm, (void **) &rotate_return); - if (ret < 0) { + if (ret <= 0) { *rotation_handle = NULL; goto end; } @@ -299,23 +289,33 @@ enum lttng_rotation_status lttng_rotation_update_schedule( switch (schedule->type) { case LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD: { + uint64_t threshold; + status = lttng_rotation_schedule_size_threshold_get_threshold( - schedule, &lsm.u.rotation_set_schedule.value); + schedule, &threshold); if (status != LTTNG_ROTATION_STATUS_OK) { + if (status == LTTNG_ROTATION_STATUS_UNAVAILABLE) { + status = LTTNG_ROTATION_STATUS_INVALID; + } goto end; } - + lsm.u.rotation_set_schedule.value = threshold; lsm.u.rotation_set_schedule.set = !!add; break; } case LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC: { + uint64_t period; + status = lttng_rotation_schedule_periodic_get_period( - schedule, &lsm.u.rotation_set_schedule.value); + schedule, &period); if (status != LTTNG_ROTATION_STATUS_OK) { + if (status == LTTNG_ROTATION_STATUS_UNAVAILABLE) { + status = LTTNG_ROTATION_STATUS_INVALID; + } goto end; } - + lsm.u.rotation_set_schedule.value = period; lsm.u.rotation_set_schedule.set = !!add; break; } @@ -362,7 +362,7 @@ int get_schedules(const char *session_name, { int ret; struct lttcomm_session_msg lsm; - struct lttng_session_list_schedules_return *schedules_comm; + struct lttng_session_list_schedules_return *schedules_comm = NULL; struct lttng_rotation_schedules *schedules = NULL; struct lttng_rotation_schedule *periodic = NULL, *size = NULL; @@ -468,7 +468,8 @@ lttng_rotation_schedule_size_threshold_get_threshold( enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK; struct lttng_rotation_schedule_size_threshold *size_schedule; - if (!schedule || !size_threshold_bytes) { + if (!schedule || !size_threshold_bytes || + schedule->type != LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD) { status = LTTNG_ROTATION_STATUS_INVALID; goto end; } @@ -495,7 +496,8 @@ lttng_rotation_schedule_size_threshold_set_threshold( struct lttng_rotation_schedule_size_threshold *size_schedule; if (!schedule || size_threshold_bytes == 0 || - size_threshold_bytes == -1ULL) { + size_threshold_bytes == -1ULL || + schedule->type != LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD) { status = LTTNG_ROTATION_STATUS_INVALID; goto end; } @@ -532,7 +534,8 @@ lttng_rotation_schedule_periodic_get_period( enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK; struct lttng_rotation_schedule_periodic *periodic_schedule; - if (!schedule || !period_us) { + if (!schedule || !period_us || + schedule->type != LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC) { status = LTTNG_ROTATION_STATUS_INVALID; goto end; } @@ -558,7 +561,8 @@ lttng_rotation_schedule_periodic_set_period( enum lttng_rotation_status status = LTTNG_ROTATION_STATUS_OK; struct lttng_rotation_schedule_periodic *periodic_schedule; - if (!schedule || period_us == 0 || period_us == -1ULL) { + if (!schedule || period_us == 0 || period_us == -1ULL || + schedule->type != LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC) { status = LTTNG_ROTATION_STATUS_INVALID; goto end; }