Introduce EXTRA_VERSION_PATCHES
[lttng-tools.git] / src / bin / lttng-sessiond / sessiond-config.c
1 /*
2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include "version.h"
19 #include "sessiond-config.h"
20 #include <assert.h>
21 #include "lttng-ust-ctl.h"
22 #include <common/defaults.h>
23 #include <limits.h>
24 #include <errno.h>
25 #include <ctype.h>
26 #include <common/error.h>
27 #include <common/utils.h>
28 #include <common/compat/getenv.h>
29
30 static
31 struct sessiond_config sessiond_config_build_defaults = {
32 .quiet = false,
33 .verbose = 0,
34 .verbose_consumer = 0,
35
36 .agent_tcp_port = { .begin = DEFAULT_AGENT_TCP_PORT_RANGE_BEGIN, .end = DEFAULT_AGENT_TCP_PORT_RANGE_END },
37 .app_socket_timeout = DEFAULT_APP_SOCKET_RW_TIMEOUT,
38
39 .no_kernel = false,
40 .background = false,
41 .daemonize = false,
42 .sig_parent = false,
43
44 .tracing_group_name.value = DEFAULT_TRACING_GROUP,
45 .kmod_probes_list.value = NULL,
46 .kmod_extra_probes_list.value = NULL,
47
48 .rundir.value = NULL,
49
50 .apps_unix_sock_path.value = NULL,
51 .client_unix_sock_path.value = NULL,
52 .wait_shm_path.value = NULL,
53 .health_unix_sock_path.value = NULL,
54 .lttng_ust_clock_plugin.value = NULL,
55 .pid_file_path.value = NULL,
56 .lock_file_path.value = NULL,
57 .agent_port_file_path.value = NULL,
58 .load_session_path.value = NULL,
59
60 .consumerd32_path.value = NULL,
61 .consumerd32_bin_path.value = NULL,
62 .consumerd32_lib_dir.value = NULL,
63 .consumerd32_err_unix_sock_path.value = NULL,
64 .consumerd32_cmd_unix_sock_path.value = NULL,
65
66 .consumerd64_path.value = NULL,
67 .consumerd64_bin_path.value = NULL,
68 .consumerd64_lib_dir.value = NULL,
69 .consumerd64_err_unix_sock_path.value = NULL,
70 .consumerd64_cmd_unix_sock_path.value = NULL,
71
72 .kconsumerd_path.value = NULL,
73 .kconsumerd_err_unix_sock_path.value = NULL,
74 .kconsumerd_cmd_unix_sock_path.value = NULL,
75 };
76
77 static
78 void config_string_fini(struct config_string *str)
79 {
80 config_string_set(str, NULL);
81 }
82
83 static
84 void config_string_set_static(struct config_string *config_str,
85 const char *value)
86 {
87 config_string_set(config_str, (char *) value);
88 config_str->should_free = false;
89 }
90
91 /* Only use for dynamically-allocated strings. */
92 LTTNG_HIDDEN
93 void config_string_set(struct config_string *config_str, char *value)
94 {
95 assert(config_str);
96 if (config_str->should_free) {
97 free(config_str->value);
98 config_str->should_free = false;
99 }
100
101 config_str->should_free = !!value;
102 config_str->value = value;
103 }
104
105 LTTNG_HIDDEN
106 int sessiond_config_apply_env_config(struct sessiond_config *config)
107 {
108 int ret = 0;
109 const char *env_value;
110
111 env_value = getenv(DEFAULT_APP_SOCKET_TIMEOUT_ENV);
112 if (env_value) {
113 char *endptr;
114 long int_val;
115
116 errno = 0;
117 int_val = strtoul(env_value, &endptr, 0);
118 if (errno != 0 || int_val > INT_MAX ||
119 (int_val < 0 && int_val != -1)) {
120 ERR("Invalid value \"%s\" used for \"%s\" environment variable",
121 env_value, DEFAULT_APP_SOCKET_TIMEOUT_ENV);
122 ret = -1;
123 goto end;
124 }
125
126 config->app_socket_timeout = int_val;
127 }
128
129 env_value = lttng_secure_getenv("LTTNG_CONSUMERD32_BIN");
130 if (env_value) {
131 config_string_set_static(&config->consumerd32_bin_path,
132 env_value);
133 }
134 env_value = lttng_secure_getenv("LTTNG_CONSUMERD64_BIN");
135 if (env_value) {
136 config_string_set_static(&config->consumerd64_bin_path,
137 env_value);
138 }
139
140 env_value = lttng_secure_getenv("LTTNG_CONSUMERD32_LIBDIR");
141 if (env_value) {
142 config_string_set_static(&config->consumerd32_lib_dir,
143 env_value);
144 }
145 env_value = lttng_secure_getenv("LTTNG_CONSUMERD64_LIBDIR");
146 if (env_value) {
147 config_string_set_static(&config->consumerd64_lib_dir,
148 env_value);
149 }
150
151 env_value = lttng_secure_getenv("LTTNG_UST_CLOCK_PLUGIN");
152 if (env_value) {
153 config_string_set_static(&config->lttng_ust_clock_plugin,
154 env_value);
155 }
156
157 env_value = lttng_secure_getenv(DEFAULT_LTTNG_KMOD_PROBES);
158 if (env_value) {
159 config_string_set_static(&config->kmod_probes_list,
160 env_value);
161 }
162
163 env_value = lttng_secure_getenv(DEFAULT_LTTNG_EXTRA_KMOD_PROBES);
164 if (env_value) {
165 config_string_set_static(&config->kmod_extra_probes_list,
166 env_value);
167 }
168 end:
169 return ret;
170 }
171
172 static
173 int config_set_paths_root(struct sessiond_config *config)
174 {
175 int ret = 0;
176
177 config_string_set(&config->rundir, strdup(DEFAULT_LTTNG_RUNDIR));
178 if (!config->rundir.value) {
179 ERR("Failed to set rundir");
180 ret = -1;
181 goto end;
182 }
183
184 config_string_set_static(&config->apps_unix_sock_path,
185 DEFAULT_GLOBAL_APPS_UNIX_SOCK);
186 config_string_set_static(&config->client_unix_sock_path,
187 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK);
188 config_string_set_static(&config->wait_shm_path,
189 DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH);
190 config_string_set_static(&config->health_unix_sock_path,
191 DEFAULT_GLOBAL_HEALTH_UNIX_SOCK);
192 end:
193 return ret;
194 }
195
196 static
197 int config_set_paths_non_root(struct sessiond_config *config)
198 {
199 int ret = 0;
200 const char *home_path = utils_get_home_dir();
201 char *str;
202
203 if (home_path == NULL) {
204 ERR("Can't get HOME directory for sockets creation.");
205 ret = -1;
206 goto end;
207 }
208
209 /*
210 * Create rundir from home path. This will create something like
211 * $HOME/.lttng
212 */
213 ret = asprintf(&str, DEFAULT_LTTNG_HOME_RUNDIR, home_path);
214 if (ret < 0) {
215 ERR("Failed to set rundir");
216 goto end;
217 }
218 config_string_set(&config->rundir, str);
219 str = NULL;
220
221 ret = asprintf(&str, DEFAULT_HOME_APPS_UNIX_SOCK, home_path);
222 if (ret < 0) {
223 ERR("Failed to set default home apps unix socket path");
224 goto end;
225 }
226 config_string_set(&config->apps_unix_sock_path, str);
227 str = NULL;
228
229 ret = asprintf(&str, DEFAULT_HOME_CLIENT_UNIX_SOCK, home_path);
230 if (ret < 0) {
231 ERR("Failed to set default home client unix socket path");
232 goto end;
233 }
234 config_string_set(&config->client_unix_sock_path, str);
235 str = NULL;
236
237 ret = asprintf(&str, DEFAULT_HOME_APPS_WAIT_SHM_PATH, getuid());
238 if (ret < 0) {
239 ERR("Failed to set default home apps wait shm path");
240 goto end;
241 }
242 config_string_set(&config->wait_shm_path, str);
243 str = NULL;
244
245 ret = asprintf(&str, DEFAULT_HOME_HEALTH_UNIX_SOCK, home_path);
246 if (ret < 0) {
247 ERR("Failed to set default home health UNIX socket path");
248 goto end;
249 }
250 config_string_set(&config->health_unix_sock_path, str);
251 str = NULL;
252
253 ret = 0;
254 end:
255 return ret;
256 }
257
258 LTTNG_HIDDEN
259 int sessiond_config_init(struct sessiond_config *config)
260 {
261 int ret;
262 bool is_root = (getuid() == 0);
263 char *str;
264
265 assert(config);
266 memcpy(config, &sessiond_config_build_defaults, sizeof(*config));
267
268 if (is_root) {
269 ret = config_set_paths_root(config);
270 } else {
271 ret = config_set_paths_non_root(config);
272 }
273 if (ret < 0) {
274 goto error;
275 }
276
277 /* 32 bits consumerd path setup */
278 ret = asprintf(&str, DEFAULT_USTCONSUMERD32_PATH,
279 config->rundir.value);
280 if (ret < 0) {
281 ERR("Failed to set 32-bit consumer path");
282 goto error;
283 }
284 config_string_set(&config->consumerd32_path, str);
285 str = NULL;
286
287 ret = asprintf(&str, DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH,
288 config->rundir.value);
289 if (ret < 0) {
290 ERR("Failed to set 32-bit consumer error socket path");
291 goto error;
292 }
293 config_string_set(&config->consumerd32_err_unix_sock_path, str);
294 str = NULL;
295
296 ret = asprintf(&str, DEFAULT_USTCONSUMERD32_CMD_SOCK_PATH,
297 config->rundir.value);
298 if (ret < 0) {
299 ERR("Failed to set 32-bit consumer command socket path");
300 goto error;
301 }
302 config_string_set(&config->consumerd32_cmd_unix_sock_path, str);
303 str = NULL;
304
305 /* 64 bits consumerd path setup */
306 ret = asprintf(&str, DEFAULT_USTCONSUMERD64_PATH,
307 config->rundir.value);
308 if (ret < 0) {
309 ERR("Failed to set 64-bit consumer path");
310 goto error;
311 }
312 config_string_set(&config->consumerd64_path, str);
313 str = NULL;
314
315 ret = asprintf(&str, DEFAULT_USTCONSUMERD64_ERR_SOCK_PATH,
316 config->rundir.value);
317 if (ret < 0) {
318 ERR("Failed to set 64-bit consumer error socket path");
319 goto error;
320 }
321 config_string_set(&config->consumerd64_err_unix_sock_path, str);
322 str = NULL;
323
324 ret = asprintf(&str, DEFAULT_USTCONSUMERD64_CMD_SOCK_PATH,
325 config->rundir.value);
326 if (ret < 0) {
327 ERR("Failed to set 64-bit consumer command socket path");
328 goto error;
329 }
330 config_string_set(&config->consumerd64_cmd_unix_sock_path, str);
331 str = NULL;
332
333 /* kconsumerd consumerd path setup */
334 ret = asprintf(&str, DEFAULT_KCONSUMERD_PATH,
335 config->rundir.value);
336 if (ret < 0) {
337 ERR("Failed to set kernel consumer path");
338 goto error;
339 }
340 config_string_set(&config->kconsumerd_path, str);
341 str = NULL;
342
343 ret = asprintf(&str, DEFAULT_KCONSUMERD_ERR_SOCK_PATH,
344 config->rundir.value);
345 if (ret < 0) {
346 ERR("Failed to set kernel consumer error socket path");
347 goto error;
348 }
349 config_string_set(&config->kconsumerd_err_unix_sock_path, str);
350 str = NULL;
351
352 ret = asprintf(&str, DEFAULT_KCONSUMERD_CMD_SOCK_PATH,
353 config->rundir.value);
354 if (ret < 0) {
355 ERR("Failed to set kernel consumer command socket path");
356 goto error;
357 }
358 config_string_set(&config->kconsumerd_cmd_unix_sock_path, str);
359 str = NULL;
360
361 ret = asprintf(&str, "%s/%s", config->rundir.value,
362 DEFAULT_LTTNG_SESSIOND_PIDFILE);
363 if (ret < 0) {
364 ERR("Failed to set PID file path");
365 goto error;
366 }
367 config_string_set(&config->pid_file_path, str);
368 str = NULL;
369
370 ret = asprintf(&str, "%s/%s", config->rundir.value,
371 DEFAULT_LTTNG_SESSIOND_LOCKFILE);
372 if (ret < 0) {
373 ERR("Failed to set lock file path");
374 goto error;
375 }
376 config_string_set(&config->lock_file_path, str);
377 str = NULL;
378
379 ret = asprintf(&str, "%s/%s", config->rundir.value,
380 DEFAULT_LTTNG_SESSIOND_AGENTPORT_FILE);
381 if (ret < 0) {
382 ERR("Failed to set agent port file path");
383 goto error;
384 }
385 config_string_set(&config->agent_port_file_path, str);
386 str = NULL;
387
388 /*
389 * Allow INSTALL_BIN_PATH to be used as a target path for the
390 * native architecture size consumer if CONFIG_CONSUMER*_PATH
391 * has not been defined.
392 */
393 #if (CAA_BITS_PER_LONG == 32)
394 config_string_set_static(&config->consumerd32_bin_path,
395 INSTALL_BIN_PATH "/" DEFAULT_CONSUMERD_FILE);
396 config_string_set_static(&config->consumerd32_lib_dir,
397 INSTALL_LIB_PATH);
398 #elif (CAA_BITS_PER_LONG == 64)
399 config_string_set_static(&config->consumerd64_bin_path,
400 INSTALL_BIN_PATH "/" DEFAULT_CONSUMERD_FILE);
401 config_string_set_static(&config->consumerd64_lib_dir,
402 INSTALL_LIB_PATH);
403 #else
404 #error "Unknown bitness"
405 #endif
406 ret = 0;
407 return ret;
408 error:
409 sessiond_config_fini(config);
410 return ret;
411 }
412
413 LTTNG_HIDDEN
414 void sessiond_config_fini(struct sessiond_config *config)
415 {
416 config_string_fini(&config->tracing_group_name);
417 config_string_fini(&config->kmod_probes_list);
418 config_string_fini(&config->kmod_extra_probes_list);
419 config_string_fini(&config->rundir);
420 config_string_fini(&config->apps_unix_sock_path);
421 config_string_fini(&config->client_unix_sock_path);
422 config_string_fini(&config->wait_shm_path);
423 config_string_fini(&config->health_unix_sock_path);
424 config_string_fini(&config->lttng_ust_clock_plugin);
425 config_string_fini(&config->pid_file_path);
426 config_string_fini(&config->lock_file_path);
427 config_string_fini(&config->load_session_path);
428 config_string_fini(&config->agent_port_file_path);
429 config_string_fini(&config->consumerd32_path);
430 config_string_fini(&config->consumerd32_bin_path);
431 config_string_fini(&config->consumerd32_lib_dir);
432 config_string_fini(&config->consumerd32_err_unix_sock_path);
433 config_string_fini(&config->consumerd32_cmd_unix_sock_path);
434 config_string_fini(&config->consumerd64_path);
435 config_string_fini(&config->consumerd64_bin_path);
436 config_string_fini(&config->consumerd64_lib_dir);
437 config_string_fini(&config->consumerd64_err_unix_sock_path);
438 config_string_fini(&config->consumerd64_cmd_unix_sock_path);
439 config_string_fini(&config->kconsumerd_path);
440 config_string_fini(&config->kconsumerd_err_unix_sock_path);
441 config_string_fini(&config->kconsumerd_cmd_unix_sock_path);
442 }
443
444 static
445 int resolve_path(struct config_string *path)
446 {
447 int ret = 0;
448 char *absolute_path;
449
450 if (!path->value || path->value[0] == '/') {
451 goto end;
452 }
453
454 absolute_path = utils_expand_path(path->value);
455 if (!absolute_path) {
456 ret = -1;
457 goto end;
458 }
459
460 config_string_set(path, absolute_path);
461 end:
462 return ret;
463 }
464
465 #define RESOLVE_CHECK(path_config_str) \
466 if (resolve_path(path_config_str)) \
467 return -1
468
469 LTTNG_HIDDEN
470 int sessiond_config_resolve_paths(struct sessiond_config *config)
471 {
472 RESOLVE_CHECK(&config->apps_unix_sock_path);
473 RESOLVE_CHECK(&config->client_unix_sock_path);
474 RESOLVE_CHECK(&config->wait_shm_path);
475 RESOLVE_CHECK(&config->health_unix_sock_path);
476 RESOLVE_CHECK(&config->lttng_ust_clock_plugin);
477 RESOLVE_CHECK(&config->pid_file_path);
478 RESOLVE_CHECK(&config->lock_file_path);
479 RESOLVE_CHECK(&config->load_session_path);
480 RESOLVE_CHECK(&config->agent_port_file_path);
481 RESOLVE_CHECK(&config->consumerd32_path);
482 RESOLVE_CHECK(&config->consumerd32_bin_path);
483 RESOLVE_CHECK(&config->consumerd32_lib_dir);
484 RESOLVE_CHECK(&config->consumerd32_err_unix_sock_path);
485 RESOLVE_CHECK(&config->consumerd32_cmd_unix_sock_path);
486 RESOLVE_CHECK(&config->consumerd64_path);
487 RESOLVE_CHECK(&config->consumerd64_bin_path);
488 RESOLVE_CHECK(&config->consumerd64_lib_dir);
489 RESOLVE_CHECK(&config->consumerd64_err_unix_sock_path);
490 RESOLVE_CHECK(&config->consumerd64_cmd_unix_sock_path);
491 RESOLVE_CHECK(&config->kconsumerd_path);
492 RESOLVE_CHECK(&config->kconsumerd_err_unix_sock_path);
493 RESOLVE_CHECK(&config->kconsumerd_cmd_unix_sock_path);
494 return 0;
495 }
496
497 LTTNG_HIDDEN
498 void sessiond_config_log(struct sessiond_config *config)
499 {
500 DBG_NO_LOC("[sessiond configuration]");
501 DBG_NO_LOC("\tversion %s", VERSION);
502 if (GIT_VERSION[0] != '\0') {
503 DBG_NO_LOC("\tgit version %s", GIT_VERSION);
504 }
505 if (EXTRA_VERSION_NAME[0] != '\0') {
506 DBG_NO_LOC("\textra version name %s", EXTRA_VERSION_NAME);
507 }
508 if (EXTRA_VERSION_DESCRIPTION[0] != '\0') {
509 DBG_NO_LOC("\textra version description:\n\t%s", EXTRA_VERSION_DESCRIPTION);
510 }
511 if (EXTRA_VERSION_PATCHES[0] != '\0') {
512 DBG_NO_LOC("\textra version patches:\n\t%s", EXTRA_VERSION_PATCHES);
513 }
514 DBG_NO_LOC("\tverbose: %i", config->verbose);
515 DBG_NO_LOC("\tverbose consumer: %i", config->verbose_consumer);
516 DBG_NO_LOC("\tquiet mode: %s", config->quiet ? "True" : "False");
517 if (config->agent_tcp_port.begin == config->agent_tcp_port.end) {
518 DBG_NO_LOC("\tagent_tcp_port: %i", config->agent_tcp_port.begin);
519 } else {
520 DBG_NO_LOC("\tagent_tcp_port: [%i, %i]",
521 config->agent_tcp_port.begin,
522 config->agent_tcp_port.end);
523 }
524 DBG_NO_LOC("\tapplication socket timeout: %i", config->app_socket_timeout);
525 DBG_NO_LOC("\tno-kernel: %s", config->no_kernel ? "True" : "False");
526 DBG_NO_LOC("\tbackground: %s", config->background ? "True" : "False");
527 DBG_NO_LOC("\tdaemonize: %s", config->daemonize ? "True" : "False");
528 DBG_NO_LOC("\tsignal parent on start: %s", config->sig_parent ? "True" : "False");
529 DBG_NO_LOC("\ttracing group name: %s", config->tracing_group_name.value ? : "Unknown");
530 DBG_NO_LOC("\tkmod_probe_list: %s", config->kmod_probes_list.value ? : "None");
531 DBG_NO_LOC("\tkmod_extra_probe_list: %s", config->kmod_extra_probes_list.value ? : "None");
532 DBG_NO_LOC("\trundir: %s", config->rundir.value ? : "Unknown");
533 DBG_NO_LOC("\tapplication socket path: %s", config->apps_unix_sock_path.value ? : "Unknown");
534 DBG_NO_LOC("\tclient socket path: %s", config->client_unix_sock_path.value ? : "Unknown");
535 DBG_NO_LOC("\twait shm path: %s", config->wait_shm_path.value ? : "Unknown");
536 DBG_NO_LOC("\thealth socket path: %s", config->health_unix_sock_path.value ? : "Unknown");
537 DBG_NO_LOC("\tLTTNG_UST_CLOCK_PLUGIN: %s", config->lttng_ust_clock_plugin.value ? : "None");
538 DBG_NO_LOC("\tpid file path: %s", config->pid_file_path.value ? : "Unknown");
539 DBG_NO_LOC("\tlock file path: %s", config->lock_file_path.value ? : "Unknown");
540 DBG_NO_LOC("\tsession load path: %s", config->load_session_path.value ? : "None");
541 DBG_NO_LOC("\tagent port file path: %s", config->agent_port_file_path.value ? : "Unknown");
542 DBG_NO_LOC("\tconsumerd32 path: %s", config->consumerd32_path.value ? : "Unknown");
543 DBG_NO_LOC("\tconsumerd32 bin path: %s", config->consumerd32_bin_path.value ? : "Unknown");
544 DBG_NO_LOC("\tconsumerd32 lib dir: %s", config->consumerd32_lib_dir.value ? : "Unknown");
545 DBG_NO_LOC("\tconsumerd32 err unix sock path:%s", config->consumerd32_err_unix_sock_path.value ? : "Unknown");
546 DBG_NO_LOC("\tconsumerd32 cmd unix sock path:%s", config->consumerd32_cmd_unix_sock_path.value ? : "Unknown");
547 DBG_NO_LOC("\tconsumerd64 path: %s", config->consumerd64_path.value ? : "Unknown");
548 DBG_NO_LOC("\tconsumerd64 bin path: %s", config->consumerd64_bin_path.value ? : "Unknown");
549 DBG_NO_LOC("\tconsumerd64 lib dir: %s", config->consumerd64_lib_dir.value ? : "Unknown");
550 DBG_NO_LOC("\tconsumerd64 err unix sock path:%s", config->consumerd64_err_unix_sock_path.value ? : "Unknown");
551 DBG_NO_LOC("\tconsumerd64 cmd unix sock path:%s", config->consumerd64_cmd_unix_sock_path.value ? : "Unknown");
552 DBG_NO_LOC("\tkconsumerd path: %s", config->kconsumerd_path.value ? : "Unknown");
553 DBG_NO_LOC("\tkconsumerd err unix sock path: %s", config->kconsumerd_err_unix_sock_path.value ? : "Unknown");
554 DBG_NO_LOC("\tkconsumerd cmd unix sock path: %s", config->kconsumerd_cmd_unix_sock_path.value ? : "Unknown");
555 }
This page took 0.041241 seconds and 5 git commands to generate.