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 int sock
, struct ltt_kernel_channel
*channel
, uid_t uid
, gid_t gid
)
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
);
45 lkm
.cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
46 lkm
.u
.channel
.channel_key
= channel
->fd
;
47 lkm
.u
.channel
.max_sb_size
= channel
->channel
->attr
.subbuf_size
;
48 lkm
.u
.channel
.mmap_len
= 0; /* for kernel */
49 DBG("Sending channel %d to consumer", lkm
.u
.channel
.channel_key
);
50 ret
= lttcomm_send_unix_sock(sock
, &lkm
, sizeof(lkm
));
52 PERROR("send consumer channel");
57 cds_list_for_each_entry(stream
, &channel
->stream_list
.head
, list
) {
61 /* Reset consumer message structure */
62 memset(&lkm
, 0, sizeof(lkm
));
63 lkm
.cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
64 lkm
.u
.stream
.channel_key
= channel
->fd
;
65 lkm
.u
.stream
.stream_key
= stream
->fd
;
66 lkm
.u
.stream
.state
= stream
->state
;
67 lkm
.u
.stream
.output
= channel
->channel
->attr
.output
;
68 lkm
.u
.stream
.mmap_len
= 0; /* for kernel */
69 lkm
.u
.stream
.uid
= uid
;
70 lkm
.u
.stream
.gid
= gid
;
71 strncpy(lkm
.u
.stream
.path_name
, stream
->pathname
, PATH_MAX
- 1);
72 lkm
.u
.stream
.path_name
[PATH_MAX
- 1] = '\0';
75 DBG("Sending stream %d to consumer", lkm
.u
.stream
.stream_key
);
76 ret
= lttcomm_send_unix_sock(sock
, &lkm
, sizeof(lkm
));
78 PERROR("send consumer stream");
81 ret
= lttcomm_send_fds_unix_sock(sock
, &stream
->fd
, 1);
83 PERROR("send consumer stream ancillary data");
88 DBG("consumer channel streams sent");
97 * Send all stream fds of the kernel session to the consumer.
99 int kernel_consumer_send_session(struct consumer_data
*consumer_data
,
100 struct ltt_kernel_session
*session
)
103 struct ltt_kernel_channel
*chan
;
104 struct lttcomm_consumer_msg lkm
;
105 int sock
= session
->consumer_fd
;
107 DBG("Sending metadata stream fd");
109 /* Extra protection. It's NOT supposed to be set to -1 at this point */
110 if (session
->consumer_fd
< 0) {
111 session
->consumer_fd
= consumer_data
->cmd_sock
;
114 if (session
->metadata_stream_fd
>= 0) {
115 /* Send metadata channel fd */
116 lkm
.cmd_type
= LTTNG_CONSUMER_ADD_CHANNEL
;
117 lkm
.u
.channel
.channel_key
= session
->metadata
->fd
;
118 lkm
.u
.channel
.max_sb_size
= session
->metadata
->conf
->attr
.subbuf_size
;
119 lkm
.u
.channel
.mmap_len
= 0; /* for kernel */
120 DBG("Sending metadata channel %d to consumer", lkm
.u
.channel
.channel_key
);
121 ret
= lttcomm_send_unix_sock(sock
, &lkm
, sizeof(lkm
));
123 PERROR("send consumer channel");
127 /* Send metadata stream fd */
128 lkm
.cmd_type
= LTTNG_CONSUMER_ADD_STREAM
;
129 lkm
.u
.stream
.channel_key
= session
->metadata
->fd
;
130 lkm
.u
.stream
.stream_key
= session
->metadata_stream_fd
;
131 lkm
.u
.stream
.state
= LTTNG_CONSUMER_ACTIVE_STREAM
;
132 lkm
.u
.stream
.output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
133 lkm
.u
.stream
.mmap_len
= 0; /* for kernel */
134 lkm
.u
.stream
.uid
= session
->uid
;
135 lkm
.u
.stream
.gid
= session
->gid
;
136 strncpy(lkm
.u
.stream
.path_name
, session
->metadata
->pathname
,
138 lkm
.u
.stream
.path_name
[PATH_MAX
- 1] = '\0';
140 DBG("Sending metadata stream %d to consumer", lkm
.u
.stream
.stream_key
);
141 ret
= lttcomm_send_unix_sock(sock
, &lkm
, sizeof(lkm
));
143 PERROR("send consumer stream");
146 ret
= lttcomm_send_fds_unix_sock(sock
, &session
->metadata_stream_fd
, 1);
148 PERROR("send consumer stream");
153 cds_list_for_each_entry(chan
, &session
->channel_list
.head
, list
) {
154 ret
= kernel_consumer_send_channel_stream(consumer_data
, sock
, chan
,
155 session
->uid
, session
->gid
);
161 DBG("consumer fds (metadata and channel streams) sent");