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