Commit | Line | Data |
---|---|---|
f3e3b722 JR |
1 | /* |
2 | * Copyright (C) 2019 - Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License, version 2 only, as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
15 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
16 | */ | |
17 | ||
18 | #define _LGPL_SOURCE | |
19 | #include <assert.h> | |
20 | #include <inttypes.h> | |
21 | #include <string.h> | |
22 | #include <unistd.h> | |
23 | ||
24 | #include <common/defaults.h> | |
25 | #include <common/error.h> | |
26 | #include <common/utils.h> | |
27 | ||
28 | #include "clear.h" | |
29 | #include "session.h" | |
30 | #include "ust-app.h" | |
31 | #include "kernel.h" | |
32 | ||
33 | ||
34 | int cmd_clear_session(struct ltt_session *session) | |
35 | { | |
36 | int ret; | |
37 | ||
38 | if (!session->has_been_started) { | |
39 | /* Nothing to be cleared, do not warn */ | |
40 | ret = LTTNG_OK; | |
41 | goto end; | |
42 | } | |
43 | ||
44 | /* | |
45 | * Unsupported feature in lttng-relayd before 2.12. | |
46 | */ | |
47 | if (session->consumer->type == CONSUMER_DST_NET && | |
48 | (session->consumer->relay_major_version == 2 && | |
49 | session->consumer->relay_minor_version < 12)) { | |
50 | ret = LTTNG_ERR_CLEAR_NOT_AVAILABLE_RELAY; | |
51 | goto end; | |
52 | } | |
53 | ||
54 | /* TODO: Should we check for disallowed here or consumer side? */ | |
55 | ||
56 | /* Snapshot session are the only one supported for now */ | |
57 | if (!session->snapshot_mode) { | |
58 | /* | |
59 | * TODO: this error code is temporary and will be removed since | |
60 | * we will be supporting all session type | |
61 | */ | |
62 | ret = LTTNG_ERR_CLEAR_NOT_AVAILABLE; | |
63 | goto end; | |
64 | } | |
65 | ||
66 | if (session->kernel_session) { | |
67 | ret = kernel_clear_session(session); | |
68 | if (ret != LTTNG_OK) { | |
69 | goto error; | |
70 | } | |
71 | } | |
72 | if (session->ust_session) { | |
73 | ret = ust_app_clear_session(session); | |
74 | if (ret != LTTNG_OK) { | |
75 | goto error; | |
76 | } | |
77 | } | |
78 | error: | |
79 | end: | |
80 | return ret; | |
81 | } |