X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fsession-rotation.c;h=7df5ebab0d8daf97324fccdc0dfb55715ae01da5;hp=be48a998a98030d41e4cdc49793f3f3579481f4c;hb=3e6e0df2f8f9f23d252c2508b6d741916dfcc4b3;hpb=c19092cd4d6af49c38322fc55ca91f17f03f32ac diff --git a/src/common/session-rotation.c b/src/common/session-rotation.c index be48a998a..7df5ebab0 100644 --- a/src/common/session-rotation.c +++ b/src/common/session-rotation.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2017 - Jérémie Galarneau + * Copyright (C) 2017 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 @@ -29,7 +19,7 @@ bool lttng_condition_session_rotation_validate( static int lttng_condition_session_rotation_serialize( const struct lttng_condition *condition, - struct lttng_dynamic_buffer *buf); + struct lttng_payload *payload); static bool lttng_condition_session_rotation_is_equal(const struct lttng_condition *_a, const struct lttng_condition *_b); @@ -49,7 +39,7 @@ struct lttng_condition rotation_condition_template = { static int lttng_evaluation_session_rotation_serialize( const struct lttng_evaluation *evaluation, - struct lttng_dynamic_buffer *buf); + struct lttng_payload *payload); static void lttng_evaluation_session_rotation_destroy( struct lttng_evaluation *evaluation); @@ -105,7 +95,7 @@ end: static int lttng_condition_session_rotation_serialize( const struct lttng_condition *condition, - struct lttng_dynamic_buffer *buf) + struct lttng_payload *payload) { int ret; size_t session_name_len; @@ -128,13 +118,13 @@ int lttng_condition_session_rotation_serialize( } rotation_comm.session_name_len = session_name_len; - ret = lttng_dynamic_buffer_append(buf, &rotation_comm, + ret = lttng_dynamic_buffer_append(&payload->buffer, &rotation_comm, sizeof(rotation_comm)); if (ret) { goto end; } - ret = lttng_dynamic_buffer_append(buf, rotation->session_name, - session_name_len); + ret = lttng_dynamic_buffer_append(&payload->buffer, + rotation->session_name, session_name_len); if (ret) { goto end; } @@ -194,7 +184,7 @@ struct lttng_condition *lttng_condition_session_rotation_create( } memcpy(&condition->parent, &rotation_condition_template, - sizeof(*condition)); + sizeof(condition->parent)); lttng_condition_init(&condition->parent, type); return &condition->parent; } @@ -212,33 +202,36 @@ struct lttng_condition *lttng_condition_session_rotation_completed_create(void) } static -ssize_t init_condition_from_buffer(struct lttng_condition *condition, - const struct lttng_buffer_view *src_view) +ssize_t init_condition_from_payload(struct lttng_condition *condition, + struct lttng_payload_view *src_view) { ssize_t ret, condition_size; enum lttng_condition_status status; - const struct lttng_condition_session_rotation_comm *condition_comm; const char *session_name; struct lttng_buffer_view name_view; + const struct lttng_condition_session_rotation_comm *condition_comm; + struct lttng_payload_view condition_comm_view = + lttng_payload_view_from_view( + src_view, 0, sizeof(*condition_comm)); - if (src_view->size < sizeof(*condition_comm)) { + if (!lttng_payload_view_is_valid(&condition_comm_view)) { ERR("Failed to initialize from malformed condition buffer: buffer too short to contain header"); ret = -1; goto end; } - condition_comm = (const struct lttng_condition_session_rotation_comm *) src_view->data; - name_view = lttng_buffer_view_from_view(src_view, - sizeof(*condition_comm), -1); + condition_comm = (typeof(condition_comm)) src_view->buffer.data; + name_view = lttng_buffer_view_from_view(&src_view->buffer, + sizeof(*condition_comm), condition_comm->session_name_len); - if (condition_comm->session_name_len > LTTNG_NAME_MAX) { - ERR("Failed to initialize from malformed condition buffer: name exceeds LTTNG_MAX_NAME"); + if (!lttng_buffer_view_is_valid(&name_view)) { + ERR("Failed to initialize from malformed condition buffer: buffer too short to contain session name"); ret = -1; goto end; } - if (name_view.size < condition_comm->session_name_len) { - ERR("Failed to initialize from malformed condition buffer: buffer too short to contain session name"); + if (condition_comm->session_name_len > LTTNG_NAME_MAX) { + ERR("Failed to initialize from malformed condition buffer: name exceeds LTTNG_MAX_NAME"); ret = -1; goto end; } @@ -271,8 +264,8 @@ end: } static -ssize_t lttng_condition_session_rotation_create_from_buffer( - const struct lttng_buffer_view *view, +ssize_t lttng_condition_session_rotation_create_from_payload( + struct lttng_payload_view *view, struct lttng_condition **_condition, enum lttng_condition_type type) { @@ -296,7 +289,7 @@ ssize_t lttng_condition_session_rotation_create_from_buffer( goto error; } - ret = init_condition_from_buffer(condition, view); + ret = init_condition_from_payload(condition, view); if (ret < 0) { goto error; } @@ -309,21 +302,21 @@ error: } LTTNG_HIDDEN -ssize_t lttng_condition_session_rotation_ongoing_create_from_buffer( - const struct lttng_buffer_view *view, +ssize_t lttng_condition_session_rotation_ongoing_create_from_payload( + struct lttng_payload_view *view, struct lttng_condition **condition) { - return lttng_condition_session_rotation_create_from_buffer(view, + return lttng_condition_session_rotation_create_from_payload(view, condition, LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING); } LTTNG_HIDDEN -ssize_t lttng_condition_session_rotation_completed_create_from_buffer( - const struct lttng_buffer_view *view, +ssize_t lttng_condition_session_rotation_completed_create_from_payload( + struct lttng_payload_view *view, struct lttng_condition **condition) { - return lttng_condition_session_rotation_create_from_buffer(view, + return lttng_condition_session_rotation_create_from_payload(view, condition, LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED); } @@ -341,7 +334,7 @@ struct lttng_evaluation *lttng_evaluation_session_rotation_create( } memcpy(&evaluation->parent, &rotation_evaluation_template, - sizeof(*evaluation)); + sizeof(evaluation->parent)); lttng_evaluation_init(&evaluation->parent, type); evaluation->id = id; evaluation->location = location; @@ -349,27 +342,30 @@ struct lttng_evaluation *lttng_evaluation_session_rotation_create( } static -ssize_t create_evaluation_from_buffer( +ssize_t create_evaluation_from_payload( enum lttng_condition_type type, - const struct lttng_buffer_view *view, + struct lttng_payload_view *view, struct lttng_evaluation **_evaluation) { ssize_t ret, size; struct lttng_evaluation *evaluation = NULL; struct lttng_trace_archive_location *location = NULL; - const struct lttng_evaluation_session_rotation_comm *comm = - (const struct lttng_evaluation_session_rotation_comm *) view->data; - struct lttng_buffer_view location_view; + const struct lttng_evaluation_session_rotation_comm *comm; + struct lttng_payload_view comm_view = lttng_payload_view_from_view( + view, 0, sizeof(*comm)); - if (view->size < sizeof(*comm)) { + if (!lttng_payload_view_is_valid(&comm_view)) { goto error; } + comm = (typeof(comm)) comm_view.buffer.data; size = sizeof(*comm); if (comm->has_location) { - location_view = lttng_buffer_view_from_view(view, sizeof(*comm), - -1); - if (!location_view.data) { + const struct lttng_buffer_view location_view = + lttng_buffer_view_from_view( + &view->buffer, sizeof(*comm), -1); + + if (!lttng_buffer_view_is_valid(&location_view)) { goto error; } @@ -397,9 +393,9 @@ error: } static -ssize_t lttng_evaluation_session_rotation_create_from_buffer( +ssize_t lttng_evaluation_session_rotation_create_from_payload( enum lttng_condition_type type, - const struct lttng_buffer_view *view, + struct lttng_payload_view *view, struct lttng_evaluation **_evaluation) { ssize_t ret; @@ -410,7 +406,7 @@ ssize_t lttng_evaluation_session_rotation_create_from_buffer( goto error; } - ret = create_evaluation_from_buffer(type, view, &evaluation); + ret = create_evaluation_from_payload(type, view, &evaluation); if (ret < 0) { goto error; } @@ -423,21 +419,21 @@ error: } LTTNG_HIDDEN -ssize_t lttng_evaluation_session_rotation_ongoing_create_from_buffer( - const struct lttng_buffer_view *view, +ssize_t lttng_evaluation_session_rotation_ongoing_create_from_payload( + struct lttng_payload_view *view, struct lttng_evaluation **evaluation) { - return lttng_evaluation_session_rotation_create_from_buffer( + return lttng_evaluation_session_rotation_create_from_payload( LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING, view, evaluation); } LTTNG_HIDDEN -ssize_t lttng_evaluation_session_rotation_completed_create_from_buffer( - const struct lttng_buffer_view *view, +ssize_t lttng_evaluation_session_rotation_completed_create_from_payload( + struct lttng_payload_view *view, struct lttng_evaluation **evaluation) { - return lttng_evaluation_session_rotation_create_from_buffer( + return lttng_evaluation_session_rotation_create_from_payload( LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED, view, evaluation); } @@ -515,7 +511,7 @@ end: static int lttng_evaluation_session_rotation_serialize( const struct lttng_evaluation *evaluation, - struct lttng_dynamic_buffer *buf) + struct lttng_payload *payload) { int ret; struct lttng_evaluation_session_rotation *rotation; @@ -525,7 +521,8 @@ int lttng_evaluation_session_rotation_serialize( struct lttng_evaluation_session_rotation, parent); comm.id = rotation->id; comm.has_location = !!rotation->location; - ret = lttng_dynamic_buffer_append(buf, &comm, sizeof(comm)); + ret = lttng_dynamic_buffer_append( + &payload->buffer, &comm, sizeof(comm)); if (ret) { goto end; } @@ -533,7 +530,7 @@ int lttng_evaluation_session_rotation_serialize( goto end; } ret = lttng_trace_archive_location_serialize(rotation->location, - buf); + &payload->buffer); end: return ret; }