docs: Add supported versions and fix-backport policy
[lttng-tools.git] / src / bin / lttng-relayd / cmd-2-4.cpp
CommitLineData
d3e2ba59 1/*
ab5be9fa
MJ
2 * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
d3e2ba59 5 *
ab5be9fa 6 * SPDX-License-Identifier: GPL-2.0-only
d3e2ba59 7 *
d3e2ba59
JD
8 */
9
6c1c0768 10#define _LGPL_SOURCE
d3e2ba59 11
28ab034a
JG
12#include "cmd-2-4.hpp"
13#include "lttng-relayd.hpp"
d3e2ba59 14
28ab034a 15#include <common/common.hpp>
c9e313bc
SM
16#include <common/compat/endian.hpp>
17#include <common/compat/string.hpp>
28ab034a 18#include <common/sessiond-comm/relayd.hpp>
f263b7fd 19
28ab034a 20#include <lttng/constant.h>
d3e2ba59 21
5312a3ed 22int cmd_create_session_2_4(const struct lttng_buffer_view *payload,
28ab034a
JG
23 char *session_name,
24 char *hostname,
25 uint32_t *live_timer,
26 bool *snapshot)
d3e2ba59
JD
27{
28 int ret;
29 struct lttcomm_relayd_create_session_2_4 session_info;
246777db 30 size_t len;
d3e2ba59 31
5312a3ed
JG
32 if (payload->size < sizeof(session_info)) {
33 ERR("Unexpected payload size in \"cmd_create_session_2_4\": expected >= %zu bytes, got %zu bytes",
28ab034a
JG
34 sizeof(session_info),
35 payload->size);
5312a3ed 36 ret = -1;
d3e2ba59
JD
37 goto error;
38 }
5312a3ed
JG
39 memcpy(&session_info, payload->data, sizeof(session_info));
40
246777db
MD
41 len = lttng_strnlen(session_info.session_name, sizeof(session_info.session_name));
42 /* Ensure that NULL-terminated and fits in local filename length. */
43 if (len == sizeof(session_info.session_name) || len >= LTTNG_NAME_MAX) {
44 ret = -ENAMETOOLONG;
45 ERR("Session name too long");
46 goto error;
e7f8eff3
JG
47 } else if (len == 0) {
48 ret = -EINVAL;
49 ERR("Session name can't be of length 0");
50 goto error;
246777db 51 }
da4f23ee 52 strncpy(session_name, session_info.session_name, LTTNG_NAME_MAX);
246777db
MD
53
54 len = lttng_strnlen(session_info.hostname, sizeof(session_info.hostname));
55 if (len == sizeof(session_info.hostname) || len >= LTTNG_HOST_NAME_MAX) {
56 ret = -ENAMETOOLONG;
57 ERR("Session name too long");
58 goto error;
59 }
885e05c5 60 strncpy(hostname, session_info.hostname, LTTNG_HOST_NAME_MAX);
46ef2188 61
7591bab1
MD
62 *live_timer = be32toh(session_info.live_timer);
63 *snapshot = be32toh(session_info.snapshot);
d3e2ba59
JD
64
65 ret = 0;
66
67error:
68 return ret;
69}
This page took 0.071527 seconds and 4 git commands to generate.