sessiond: Implement clear for sessions with local and remote output
[lttng-tools.git] / src / bin / lttng-sessiond / clear.c
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 if (session->ust_session) {
45 switch (session->ust_session->buffer_type) {
46 case LTTNG_BUFFER_PER_PID:
47 ERR("Clear command not supported for per-pid buffers.");
48 ret = LTTNG_ERR_CLEAR_NOT_AVAILABLE;
49 goto error;
50 case LTTNG_BUFFER_PER_UID:
51 case LTTNG_BUFFER_GLOBAL:
52 break;
53 }
54 }
55
56 /*
57 * Clear kernel and UST session buffers and local files (if any).
58 */
59 if (session->kernel_session) {
60 ret = kernel_clear_session(session);
61 if (ret != LTTNG_OK) {
62 goto error;
63 }
64 }
65 if (session->ust_session) {
66 ret = ust_app_clear_session(session);
67 if (ret != LTTNG_OK) {
68 goto error;
69 }
70 }
71
72 /*
73 * Clear remote (relayd) session files.
74 */
75 ret = consumer_clear_session(session);
76 if (ret < 0) {
77 ret = LTTNG_ERR_CLEAR_FAIL_CONSUMER;
78 goto error;
79 }
80 ret = LTTNG_OK;
81 error:
82 end:
83 return ret;
84 }
This page took 0.032129 seconds and 5 git commands to generate.