X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Fdestruction-handle.c;h=aeeece7e316abad31884c5498667b1fb09f60f3c;hp=f0ff0d4e170e0e4bf2178b0075e91047b3170a4e;hb=96c5e4c3a65d7c43793b1d93b78697633da823ca;hpb=b6d816c549c67b05339722a503a8272f81022dc2 diff --git a/src/lib/lttng-ctl/destruction-handle.c b/src/lib/lttng-ctl/destruction-handle.c index f0ff0d4e1..aeeece7e3 100644 --- a/src/lib/lttng-ctl/destruction-handle.c +++ b/src/lib/lttng-ctl/destruction-handle.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2019 - Jérémie Galarneau + * Copyright (C) 2019 Jérémie Galarneau * - * 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 */ #include @@ -66,8 +56,8 @@ void lttng_destruction_handle_destroy(struct lttng_destruction_handle *handle) if (ret) { PERROR("Failed to close lttng-sessiond command socket"); } - } - lttng_poll_clean(&handle->communication.events); + } + lttng_poll_clean(&handle->communication.events); lttng_dynamic_buffer_reset(&handle->communication.buffer); lttng_trace_archive_location_destroy(handle->location); free(handle); @@ -92,9 +82,9 @@ struct lttng_destruction_handle *lttng_destruction_handle_create( ret = lttng_poll_add(&handle->communication.events, sessiond_socket, LPOLLIN | LPOLLHUP | LPOLLRDHUP | LPOLLERR); - if (ret) { + if (ret) { goto error; - } + } handle->communication.bytes_left_to_receive = sizeof(struct lttcomm_lttng_msg); @@ -241,34 +231,39 @@ lttng_destruction_handle_wait_for_completion( enum lttng_destruction_handle_status status; unsigned long time_left_ms = 0; const bool has_timeout = timeout_ms > 0; - struct timespec initial_time; + struct timespec initial_time; - if (handle->communication.state == COMMUNICATION_STATE_ERROR) { + if (!handle) { + status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID; + goto end; + } + + if (handle->communication.state == COMMUNICATION_STATE_ERROR) { status = LTTNG_DESTRUCTION_HANDLE_STATUS_ERROR; goto end; } else if (handle->communication.state == COMMUNICATION_STATE_END) { status = LTTNG_DESTRUCTION_HANDLE_STATUS_COMPLETED; goto end; } - if (has_timeout) { + if (has_timeout) { ret = lttng_clock_gettime(CLOCK_MONOTONIC, &initial_time); if (ret) { status = LTTNG_DESTRUCTION_HANDLE_STATUS_ERROR; goto end; } time_left_ms = (unsigned long) timeout_ms; - } + } - while (handle->communication.state != COMMUNICATION_STATE_END && + while (handle->communication.state != COMMUNICATION_STATE_END && (time_left_ms || !has_timeout)) { int ret; uint32_t revents; - struct timespec current_time, diff; + struct timespec current_time, diff; unsigned long diff_ms; - ret = lttng_poll_wait(&handle->communication.events, + ret = lttng_poll_wait(&handle->communication.events, has_timeout ? time_left_ms : -1); - if (ret == 0) { + if (ret == 0) { /* timeout */ break; } else if (ret < 0) { @@ -329,6 +324,11 @@ lttng_destruction_handle_get_rotation_state( enum lttng_destruction_handle_status status = LTTNG_DESTRUCTION_HANDLE_STATUS_OK; + if (!handle || !rotation_state) { + status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID; + goto end; + } + if (!handle->rotation_state.is_set) { status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID; goto end; @@ -346,6 +346,11 @@ lttng_destruction_handle_get_archive_location( enum lttng_destruction_handle_status status = LTTNG_DESTRUCTION_HANDLE_STATUS_OK; + if (!handle || !location) { + status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID; + goto end; + } + if (!handle->location) { status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID; goto end; @@ -363,6 +368,11 @@ lttng_destruction_handle_get_result( enum lttng_destruction_handle_status status = LTTNG_DESTRUCTION_HANDLE_STATUS_OK; + if (!handle || !result) { + status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID; + goto end; + } + if (!handle->destruction_return_code.is_set) { status = LTTNG_DESTRUCTION_HANDLE_STATUS_INVALID; goto end; @@ -378,12 +388,17 @@ enum lttng_error_code lttng_destroy_session_ext(const char *session_name, int ret; ssize_t comm_ret; enum lttng_error_code ret_code = LTTNG_OK; - struct lttcomm_session_msg lsm = { + struct lttcomm_session_msg lsm = { .cmd_type = LTTNG_DESTROY_SESSION, }; int sessiond_socket = -1; struct lttng_destruction_handle *handle = NULL; + if (!session_name) { + ret_code = LTTNG_ERR_INVALID; + goto error; + } + ret = lttng_strncpy(lsm.session.name, session_name, sizeof(lsm.session.name)); if (ret) {