2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
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.
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
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.
25 #include <common/common.h>
26 #include <common/defaults.h>
27 #include <common/sessiond-comm/sessiond-comm.h>
29 #include "kernel-consumer.h"
32 * Send all stream fds of kernel channel to the consumer.
34 int kernel_consumer_send_channel_stream(struct consumer_data
*consumer_data
,
35 struct ltt_kernel_channel
*channel
, uid_t uid
, gid_t gid
)
37 int ret
, count
= 0, consumer_sock
;
38 struct ltt_kernel_stream
*stream
;
39 struct lttcomm_consumer_msg lkm
;
41 DBG("Sending streams of channel %s to kernel consumer",
42 channel
->channel
->name
);
44 consumer_sock
= consumer_data
->cmd_sock
;
47 lkm
.cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
48 lkm
.u
.channel
.channel_key
= channel
->fd
;
49 lkm
.u
.channel
.max_sb_size
= channel
->channel
->attr
.subbuf_size
;
50 lkm
.u
.channel
.mmap_len
= 0; /* for kernel */
51 DBG("Sending channel %d to consumer", lkm
.u
.channel
.channel_key
);
52 ret
= lttcomm_send_unix_sock(consumer_sock
, &lkm
, sizeof(lkm
));
54 PERROR("send consumer channel");
59 cds_list_for_each_entry(stream
, &channel
->stream_list
.head
, list
) {
63 /* Reset consumer message structure */
64 memset(&lkm
, 0, sizeof(lkm
));
65 lkm
.cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
66 lkm
.u
.stream
.channel_key
= channel
->fd
;
67 lkm
.u
.stream
.stream_key
= stream
->fd
;
68 lkm
.u
.stream
.state
= stream
->state
;
69 lkm
.u
.stream
.output
= channel
->channel
->attr
.output
;
70 lkm
.u
.stream
.mmap_len
= 0; /* for kernel */
71 lkm
.u
.stream
.uid
= uid
;
72 lkm
.u
.stream
.gid
= gid
;
73 strncpy(lkm
.u
.stream
.path_name
, stream
->pathname
, PATH_MAX
- 1);
74 lkm
.u
.stream
.path_name
[PATH_MAX
- 1] = '\0';
77 DBG("Sending stream %d to consumer", lkm
.u
.stream
.stream_key
);
78 ret
= lttcomm_send_unix_sock(consumer_sock
, &lkm
, sizeof(lkm
));
80 PERROR("send consumer stream");
83 ret
= lttcomm_send_fds_unix_sock(consumer_sock
, &stream
->fd
, 1);
85 PERROR("send consumer stream ancillary data");
90 DBG("consumer channel streams sent");
99 * Send all stream fds of the kernel session to the consumer.
101 int kernel_consumer_send_session(struct consumer_data
*consumer_data
,
102 struct ltt_kernel_session
*session
)
105 struct ltt_kernel_channel
*chan
;
106 struct lttcomm_consumer_msg lkm
;
107 int sock
= session
->consumer_fd
;
109 DBG("Sending metadata stream fd");
111 /* Extra protection. It's NOT supposed to be set to -1 at this point */
112 if (session
->consumer_fd
< 0) {
113 session
->consumer_fd
= consumer_data
->cmd_sock
;
116 if (session
->metadata_stream_fd
>= 0) {
117 /* Send metadata channel fd */
118 lkm
.cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
119 lkm
.u
.channel
.channel_key
= session
->metadata
->fd
;
120 lkm
.u
.channel
.max_sb_size
= session
->metadata
->conf
->attr
.subbuf_size
;
121 lkm
.u
.channel
.mmap_len
= 0; /* for kernel */
122 DBG("Sending metadata channel %d to consumer", lkm
.u
.channel
.channel_key
);
123 ret
= lttcomm_send_unix_sock(sock
, &lkm
, sizeof(lkm
));
125 PERROR("send consumer channel");
129 /* Send metadata stream fd */
130 lkm
.cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
131 lkm
.u
.stream
.channel_key
= session
->metadata
->fd
;
132 lkm
.u
.stream
.stream_key
= session
->metadata_stream_fd
;
133 lkm
.u
.stream
.state
= LTTNG_CONSUMER_ACTIVE_STREAM
;
134 lkm
.u
.stream
.output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
135 lkm
.u
.stream
.mmap_len
= 0; /* for kernel */
136 lkm
.u
.stream
.uid
= session
->uid
;
137 lkm
.u
.stream
.gid
= session
->gid
;
138 strncpy(lkm
.u
.stream
.path_name
, session
->metadata
->pathname
,
140 lkm
.u
.stream
.path_name
[PATH_MAX
- 1] = '\0';
142 DBG("Sending metadata stream %d to consumer", lkm
.u
.stream
.stream_key
);
143 ret
= lttcomm_send_unix_sock(sock
, &lkm
, sizeof(lkm
));
145 PERROR("send consumer stream");
148 ret
= lttcomm_send_fds_unix_sock(sock
, &session
->metadata_stream_fd
, 1);
150 PERROR("send consumer stream");
155 cds_list_for_each_entry(chan
, &session
->channel_list
.head
, list
) {
156 ret
= kernel_consumer_send_channel_stream(consumer_data
, chan
,
157 session
->uid
, session
->gid
);
163 DBG("consumer fds (metadata and channel streams) sent");