9bc82eac7a705e680a812e8757dce083c1caa2b3
2 * Copyright (C) 2013 - 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.
21 #include <common/common.h>
22 #include <common/sessiond-comm/sessiond-comm.h>
23 #include <common/uri.h>
24 #include <common/utils.h>
27 #include "jul-thread.h"
28 #include "lttng-sessiond.h"
31 * Note that there is not port here. It's set after this URI is parsed so we
32 * can let the user define a custom one. However, localhost is ALWAYS the
33 * default listening address.
35 static const char *default_reg_uri
= "tcp://localhost";
38 * Create and init socket from uri.
40 static struct lttcomm_sock
*init_tcp_socket(void)
43 struct lttng_uri
*uri
= NULL
;
44 struct lttcomm_sock
*sock
= NULL
;
47 * This should never fail since the URI is hardcoded and the port is set
48 * before this thread is launched.
50 ret
= uri_parse(default_reg_uri
, &uri
);
53 uri
->port
= jul_tcp_port
;
55 sock
= lttcomm_alloc_sock_from_uri(uri
);
58 ERR("[jul-thread] JUL allocating TCP socket");
62 ret
= lttcomm_create_sock(sock
);
67 ret
= sock
->ops
->bind(sock
);
72 ret
= sock
->ops
->listen(sock
, -1);
77 DBG("[jul-thread] Listening on TCP port %u and socket %d", jul_tcp_port
,
84 lttcomm_destroy_sock(sock
);
90 * Close and destroy the given TCP socket.
92 static void destroy_tcp_socket(struct lttcomm_sock
*sock
)
96 DBG3("[jul-thread] Destroy TCP socket on port %u", jul_tcp_port
);
98 /* This will return gracefully if fd is invalid. */
99 sock
->ops
->close(sock
);
100 lttcomm_destroy_sock(sock
);
104 * This thread manage application notify communication.
106 void *jul_thread_manage_registration(void *data
)
109 uint32_t revents
, nb_fd
;
110 struct lttng_poll_event events
;
111 struct lttcomm_sock
*reg_sock
;
113 DBG("[jul-thread] Manage JUL application registration.");
115 rcu_register_thread();
118 /* Create pollset with size 2, quit pipe and socket. */
119 ret
= sessiond_set_thread_pollset(&events
, 2);
121 goto error_poll_create
;
124 reg_sock
= init_tcp_socket();
126 goto error_tcp_socket
;
129 /* Add create valid TCP socket to poll set. */
130 ret
= lttng_poll_add(&events
, reg_sock
->fd
,
131 LPOLLIN
| LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
);
137 DBG3("[jul-thread] Manage JUL polling on %d fds",
138 LTTNG_POLL_GETNB(&events
));
140 /* Inifinite blocking call, waiting for transmission */
142 ret
= lttng_poll_wait(&events
, -1);
145 * Restart interrupted system call.
147 if (errno
== EINTR
) {
154 for (i
= 0; i
< nb_fd
; i
++) {
155 /* Fetch once the poll data */
156 revents
= LTTNG_POLL_GETEV(&events
, i
);
157 pollfd
= LTTNG_POLL_GETFD(&events
, i
);
159 /* Thread quit pipe has been closed. Killing thread. */
160 ret
= sessiond_check_thread_quit_pipe(pollfd
, revents
);
166 * Check first if this is a POLLERR since POLLIN is also included
167 * in an error value thus checking first.
169 if (revents
& (LPOLLERR
| LPOLLHUP
| LPOLLRDHUP
)) {
170 /* Removing from the poll set */
171 ret
= lttng_poll_del(&events
, pollfd
);
176 /* FIXME: Nullify the JUL socket for the associated ust app. */
177 } else if (revents
& (LPOLLIN
| LPOLLPRI
)) {
179 * FIXME: Handle JUL registration which must link an UST-app
180 * and this JUL socket.
183 ERR("Unknown poll events %u for sock %d", revents
, pollfd
);
191 destroy_tcp_socket(reg_sock
);
193 lttng_poll_clean(&events
);
195 DBG("[jul-thread] is cleaning up and stopping.");
197 rcu_thread_offline();
198 rcu_unregister_thread();
This page took 0.032908 seconds and 3 git commands to generate.