Add UST event exist error code
[lttng-tools.git] / lttng-sessiond / channel.c
CommitLineData
54d01ffb
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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 as published by the Free
6 * Software Foundation; only version 2 of the License.
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., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
56fff090 18#include <string.h>
54d01ffb
DG
19#include <unistd.h>
20
21#include <lttng/lttng.h>
22#include <lttng-sessiond-comm.h>
23#include <lttngerr.h>
24
25#include "channel.h"
f6a9efaa 26#include "hashtable.h"
4771f025 27#include "kernel.h"
44d3bd01 28#include "ust-ctl.h"
54d01ffb
DG
29#include "utils.h"
30
31/*
32 * Return allocated channel attributes.
33 */
f6cd6b0f 34struct lttng_channel *channel_new_default_attr(int dom)
54d01ffb
DG
35{
36 struct lttng_channel *chan;
37
38 chan = zmalloc(sizeof(struct lttng_channel));
39 if (chan == NULL) {
ba7f0ae5 40 perror("zmalloc channel init");
54d01ffb
DG
41 goto error_alloc;
42 }
43
44d3bd01
DG
44 if (snprintf(chan->name, sizeof(chan->name), "%s",
45 DEFAULT_CHANNEL_NAME) < 0) {
46 perror("snprintf default channel name");
54d01ffb
DG
47 goto error;
48 }
49
50 chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
51 chan->attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
52 chan->attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
53
54 switch (dom) {
1b1c65fa
MD
55 case LTTNG_DOMAIN_KERNEL:
56 chan->attr.subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE;
57 chan->attr.num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
58 chan->attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
59 break;
60 case LTTNG_DOMAIN_UST:
61 case LTTNG_DOMAIN_UST_PID:
62 chan->attr.subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE;
63 chan->attr.num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM;
64 chan->attr.output = DEFAULT_UST_CHANNEL_OUTPUT;
65 break;
66 default:
67 goto error; /* Not implemented */
54d01ffb
DG
68 }
69
70 return chan;
71
72error:
73 free(chan);
74error_alloc:
75 return NULL;
76}
77
78/*
79 * Disable kernel channel of the kernel session.
80 */
81int channel_kernel_disable(struct ltt_kernel_session *ksession,
82 char *channel_name)
83{
84 int ret;
85 struct ltt_kernel_channel *kchan;
86
87 kchan = trace_kernel_get_channel_by_name(channel_name, ksession);
88 if (kchan == NULL) {
89 ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
90 goto error;
91 } else if (kchan->enabled == 1) {
92 ret = kernel_disable_channel(kchan);
93 if (ret < 0) {
94 if (ret != EEXIST) {
95 ret = LTTCOMM_KERN_CHAN_DISABLE_FAIL;
96 }
97 goto error;
98 }
99 }
100
101 ret = LTTCOMM_OK;
102
103error:
104 return ret;
105}
106
107/*
108 * Enable kernel channel of the kernel session.
109 */
110int channel_kernel_enable(struct ltt_kernel_session *ksession,
111 struct ltt_kernel_channel *kchan)
112{
113 int ret;
114
115 if (kchan->enabled == 0) {
116 ret = kernel_enable_channel(kchan);
117 if (ret < 0) {
118 ret = LTTCOMM_KERN_CHAN_ENABLE_FAIL;
119 goto error;
120 }
121 }
122
123 ret = LTTCOMM_OK;
124
125error:
126 return ret;
127}
128
129/*
130 * Create kernel channel of the kernel session and notify kernel thread.
131 */
132int channel_kernel_create(struct ltt_kernel_session *ksession,
ff4d74e6 133 struct lttng_channel *attr, int kernel_pipe)
54d01ffb
DG
134{
135 int ret;
ff4d74e6 136 struct lttng_channel *defattr = NULL;
54d01ffb
DG
137
138 /* Creating channel attributes if needed */
139 if (attr == NULL) {
ff4d74e6
MD
140 defattr = channel_new_default_attr(LTTNG_DOMAIN_KERNEL);
141 if (defattr == NULL) {
54d01ffb
DG
142 ret = LTTCOMM_FATAL;
143 goto error;
144 }
ff4d74e6 145 attr = defattr;
54d01ffb
DG
146 }
147
148 /* Channel not found, creating it */
149 ret = kernel_create_channel(ksession, attr, ksession->trace_path);
150 if (ret < 0) {
151 ret = LTTCOMM_KERN_CHAN_FAIL;
152 goto error;
153 }
154
155 /* Notify kernel thread that there is a new channel */
156 ret = notify_thread_pipe(kernel_pipe);
157 if (ret < 0) {
158 ret = LTTCOMM_FATAL;
159 goto error;
160 }
161
162 ret = LTTCOMM_OK;
54d01ffb 163error:
ff4d74e6 164 free(defattr);
54d01ffb
DG
165 return ret;
166}
This page took 0.029164 seconds and 4 git commands to generate.