2 * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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.
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.
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.
18 #include "sessiond-config.h"
20 #include "lttng-ust-ctl.h"
21 #include <common/defaults.h>
25 #include <common/error.h>
26 #include <common/utils.h>
27 #include <common/compat/getenv.h>
30 struct sessiond_config sessiond_config_build_defaults
= {
33 .verbose_consumer
= 0,
35 .agent_tcp_port
= DEFAULT_AGENT_TCP_PORT
,
36 .app_socket_timeout
= DEFAULT_APP_SOCKET_RW_TIMEOUT
,
43 .tracing_group_name
.value
= DEFAULT_TRACING_GROUP
,
44 .kmod_probes_list
.value
= NULL
,
45 .kmod_extra_probes_list
.value
= NULL
,
49 .apps_unix_sock_path
.value
= NULL
,
50 .client_unix_sock_path
.value
= NULL
,
51 .wait_shm_path
.value
= NULL
,
52 .health_unix_sock_path
.value
= NULL
,
53 .lttng_ust_clock_plugin
.value
= NULL
,
54 .pid_file_path
.value
= NULL
,
55 .lock_file_path
.value
= NULL
,
56 .agent_port_file_path
.value
= NULL
,
57 .load_session_path
.value
= NULL
,
59 .consumerd32_path
.value
= NULL
,
60 .consumerd32_bin_path
.value
= NULL
,
61 .consumerd32_lib_dir
.value
= NULL
,
62 .consumerd32_err_unix_sock_path
.value
= NULL
,
63 .consumerd32_cmd_unix_sock_path
.value
= NULL
,
65 .consumerd64_path
.value
= NULL
,
66 .consumerd64_bin_path
.value
= NULL
,
67 .consumerd64_lib_dir
.value
= NULL
,
68 .consumerd64_err_unix_sock_path
.value
= NULL
,
69 .consumerd64_cmd_unix_sock_path
.value
= NULL
,
71 .kconsumerd_path
.value
= NULL
,
72 .kconsumerd_err_unix_sock_path
.value
= NULL
,
73 .kconsumerd_cmd_unix_sock_path
.value
= NULL
,
77 void config_string_fini(struct config_string
*str
)
79 config_string_set(str
, NULL
);
83 void config_string_set_static(struct config_string
*config_str
,
86 config_string_set(config_str
, (char *) value
);
87 config_str
->should_free
= false;
90 /* Only use for dynamically-allocated strings. */
92 void config_string_set(struct config_string
*config_str
, char *value
)
95 if (config_str
->should_free
) {
96 free(config_str
->value
);
97 config_str
->should_free
= false;
100 config_str
->should_free
= !!value
;
101 config_str
->value
= value
;
105 int sessiond_config_apply_env_config(struct sessiond_config
*config
)
108 const char *env_value
;
110 env_value
= getenv(DEFAULT_APP_SOCKET_TIMEOUT_ENV
);
116 int_val
= strtoul(env_value
, &endptr
, 0);
117 if (errno
!= 0 || int_val
> INT_MAX
||
118 (int_val
< 0 && int_val
!= -1)) {
119 ERR("Invalid value \"%s\" used for \"%s\" environment variable",
120 env_value
, DEFAULT_APP_SOCKET_TIMEOUT_ENV
);
125 config
->app_socket_timeout
= int_val
;
128 env_value
= lttng_secure_getenv("LTTNG_CONSUMERD32_BIN");
130 config_string_set_static(&config
->consumerd32_bin_path
,
133 env_value
= lttng_secure_getenv("LTTNG_CONSUMERD64_BIN");
135 config_string_set_static(&config
->consumerd64_bin_path
,
139 env_value
= lttng_secure_getenv("LTTNG_CONSUMERD32_LIBDIR");
141 config_string_set_static(&config
->consumerd32_lib_dir
,
144 env_value
= lttng_secure_getenv("LTTNG_CONSUMERD64_LIBDIR");
146 config_string_set_static(&config
->consumerd64_lib_dir
,
150 env_value
= lttng_secure_getenv("LTTNG_UST_CLOCK_PLUGIN");
152 config_string_set_static(&config
->lttng_ust_clock_plugin
,
156 env_value
= lttng_secure_getenv(DEFAULT_LTTNG_KMOD_PROBES
);
158 config_string_set_static(&config
->kmod_probes_list
,
162 env_value
= lttng_secure_getenv(DEFAULT_LTTNG_EXTRA_KMOD_PROBES
);
164 config_string_set_static(&config
->kmod_extra_probes_list
,
172 int config_set_paths_root(struct sessiond_config
*config
)
176 config_string_set(&config
->rundir
, strdup(DEFAULT_LTTNG_RUNDIR
));
177 if (!config
->rundir
.value
) {
178 ERR("Failed to set rundir");
183 config_string_set_static(&config
->apps_unix_sock_path
,
184 DEFAULT_GLOBAL_APPS_UNIX_SOCK
);
185 config_string_set_static(&config
->client_unix_sock_path
,
186 DEFAULT_GLOBAL_CLIENT_UNIX_SOCK
);
187 config_string_set_static(&config
->wait_shm_path
,
188 DEFAULT_GLOBAL_APPS_WAIT_SHM_PATH
);
189 config_string_set_static(&config
->health_unix_sock_path
,
190 DEFAULT_GLOBAL_HEALTH_UNIX_SOCK
);
196 int config_set_paths_non_root(struct sessiond_config
*config
)
199 const char *home_path
= utils_get_home_dir();
202 if (home_path
== NULL
) {
203 ERR("Can't get HOME directory for sockets creation.");
209 * Create rundir from home path. This will create something like
212 ret
= asprintf(&str
, DEFAULT_LTTNG_HOME_RUNDIR
, home_path
);
214 ERR("Failed to set rundir");
217 config_string_set(&config
->rundir
, str
);
220 ret
= asprintf(&str
, DEFAULT_HOME_APPS_UNIX_SOCK
, home_path
);
222 ERR("Failed to set default home apps unix socket path");
225 config_string_set(&config
->apps_unix_sock_path
, str
);
228 ret
= asprintf(&str
, DEFAULT_HOME_CLIENT_UNIX_SOCK
, home_path
);
230 ERR("Failed to set default home client unix socket path");
233 config_string_set(&config
->client_unix_sock_path
, str
);
236 ret
= asprintf(&str
, DEFAULT_HOME_APPS_WAIT_SHM_PATH
, getuid());
238 ERR("Failed to set default home apps wait shm path");
241 config_string_set(&config
->wait_shm_path
, str
);
244 ret
= asprintf(&str
, DEFAULT_HOME_HEALTH_UNIX_SOCK
, home_path
);
246 ERR("Failed to set default home health UNIX socket path");
249 config_string_set(&config
->health_unix_sock_path
, str
);
258 int sessiond_config_init(struct sessiond_config
*config
)
261 bool is_root
= (getuid() == 0);
265 memcpy(config
, &sessiond_config_build_defaults
, sizeof(*config
));
268 ret
= config_set_paths_root(config
);
270 ret
= config_set_paths_non_root(config
);
273 /* 32 bits consumerd path setup */
274 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD32_PATH
,
275 config
->rundir
.value
);
277 ERR("Failed to set 32-bit consumer path");
280 config_string_set(&config
->consumerd32_path
, str
);
283 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD32_ERR_SOCK_PATH
,
284 config
->rundir
.value
);
286 ERR("Failed to set 32-bit consumer error socket path");
289 config_string_set(&config
->consumerd32_err_unix_sock_path
, str
);
292 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD32_CMD_SOCK_PATH
,
293 config
->rundir
.value
);
295 ERR("Failed to set 32-bit consumer command socket path");
298 config_string_set(&config
->consumerd32_cmd_unix_sock_path
, str
);
301 /* 64 bits consumerd path setup */
302 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD64_PATH
,
303 config
->rundir
.value
);
305 ERR("Failed to set 64-bit consumer path");
308 config_string_set(&config
->consumerd64_path
, str
);
311 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD64_ERR_SOCK_PATH
,
312 config
->rundir
.value
);
314 ERR("Failed to set 64-bit consumer error socket path");
317 config_string_set(&config
->consumerd64_err_unix_sock_path
, str
);
320 ret
= asprintf(&str
, DEFAULT_USTCONSUMERD64_CMD_SOCK_PATH
,
321 config
->rundir
.value
);
323 ERR("Failed to set 64-bit consumer command socket path");
326 config_string_set(&config
->consumerd64_cmd_unix_sock_path
, str
);
329 /* kconsumerd consumerd path setup */
330 ret
= asprintf(&str
, DEFAULT_KCONSUMERD_PATH
,
331 config
->rundir
.value
);
333 ERR("Failed to set kernel consumer path");
336 config_string_set(&config
->kconsumerd_path
, str
);
339 ret
= asprintf(&str
, DEFAULT_KCONSUMERD_ERR_SOCK_PATH
,
340 config
->rundir
.value
);
342 ERR("Failed to set kernel consumer error socket path");
345 config_string_set(&config
->kconsumerd_err_unix_sock_path
, str
);
348 ret
= asprintf(&str
, DEFAULT_KCONSUMERD_CMD_SOCK_PATH
,
349 config
->rundir
.value
);
351 ERR("Failed to set kernel consumer command socket path");
354 config_string_set(&config
->kconsumerd_cmd_unix_sock_path
, str
);
357 ret
= asprintf(&str
, "%s/%s", config
->rundir
.value
,
358 DEFAULT_LTTNG_SESSIOND_PIDFILE
);
360 ERR("Failed to set PID file path");
363 config_string_set(&config
->pid_file_path
, str
);
366 ret
= asprintf(&str
, "%s/%s", config
->rundir
.value
,
367 DEFAULT_LTTNG_SESSIOND_LOCKFILE
);
369 ERR("Failed to set lock file path");
372 config_string_set(&config
->lock_file_path
, str
);
375 ret
= asprintf(&str
, "%s/%s", config
->rundir
.value
,
376 DEFAULT_LTTNG_SESSIOND_AGENTPORT_FILE
);
378 ERR("Failed to set agent port file path");
381 config_string_set(&config
->agent_port_file_path
, str
);
385 * Allow INSTALL_BIN_PATH to be used as a target path for the
386 * native architecture size consumer if CONFIG_CONSUMER*_PATH
387 * has not been defined.
389 #if (CAA_BITS_PER_LONG == 32)
390 config_string_set_static(&config
->consumerd32_bin_path
,
391 INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
);
392 config_string_set_static(&config
->consumerd32_lib_dir
,
394 #elif (CAA_BITS_PER_LONG == 64)
395 config_string_set_static(&config
->consumerd64_bin_path
,
396 INSTALL_BIN_PATH
"/" DEFAULT_CONSUMERD_FILE
);
397 config_string_set_static(&config
->consumerd64_lib_dir
,
400 #error "Unknown bitness"
408 void sessiond_config_fini(struct sessiond_config
*config
)
410 config_string_fini(&config
->tracing_group_name
);
411 config_string_fini(&config
->kmod_probes_list
);
412 config_string_fini(&config
->kmod_extra_probes_list
);
413 config_string_fini(&config
->apps_unix_sock_path
);
414 config_string_fini(&config
->client_unix_sock_path
);
415 config_string_fini(&config
->wait_shm_path
);
416 config_string_fini(&config
->health_unix_sock_path
);
417 config_string_fini(&config
->lttng_ust_clock_plugin
);
418 config_string_fini(&config
->pid_file_path
);
419 config_string_fini(&config
->lock_file_path
);
420 config_string_fini(&config
->load_session_path
);
421 config_string_fini(&config
->agent_port_file_path
);
422 config_string_fini(&config
->consumerd32_path
);
423 config_string_fini(&config
->consumerd32_bin_path
);
424 config_string_fini(&config
->consumerd32_lib_dir
);
425 config_string_fini(&config
->consumerd32_err_unix_sock_path
);
426 config_string_fini(&config
->consumerd32_cmd_unix_sock_path
);
427 config_string_fini(&config
->consumerd64_path
);
428 config_string_fini(&config
->consumerd64_bin_path
);
429 config_string_fini(&config
->consumerd64_lib_dir
);
430 config_string_fini(&config
->consumerd64_err_unix_sock_path
);
431 config_string_fini(&config
->consumerd64_cmd_unix_sock_path
);
432 config_string_fini(&config
->kconsumerd_path
);
433 config_string_fini(&config
->kconsumerd_err_unix_sock_path
);
434 config_string_fini(&config
->kconsumerd_cmd_unix_sock_path
);
438 int resolve_path(struct config_string
*path
)
443 if (!path
->value
|| path
->value
[0] == '/') {
447 absolute_path
= utils_expand_path(path
->value
);
448 if (!absolute_path
) {
453 config_string_set(path
, absolute_path
);
458 #define RESOLVE_CHECK(path_config_str) \
459 if (resolve_path(path_config_str)) \
463 int sessiond_config_resolve_paths(struct sessiond_config
*config
)
465 RESOLVE_CHECK(&config
->apps_unix_sock_path
);
466 RESOLVE_CHECK(&config
->client_unix_sock_path
);
467 RESOLVE_CHECK(&config
->wait_shm_path
);
468 RESOLVE_CHECK(&config
->health_unix_sock_path
);
469 RESOLVE_CHECK(&config
->lttng_ust_clock_plugin
);
470 RESOLVE_CHECK(&config
->pid_file_path
);
471 RESOLVE_CHECK(&config
->lock_file_path
);
472 RESOLVE_CHECK(&config
->load_session_path
);
473 RESOLVE_CHECK(&config
->agent_port_file_path
);
474 RESOLVE_CHECK(&config
->consumerd32_path
);
475 RESOLVE_CHECK(&config
->consumerd32_bin_path
);
476 RESOLVE_CHECK(&config
->consumerd32_lib_dir
);
477 RESOLVE_CHECK(&config
->consumerd32_err_unix_sock_path
);
478 RESOLVE_CHECK(&config
->consumerd32_cmd_unix_sock_path
);
479 RESOLVE_CHECK(&config
->consumerd64_path
);
480 RESOLVE_CHECK(&config
->consumerd64_bin_path
);
481 RESOLVE_CHECK(&config
->consumerd64_lib_dir
);
482 RESOLVE_CHECK(&config
->consumerd64_err_unix_sock_path
);
483 RESOLVE_CHECK(&config
->consumerd64_cmd_unix_sock_path
);
484 RESOLVE_CHECK(&config
->kconsumerd_path
);
485 RESOLVE_CHECK(&config
->kconsumerd_err_unix_sock_path
);
486 RESOLVE_CHECK(&config
->kconsumerd_cmd_unix_sock_path
);
491 void sessiond_config_log(struct sessiond_config
*config
)
493 DBG_NO_LOC("[sessiond configuration]");
494 DBG_NO_LOC("\tverbose: %i", config
->verbose
);
495 DBG_NO_LOC("\tverbose consumer: %i", config
->verbose_consumer
);
496 DBG_NO_LOC("\tquiet mode: %s", config
->quiet
? "True" : "False");
497 DBG_NO_LOC("\tagent_tcp_port: %i", config
->agent_tcp_port
);
498 DBG_NO_LOC("\tapplication socket timeout: %i", config
->app_socket_timeout
);
499 DBG_NO_LOC("\tno-kernel: %s", config
->no_kernel
? "True" : "False");
500 DBG_NO_LOC("\tbackground: %s", config
->background
? "True" : "False");
501 DBG_NO_LOC("\tdaemonize: %s", config
->daemonize
? "True" : "False");
502 DBG_NO_LOC("\tsignal parent on start: %s", config
->sig_parent
? "True" : "False");
503 DBG_NO_LOC("\ttracing group name: %s", config
->tracing_group_name
.value
? : "Unknown");
504 DBG_NO_LOC("\tkmod_probe_list: %s", config
->kmod_probes_list
.value
? : "None");
505 DBG_NO_LOC("\tkmod_extra_probe_list: %s", config
->kmod_extra_probes_list
.value
? : "None");
506 DBG_NO_LOC("\trundir: %s", config
->rundir
.value
? : "Unknown");
507 DBG_NO_LOC("\tapplication socket path: %s", config
->apps_unix_sock_path
.value
? : "Unknown");
508 DBG_NO_LOC("\tclient socket path: %s", config
->client_unix_sock_path
.value
? : "Unknown");
509 DBG_NO_LOC("\twait shm path: %s", config
->wait_shm_path
.value
? : "Unknown");
510 DBG_NO_LOC("\thealth socket path: %s", config
->health_unix_sock_path
.value
? : "Unknown");
511 DBG_NO_LOC("\tLTTNG_UST_CLOCK_PLUGIN: %s", config
->lttng_ust_clock_plugin
.value
? : "None");
512 DBG_NO_LOC("\tpid file path: %s", config
->pid_file_path
.value
? : "Unknown");
513 DBG_NO_LOC("\tlock file path: %s", config
->lock_file_path
.value
? : "Unknown");
514 DBG_NO_LOC("\tsession load path: %s", config
->load_session_path
.value
? : "None");
515 DBG_NO_LOC("\tagent port file path: %s", config
->agent_port_file_path
.value
? : "Unknown");