2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
9 #include "sessiond-config.h"
10 #include "lttng-ust-ctl.h"
11 #include <common/defaults.h>
14 #include <common/error.h>
15 #include <common/utils.h>
16 #include <common/compat/errno.h>
17 #include <common/compat/getenv.h>
20 struct sessiond_config sessiond_config_build_defaults
= {
22 .verbose_consumer
= 0,
23 .agent_tcp_port
= { .begin
= DEFAULT_AGENT_TCP_PORT_RANGE_BEGIN
, .end
= DEFAULT_AGENT_TCP_PORT_RANGE_END
},
25 .event_notifier_buffer_size_kernel
= DEFAULT_EVENT_NOTIFIER_ERROR_COUNT_MAP_SIZE
,
26 .event_notifier_buffer_size_userspace
= DEFAULT_EVENT_NOTIFIER_ERROR_COUNT_MAP_SIZE
,
27 .app_socket_timeout
= DEFAULT_APP_SOCKET_RW_TIMEOUT
,
37 .tracing_group_name
= { (char *) DEFAULT_TRACING_GROUP
},
38 .kmod_probes_list
= { nullptr },
39 .kmod_extra_probes_list
= { nullptr },
41 .rundir
= { nullptr },
43 .apps_unix_sock_path
= { nullptr },
44 .client_unix_sock_path
= { nullptr },
45 .wait_shm_path
= { nullptr },
46 .health_unix_sock_path
= { nullptr },
47 .lttng_ust_clock_plugin
= { nullptr },
48 .pid_file_path
= { nullptr },
49 .lock_file_path
= { nullptr },
50 .load_session_path
= { nullptr },
51 .agent_port_file_path
= { nullptr },
53 .consumerd32_path
= { nullptr },
54 .consumerd32_bin_path
= { nullptr },
55 .consumerd32_lib_dir
= { nullptr },
56 .consumerd32_err_unix_sock_path
= { nullptr },
57 .consumerd32_cmd_unix_sock_path
= { nullptr },
59 .consumerd64_path
= { nullptr },
60 .consumerd64_bin_path
= { nullptr },
61 .consumerd64_lib_dir
= { nullptr },
62 .consumerd64_err_unix_sock_path
= { nullptr },
63 .consumerd64_cmd_unix_sock_path
= { nullptr },
65 .kconsumerd_path
= { nullptr },
66 .kconsumerd_err_unix_sock_path
= { nullptr },
67 .kconsumerd_cmd_unix_sock_path
= { nullptr },
71 void config_string_fini(struct config_string
*str
)
73 config_string_set(str
, NULL
);
77 void config_string_set_static(struct config_string
*config_str
,
80 config_string_set(config_str
, (char *) value
);
81 config_str
->should_free
= false;
84 /* Only use for dynamically-allocated strings. */
85 void config_string_set(struct config_string
*config_str
, char *value
)
87 LTTNG_ASSERT(config_str
);
88 if (config_str
->should_free
) {
89 free(config_str
->value
);
90 config_str
->should_free
= false;
93 config_str
->should_free
= !!value
;
94 config_str
->value
= value
;
97 int sessiond_config_apply_env_config(struct sessiond_config
*config
)
100 const char *env_value
;
102 env_value
= getenv(DEFAULT_APP_SOCKET_TIMEOUT_ENV
);
108 int_val
= strtoul(env_value
, &endptr
, 0);
109 if (errno
!= 0 || int_val
> INT_MAX
||
110 (int_val
< 0 && int_val
!= -1)) {
111 ERR("Invalid value \"%s\" used for \"%s\" environment variable",
112 env_value
, DEFAULT_APP_SOCKET_TIMEOUT_ENV
);
117 config
->app_socket_timeout
= int_val
;
120 env_value
= lttng_secure_getenv("LTTNG_CONSUMERD32_BIN");
122 config_string_set_static(&config
->consumerd32_bin_path
,
125 env_value
= lttng_secure_getenv("LTTNG_CONSUMERD64_BIN");
127 config_string_set_static(&config
->consumerd64_bin_path
,
131 env_value
= lttng_secure_getenv("LTTNG_CONSUMERD32_LIBDIR");
133 config_string_set_static(&config
->consumerd32_lib_dir
,
136 env_value
= lttng_secure_getenv("LTTNG_CONSUMERD64_LIBDIR");
138 config_string_set_static(&config
->consumerd64_lib_dir
,
142 env_value
= lttng_secure_getenv("LTTNG_UST_CLOCK_PLUGIN");
144 config_string_set_static(&config
->lttng_ust_clock_plugin
,
148 env_value
= lttng_secure_getenv(DEFAULT_LTTNG_KMOD_PROBES
);
150 config_string_set_static(&config
->kmod_probes_list
,
154 env_value
= lttng_secure_getenv(DEFAULT_LTTNG_EXTRA_KMOD_PROBES
);
156 config_string_set_static(&config
->kmod_extra_probes_list
,
164 int config_set_paths_root(struct sessiond_config
*config
)
168 config_string_set(&config
->rundir
, strdup(DEFAULT_LTTNG_RUNDIR
));
169 if (!config
->rundir
.value
) {
170 ERR("Failed to set rundir");
175 config_string_set_static(&config
->apps_unix_sock_path
,
176 DEFAULT_GLOBAL_APPS_UNIX_SOCK
);
177 config_string_set_static(&config
->client_unix_sock_path
,
178 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
);
179 config_string_set_static(&config
->wait_shm_path
,
180 DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH
);
181 config_string_set_static(&config
->health_unix_sock_path
,
182 DEFAULT_GLOBAL_HEALTH_UNIX_SOCK
);
188 int config_set_paths_non_root(struct sessiond_config
*config
)
191 const char *home_path
= utils_get_home_dir();
194 if (home_path
== NULL
) {
195 ERR("Can't get HOME directory for sockets creation.");
201 * Create rundir from home path. This will create something like
204 ret
= asprintf(&str
, DEFAULT_LTTNG_HOME_RUNDIR
, home_path
);
206 ERR("Failed to set rundir");
209 config_string_set(&config
->rundir
, str
);
212 ret
= asprintf(&str
, DEFAULT_HOME_APPS_UNIX_SOCK
, home_path
);
214 ERR("Failed to set default home apps unix socket path");
217 config_string_set(&config
->apps_unix_sock_path
, str
);
220 ret
= asprintf(&str
, DEFAULT_HOME_CLIENT_UNIX_SOCK
, home_path
);
222 ERR("Failed to set default home client unix socket path");
225 config_string_set(&config
->client_unix_sock_path
, str
);
228 ret
= asprintf(&str
, DEFAULT_HOME_APPS_WAIT_SHM_PATH
, getuid());
230 ERR("Failed to set default home apps wait shm path");
233 config_string_set(&config
->wait_shm_path
, str
);
236 ret
= asprintf(&str
, DEFAULT_HOME_HEALTH_UNIX_SOCK
, home_path
);
238 ERR("Failed to set default home health UNIX socket path");
241 config_string_set(&config
->health_unix_sock_path
, str
);
249 int sessiond_config_init(struct sessiond_config
*config
)
252 bool is_root
= (getuid() == 0);
255 LTTNG_ASSERT(config
);
256 memcpy(config
, &sessiond_config_build_defaults
, sizeof(*config
));
259 ret
= config_set_paths_root(config
);
261 ret
= config_set_paths_non_root(config
);
267 /* 32 bits consumerd path setup */
268 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD32_PATH
,
269 config
->rundir
.value
);
271 ERR("Failed to set 32-bit consumer path");
274 config_string_set(&config
->consumerd32_path
, str
);
277 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH
,
278 config
->rundir
.value
);
280 ERR("Failed to set 32-bit consumer error socket path");
283 config_string_set(&config
->consumerd32_err_unix_sock_path
, str
);
286 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD32_CMD_SOCK_PATH
,
287 config
->rundir
.value
);
289 ERR("Failed to set 32-bit consumer command socket path");
292 config_string_set(&config
->consumerd32_cmd_unix_sock_path
, str
);
295 /* 64 bits consumerd path setup */
296 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD64_PATH
,
297 config
->rundir
.value
);
299 ERR("Failed to set 64-bit consumer path");
302 config_string_set(&config
->consumerd64_path
, str
);
305 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD64_ERR_SOCK_PATH
,
306 config
->rundir
.value
);
308 ERR("Failed to set 64-bit consumer error socket path");
311 config_string_set(&config
->consumerd64_err_unix_sock_path
, str
);
314 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD64_CMD_SOCK_PATH
,
315 config
->rundir
.value
);
317 ERR("Failed to set 64-bit consumer command socket path");
320 config_string_set(&config
->consumerd64_cmd_unix_sock_path
, str
);
323 /* kconsumerd consumerd path setup */
324 ret
= asprintf(&str
, DEFAULT_KCONSUMERD_PATH
,
325 config
->rundir
.value
);
327 ERR("Failed to set kernel consumer path");
330 config_string_set(&config
->kconsumerd_path
, str
);
333 ret
= asprintf(&str
, DEFAULT_KCONSUMERD_ERR_SOCK_PATH
,
334 config
->rundir
.value
);
336 ERR("Failed to set kernel consumer error socket path");
339 config_string_set(&config
->kconsumerd_err_unix_sock_path
, str
);
342 ret
= asprintf(&str
, DEFAULT_KCONSUMERD_CMD_SOCK_PATH
,
343 config
->rundir
.value
);
345 ERR("Failed to set kernel consumer command socket path");
348 config_string_set(&config
->kconsumerd_cmd_unix_sock_path
, str
);
351 ret
= asprintf(&str
, "%s/%s", config
->rundir
.value
,
352 DEFAULT_LTTNG_SESSIOND_PIDFILE
);
354 ERR("Failed to set PID file path");
357 config_string_set(&config
->pid_file_path
, str
);
360 ret
= asprintf(&str
, "%s/%s", config
->rundir
.value
,
361 DEFAULT_LTTNG_SESSIOND_LOCKFILE
);
363 ERR("Failed to set lock file path");
366 config_string_set(&config
->lock_file_path
, str
);
369 ret
= asprintf(&str
, "%s/%s", config
->rundir
.value
,
370 DEFAULT_LTTNG_SESSIOND_AGENTPORT_FILE
);
372 ERR("Failed to set agent port file path");
375 config_string_set(&config
->agent_port_file_path
, str
);
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.
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
,
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
,
394 #error "Unknown bitness"
399 sessiond_config_fini(config
);
403 void sessiond_config_fini(struct sessiond_config
*config
)
405 config_string_fini(&config
->tracing_group_name
);
406 config_string_fini(&config
->kmod_probes_list
);
407 config_string_fini(&config
->kmod_extra_probes_list
);
408 config_string_fini(&config
->rundir
);
409 config_string_fini(&config
->apps_unix_sock_path
);
410 config_string_fini(&config
->client_unix_sock_path
);
411 config_string_fini(&config
->wait_shm_path
);
412 config_string_fini(&config
->health_unix_sock_path
);
413 config_string_fini(&config
->lttng_ust_clock_plugin
);
414 config_string_fini(&config
->pid_file_path
);
415 config_string_fini(&config
->lock_file_path
);
416 config_string_fini(&config
->load_session_path
);
417 config_string_fini(&config
->agent_port_file_path
);
418 config_string_fini(&config
->consumerd32_path
);
419 config_string_fini(&config
->consumerd32_bin_path
);
420 config_string_fini(&config
->consumerd32_lib_dir
);
421 config_string_fini(&config
->consumerd32_err_unix_sock_path
);
422 config_string_fini(&config
->consumerd32_cmd_unix_sock_path
);
423 config_string_fini(&config
->consumerd64_path
);
424 config_string_fini(&config
->consumerd64_bin_path
);
425 config_string_fini(&config
->consumerd64_lib_dir
);
426 config_string_fini(&config
->consumerd64_err_unix_sock_path
);
427 config_string_fini(&config
->consumerd64_cmd_unix_sock_path
);
428 config_string_fini(&config
->kconsumerd_path
);
429 config_string_fini(&config
->kconsumerd_err_unix_sock_path
);
430 config_string_fini(&config
->kconsumerd_cmd_unix_sock_path
);
434 int resolve_path(struct config_string
*path
)
439 if (!path
->value
|| path
->value
[0] == '/') {
443 absolute_path
= utils_expand_path(path
->value
);
444 if (!absolute_path
) {
449 config_string_set(path
, absolute_path
);
454 #define RESOLVE_CHECK(path_config_str) \
455 if (resolve_path(path_config_str)) \
458 int sessiond_config_resolve_paths(struct sessiond_config
*config
)
460 RESOLVE_CHECK(&config
->apps_unix_sock_path
);
461 RESOLVE_CHECK(&config
->client_unix_sock_path
);
462 RESOLVE_CHECK(&config
->wait_shm_path
);
463 RESOLVE_CHECK(&config
->health_unix_sock_path
);
464 RESOLVE_CHECK(&config
->lttng_ust_clock_plugin
);
465 RESOLVE_CHECK(&config
->pid_file_path
);
466 RESOLVE_CHECK(&config
->lock_file_path
);
467 RESOLVE_CHECK(&config
->load_session_path
);
468 RESOLVE_CHECK(&config
->agent_port_file_path
);
469 RESOLVE_CHECK(&config
->consumerd32_path
);
470 RESOLVE_CHECK(&config
->consumerd32_bin_path
);
471 RESOLVE_CHECK(&config
->consumerd32_lib_dir
);
472 RESOLVE_CHECK(&config
->consumerd32_err_unix_sock_path
);
473 RESOLVE_CHECK(&config
->consumerd32_cmd_unix_sock_path
);
474 RESOLVE_CHECK(&config
->consumerd64_path
);
475 RESOLVE_CHECK(&config
->consumerd64_bin_path
);
476 RESOLVE_CHECK(&config
->consumerd64_lib_dir
);
477 RESOLVE_CHECK(&config
->consumerd64_err_unix_sock_path
);
478 RESOLVE_CHECK(&config
->consumerd64_cmd_unix_sock_path
);
479 RESOLVE_CHECK(&config
->kconsumerd_path
);
480 RESOLVE_CHECK(&config
->kconsumerd_err_unix_sock_path
);
481 RESOLVE_CHECK(&config
->kconsumerd_cmd_unix_sock_path
);
485 void sessiond_config_log(struct sessiond_config
*config
)
487 DBG_NO_LOC("[sessiond configuration]");
488 DBG_NO_LOC("\tversion %s", VERSION
);
489 if (GIT_VERSION
[0] != '\0') {
490 DBG_NO_LOC("\tgit version %s", GIT_VERSION
);
492 if (EXTRA_VERSION_NAME
[0] != '\0') {
493 DBG_NO_LOC("\textra version name %s", EXTRA_VERSION_NAME
);
495 if (EXTRA_VERSION_DESCRIPTION
[0] != '\0') {
496 DBG_NO_LOC("\textra version description:\n\t%s", EXTRA_VERSION_DESCRIPTION
);
498 if (EXTRA_VERSION_PATCHES
[0] != '\0') {
499 DBG_NO_LOC("\textra version patches:\n\t%s", EXTRA_VERSION_PATCHES
);
501 DBG_NO_LOC("\tverbose: %i", config
->verbose
);
502 DBG_NO_LOC("\tverbose consumer: %i", config
->verbose_consumer
);
503 DBG_NO_LOC("\tquiet mode: %s", config
->quiet
? "True" : "False");
504 if (config
->agent_tcp_port
.begin
== config
->agent_tcp_port
.end
) {
505 DBG_NO_LOC("\tagent_tcp_port: %i", config
->agent_tcp_port
.begin
);
507 DBG_NO_LOC("\tagent_tcp_port: [%i, %i]",
508 config
->agent_tcp_port
.begin
,
509 config
->agent_tcp_port
.end
);
511 DBG_NO_LOC("\tapplication socket timeout: %i", config
->app_socket_timeout
);
512 DBG_NO_LOC("\tno-kernel: %s", config
->no_kernel
? "True" : "False");
513 DBG_NO_LOC("\tbackground: %s", config
->background
? "True" : "False");
514 DBG_NO_LOC("\tdaemonize: %s", config
->daemonize
? "True" : "False");
515 DBG_NO_LOC("\tsignal parent on start: %s", config
->sig_parent
? "True" : "False");
516 DBG_NO_LOC("\ttracing group name: %s", config
->tracing_group_name
.value
? : "Unknown");
517 DBG_NO_LOC("\tkmod_probe_list: %s", config
->kmod_probes_list
.value
? : "None");
518 DBG_NO_LOC("\tkmod_extra_probe_list: %s", config
->kmod_extra_probes_list
.value
? : "None");
519 DBG_NO_LOC("\trundir: %s", config
->rundir
.value
? : "Unknown");
520 DBG_NO_LOC("\tapplication socket path: %s", config
->apps_unix_sock_path
.value
? : "Unknown");
521 DBG_NO_LOC("\tclient socket path: %s", config
->client_unix_sock_path
.value
? : "Unknown");
522 DBG_NO_LOC("\twait shm path: %s", config
->wait_shm_path
.value
? : "Unknown");
523 DBG_NO_LOC("\thealth socket path: %s", config
->health_unix_sock_path
.value
? : "Unknown");
524 DBG_NO_LOC("\tLTTNG_UST_CLOCK_PLUGIN: %s", config
->lttng_ust_clock_plugin
.value
? : "None");
525 DBG_NO_LOC("\tpid file path: %s", config
->pid_file_path
.value
? : "Unknown");
526 DBG_NO_LOC("\tlock file path: %s", config
->lock_file_path
.value
? : "Unknown");
527 DBG_NO_LOC("\tsession load path: %s", config
->load_session_path
.value
? : "None");
528 DBG_NO_LOC("\tagent port file path: %s", config
->agent_port_file_path
.value
? : "Unknown");
529 DBG_NO_LOC("\tconsumerd32 path: %s", config
->consumerd32_path
.value
? : "Unknown");
530 DBG_NO_LOC("\tconsumerd32 bin path: %s", config
->consumerd32_bin_path
.value
? : "Unknown");
531 DBG_NO_LOC("\tconsumerd32 lib dir: %s", config
->consumerd32_lib_dir
.value
? : "Unknown");
532 DBG_NO_LOC("\tconsumerd32 err unix sock path:%s", config
->consumerd32_err_unix_sock_path
.value
? : "Unknown");
533 DBG_NO_LOC("\tconsumerd32 cmd unix sock path:%s", config
->consumerd32_cmd_unix_sock_path
.value
? : "Unknown");
534 DBG_NO_LOC("\tconsumerd64 path: %s", config
->consumerd64_path
.value
? : "Unknown");
535 DBG_NO_LOC("\tconsumerd64 bin path: %s", config
->consumerd64_bin_path
.value
? : "Unknown");
536 DBG_NO_LOC("\tconsumerd64 lib dir: %s", config
->consumerd64_lib_dir
.value
? : "Unknown");
537 DBG_NO_LOC("\tconsumerd64 err unix sock path:%s", config
->consumerd64_err_unix_sock_path
.value
? : "Unknown");
538 DBG_NO_LOC("\tconsumerd64 cmd unix sock path:%s", config
->consumerd64_cmd_unix_sock_path
.value
? : "Unknown");
539 DBG_NO_LOC("\tkconsumerd path: %s", config
->kconsumerd_path
.value
? : "Unknown");
540 DBG_NO_LOC("\tkconsumerd err unix sock path: %s", config
->kconsumerd_err_unix_sock_path
.value
? : "Unknown");
541 DBG_NO_LOC("\tkconsumerd cmd unix sock path: %s", config
->kconsumerd_cmd_unix_sock_path
.value
? : "Unknown");