| 1 | /* |
| 2 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> |
| 3 | * David Goulet <dgoulet@efficios.com> |
| 4 | * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License, version 2 only, as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along with |
| 16 | * this program; if not, write to the Free Software Foundation, Inc., 51 |
| 17 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | */ |
| 19 | |
| 20 | #define _LGPL_SOURCE |
| 21 | #include <assert.h> |
| 22 | |
| 23 | #include <common/common.h> |
| 24 | #include <common/sessiond-comm/relayd.h> |
| 25 | |
| 26 | #include <common/compat/endian.h> |
| 27 | #include <common/compat/string.h> |
| 28 | #include <lttng/constant.h> |
| 29 | |
| 30 | #include "cmd-2-4.h" |
| 31 | #include "lttng-relayd.h" |
| 32 | |
| 33 | int cmd_create_session_2_4(const struct lttng_buffer_view *payload, |
| 34 | char *session_name, char *hostname, |
| 35 | uint32_t *live_timer, bool *snapshot) |
| 36 | { |
| 37 | int ret; |
| 38 | struct lttcomm_relayd_create_session_2_4 session_info; |
| 39 | size_t len; |
| 40 | |
| 41 | if (payload->size < sizeof(session_info)) { |
| 42 | ERR("Unexpected payload size in \"cmd_create_session_2_4\": expected >= %zu bytes, got %zu bytes", |
| 43 | sizeof(session_info), payload->size); |
| 44 | ret = -1; |
| 45 | goto error; |
| 46 | } |
| 47 | memcpy(&session_info, payload->data, sizeof(session_info)); |
| 48 | |
| 49 | len = lttng_strnlen(session_info.session_name, sizeof(session_info.session_name)); |
| 50 | /* Ensure that NULL-terminated and fits in local filename length. */ |
| 51 | if (len == sizeof(session_info.session_name) || len >= LTTNG_NAME_MAX) { |
| 52 | ret = -ENAMETOOLONG; |
| 53 | ERR("Session name too long"); |
| 54 | goto error; |
| 55 | } else if (len == 0) { |
| 56 | ret = -EINVAL; |
| 57 | ERR("Session name can't be of length 0"); |
| 58 | goto error; |
| 59 | } |
| 60 | strncpy(session_name, session_info.session_name, LTTNG_NAME_MAX); |
| 61 | |
| 62 | len = lttng_strnlen(session_info.hostname, sizeof(session_info.hostname)); |
| 63 | if (len == sizeof(session_info.hostname) || len >= LTTNG_HOST_NAME_MAX) { |
| 64 | ret = -ENAMETOOLONG; |
| 65 | ERR("Session name too long"); |
| 66 | goto error; |
| 67 | } |
| 68 | strncpy(hostname, session_info.hostname, LTTNG_HOST_NAME_MAX); |
| 69 | |
| 70 | *live_timer = be32toh(session_info.live_timer); |
| 71 | *snapshot = be32toh(session_info.snapshot); |
| 72 | |
| 73 | ret = 0; |
| 74 | |
| 75 | error: |
| 76 | return ret; |
| 77 | } |