X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Flib%2Flttng-ctl%2Fsnapshot.c;h=93f393fc298bc7e9d40efebc8026913229a26ae0;hp=b30c4706e7db2a5d6901b1dd586a245d1e912ddb;hb=0de2479d5f5a287d31c69e34ea5202a69019f224;hpb=890d8fe47755c3bad936389cf48ffa141cff41c9 diff --git a/src/lib/lttng-ctl/snapshot.c b/src/lib/lttng-ctl/snapshot.c index b30c4706e..93f393fc2 100644 --- a/src/lib/lttng-ctl/snapshot.c +++ b/src/lib/lttng-ctl/snapshot.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2013 - David Goulet + * Copyright (C) 2013 David Goulet * - * 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 @@ -39,26 +29,33 @@ int lttng_snapshot_add_output(const char *session_name, struct lttcomm_lttng_output_id *reply; if (!session_name || !output) { - return -LTTNG_ERR_INVALID; + ret = -LTTNG_ERR_INVALID; + goto end; } memset(&lsm, 0, sizeof(lsm)); lsm.cmd_type = LTTNG_SNAPSHOT_ADD_OUTPUT; - lttng_ctl_copy_string(lsm.session.name, session_name, + ret = lttng_strncpy(lsm.session.name, session_name, sizeof(lsm.session.name)); + if (ret) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + memcpy(&lsm.u.snapshot_output.output, output, sizeof(lsm.u.snapshot_output.output)); ret = lttng_ctl_ask_sessiond(&lsm, (void **) &reply); if (ret < 0) { - return ret; + goto end; } output->id = reply->id; free(reply); - - return 0; + ret = 0; +end: + return ret; } /* @@ -69,21 +66,30 @@ int lttng_snapshot_add_output(const char *session_name, int lttng_snapshot_del_output(const char *session_name, struct lttng_snapshot_output *output) { + int ret; struct lttcomm_session_msg lsm; if (!session_name || !output) { - return -LTTNG_ERR_INVALID; + ret = -LTTNG_ERR_INVALID; + goto end; } memset(&lsm, 0, sizeof(lsm)); lsm.cmd_type = LTTNG_SNAPSHOT_DEL_OUTPUT; - lttng_ctl_copy_string(lsm.session.name, session_name, - sizeof(lsm.session.name)); + ret = lttng_strncpy(lsm.session.name, session_name, + sizeof(lsm.session.name)); + if (ret) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + memcpy(&lsm.u.snapshot_output.output, output, sizeof(lsm.u.snapshot_output.output)); - return lttng_ctl_ask_sessiond(&lsm, NULL); + ret = lttng_ctl_ask_sessiond(&lsm, NULL); +end: + return ret; } /* @@ -108,8 +114,12 @@ int lttng_snapshot_list_output(const char *session_name, memset(&lsm, 0, sizeof(lsm)); lsm.cmd_type = LTTNG_SNAPSHOT_LIST_OUTPUT; - lttng_ctl_copy_string(lsm.session.name, session_name, - sizeof(lsm.session.name)); + ret = lttng_strncpy(lsm.session.name, session_name, + sizeof(lsm.session.name)); + if (ret) { + ret = -LTTNG_ERR_INVALID; + goto error; + } new_list = zmalloc(sizeof(*new_list)); if (!new_list) { @@ -189,17 +199,23 @@ void lttng_snapshot_output_list_destroy(struct lttng_snapshot_output_list *list) int lttng_snapshot_record(const char *session_name, struct lttng_snapshot_output *output, int wait) { + int ret; struct lttcomm_session_msg lsm; if (!session_name) { - return -LTTNG_ERR_INVALID; + ret = -LTTNG_ERR_INVALID; + goto end; } memset(&lsm, 0, sizeof(lsm)); lsm.cmd_type = LTTNG_SNAPSHOT_RECORD; - lttng_ctl_copy_string(lsm.session.name, session_name, + ret = lttng_strncpy(lsm.session.name, session_name, sizeof(lsm.session.name)); + if (ret) { + ret = -LTTNG_ERR_INVALID; + goto end; + } /* * Not having an output object will use the default one of the session that @@ -212,8 +228,9 @@ int lttng_snapshot_record(const char *session_name, } /* The wait param is ignored. */ - - return lttng_ctl_ask_sessiond(&lsm, NULL); + ret = lttng_ctl_ask_sessiond(&lsm, NULL); +end: + return ret; } /* @@ -248,29 +265,29 @@ void lttng_snapshot_output_destroy(struct lttng_snapshot_output *obj) * Getter family functions of snapshot output. */ -uint32_t lttng_snapshot_output_get_id(struct lttng_snapshot_output *output) +uint32_t lttng_snapshot_output_get_id(const struct lttng_snapshot_output *output) { return output->id; } const char *lttng_snapshot_output_get_name( - struct lttng_snapshot_output *output) + const struct lttng_snapshot_output *output) { return output->name; } -const char *lttng_snapshot_output_get_data_url(struct lttng_snapshot_output *output) +const char *lttng_snapshot_output_get_data_url(const struct lttng_snapshot_output *output) { return output->data_url; } -const char *lttng_snapshot_output_get_ctrl_url(struct lttng_snapshot_output *output) +const char *lttng_snapshot_output_get_ctrl_url(const struct lttng_snapshot_output *output) { return output->ctrl_url; } uint64_t lttng_snapshot_output_get_maxsize( - struct lttng_snapshot_output *output) + const struct lttng_snapshot_output *output) { return output->max_size; } @@ -304,32 +321,182 @@ int lttng_snapshot_output_set_size(uint64_t size, int lttng_snapshot_output_set_name(const char *name, struct lttng_snapshot_output *output) { + int ret; + if (!output || !name) { - return -LTTNG_ERR_INVALID; + ret = -LTTNG_ERR_INVALID; + goto end; } - lttng_ctl_copy_string(output->name, name, sizeof(output->name)); - return 0; + ret = lttng_strncpy(output->name, name, sizeof(output->name)); + if (ret) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + +end: + return ret; } int lttng_snapshot_output_set_ctrl_url(const char *url, struct lttng_snapshot_output *output) { + int ret; + if (!output || !url) { - return -LTTNG_ERR_INVALID; + ret = -LTTNG_ERR_INVALID; + goto end; } - lttng_ctl_copy_string(output->ctrl_url, url, sizeof(output->ctrl_url)); - return 0; + ret = lttng_strncpy(output->ctrl_url, url, sizeof(output->ctrl_url)); + if (ret) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + +end: + return ret; } int lttng_snapshot_output_set_data_url(const char *url, struct lttng_snapshot_output *output) { + int ret; + if (!output || !url) { - return -LTTNG_ERR_INVALID; + ret = -LTTNG_ERR_INVALID; + goto end; } - lttng_ctl_copy_string(output->data_url, url, sizeof(output->data_url)); - return 0; + ret = lttng_strncpy(output->data_url, url, sizeof(output->data_url)); + if (ret) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + +end: + return ret; +} + +int lttng_snapshot_output_set_local_path(const char *path, + struct lttng_snapshot_output *output) +{ + int ret; + struct lttng_uri *uris = NULL; + ssize_t num_uris; + + if (!path || !output) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + num_uris = uri_parse_str_urls(path, NULL, &uris); + if (num_uris != 1) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + if (uris[0].dtype != LTTNG_DST_PATH) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ret = lttng_strncpy(output->ctrl_url, path, sizeof(output->ctrl_url)); + if (ret != 0) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + +end: + free(uris); + return ret; +} + +int lttng_snapshot_output_set_network_url(const char *url, + struct lttng_snapshot_output *output) +{ + int ret; + struct lttng_uri *uris = NULL; + ssize_t num_uris; + + if (!url || !output) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + num_uris = uri_parse_str_urls(url, NULL, &uris); + if (num_uris != 2) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + if (uris[0].dtype != LTTNG_DST_IPV4 && + uris[0].dtype != LTTNG_DST_IPV6) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + if (uris[1].dtype != LTTNG_DST_IPV4 && + uris[1].dtype != LTTNG_DST_IPV6) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ret = lttng_strncpy(output->ctrl_url, url, sizeof(output->ctrl_url)); + if (ret != 0) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + +end: + free(uris); + return ret; +} + +int lttng_snapshot_output_set_network_urls( + const char *ctrl_url, const char *data_url, + struct lttng_snapshot_output *output) +{ + int ret; + struct lttng_uri *uris = NULL; + ssize_t num_uris; + + if (!ctrl_url || !data_url || !output) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + num_uris = uri_parse_str_urls(ctrl_url, data_url, &uris); + if (num_uris != 2) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + if (uris[0].dtype != LTTNG_DST_IPV4 && + uris[0].dtype != LTTNG_DST_IPV6) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + if (uris[1].dtype != LTTNG_DST_IPV4 && + uris[1].dtype != LTTNG_DST_IPV6) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ret = lttng_strncpy(output->ctrl_url, ctrl_url, sizeof(output->ctrl_url)); + if (ret != 0) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ret = lttng_strncpy(output->data_url, data_url, sizeof(output->data_url)); + if (ret != 0) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + +end: + free(uris); + return ret; }